1 from __future__
import print_function
3 from fitResidual
import fitResidual
4 from drawHistoAllChambers
import drawHisto
6 layerCorrectionFactors = {
'SL1':(1.17,1.16,1.15,1.14),
7 'SL2':(1.83,1.20,1.20,1.83),
8 'SL3':(1.14,1.15,1.16,1.17)}
11 dir=
'DQMData/Run 1/DT/Run summary/DTCalibValidation',
12 option=
"HISTOPE1",draw=
True):
20 slStr =
"SL%d" % slType
22 layerStr =
"Layer%d" % layerType
26 ROOT.TH1.AddDirectory(
False)
28 file = ROOT.TFile(fileName,
'read')
30 wheels = (-2,-1,0,1,2)
36 if slType == 2: nBins = 180
37 histoMean = ROOT.TH1F(
"h_ResMeanAll_%s_%s" % (slStr,layerStr),
"Mean of residuals",nBins,0,nBins)
38 histoSigma = ROOT.TH1F(
"h_ResSigmaAll_%s_%s" % (slStr,layerStr),
"Sigma of residuals",nBins,0,nBins)
41 if st == 4: nSectors = 14
42 if st == 4
and slType == 2:
continue 43 if verbose:
print(
"Station",st)
45 if verbose:
print(
"Wheel",wh)
46 for sec
in range(1,nSectors+1):
47 if verbose:
print(
"Sector",sec)
49 histoName =
"%s/Wheel%d/Station%d/Sector%d/%s/hResDist_STEP3_W%d_St%d_Sec%d_%s_%s" % (dir,wh,st,sec,slStr,wh,st,sec,slStr,layerStr)
50 print(
"Accessing",histoName)
51 histo = file.Get(histoName)
52 (histo,fitFunc) =
fitResidual(histo,nSigmas,verbose)
53 fitMean = fitFunc.GetParameter(1)
54 fitMeanErr = fitFunc.GetParError(1)
55 fitSigma = fitFunc.GetParameter(2)
56 fitSigmaErr = fitFunc.GetParError(2)
58 layerIdx = (layer - 1)
59 corrFactor = layerCorrectionFactors[slStr][layerIdx]
61 binHistoNew = (st - 1)*60 + (wh + 2)*nSectors + sec
62 if verbose:
print(
"Bin in summary histo",binHistoNew)
63 histoMean.SetBinContent(binHistoNew,fitMean)
64 histoMean.SetBinError(binHistoNew,fitMeanErr)
65 histoSigma.SetBinContent(binHistoNew,fitSigma*corrFactor)
66 histoSigma.SetBinError(binHistoNew,fitSigmaErr*corrFactor)
69 label =
"Wheel %d" % wh
70 if wh == -2: label +=
" MB%d" % st
71 histoMean.GetXaxis().SetBinLabel(binHistoNew,label)
72 histoSigma.GetXaxis().SetBinLabel(binHistoNew,label)
74 objectsMean =
drawHisto(histoMean,title=
"Mean of residuals (cm)",
75 ymin=mean_ymin,ymax=mean_ymax,option=option,draw=draw)
76 objectsSigma =
drawHisto(histoSigma,title=
"Resolution (cm)",
77 ymin=sig_ymin,ymax=sig_ymax,option=option,draw=draw)
79 return (objectsMean,objectsSigma)
82 dir=
'DQMData/Run 1/DT/Run summary/DTCalibValidation',type=
'mean',option=
'HISTOPE1'):
83 colors = (2,4,12,44,55,38,27,46)
84 markers = (24,25,26,27,28,30,32,5)
85 labels=[
'Layer 1',
'Layer 2',
'Layer 3',
'Layer 4']
87 if type ==
'mean': idx_type = 0
88 elif type ==
'sigma': idx_type = 1
89 else:
raise RuntimeError(
"Wrong option: %s" % type)
95 for layer
in range(1,5):
97 if not idx: draw =
True 100 histos.append(objs[idx_type][1])
101 histos[-1].SetName(
"%s_%d" % (histos[-1].GetName(),idx) )
103 canvas = objs[idx_type][0]
104 objects = objs[idx_type][2]
108 histos[-1].SetLineColor(colors[ (idx - 1) % len(colors) ])
109 histos[-1].SetMarkerColor(colors[ (idx - 1) % len(colors) ])
110 histos[-1].SetMarkerStyle(markers[ (idx - 1) % len(markers) ])
112 histos[-1].Draw(option +
"SAME")
116 legend = ROOT.TLegend(0.4,0.7,0.95,0.8)
117 for idx
in range( len(histos) ):
119 label = histo.GetName()
120 if len(labels): label = labels[idx]
121 legend.AddEntry(histo,label,
"LP")
126 legend.SetFillColor( canvas.GetFillColor() )
128 objects.append(legend)
134 wheels = (-2,-1,0,1,2)
137 slStr =
"SL%d" % slType
139 nBinsAve = len(stations)*len(wheels)
140 histoAverage = ROOT.TH1F(
"h_AverageAll_" + slStr,
"",nBinsAve,0,nBinsAve)
147 if st == 4: nSectors = 14
148 if st == 4
and slType == 2:
continue 150 binHistoAve = (st - 1)*5 + (wh + 2) + 1
151 label =
"Wheel %d" % wh
152 if wh == -2: label +=
" MB%d" % st
153 histoAverage.GetXaxis().SetBinLabel(binHistoAve,label)
155 averages[(st,wh)] = 0.
156 averagesSumw[(st,wh)] = 0.
157 for sec
in range(1,nSectors+1):
158 binHisto = (st - 1)*60 + (wh + 2)*nSectors + sec
159 for idx
in range( len(histos) ):
161 value = histo.GetBinContent( binHisto )
162 error = histo.GetBinError( binHisto )
163 averages[(st,wh)] += value/( error*error )
164 averagesSumw[(st,wh)] += 1./( error*error )
166 averages[(st,wh)] = averages[(st,wh)]/averagesSumw[(st,wh)]
167 averagesErr[(st,wh)] = math.sqrt( 1./averagesSumw[(st,wh)] )
168 histoAverage.SetBinContent(binHistoAve,averages[(st,wh)])
169 histoAverage.SetBinError(binHistoAve,averagesErr[(st,wh)])
170 print(
"Station %d, Wheel %d: %.4f +/- %.6f" % (st,wh,averages[(st,wh)],averagesErr[(st,wh)]))
172 canvasAverage = ROOT.TCanvas(
"c_" + histoAverage.GetName())
173 canvasAverage.SetGridx()
174 canvasAverage.SetGridy()
175 canvasAverage.SetFillColor( 0 )
182 histoAverage.GetYaxis().SetTitle(
"Mean of residuals (cm)")
183 histoAverage.GetYaxis().SetRangeUser(mean_ymin,mean_ymax)
184 elif type ==
'sigma':
185 histoAverage.GetYaxis().SetTitle(
"Resolution (cm)")
186 histoAverage.GetYaxis().SetRangeUser(sig_ymin,sig_ymax)
188 histoAverage.SetStats(0)
189 histoAverage.SetLineWidth(2)
190 histoAverage.SetMarkerStyle( 27 )
191 histoAverage.SetMarkerSize( 1.5 )
192 histoAverage.LabelsOption(
"d",
"X")
193 histoAverage.Draw(
"E2")
195 return ( (canvas,canvasAverage),(histos,histoAverage),objects )
197 def plotMean(fileName,sl,dir='DQMData/Run 1/DT/Run summary/DTCalibValidation',option='HISTOPE1'):
199 objs =
plot(fileName,sl,dir,type,option)
202 def plotSigma(fileName,sl,dir='DQMData/Run 1/DT/Run summary/DTCalibValidation',option='HISTOPE1'):
204 objs =
plot(fileName,sl,dir,type,option)
207 def plotSigmaAll(fileName,dir='DQMData/Run 1/DT/Run summary/DTCalibValidation',option='HISTOPE1',outputFileName=''):
208 colors = (2,4,12,44,55,38,27,46)
209 markers = (24,25,26,27,28,30,32,5)
212 labels = (
'R-#phi SL1',
'R-z SL2',
'R-#phi SL3')
219 if not idx: draw =
True 222 histos.append(objs[1][1])
223 histos[-1].SetName(
"%s_%d" % (histos[-1].GetName(),idx) )
230 histos[-1].SetLineColor(colors[ (idx - 1) % len(colors) ])
231 histos[-1].SetMarkerColor(colors[ (idx - 1) % len(colors) ])
232 histos[-1].SetMarkerStyle(markers[ (idx - 1) % len(markers) ])
234 histos[-1].Draw(option +
"SAME")
238 legend = ROOT.TLegend(0.4,0.7,0.95,0.8)
239 for idx
in range( len(histos) ):
241 label = histo.GetName()
242 if len(labels): label = labels[idx]
243 legend.AddEntry(histo,label,
"LP")
248 legend.SetFillColor( canvas.GetFillColor() )
250 if not objects: objects = [legend]
251 else: objects.append(legend)
254 outputFile = ROOT.TFile(outputFileName,
'recreate')
256 for histo
in histos: histo.Write()
260 return (canvas,histos,objects)
265 AddDirectoryStatus_ = ROOT.TH1.AddDirectoryStatus()
266 ROOT.TH1.AddDirectory(
False)
271 for file
in fileNames: rootFiles.append( ROOT.TFile(file,
'read') )
273 variables = [
'h_AverageAll_SL1_0',
274 'h_AverageAll_SL2_1',
275 'h_AverageAll_SL3_2']
277 colors = (1,2,4,12,44,55,38,27,46)
278 markers = (20,24,25,26,27,28,30,32,5)
284 for var
in variables:
285 print(
"Accessing",var)
302 for file
in rootFiles:
303 histos_tmp.append( file.Get(var) )
304 histos_tmp[-1].SetName(
"%s_%d" % (histos_tmp[-1].GetName(),idx) )
305 print(
"Created",histos_tmp[-1].GetName())
306 histos_tmp[-1].SetLineColor(colors[ idx % len(colors) ])
307 histos_tmp[-1].SetMarkerColor(colors[ idx % len(colors) ])
308 histos_tmp[-1].SetMarkerStyle(markers[ idx % len(markers) ])
309 histos_tmp[-1].SetMarkerSize(1.4)
311 histos.append( histos_tmp )
313 canvases.append( ROOT.TCanvas(
"c_" + var,var) )
314 canvases[-1].SetGridx()
315 canvases[-1].SetGridy()
316 canvases[-1].SetFillColor(0)
322 for histo
in histos[-1][1:]: histo.Draw(
"SAME")
327 legends.append( ROOT.TLegend(0.4,0.7,0.95,0.8) )
329 for histo
in histos[-1]:
330 legends[-1].AddEntry(histo,labels[idx],
"LP")
333 legends[-1].SetFillColor( canvases[-1].GetFillColor() )
334 legends[-1].Draw(
"SAME")
338 if not objects: objects = [legends]
339 else: objects.append(legends)
341 ROOT.TH1.AddDirectory(AddDirectoryStatus_)
343 return (canvases,histos,objects)
def plotSigma(fileName, sl, dir='DQMData/Run 1/DT/Run summary/DTCalibValidation', option='HISTOPE1')
S & print(S &os, JobReport::InputFile const &f)
def plotMean(fileName, sl, dir='DQMData/Run 1/DT/Run summary/DTCalibValidation', option='HISTOPE1')
def plotSigmaAll(fileName, dir='DQMData/Run 1/DT/Run summary/DTCalibValidation', option='HISTOPE1', outputFileName='')
def plotFromFile(fileNames, labels=[])
def plot(fileName, sl, dir='DQMData/Run 1/DT/Run summary/DTCalibValidation', type='mean', option='HISTOPE1')
def plotResLayer(fileName, sl, layer, dir='DQMData/Run 1/DT/Run summary/DTCalibValidation', option="HISTOPE1", draw=True)
def drawHisto(histo, title, ymin, ymax, option="HISTOP", draw=True)