CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_2_7_hltpatch2/src/CalibMuon/DTCalibration/python/PlottingTools/plotResidualsCosmics.py

Go to the documentation of this file.
00001 import ROOT
00002 from fitResidual import fitResidual
00003 from drawHistoAllChambers import drawHisto
00004 
00005 def plot(fileName,sl,dir='DQMData/Run 1/DT/Run summary/DTCalibValidation',option="HISTOPE1",draw=True):
00006 
00007     slType = sl
00008     slStr = "SL%d" % slType
00009     verbose = False
00010     nSigmas = 2
00011 
00012     ROOT.TH1.AddDirectory(False)
00013 
00014     file = ROOT.TFile(fileName,'read')
00015 
00016     wheels = (-2,-1,0,1,2)
00017     stations = (1,2,3,4)
00018 
00019     # (Wh-2 MB1 Sec1 ... Wh-2 MB1 Sec12 ... Wh-1 MB1 Sec1 ... Wh-1 MB1 Sec12 ...)
00020     # (Wh-2 MB2 Sec1 ... Wh-2 MB2 Sec12 ... Wh-1 MB2 Sec1 ... Wh-1 MB1 Sec12 ...) ...  
00021     nBins = 250
00022     if slType == 2: nBins = 180
00023     histoMean = ROOT.TH1F("h_ResMeanAll","Mean of residuals",nBins,0,nBins)
00024     histoSigma = ROOT.TH1F("h_ResSigmaAll","Sigma of residuals",nBins,0,nBins)
00025     for st in stations:
00026         nSectors = 12
00027         if st == 4: nSectors = 14
00028         if st == 4 and slType == 2: continue 
00029         if verbose: print "Station",st
00030         for wh in wheels:
00031             if verbose: print "Wheel",wh 
00032             for sec in range(1,nSectors+1):
00033                 if verbose: print "Sector",sec
00034                 # Get histogram
00035                 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) 
00036                 print "Accessing",histoName
00037                 histo = file.Get(histoName)
00038                 (histo,fitFunc) = fitResidual(histo,nSigmas,verbose)
00039                 fitMean = fitFunc.GetParameter(1)
00040                 fitMeanErr = fitFunc.GetParError(1)
00041                 fitSigma = fitFunc.GetParameter(2)
00042                 fitSigmaErr = fitFunc.GetParError(2)
00043 
00044                 binHistoNew = (st - 1)*60 + (wh + 2)*nSectors + sec
00045                 if verbose: print "Bin in summary histo",binHistoNew
00046                 histoMean.SetBinContent(binHistoNew,fitMean)
00047                 histoMean.SetBinError(binHistoNew,fitMeanErr)
00048                 histoSigma.SetBinContent(binHistoNew,fitSigma)
00049                 histoSigma.SetBinError(binHistoNew,fitSigmaErr)  
00050 
00051                 if sec == 1:
00052                     label = "Wheel %d" % wh
00053                     if wh == -2: label += " MB%d" % st  
00054                     histoMean.GetXaxis().SetBinLabel(binHistoNew,label) 
00055                     histoSigma.GetXaxis().SetBinLabel(binHistoNew,label)
00056 
00057     objectsMean = drawHisto(histoMean,title="Mean of residuals (cm)",
00058                                       ymin=-0.1,ymax=0.1,option=option,draw=draw)
00059     objectsSigma = drawHisto(histoSigma,title="Sigma of residuals (cm)",
00060                                       ymin=0.,ymax=0.15,option=option,draw=draw)
00061 
00062     return (objectsMean,objectsSigma)