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

Constructor & Destructor Documentation

◆ __init__()

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

Definition at line 236 of file physvalPostProcessingTools.py.

236 def __init__(self, histogram_name):
237 self.histogram_name = histogram_name
238

Member Function Documentation

◆ __call__()

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

Definition at line 239 of file physvalPostProcessingTools.py.

239 def __call__(self, root_file):
240 hist = find_histo(root_file, self.histogram_name)
241 if not hist:
242 if crash_on_error:
243 raise RuntimeError(f"Histogram '{self.histogram_name}' not found.")
244 else:
245 logging.error(f"Histogram '{self.histogram_name}' not found.")
246 return
247
248 # Step 1: Compute normalized cumulative sum
249 cum = [hist.GetBinContent(i) for i in range(0, hist.GetNbinsX() + 2)]
250 for i in range(1, len(cum)):
251 cum[i] += cum[i - 1]
252 total = cum[-1] or 1.0
253 cum = [x / total for x in cum]
254
255 # Step 2: Compute smallest intervals
256 s68 = self._compute_s(hist, cum, 0.683)
257 s90 = self._compute_s(hist, cum, 0.90)
258
259 logging.info(f"Resolution widths for {self.histogram_name} -> s68: {s68:.4f}, s90: {s90:.4f}")
260 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")
261

◆ _compute_s()

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

Definition at line 262 of file physvalPostProcessingTools.py.

262 def _compute_s(self, hist, cum, prob):
263 # Compute the smallest interval that contains the given probability.
264 min_width = float("inf")
265 best = (0, 0)
266 for i in range(len(cum)):
267 target = cum[i] + prob
268 if target > 1:
269 break
270 for j in range(i + 1, len(cum)):
271 if cum[j] >= target:
272 width = hist.GetBinCenter(j) - hist.GetBinCenter(i)
273 if width < min_width:
274 min_width = width
275 best = (i, j)
276 break
277 return 0.5 * (hist.GetBinCenter(best[1]) - hist.GetBinCenter(best[0]))
278

◆ from_yaml()

python.physvalPostProcessingTools.ResolutionComputation.from_yaml ( fragment)
static

Definition at line 280 of file physvalPostProcessingTools.py.

280 def from_yaml(fragment):
281 return ResolutionComputation(
282 histogram_name=fragment["histogram"]
283 )
284

Member Data Documentation

◆ histogram_name

python.physvalPostProcessingTools.ResolutionComputation.histogram_name = histogram_name

Definition at line 237 of file physvalPostProcessingTools.py.


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