3 from ROOT
import TCanvas
7 from ROOT
import TEfficiency
14 tm = ROOT.TreeManager(
"./test.root")
17 bt = ROOT.Backtracker(tm);
19 print(
"constructed treemanager")
24 rec = tm.GetRecoTree()
31 hg4_nmatch = TH1F(
'hg4_nmatch',
'G4Particle -> Track matching;N^{0} matches',10,0,10)
33 hfrac = TH1F(
"hfrac",
"particle contributing most energy;fraction of total",50,0,1.1)
34 hncont = TH1F(
"hncont",
"particles contributing energy;N^{0} particles",10,0,10)
35 hncontfrac = TH2F(
'hncontfrac',
'particles contributing energy;N^{0} particles;max fraction of total',10,0,25,0,1.1)
37 eff_g4match = TEfficiency(
'eff_g4match',
'G4Particle -> Track matching; initial energy [GeV]; efficiency',10,0,5)
40 for ientry
in range(rec.NEntries()):
42 if ientry%100 == 0 : print(
'processing event '+
str(ientry))
48 for ig4
in range(g4.NSim()):
49 if not g4.IsPrimary(ig4) :
continue 50 if not abs(g4.PDG(ig4)) == 2212 :
continue 52 if bt.G4ParticleToTracks(ig4).
size() > 0 : nprimary_match += 1
53 hg4_nmatch.Fill(bt.G4ParticleToTracks(ig4).
size())
54 eff_g4match.Fill(bt.G4ParticleToTracks(ig4).
size() > 0, g4.SimMomEnter(ig4,0).
E())
56 ntrack += rec.NTrack()
57 for itrack
in range(rec.NTrack()):
59 imatch = bt.TrackToG4Particle(itrack);
60 if imatch < g4.NSim(): nmatch += 1
63 hncont.Fill(rec.TrackNTrueTrack(itrack))
64 for ip
in range(rec.TrackNTrueTrack(itrack)):
65 hfrac.Fill(rec.TrackMaxDepositFrac(itrack))
66 hncontfrac.Fill(rec.TrackNTrueTrack(itrack),rec.TrackMaxDepositFrac(itrack))
69 print(
'number of primaries found: ',nprimary)
70 print(
'number of matched primaries: ',nprimary_match)
71 print(
'g4particle -> track matching efficiency: ',1.0*nprimary_match/nprimary)
72 else : print(
'no G4particles found!')
74 if ntrack != 0 :print(
'track -> g4particle matching efficiency: ',1.0*nmatch/ntrack)
75 else : print(
'no tracks found!')
77 print(
'hncont size is ',hncont.Integral())
78 print(
'hfrac size is ',hfrac.Integral())
80 cg4_nmatch = TCanvas()
82 cg4_nmatch.SaveAs(
'g4_nmatch.png')
86 cncont.SaveAs(
'ncont.png')
90 cfrac.SaveAs(
'frac.png')
92 cncontfrac = TCanvas()
94 cncontfrac.SaveAs(
'ncont_v_frac.png')
96 ceff_g4match = TCanvas()
98 ceff_g4match.SaveAs(
'g4match_eff.png')
104 null =
input(
"press <Enter> to close canvas and exit program.")
110 if __name__ ==
'__main__':
decltype(auto) constexpr size(T &&obj)
ADL-aware version of std::size.