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