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

379 def __init__(self, input_hist, new_path, x_label=None, y_label=None, xlow=None, xhigh=None):
380 self.input_hist = input_hist
381 self.new_path = new_path
382 self.x_label = x_label
383 self.y_label = y_label
384 self.xlow = xlow
385 self.xhigh = xhigh
386

Member Function Documentation

◆ __call__()

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

Definition at line 387 of file physvalPostProcessingTools.py.

387 def __call__(self, root_file):
388 ROOT.TH1.AddDirectory(False)
389 hist = find_histo(root_file, self.input_hist)
390 if not hist:
391 if crash_on_error:
392 raise RuntimeError(f"Histogram '{self.input_hist}' not found.")
393 else:
394 logging.error(f"Histogram '{self.input_hist}' not found.")
395 return
396
397 path_parts = self.new_path.strip("/").split("/")
398 *dir_path, new_name = path_parts
399 directory_path = "/".join(dir_path)
400 ensure_directory_exists(root_file, directory_path)
401 root_file.cd(directory_path)
402
403 if self.xlow is None or self.xhigh is None:
404 h_out = hist.Clone(new_name)
405 else:
406 ax = hist.GetXaxis()
407 bin_low = max(1, min(ax.FindBin(self.xlow), ax.GetNbins()))
408 bin_high = max(1, min(ax.FindBin(self.xhigh), ax.GetNbins()))
409 nbins = bin_high - bin_low
410 h_out = ROOT.TH1D(new_name, hist.GetTitle(), nbins + 1, float(self.xlow), float(self.xhigh))
411 for i in range(nbins + 1):
412 h_out.SetBinContent(i + 1, hist.GetBinContent(i + bin_low))
413
414 if self.x_label:
415 h_out.GetXaxis().SetTitle(self.x_label)
416 if self.y_label:
417 h_out.GetYaxis().SetTitle(self.y_label)
418 h_out.Write(new_name, ROOT.TObject.kOverwrite)
419 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})")
420
#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:177

◆ from_yaml()

python.physvalPostProcessingTools.HistogramAdjustment.from_yaml ( fragment)
static

Definition at line 422 of file physvalPostProcessingTools.py.

422 def from_yaml(fragment):
423 return HistogramAdjustment(
424 input_hist=fragment["hist"],
425 new_path=fragment.get("final_histo_name", fragment["hist"]),
426 x_label=fragment.get("x_axis_label"),
427 y_label=fragment.get("y_axis_label"),
428 xlow=fragment.get("xlow"),
429 xhigh=fragment.get("xhigh")
430 )

Member Data Documentation

◆ input_hist

python.physvalPostProcessingTools.HistogramAdjustment.input_hist = input_hist

Definition at line 380 of file physvalPostProcessingTools.py.

◆ new_path

python.physvalPostProcessingTools.HistogramAdjustment.new_path = new_path

Definition at line 381 of file physvalPostProcessingTools.py.

◆ x_label

python.physvalPostProcessingTools.HistogramAdjustment.x_label = x_label

Definition at line 382 of file physvalPostProcessingTools.py.

◆ xhigh

python.physvalPostProcessingTools.HistogramAdjustment.xhigh = xhigh

Definition at line 385 of file physvalPostProcessingTools.py.

◆ xlow

python.physvalPostProcessingTools.HistogramAdjustment.xlow = xlow

Definition at line 384 of file physvalPostProcessingTools.py.

◆ y_label

python.physvalPostProcessingTools.HistogramAdjustment.y_label = y_label

Definition at line 383 of file physvalPostProcessingTools.py.


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