00001 import ROOT
00002 from drawHistoAllChambers import drawHisto
00003
00004 def binNumber(station,sector):
00005 start = (station - 1)*12
00006 return start + sector
00007
00008 def plot(fileName,sl,ymin=300,ymax=360,option="HISTOP",draw=True):
00009
00010 slType = sl
00011 slStr = "SL%d" % slType
00012 verbose = False
00013
00014 ROOT.TH1.AddDirectory(False)
00015
00016 file = ROOT.TFile(fileName,'read')
00017
00018 wheels = (-2,-1,0,1,2)
00019 stations = (1,2,3,4)
00020
00021 histosWheel = {}
00022 for wh in wheels:
00023 histoName = 'Wheel%d_%s_TTrig' % (wh,slStr)
00024 print "Accessing",histoName
00025 histosWheel[wh] = file.Get(histoName)
00026
00027
00028
00029 nBins = 250
00030 if slType == 2: nBins = 180
00031 histo = ROOT.TH1F("h_TTrigAll","TTrig",nBins,0,nBins)
00032 for st in stations:
00033 nSectors = 12
00034 if st == 4: nSectors = 14
00035 if st == 4 and slType == 2: continue
00036 if verbose: print "Station",st
00037 for wh in wheels:
00038 if verbose: print "Wheel",wh
00039 for sec in range(1,nSectors+1):
00040 if verbose: print "Sector",sec
00041 binHisto = binNumber(st,sec)
00042 if verbose: print "Bin from histos:",binHisto
00043 value = histosWheel[wh].GetBinContent(binHisto)
00044
00045 binHistoNew = (st - 1)*60 + (wh + 2)*nSectors + sec
00046 if verbose: print "Bin final",binHistoNew
00047 histo.SetBinContent(binHistoNew,value)
00048
00049 if sec == 1:
00050 label = "Wheel %d" % wh
00051 if wh == -2: label += " MB%d" % st
00052 histo.GetXaxis().SetBinLabel(binHistoNew,label)
00053
00054 objects = drawHisto(histo,
00055 title="t_{Trig} (ns)",
00056 ymin=ymin,ymax=ymax,option=option,draw=draw)
00057
00058 return objects
00059
00060 def compare(fileNames,sl,ymin=300,ymax=360,labels=[]):
00061 option = "HISTOP"
00062 colors = (2,4,12,44,55,38,27,46)
00063 markers = (24,25,26,27,28,30,32,5)
00064
00065 idx = 0
00066 canvas = None
00067 objects = None
00068 histos = []
00069 for fileName in fileNames:
00070 draw = False
00071 if not idx: draw = True
00072
00073 objs = plot(fileName,sl,ymin,ymax,option,draw)
00074 histos.append(objs[1])
00075 histos[-1].SetName( "%s_%d" % (histos[-1].GetName(),idx) )
00076 if not idx:
00077 canvas = objs[0]
00078 objects = objs[2]
00079
00080 canvas.cd()
00081 if idx:
00082 histos[-1].SetLineColor(colors[ (idx - 1) % len(colors) ])
00083 histos[-1].SetMarkerColor(colors[ (idx - 1) % len(colors) ])
00084 histos[-1].SetMarkerStyle(markers[ (idx - 1) % len(markers) ])
00085
00086 histos[-1].Draw(option + "SAME")
00087
00088 idx += 1
00089
00090 legend = ROOT.TLegend(0.4,0.7,0.95,0.8)
00091 for idx in range( len(histos) ):
00092 histo = histos[idx]
00093 label = histo.GetName()
00094 if len(labels): label = labels[idx]
00095 legend.AddEntry(histo,label,"LP")
00096
00097 idx += 1
00098
00099 canvas.cd()
00100 legend.SetFillColor( canvas.GetFillColor() )
00101 legend.Draw("SAME")
00102
00103 objects.append(legend)
00104
00105 return (canvas,histos,objects)
00106
00107 def compareDiff(fileNames,sl,ymin=-15.,ymax=15.):
00108 option = "HISTOP"
00109 colors = (2,4,9,12,38,44,46,55)
00110 markers = (24,25,26,27,28,30,32,5)
00111
00112 idx = 0
00113 canvases = [None,None]
00114 objects = None
00115 histoRef = None
00116 histos = []
00117 histosDist = []
00118 for fileName in fileNames:
00119 objs = plot(fileName,sl,300,360,'',False)
00120 histos.append( objs[1].Clone(objs[1].GetName() + "_diff") )
00121 histos[-1].SetName( "%s_%d" % (histos[-1].GetName(),idx) )
00122 if not idx:
00123 histoRef = objs[1]
00124 histos[-1].Reset()
00125 else:
00126 histos[-1].Add(histoRef,-1.)
00127
00128 draw = False
00129 if not idx: draw = True
00130
00131 objs = drawHisto(histos[-1],
00132 title="t_{Trig} difference (ns)",
00133 ymin=ymin,ymax=ymax,option=option,draw=draw)
00134
00135 if not idx:
00136 canvases[0] = objs[0]
00137 objects = objs[2]
00138
00139 if idx:
00140 canvases[0].cd()
00141 histos[-1].SetLineColor(colors[ (idx - 1) % len(colors) ])
00142 histos[-1].SetMarkerColor(colors[ (idx - 1) % len(colors) ])
00143 histos[-1].SetMarkerStyle(markers[ (idx - 1) % len(markers) ])
00144
00145 histos[-1].Draw(option + "SAME")
00146
00147 histosDist.append( ROOT.TH1F(histos[-1].GetName() + "_dist","tTrig distribution",200,ymin,ymax) )
00148 for ibin in range(1,histos[-1].GetNbinsX()+1):
00149 histosDist[-1].Fill( histos[-1].GetBinContent(ibin) )
00150
00151 histosDist[-1].SetLineColor(colors[ (idx - 1) % len(colors) ])
00152 histosDist[-1].SetMarkerColor(colors[ (idx - 1) % len(colors) ])
00153 histosDist[-1].SetMarkerStyle(markers[ (idx - 1) % len(markers) ])
00154
00155 idx += 1
00156
00157
00158 canvases[1] = ROOT.TCanvas("c_tTrigDist")
00159 canvases[1].SetGridy()
00160 canvases[1].SetFillColor(0)
00161 canvases[1].cd()
00162 option = "HISTO"
00163 idx = 0
00164 for histo in histosDist:
00165 if not idx:
00166 histo.GetXaxis().SetTitle("t_{Trig} difference (ns)")
00167 histo.GetYaxis().SetTitle("Number of chambers")
00168 histo.Draw(option)
00169 else:
00170 histo.Draw(option + "SAME")
00171 idx += 1
00172
00173 return (canvases,histos,histosDist,objects)