Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:47:43

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