16 """Sample function to analyse the pre-selection parameters."""
17 parser = ArgumentParser(description=__doc__)
18 parser.add_argument("-f", "--simfile", help="MC simulation file", default="ship.conical.Pythia8-TGeant4.root")
19 parser.add_argument("-r", "--recofile", help="Reconstruction file", default="ship.conical.Pythia8-TGeant4_rec.root")
20 parser.add_argument("-g", "--geofile", help="Geometry file", default="geofile_full.conical.Pythia8-TGeant4.root")
21 options = parser.parse_args()
22
23
24 f = ROOT.TFile.Open(options.simfile, "read")
25
26
27 keys = [k.GetName() for k in f.GetListOfKeys()]
28 print(f"Keys in {options.simfile}: {keys}")
29
30 if "cbmsim" not in keys:
31 print(f"ERROR: MC simulation file {options.simfile} does not contain 'cbmsim' tree")
32 print(f"Available keys: {keys}")
33 raise RuntimeError("MC simulation file does not contain 'cbmsim' tree")
34
35 tree = f["cbmsim"]
36
37
38 reco_f = ROOT.TFile.Open(options.recofile, "read")
39
40 reco_keys = [k.GetName() for k in reco_f.GetListOfKeys()]
41 print(f"Keys in {options.recofile}: {reco_keys}")
42
43 tree.AddFriend("ship_reco_sim", options.recofile)
44
45 geo_file = ROOT.TFile.Open(options.geofile, "read")
46
47 selection = analysis_toolkit.selection_check(geo_file)
48 inspector = analysis_toolkit.event_inspector()
49
50 hist_dict = {}
51
52 ut.bookHist(hist_dict, "event_weight", "Event weight", 100, 100, 100)
53 ut.bookHist(
54 hist_dict,
55 "candidate_time",
56 "candidate time @ decay vertex; ns",
57 200,
58 100,
59 100,
60 )
61 ut.bookHist(hist_dict, "impact_parameter", "Impact parameter; cm", 200, 100, 100)
62 ut.bookHist(hist_dict, "dist_to_innerwall", "Distance to inner wall; cm", 200, 100, 100)
63 ut.bookHist(
64 hist_dict,
65 "dist_to_vesselentrance",
66 "Distance to Decay Vessel Entrance; cm",
67 200,
68 100,
69 100,
70 )
71 ut.bookHist(hist_dict, "inv_mass", "Invariant mass; GeV", 200, 100, 100)
72 ut.bookHist(hist_dict, "DOCA", "Distance of closest approach; cm", 200, 100, 100)
73 ut.bookHist(
74 hist_dict,
75 "len_Particles",
76 "len(tree.Particles); Number of candidates per event",
77 200,
78 100,
79 100,
80 )
81 ut.bookHist(
82 hist_dict,
83 "d_mom",
84 "momentum of daughters; d1 (GeV); d2 (GeV)",
85 200,
86 100,
87 100,
88 200,
89 100,
90 100,
91 )
92 ut.bookHist(hist_dict, "nDOF", "nDOF; d1; d2", 200, 100, 100, 200, 100, 100)
93 ut.bookHist(hist_dict, "chi2nDOF", "chi2nDOF; d1; d2", 200, 100, 100, 200, 100, 100)
94
95 for event_nr, event in enumerate(tree):
96 selection.access_event(event)
97 if len(event.Particles) == 0:
98 continue
99
100 print(f"Event{event_nr}:")
101 inspector.dump_event(event, mom_threshold=0.5)
102
103 event_weight = signal_weight(event.MCTrack)
104
105 hist_dict["event_weight"].Fill(event_weight)
106
107 for candidate_id_in_event, signal in enumerate(event.Particles):
108 hist_dict["candidate_time"].Fill(selection.define_candidate_time(signal))
109 hist_dict["impact_parameter"].Fill(selection.impact_parameter(signal))
110 hist_dict["dist_to_innerwall"].Fill(selection.dist_to_innerwall(signal))
111 hist_dict["dist_to_vesselentrance"].Fill(selection.dist_to_vesselentrance(signal))
112 hist_dict["DOCA"].Fill(selection.DOCA(signal))
113 hist_dict["inv_mass"].Fill(selection.invariant_mass(signal))
114 hist_dict["len_Particles"].Fill(len(tree.Particles))
115 hist_dict["d_mom"].Fill(*selection.daughtermomentum(signal))
116 hist_dict["nDOF"].Fill(*selection.nDOF(signal))
117 hist_dict["chi2nDOF"].Fill(*selection.chi2nDOF(signal))
118
119 IP_cut = 250
120 preselection_flag = selection.preselection_cut(signal, IP_cut=IP_cut, show_table=False)
121
122 if preselection_flag:
123 print(f"Event:{event_nr} Candidate_index: {candidate_id_in_event} <--passes the pre-selection\n\n")
124
125 ut.writeHists(hist_dict, "preselectionparameters.root")
126
127