File indexing completed on 2025-05-29 03:17:17
0001 import ROOT
0002 from .fitResidual import fitResidual
0003 from .drawHistoAllChambers import drawHisto
0004
0005
0006
0007
0008 def plot(fileName,sl,dir='DTResiduals', run='1',option="HISTOPE1",draw=True):
0009
0010 if run in ['390106','390170']:
0011
0012 mean_ymin = -0.15
0013 mean_ymax = 0.15
0014 sig_ymin = 0.
0015 sig_ymax = 0.15
0016 else:
0017 mean_ymin = -0.02
0018 mean_ymax = 0.02
0019 sig_ymin = 0.
0020 sig_ymax = 0.07
0021
0022 slType = sl
0023 slStr = "SL%d" % slType
0024 verbose = False
0025 nSigmas = 2
0026
0027 ROOT.TH1.AddDirectory(False)
0028
0029 file = ROOT.TFile(fileName,'read')
0030
0031 wheels = (-2,-1,0,1,2)
0032 stations = (1,2,3,4)
0033
0034
0035
0036 nBins = 250
0037 if slType == 2: nBins = 180
0038 histoMean = ROOT.TH1F("h_ResMeanAll","Mean of residuals for Run=%s at %s" % (run,slStr),nBins,0,nBins)
0039 histoSigma = ROOT.TH1F("h_ResSigmaAll","Sigma of residuals for Run=%s at %s" % (run,slStr),nBins,0,nBins)
0040 for st in stations:
0041 nSectors = 12
0042 if st == 4: nSectors = 14
0043 if st == 4 and slType == 2: continue
0044 if verbose: print("Station",st)
0045 for wh in wheels:
0046 if verbose: print("Wheel",wh)
0047 for sec in range(1,nSectors+1):
0048 if verbose: print("Sector",sec)
0049
0050 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)
0051 if verbose: print("Accessing",histoName)
0052 histo = file.Get(histoName)
0053 (histo,fitFunc) = fitResidual(histo,nSigmas,verbose)
0054 fitMean = fitFunc.GetParameter(1)
0055 fitMeanErr = fitFunc.GetParError(1)
0056 fitSigma = fitFunc.GetParameter(2)
0057 fitSigmaErr = fitFunc.GetParError(2)
0058
0059 binHistoNew = (st - 1)*60 + (wh + 2)*nSectors + sec
0060 if verbose: print("Bin in summary histo",binHistoNew)
0061 histoMean.SetBinContent(binHistoNew,fitMean)
0062 histoMean.SetBinError(binHistoNew,fitMeanErr)
0063 histoSigma.SetBinContent(binHistoNew,fitSigma)
0064 histoSigma.SetBinError(binHistoNew,fitSigmaErr)
0065
0066 if sec == 1:
0067 label = "Wheel %d" % wh
0068 if wh == -2: label += " MB%d" % st
0069 histoMean.GetXaxis().SetBinLabel(binHistoNew,label)
0070 histoSigma.GetXaxis().SetBinLabel(binHistoNew,label)
0071
0072 objectsMean = drawHisto(histoMean,yaxis_title="Mean of residuals (cm)",
0073 ymin=mean_ymin,ymax=mean_ymax,option=option,draw=draw)
0074 objectsSigma = drawHisto(histoSigma,yaxis_title="Sigma of residuals (cm)",ymin=sig_ymin,ymax=sig_ymax,option=option,draw=draw)
0075
0076
0077 return (objectsMean,objectsSigma)