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

Public Member Functions

 __init__ (self, signal_path, background_path, output)
 __call__ (self, root_file)
 compute_roc (self, sig, bkg)

Static Public Member Functions

 from_yaml (fragment)

Public Attributes

 signal_path = signal_path
 background_path = background_path
 output = output

Detailed Description

Definition at line 285 of file physvalPostProcessingTools.py.

Constructor & Destructor Documentation

◆ __init__()

python.physvalPostProcessingTools.ROCCurveComputation.__init__ ( self,
signal_path,
background_path,
output )

Definition at line 286 of file physvalPostProcessingTools.py.

286 def __init__(self, signal_path, background_path, output):
287 self.signal_path = signal_path
288 self.background_path = background_path
289 self.output = output
290

Member Function Documentation

◆ __call__()

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

Definition at line 291 of file physvalPostProcessingTools.py.

291 def __call__(self, root_file):
292 sig = find_histo(root_file, self.signal_path)
293 bkg = find_histo(root_file, self.background_path)
294
295 if not sig or not bkg:
296 if crash_on_error:
297 raise RuntimeError(f"Missing histogram: {self.signal_path} or {self.background_path}")
298 else:
299 logging.error(f"Missing histogram: {self.signal_path} or {self.background_path}")
300 return
301
302 graph = self.compute_roc(sig, bkg)
303 if not graph:
304 logging.error("ROC graph is empty or could not be constructed.")
305 return
306
307 path_parts = self.output.strip("/").split("/")
308 *dir_path, obj_name = path_parts
309 directory_path = "/".join(dir_path)
310
311 graph.SetName(obj_name)
312 graph.SetTitle(f"{obj_name};Signal Efficiency;Background Rejection")
313
314 ensure_directory_exists(root_file, directory_path)
315 root_file.cd(directory_path)
316 graph.Write()
317 logging.info(f"Saved ROC curve '{obj_name}' in '{directory_path}'.")
318
std::vector< std::string > split(const std::string &s, const std::string &t=":")
Definition hcg.cxx:179

◆ compute_roc()

python.physvalPostProcessingTools.ROCCurveComputation.compute_roc ( self,
sig,
bkg )

Definition at line 319 of file physvalPostProcessingTools.py.

319 def compute_roc(self, sig, bkg):
320 n_bins = sig.GetNbinsX()
321 total_sig = sig.Integral()
322 total_bkg = bkg.Integral()
323
324 x_vals, y_vals = [], []
325 if total_sig == 0 or total_bkg == 0:
326 logging.error("Zero total signal or background counts; cannot compute ROC.")
327 return None
328
329 for cut_bin in range(1, n_bins + 1): # Loops over histogram bins, each corresponding to a cut value on the tagger output.
330 sig_pass = sig.Integral(cut_bin, n_bins)
331 bkg_pass = bkg.Integral(cut_bin, n_bins)
332
333 eff = sig_pass / total_sig # Signal efficiency eff = (number of b-jets passing cut) / (total b-jets).
334
335 if bkg_pass <= 0:
336 # logging.info(f"Skipping cut bin {cut_bin} due to zero or negative background pass count: {bkg_pass}. Any other options?")
337 continue
338
339 rej = total_bkg / bkg_pass # Background rejection rej = (total background jets) / (number of background jets passing cut).
340
341 x_vals.append(eff)
342 y_vals.append(rej)
343
344 if not x_vals:
345 return None
346
347 graph = ROOT.TGraphErrors(len(x_vals))
348 for i, (x, y) in enumerate(zip(x_vals, y_vals)):
349 graph.SetPoint(i, x, y)
350
351 return graph
352

◆ from_yaml()

python.physvalPostProcessingTools.ROCCurveComputation.from_yaml ( fragment)
static

Definition at line 354 of file physvalPostProcessingTools.py.

354 def from_yaml(fragment):
355 return ROCCurveComputation(
356 signal_path=fragment["signal"],
357 background_path=fragment["background"],
358 output=fragment["output"]
359 )

Member Data Documentation

◆ background_path

python.physvalPostProcessingTools.ROCCurveComputation.background_path = background_path

Definition at line 288 of file physvalPostProcessingTools.py.

◆ output

python.physvalPostProcessingTools.ROCCurveComputation.output = output

Definition at line 289 of file physvalPostProcessingTools.py.

◆ signal_path

python.physvalPostProcessingTools.ROCCurveComputation.signal_path = signal_path

Definition at line 287 of file physvalPostProcessingTools.py.


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