11 ROOT.gROOT.ProcessLine(
".x ~/atlasstyle/AtlasStyle.C")
16old_filename =
"/home/turra/simon/latest_simon.root"
17old_file = ROOT.TFile.Open(old_filename)
18old_scale_histogram = old_file.Get(
"Scales/es2012c/alphaZee_errStat")
19old_ct_histogram = old_file.Get(
"Resolution/es2012c/ctZee_errStat")
20old_scale_sys = old_file.Get(
"Scales/es2012c/alphaZee_errSyst")
21old_ct_sys = old_file.Get(
"Resolution/es2012c/ctZee_errSyst")
23assert old_scale_histogram
24assert old_ct_histogram
28file_christophe = ROOT.TFile(
"~/ElectronEnergyScaleFactor.root")
29scales_christophe = file_christophe.Get(
"alpha68")
30ct_christophe = file_christophe.Get(
"sigma24")
32scales_sys_christophe = file_christophe.Get(
"systAlpha")
33ct_sys_christophe = file_christophe.Get(
"systSigma")
35assert scales_christophe
37assert scales_sys_christophe
38assert ct_sys_christophe
42 new_histo = histo1.Clone()
44 for ibin
in range(histo1.GetNbinsX() + 2):
45 value1 = histo1.GetBinContent(ibin)
46 central_value = histo1.GetBinCenter(ibin)
47 ibin2 = histo2.FindBin(central_value)
48 value2 = histo2.GetBinContent(ibin2)
49 new_value = np.sqrt(value1 * value1 + value2 * value2)
50 new_histo.SetBinContent(ibin, new_value)
55 """ avoid bin with value == 0 """
56 empty_bins_in_transition =
set()
58 bin = histo.FindBin(eta)
59 if (histo.GetBinContent(bin) == 0):
60 empty_bins_in_transition.add(bin)
61 assert len(empty_bins_in_transition) == 1
62 empty_bin = list(empty_bins_in_transition)[0]
64 assert(histo_scale.GetBinContent(empty_bin - 1) != 0)
65 histo.SetBinContent(empty_bin, histo.GetBinContent(empty_bin - 1))
66 histo.SetBinError(empty_bin, histo.GetBinError(empty_bin - 1))
68 assert(histo_scale.GetBinContent(empty_bin + 1) != 0)
69 histo.SetBinContent(empty_bin, histo.GetBinContent(empty_bin + 1))
70 histo.SetBinError(empty_bin, histo.GetBinError(empty_bin + 1))
75 savdir = ROOT.gDirectory
78 for key
in source.GetListOfKeys():
79 classname = key.GetClassName()
80 cl = ROOT.gROOT.GetClass(classname)
83 if (cl.InheritsFrom(ROOT.TDirectory.Class())):
84 d = destination.mkdir(key.GetName())
85 copy_dir(source.GetDirectory(key.GetName()), d)
87 elif (cl.InheritsFrom(ROOT.TTree.Class())):
88 T = source.Get(key.GetName())
90 newT = T.CloneTree(-1,
"fast")
92 elif (cl.InheritsFrom(ROOT.TList.Class())):
96 obj.Write(obj.GetName(), ROOT.TObject.kSingleKey)
105 destination.SaveSelf(
True)
110 output_file = ROOT.TFile(path,
"recreate")
111 output_file.mkdir(
"Scales")
112 output_file.mkdir(
"Resolution")
113 output_file.mkdir(
"PSRecalibration")
114 output_file.mkdir(
"S1Recalibration")
119 output_file.Get(
"Scales").mkdir(
"es2015PRE")
120 output_file.Get(
"Resolution").mkdir(
"es2015PRE")
121 output_file.Get(
"PSRecalibration").mkdir(
"es2015PRE")
122 output_file.Get(
"S1Recalibration").mkdir(
"es2015PRE")
130 OVERFLOW = new.GetNbinsX() + 1
132 for iold
in range(1, old.GetNbinsX()):
133 low = old.GetBinLowEdge(iold)
134 r = low + old.GetBinWidth(iold)
136 il_new = new.FindFixBin(low)
137 ir_new = new.FindFixBin(r)
140 if il_new == UNDERFLOW
and ir_new == UNDERFLOW:
141 new_binning.append((low, r))
142 new_values.append(old.GetBinContent(iold))
143 new_errors.append(old.GetBinError(iold))
145 elif il_new == UNDERFLOW
and ir_new > UNDERFLOW
and ir_new < OVERFLOW:
146 if abs(new.GetBinLowEdge(1) - low) < 1E-100:
148 new_binning.append((low, new.GetBinLowEdge(1)))
149 new_values.append(old.GetBinContent(iold))
150 new_errors.append(old.GetBinError(iold))
151 if ir_new == OVERFLOW:
156 for inew
in range(1, new.GetNbinsX() + 1):
157 low = new.GetBinLowEdge(inew)
158 r = low + new.GetBinWidth(inew)
159 new_binning.append((low, r))
160 new_values.append(new.GetBinContent(inew))
161 new_errors.append(new.GetBinError(inew))
163 if remainer
is not None:
164 new_binning.append((new.GetBinLowEdge(new.GetNbinsX()),
165 old.GetBinLowEdge(remainer)
166 + old.GetBinWidth(remainer)))
167 new_values.append(old.GetBinContent(remainer))
168 new_errors.append(old.GetBinError(remainer))
170 for iold
in range(last_old, old.GetNbinsX() + 1):
171 low = old.GetBinLowEdge(iold)
172 r = low + old.GetBinWidth(iold)
174 il_new = new.FindFixBin(low)
175 ir_new = new.FindFixBin(r)
177 if il_new == OVERFLOW
and ir_new == OVERFLOW:
178 new_binning.append((low, r))
179 new_values.append(old.GetBinContent(iold))
180 new_errors.append(old.GetBinError(iold))
181 elif il_new < OVERFLOW
and ir_new == OVERFLOW:
182 if abs(new.GetBinLowEdge(new.GetNbinsX() + 1) - r) < 1E-100:
184 new_binning.append((new.GetBinLowEdge(new.GetNbinsX() + 1), r))
185 new_values.append(old.GetBinContent(iold))
186 new_errors.append(old.GetBinError(iold))
188 new_edges =
array(
'f', [x[0]
for x
in new_binning] + [new_binning[-1][1]])
189 histo_type =
type(new)
190 result = histo_type(new.GetName(), new.GetTitle(),
191 len(new_edges) - 1, new_edges)
192 for i, (v, e)
in enumerate(zip(new_values, new_errors), 1):
193 result.SetBinContent(i, v)
195 result.SetBinError(i, e)
203copy_bin(histo_scale, np.arange(2, 2.7, 0.001))
204copy_bin(histo_scale, np.arange(-2.7, -2, 0.001))
206copy_bin(histo_ct, np.arange(2, 2.7, 0.001))
207copy_bin(histo_ct, np.arange(-2.7, -2, 0.001))
210histo_scale.SetTitle(
"Zee energy scale factor - es2015 prerecommendation")
211histo_ct.SetTitle(
"Zee additional constant term - es2015 prerecommendation")
213for h
in histo_scale, histo_ct:
214 h.SetMarkerColor(ROOT.kBlack)
217canvas1 = ROOT.TCanvas()
219old_scale_histogram.Draw(
"sameL")
220scales_christophe.Draw(
"sameL")
222canvas2 = ROOT.TCanvas()
224old_ct_histogram.Draw(
"sameL")
225ct_christophe.Draw(
"sameL")
227histo_scale.SetName(
"alphaZee_errStat")
228histo_ct.SetName(
"ctZee_errStat")
233shutil.copy2(old_filename,
"xxx.root")
234output_file = ROOT.TFile(
"xxx.root",
"update")
237output_file.GetDirectory(
"Scales").GetDirectory(
238 "es2015PRE").WriteObject(histo_scale,
"alphaZee_errStat")
239output_file.GetDirectory(
"Resolution").GetDirectory(
240 "es2015PRE").WriteObject(histo_ct,
"ctZee_errStat")
248new_scale_sys.SetTitle(
249 "es2015PRE scales sys = es2012c sys + 7/13 TeV diff + 34/68 bin diff")
250new_ct_sys.SetTitle(
"es2015 ct sys = es2012c sys + 7/13 TeV diff")
251output_file.GetDirectory(
"Scales").GetDirectory(
252 "es2015PRE").WriteObject(new_scale_sys,
"alphaZee_errSyst")
253output_file.GetDirectory(
"Resolution").GetDirectory(
254 "es2015PRE").WriteObject(new_ct_sys,
"ctZee_errSyst")
256legend3 = ROOT.TLegend(0.6, 0.7, 0.9, 0.9)
257legend3.SetBorderSize(0)
258canvas3 = ROOT.TCanvas()
259old_scale_sys.GetXaxis().SetTitle(
"#eta")
260old_scale_sys.GetYaxis().SetTitle(
"scale systematics")
261old_scale_sys.SetLineColor(ROOT.kRed)
263scales_sys_christophe.SetLineColor(ROOT.kBlue)
264scales_sys_christophe.Draw(
"same")
265new_scale_sys.Draw(
"same")
266legend3.AddEntry(scales_sys_christophe,
"8/13 TeV diff + 34/68 bin diff",
"L")
267legend3.AddEntry(old_scale_sys,
"2012c systematics",
"L")
268legend3.AddEntry(new_scale_sys,
"sum (2015PRE)",
"L")
271legend4 = ROOT.TLegend(0.6, 0.7, 0.9, 0.9)
272legend4.SetBorderSize(0)
273canvas4 = ROOT.TCanvas()
274old_ct_sys.GetXaxis().SetTitle(
"#eta")
275old_ct_sys.GetYaxis().SetTitle(
"ct systematics")
276old_ct_sys.SetLineColor(ROOT.kRed)
278ct_sys_christophe.SetLineColor(ROOT.kBlue)
279ct_sys_christophe.Draw(
"same")
280new_ct_sys.Draw(
"same")
281legend4.AddEntry(ct_sys_christophe,
"8/13 TeV diff",
"L")
282legend4.AddEntry(old_ct_sys,
"2012c systematics",
"L")
283legend4.AddEntry(new_ct_sys,
"sum (2015PRE)",
"L")
288stefano_file = ROOT.TFile(
"egammaEnergyCorrectionDataMC15.root")
289copy_dir(stefano_file.GetDirectory(
"PSRecalibration"),
290 output_file.GetDirectory(
"PSRecalibration").GetDirectory(
"es2015PRE"))
291copy_dir(stefano_file.GetDirectory(
"S1Recalibration"),
292 output_file.GetDirectory(
"S1Recalibration").GetDirectory(
"es2015PRE"))
296f_ua2mev = ROOT.TFile.Open(
"~/uA2MeV.root")
297histo_ua2mev = f_ua2mev.Get(
"histo_uA2MeV_week12")
298output_file.Get(
"Scales").
Get(
"es2015PRE").WriteTObject(histo_ua2mev)
void print(char *figname, TCanvas *c1)
T * Get(TFile &f, const std::string &n, const std::string &dir="", const chainmap_t *chainmap=0, std::vector< std::string > *saved=0)
get a histogram given a path, and an optional initial directory if histogram is not found,...