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

Constructor & Destructor Documentation

◆ __init__()

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

Definition at line 213 of file physvalPostProcessingTools.py.

213 def __init__(self, signal_path, background_path, output):
214 self.signal_path = signal_path
215 self.background_path = background_path
216 self.output = output
217

Member Function Documentation

◆ __call__()

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

Definition at line 218 of file physvalPostProcessingTools.py.

218 def __call__(self, root_file):
219 sig = find_histo(root_file, self.signal_path)
220 bkg = find_histo(root_file, self.background_path)
221
222 if not sig or not bkg:
223 if crash_on_error:
224 raise RuntimeError(f"Missing histogram: {self.signal_path} or {self.background_path}")
225 else:
226 logging.error(f"Missing histogram: {self.signal_path} or {self.background_path}")
227 return
228
229 graph = self.compute_roc(sig, bkg)
230 if not graph:
231 logging.error("ROC graph is empty or could not be constructed.")
232 return
233
234 path_parts = self.output.strip("/").split("/")
235 *dir_path, obj_name = path_parts
236 directory_path = "/".join(dir_path)
237
238 graph.SetName(obj_name)
239 graph.SetTitle(f"{obj_name};Signal Efficiency;Background Rejection")
240
241 ensure_directory_exists(root_file, directory_path)
242 root_file.cd(directory_path)
243 graph.Write()
244 logging.info(f"Saved ROC curve '{obj_name}' in '{directory_path}'.")
245
std::vector< std::string > split(const std::string &s, const std::string &t=":")
Definition hcg.cxx:177

◆ compute_roc()

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

Definition at line 246 of file physvalPostProcessingTools.py.

246 def compute_roc(self, sig, bkg):
247 n_bins = sig.GetNbinsX()
248 total_sig = sig.Integral()
249 total_bkg = bkg.Integral()
250
251 x_vals, y_vals = [], []
252 if total_sig == 0 or total_bkg == 0:
253 logging.error("Zero total signal or background counts; cannot compute ROC.")
254 return None
255
256 for cut_bin in range(1, n_bins + 1): # Loops over histogram bins, each corresponding to a cut value on the tagger output.
257 sig_pass = sig.Integral(cut_bin, n_bins)
258 bkg_pass = bkg.Integral(cut_bin, n_bins)
259
260 eff = sig_pass / total_sig # Signal efficiency eff = (number of b-jets passing cut) / (total b-jets).
261
262 if bkg_pass <= 0:
263 # logging.info(f"Skipping cut bin {cut_bin} due to zero or negative background pass count: {bkg_pass}. Any other options?")
264 continue
265
266 rej = total_bkg / bkg_pass # Background rejection rej = (total background jets) / (number of background jets passing cut).
267
268 x_vals.append(eff)
269 y_vals.append(rej)
270
271 if not x_vals:
272 return None
273
274 graph = ROOT.TGraphErrors(len(x_vals))
275 for i, (x, y) in enumerate(zip(x_vals, y_vals)):
276 graph.SetPoint(i, x, y)
277
278 return graph
279

◆ from_yaml()

python.physvalPostProcessingTools.ROCCurveComputation.from_yaml ( fragment)
static

Definition at line 281 of file physvalPostProcessingTools.py.

281 def from_yaml(fragment):
282 return ROCCurveComputation(
283 signal_path=fragment["signal"],
284 background_path=fragment["background"],
285 output=fragment["output"]
286 )

Member Data Documentation

◆ background_path

python.physvalPostProcessingTools.ROCCurveComputation.background_path = background_path

Definition at line 215 of file physvalPostProcessingTools.py.

◆ output

python.physvalPostProcessingTools.ROCCurveComputation.output = output

Definition at line 216 of file physvalPostProcessingTools.py.

◆ signal_path

python.physvalPostProcessingTools.ROCCurveComputation.signal_path = signal_path

Definition at line 214 of file physvalPostProcessingTools.py.


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