Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-08-15 22:40:12

0001 from __future__ import print_function
0002 from __future__ import absolute_import
0003 import ROOT
0004 from .drawHistoAllChambers import drawHisto
0005 
0006 def binNumber(station,sl):
0007     if sl == 3 and station == 4: return 11
0008     if sl == 2 and station == 4: return None
0009     start = (station - 1)*3
0010     return start + sl
0011 
0012 def plot(fileName,sl,run,ymin=-5,ymax=5,option="HISTOP",draw=True):
0013     path = "DQMData/Run "+str(run)+"/DT/Run summary/DtCalib/TTrigDBValidation/"
0014     slType = sl
0015     slStr = "SL%d" % slType
0016     verbose = True #False
0017 
0018     ROOT.TH1.AddDirectory(False)
0019 
0020     file = ROOT.TFile(fileName,'read')
0021 
0022     wheels = (-2,-1,0,1,2)
0023     stations = (1,2,3,4)
0024 
0025     #histosWheel = {}
0026     #for wh in wheels:
0027     #    histoName = path+'Wheel%d_%s_TTrig' % (wh,slStr)
0028     #    print "Accessing",histoName
0029     #    histosWheel[wh] = file.Get(histoName)
0030 
0031     # (Wh-2 MB1 Sec1 ... Wh-2 MB1 Sec12 ... Wh-1 MB1 Sec1 ... Wh-1 MB1 Sec12 ...)
0032     # (Wh-2 MB2 Sec1 ... Wh-2 MB2 Sec12 ... Wh-1 MB2 Sec1 ... Wh-1 MB1 Sec12 ...) ...  
0033     nBins = 250
0034     #if slType == 2: nBins = 180
0035     histo = ROOT.TH1F("h_TTrigAll","TTrig Run "+str(run),nBins,0,nBins)
0036     for st in stations:
0037         nSectors = 12
0038         if st == 4: nSectors = 14 
0039         if st == 4 and sl == 2: continue
0040         if verbose: print("Station",st)
0041         for wh in wheels:
0042             if verbose: print("Wheel",wh) 
0043             for sec in range(1,nSectors+1):
0044                 if verbose: print("Sector",sec)
0045                 binHisto = binNumber(st,sl)
0046                 if verbose: print("Bin from histos:",binHisto) 
0047                 histoName = path+'Wheel%d/TTrigDifference_W%d_Sec%d' % (wh,wh,sec)
0048                 value = file.Get(histoName).GetBinContent(binHisto)
0049 
0050                 binHistoNew = (st - 1)*60 + (wh + 2)*nSectors + sec
0051                 if verbose: print("Bin final",binHistoNew,value)
0052                 histo.SetBinContent(binHistoNew,value) 
0053 
0054                 if sec == 1:
0055                     label = "Wheel %d" % wh
0056                     if wh == -2: label += " MB%d" % st  
0057                     histo.GetXaxis().SetBinLabel(binHistoNew,label) 
0058 
0059     objects = drawHisto(histo,
0060                         title="#Deltat_{Trig} (ns)",
0061                         ymin=ymin,ymax=ymax,option=option,draw=draw)
0062 
0063     return objects
0064 
0065 def SLcompare(fileName,sls,run,ymin=-5,ymax=5,labels=[]):
0066     option = "HISTOP"
0067     colors = (2,4,12,44,55,38,27,46)
0068     markers = (24,25,26,27,28,30,32,5)
0069 
0070     idx = 0
0071     canvas = None
0072     objects = None
0073     histos = []
0074     for sl in sls:
0075         draw = False
0076         if not idx: draw = True
0077 
0078         objs = plot(fileName,sl,run,ymin,ymax,option,draw)
0079         histos.append(objs[1])
0080         histos[-1].SetName( "SL %d" % sl) 
0081         if not idx:
0082             canvas = objs[0]
0083             objects = objs[2]
0084 
0085         canvas.cd()
0086         if idx:
0087             histos[-1].SetLineColor(colors[ (idx - 1) % len(colors) ])
0088             histos[-1].SetMarkerColor(colors[ (idx - 1) % len(colors) ])
0089             histos[-1].SetMarkerStyle(markers[ (idx - 1) % len(markers) ])
0090 
0091             histos[-1].Draw(option + "SAME")
0092 
0093         idx += 1
0094 
0095     legend = ROOT.TLegend(0.4,0.7,0.95,0.8)
0096     for idx in range( len(histos) ):
0097         histo = histos[idx]
0098         label = histo.GetName()
0099         if len(labels): label = labels[idx]
0100         legend.AddEntry(histo,label,"LP")
0101 
0102         idx += 1
0103 
0104     canvas.cd()
0105     legend.SetFillColor( canvas.GetFillColor() )
0106     legend.Draw("SAME")
0107 
0108     objects.append(legend)
0109 
0110     return (canvas,histos,objects)
0111 
0112 def compareDiff(fileNames,sl,ymin=-15.,ymax=15.):
0113     option = "HISTOP"
0114     colors = (2,4,9,12,38,44,46,55)
0115     markers = (24,25,26,27,28,30,32,5)
0116 
0117     idx = 0
0118     canvases = [None,None]
0119     objects = None
0120     histoRef = None
0121     histos = []
0122     histosDist = []
0123     for fileName in fileNames:
0124         objs = plot(fileName,sl,300,360,'',False)
0125         histos.append( objs[1].Clone(objs[1].GetName() + "_diff") )
0126         histos[-1].SetName( "%s_%d" % (histos[-1].GetName(),idx) )
0127         if not idx:
0128             histoRef = objs[1]
0129             histos[-1].Reset()
0130         else:
0131             histos[-1].Add(histoRef,-1.) 
0132 
0133         draw = False
0134         if not idx: draw = True
0135 
0136         objs = drawHisto(histos[-1],
0137                          title="t_{Trig} difference (ns)",
0138                          ymin=ymin,ymax=ymax,option=option,draw=draw)
0139 
0140         if not idx: 
0141             canvases[0] = objs[0]
0142             objects = objs[2]
0143 
0144         if idx:
0145             canvases[0].cd()
0146             histos[-1].SetLineColor(colors[ (idx - 1) % len(colors) ])
0147             histos[-1].SetMarkerColor(colors[ (idx - 1) % len(colors) ])
0148             histos[-1].SetMarkerStyle(markers[ (idx - 1) % len(markers) ])
0149 
0150             histos[-1].Draw(option + "SAME")
0151 
0152             histosDist.append( ROOT.TH1F(histos[-1].GetName() + "_dist","tTrig distribution",200,ymin,ymax) )
0153             for ibin in range(1,histos[-1].GetNbinsX()+1):
0154                 histosDist[-1].Fill( histos[-1].GetBinContent(ibin) )
0155 
0156             histosDist[-1].SetLineColor(colors[ (idx - 1) % len(colors) ])
0157             histosDist[-1].SetMarkerColor(colors[ (idx - 1) % len(colors) ])
0158             histosDist[-1].SetMarkerStyle(markers[ (idx - 1) % len(markers) ])
0159 
0160         idx += 1
0161 
0162 
0163     canvases[1] = ROOT.TCanvas("c_tTrigDist")
0164     canvases[1].SetGridy()
0165     canvases[1].SetFillColor(0)
0166     canvases[1].cd()
0167     option = "HISTO"
0168     idx = 0
0169     for histo in histosDist:
0170         if not idx:
0171             histo.GetXaxis().SetTitle("t_{Trig} difference (ns)")
0172             histo.GetYaxis().SetTitle("Number of chambers")
0173             histo.Draw(option)
0174         else:
0175             histo.Draw(option + "SAME") 
0176         idx += 1
0177 
0178     return (canvases,histos,histosDist,objects)