Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-03-17 10:42:21

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,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_VDrift' % (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_VDriftAll","VDrift",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                 # From cm/ns to micron/ns
0047                 value *= 10000.
0048  
0049                 binHistoNew = (st - 1)*60 + (wh + 2)*nSectors + sec
0050                 if verbose: print("Bin final",binHistoNew)
0051                 histo.SetBinContent(binHistoNew,value) 
0052   
0053                 if sec == 1:
0054                     label = "Wheel %d" % wh
0055                     if wh == -2: label += " MB%d" % st  
0056                     histo.GetXaxis().SetBinLabel(binHistoNew,label) 
0057 
0058     objects = drawHisto(histo,
0059                         title="v_{drift} (#mum/ns)",
0060                         ymin=53,ymax=57,option=option,draw=draw)
0061 
0062     return objects
0063 
0064 def compare(fileNames,sl):
0065     option = "HISTOP"
0066     colors = (2,4,12,44,55)
0067     markers = (24,25,26,27)
0068 
0069     idx = 0
0070     canvas = None
0071     objects = None
0072     histos = []
0073     for fileName in fileNames:
0074         draw = False
0075         if not idx: draw = True
0076 
0077         objs = plot(fileName,sl,option,draw)
0078         if not idx:
0079             canvas = objs[0]
0080             objects = objs[2]
0081         histos.append(objs[1])
0082         
0083         canvas.cd()
0084         if idx:
0085             histos[-1].SetLineColor(colors[ (idx - 1) % len(colors) ])
0086             histos[-1].SetMarkerColor(colors[ (idx - 1) % len(colors) ])
0087             histos[-1].SetMarkerStyle(markers[ (idx - 1) % len(markers) ])
0088 
0089             histos[-1].Draw(option + "SAME")
0090 
0091         idx += 1
0092 
0093     return (canvas,histos,objects)