2 from __future__
import print_function
10 from geo_id
import GeometryID
14 h.SetFillColor(ROOT.kBlue)
16 def mkdir(path, recursive=True):
18 if recursive: cmd += [
"-p"]
20 os.system(
" ".
join(cmd))
24 etas = etas + [-eta
for eta
in etas
if eta != 0.]
26 xmin = hist.GetXaxis().GetBinLowEdge(0)
27 xmax = hist.GetXaxis().GetBinUpEdge(hist.GetXaxis().GetNbins())
29 xext =
min(map(abs, (xmin, xmax)))
33 ymax = hist.GetYaxis().GetBinUpEdge(hist.GetYaxis().GetNbins())
37 l.SetLineColor(ROOT.kRed)
40 tl.SetTextColor(ROOT.kRed)
43 theta = 2 * math.atan(math.exp(-eta))
45 x = y / math.tan(theta)
55 lab_offset = ymax * tl.GetTextSize()*0.5
56 l.DrawLine(0, 0, x, y)
64 tl.DrawLatex(x, y + lab_offset,
"#eta = {:.1f}".
format(eta))
74 return "_".
join(
str(v)
for v
in k)
78 def addHist2D(self, name, binx, xmin, xmax, biny, ymin, ymax, xlab="", ylab="", zlab="", average=False):
80 root_name = os.path.basename(name)
82 assert key
not in self.
_hist2D,
"hist2D with key {} exists".
format(key)
83 self.
_hist2D[key] = ROOT.TH2D(root_name, root_name, binx, xmin, xmax, biny, ymin, ymax)
84 self.
_hist2D[key].GetXaxis().SetTitle(xlab)
85 self.
_hist2D[key].GetYaxis().SetTitle(ylab)
86 self.
_hist2D[key].GetZaxis().SetTitle(zlab)
91 self.
_hist2D_count[key] = ROOT.TH2D(root_name+
"_count", root_name+
"_count", binx, xmin, xmax, biny, ymin, ymax)
99 assert key
in self.
_hist2D,
"{} not in histograms".
format(key)
100 self.
_hist2D[key].Fill(x, y, *args)
105 key = self.
_key(name)
113 hist_divided = hist.Clone()
115 yield name, hist_divided
118 h.GetXaxis().SetTitle(x)
119 h.GetYaxis().SetTitle(y)
124 p = argparse.ArgumentParser()
125 p.add_argument(
"geant")
126 p.add_argument(
"mapped")
127 p.add_argument(
"--events",
"-n", type=int)
128 p.add_argument(
"outdir")
130 args = p.parse_args()
133 ROOT.gROOT.SetBatch()
135 ROOT.gROOT.LoadMacro(
"../AtlasStyle.C")
139 ROOT.gROOT.LoadMacro(os.path.join(os.path.dirname(__file__),
"plot_helper.C"))
140 geom_graph = ROOT.fill_geometry_hist_rz(
"excells_charged.root", 5000)
142 c = ROOT.TCanvas(
"c",
"c", 800, 600)
144 geom_graph.Draw(
"ap")
145 c.SaveAs(os.path.join(args.outdir,
"geom_graph.png"))
147 geant_file = ROOT.TFile.Open(args.geant)
148 geant_tree = geant_file.Get(
"MaterialTracks")
150 mapped_file = ROOT.TFile.Open(args.mapped)
151 mapped_tree = mapped_file.Get(
"MaterialTracks")
190 vol_6_lay_idxs =
range(2, 12+2, 2)
191 vol_7_lay_idxs =
range(2, 8+2, 2)
192 vol_11_lay_idxs =
range(2, 18+2, 2)
193 vol_12_lay_idxs =
range(2, 8+2, 2)
195 for i, l
in enumerate(vol_6_lay_idxs):
196 vol_lay_col_map[(6, l)] = colors[i%len(colors)]
198 for l1, l2
in zip(vol_6_lay_idxs, reversed(vol_6_lay_idxs)):
199 vol_lay_col_map[(8, l1)] = vol_lay_col_map[(6, l2)]
201 for i, l
in enumerate(vol_11_lay_idxs):
202 vol_lay_col_map[(11, l)] = colors[i%len(colors)]
204 for l1, l2
in zip(vol_11_lay_idxs, reversed(vol_11_lay_idxs)):
205 vol_lay_col_map[(13, l1)] = vol_lay_col_map[(11, l2)]
207 for i, l
in enumerate(vol_7_lay_idxs):
208 vol_lay_col_map[(7, l)] = colors[i%len(colors)]
209 for i, l
in enumerate(vol_12_lay_idxs):
210 vol_lay_col_map[(12, l)] = colors[i%len(colors)]
229 return tuple(
int(h[i:i+2], 16)
for i
in (0, 2 ,4))
232 layers_geant =
do_step(c, geant_tree, os.path.join(args.outdir,
"geant"), args.events, geom_graph)
233 layers_mapped =
do_step(c, mapped_tree, os.path.join(args.outdir,
"mapped"), args.events, geom_graph)
236 c_all = ROOT.TCanvas(
"c_all",
"c_all", 1000, 600)
238 keys_geant =
set(layers_geant.keys())
239 keys_mapped =
set(layers_mapped.keys())
240 keys = keys_geant & keys_mapped
242 for idx, key
in enumerate(keys):
246 h2_geant = layers_geant[key]
247 h2_mapped = layers_mapped[key]
250 for bx
in range(h.GetNbinsX()):
251 for by
in range(h.GetNbinsY()):
252 bc = h.GetBinContent(bx, by)
254 h.SetBinContent(bx, by, val)
267 color_a = vol_lay_col_map[(geo_id.vol_id, geo_id.lay_id)]
280 color_b = ROOT.TColor.GetColorTransparent(color_a, 0.6)
288 h2_geant.SetLineColor(color_a)
289 h2_mapped.SetLineColor(color_a)
290 h2_mapped.SetLineStyle(2)
291 h2_mapped.SetFillColor(color_a)
293 for h
in (h2_geant, h2_mapped):
300 h2_mapped.Draw(opt+
" sames")
306 h2_mapped.Draw(opt+
" sames")
313 lay_str =
"vol_{:03d}_lay_{:03d}_app_{:03d}.pdf".
format(geo_id.vol_id, geo_id.lay_id, geo_id.app_id)
314 path = os.path.join(args.outdir,
"assoc",
"{}.pdf".
format(lay_str))
315 mkdir(os.path.dirname(path))
318 path = os.path.join(args.outdir,
"assoc.pdf")
319 mkdir(os.path.dirname(path))
326 def do_step(c, tree, outdir, events, geom_graph):
331 def mkprofile(name, xlab, ylab, *args):
332 hists[name] = ROOT.TProfile(name, name, *args)
335 mkprofile(
"theta_x0",
'\\theta',
"X_{0}", 40, 0, math.pi)
336 mkprofile(
"theta_dInX0",
'\\theta',
"t/X_{0}", 40, 0, math.pi)
337 mkprofile(
"theta_t",
'\\theta',
"t", 40, 0, math.pi)
338 mkprofile(
"theta_tTot",
'\\theta',
"t_{tot}", 40, 0, math.pi)
340 mkprofile(
"phi_x0",
"\\phi",
"X_{0}", 40, -math.pi, math.pi)
341 mkprofile(
"phi_dInX0",
'\\phi',
"t/X_{0}", 40, -math.pi, math.pi)
342 mkprofile(
"phi_t",
'\\phi',
't', 40, -math.pi, math.pi)
343 mkprofile(
"phi_tTot",
'\\phi',
't_{tot}', 40, -math.pi, math.pi)
345 mkprofile(
"eta_x0",
'\\eta',
'X_{0}', 40, -4, 4)
346 mkprofile(
"eta_dInX0",
'\\eta',
't/X_{0}', 40, -4, 4)
347 mkprofile(
"eta_t",
'\\eta',
't', 40, -4, 4)
348 mkprofile(
"eta_tTot",
'\\eta',
't_{tot}', 40, -4, 4)
356 hm.addHist2D(
"eta_phi/eta_phi_x0", nBinsEta, -4, 4, nBinsPhi, -math.pi, math.pi,
"\\eta",
"\\phi", average=
True)
357 hm.addHist2D(
"eta_phi/eta_phi_dInX0", nBinsEta, -4, 4, nBinsPhi, -math.pi, math.pi,
"\\eta",
"\\phi", average=
True)
358 hm.addHist2D(
"eta_phi/eta_phi_tTot", nBinsEta, -4, 4, nBinsPhi, -math.pi, math.pi,
"\\eta",
"\\phi", average=
True)
360 hm.addHist2D(
"z_r/z_r_x0", nBinsZ, -3000, 3000, nBinsR, 0, 1200,
"z [mm]",
"r [mm]",
"X_{0}", average=
True)
362 for k, v
in hists.iteritems():
368 for idx, event
in enumerate(tree):
371 if idx > events:
break
379 eta = - math.log(math.tan(theta/2))
384 dInX0_tot = event.dInX0
388 zipped = zip(event.step_t,
394 for t, x0, dInX0, z, r, _geo_id
in zipped:
403 lay_str =
"vol_{}_lay_{}_app_{}".
format(geo_id.vol_id, geo_id.lay_id, geo_id.app_id)
404 if _geo_id
not in layers:
405 hname = lay_str+
"_"+outdir+
"_z_r"
406 layers[_geo_id] = ROOT.TH2D(hname, hname, nBinsZ/2, -3000, 3000, nBinsR/2, 0, 1200)
412 hm.fillHist2D(
"z_r/z_r_x0", z, r, x0)
419 hists[
"theta_x0"].Fill(theta, totalX0)
420 hists[
"phi_x0"].Fill(phi, totalX0)
421 hists[
"eta_x0"].Fill(eta, totalX0)
423 hm.fillHist2D(
"eta_phi/eta_phi_x0", eta, phi, totalX0)
424 hm.fillHist2D(
"eta_phi/eta_phi_tTot", eta, phi, tTot)
425 hm.fillHist2D(
"eta_phi/eta_phi_dInX0", eta, phi, dInX0_tot)
427 hists[
"theta_dInX0"].Fill(theta, dInX0_tot)
428 hists[
"phi_dInX0"].Fill(phi, dInX0_tot)
429 hists[
"eta_dInX0"].Fill(eta, dInX0_tot)
431 hists[
"theta_tTot"].Fill(theta, tTot)
432 hists[
"phi_tTot"].Fill(phi, tTot)
433 hists[
"eta_tTot"].Fill(eta, tTot)
436 hists[
"phi_dInX0"].GetYaxis().SetRangeUser(0, hists[
"phi_dInX0"].GetMaximum()*1.2)
437 hists[
"phi_x0"].GetYaxis().SetRangeUser(0, hists[
"phi_x0"].GetMaximum()*1.2)
438 hists[
"phi_t"].GetYaxis().SetRangeUser(0, hists[
"phi_t"].GetMaximum()*1.2)
439 hists[
"phi_tTot"].GetYaxis().SetRangeUser(0, hists[
"phi_tTot"].GetMaximum()*1.2)
441 os.system(
"mkdir -p {}".
format(outdir))
443 for k, v
in hists.iteritems():
445 c.SaveAs(
"{}/{}.pdf".
format(outdir, k))
447 c.SetRightMargin(0.2)
450 for name, h2
in hm.hist2Diter():
452 parts = name.split(
"/")
457 filename =
"{}.pdf".
format(os.path.join(outdir, name))
458 mkdir(os.path.dirname(filename))
462 geom_graph.Draw(
"p+same")
464 filename =
"{}_geom.pdf".
format(os.path.join(outdir, name))
465 mkdir(os.path.dirname(filename))
470 filename =
"{}.pdf".
format(os.path.join(outdir, name))
471 mkdir(os.path.dirname(filename))
495 if "__main__" == __name__: