9 from geo_id
import GeometryID
13 h.SetFillColor(ROOT.kBlue)
15 def mkdir(path, recursive=True):
17 if recursive: cmd += [
"-p"]
19 os.system(
" ".
join(cmd))
23 etas = etas + [-eta
for eta
in etas
if eta != 0.]
25 xmin = hist.GetXaxis().GetBinLowEdge(0)
26 xmax = hist.GetXaxis().GetBinUpEdge(hist.GetXaxis().GetNbins())
28 xext =
min(map(abs, (xmin, xmax)))
32 ymax = hist.GetYaxis().GetBinUpEdge(hist.GetYaxis().GetNbins())
36 l.SetLineColor(ROOT.kRed)
39 tl.SetTextColor(ROOT.kRed)
42 theta = 2 * math.atan(math.exp(-eta))
44 x = y / math.tan(theta)
54 lab_offset = ymax * tl.GetTextSize()*0.5
55 l.DrawLine(0, 0, x, y)
63 tl.DrawLatex(x, y + lab_offset,
"#eta = {:.1f}".
format(eta))
73 return "_".
join(
str(v)
for v
in k)
77 def addHist2D(self, name, binx, xmin, xmax, biny, ymin, ymax, xlab="", ylab="", zlab="", average=False):
79 root_name = os.path.basename(name)
81 assert key
not in self.
_hist2D,
"hist2D with key {} exists".
format(key)
82 self.
_hist2D[key] = ROOT.TH2D(root_name, root_name, binx, xmin, xmax, biny, ymin, ymax)
83 self.
_hist2D[key].GetXaxis().SetTitle(xlab)
84 self.
_hist2D[key].GetYaxis().SetTitle(ylab)
85 self.
_hist2D[key].GetZaxis().SetTitle(zlab)
90 self.
_hist2D_count[key] = ROOT.TH2D(root_name+
"_count", root_name+
"_count", binx, xmin, xmax, biny, ymin, ymax)
98 assert key
in self.
_hist2D,
"{} not in histograms".
format(key)
99 self.
_hist2D[key].Fill(x, y, *args)
104 key = self.
_key(name)
112 hist_divided = hist.Clone()
114 yield name, hist_divided
117 h.GetXaxis().SetTitle(x)
118 h.GetYaxis().SetTitle(y)
123 p = argparse.ArgumentParser()
124 p.add_argument(
"geant")
125 p.add_argument(
"mapped")
126 p.add_argument(
"--events",
"-n", type=int)
127 p.add_argument(
"outdir")
129 args = p.parse_args()
132 ROOT.gROOT.SetBatch()
134 ROOT.gROOT.LoadMacro(
"../AtlasStyle.C")
138 ROOT.gROOT.LoadMacro(os.path.join(os.path.dirname(__file__),
"plot_helper.C"))
139 geom_graph = ROOT.fill_geometry_hist_rz(
"excells_charged.root", 5000)
141 c = ROOT.TCanvas(
"c",
"c", 800, 600)
143 geom_graph.Draw(
"ap")
144 c.SaveAs(os.path.join(args.outdir,
"geom_graph.png"))
146 geant_file = ROOT.TFile.Open(args.geant)
147 geant_tree = geant_file.Get(
"MaterialTracks")
149 mapped_file = ROOT.TFile.Open(args.mapped)
150 mapped_tree = mapped_file.Get(
"MaterialTracks")
189 vol_6_lay_idxs =
range(2, 12+2, 2)
190 vol_7_lay_idxs =
range(2, 8+2, 2)
191 vol_11_lay_idxs =
range(2, 18+2, 2)
192 vol_12_lay_idxs =
range(2, 8+2, 2)
194 for i, l
in enumerate(vol_6_lay_idxs):
195 vol_lay_col_map[(6, l)] = colors[i%len(colors)]
197 for l1, l2
in zip(vol_6_lay_idxs, reversed(vol_6_lay_idxs)):
198 vol_lay_col_map[(8, l1)] = vol_lay_col_map[(6, l2)]
200 for i, l
in enumerate(vol_11_lay_idxs):
201 vol_lay_col_map[(11, l)] = colors[i%len(colors)]
203 for l1, l2
in zip(vol_11_lay_idxs, reversed(vol_11_lay_idxs)):
204 vol_lay_col_map[(13, l1)] = vol_lay_col_map[(11, l2)]
206 for i, l
in enumerate(vol_7_lay_idxs):
207 vol_lay_col_map[(7, l)] = colors[i%len(colors)]
208 for i, l
in enumerate(vol_12_lay_idxs):
209 vol_lay_col_map[(12, l)] = colors[i%len(colors)]
228 return tuple(
int(h[i:i+2], 16)
for i
in (0, 2 ,4))
231 layers_geant =
do_step(c, geant_tree, os.path.join(args.outdir,
"geant"), args.events, geom_graph)
232 layers_mapped =
do_step(c, mapped_tree, os.path.join(args.outdir,
"mapped"), args.events, geom_graph)
235 c_all = ROOT.TCanvas(
"c_all",
"c_all", 1000, 600)
237 keys_geant =
set(layers_geant.keys())
238 keys_mapped =
set(layers_mapped.keys())
239 keys = keys_geant & keys_mapped
241 for idx, key
in enumerate(keys):
245 h2_geant = layers_geant[key]
246 h2_mapped = layers_mapped[key]
249 for bx
in range(h.GetNbinsX()):
250 for by
in range(h.GetNbinsY()):
251 bc = h.GetBinContent(bx, by)
253 h.SetBinContent(bx, by, val)
266 color_a = vol_lay_col_map[(geo_id.vol_id, geo_id.lay_id)]
279 color_b = ROOT.TColor.GetColorTransparent(color_a, 0.6)
287 h2_geant.SetLineColor(color_a)
288 h2_mapped.SetLineColor(color_a)
289 h2_mapped.SetLineStyle(2)
290 h2_mapped.SetFillColor(color_a)
292 for h
in (h2_geant, h2_mapped):
299 h2_mapped.Draw(opt+
" sames")
305 h2_mapped.Draw(opt+
" sames")
312 lay_str =
"vol_{:03d}_lay_{:03d}_app_{:03d}.pdf".
format(geo_id.vol_id, geo_id.lay_id, geo_id.app_id)
313 path = os.path.join(args.outdir,
"assoc",
"{}.pdf".
format(lay_str))
314 mkdir(os.path.dirname(path))
317 path = os.path.join(args.outdir,
"assoc.pdf")
318 mkdir(os.path.dirname(path))
325 def do_step(c, tree, outdir, events, geom_graph):
330 def mkprofile(name, xlab, ylab, *args):
331 hists[name] = ROOT.TProfile(name, name, *args)
334 mkprofile(
"theta_x0",
'\\theta',
"X_{0}", 40, 0, math.pi)
335 mkprofile(
"theta_dInX0",
'\\theta',
"t/X_{0}", 40, 0, math.pi)
336 mkprofile(
"theta_t",
'\\theta',
"t", 40, 0, math.pi)
337 mkprofile(
"theta_tTot",
'\\theta',
"t_{tot}", 40, 0, math.pi)
339 mkprofile(
"phi_x0",
"\\phi",
"X_{0}", 40, -math.pi, math.pi)
340 mkprofile(
"phi_dInX0",
'\\phi',
"t/X_{0}", 40, -math.pi, math.pi)
341 mkprofile(
"phi_t",
'\\phi',
't', 40, -math.pi, math.pi)
342 mkprofile(
"phi_tTot",
'\\phi',
't_{tot}', 40, -math.pi, math.pi)
344 mkprofile(
"eta_x0",
'\\eta',
'X_{0}', 40, -4, 4)
345 mkprofile(
"eta_dInX0",
'\\eta',
't/X_{0}', 40, -4, 4)
346 mkprofile(
"eta_t",
'\\eta',
't', 40, -4, 4)
347 mkprofile(
"eta_tTot",
'\\eta',
't_{tot}', 40, -4, 4)
355 hm.addHist2D(
"eta_phi/eta_phi_x0", nBinsEta, -4, 4, nBinsPhi, -math.pi, math.pi,
"\\eta",
"\\phi", average=
True)
356 hm.addHist2D(
"eta_phi/eta_phi_dInX0", nBinsEta, -4, 4, nBinsPhi, -math.pi, math.pi,
"\\eta",
"\\phi", average=
True)
357 hm.addHist2D(
"eta_phi/eta_phi_tTot", nBinsEta, -4, 4, nBinsPhi, -math.pi, math.pi,
"\\eta",
"\\phi", average=
True)
359 hm.addHist2D(
"z_r/z_r_x0", nBinsZ, -3000, 3000, nBinsR, 0, 1200,
"z [mm]",
"r [mm]",
"X_{0}", average=
True)
361 for k, v
in hists.iteritems():
367 for idx, event
in enumerate(tree):
370 if idx > events:
break
378 eta = - math.log(math.tan(theta/2))
383 dInX0_tot = event.dInX0
387 zipped = zip(event.step_t,
393 for t, x0, dInX0, z, r, _geo_id
in zipped:
402 lay_str =
"vol_{}_lay_{}_app_{}".
format(geo_id.vol_id, geo_id.lay_id, geo_id.app_id)
403 if _geo_id
not in layers:
404 hname = lay_str+
"_"+outdir+
"_z_r"
405 layers[_geo_id] = ROOT.TH2D(hname, hname, nBinsZ/2, -3000, 3000, nBinsR/2, 0, 1200)
411 hm.fillHist2D(
"z_r/z_r_x0", z, r, x0)
418 hists[
"theta_x0"].Fill(theta, totalX0)
419 hists[
"phi_x0"].Fill(phi, totalX0)
420 hists[
"eta_x0"].Fill(eta, totalX0)
422 hm.fillHist2D(
"eta_phi/eta_phi_x0", eta, phi, totalX0)
423 hm.fillHist2D(
"eta_phi/eta_phi_tTot", eta, phi, tTot)
424 hm.fillHist2D(
"eta_phi/eta_phi_dInX0", eta, phi, dInX0_tot)
426 hists[
"theta_dInX0"].Fill(theta, dInX0_tot)
427 hists[
"phi_dInX0"].Fill(phi, dInX0_tot)
428 hists[
"eta_dInX0"].Fill(eta, dInX0_tot)
430 hists[
"theta_tTot"].Fill(theta, tTot)
431 hists[
"phi_tTot"].Fill(phi, tTot)
432 hists[
"eta_tTot"].Fill(eta, tTot)
435 hists[
"phi_dInX0"].GetYaxis().SetRangeUser(0, hists[
"phi_dInX0"].GetMaximum()*1.2)
436 hists[
"phi_x0"].GetYaxis().SetRangeUser(0, hists[
"phi_x0"].GetMaximum()*1.2)
437 hists[
"phi_t"].GetYaxis().SetRangeUser(0, hists[
"phi_t"].GetMaximum()*1.2)
438 hists[
"phi_tTot"].GetYaxis().SetRangeUser(0, hists[
"phi_tTot"].GetMaximum()*1.2)
440 os.system(
"mkdir -p {}".
format(outdir))
442 for k, v
in hists.iteritems():
444 c.SaveAs(
"{}/{}.pdf".
format(outdir, k))
446 c.SetRightMargin(0.2)
449 for name, h2
in hm.hist2Diter():
451 parts = name.split(
"/")
456 filename =
"{}.pdf".
format(os.path.join(outdir, name))
457 mkdir(os.path.dirname(filename))
461 geom_graph.Draw(
"p+same")
463 filename =
"{}_geom.pdf".
format(os.path.join(outdir, name))
464 mkdir(os.path.dirname(filename))
469 filename =
"{}.pdf".
format(os.path.join(outdir, name))
470 mkdir(os.path.dirname(filename))
494 if "__main__" == __name__: