@@ -30,6 +30,19 @@ class PlotType(IntEnum):
3030 Unc = auto ()
3131 N = auto ()
3232
33+ class ObjectToSave (IntEnum ):
34+ Canvas = 0
35+ RawYield = auto ()
36+ Uncertainty = auto ()
37+ Efficiency = auto ()
38+ Fraction = auto ()
39+ CorrectedYield = auto ()
40+ CorrelationMatrix = auto ()
41+ Covariance = auto ()
42+ CorrectedFraction = auto ()
43+ MinimisationStatus = auto ()
44+ N = auto ()
45+
3346def main (config ):
3447 """
3548 Main function
@@ -84,6 +97,18 @@ def main(config):
8497 is_save_canvas_as_macro [PlotType .Cov ] = cfg .get ("is_save_canvas_as_macro" , {}).get ("cov" , False )
8598 is_save_canvas_as_macro [PlotType .Unc ] = cfg .get ("is_save_canvas_as_macro" , {}).get ("unc" , False )
8699
100+ is_save_to_root_file = [False ] * ObjectToSave .N
101+ is_save_to_root_file [ObjectToSave .Canvas ] = cfg .get ("is_save_to_root_file" , {}).get ("canvas" , False )
102+ is_save_to_root_file [ObjectToSave .RawYield ] = cfg .get ("is_save_to_root_file" , {}).get ("raw_yield" , False )
103+ is_save_to_root_file [ObjectToSave .Uncertainty ] = cfg .get ("is_save_to_root_file" , {}).get ("uncertainty" , False )
104+ is_save_to_root_file [ObjectToSave .Efficiency ] = cfg .get ("is_save_to_root_file" , {}).get ("efficiency" , False )
105+ is_save_to_root_file [ObjectToSave .Fraction ] = cfg .get ("is_save_to_root_file" , {}).get ("fraction" , False )
106+ is_save_to_root_file [ObjectToSave .CorrectedYield ] = cfg .get ("is_save_to_root_file" , {}).get ("corrected_yield" , True )
107+ is_save_to_root_file [ObjectToSave .CorrelationMatrix ] = cfg .get ("is_save_to_root_file" , {}).get ("correlation_matrix" , False )
108+ is_save_to_root_file [ObjectToSave .Covariance ] = cfg .get ("is_save_to_root_file" , {}).get ("covariance" , False )
109+ is_save_to_root_file [ObjectToSave .CorrectedFraction ] = cfg .get ("is_save_to_root_file" , {}).get ("corrected_fraction" , False )
110+ is_save_to_root_file [ObjectToSave .MinimisationStatus ] = cfg .get ("is_save_to_root_file" , {}).get ("minimisation_status" , True )
111+
87112 if cfg ["central_efficiency" ]["computerawfrac" ]:
88113 infile_name = os .path .join (cfg ["central_efficiency" ]["inputdir" ], cfg ["central_efficiency" ]["inputfile" ])
89114 infile_central_eff = ROOT .TFile .Open (infile_name )
@@ -253,44 +278,48 @@ def main(config):
253278 hist_bin_title_rawy = hist_bin_title if is_draw_title [PlotType .Rawy ] else ""
254279 canv_rawy , histos_rawy , leg_r = minimiser .plot_result (f"_pt_{ pt_min } _to_{ pt_max } " , hist_bin_title_rawy )
255280 output .cd ()
256- canv_rawy .Write ()
257- for _ , hist in histos_rawy .items ():
258- hist .Write ()
281+ if is_save_to_root_file [ObjectToSave .Canvas ]: canv_rawy .Write ()
282+ if is_save_to_root_file [ObjectToSave .RawYield ]:
283+ for _ , hist in histos_rawy .items ():
284+ hist .Write ()
259285 if (is_save_canvas_as_macro [PlotType .Rawy ]):
260286 canv_rawy .SaveAs (f"canv_rawy_{ ipt + 1 } .C" )
261287
262288 hist_bin_title_unc = hist_bin_title if is_draw_title [PlotType .Unc ] else ""
263289 canv_unc , histos_unc , leg_unc = minimiser .plot_uncertainties (f"_pt_{ pt_min } _to_{ pt_max } " , hist_bin_title_unc )
264290 output .cd ()
265- canv_unc .Write ()
266- for _ , hist in histos_unc .items ():
267- hist .Write ()
291+ if is_save_to_root_file [ObjectToSave .Canvas ]: canv_unc .Write ()
292+ if is_save_to_root_file [ObjectToSave .Uncertainty ]:
293+ for _ , hist in histos_unc .items ():
294+ hist .Write ()
268295 if (is_save_canvas_as_macro [PlotType .Unc ]):
269296 canv_unc .SaveAs (f"canv_unc_{ ipt + 1 } .C" )
270297
271298 hist_bin_title_eff = hist_bin_title if is_draw_title [PlotType .Eff ] else ""
272299 canv_eff , histos_eff , leg_e = minimiser .plot_efficiencies (f"_pt_{ pt_min } _to_{ pt_max } " , hist_bin_title_eff )
273300 output .cd ()
274- canv_eff .Write ()
275- for _ , hist in histos_eff .items ():
276- hist .Write ()
301+ if is_save_to_root_file [ObjectToSave .Canvas ]: canv_eff .Write ()
302+ if is_save_to_root_file [ObjectToSave .Efficiency ]:
303+ for _ , hist in histos_eff .items ():
304+ hist .Write ()
277305 if (is_save_canvas_as_macro [PlotType .Eff ]):
278306 canv_eff .SaveAs (f"canv_eff_{ ipt + 1 } .C" )
279307
280308 hist_bin_title_frac = hist_bin_title if is_draw_title [PlotType .Frac ] else ""
281309 canv_frac , histos_frac , leg_f = minimiser .plot_fractions (f"_pt_{ pt_min } _to_{ pt_max } " , hist_bin_title_frac )
282310 output .cd ()
283- canv_frac .Write ()
284- for _ , hist in histos_frac .items ():
285- hist .Write ()
311+ if is_save_to_root_file [ObjectToSave .Canvas ]: canv_frac .Write ()
312+ if is_save_to_root_file [ObjectToSave .Fraction ]:
313+ for _ , hist in histos_frac .items ():
314+ hist .Write ()
286315 if (is_save_canvas_as_macro [PlotType .Frac ]):
287316 canv_frac .SaveAs (f"canv_frac_{ ipt + 1 } .C" )
288317
289318 hist_bin_title_cov = hist_bin_title if is_draw_title [PlotType .Cov ] else ""
290319 canv_cov , histo_cov = minimiser .plot_cov_matrix (True , f"_pt_{ pt_min } _to_{ pt_max } " , hist_bin_title_cov )
291320 output .cd ()
292- canv_cov .Write ()
293- histo_cov .Write ()
321+ if is_save_to_root_file [ ObjectToSave . Canvas ]: canv_cov .Write ()
322+ if is_save_to_root_file [ ObjectToSave . CorrelationMatrix ]: histo_cov .Write ()
294323 if (is_save_canvas_as_macro [PlotType .Cov ]):
295324 canv_cov .SaveAs (f"canv_cov_{ ipt + 1 } .C" )
296325 else :
@@ -338,14 +367,17 @@ def main(config):
338367 canv_unc .Print (f"{ os .path .join (cfg ['output' ]['directory' ], output_name_unc_pdf )} { print_bracket } " )
339368
340369 output .cd ()
341- hist_corry_prompt .Write ()
342- hist_corry_nonprompt .Write ()
343- hist_covariance_pnp .Write ()
344- hist_covariance_pp .Write ()
345- hist_covariance_npnp .Write ()
346- hist_corrfrac_prompt .Write ()
347- hist_corrfrac_nonprompt .Write ()
348- hist_minimisation_status .Write ()
370+ if is_save_to_root_file [ObjectToSave .CorrectedYield ]:
371+ hist_corry_prompt .Write ()
372+ hist_corry_nonprompt .Write ()
373+ if is_save_to_root_file [ObjectToSave .Covariance ]:
374+ hist_covariance_pnp .Write ()
375+ hist_covariance_pp .Write ()
376+ hist_covariance_npnp .Write ()
377+ if is_save_to_root_file [ObjectToSave .CorrectedFraction ]:
378+ hist_corrfrac_prompt .Write ()
379+ hist_corrfrac_nonprompt .Write ()
380+ if is_save_to_root_file [ObjectToSave .MinimisationStatus ]: hist_minimisation_status .Write ()
349381 if cfg ["central_efficiency" ]["computerawfrac" ]:
350382 hist_frac_raw_prompt .Write ()
351383 hist_frac_raw_nonprompt .Write ()
0 commit comments