ATLAS Offline Software
check_samples_monocis.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_MonoCis.%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  histos = [ROOT.TH1F('%s MOD %02d PMT %02d' % (part, mod, int(pmt + 1)), '%02d' % (int(pmt + 1)), 7, 1, 8) for pmt in range(48)]
21  entries = [0 for pmt in range(48)]
22  for hist in histos:
23  hist.GetXaxis().CenterLabels(ROOT.kTRUE)
24  hist = cleanHisto(hist)
25 
26 
27  if os.path.exists(filename):
28  print 'Using', filename
29  file = ROOT.TFile.Open(filename)
30  if file and not file.IsZombie():
31  tree = file.Get('h1000')
32  nevents = tree.GetEntries()
33  #nevents = 100 # for testing
34 
35  for ev in range(1, nevents):
36 
37  tree.GetEntry(ev)
38 
39  pha = tree.m_cispar[5]
40  dac = tree.m_cispar[6]
41  cap = tree.m_cispar[7]
42  if pha!=0 or dac!=120 or cap!=100:
43  continue
44  for pmt in range(48):
45  samples = getattr(tree, 'sample%s%02d' % (partmap[part], mod))
46  for samp in range(7):
47  histos[pmt].Fill(samp+1, samples[pmt*9+samp])
48  entries[pmt] = entries[pmt] + 1
49 
50 
51  for pmt in range(48):
52  if entries[pmt]==0:
53  continue
54  factor = 1./float(entries[pmt])
55  histos[pmt].Scale(factor)
56 
57  for histo in histos:
58  histo, color = checkSamples(histo)
59 
60  saveHistos(histos, part, mod, runnumber, outdir)
61  file.Close()
62 
63 
64 def checkSamples(histo):
65 
66  maxval = 0
67  maxvalsamp = 0
68 
69  color = 'null'
70 
71  for bin in range(1, histo.GetXaxis().GetNbins()):
72  val = histo.GetBinContent(bin)
73  if val > maxval:
74  maxval = val
75  maxvalsamp = bin
76 
77  if maxvalsamp==4:
78  histo.SetFillColor(ROOT.kGreen)
79  color = 'green'
80  elif maxvalsamp==3 or maxvalsamp==5:
81  histo.SetFillColor(ROOT.kYellow)
82  color = 'yellow'
83  elif maxvalsamp==1 or maxvalsamp==2 or maxvalsamp==6 or maxvalsamp==7:
84  histo.SetFillColor(ROOT.kRed)
85  color = 'red'
86 
87  return histo, color
88 
89 
90 def saveHistos(histos, part, mod, runnumber, outdir):
91 
92  name = '%s%02d.ps' % (part, mod)
93 
94  packname = outdir+name
95  partnames = ['LBA', 'LBC', 'EBA', 'EBC']
96 
97  can = SetupDraw()
98  can.Divide(1,1)
99 
100  toptitle = ROOT.TLatex(0.45, 0.9, '%s %02d' % (part, mod))
101  toptitle.SetTextSize(0.05)
102  toptitle.SetNDC()
103  toptitle.SetTextAlign(12)
104 
105  can.Divide(8,7)
106 
107  for hist in histos:
108  can.cd(histos.index(hist)+8+1)
109  pmt = int(hist.GetTitle())
110  if pmt == '':
111  continue
112  if checkPMTValid(partnames.index(part), pmt-1)=='noninst':
113  continue
114 
115  if hist!=0:
116  hist.Draw()
117  can.Modified()
118  can.Update()
119 
120  can.Modified()
121 
122  can.cd(0)
123  toptitle.Draw()
124  can.Modified()
125  can.Update()
126 
127  pickfile = open('%s%s%02d.dat' % (outdir, part, mod), 'w')
128  pickle.dump(can, pickfile)
129  pickfile.close()
130 
131 
132 def getPMTTex(pmt):
133 
134  pave = ROOT.TPaveText(0.7, 0.6, 0.9, 0.95)
135  pave.AddText(pmt)
136  pave.SetFillColor(0)
137 
138  pave.SetBorderSize(1)
139  pave.SetTextSize(0.15)
140  pave.SetTextAlign(12)
141 
142  return pave
143 
144 def cleanHisto(hist):
145 
146  hist.GetXaxis().CenterTitle()
147  hist.GetXaxis().SetTitleOffset(1.4)
148  hist.GetXaxis().SetLabelOffset(0.021)
149  hist.GetXaxis().SetLabelSize(0.06)
150  hist.GetYaxis().CenterTitle()
151  hist.GetYaxis().SetTitleOffset(1.3)
152  hist.GetYaxis().SetLabelOffset(0.015)
153  hist.GetYaxis().SetLabelSize(0.06)
154  hist.SetFillColor(ROOT.kGray)
155 
156  return hist
157 
158 
159 def SetupDraw():
160 
161  ROOT.gROOT.SetStyle("Plain")
162  ROOT.gStyle.SetCanvasBorderMode(0)
163  ROOT.gStyle.SetPadBorderMode(0)
164  ROOT.gStyle.SetTitleX(0.75)
165  ROOT.gStyle.SetTitleY(1.0)
166  ROOT.gStyle.SetTitleW(0.25)
167  ROOT.gStyle.SetTitleH(0.25)
168  #ROOT.gStyle.SetStatX(0.64)
169  #ROOT.gStyle.SetStatY(0.64)
170  ROOT.gStyle.SetLabelFont(42,"XYZ")
171  ROOT.gStyle.SetTextFont(42)
172  #ROOT.gStyle.SetOptStat(111110)
173  ROOT.gStyle.SetOptStat(0)
174  ROOT.gStyle.SetPalette(1)
175  ROOT.gStyle.SetTitleFont(42,"XYZ")
176  ROOT.gStyle.SetTitleBorderSize(1)
177  ROOT.gStyle.SetPadColor(0)
178  ROOT.gStyle.SetCanvasColor(0)
179  ROOT.gStyle.SetOptFit(0)
180 
181  c1 = ROOT.TCanvas()
182  c1.SetFrameBorderMode(0)
183  c1.SetBorderSize(0)
184  c1.SetBorderMode(0)
185  c1.SetFillColor(0)
186  c1.SetTickx()
187  c1.SetTicky()
188 
189  return c1
190 
191 
192 
193 def main():
194 
195 
196  if len(sys.argv)!=2:
197  print "Please pass a run number."
198  return True
199 
200  runnumber = int(sys.argv[1])
201 
202  datadir = '/location/of/ntuples'
203  outdir = '/where/output/will/be/sent/'
204 
205  datadir = datadir + str(runnumber) + '/'
206  outdir = outdir + str(runnumber) + '/'
207 
208  if not os.path.exists(outdir):
209  os.mkdir(outdir)
210 
211  print 'Using data from', datadir
212  print 'Ouput will be sent to', outdir
213 
214  parts = ['LBA', 'LBC', 'EBA', 'EBC']
215 
216  for part in parts:
217  for mod in range(1,65):
218  readModule(part, mod, runnumber, datadir, outdir)
219 
220  name = 'samples_%d.ps' % runnumber
221  packname = outdir + name
222 
223  can = SetupDraw()
224  can.Print('%s[' % packname)
225 
226  for part in parts:
227  for mod in range(1,65):
228  pickfile = '%s%s%02d.dat' % (outdir, part, mod)
229  if os.path.exists(pickfile):
230  pickfile = open(pickfile, 'r')
231  page = pickle.load(pickfile)
232  page.Print(packname)
233  pickfile.close()
234 
235  can.Print('%s]' % packname)
236 
237 if __name__ == '__main__':
238  main()
check_samples_monocis.getPMTTex
def getPMTTex(pmt)
Definition: check_samples_monocis.py:132
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
check_samples_monocis.cleanHisto
def cleanHisto(hist)
Definition: check_samples_monocis.py:144
check_samples_monocis.readModule
def readModule(part, mod, runnumber, datadir, outdir)
Definition: check_samples_monocis.py:10
plotBeamSpotVxVal.range
range
Definition: plotBeamSpotVxVal.py:195
check_samples_monocis.main
def main()
Definition: check_samples_monocis.py:193
check_samples_monocis.SetupDraw
def SetupDraw()
Definition: check_samples_monocis.py:159
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_monocis.saveHistos
def saveHistos(histos, part, mod, runnumber, outdir)
Definition: check_samples_monocis.py:90
check_samples_monocis.checkSamples
def checkSamples(histo)
Definition: check_samples_monocis.py:64
str
Definition: BTagTrackIpAccessor.cxx:11
readCCLHist.float
float
Definition: readCCLHist.py:83