13 from ROOT
import TMath, TH1F, TH2F, TProfile
16 def setMaxMin(inputs,maxVal=0,minVal=0,useMax=True,useMin=True):
17 """ This function sets the histogram max/min """
18 assert len(inputs) == 1 , len(inputs)
19 cl = inputs[0][1][0].Clone()
32 void takemax(int sc, const TH2I* inhist, TH2I* outhist) {
33 for (int i = 0; i < outhist->GetSize(); ++i) {
34 if (inhist->At(i) != 0 && sc > outhist->At(i)) {
35 outhist->SetBinContent(i, sc);
42 void clearhist(TH2I* hist) {
43 for (int i = 0; i < hist->GetSize(); ++i) {
44 hist->SetBinContent(i,0);
45 hist->SetBinError(i,0);
51 """ For each bin, fill the output with the max filled error code. All histograms should have the same bin content"""
53 assert len(inputs) >= 1 , len(inputs)
55 cl = inputs[0][1][0].Clone()
56 partition = inputs[0][0][
'part']
57 if 'side' in inputs[0][0]:
58 partition=partition+inputs[0][0][
'side']
60 if 'sampling' in inputs[0][0]:
61 sampling =
int(inputs[0][0][
'sampling'])
66 doFixEmptyBins = (
not isFtSlotPlot
and ((
'EMB' in partition
and sampling==1)
or (
'EMEC' in partition
and sampling==2)
or (
'HEC' in partition)))
69 if len(inputs)==1
and not doFixEmptyBins:
79 for j
in range(1,len(inputs)):
80 if inputs[j][1][0].GetNbinsX()!=Nx:
83 if inputs[j][1][0].GetNbinsY()!=Ny:
87 assert binsok ,
"Histograms must all have the same number of bins"
91 cppyy.gbl.clearhist(cl)
93 statusCode=
int(i[0][
'sc'])
95 cppyy.gbl.takemax(statusCode, h, cl)
101 if(
not doFixEmptyBins):
105 if 'EMBA' in partition:
112 Diphi_toSet = [0,2,3]
113 elif 'EMBC' in partition:
120 Diphi_toSet = [0,1,3]
121 elif 'EMECA' in partition:
128 Diphi_toSet = [0,2,3]
129 elif 'EMECC' in partition:
136 Diphi_toSet = [0,1,3]
138 hecetabinmin=[11,11,9,9]
139 hecetabinmax=[14,13,12,12]
140 if partition==
'HECA':
141 ieta_min = hecetabinmin[sampling]
142 ieta_max = hecetabinmax[sampling]
145 ieta_max = hecetabinmax[sampling]-hecetabinmin[sampling]
155 while iphi<=iphi_max:
157 while ieta<=ieta_max:
158 content = cl.GetBinContent(ieta,iphi+Diphi_toGet)
159 error = cl.GetBinError(ieta,iphi+Diphi_toGet)
160 for Di
in Diphi_toSet:
161 cl.SetBinContent(ieta,iphi+Di,content)
162 cl.SetBinError(ieta,iphi+Di,error)
176 """ This function creates TH2F as ratio of input TH2I and the number of entries of histogram 2 (which is supposed to represent the number of events) """
177 assert len(inputs) == 1 , len(inputs)
178 assert len(inputs[0][1]) == 2 , len(inputs[0][1])
182 cl=
TH2F(inh.GetName(),inh.GetTitle(),inh.GetXaxis().GetNbins(),inh.GetXaxis().GetBinLowEdge(1),inh.GetXaxis().GetBinUpEdge(inh.GetXaxis().GetNbins()), inh.GetYaxis().GetNbins(),inh.GetYaxis().GetBinLowEdge(1),inh.GetYaxis().GetBinUpEdge(inh.GetYaxis().GetNbins()))
184 clx.SetTitle(inh.GetXaxis().GetTitle())
185 cl.GetYaxis().SetTitle(inh.GetYaxis().GetTitle())
189 for xbins
in range(1,cl.GetNbinsX()+1):
190 for ybins
in range(1,cl.GetNbinsY()+1):
191 ibin=inh.GetBin(xbins,ybins)
192 cl.SetBinContent(ibin, 100.*inh.GetBinContent(ibin) / Nen)
195 if titleToReplace==
"":
199 tit=tit.replace(titleToReplace,replaceWith)
207 """ This function normalises histogram 1 to the number of entries of histogram 2 (which is supposed to represent the number of events) and sets the histogram max/min """
209 assert len(inputs) == 1 , len(inputs)
210 assert len(inputs[0][1]) == 2 , len(inputs[0][1])
213 cl = inputs[0][1][0].Clone()
216 cl=
TH2F(inh.GetName()[3:],inh.GetTitle(),inh.GetXaxis().GetNbins(),inh.GetXaxis().GetBinLowEdge(1),inh.GetXaxis().GetBinUpEdge(inh.GetXaxis().GetNbins()), inh.GetYaxis().GetNbins(),inh.GetYaxis().GetBinLowEdge(1),inh.GetYaxis().GetBinUpEdge(inh.GetYaxis().GetNbins()))
217 cl.GetXaxis().SetTitle(inh.GetXaxis().GetTitle())
218 cl.GetYaxis().SetTitle(inh.GetYaxis().GetTitle())
219 for xbins
in range(1,cl.GetNbinsX()+1):
220 for ybins
in range(1,cl.GetNbinsY()+1):
221 ibin=inh.GetBin(xbins,ybins)
222 cl.SetBinContent(ibin, inh.GetBinContent(ibin))
229 cl.SetMinimum(minVal)
231 cl.SetMaximum(maxVal)
234 if titleToReplace==
"":
238 tit=tit.replace(titleToReplace,replaceWith)
243 def normToBinAndSetMinMax(inputs,bin_norm=0,minVal=0,maxVal=0,useMax=False, titleToReplace="",replaceWith="",newYaxis=""):
244 """ This function normalises histogram 1 to the content of bin bin_norm (which is supposed to represent the number of events) and sets the histogram max/min """
246 assert len(inputs) == 1 , len(inputs)
247 assert len(inputs[0][1]) == 1 , len(inputs[0][1])
250 cl=
TH1F(inh.GetName()+
"Yield",inh.GetTitle(),inh.GetNbinsX(),inh.GetBinLowEdge(1),inh.GetBinLowEdge(inh.GetNbinsX()))
252 clx.SetTitle(inh.GetXaxis().GetTitle())
253 for i
in range(1,inh.GetNbinsX()+1):
254 clx.SetBinLabel(i,inh.GetXaxis().GetBinLabel(i))
255 cl.GetYaxis().SetTitle(inh.GetYaxis().GetTitle())
257 Nen = inputs[0][1][0].GetBinContent(bin_norm)
259 for ibin
in range(0,inh.GetNbinsX()+1):
260 cl.SetBinContent(ibin,100.*inh.GetBinContent(ibin)/Nen)
263 cl.SetMinimum(minVal)
265 cl.SetMaximum(maxVal)
269 cl.GetYaxis().SetTitle(newYaxis)
271 if titleToReplace==
"":
275 tit=tit.replace(titleToReplace,replaceWith)
283 """ This function create a new TH1F from ratio of two ROOT histograms """
284 assert len(inputs) == 1
285 assert len(inputs[0][1]) == 2
288 cl=
TH1F(inh.GetName(),inh.GetTitle(),inh.GetNbinsX(),inh.GetBinLowEdge(1),inh.GetBinLowEdge(inh.GetNbinsX()))
290 clx.SetTitle(inh.GetXaxis().GetTitle())
291 cl.GetYaxis().SetTitle(inh.GetYaxis().GetTitle())
293 xbins = inh.GetNbinsX()
294 if inn.GetNbinsX() < xbins: xbins=inn.GetNbinsX()
295 for ibin
in range(1,xbins+1):
296 if inn.GetBinContent(ibin) > 0:
297 cl.SetBinContent(ibin,1.*inh.GetBinContent(ibin)/inn.GetBinContent(ibin))
299 cl.SetBinContent(ibin,1.*inh.GetBinContent(ibin))
301 if titleToReplace==
"":
305 tit=tit.replace(titleToReplace,replaceWith)
313 cl =
TH2F(
"summary",
"LArDigit Summary;Status;Partition",4,0.,4.,8,0.,8.)
315 cl.GetYaxis().SetBinLabel(1,
"EMBC")
316 cl.GetYaxis().SetBinLabel(2,
"EMBA")
317 cl.GetYaxis().SetBinLabel(3,
"EMECC")
318 cl.GetYaxis().SetBinLabel(4,
"EMECA")
319 cl.GetYaxis().SetBinLabel(5,
"HECC")
320 cl.GetYaxis().SetBinLabel(6,
"HECA")
321 cl.GetYaxis().SetBinLabel(7,
"FCalC")
322 cl.GetYaxis().SetBinLabel(8,
"FCalA")
323 cl.GetXaxis().SetBinLabel(1,
"OutOfRange")
324 cl.GetXaxis().SetBinLabel(2,
"Saturation")
325 cl.GetXaxis().SetBinLabel(3,
"Null Digits")
326 cl.GetXaxis().SetBinLabel(4,
"Mean Time")
327 cl.GetXaxis().SetLabelSize(0.055)
328 cl.GetYaxis().SetLabelSize(0.055)
331 assert len(i[1])==1, len(i[1])
350 if i[0][
'side'] ==
"A":
359 for xbin
in range(1,i[1][0].GetNbinsX()+1):
361 for ybin
in range(1,i[1][0].GetNbinsY()+1):
362 sumx=sumx+i[1][0].GetBinContent(xbin,ybin)
364 content=content+(sumx*i[1][0].GetXaxis().GetBinLowEdge(xbin))
368 if "OutOfRange" in hn:
371 elif "Saturation" in hn:
374 elif "NullDigit" in hn:
383 for xbin
in range(i[1][0].GetNbinsX()):
384 for ybin
in range(i[1][0].GetNbinsY()):
385 if i[1][0].GetBinContent(xbin,ybin)>treshold :
393 cl.SetBinContent(ix,iy,content)
403 assert len(inputs)==2 , len(inputs)
405 assert ((inputs[0][0][
'name']==
'average' and inputs[1][0][
'name']==
'partialSum')
or (inputs[1][0][
'name']==
'average' and inputs[0][0][
'name']==
'partialSum')) ,
"Wrong inputs"
407 if inputs[1][0][
'name']==
'partialSum':
414 inh=inputs[i_parSum][1][0]
415 cl=
TH2F(inh.GetName()[3:],inh.GetTitle()[2:12],inh.GetXaxis().GetNbins(),inh.GetXaxis().GetBinLowEdge(1),inh.GetXaxis().GetBinUpEdge(inh.GetXaxis().GetNbins()), inh.GetYaxis().GetNbins(),inh.GetYaxis().GetBinLowEdge(1),inh.GetYaxis().GetBinUpEdge(inh.GetYaxis().GetNbins()))
416 cl.GetXaxis().SetTitle(inh.GetXaxis().GetTitle())
417 cl.GetYaxis().SetTitle(inh.GetYaxis().GetTitle())
419 for i
in range(1,cl.GetNbinsX()+1):
420 mean1 = inputs[i_av][1][0].GetBinContent(i)
421 sumVar1 = inputs[i_parSum][1][0].GetBinContent(i,i)
422 N = inputs[i_av][1][0].GetBinEntries(i)
425 for j
in range(i+1,cl.GetNbinsY()+1):
426 mean2 = inputs[i_av][1][0].GetBinContent(j)
427 sumVar2 = inputs[i_parSum][1][0].GetBinContent(j,j)
428 if (sumVar1-N*mean1*mean1)*(sumVar2-N*mean2*mean2)==0:
430 cor=(inputs[i_parSum][1][0].GetBinContent(i,j)-N*mean1*mean2)/TMath.Sqrt((sumVar1-N*mean1*mean1)*(sumVar2-N*mean2*mean2))
431 cl.SetBinContent(i,j,cor)
432 cl.SetBinContent(j,i,cor)
440 cl =
TProfile(
"summary",
"Summary;Partition;Mean",8,0.,8.,0.,10.,
"s")
442 cl.GetXaxis().SetBinLabel(1,
"EMBA")
443 cl.GetXaxis().SetBinLabel(2,
"EMBC")
444 cl.GetXaxis().SetBinLabel(3,
"EMECA")
445 cl.GetXaxis().SetBinLabel(4,
"EMECC")
446 cl.GetXaxis().SetBinLabel(5,
"HECA")
447 cl.GetXaxis().SetBinLabel(6,
"HECC")
448 cl.GetXaxis().SetBinLabel(7,
"FCalA")
449 cl.GetXaxis().SetBinLabel(8,
"FCalC")
450 cl.GetXaxis().SetLabelSize(0.055)
451 cl.GetYaxis().SetLabelSize(0.055)
454 assert len(i[1])==1, len(i[1])
469 if i[0][
'side'] ==
"C":
479 for xbin
in range(0,i[1][0].GetNbinsX()):
481 if i[1][0].GetBinContent(xbin) > 0.:
482 cl.Fill (ix-1, i[1][0].GetBinContent(xbin))