CMS 3D CMS Logo

plotResidualsCosmics.py
Go to the documentation of this file.
1 from __future__ import print_function
2 from __future__ import absolute_import
3 import ROOT
4 from .fitResidual import fitResidual
5 from .drawHistoAllChambers import drawHisto
6 
7 def plot(fileName,sl,dir='DQMData/Run 1/DT/Run summary/DTCalibValidation',option="HISTOPE1",draw=True):
8 
9  slType = sl
10  slStr = "SL%d" % slType
11  verbose = False
12  nSigmas = 2
13 
14  ROOT.TH1.AddDirectory(False)
15 
16  file = ROOT.TFile(fileName,'read')
17 
18  wheels = (-2,-1,0,1,2)
19  stations = (1,2,3,4)
20 
21  # (Wh-2 MB1 Sec1 ... Wh-2 MB1 Sec12 ... Wh-1 MB1 Sec1 ... Wh-1 MB1 Sec12 ...)
22  # (Wh-2 MB2 Sec1 ... Wh-2 MB2 Sec12 ... Wh-1 MB2 Sec1 ... Wh-1 MB1 Sec12 ...) ...
23  nBins = 250
24  if slType == 2: nBins = 180
25  histoMean = ROOT.TH1F("h_ResMeanAll","Mean of residuals",nBins,0,nBins)
26  histoSigma = ROOT.TH1F("h_ResSigmaAll","Sigma of residuals",nBins,0,nBins)
27  for st in stations:
28  nSectors = 12
29  if st == 4: nSectors = 14
30  if st == 4 and slType == 2: continue
31  if verbose: print("Station",st)
32  for wh in wheels:
33  if verbose: print("Wheel",wh)
34  for sec in range(1,nSectors+1):
35  if verbose: print("Sector",sec)
36  # Get histogram
37  histoName = "%s/Wheel%d/Station%d/Sector%d/hResDist_STEP3_W%d_St%d_Sec%d_%s" % (dir,wh,st,sec,wh,st,sec,slStr)
38  print("Accessing",histoName)
39  histo = file.Get(histoName)
40  (histo,fitFunc) = fitResidual(histo,nSigmas,verbose)
41  fitMean = fitFunc.GetParameter(1)
42  fitMeanErr = fitFunc.GetParError(1)
43  fitSigma = fitFunc.GetParameter(2)
44  fitSigmaErr = fitFunc.GetParError(2)
45 
46  binHistoNew = (st - 1)*60 + (wh + 2)*nSectors + sec
47  if verbose: print("Bin in summary histo",binHistoNew)
48  histoMean.SetBinContent(binHistoNew,fitMean)
49  histoMean.SetBinError(binHistoNew,fitMeanErr)
50  histoSigma.SetBinContent(binHistoNew,fitSigma)
51  histoSigma.SetBinError(binHistoNew,fitSigmaErr)
52 
53  if sec == 1:
54  label = "Wheel %d" % wh
55  if wh == -2: label += " MB%d" % st
56  histoMean.GetXaxis().SetBinLabel(binHistoNew,label)
57  histoSigma.GetXaxis().SetBinLabel(binHistoNew,label)
58 
59  objectsMean = drawHisto(histoMean,title="Mean of residuals (cm)",
60  ymin=-0.1,ymax=0.1,option=option,draw=draw)
61  objectsSigma = drawHisto(histoSigma,title="Sigma of residuals (cm)",
62  ymin=0.,ymax=0.15,option=option,draw=draw)
63 
64  return (objectsMean,objectsSigma)
FastTimerService_cff.range
range
Definition: FastTimerService_cff.py:34
fitResidual
Definition: fitResidual.py:1
plotResidualsCosmics.plot
def plot(fileName, sl, dir='DQMData/Run 1/DT/Run summary/DTCalibValidation', option="HISTOPE1", draw=True)
Definition: plotResidualsCosmics.py:7
print
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Definition: Utilities.cc:46
drawHistoAllChambers.drawHisto
def drawHisto(histo, title, ymin, ymax, option="HISTOP", draw=True)
Definition: drawHistoAllChambers.py:3