ATLAS Offline Software
Public Member Functions | Static Public Member Functions | Public Attributes | List of all members
python.physvalPostProcessingTools.HistogramAdjustment Class Reference
Collaboration diagram for python.physvalPostProcessingTools.HistogramAdjustment:

Public Member Functions

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

Static Public Member Functions

def from_yaml (fragment)
 

Public Attributes

 input_hist
 
 new_path
 
 x_label
 
 y_label
 
 xlow
 
 xhigh
 

Detailed Description

Definition at line 378 of file physvalPostProcessingTools.py.

Constructor & Destructor Documentation

◆ __init__()

def 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__()

def 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 

◆ from_yaml()

def 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

Definition at line 380 of file physvalPostProcessingTools.py.

◆ new_path

python.physvalPostProcessingTools.HistogramAdjustment.new_path

Definition at line 381 of file physvalPostProcessingTools.py.

◆ x_label

python.physvalPostProcessingTools.HistogramAdjustment.x_label

Definition at line 382 of file physvalPostProcessingTools.py.

◆ xhigh

python.physvalPostProcessingTools.HistogramAdjustment.xhigh

Definition at line 385 of file physvalPostProcessingTools.py.

◆ xlow

python.physvalPostProcessingTools.HistogramAdjustment.xlow

Definition at line 384 of file physvalPostProcessingTools.py.

◆ y_label

python.physvalPostProcessingTools.HistogramAdjustment.y_label

Definition at line 383 of file physvalPostProcessingTools.py.


The documentation for this class was generated from the following file:
max
constexpr double max()
Definition: ap_fixedTest.cxx:33
min
constexpr double min()
Definition: ap_fixedTest.cxx:26
python.processes.powheg.ZZj_MiNNLO.ZZj_MiNNLO.__init__
def __init__(self, base_directory, **kwargs)
Constructor: all process options are set here.
Definition: ZZj_MiNNLO.py:18
python.physvalPostProcessingTools.ensure_directory_exists
def ensure_directory_exists(root_file, path)
— HELPER — ###
Definition: physvalPostProcessingTools.py:37
plotBeamSpotVxVal.range
range
Definition: plotBeamSpotVxVal.py:194
TCS::join
std::string join(const std::vector< std::string > &v, const char c=',')
Definition: Trigger/TrigT1/L1Topo/L1TopoCommon/Root/StringUtils.cxx:10
python.physvalPostProcessingTools.find_histo
def find_histo(root_file, path, should_delete=False)
— HELPER — ###
Definition: physvalPostProcessingTools.py:10
Trk::split
@ split
Definition: LayerMaterialProperties.h:38
python.LArMinBiasAlgConfig.float
float
Definition: LArMinBiasAlgConfig.py:65