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

Public Member Functions

 __init__ (self, input_hist, new_path, x_label=None, y_label=None, xlow=None, xhigh=None)
 __call__ (self, root_file)

Static Public Member Functions

 from_yaml (fragment)

Public Attributes

 input_hist = input_hist
 new_path = new_path
 x_label = x_label
 y_label = y_label
 xlow = xlow
 xhigh = xhigh

Detailed Description

Definition at line 451 of file physvalPostProcessingTools.py.

Constructor & Destructor Documentation

◆ __init__()

python.physvalPostProcessingTools.HistogramAdjustment.__init__ ( self,
input_hist,
new_path,
x_label = None,
y_label = None,
xlow = None,
xhigh = None )

Definition at line 452 of file physvalPostProcessingTools.py.

452 def __init__(self, input_hist, new_path, x_label=None, y_label=None, xlow=None, xhigh=None):
453 self.input_hist = input_hist
454 self.new_path = new_path
455 self.x_label = x_label
456 self.y_label = y_label
457 self.xlow = xlow
458 self.xhigh = xhigh
459

Member Function Documentation

◆ __call__()

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

Definition at line 460 of file physvalPostProcessingTools.py.

460 def __call__(self, root_file):
461 ROOT.TH1.AddDirectory(False)
462 hist = find_histo(root_file, self.input_hist)
463 if not hist:
464 if crash_on_error:
465 raise RuntimeError(f"Histogram '{self.input_hist}' not found.")
466 else:
467 logging.error(f"Histogram '{self.input_hist}' not found.")
468 return
469
470 path_parts = self.new_path.strip("/").split("/")
471 *dir_path, new_name = path_parts
472 directory_path = "/".join(dir_path)
473 ensure_directory_exists(root_file, directory_path)
474 root_file.cd(directory_path)
475
476 if self.xlow is None or self.xhigh is None:
477 h_out = hist.Clone(new_name)
478 else:
479 ax = hist.GetXaxis()
480 bin_low = max(1, min(ax.FindBin(self.xlow), ax.GetNbins()))
481 bin_high = max(1, min(ax.FindBin(self.xhigh), ax.GetNbins()))
482 nbins = bin_high - bin_low
483 h_out = ROOT.TH1D(new_name, hist.GetTitle(), nbins, float(self.xlow), float(self.xhigh))
484 for i in range(nbins + 1):
485 h_out.SetBinContent(i + 1, hist.GetBinContent(i + bin_low))
486 h_out.SetBinError(i + 1, hist.GetBinError(i + bin_low))
487 # let's retain entries in the full range -- more meaningful than default (number of bins)
488 h_out.SetEntries(hist.GetEntries())
489
490 if self.x_label:
491 h_out.GetXaxis().SetTitle(self.x_label)
492 if self.y_label:
493 h_out.GetYaxis().SetTitle(self.y_label)
494 h_out.Write(new_name, ROOT.TObject.kOverwrite)
495 logging.info(f"Renamed and updated histogram '{self.input_hist}' → '{self.new_path}' in '{directory_path}' | X-axis: '{self.x_label}' | Y-axis: '{self.y_label}' | Range: ({self.xlow}, {self.xhigh})")
496
#define min(a, b)
Definition cfImp.cxx:40
#define max(a, b)
Definition cfImp.cxx:41
std::vector< std::string > split(const std::string &s, const std::string &t=":")
Definition hcg.cxx:179

◆ from_yaml()

python.physvalPostProcessingTools.HistogramAdjustment.from_yaml ( fragment)
static

Definition at line 498 of file physvalPostProcessingTools.py.

498 def from_yaml(fragment):
499 return HistogramAdjustment(
500 input_hist=fragment["hist"],
501 new_path=fragment.get("final_histo_name", fragment["hist"]),
502 x_label=fragment.get("x_axis_label"),
503 y_label=fragment.get("y_axis_label"),
504 xlow=fragment.get("xlow"),
505 xhigh=fragment.get("xhigh")
506 )

Member Data Documentation

◆ input_hist

python.physvalPostProcessingTools.HistogramAdjustment.input_hist = input_hist

Definition at line 453 of file physvalPostProcessingTools.py.

◆ new_path

python.physvalPostProcessingTools.HistogramAdjustment.new_path = new_path

Definition at line 454 of file physvalPostProcessingTools.py.

◆ x_label

python.physvalPostProcessingTools.HistogramAdjustment.x_label = x_label

Definition at line 455 of file physvalPostProcessingTools.py.

◆ xhigh

python.physvalPostProcessingTools.HistogramAdjustment.xhigh = xhigh

Definition at line 458 of file physvalPostProcessingTools.py.

◆ xlow

python.physvalPostProcessingTools.HistogramAdjustment.xlow = xlow

Definition at line 457 of file physvalPostProcessingTools.py.

◆ y_label

python.physvalPostProcessingTools.HistogramAdjustment.y_label = y_label

Definition at line 456 of file physvalPostProcessingTools.py.


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