CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups 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 83 of file plotResidualsPerLayer.py.

References plotResLayer(), print(), and sistrip::SpyUtilities.range().

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

83 
84  dir='DQMData/Run 1/DT/Run summary/DTCalibValidation',type='mean',option='HISTOPE1'):
85  colors = (2,4,12,44,55,38,27,46)
86  markers = (24,25,26,27,28,30,32,5)
87  labels=['Layer 1','Layer 2','Layer 3','Layer 4']
88  idx_type = None
89  if type == 'mean': idx_type = 0
90  elif type == 'sigma': idx_type = 1
91  else: raise RuntimeError("Wrong option: %s" % type)
92 
93  idx = 0
94  canvas = None
95  objects = None
96  histos = []
97  for layer in range(1,5):
98  draw = False
99  if not idx: draw = True
100 
101  objs = plotResLayer(fileName,sl,layer,dir,option,draw)
102  histos.append(objs[idx_type][1])
103  histos[-1].SetName( "%s_%d" % (histos[-1].GetName(),idx) )
104  if not idx:
105  canvas = objs[idx_type][0]
106  objects = objs[idx_type][2]
107 
108  canvas.cd()
109  if idx:
110  histos[-1].SetLineColor(colors[ (idx - 1) % len(colors) ])
111  histos[-1].SetMarkerColor(colors[ (idx - 1) % len(colors) ])
112  histos[-1].SetMarkerStyle(markers[ (idx - 1) % len(markers) ])
113 
114  histos[-1].Draw(option + "SAME")
115 
116  idx += 1
117 
118  legend = ROOT.TLegend(0.4,0.7,0.95,0.8)
119  for idx in range( len(histos) ):
120  histo = histos[idx]
121  label = histo.GetName()
122  if len(labels): label = labels[idx]
123  legend.AddEntry(histo,label,"LP")
124 
125  idx += 1
126 
127  canvas.cd()
128  legend.SetFillColor( canvas.GetFillColor() )
129  legend.Draw("SAME")
130  objects.append(legend)
131 
132  # Compute averages
133  # (Wh-2 MB1 Sec1 ... Wh-2 MB1 Sec12 ... Wh-1 MB1 Sec1 ... Wh-1 MB1 Sec12 ...)
134  # (Wh-2 MB2 Sec1 ... Wh-2 MB2 Sec12 ... Wh-1 MB2 Sec1 ... Wh-1 MB1 Sec12 ...) ...
135  import math
136  wheels = (-2,-1,0,1,2)
137  stations = (1,2,3,4)
138  slType = sl
139  slStr = "SL%d" % slType
140 
141  nBinsAve = len(stations)*len(wheels)
142  histoAverage = ROOT.TH1F("h_AverageAll_" + slStr,"",nBinsAve,0,nBinsAve)
143  averages = {}
144  averagesErr = {}
145  averagesSumw = {}
146  print("Averages:")
147  for st in stations:
148  nSectors = 12
149  if st == 4: nSectors = 14
150  if st == 4 and slType == 2: continue
151  for wh in wheels:
152  binHistoAve = (st - 1)*5 + (wh + 2) + 1
153  label = "Wheel %d" % wh
154  if wh == -2: label += " MB%d" % st
155  histoAverage.GetXaxis().SetBinLabel(binHistoAve,label)
156 
157  averages[(st,wh)] = 0.
158  averagesSumw[(st,wh)] = 0.
159  for sec in range(1,nSectors+1):
160  binHisto = (st - 1)*60 + (wh + 2)*nSectors + sec
161  for idx in range( len(histos) ):
162  histo = histos[idx]
163  value = histo.GetBinContent( binHisto )
164  error = histo.GetBinError( binHisto )
165  averages[(st,wh)] += value/( error*error )
166  averagesSumw[(st,wh)] += 1./( error*error )
167  # Average per (st,wh)
168  averages[(st,wh)] = averages[(st,wh)]/averagesSumw[(st,wh)]
169  averagesErr[(st,wh)] = math.sqrt( 1./averagesSumw[(st,wh)] )
170  histoAverage.SetBinContent(binHistoAve,averages[(st,wh)])
171  histoAverage.SetBinError(binHistoAve,averagesErr[(st,wh)])
172  print("Station %d, Wheel %d: %.4f +/- %.6f" % (st,wh,averages[(st,wh)],averagesErr[(st,wh)]))
173 
174  canvasAverage = ROOT.TCanvas("c_" + histoAverage.GetName())
175  canvasAverage.SetGridx()
176  canvasAverage.SetGridy()
177  canvasAverage.SetFillColor( 0 )
178  canvasAverage.cd()
179  mean_ymin = -0.02
180  mean_ymax = 0.02
181  sig_ymin = 0.
182  sig_ymax = 0.1
183  if type == 'mean':
184  histoAverage.GetYaxis().SetTitle("Mean of residuals (cm)")
185  histoAverage.GetYaxis().SetRangeUser(mean_ymin,mean_ymax)
186  elif type == 'sigma':
187  histoAverage.GetYaxis().SetTitle("Resolution (cm)")
188  histoAverage.GetYaxis().SetRangeUser(sig_ymin,sig_ymax)
189 
190  histoAverage.SetStats(0)
191  histoAverage.SetLineWidth(2)
192  histoAverage.SetMarkerStyle( 27 )
193  histoAverage.SetMarkerSize( 1.5 )
194  histoAverage.LabelsOption("d","X")
195  histoAverage.Draw("E2")
196 
197  return ( (canvas,canvasAverage),(histos,histoAverage),objects )
const uint16_t range(const Frame &aFrame)
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Definition: Utilities.cc:47
def plotResidualsPerLayer.plotFromFile (   fileNames,
  labels = [] 
)

