2 from __future__
import print_function
3 from past.builtins
import execfile
4 from builtins
import map
5 from builtins
import range
9 if sys.argv[0]
and "PYTHONSTARTUP" in os.environ:
12 from optparse
import OptionParser
14 usage =
"usage: %prog -n <nominal file> -t <test file> [-o <dir>] [-s] [-d] [-e 0,1] [--opdets=0,1] " 15 parser = OptionParser(usage=usage)
16 parser.add_option(
"-n",
"--nominal", dest=
"nominalfile", help=
"Nominal hist file", metavar=
"F")
17 parser.add_option(
"-t",
"--test", dest=
"testfile", help=
"Test hist file", metavar=
"F")
18 parser.add_option(
"-o",
"--outdir", dest=
"dir", help=
"Directory to output plots", default=
"plots")
19 parser.add_option(
"-s",
"--sim", dest=
"sim", help=
"Make simulation plots", default=
False, action=
"store_true")
20 parser.add_option(
"-d",
"--digi", dest=
"digi", help=
"Make digitizer plots", default=
False, action=
"store_true")
21 parser.add_option(
"-e",
"--events", dest=
"events", help=
"List of events to draw an individual opdet, comma-separated")
22 parser.add_option(
"--opdets", dest=
"opdets", help=
"List of opdets to draw, comma-separated", default=
"0")
23 parser.add_option(
"--wide", dest=
"wide", help=
"Make widely binned plots (for uBooNE)")
25 (options, args) = parser.parse_args()
27 if not (options.nominalfile
and options.testfile):
28 print(
"Both nominal file (-n) and test file (-t) required.")
31 if not (options.sim
or options.digi
or options.event):
32 print(
"No plots to make. Specify at least one of --sim, --digi, or --events=M,N,O.")
35 if not os.path.exists(options.dir):
36 os.makedirs(options.dir)
41 execfile(os.environ[
"PYTHONSTARTUP"])
44 from HandyFuncs
import VerticalRange, GetHists, pbloop
45 from collections
import defaultdict
49 versions = [
"nominal",
"test" ]
50 colors = {
"nominal":kBlue,
"test":kRed }
54 files[N] = TFile(options.nominalfile)
55 files[T] = TFile(options.testfile)
66 plotinfo = [ (
"CountAll",
"OpDetEvents", 100, 0, 100000),
67 (
"CountAll",
"OpDets", 100, 0, 5000) ]
69 plotinfo = [ (
"CountAll",
"OpDetEvents", 100, 0, 4500),
70 (
"CountAll",
"OpDets", 100, 0, 500) ]
71 for var, treename, nbins, xmin, xmax
in plotinfo:
74 trees[v] = files[v].Get(
"pmtresponse/"+treename)
76 c1 = TCanvas(
"_".join([
"c",var,treename]),
"_".join([
"c",var,treename]))
80 hists[v] = TH1D(
"h"+v,v, nbins, xmin, xmax)
81 hists[v].SetLineColor(colors[v])
82 if "same" in dopt: hists[v].SetLineColor(2)
83 trees[v].
Draw(var+
">>h"+v,
"", dopt)
84 if "same" not in dopt: dopt+=
"same" 85 print(v, var, hists[v].Integral())
88 c1.Print(os.path.join(options.dir,
"g4_{0}_by_{1}.png".
format(treename, var)))
96 nom_channel_map = { 0:0, 1:0, 2:0,
108 hists = {
"per_Event":{},
109 "per_Channel":{},
"by_Channel":{},
"by_Channel_cnt":{},
110 "per_OpDet":{},
"by_OpDet":{},
"by_OpDet_cnt":{},
114 c[name] = TCanvas(
"c"+name,
"c"+name)
119 eventintegral = defaultdict(int)
120 opdetintegral = defaultdict(int)
122 hists[
"per_Event"][v] = TH1D(
"hperevent" +v,
"ADCs Per Event", 100, 0, 4e4)
123 hists[
"per_Channel"][v] = TH1D(
"hperchannel" +v,
"ADCs Per Channel", 100, 0, 3e3)
124 hists[
"by_Channel"][v] = TH1D(
"hbychannel" +v,
"ADCs by Channel Number", 96, 0, 96)
125 hists[
"by_Channel_cnt"][v] = TH1D(
"hbychannelcnt" +v,
"Count by Channel Number", 96, 0, 96)
126 hists[
"per_OpDet"][v] = TH1D(
"hperopdet" +v,
"ADCs Per OpDet", 100, 0, 5000)
127 hists[
"by_OpDet"][v] = TH1D(
"hbyopdet" +v,
"ADCs by OpDet Number", 8, 0, 8)
128 hists[
"by_OpDet_cnt"][v] = TH1D(
"hbyopdetcnt" +v,
"Count by OpDet Number", 8, 0, 8)
131 hists[name][v].SetLineColor(colors[v])
134 tdir = files[v].Get(
"opdigiana")
135 keys = list(tdir.GetListOfKeys())
136 for rootkey
in pbloop(keys, v+
":"):
137 hist = tdir.Get(rootkey.GetName())
141 integral = hist.Integral()
142 if v == T: opdet =
int(channel//12)
143 else: opdet = nom_channel_map[channel]
145 eventintegral[event] += integral
146 hists[
"per_Channel"][v].Fill(integral)
147 hists[
"by_Channel"][v].Fill(channel, integral)
148 if integral > 0: hists[
"by_Channel_cnt"][v].Fill(channel)
149 opdetintegral[opdet,event] += integral
150 hists[
"by_OpDet"][v].Fill(opdet, integral)
151 if integral > 0: hists[
"by_OpDet_cnt"][v].Fill(opdet)
153 for val
in eventintegral.values():
154 if val > 4e4: print(
"Overflow: ",val)
155 hists[
"per_Event"][v].Fill(val)
156 for val
in opdetintegral.values():
157 hists[
"per_OpDet"][v].Fill(val)
161 hists[name][v].
Draw(dopt)
163 if "same" not in dopt: dopt+=
"same" 167 if name ==
"per_Channel":
173 c[name].Print(os.path.join(options.dir,
"ADC_"+name+
".png"))
179 events = list(map(int, options.events.split(
",")))
180 opdets = list(map(int, options.opdets.split(
",")))
181 for event, opdet
in [ (e,o)
for e
in events
for o
in opdets ]:
182 channels = { N:[], T:[] }
183 for (c,o)
in nom_channel_map.items():
185 channels[N].append(c)
186 channels[T] = list(range(o*12,(o+1)*12))
191 trees[v] = files[v].Get(
"pmtresponse/OpDets")
192 trees[v].GetEntry(8*(event-1)+opdet)
194 tdir = files[v].Get(
"opdigiana")
195 for c
in channels[v]:
196 htemp = tdir.Get(
"Event_{0:d}_OpDet_{1:d}_Pulse_0".
format(event, c))
197 print(v, event, c, htemp.Integral())
199 hists[v] = htemp.Clone(
"h"+v)
200 hists[v].SetLineColor(colors[v])
201 hists[v].GetXaxis().SetRangeUser(0, 8000)
207 ratio[v] = hists[v].Clone(
"hratio"+v)
208 ratio[v].Divide(hists[N])
210 c1 = TCanvas(
"c1_event{0:d}_opdet{1:d}".
format(event, opdet),
"c_event{0:d}_opdet{1:d}")
214 print(v, hists[v].Integral(), hists[v].Integral()/trees[v].CountAll)
215 if "same" not in dopt: dopt +=
"same" 216 c1.Print(os.path.join(options.dir,
"waveform_event{0:d}_opdet{1:d}.png".
format(event, opdet)))
218 c1 = TCanvas(
"c2_event{0:d}_opdet{1:d}".
format(event, opdet),
"c_event{0:d}_opdet{1:d}")
222 if "same" not in dopt: dopt +=
"same" 223 c2.Print(os.path.join(options.dir,
"waveform_event{0:d}_opdet{1:d}_ratio.png".
format(event, opdet)))
static bool format(QChar::Decomposition tag, QString &str, int index, int len)
def VerticalRange(hists, xrange=(0, 0), ratio=False, forceOne=True, ignoreError=False, maxerr=0.25, absMax=-999, absMin=-999, buffer=0.05)
void Draw(const char *plot, const char *title)
void split(std::string const &s, char c, OutIter dest)
def pbloop(iterable, name="Entries")
bool Update(detinfo::DetectorClocksData const &clockData, detinfo::DetectorPropertiesData const &detProp, const TCSlice &slc, PFPStruct &pfp, bool prt)