45 """Inspecting the produced file for successfully added muon veto points."""
46 input_file = r.TFile.Open(inputfile,
"read")
47 input_tree = input_file[
"cbmsim"]
49 muon_file = r.TFile.Open(muonfile,
"read")
50 muon_tree = muon_file[
"DIS"]
56 for i, (muon_event, input_event)
in enumerate(zip(muon_tree, input_tree)):
57 muon_hits = len(muon_event.muon_vetoPoints)
60 for hit
in input_event.vetoPoint:
61 if hit.GetTrackID() == 0:
65 muon_ubthits = len(muon_event.muon_UpstreamTaggerPoints)
68 for hit
in input_event.UpstreamTaggerPoint:
69 if hit.GetTrackID() == 0:
76 len(input_event.vetoPoint) - muoncount,
78 len(input_event.vetoPoint),
80 len(input_event.UpstreamTaggerPoint) - muon_ubtcount,
82 len(input_event.UpstreamTaggerPoint),
87 print(tabulate(table_data, headers=headers, tablefmt=
"grid"))
96 """Add information from original muon to input simulation file."""
98 f
"vetoPoints & UpstreamTaggerPoints from the incoming muon (saved in {muonfile}) will be added to {inputfile}."
101 input_file = r.TFile.Open(inputfile,
"read")
103 input_tree = input_file[
"cbmsim"]
104 except Exception
as e:
110 muon_file = r.TFile.Open(muonfile,
"read")
112 muon_tree = muon_file[
"DIS"]
113 except Exception
as e:
118 temp_filename = inputfile.replace(
".root",
".tmp")
119 temp_file = r.TFile.Open(temp_filename,
"recreate")
120 output_tree = input_tree.CloneTree(0)
122 combined_vetoPoint = r.TClonesArray(
"vetoPoint")
123 output_tree.SetBranchAddress(
"vetoPoint", combined_vetoPoint)
125 combined_UpstreamTaggerPoint = r.TClonesArray(
"UpstreamTaggerPoint")
126 output_tree.SetBranchAddress(
"UpstreamTaggerPoint", combined_UpstreamTaggerPoint)
130 for i, (input_event, muon_event)
in enumerate(zip(input_tree, muon_tree)):
131 interaction_point = r.TVector3()
132 input_event.MCTrack[0].GetStartVertex(interaction_point)
134 combined_vetoPoint.Clear()
138 for hit
in input_event.vetoPoint:
139 ut.assignClonesArrayItem(combined_vetoPoint, index, hit)
143 for hit
in muon_event.muon_vetoPoints:
144 if hit.GetZ() < interaction_point.Z():
145 ut.assignClonesArrayItem(combined_vetoPoint, index, hit)
149 combined_UpstreamTaggerPoint.Clear()
153 for hit
in input_event.UpstreamTaggerPoint:
154 ut.assignClonesArrayItem(combined_UpstreamTaggerPoint, ubt_index, hit)
158 for hit
in muon_event.muon_UpstreamTaggerPoints:
159 if hit.GetZ() < interaction_point.Z():
160 ut.assignClonesArrayItem(combined_UpstreamTaggerPoint, ubt_index, hit)
167 len(muon_event.muon_vetoPoints),
168 len(input_event.vetoPoint),
170 len(combined_vetoPoint),
171 len(muon_event.muon_UpstreamTaggerPoints),
172 len(input_event.UpstreamTaggerPoint),
174 len(combined_UpstreamTaggerPoint),
179 output_tree.Write(
"cbmsim", r.TObject.kOverwrite)
185 os.rename(temp_filename, inputfile)
186 print(f
"File updated with incoming muon info as {inputfile}")
187 print(tabulate(table_data, headers=headers, tablefmt=
"grid"))