@@ -55,6 +55,12 @@ def main(config):
5555 hist_effnp [- 1 ].SetDirectory (0 )
5656 infile_eff .Close ()
5757
58+ pt_bin_to_process = cfg .get ("pt_bin_to_process" , - 1 )
59+ if not isinstance (pt_bin_to_process , int ):
60+ sys .exit ("Fatal error: pt_bin_to_process must be an integer value. Exit." )
61+ 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." )
63+
5864 if cfg ["central_efficiency" ]["computerawfrac" ]:
5965 infile_name = os .path .join (cfg ["central_efficiency" ]["inputdir" ], cfg ["central_efficiency" ]["inputfile" ])
6066 infile_central_eff = ROOT .TFile .Open (infile_name )
@@ -80,6 +86,8 @@ def main(config):
8086 hist_covariance = hist_rawy [0 ].Clone ("hCovPromptNonPrompt" )
8187 hist_corrfrac_prompt = hist_rawy [0 ].Clone ("hCorrFracPrompt" )
8288 hist_corrfrac_nonprompt = hist_rawy [0 ].Clone ("hCorrFracNonPrompt" )
89+ for histo in hist_corry_prompt , hist_corry_nonprompt , hist_covariance , hist_corrfrac_prompt , hist_corrfrac_nonprompt :
90+ histo .Reset ()
8391 hist_corry_prompt .GetYaxis ().SetTitle ("corrected yields prompt" )
8492 hist_corry_nonprompt .GetYaxis ().SetTitle ("corrected yields non-prompt" )
8593 hist_covariance .GetYaxis ().SetTitle ("#sigma(prompt, non-prompt)" )
@@ -113,6 +121,8 @@ def main(config):
113121 if cfg ["central_efficiency" ]["computerawfrac" ]:
114122 hist_frac_raw_prompt = hist_rawy [0 ].Clone ("hRawFracPrompt" )
115123 hist_frac_raw_nonprompt = hist_rawy [0 ].Clone ("hRawFracNonPrompt" )
124+ for histo in hist_frac_raw_prompt , hist_frac_raw_nonprompt :
125+ histo .Reset ()
116126 hist_frac_raw_prompt .GetYaxis ().SetTitle ("raw fraction prompt" )
117127 hist_frac_raw_nonprompt .GetYaxis ().SetTitle ("raw fraction non-prompt" )
118128 set_object_style (
@@ -129,12 +139,20 @@ def main(config):
129139 markerstyle = ROOT .kFullSquare ,
130140 )
131141
132- output = ROOT .TFile (os .path .join (cfg ["output" ]["directory" ], cfg ["output" ]["file" ]), "recreate" )
142+ pt_bin_to_process_name_suffix = ""
143+ if pt_bin_to_process != - 1 :
144+ pt_bin_to_process_name_suffix = "_bin_" + str (pt_bin_to_process )
145+
146+ output_name_template = cfg ['output' ]['file' ].replace (".root" , "" ) + pt_bin_to_process_name_suffix + ".root"
147+ output = ROOT .TFile (os .path .join (cfg ["output" ]["directory" ], output_name_template ), "recreate" )
133148 n_sets = len (hist_rawy )
134149 pt_axis_title = hist_rawy [0 ].GetXaxis ().GetTitle ()
135150 for ipt in range (hist_rawy [0 ].GetNbinsX ()):
151+ if pt_bin_to_process != - 1 and ipt + 1 != pt_bin_to_process :
152+ continue
136153 pt_min = hist_rawy [0 ].GetXaxis ().GetBinLowEdge (ipt + 1 )
137154 pt_max = hist_rawy [0 ].GetXaxis ().GetBinUpEdge (ipt + 1 )
155+ print (f"\n \n INFO: processing pt range { ipt + 1 } from { pt_min } to { pt_max } { pt_axis_title } " )
138156
139157 rawy , effp , effnp , unc_rawy , unc_effp , unc_effnp = (np .zeros (n_sets ) for _ in range (6 ))
140158 for iset , (hrawy , heffp , heffnp ) in enumerate (zip (hist_rawy , hist_effp , hist_effnp )):
@@ -145,6 +163,14 @@ def main(config):
145163 unc_effp [iset ] = heffp .GetBinError (ipt + 1 )
146164 unc_effnp [iset ] = heffnp .GetBinError (ipt + 1 )
147165
166+ if cfg ["minimisation" ]["correlated" ]:
167+ if not (np .all (rawy [1 :] > rawy [:- 1 ]) or np .all (rawy [1 :] < rawy [:- 1 ])):
168+ print ("WARNING! main(): the raw yield vector is not monotonous. Check the input for stability." )
169+ print (f"raw yield vector elements = { rawy } \n " )
170+ if not (np .all (unc_rawy [1 :] > unc_rawy [:- 1 ]) or np .all (unc_rawy [1 :] < unc_rawy [:- 1 ])):
171+ print ("WARNING! main(): the raw yield uncertainties vector is not monotonous. Check the input for stability." )
172+ print (f"raw yield uncertainties vector elements = { unc_rawy } \n " )
173+
148174 minimiser = CutVarMinimiser (rawy , effp , effnp , unc_rawy , unc_effp , unc_effnp )
149175 minimiser .minimise_system (cfg ["minimisation" ]["correlated" ])
150176
@@ -180,6 +206,12 @@ def main(config):
180206 for _ , hist in histos_rawy .items ():
181207 hist .Write ()
182208
209+ canv_unc , histos_unc , leg_unc = minimiser .plot_uncertainties (f"_pt{ pt_min } _{ pt_max } " , hist_bin_title )
210+ output .cd ()
211+ canv_unc .Write ()
212+ for _ , hist in histos_unc .items ():
213+ hist .Write ()
214+
183215 canv_eff , histos_eff , leg_e = minimiser .plot_efficiencies (f"_pt{ pt_min } _{ pt_max } " , hist_bin_title )
184216 output .cd ()
185217 canv_eff .Write ()
@@ -208,13 +240,16 @@ def main(config):
208240 canv_combined .cd (4 )
209241 canv_cov .DrawClonePad ()
210242
211- output_name_rawy_pdf = f"Distr_{ cfg ['output' ]['file' ].replace ('.root' , '.pdf' )} "
212- output_name_eff_pdf = f"Eff_{ cfg ['output' ]['file' ].replace ('.root' , '.pdf' )} "
213- output_name_frac_pdf = f"Frac_{ cfg ['output' ]['file' ].replace ('.root' , '.pdf' )} "
214- output_name_covmat_pdf = f"CovMatrix_{ cfg ['output' ]['file' ].replace ('.root' , '.pdf' )} "
215- output_name_pdf = f"{ cfg ['output' ]['file' ].replace ('.root' , '.pdf' )} "
243+ output_name_template = output_name_template .replace ('.root' , '.pdf' )
244+
245+ output_name_rawy_pdf = f"Distr_{ output_name_template } "
246+ output_name_eff_pdf = f"Eff_{ output_name_template } "
247+ output_name_frac_pdf = f"Frac_{ output_name_template } "
248+ output_name_covmat_pdf = f"CovMatrix_{ output_name_template } "
249+ output_name_unc_pdf = f"Unc_{ output_name_template } "
250+ output_name_pdf = f"{ output_name_template } "
216251
217- if hist_rawy [0 ].GetNbinsX () == 1 :
252+ if hist_rawy [0 ].GetNbinsX () == 1 or pt_bin_to_process != - 1 :
218253 print_bracket = ""
219254 elif ipt == 0 :
220255 print_bracket = "("
@@ -227,6 +262,7 @@ def main(config):
227262 canv_frac .Print (f"{ os .path .join (cfg ['output' ]['directory' ], output_name_frac_pdf )} { print_bracket } " )
228263 canv_cov .Print (f"{ os .path .join (cfg ['output' ]['directory' ], output_name_covmat_pdf )} { print_bracket } " )
229264 canv_combined .Print (f"{ os .path .join (cfg ['output' ]['directory' ], output_name_pdf )} { print_bracket } " )
265+ canv_unc .Print (f"{ os .path .join (cfg ['output' ]['directory' ], output_name_unc_pdf )} { print_bracket } " )
230266
231267 output .cd ()
232268 hist_corry_prompt .Write ()
0 commit comments