1 from __future__
import print_function
2 from __future__
import absolute_import
4 from .drawHistoAllChambers
import drawHisto
7 start = (station - 1)*12
10 def plot(fileName,sl,ymin=300,ymax=360,option="HISTOP",draw=True):
13 slStr =
"SL%d" % slType
16 ROOT.TH1.AddDirectory(
False)
18 file = ROOT.TFile(fileName,
'read')
20 wheels = (-2,-1,0,1,2)
25 histoName =
'Wheel%d_%s_TTrig' % (wh,slStr)
26 print(
"Accessing",histoName)
27 histosWheel[wh] = file.Get(histoName)
32 if slType == 2: nBins = 180
33 histo = ROOT.TH1F(
"h_TTrigAll",
"TTrig",nBins,0,nBins)
36 if st == 4: nSectors = 14
37 if st == 4
and slType == 2:
continue
38 if verbose:
print(
"Station",st)
40 if verbose:
print(
"Wheel",wh)
41 for sec
in range(1,nSectors+1):
42 if verbose:
print(
"Sector",sec)
44 if verbose:
print(
"Bin from histos:",binHisto)
45 value = histosWheel[wh].GetBinContent(binHisto)
47 binHistoNew = (st - 1)*60 + (wh + 2)*nSectors + sec
48 if verbose:
print(
"Bin final",binHistoNew)
49 histo.SetBinContent(binHistoNew,value)
52 label =
"Wheel %d" % wh
53 if wh == -2: label +=
" MB%d" % st
54 histo.GetXaxis().SetBinLabel(binHistoNew,label)
57 title=
"t_{Trig} (ns)",
58 ymin=ymin,ymax=ymax,option=option,draw=draw)
62 def compare(fileNames,sl,ymin=300,ymax=360,labels=[]):
64 colors = (2,4,12,44,55,38,27,46)
65 markers = (24,25,26,27,28,30,32,5)
71 for fileName
in fileNames:
73 if not idx: draw =
True
75 objs =
plot(fileName,sl,ymin,ymax,option,draw)
76 histos.append(objs[1])
77 histos[-1].SetName(
"%s_%d" % (histos[-1].GetName(),idx) )
84 histos[-1].SetLineColor(colors[ (idx - 1) % len(colors) ])
85 histos[-1].SetMarkerColor(colors[ (idx - 1) % len(colors) ])
86 histos[-1].SetMarkerStyle(markers[ (idx - 1) % len(markers) ])
88 histos[-1].Draw(option +
"SAME")
92 legend = ROOT.TLegend(0.4,0.7,0.95,0.8)
93 for idx
in range( len(histos) ):
95 label = histo.GetName()
96 if len(labels): label = labels[idx]
97 legend.AddEntry(histo,label,
"LP")
102 legend.SetFillColor( canvas.GetFillColor() )
105 objects.append(legend)
107 return (canvas,histos,objects)
111 colors = (2,4,9,12,38,44,46,55)
112 markers = (24,25,26,27,28,30,32,5)
115 canvases = [
None,
None]
120 for fileName
in fileNames:
121 objs =
plot(fileName,sl,300,360,
'',
False)
122 histos.append( objs[1].Clone(objs[1].GetName() +
"_diff") )
123 histos[-1].SetName(
"%s_%d" % (histos[-1].GetName(),idx) )
128 histos[-1].Add(histoRef,-1.)
131 if not idx: draw =
True
134 title=
"t_{Trig} difference (ns)",
135 ymin=ymin,ymax=ymax,option=option,draw=draw)
138 canvases[0] = objs[0]
143 histos[-1].SetLineColor(colors[ (idx - 1) % len(colors) ])
144 histos[-1].SetMarkerColor(colors[ (idx - 1) % len(colors) ])
145 histos[-1].SetMarkerStyle(markers[ (idx - 1) % len(markers) ])
147 histos[-1].Draw(option +
"SAME")
149 histosDist.append( ROOT.TH1F(histos[-1].GetName() +
"_dist",
"tTrig distribution",200,ymin,ymax) )
150 for ibin
in range(1,histos[-1].GetNbinsX()+1):
151 histosDist[-1].
Fill( histos[-1].GetBinContent(ibin) )
153 histosDist[-1].SetLineColor(colors[ (idx - 1) % len(colors) ])
154 histosDist[-1].SetMarkerColor(colors[ (idx - 1) % len(colors) ])
155 histosDist[-1].SetMarkerStyle(markers[ (idx - 1) % len(markers) ])
160 canvases[1] = ROOT.TCanvas(
"c_tTrigDist")
161 canvases[1].SetGridy()
162 canvases[1].SetFillColor(0)
166 for histo
in histosDist:
168 histo.GetXaxis().SetTitle(
"t_{Trig} difference (ns)")
169 histo.GetYaxis().SetTitle(
"Number of chambers")
172 histo.Draw(option +
"SAME")
175 return (canvases,histos,histosDist,objects)