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

Public Member Functions

 __init__ (self, histogram_name)
 __call__ (self, root_file)

Static Public Member Functions

 from_yaml (fragment)

Public Attributes

 histogram_name = histogram_name

Protected Member Functions

 _compute_s (self, hist, cum, prob)

Detailed Description

Definition at line 161 of file physvalPostProcessingTools.py.

Constructor & Destructor Documentation

◆ __init__()

python.physvalPostProcessingTools.ResolutionComputation.__init__ ( self,
histogram_name )

Definition at line 163 of file physvalPostProcessingTools.py.

163 def __init__(self, histogram_name):
164 self.histogram_name = histogram_name
165

Member Function Documentation

◆ __call__()

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

Definition at line 166 of file physvalPostProcessingTools.py.

166 def __call__(self, root_file):
167 hist = find_histo(root_file, self.histogram_name)
168 if not hist:
169 if crash_on_error:
170 raise RuntimeError(f"Histogram '{self.histogram_name}' not found.")
171 else:
172 logging.error(f"Histogram '{self.histogram_name}' not found.")
173 return
174
175 # Step 1: Compute normalized cumulative sum
176 cum = [hist.GetBinContent(i) for i in range(0, hist.GetNbinsX() + 2)]
177 for i in range(1, len(cum)):
178 cum[i] += cum[i - 1]
179 total = cum[-1] or 1.0
180 cum = [x / total for x in cum]
181
182 # Step 2: Compute smallest intervals
183 s68 = self._compute_s(hist, cum, 0.683)
184 s90 = self._compute_s(hist, cum, 0.90)
185
186 logging.info(f"Resolution widths for {self.histogram_name} -> s68: {s68:.4f}, s90: {s90:.4f}")
187 logging.info("Todo: Take a 2D histo, take the quantity say xaxis, make its small intervals %s", "and then compute the Resolution widths and then save as a 1D histo with quantity on xaxis and Resolution widths on yaxis")
188

◆ _compute_s()

python.physvalPostProcessingTools.ResolutionComputation._compute_s ( self,
hist,
cum,
prob )
protected

Definition at line 189 of file physvalPostProcessingTools.py.

189 def _compute_s(self, hist, cum, prob):
190 # Compute the smallest interval that contains the given probability.
191 min_width = float("inf")
192 best = (0, 0)
193 for i in range(len(cum)):
194 target = cum[i] + prob
195 if target > 1:
196 break
197 for j in range(i + 1, len(cum)):
198 if cum[j] >= target:
199 width = hist.GetBinCenter(j) - hist.GetBinCenter(i)
200 if width < min_width:
201 min_width = width
202 best = (i, j)
203 break
204 return 0.5 * (hist.GetBinCenter(best[1]) - hist.GetBinCenter(best[0]))
205

◆ from_yaml()

python.physvalPostProcessingTools.ResolutionComputation.from_yaml ( fragment)
static

Definition at line 207 of file physvalPostProcessingTools.py.

207 def from_yaml(fragment):
208 return ResolutionComputation(
209 histogram_name=fragment["histogram"]
210 )
211

Member Data Documentation

◆ histogram_name

python.physvalPostProcessingTools.ResolutionComputation.histogram_name = histogram_name

Definition at line 164 of file physvalPostProcessingTools.py.


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