Definition at line 264 of file plotResidualsPerLayer.py.

References hippyaddtobaddatafiles.cd(), and print().

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

Definition at line 198 of file plotResidualsPerLayer.py.

References plot().

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

Definition at line 13 of file plotResidualsPerLayer.py.

References drawHistoAllChambers.drawHisto(), plot(), print(), and sistrip::SpyUtilities.range().

Referenced by plot().

13 
14  option="HISTOPE1",draw=True):
15 
16  mean_ymin = -0.02
17  mean_ymax = 0.02
18  sig_ymin = 0.
19  sig_ymax = 0.1
20 
21  slType = sl
22  slStr = "SL%d" % slType
23  layerType = layer
24  layerStr = "Layer%d" % layerType
25  verbose = False
26  nSigmas = 2
27 
28  ROOT.TH1.AddDirectory(False)
29 
30  file = ROOT.TFile(fileName,'read')
31 
32  wheels = (-2,-1,0,1,2)
33  stations = (1,2,3,4)
34 
35  # (Wh-2 MB1 Sec1 ... Wh-2 MB1 Sec12 ... Wh-1 MB1 Sec1 ... Wh-1 MB1 Sec12 ...)
36  # (Wh-2 MB2 Sec1 ... Wh-2 MB2 Sec12 ... Wh-1 MB2 Sec1 ... Wh-1 MB1 Sec12 ...) ...
37  nBins = 250
38  if slType == 2: nBins = 180
39  histoMean = ROOT.TH1F("h_ResMeanAll_%s_%s" % (slStr,layerStr),"Mean of residuals",nBins,0,nBins)
40  histoSigma = ROOT.TH1F("h_ResSigmaAll_%s_%s" % (slStr,layerStr),"Sigma of residuals",nBins,0,nBins)
41  for st in stations:
42  nSectors = 12
43  if st == 4: nSectors = 14
44  if st == 4 and slType == 2: continue
45  if verbose: print("Station",st)
46  for wh in wheels:
47  if verbose: print("Wheel",wh)
48  for sec in range(1,nSectors+1):
49  if verbose: print("Sector",sec)
50  # Get histogram
51  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)
52  print("Accessing",histoName)
53  histo = file.Get(histoName)
54  (histo,fitFunc) = fitResidual(histo,nSigmas,verbose)
55  fitMean = fitFunc.GetParameter(1)
56  fitMeanErr = fitFunc.GetParError(1)
57  fitSigma = fitFunc.GetParameter(2)
58  fitSigmaErr = fitFunc.GetParError(2)
59 
60  layerIdx = (layer - 1)
61  corrFactor = layerCorrectionFactors[slStr][layerIdx]
62 
63  binHistoNew = (st - 1)*60 + (wh + 2)*nSectors + sec
64  if verbose: print("Bin in summary histo",binHistoNew)
65  histoMean.SetBinContent(binHistoNew,fitMean)
66  histoMean.SetBinError(binHistoNew,fitMeanErr)
67  histoSigma.SetBinContent(binHistoNew,fitSigma*corrFactor)
68  histoSigma.SetBinError(binHistoNew,fitSigmaErr*corrFactor)
69 
70  if sec == 1:
71  label = "Wheel %d" % wh
72  if wh == -2: label += " MB%d" % st
73  histoMean.GetXaxis().SetBinLabel(binHistoNew,label)
74  histoSigma.GetXaxis().SetBinLabel(binHistoNew,label)
75 
76  objectsMean = drawHisto(histoMean,title="Mean of residuals (cm)",
77  ymin=mean_ymin,ymax=mean_ymax,option=option,draw=draw)
78  objectsSigma = drawHisto(histoSigma,title="Resolution (cm)",
79  ymin=sig_ymin,ymax=sig_ymax,option=option,draw=draw)
80 
81  return (objectsMean,objectsSigma)
const uint16_t range(const Frame &aFrame)
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Definition: Utilities.cc:47
def plotResidualsPerLayer.plotSigma (   fileName,
  sl,
  dir = 'DQMData/Run 1/DT/Run summary/DTCalibValidation',
  option = 'HISTOPE1' 
)

Definition at line 203 of file plotResidualsPerLayer.py.

References plot().

Referenced by plotSigmaAll().

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

Definition at line 208 of file plotResidualsPerLayer.py.

References plotSigma(), and sistrip::SpyUtilities.range().

209 def plotSigmaAll(fileName,dir='DQMData/Run 1/DT/Run summary/DTCalibValidation',option='HISTOPE1',outputFileName=''):
210  colors = (2,4,12,44,55,38,27,46)
211  markers = (24,25,26,27,28,30,32,5)
212 
213  slList = (1,2,3)
214  labels = ('R-#phi SL1','R-z SL2','R-#phi SL3')
215  canvas = None
216  objects = None
217  histos = []
218  idx = 0
219  for sl in slList:
220  draw = False
221  if not idx: draw = True
222 
223  objs = plotSigma(fileName,sl,dir,option)
224  histos.append(objs[1][1])
225  histos[-1].SetName( "%s_%d" % (histos[-1].GetName(),idx) )
226  if not idx:
227  canvas = objs[0][1]
228  #objects = objs[2][1]
229 
230  canvas.cd()
231  if idx:
232  histos[-1].SetLineColor(colors[ (idx - 1) % len(colors) ])
233  histos[-1].SetMarkerColor(colors[ (idx - 1) % len(colors) ])
234  histos[-1].SetMarkerStyle(markers[ (idx - 1) % len(markers) ])
235 
236  histos[-1].Draw(option + "SAME")
237 
238  idx += 1
239 
240  legend = ROOT.TLegend(0.4,0.7,0.95,0.8)
241  for idx in range( len(histos) ):
242  histo = histos[idx]
243  label = histo.GetName()
244  if len(labels): label = labels[idx]
245  legend.AddEntry(histo,label,"LP")
246 
247  idx += 1
248 
249  canvas.cd()
250  legend.SetFillColor( canvas.GetFillColor() )
251  legend.Draw("SAME")
252  if not objects: objects = [legend]
253  else: objects.append(legend)
254 
255  if outputFileName:
256  outputFile = ROOT.TFile(outputFileName,'recreate')
257  outputFile.cd()
258  for histo in histos: histo.Write()
259  outputFile.Close()
260  return 0
261  else:
262  return (canvas,histos,objects)
263 
#def plotDataVsMCFromFile(fileNameData,fileNameMC,labels=[]):
const uint16_t range(const Frame &aFrame)

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 7 of file plotResidualsPerLayer.py.