File indexing completed on 2024-11-25 02:29:08
0001 import ROOT
0002 from .drawHistoAllChambers import drawHisto
0003
0004 def binNumber(station,sl):
0005 if sl == 3 and station == 4: return 11
0006 if sl == 2 and station == 4: return None
0007 start = (station - 1)*3
0008 return start + sl
0009
0010 def plot(fileName,sl,run,ymin=-5,ymax=5,option="HISTOP",draw=True):
0011 path = "DQMData/Run "+str(run)+"/DT/Run summary/DtCalib/TTrigDBValidation/"
0012 slType = sl
0013 slStr = "SL%d" % slType
0014 verbose = True
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
0024
0025
0026
0027
0028
0029
0030
0031 nBins = 250
0032
0033 histo = ROOT.TH1F("h_TTrigAll","TTrig Run "+str(run),nBins,0,nBins)
0034 for st in stations:
0035 nSectors = 12
0036 if st == 4: nSectors = 14
0037 if st == 4 and sl == 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,sl)
0044 if verbose: print("Bin from histos:",binHisto)
0045 histoName = path+'Wheel%d/TTrigDifference_W%d_Sec%d' % (wh,wh,sec)
0046 value = file.Get(histoName).GetBinContent(binHisto)
0047
0048 binHistoNew = (st - 1)*60 + (wh + 2)*nSectors + sec
0049 if verbose: print("Bin final",binHistoNew,value)
0050 histo.SetBinContent(binHistoNew,value)
0051
0052 if sec == 1:
0053 label = "Wheel %d" % wh
0054 if wh == -2: label += " MB%d" % st
0055 histo.GetXaxis().SetBinLabel(binHistoNew,label)
0056
0057 objects = drawHisto(histo,
0058 title="#Deltat_{Trig} (ns)",
0059 ymin=ymin,ymax=ymax,option=option,draw=draw)
0060
0061 return objects
0062
0063 def SLcompare(fileName,sls,run,ymin=-5,ymax=5,labels=[]):
0064 option = "HISTOP"
0065 colors = (2,4,12,44,55,38,27,46)
0066 markers = (24,25,26,27,28,30,32,5)
0067
0068 idx = 0
0069 canvas = None
0070 objects = None
0071 histos = []
0072 for sl in sls:
0073 draw = False
0074 if not idx: draw = True
0075
0076 objs = plot(fileName,sl,run,ymin,ymax,option,draw)
0077 histos.append(objs[1])
0078 histos[-1].SetName( "SL %d" % sl)
0079 if not idx:
0080 canvas = objs[0]
0081 objects = objs[2]
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 legend = ROOT.TLegend(0.4,0.7,0.95,0.8)
0094 for idx in range( len(histos) ):
0095 histo = histos[idx]
0096 label = histo.GetName()
0097 if len(labels): label = labels[idx]
0098 legend.AddEntry(histo,label,"LP")
0099
0100 idx += 1
0101
0102 canvas.cd()
0103 legend.SetFillColor( canvas.GetFillColor() )
0104 legend.Draw("SAME")
0105
0106 objects.append(legend)
0107
0108 return (canvas,histos,objects)
0109
0110 def compareDiff(fileNames,sl,ymin=-15.,ymax=15.):
0111 option = "HISTOP"
0112 colors = (2,4,9,12,38,44,46,55)
0113 markers = (24,25,26,27,28,30,32,5)
0114
0115 idx = 0
0116 canvases = [None,None]
0117 objects = None
0118 histoRef = None
0119 histos = []
0120 histosDist = []
0121 for fileName in fileNames:
0122 objs = plot(fileName,sl,300,360,'',False)
0123 histos.append( objs[1].Clone(objs[1].GetName() + "_diff") )
0124 histos[-1].SetName( "%s_%d" % (histos[-1].GetName(),idx) )
0125 if not idx:
0126 histoRef = objs[1]
0127 histos[-1].Reset()
0128 else:
0129 histos[-1].Add(histoRef,-1.)
0130
0131 draw = False
0132 if not idx: draw = True
0133
0134 objs = drawHisto(histos[-1],
0135 title="t_{Trig} difference (ns)",
0136 ymin=ymin,ymax=ymax,option=option,draw=draw)
0137
0138 if not idx:
0139 canvases[0] = objs[0]
0140 objects = objs[2]
0141
0142 if idx:
0143 canvases[0].cd()
0144 histos[-1].SetLineColor(colors[ (idx - 1) % len(colors) ])
0145 histos[-1].SetMarkerColor(colors[ (idx - 1) % len(colors) ])
0146 histos[-1].SetMarkerStyle(markers[ (idx - 1) % len(markers) ])
0147
0148 histos[-1].Draw(option + "SAME")
0149
0150 histosDist.append( ROOT.TH1F(histos[-1].GetName() + "_dist","tTrig distribution",200,ymin,ymax) )
0151 for ibin in range(1,histos[-1].GetNbinsX()+1):
0152 histosDist[-1].Fill( histos[-1].GetBinContent(ibin) )
0153
0154 histosDist[-1].SetLineColor(colors[ (idx - 1) % len(colors) ])
0155 histosDist[-1].SetMarkerColor(colors[ (idx - 1) % len(colors) ])
0156 histosDist[-1].SetMarkerStyle(markers[ (idx - 1) % len(markers) ])
0157
0158 idx += 1
0159
0160
0161 canvases[1] = ROOT.TCanvas("c_tTrigDist")
0162 canvases[1].SetGridy()
0163 canvases[1].SetFillColor(0)
0164 canvases[1].cd()
0165 option = "HISTO"
0166 idx = 0
0167 for histo in histosDist:
0168 if not idx:
0169 histo.GetXaxis().SetTitle("t_{Trig} difference (ns)")
0170 histo.GetYaxis().SetTitle("Number of chambers")
0171 histo.Draw(option)
0172 else:
0173 histo.Draw(option + "SAME")
0174 idx += 1
0175
0176 return (canvases,histos,histosDist,objects)