ATLAS Offline Software
check_samples_cis.py
Go to the documentation of this file.
1 #!/bin/env python
2 # Author: Michael Miller (miller@uchicago.edu)
3 
4 import os, struct, sys
5 import time
6 import pickle
7 import ROOT
8 from aux_functions import *
9 
10 def readModule(part, mod, runnumber, datadir, outdir):
11 
12  ROOT.gROOT.SetBatch()
13  print 'Checking', part, mod
14 
15  filename = '%stiletb_%d_CIS.%s%02d.0.aan.root' % (datadir, runnumber, part, mod)
16 
17  partnames = ['LBA', 'LBC', 'EBA', 'EBC']
18  partmap = {'LBA': 'A', 'LBC': 'C', 'EBA': 'D', 'EBC': 'E'}
19 
20  histoshg = [ROOT.TH1F('%s MOD %02d PMT %02d HG' % (part, mod, int(pmt + 1)), '%02d' % (int(pmt + 1)), 7, 1, 8) for pmt in range(48)]
21  histoslg = [ROOT.TH1F('%s MOD %02d PMT %02d LG' % (part, mod, int(pmt + 1)), '%02d' % (int(pmt + 1)), 7, 1, 8) for pmt in range(48)]
22 
23  entrieshg = [0 for pmt in range(48)]
24  entrieslg = [0 for pmt in range(48)]
25 
26  for list in [histoshg, histoslg]:
27  for hist in list:
28  hist.GetXaxis().CenterLabels(ROOT.kTRUE)
29  hist = cleanHisto(hist)
30 
31 
32  if os.path.exists(filename):
33  print 'Using', filename
34  file = ROOT.TFile.Open(filename)
35  if file and not file.IsZombie():
36  tree = file.Get('h1000')
37  nevents = tree.GetEntries()
38  #nevents = 100 # for testing
39 
40  for ev in range(1, nevents):
41 
42  tree.GetEntry(ev)
43 
44  pha = tree.m_cispar[5]
45  dac = tree.m_cispar[6]
46  cap = tree.m_cispar[7]
47  if pha!=0 or cap!=100:
48  continue
49  if dac==7:
50  for pmt in range(48):
51  sampleshg = getattr(tree, 'sample%s%02dhi' % (partmap[part], mod))
52  for samp in range(7):
53  histoshg[pmt].Fill(samp+1, sampleshg[pmt*9+samp])
54  entrieshg[pmt] = entrieshg[pmt] + 1
55  if dac==128:
56  for pmt in range(48):
57  sampleslg = getattr(tree, 'sample%s%02dlo' % (partmap[part], mod))
58  for samp in range(7):
59  histoslg[pmt].Fill(samp+1, sampleslg[pmt*9+samp])
60  entrieslg[pmt] = entrieslg[pmt] + 1
61 
62 
63  for pmt in range(48):
64  if entrieshg[pmt]==0:
65  continue
66  factor = 1./float(entrieshg[pmt])
67  histoshg[pmt].Scale(factor)
68 
69  for pmt in range(48):
70  if entrieslg[pmt]==0:
71  continue
72  factor = 1./float(entrieslg[pmt])
73  histoslg[pmt].Scale(factor)
74 
75 
76  for histo in histoshg:
77  histo, color = checkSamples(histo)
78 
79  for histo in histoslg:
80  histo, color = checkSamples(histo)
81 
82 
83  saveHistos(histoshg, part, mod, 'hg', runnumber, outdir)
84  saveHistos(histoslg, part, mod, 'lg', runnumber, outdir)
85  file.Close()
86 
87 
88 def checkSamples(histo):
89 
90  maxval = 0
91  maxvalsamp = 0
92 
93  color = 'null'
94 
95  for bin in range(1, histo.GetXaxis().GetNbins()):
96  val = histo.GetBinContent(bin)
97  if val > maxval:
98  maxval = val
99  maxvalsamp = bin
100 
101  if maxvalsamp==4:
102  histo.SetFillColor(ROOT.kGreen)
103  color = 'green'
104  elif maxvalsamp==3 or maxvalsamp==5:
105  histo.SetFillColor(ROOT.kYellow)
106  color = 'yellow'
107  elif maxvalsamp==1 or maxvalsamp==2 or maxvalsamp==6 or maxvalsamp==7:
108  histo.SetFillColor(ROOT.kRed)
109  color = 'red'
110 
111  return histo, color
112 
113 
114 def saveHistos(histos, part, mod, gain, runnumber, outdir):
115 
116 
117 
118  partnames = ['LBA', 'LBC', 'EBA', 'EBC']
119 
120  can = SetupDraw()
121  can.Divide(1,1)
122 
123  if gain == 'hg':
124  gn = 'HG'
125  elif gain == 'lg':
126  gn = 'LG'
127 
128  toptitle = ROOT.TLatex(0.42, 0.9, '%s %02d %s' % (part, mod, gn))
129  toptitle.SetTextSize(0.05)
130  toptitle.SetNDC()
131  toptitle.SetTextAlign(12)
132 
133  can.Divide(8,7)
134 
135  for hist in histos:
136  if gain == 'hg':
137  hist.SetMaximum(500)
138  elif gain == 'lg':
139  hist.SetMaximum(200)
140  can.cd(histos.index(hist)+8+1)
141  pmt = int(hist.GetTitle())
142  if pmt == '':
143  continue
144  if checkPMTValid(partnames.index(part), pmt-1)=='noninst':
145  continue
146 
147  if hist!=0:
148  hist.Draw()
149  can.Modified()
150  can.Update()
151 
152  can.Modified()
153 
154  can.cd(0)
155  toptitle.Draw()
156  can.Modified()
157  can.Update()
158 
159  pickfile = open('%s%s%02d%s.dat' % (outdir, part, mod, gain), 'w')
160  pickle.dump(can, pickfile)
161  pickfile.close()
162 
163 
164 def getPMTTex(pmt):
165 
166  pave = ROOT.TPaveText(0.7, 0.6, 0.9, 0.95)
167  pave.AddText(pmt)
168  pave.SetFillColor(0)
169 
170  pave.SetBorderSize(1)
171  pave.SetTextSize(0.15)
172  pave.SetTextAlign(12)
173 
174  return pave
175 
176 def cleanHisto(hist):
177 
178  hist.GetXaxis().CenterTitle()
179  hist.GetXaxis().SetTitleOffset(1.4)
180  hist.GetXaxis().SetLabelOffset(0.021)
181  hist.GetXaxis().SetLabelSize(0.06)
182  hist.GetYaxis().CenterTitle()
183  hist.GetYaxis().SetTitleOffset(1.3)
184  hist.GetYaxis().SetLabelOffset(0.015)
185  hist.GetYaxis().SetLabelSize(0.06)
186  hist.SetFillColor(ROOT.kGray)
187 
188  return hist
189 
190 
191 def SetupDraw():
192 
193  ROOT.gROOT.SetStyle("Plain")
194  ROOT.gStyle.SetCanvasBorderMode(0)
195  ROOT.gStyle.SetPadBorderMode(0)
196  ROOT.gStyle.SetTitleX(0.75)
197  ROOT.gStyle.SetTitleY(1.0)
198  ROOT.gStyle.SetTitleW(0.25)
199  ROOT.gStyle.SetTitleH(0.25)
200  #ROOT.gStyle.SetStatX(0.64)
201  #ROOT.gStyle.SetStatY(0.64)
202  ROOT.gStyle.SetLabelFont(42,"XYZ")
203  ROOT.gStyle.SetTextFont(42)
204  #ROOT.gStyle.SetOptStat(111110)
205  ROOT.gStyle.SetOptStat(0)
206  ROOT.gStyle.SetPalette(1)
207  ROOT.gStyle.SetTitleFont(42,"XYZ")
208  ROOT.gStyle.SetTitleBorderSize(1)
209  ROOT.gStyle.SetPadColor(0)
210  ROOT.gStyle.SetCanvasColor(0)
211  ROOT.gStyle.SetOptFit(0)
212 
213  c1 = ROOT.TCanvas()
214  c1.SetFrameBorderMode(0)
215  c1.SetBorderSize(0)
216  c1.SetBorderMode(0)
217  c1.SetFillColor(0)
218  c1.SetTickx()
219  c1.SetTicky()
220 
221  return c1
222 
223 
224 
225 def main():
226 
227 
228  if len(sys.argv)!=2:
229  print "Please pass a run number."
230  return True
231 
232  runnumber = int(sys.argv[1])
233 
234  datadir = '/location/of/ntuples'
235  outdir = '/where/output/will/be/sent/'
236 
237  datadir = datadir + str(runnumber) + '/'
238  outdir = outdir + str(runnumber) + '/'
239 
240  if not os.path.exists(outdir):
241  os.mkdir(outdir)
242 
243  print 'Using data from', datadir
244  print 'Ouput will be sent to', outdir
245 
246  parts = ['LBA', 'LBC', 'EBA', 'EBC']
247 
248  for part in parts:
249  for mod in range(1,65):
250  readModule(part, mod, runnumber, datadir, outdir)
251 
252  namehg = 'samples_HG_%d.ps' % runnumber
253  namelg = 'samples_LG_%d.ps' % runnumber
254  packnamehg = outdir + namehg
255  packnamelg = outdir + namelg
256 
257  can = SetupDraw()
258  can.Print('%s[' % packnamehg)
259 
260  for part in parts:
261  for mod in range(1,65):
262  pickfile = '%s%s%02dhg.dat' % (outdir, part, mod)
263  if os.path.exists(pickfile):
264  pickfile = open(pickfile, 'r')
265  page = pickle.load(pickfile)
266  page.Print(packnamehg)
267  pickfile.close()
268 
269  can.Print('%s]' % packnamehg)
270 
271  can = SetupDraw()
272  can.Print('%s[' % packnamelg)
273 
274  for part in parts:
275  for mod in range(1,65):
276  pickfile = '%s%s%02dlg.dat' % (outdir, part, mod)
277  if os.path.exists(pickfile):
278  pickfile = open(pickfile, 'r')
279  page = pickle.load(pickfile)
280  page.Print(packnamelg)
281  pickfile.close()
282 
283  can.Print('%s]' % packnamelg)
284 
285 
286 if __name__ == '__main__':
287  main()
check_samples_cis.cleanHisto
def cleanHisto(hist)
Definition: check_samples_cis.py:176
check_samples_cis.checkSamples
def checkSamples(histo)
Definition: check_samples_cis.py:88
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
check_samples_cis.main
def main()
Definition: check_samples_cis.py:225
check_samples_cis.readModule
def readModule(part, mod, runnumber, datadir, outdir)
Definition: check_samples_cis.py:10
check_samples_cis.SetupDraw
def SetupDraw()
Definition: check_samples_cis.py:191
plotBeamSpotVxVal.range
range
Definition: plotBeamSpotVxVal.py:195
Scale
void Scale(TH1 *h, double d=1)
Definition: comparitor.cxx:76
aux_functions.checkPMTValid
def checkPMTValid(ros, pmt)
Definition: aux_functions.py:2
Trk::open
@ open
Definition: BinningType.h:40
check_samples_cis.getPMTTex
def getPMTTex(pmt)
Definition: check_samples_cis.py:164
str
Definition: BTagTrackIpAccessor.cxx:11
check_samples_cis.saveHistos
def saveHistos(histos, part, mod, gain, runnumber, outdir)
Definition: check_samples_cis.py:114
readCCLHist.float
float
Definition: readCCLHist.py:83