Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-11-25 02:29:08

0001 import ROOT
0002 from .drawHistoAllChambers import drawHisto
0003 
0004 def binNumber(station,sector):
0005     start = (station - 1)*12
0006     return start + sector
0007  
0008 def plot(fileName,sl,option="HISTOP",draw=True):
0009 
0010     slType = sl
0011     slStr = "SL%d" % slType
0012     verbose = False
0013 
0014     ROOT.TH1.AddDirectory(False)
0015 
0016     file = ROOT.TFile(fileName,'read')
0017 
0018     wheels = (-2,-1,0,1,2)
0019     stations = (1,2,3,4)
0020 
0021     histosWheel = {}
0022     for wh in wheels:
0023         histoName = 'Wheel%d_%s_VDrift' % (wh,slStr)
0024         print("Accessing",histoName)
0025         histosWheel[wh] = file.Get(histoName)
0026 
0027     # (Wh-2 MB1 Sec1 ... Wh-2 MB1 Sec12 ... Wh-1 MB1 Sec1 ... Wh-1 MB1 Sec12 ...)
0028     # (Wh-2 MB2 Sec1 ... Wh-2 MB2 Sec12 ... Wh-1 MB2 Sec1 ... Wh-1 MB1 Sec12 ...) ...  
0029     nBins = 250
0030     if slType == 2: nBins = 180
0031     histo = ROOT.TH1F("h_VDriftAll","VDrift",nBins,0,nBins)
0032     for st in stations:
0033         nSectors = 12
0034         if st == 4: nSectors = 14 
0035         if st == 4 and slType == 2: continue 
0036         if verbose: print("Station",st)
0037         for wh in wheels:
0038             if verbose: print("Wheel",wh) 
0039             for sec in range(1,nSectors+1):
0040                 if verbose: print("Sector",sec)
0041                 binHisto = binNumber(st,sec)
0042                 if verbose: print("Bin from histos:",binHisto) 
0043                 value = histosWheel[wh].GetBinContent(binHisto)
0044                 # From cm/ns to micron/ns
0045                 value *= 10000.
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="v_{drift} (#mum/ns)",
0058                         ymin=53,ymax=57,option=option,draw=draw)
0059 
0060     return objects
0061 
0062 def compare(fileNames,sl):
0063     option = "HISTOP"
0064     colors = (2,4,12,44,55)
0065     markers = (24,25,26,27)
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,option,draw)
0076         if not idx:
0077             canvas = objs[0]
0078             objects = objs[2]
0079         histos.append(objs[1])
0080         
0081         canvas.cd()
0082         if idx:
0083             histos[-1].SetLineColor(colors[ (idx - 1) % len(colors) ])
0084             histos[-1].SetMarkerColor(colors[ (idx - 1) % len(colors) ])
0085             histos[-1].SetMarkerStyle(markers[ (idx - 1) % len(markers) ])
0086 
0087             histos[-1].Draw(option + "SAME")
0088 
0089         idx += 1
0090 
0091     return (canvas,histos,objects)