CMS 3D CMS Logo

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