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

Public Member Functions

 __init__ (self, input, output, rebin_factor, delete_original=False)
 __call__ (self, root_file)

Static Public Member Functions

 from_yaml (fragment)

Public Attributes

 input = input
 output = output
 rebin_factor = rebin_factor
 delete_original = delete_original

Detailed Description

Definition at line 138 of file physvalPostProcessingTools.py.

Constructor & Destructor Documentation

◆ __init__()

python.physvalPostProcessingTools.RebinningOperation.__init__ ( self,
input,
output,
rebin_factor,
delete_original = False )

Definition at line 139 of file physvalPostProcessingTools.py.

139 def __init__(self, input, output, rebin_factor, delete_original=False):
140 self.input = input
141 self.output = output
142 self.rebin_factor = rebin_factor
143 self.delete_original = delete_original
144

Member Function Documentation

◆ __call__()

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

Definition at line 145 of file physvalPostProcessingTools.py.

145 def __call__(self, root_file):
146 hist = find_histo(root_file, self.input)
147 if not hist:
148 if crash_on_error:
149 raise RuntimeError(f"Histogram '{self.input}' not found for rebinning.")
150 else:
151 logging.error(f"Histogram '{self.input}' not found for rebinning.")
152 return
153
154 path_parts = self.output.strip("/").split("/")
155 *dir_parts, output_name = path_parts
156 directory_path = "/".join(dir_parts)
157 ensure_directory_exists(root_file, directory_path)
158 root_file.cd(directory_path)
159
160 if hist.GetDimension() == 1:
161 rebinned = hist.Rebin(self.rebin_factor, output_name)
162 rebinned.Write(output_name, ROOT.TObject.kOverwrite)
163 logging.info(f"Rebinned 1D histogram and saved as '{output_name}' in '{directory_path}'.")
164 elif hist.GetDimension() == 2:
165 hist.RebinX(self.rebin_factor)
166 hist.RebinY(self.rebin_factor)
167 hist.SetName(output_name)
168 hist.Write(output_name, ROOT.TObject.kOverwrite)
169 logging.info(f"Rebinned 2D histogram and saved as '{output_name}' in '{directory_path}'.")
170 if self.delete_original:
171 find_histo(root_file, self.input, should_delete=True)
172
std::vector< std::string > split(const std::string &s, const std::string &t=":")
Definition hcg.cxx:179

◆ from_yaml()

python.physvalPostProcessingTools.RebinningOperation.from_yaml ( fragment)
static

Definition at line 174 of file physvalPostProcessingTools.py.

174 def from_yaml(fragment):
175 return RebinningOperation(
176 input=fragment["input"],
177 output=fragment["output"],
178 rebin_factor=fragment["rebin"],
179 delete_original=fragment.get("delete_original", False)
180 )

Member Data Documentation

◆ delete_original

python.physvalPostProcessingTools.RebinningOperation.delete_original = delete_original

Definition at line 143 of file physvalPostProcessingTools.py.

◆ input

python.physvalPostProcessingTools.RebinningOperation.input = input

Definition at line 140 of file physvalPostProcessingTools.py.

◆ output

python.physvalPostProcessingTools.RebinningOperation.output = output

Definition at line 141 of file physvalPostProcessingTools.py.

◆ rebin_factor

python.physvalPostProcessingTools.RebinningOperation.rebin_factor = rebin_factor

Definition at line 142 of file physvalPostProcessingTools.py.


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