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 411 of file physvalPostProcessingTools.py.

Constructor & Destructor Documentation

◆ __init__()

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

Definition at line 412 of file physvalPostProcessingTools.py.

412 def __init__(self, histo1, histo2, output, delete_inputs=False):
413 self.histo1 = histo1
414 self.histo2 = histo2
415 self.output = output
416 self.delete_inputs = delete_inputs
417

Member Function Documentation

◆ __call__()

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

Definition at line 418 of file physvalPostProcessingTools.py.

418 def __call__(self, root_file):
419 histo1 = find_histo(root_file, self.histo1)
420 histo2 = find_histo(root_file, self.histo2)
421 if not histo1 or not histo2:
422 if crash_on_error:
423 raise RuntimeError(f"Missing histograms: {self.histo1} or {self.histo2}")
424 else:
425 logging.error(f"Missing histograms: {self.histo1} or {self.histo2}")
426 return
427
428 path_parts = self.output.strip("/").split("/")
429 *dir_path, output_name = path_parts
430 directory_path = "/".join(dir_path)
431 summed = histo1.Clone(output_name)
432 summed.Add(histo2)
433 ensure_directory_exists(root_file, directory_path)
434 root_file.cd(directory_path)
435 summed.Write(output_name, ROOT.TObject.kOverwrite)
436 logging.info(f"Saved added histogram '{output_name}' in '{directory_path}'.")
437 if self.delete_inputs:
438 # logging.info(f"Deleting input histograms '{self.histo1}' and '{self.histo2}' after addition.")
439 find_histo(root_file, self.histo1, should_delete=True)
440 find_histo(root_file, self.histo2, should_delete=True)
441
std::vector< std::string > split(const std::string &s, const std::string &t=":")
Definition hcg.cxx:179

◆ from_yaml()

python.physvalPostProcessingTools.HistogramAddition.from_yaml ( fragment)
static

Definition at line 443 of file physvalPostProcessingTools.py.

443 def from_yaml(fragment):
444 return HistogramAddition(
445 histo1=fragment["histo1_name"],
446 histo2=fragment["histo2_name"],
447 output=fragment["output"],
448 delete_inputs=fragment.get("delete_inputs", False)
449 )
450

Member Data Documentation

◆ delete_inputs

python.physvalPostProcessingTools.HistogramAddition.delete_inputs = delete_inputs

Definition at line 416 of file physvalPostProcessingTools.py.

◆ histo1

python.physvalPostProcessingTools.HistogramAddition.histo1 = histo1

Definition at line 413 of file physvalPostProcessingTools.py.

◆ histo2

python.physvalPostProcessingTools.HistogramAddition.histo2 = histo2

Definition at line 414 of file physvalPostProcessingTools.py.

◆ output

python.physvalPostProcessingTools.HistogramAddition.output = output

Definition at line 415 of file physvalPostProcessingTools.py.


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