Skip to content
Snippets Groups Projects
Commit 4689f043 authored by Nicole Geisselbrecht's avatar Nicole Geisselbrecht
Browse files

Added charge as weights for histogram.

parent 4c3328fb
No related branches found
No related tags found
1 merge request!7Resolve "Add charge as weights for histogram"
......@@ -56,7 +56,8 @@ class FileBinner:
chunksize=32,
keep_event_info=True,
keep_mc_tracks=False,
add_t0=False,):
add_t0=False,
use_charge_as_weights=False):
"""
Parameters
----------
......@@ -97,6 +98,8 @@ class FileBinner:
add_t0 : bool
If true, add t0 to the time of hits. If using a det_file,
this will already have been done automatically [default: False].
use_charge_as_weights : bool
If true, uses blob["Hits"]["charge"] as weights for histogram. [default: False]
"""
self.bin_edges_list = bin_edges_list
......@@ -121,6 +124,8 @@ class FileBinner:
self.complevel = 1
self.flush_frequency = 1000
self.use_charge_as_weights = use_charge_as_weights
def run(self, infile, outfile=None, save_plot=False):
"""
Generate images from the infile, and save them as the outfile.
......@@ -261,7 +266,8 @@ class FileBinner:
pipe.attach(modules.ImageMaker,
bin_edges_list=self.bin_edges_list,
store_as=name_histogram)
store_as=name_histogram,
use_charge_as_weights=self.use_charge_as_weights)
if self.mc_info_extr is not None:
if isinstance(self.mc_info_extr, str):
......
......@@ -117,12 +117,15 @@ class ImageMaker(kp.Module):
including the left- and right-most bin edge.
store_as : str
Store the images with this name in the blob.
use_charge_as_weights : bool
If true, uses blob["Hits"]["charge"] as weights for histogram.
"""
def configure(self):
self.bin_edges_list = self.require('bin_edges_list')
self.store_as = self.require('store_as')
self.use_charge_as_weights = self.get('use_charge_as_weights')
def process(self, blob):
data, bins, name = [], [], ""
......@@ -132,7 +135,12 @@ class ImageMaker(kp.Module):
bins.append(bin_edges)
name += bin_name + "_"
histogram = np.histogramdd(data, bins=bins)[0]
if self.use_charge_as_weights:
weights = blob["Hits"]["charge"]
else:
weights = None
histogram = np.histogramdd(data, bins=bins, weights=weights)[0]
title = name + "event_images"
hist_one_event = histogram[np.newaxis, ...].astype(np.uint8)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment