CMS 3D CMS Logo

plotResiduals.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  mean_ymin = -0.02
10  mean_ymax = 0.02
11  sig_ymin = 0.
12  sig_ymax = 0.07
13 
14  slType = sl
15  slStr = "SL%d" % slType
16  verbose = False
17  nSigmas = 2
18 
19  ROOT.TH1.AddDirectory(False)
20 
21  file = ROOT.TFile(fileName,'read')
22 
23  wheels = (-2,-1,0,1,2)
24  stations = (1,2,3,4)
25 
26  # (Wh-2 MB1 Sec1 ... Wh-2 MB1 Sec12 ... Wh-1 MB1 Sec1 ... Wh-1 MB1 Sec12 ...)
27  # (Wh-2 MB2 Sec1 ... Wh-2 MB2 Sec12 ... Wh-1 MB2 Sec1 ... Wh-1 MB1 Sec12 ...) ...
28  nBins = 250
29  if slType == 2: nBins = 180
30  histoMean = ROOT.TH1F("h_ResMeanAll","Mean of residuals",nBins,0,nBins)
31  histoSigma = ROOT.TH1F("h_ResSigmaAll","Sigma of residuals",nBins,0,nBins)
32  for st in stations:
33  nSectors = 12
34  if st == 4: nSectors = 14
35  if st == 4 and slType == 2: continue
36  if verbose: print("Station",st)
37  for wh in wheels:
38  if verbose: print("Wheel",wh)
39  for sec in range(1,nSectors+1):
40  if verbose: print("Sector",sec)
41  # Get histogram
42  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)
43  print("Accessing",histoName)
44  histo = file.Get(histoName)
45  (histo,fitFunc) = fitResidual(histo,nSigmas,verbose)
46  fitMean = fitFunc.GetParameter(1)
47  fitMeanErr = fitFunc.GetParError(1)
48  fitSigma = fitFunc.GetParameter(2)
49  fitSigmaErr = fitFunc.GetParError(2)
50 
51  binHistoNew = (st - 1)*60 + (wh + 2)*nSectors + sec
52  if verbose: print("Bin in summary histo",binHistoNew)
53  histoMean.SetBinContent(binHistoNew,fitMean)
54  histoMean.SetBinError(binHistoNew,fitMeanErr)
55  histoSigma.SetBinContent(binHistoNew,fitSigma)
56  histoSigma.SetBinError(binHistoNew,fitSigmaErr)
57 
58  if sec == 1:
59  label = "Wheel %d" % wh
60  if wh == -2: label += " MB%d" % st
61  histoMean.GetXaxis().SetBinLabel(binHistoNew,label)
62  histoSigma.GetXaxis().SetBinLabel(binHistoNew,label)
63 
64  objectsMean = drawHisto(histoMean,title="Mean of residuals (cm)",
65  ymin=mean_ymin,ymax=mean_ymax,option=option,draw=draw)
66  objectsSigma = drawHisto(histoSigma,title="Sigma of residuals (cm)",
67  ymin=sig_ymin,ymax=sig_ymax,option=option,draw=draw)
68 
69  return (objectsMean,objectsSigma)
S & print(S &os, JobReport::InputFile const &f)
Definition: JobReport.cc:66
def drawHisto(histo, title, ymin, ymax, option="HISTOP", draw=True)
def plot(fileName, sl, dir='DQMData/Run 1/DT/Run summary/DTCalibValidation', option="HISTOPE1", draw=True)
Definition: plotResiduals.py:7