CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Functions
plotTTrigFromHistos Namespace Reference

Functions

def binNumber
 
def compare
 
def compareDiff
 
def plot
 

Function Documentation

def plotTTrigFromHistos.binNumber (   station,
  sector 
)

Definition at line 6 of file plotTTrigFromHistos.py.

Referenced by plot().

6 
7 def binNumber(station,sector):
8  start = (station - 1)*12
9  return start + sector
def plotTTrigFromHistos.compare (   fileNames,
  sl,
  ymin = 300,
  ymax = 360,
  labels = [] 
)

Definition at line 62 of file plotTTrigFromHistos.py.

References plot(), and sistrip::SpyUtilities.range().

62 
63 def compare(fileNames,sl,ymin=300,ymax=360,labels=[]):
64  option = "HISTOP"
65  colors = (2,4,12,44,55,38,27,46)
66  markers = (24,25,26,27,28,30,32,5)
67 
68  idx = 0
69  canvas = None
70  objects = None
71  histos = []
72  for fileName in fileNames:
73  draw = False
74  if not idx: draw = True
75 
76  objs = plot(fileName,sl,ymin,ymax,option,draw)
77  histos.append(objs[1])
78  histos[-1].SetName( "%s_%d" % (histos[-1].GetName(),idx) )
79  if not idx:
80  canvas = objs[0]
81  objects = objs[2]
82 
83  canvas.cd()
84  if idx:
85  histos[-1].SetLineColor(colors[ (idx - 1) % len(colors) ])
86  histos[-1].SetMarkerColor(colors[ (idx - 1) % len(colors) ])
87  histos[-1].SetMarkerStyle(markers[ (idx - 1) % len(markers) ])
88 
89  histos[-1].Draw(option + "SAME")
90 
91  idx += 1
92 
93  legend = ROOT.TLegend(0.4,0.7,0.95,0.8)
94  for idx in range( len(histos) ):
95  histo = histos[idx]
96  label = histo.GetName()
97  if len(labels): label = labels[idx]
98  legend.AddEntry(histo,label,"LP")
99 
100  idx += 1
101 
102  canvas.cd()
103  legend.SetFillColor( canvas.GetFillColor() )
104  legend.Draw("SAME")
105 
106  objects.append(legend)
107 
108  return (canvas,histos,objects)
const uint16_t range(const Frame &aFrame)
def plotTTrigFromHistos.compareDiff (   fileNames,
  sl,
  ymin = -15.,
  ymax = 15. 
)

Definition at line 109 of file plotTTrigFromHistos.py.

References hippyaddtobaddatafiles.cd(), drawHistoAllChambers.drawHisto(), HcalObjRepresent.Fill(), plot(), sistrip::SpyUtilities.range(), and HcalObjRepresent.Reset().

