CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_0/src/CalibMuon/DTCalibration/python/PlottingTools/plotResiduals.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     mean_ymin = -0.02
00008     mean_ymax =  0.02
00009     sig_ymin = 0.
00010     sig_ymax = 0.07
00011 
00012     slType = sl
00013     slStr = "SL%d" % slType
00014     verbose = False
00015     nSigmas = 2
00016 
00017     ROOT.TH1.AddDirectory(False)
00018 
00019     file = ROOT.TFile(fileName,'read')
00020 
00021     wheels = (-2,-1,0,1,2)
00022     stations = (1,2,3,4)
00023 
00024     # (Wh-2 MB1 Sec1 ... Wh-2 MB1 Sec12 ... Wh-1 MB1 Sec1 ... Wh-1 MB1 Sec12 ...)
00025     # (Wh-2 MB2 Sec1 ... Wh-2 MB2 Sec12 ... Wh-1 MB2 Sec1 ... Wh-1 MB1 Sec12 ...) ...  
00026     nBins = 250
00027     if slType == 2: nBins = 180
00028     histoMean = ROOT.TH1F("h_ResMeanAll","Mean of residuals",nBins,0,nBins)
00029     histoSigma = ROOT.TH1F("h_ResSigmaAll","Sigma of residuals",nBins,0,nBins)
00030     for st in stations:
00031         nSectors = 12
00032         if st == 4: nSectors = 14
00033         if st == 4 and slType == 2: continue 
00034         if verbose: print "Station",st
00035         for wh in wheels:
00036             if verbose: print "Wheel",wh 
00037             for sec in range(1,nSectors+1):
00038                 if verbose: print "Sector",sec
00039                 # Get histogram
00040                 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) 
00041                 print "Accessing",histoName
00042                 histo = file.Get(histoName)
00043                 (histo,fitFunc) = fitResidual(histo,nSigmas,verbose)
00044                 fitMean = fitFunc.GetParameter(1)
00045                 fitMeanErr = fitFunc.GetParError(1)
00046                 fitSigma = fitFunc.GetParameter(2)
00047                 fitSigmaErr = fitFunc.GetParError(2)
00048 
00049                 binHistoNew = (st - 1)*60 + (wh + 2)*nSectors + sec
00050                 if verbose: print "Bin in summary histo",binHistoNew
00051                 histoMean.SetBinContent(binHistoNew,fitMean)
00052                 histoMean.SetBinError(binHistoNew,fitMeanErr)
00053                 histoSigma.SetBinContent(binHistoNew,fitSigma)
00054                 histoSigma.SetBinError(binHistoNew,fitSigmaErr)
00055   
00056                 if sec == 1:
00057                     label = "Wheel %d" % wh
00058                     if wh == -2: label += " MB%d" % st  
00059                     histoMean.GetXaxis().SetBinLabel(binHistoNew,label) 
00060                     histoSigma.GetXaxis().SetBinLabel(binHistoNew,label)
00061 
00062     objectsMean = drawHisto(histoMean,title="Mean of residuals (cm)",
00063                                       ymin=mean_ymin,ymax=mean_ymax,option=option,draw=draw)
00064     objectsSigma = drawHisto(histoSigma,title="Sigma of residuals (cm)",
00065                                         ymin=sig_ymin,ymax=sig_ymax,option=option,draw=draw)
00066 
00067     return (objectsMean,objectsSigma)