ATLAS Offline Software
Loading...
Searching...
No Matches
python.physvalPostProcessingTools.HistogramAddition Class Reference
Collaboration diagram for python.physvalPostProcessingTools.HistogramAddition:

Public Member Functions

 __init__ (self, histo1, histo2, output, delete_inputs=False)
 __call__ (self, root_file)

Static Public Member Functions

 from_yaml (fragment)

Public Attributes

 histo1 = histo1
 histo2 = histo2
 output = output
 delete_inputs = delete_inputs

Detailed Description

Definition at line 338 of file physvalPostProcessingTools.py.

Constructor & Destructor Documentation

◆ __init__()

python.physvalPostProcessingTools.HistogramAddition.__init__ ( self,
histo1,
histo2,
output,
delete_inputs = False )

Definition at line 339 of file physvalPostProcessingTools.py.

339 def __init__(self, histo1, histo2, output, delete_inputs=False):
340 self.histo1 = histo1
341 self.histo2 = histo2
342 self.output = output
343 self.delete_inputs = delete_inputs
344

Member Function Documentation

◆ __call__()

python.physvalPostProcessingTools.HistogramAddition.__call__ ( self,
root_file )

Definition at line 345 of file physvalPostProcessingTools.py.

345 def __call__(self, root_file):
346 histo1 = find_histo(root_file, self.histo1)
347 histo2 = find_histo(root_file, self.histo2)
348 if not histo1 or not histo2:
349 if crash_on_error:
350 raise RuntimeError(f"Missing histograms: {self.histo1} or {self.histo2}")
351 else:
352 logging.error(f"Missing histograms: {self.histo1} or {self.histo2}")
353 return
354
355 path_parts = self.output.strip("/").split("/")
356 *dir_path, output_name = path_parts
357 directory_path = "/".join(dir_path)
358 summed = histo1.Clone(output_name)
359 summed.Add(histo2)
360 ensure_directory_exists(root_file, directory_path)
361 root_file.cd(directory_path)
362 summed.Write(output_name, ROOT.TObject.kOverwrite)
363 logging.info(f"Saved added histogram '{output_name}' in '{directory_path}'.")
364 if self.delete_inputs:
365 # logging.info(f"Deleting input histograms '{self.histo1}' and '{self.histo2}' after addition.")
366 find_histo(root_file, self.histo1, should_delete=True)
367 find_histo(root_file, self.histo2, should_delete=True)
368
std::vector< std::string > split(const std::string &s, const std::string &t=":")
Definition hcg.cxx:177

◆ from_yaml()

python.physvalPostProcessingTools.HistogramAddition.from_yaml ( fragment)
static

Definition at line 370 of file physvalPostProcessingTools.py.

370 def from_yaml(fragment):
371 return HistogramAddition(
372 histo1=fragment["histo1_name"],
373 histo2=fragment["histo2_name"],
374 output=fragment["output"],
375 delete_inputs=fragment.get("delete_inputs", False)
376 )
377

Member Data Documentation

◆ delete_inputs

python.physvalPostProcessingTools.HistogramAddition.delete_inputs = delete_inputs

Definition at line 343 of file physvalPostProcessingTools.py.

◆ histo1

python.physvalPostProcessingTools.HistogramAddition.histo1 = histo1

Definition at line 340 of file physvalPostProcessingTools.py.

◆ histo2

python.physvalPostProcessingTools.HistogramAddition.histo2 = histo2

Definition at line 341 of file physvalPostProcessingTools.py.

◆ output

python.physvalPostProcessingTools.HistogramAddition.output = output

Definition at line 342 of file physvalPostProcessingTools.py.


The documentation for this class was generated from the following file: