CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Functions | Variables
plotResidualsPerLayer Namespace Reference

Functions

def plot
 
def plotFromFile
 
def plotMean
 
def plotResLayer
 
def plotSigma
 
def plotSigmaAll
 

Variables

dictionary layerCorrectionFactors
 

Function Documentation

def plotResidualsPerLayer.plot (   fileName,
  sl,
  dir = 'DQMData/Run 1/DT/Run summary/DTCalibValidation',
  type = 'mean',
  option = 'HISTOPE1' 
)

Definition at line 81 of file plotResidualsPerLayer.py.

References plotResLayer().

Referenced by plotMean(), plotResLayer(), and plotSigma().

81 
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']
86  idx_type = None
87  if type == 'mean': idx_type = 0
88  elif type == 'sigma': idx_type = 1
89  else: raise RuntimeError, "Wrong option: %s" % type
90 
91  idx = 0
92  canvas = None
93  objects = None
94  histos = []
95  for layer in range(1,5):
96  draw = False
97  if not idx: draw = True
98 
99  objs = plotResLayer(fileName,sl,layer,dir,option,draw)
100  histos.append(objs[idx_type][1])
101  histos[-1].SetName( "%s_%d" % (histos[-1].GetName(),idx) )
102  if not idx:
103  canvas = objs[idx_type][0]
104  objects = objs[idx_type][2]
105 
106  canvas.cd()
107  if idx:
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) ])
111 
112  histos[-1].Draw(option + "SAME")
113 
114  idx += 1
115 
116  legend = ROOT.TLegend(0.4,0.7,0.95,0.8)
117  for idx in range( len(histos) ):
118  histo = histos[idx]
119  label = histo.GetName()
120  if len(labels): label = labels[idx]
121  legend.AddEntry(histo,label,"LP")
122 
123  idx += 1
124 
125  canvas.cd()
126  legend.SetFillColor( canvas.GetFillColor() )
127  legend.Draw("SAME")
128  objects.append(legend)
129 
130  # Compute averages
131  # (Wh-2 MB1 Sec1 ... Wh-2 MB1 Sec12 ... Wh-1 MB1 Sec1 ... Wh-1 MB1 Sec12 ...)
132  # (Wh-2 MB2 Sec1 ... Wh-2 MB2 Sec12 ... Wh-1 MB2 Sec1 ... Wh-1 MB1 Sec12 ...) ...
133  import math
134  wheels = (-2,-1,0,1,2)
135  stations = (1,2,3,4)
136  slType = sl
137  slStr = "SL%d" % slType
138 
139  nBinsAve = len(stations)*len(wheels)
140  histoAverage = ROOT.TH1F("h_AverageAll_" + slStr,"",nBinsAve,0,nBinsAve)
141  averages = {}
142  averagesErr = {}
143  averagesSumw = {}
144  print "Averages:"
145  for st in stations:
146  nSectors = 12
147  if st == 4: nSectors = 14
148  if st == 4 and slType == 2: continue
149  for wh in wheels:
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)
154 
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) ):
160  histo = histos[idx]
161  value = histo.GetBinContent( binHisto )
162  error = histo.GetBinError( binHisto )
163  averages[(st,wh)] += value/( error*error )
164  averagesSumw[(st,wh)] += 1./( error*error )
165  # Average per (st,wh)
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)])
171 
172  canvasAverage = ROOT.TCanvas("c_" + histoAverage.GetName())
173  canvasAverage.SetGridx()
174  canvasAverage.SetGridy()
175  canvasAverage.SetFillColor( 0 )
176  canvasAverage.cd()
177  mean_ymin = -0.02
178  mean_ymax = 0.02
179  sig_ymin = 0.
180  sig_ymax = 0.1
181  if type == 'mean':
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)
187 
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")
194 
195  return ( (canvas,canvasAverage),(histos,histoAverage),objects )
def plotResidualsPerLayer.plotFromFile (   fileNames,
  labels = [] 
)

Definition at line 262 of file plotResidualsPerLayer.py.

263 def plotFromFile(fileNames,labels=[]):
264 
265  AddDirectoryStatus_ = ROOT.TH1.AddDirectoryStatus()
266  ROOT.TH1.AddDirectory(False)
267 
268  #fileData = ROOT.TFile(fileNameData,'read')
269  #fileMC = ROOT.TFile(fileNameMC,'read')
270  rootFiles = []
271  for file in fileNames: rootFiles.append( ROOT.TFile(file,'read') )
272 
273  variables = ['h_AverageAll_SL1_0',
274  'h_AverageAll_SL2_1',
275  'h_AverageAll_SL3_2']
276 
277  colors = (1,2,4,12,44,55,38,27,46)
278  markers = (20,24,25,26,27,28,30,32,5)
279  objects = None
280  canvases = []
281  legends = []
282  histos = []
283  idx_var = 0
284  for var in variables:
285  print "Accessing",var
286  #histoData = fileData.Get(var)
287  #histoData.SetName(histoData.GetName() + "_data")
288  #histoMC = fileMC.Get(var)
289  #histoMC.SetName(histoMC.GetName() + "_mc")
290  #histoData.SetLineColor(1)
291  #histoData.SetMarkerStyle(20)
292  #histoData.SetMarkerSize(1.4)
293  #histoData.SetMarkerColor(1)
294 
295  #histoMC.SetLineColor(2)
296  #histoMC.SetMarkerStyle(24)
297  #histoMC.SetMarkerSize(1.4)
298  #histoMC.SetMarkerColor(2)
299 
300  histos_tmp = []
301  idx = 0
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)
310  idx += 1
311  histos.append( histos_tmp )
312 
313  canvases.append( ROOT.TCanvas("c_" + var,var) )
314  canvases[-1].SetGridx()
315  canvases[-1].SetGridy()
316  canvases[-1].SetFillColor(0)
317  canvases[-1].cd()
318  #histoData.Draw()
319  #histoMC.Draw("SAME")
320  #histos.append( (histoData,histoMC) )
321  histos[-1][0].Draw()
322  for histo in histos[-1][1:]: histo.Draw("SAME")
323 
324  if len(labels):
325  #labelData = labels[0]
326  #labelMC = labels[1]
327  legends.append( ROOT.TLegend(0.4,0.7,0.95,0.8) )
328  idx = 0
329  for histo in histos[-1]:
330  legends[-1].AddEntry(histo,labels[idx],"LP")
331  idx += 1
332 
333  legends[-1].SetFillColor( canvases[-1].GetFillColor() )
334  legends[-1].Draw("SAME")
335 
336  idx_var += 1
337 
338  if not objects: objects = [legends]
339  else: objects.append(legends)
340 
341  ROOT.TH1.AddDirectory(AddDirectoryStatus_)
342 
343  return (canvases,histos,objects)
def plotResidualsPerLayer.plotMean (   fileName,
  sl,
  dir = 'DQMData/Run 1/DT/Run summary/DTCalibValidation',
  option = 'HISTOPE1' 
)

Definition at line 196 of file plotResidualsPerLayer.py.

References plot().

197 def plotMean(fileName,sl,dir='DQMData/Run 1/DT/Run summary/DTCalibValidation',option='HISTOPE1'):
198  type = 'mean'
199  objs = plot(fileName,sl,dir,type,option)
200  return objs
def plotResidualsPerLayer.plotResLayer (   fileName,
  sl,
  layer,
  dir = 'DQMData/Run 1/DT/Run summary/DTCalibValidation',
  option = "HISTOPE1",
  draw = True 
)

Definition at line 11 of file plotResidualsPerLayer.py.

References drawHistoAllChambers.drawHisto(), and plot().

Referenced by plot().

11 
12  option="HISTOPE1",draw=True):
13 
14  mean_ymin = -0.02
15  mean_ymax = 0.02
16  sig_ymin = 0.
17  sig_ymax = 0.1
18 
19  slType = sl
20  slStr = "SL%d" % slType
21  layerType = layer
22  layerStr = "Layer%d" % layerType
23  verbose = False
24  nSigmas = 2
25 
26  ROOT.TH1.AddDirectory(False)
27 
28  file = ROOT.TFile(fileName,'read')
29 
30  wheels = (-2,-1,0,1,2)
31  stations = (1,2,3,4)
32 
33  # (Wh-2 MB1 Sec1 ... Wh-2 MB1 Sec12 ... Wh-1 MB1 Sec1 ... Wh-1 MB1 Sec12 ...)
34  # (Wh-2 MB2 Sec1 ... Wh-2 MB2 Sec12 ... Wh-1 MB2 Sec1 ... Wh-1 MB1 Sec12 ...) ...
35  nBins = 250
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)
39  for st in stations:
40  nSectors = 12
41  if st == 4: nSectors = 14
42  if st == 4 and slType == 2: continue
43  if verbose: print "Station",st
44  for wh in wheels:
45  if verbose: print "Wheel",wh
46  for sec in range(1,nSectors+1):
47  if verbose: print "Sector",sec
48  # Get histogram
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)
57 
58  layerIdx = (layer - 1)
59  corrFactor = layerCorrectionFactors[slStr][layerIdx]
60 
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)
67 
68  if sec == 1:
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)
73 
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)
78 
79  return (objectsMean,objectsSigma)
def plotResidualsPerLayer.plotSigma (   fileName,
  sl,
  dir = 'DQMData/Run 1/DT/Run summary/DTCalibValidation',
  option = 'HISTOPE1' 
)

Definition at line 201 of file plotResidualsPerLayer.py.

References plot().

Referenced by plotSigmaAll().

202 def plotSigma(fileName,sl,dir='DQMData/Run 1/DT/Run summary/DTCalibValidation',option='HISTOPE1'):
203  type = 'sigma'
204  objs = plot(fileName,sl,dir,type,option)
205  return objs
def plotResidualsPerLayer.plotSigmaAll (   fileName,
  dir = 'DQMData/Run 1/DT/Run summary/DTCalibValidation',
  option = 'HISTOPE1',
  outputFileName = '' 
)

Definition at line 206 of file plotResidualsPerLayer.py.

References plotSigma().

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)
210 
211  slList = (1,2,3)
212  labels = ('R-#phi SL1','R-z SL2','R-#phi SL3')
213  canvas = None
214  objects = None
215  histos = []
216  idx = 0
217  for sl in slList:
218  draw = False
219  if not idx: draw = True
220 
221  objs = plotSigma(fileName,sl,dir,option)
222  histos.append(objs[1][1])
223  histos[-1].SetName( "%s_%d" % (histos[-1].GetName(),idx) )
224  if not idx:
225  canvas = objs[0][1]
226  #objects = objs[2][1]
227 
228  canvas.cd()
229  if 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) ])
233 
234  histos[-1].Draw(option + "SAME")
235 
236  idx += 1
237 
238  legend = ROOT.TLegend(0.4,0.7,0.95,0.8)
239  for idx in range( len(histos) ):
240  histo = histos[idx]
241  label = histo.GetName()
242  if len(labels): label = labels[idx]
243  legend.AddEntry(histo,label,"LP")
244 
245  idx += 1
246 
247  canvas.cd()
248  legend.SetFillColor( canvas.GetFillColor() )
249  legend.Draw("SAME")
250  if not objects: objects = [legend]
251  else: objects.append(legend)
252 
253  if outputFileName:
254  outputFile = ROOT.TFile(outputFileName,'recreate')
255  outputFile.cd()
256  for histo in histos: histo.Write()
257  outputFile.Close()
258  return 0
259  else:
260  return (canvas,histos,objects)
261 
#def plotDataVsMCFromFile(fileNameData,fileNameMC,labels=[]):

Variable Documentation

dictionary plotResidualsPerLayer.layerCorrectionFactors
Initial value:
1 = {'SL1':(1.17,1.16,1.15,1.14),
2  'SL2':(1.83,1.20,1.20,1.83),
3  'SL3':(1.14,1.15,1.16,1.17)}

Definition at line 5 of file plotResidualsPerLayer.py.