@@ -37,8 +37,8 @@ def main(config):
3737 infile_rawy = ROOT .TFile .Open (os .path .join (cfg ["rawyields" ]["inputdir" ], filename_rawy ))
3838 hist_rawy_name = cfg ["rawyields" ]["histoname" ]
3939 hist_rawy .append (infile_rawy .Get (hist_rawy_name ))
40- if (hist_rawy [- 1 ] is None ):
41- sys .exit (f"Fatal error: Histogram with raw yield \" { hist_rawy_name } \" is absent. Exit." )
40+ if not isinstance (hist_rawy [- 1 ], ROOT . TH1 ):
41+ sys .exit (f"\33 [31mFatal error: Histogram with raw yield \" { hist_rawy_name } \" is absent. Exit.\33 [0m " )
4242 hist_rawy [- 1 ].SetDirectory (0 )
4343 infile_rawy .Close ()
4444
@@ -47,31 +47,43 @@ def main(config):
4747 hist_effnp_name = cfg ["efficiencies" ]["histonames" ]["nonprompt" ]
4848 hist_effp .append (infile_eff .Get (hist_effp_name ))
4949 hist_effnp .append (infile_eff .Get (hist_effnp_name ))
50- if (hist_effp [- 1 ] is None ):
51- sys .exit (f"Fatal error: Histogram with efficiency for prompt \" { hist_effp_name } \" is absent. Exit." )
52- if (hist_effnp [- 1 ] is None ):
53- sys .exit (f"Fatal error: Histogram with efficiency for nonprompt \" { hist_effnp } \" is absent. Exit." )
50+ if not isinstance (hist_effp [- 1 ], ROOT . TH1 ):
51+ sys .exit (f"\33 [31mFatal error: Histogram with efficiency for prompt \" { hist_effp_name } \" is absent. Exit.\33 [0m " )
52+ if not isinstance (hist_effnp [- 1 ], ROOT . TH1 ):
53+ sys .exit (f"\33 [31mFatal error: Histogram with efficiency for nonprompt \" { hist_effnp } \" is absent. Exit.\33 [0m " )
5454 hist_effp [- 1 ].SetDirectory (0 )
5555 hist_effnp [- 1 ].SetDirectory (0 )
5656 infile_eff .Close ()
5757
5858 pt_bin_to_process = cfg .get ("pt_bin_to_process" , - 1 )
5959 if not isinstance (pt_bin_to_process , int ):
60- sys .exit ("Fatal error: pt_bin_to_process must be an integer value. Exit." )
60+ sys .exit ("\33 [31mFatal error: pt_bin_to_process must be an integer value. Exit." )
6161 if (pt_bin_to_process != - 1 and pt_bin_to_process < 1 ) or pt_bin_to_process > hist_rawy [0 ].GetNbinsX ():
62- sys .exit ("Fatal error: pt_bin_to_process must be a positive value up to number of bins in raw yield histogram. Exit." )
62+ sys .exit ("\33 [31mFatal error: pt_bin_to_process must be a positive value up to number of bins in raw yield histogram. Exit." )
63+
64+ is_draw_title_rawy = cfg .get ("is_draw_title" , {}).get ("rawy" , True )
65+ is_draw_title_eff = cfg .get ("is_draw_title" , {}).get ("eff" , False )
66+ is_draw_title_frac = cfg .get ("is_draw_title" , {}).get ("frac" , False )
67+ is_draw_title_cov = cfg .get ("is_draw_title" , {}).get ("cov" , False )
68+ is_draw_title_unc = cfg .get ("is_draw_title" , {}).get ("unc" , True )
69+
70+ is_save_canvas_as_macro_rawy = cfg .get ("is_save_canvas_as_macro" , {}).get ("rawy" , False )
71+ is_save_canvas_as_macro_eff = cfg .get ("is_save_canvas_as_macro" , {}).get ("eff" , False )
72+ is_save_canvas_as_macro_frac = cfg .get ("is_save_canvas_as_macro" , {}).get ("frac" , False )
73+ is_save_canvas_as_macro_cov = cfg .get ("is_save_canvas_as_macro" , {}).get ("cov" , False )
74+ is_save_canvas_as_macro_unc = cfg .get ("is_save_canvas_as_macro" , {}).get ("unc" , False )
6375
6476 if cfg ["central_efficiency" ]["computerawfrac" ]:
6577 infile_name = os .path .join (cfg ["central_efficiency" ]["inputdir" ], cfg ["central_efficiency" ]["inputfile" ])
6678 infile_central_eff = ROOT .TFile .Open (infile_name )
6779 hist_central_effp_name = cfg ["central_efficiency" ]["histonames" ]["prompt" ]
6880 hist_central_effp = infile_central_eff .Get (hist_central_effp_name )
69- if (hist_central_effp is None ):
70- sys .exit (f"Fatal error: Histogram with central efficiency for prompt \" { hist_central_effp_name } \" is absent. Exit." )
81+ if not isinstance (hist_central_effp [ - 1 ], ROOT . TH1 ):
82+ sys .exit (f"\33 [31mFatal error: Histogram with central efficiency for prompt \" { hist_central_effp_name } \" is absent. Exit.\33 [0m " )
7183 hist_central_effnp_name = cfg ["central_efficiency" ]["histonames" ]["nonprompt" ]
7284 hist_central_effnp = infile_central_eff .Get (hist_central_effnp_name )
73- if (hist_central_effnp is None ):
74- sys .exit (f"Fatal error: Histogram with central efficiency for nonprompt \" { hist_central_effnp_name } \" is absent. Exit." )
85+ if not isinstance (hist_central_effnp [ - 1 ], ROOT . TH1 ):
86+ sys .exit (f"\33 [31mFatal error: Histogram with central efficiency for nonprompt \" { hist_central_effnp_name } \" is absent. Exit.\33 [0m " )
7587 hist_central_effp .SetDirectory (0 )
7688 hist_central_effnp .SetDirectory (0 )
7789 infile_central_eff .Close ()
@@ -171,10 +183,10 @@ def main(config):
171183
172184 if cfg ["minimisation" ]["correlated" ]:
173185 if not (np .all (rawy [1 :] > rawy [:- 1 ]) or np .all (rawy [1 :] < rawy [:- 1 ])):
174- print ("WARNING ! main(): the raw yield vector is not monotonous. Check the input for stability." )
186+ print ("\0 \33 [33mWARNING ! main(): the raw yield vector is not monotonous. Check the input for stability.\0 \33 [0m " )
175187 print (f"raw yield vector elements = { rawy } \n " )
176188 if not (np .all (unc_rawy [1 :] > unc_rawy [:- 1 ]) or np .all (unc_rawy [1 :] < unc_rawy [:- 1 ])):
177- print ("WARNING ! main(): the raw yield uncertainties vector is not monotonous. Check the input for stability." )
189+ print ("\0 \33 [33mWARNING ! main(): the raw yield uncertainties vector is not monotonous. Check the input for stability.\0 \33 [0m " )
178190 print (f"raw yield uncertainties vector elements = { unc_rawy } \n " )
179191
180192 minimiser = CutVarMinimiser (rawy , effp , effnp , unc_rawy , unc_effp , unc_effnp )
@@ -211,34 +223,49 @@ def main(config):
211223
212224 hist_bin_title = f"bin # { ipt + 1 } ; { pt_axis_title } #in ({ pt_min } ; { pt_max } )"
213225
214- canv_rawy , histos_rawy , leg_r = minimiser .plot_result (f"_pt{ pt_min } _{ pt_max } " , hist_bin_title )
226+ hist_bin_title_rawy = hist_bin_title if is_draw_title_rawy else ""
227+ canv_rawy , histos_rawy , leg_r = minimiser .plot_result (f"_pt_{ pt_min } _to_{ pt_max } " , hist_bin_title_rawy )
215228 output .cd ()
216229 canv_rawy .Write ()
217230 for _ , hist in histos_rawy .items ():
218231 hist .Write ()
232+ if (is_save_canvas_as_macro_rawy ):
233+ canv_rawy .SaveAs (f"canv_rawy_{ ipt + 1 } .C" )
219234
220- canv_unc , histos_unc , leg_unc = minimiser .plot_uncertainties (f"_pt{ pt_min } _{ pt_max } " , hist_bin_title )
235+ hist_bin_title_unc = hist_bin_title if is_draw_title_unc else ""
236+ canv_unc , histos_unc , leg_unc = minimiser .plot_uncertainties (f"_pt_{ pt_min } _to_{ pt_max } " , hist_bin_title_unc )
221237 output .cd ()
222238 canv_unc .Write ()
223239 for _ , hist in histos_unc .items ():
224240 hist .Write ()
241+ if (is_save_canvas_as_macro_unc ):
242+ canv_unc .SaveAs (f"canv_unc_{ ipt + 1 } .C" )
225243
226- canv_eff , histos_eff , leg_e = minimiser .plot_efficiencies (f"_pt{ pt_min } _{ pt_max } " , hist_bin_title )
244+ hist_bin_title_eff = hist_bin_title if is_draw_title_eff else ""
245+ canv_eff , histos_eff , leg_e = minimiser .plot_efficiencies (f"_pt_{ pt_min } _to_{ pt_max } " , hist_bin_title_eff )
227246 output .cd ()
228247 canv_eff .Write ()
229248 for _ , hist in histos_eff .items ():
230249 hist .Write ()
250+ if (is_save_canvas_as_macro_eff ):
251+ canv_eff .SaveAs (f"canv_eff_{ ipt + 1 } .C" )
231252
232- canv_frac , histos_frac , leg_f = minimiser .plot_fractions (f"_pt{ pt_min } _{ pt_max } " , hist_bin_title )
253+ hist_bin_title_frac = hist_bin_title if is_draw_title_frac else ""
254+ canv_frac , histos_frac , leg_f = minimiser .plot_fractions (f"_pt_{ pt_min } _to_{ pt_max } " , hist_bin_title_frac )
233255 output .cd ()
234256 canv_frac .Write ()
235257 for _ , hist in histos_frac .items ():
236258 hist .Write ()
259+ if (is_save_canvas_as_macro_frac ):
260+ canv_frac .SaveAs (f"canv_frac_{ ipt + 1 } .C" )
237261
238- canv_cov , histo_cov = minimiser .plot_cov_matrix (True , f"_pt{ pt_min } _{ pt_max } " , hist_bin_title )
262+ hist_bin_title_cov = hist_bin_title if is_draw_title_cov else ""
263+ canv_cov , histo_cov = minimiser .plot_cov_matrix (True , f"_pt_{ pt_min } _to_{ pt_max } " , hist_bin_title_cov )
239264 output .cd ()
240265 canv_cov .Write ()
241266 histo_cov .Write ()
267+ if (is_save_canvas_as_macro_cov ):
268+ canv_cov .SaveAs (f"canv_cov_{ ipt + 1 } .C" )
242269 else :
243270 print (f"Minimization for pT { pt_min } , { pt_max } not successful" )
244271 canv_rawy = ROOT .TCanvas ("c_rawy_minimization_error" , "Minimization error" , 500 , 500 )
0 commit comments