110 def compareDiff(fileNames,sl,ymin=-15.,ymax=15.):
111  option = "HISTOP"
112  colors = (2,4,9,12,38,44,46,55)
113  markers = (24,25,26,27,28,30,32,5)
114 
115  idx = 0
116  canvases = [None,None]
117  objects = None
118  histoRef = None
119  histos = []
120  histosDist = []
121  for fileName in fileNames:
122  objs = plot(fileName,sl,300,360,'',False)
123  histos.append( objs[1].Clone(objs[1].GetName() + "_diff") )
124  histos[-1].SetName( "%s_%d" % (histos[-1].GetName(),idx) )
125  if not idx:
126  histoRef = objs[1]
127  histos[-1].Reset()
128  else:
129  histos[-1].Add(histoRef,-1.)
130 
131  draw = False
132  if not idx: draw = True
133 
134  objs = drawHisto(histos[-1],
135  title="t_{Trig} difference (ns)",
136  ymin=ymin,ymax=ymax,option=option,draw=draw)
137 
138  if not idx:
139  canvases[0] = objs[0]
140  objects = objs[2]
141 
142  if idx:
143  canvases[0].cd()
144  histos[-1].SetLineColor(colors[ (idx - 1) % len(colors) ])
145  histos[-1].SetMarkerColor(colors[ (idx - 1) % len(colors) ])
146  histos[-1].SetMarkerStyle(markers[ (idx - 1) % len(markers) ])
147 
148  histos[-1].Draw(option + "SAME")
149 
150  histosDist.append( ROOT.TH1F(histos[-1].GetName() + "_dist","tTrig distribution",200,ymin,ymax) )
151  for ibin in range(1,histos[-1].GetNbinsX()+1):
152  histosDist[-1].Fill( histos[-1].GetBinContent(ibin) )
153 
154  histosDist[-1].SetLineColor(colors[ (idx - 1) % len(colors) ])
155  histosDist[-1].SetMarkerColor(colors[ (idx - 1) % len(colors) ])
156  histosDist[-1].SetMarkerStyle(markers[ (idx - 1) % len(markers) ])
157 
158  idx += 1
159 
160 
161  canvases[1] = ROOT.TCanvas("c_tTrigDist")
162  canvases[1].SetGridy()
163  canvases[1].SetFillColor(0)
164  canvases[1].cd()
165  option = "HISTO"
166  idx = 0
167  for histo in histosDist:
168  if not idx:
169  histo.GetXaxis().SetTitle("t_{Trig} difference (ns)")
170  histo.GetYaxis().SetTitle("Number of chambers")
171  histo.Draw(option)
172  else:
173  histo.Draw(option + "SAME")
174  idx += 1
175 
176  return (canvases,histos,histosDist,objects)
const uint16_t range(const Frame &aFrame)
void Fill(HcalDetId &id, double val, std::vector< TH2F > &depth)
void Reset(std::vector< TH2F > &depth)
def plotTTrigFromHistos.plot (   fileName,
  sl,
  ymin = 300,
  ymax = 360,
  option = "HISTOP",
  draw = True 
)

Definition at line 10 of file plotTTrigFromHistos.py.

References binNumber(), drawHistoAllChambers.drawHisto(), print(), and sistrip::SpyUtilities.range().

Referenced by compare(), and compareDiff().

10 
11 def plot(fileName,sl,ymin=300,ymax=360,option="HISTOP",draw=True):
12 
13  slType = sl
14  slStr = "SL%d" % slType
15  verbose = False
16 
17  ROOT.TH1.AddDirectory(False)
18 
19  file = ROOT.TFile(fileName,'read')
20 
21  wheels = (-2,-1,0,1,2)
22  stations = (1,2,3,4)
23 
24  histosWheel = {}
25  for wh in wheels:
26  histoName = 'Wheel%d_%s_TTrig' % (wh,slStr)
27  print("Accessing",histoName)
28  histosWheel[wh] = file.Get(histoName)
29 
30  # (Wh-2 MB1 Sec1 ... Wh-2 MB1 Sec12 ... Wh-1 MB1 Sec1 ... Wh-1 MB1 Sec12 ...)
31  # (Wh-2 MB2 Sec1 ... Wh-2 MB2 Sec12 ... Wh-1 MB2 Sec1 ... Wh-1 MB1 Sec12 ...) ...
32  nBins = 250
33  if slType == 2: nBins = 180
34  histo = ROOT.TH1F("h_TTrigAll","TTrig",nBins,0,nBins)
35  for st in stations:
36  nSectors = 12
37  if st == 4: nSectors = 14
38  if st == 4 and slType == 2: continue
39  if verbose: print("Station",st)
40  for wh in wheels:
41  if verbose: print("Wheel",wh)
42  for sec in range(1,nSectors+1):
43  if verbose: print("Sector",sec)
44  binHisto = binNumber(st,sec)
45  if verbose: print("Bin from histos:",binHisto)
46  value = histosWheel[wh].GetBinContent(binHisto)
47 
48  binHistoNew = (st - 1)*60 + (wh + 2)*nSectors + sec
49  if verbose: print("Bin final",binHistoNew)
50  histo.SetBinContent(binHistoNew,value)
51 
52  if sec == 1:
53  label = "Wheel %d" % wh
54  if wh == -2: label += " MB%d" % st
55  histo.GetXaxis().SetBinLabel(binHistoNew,label)
56 
57  objects = drawHisto(histo,
58  title="t_{Trig} (ns)",
59  ymin=ymin,ymax=ymax,option=option,draw=draw)
60 
61  return objects
const uint16_t range(const Frame &aFrame)
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Definition: Utilities.cc:47