208 p8gen = generators.get(
"P8gen")
209 if p8gen
is not None:
211 generator_stats.append((
"HNL retries", p8gen.nrOfRetries()))
212 generator_stats.append((
"Geometry rejections", p8gen.nrOfGeoRejections()))
213 generator_stats.append((
"HNL candidates", p8gen.GetCounter(
"hnl_candidates")))
214 generator_stats.append((
"Accepted HNL candidates", p8gen.GetCounter(
"hnl_accepted_candidates")))
215 generator_stats.append((
"Multi-HNL tries", p8gen.GetCounter(
"hnl_multi_candidate_tries")))
216 generator_stats.append((
"Stored decay products", p8gen.GetCounter(
"hnl_stored_decay_products")))
217 elif flags[
"DarkPhoton"]:
218 generator_stats.append((
"DP retries", p8gen.nrOfRetries()))
219 generator_stats.append((
"Geometry rejections", p8gen.nrOfGeoRejections()))
220 generator_stats.append((
"Total dark photons", p8gen.nrOfDP()))
221 elif flags[
"fixedTarget"]:
222 generator_stats.append((
"Generated events", p8gen.GetCounter(
"generated_events")))
223 generator_stats.append((
"G4-only events", p8gen.GetCounter(
"g4only_events")))
224 generator_stats.append((
"Charm input pairs", p8gen.GetCounter(
"charm_input_pairs")))
225 generator_stats.append((
"Stored tracks", p8gen.GetCounter(
"stored_tracks")))
226 generator_stats.append((
"Tracked final-state particles", p8gen.GetCounter(
"tracked_final_state_particles")))
227 generator_stats.append((
"Skipped final-state particles", p8gen.GetCounter(
"skipped_final_state_particles")))
228 muon_back_gen = generators.get(
"MuonBackgen")
229 if muon_back_gen
is not None:
230 generator_stats.append((
"Scanned input entries", muon_back_gen.GetCounter(
"scanned_entries")))
231 generator_stats.append((
"Accepted input entries", muon_back_gen.GetCounter(
"accepted_entries")))
232 generator_stats.append((
"Selected muons", muon_back_gen.GetCounter(
"selected_muons")))
233 generator_stats.append((
"Transported tracks", muon_back_gen.GetCounter(
"transported_tracks")))
234 ntuple_gen = generators.get(
"Ntuplegen")
235 if ntuple_gen
is not None:
236 generator_stats.append((
"Scanned ntuple entries", ntuple_gen.GetCounter(
"scanned_entries")))
237 generator_stats.append((
"Accepted ntuple entries", ntuple_gen.GetCounter(
"accepted_entries")))
238 generator_stats.append((
"Rejected ntuple entries", ntuple_gen.GetCounter(
"rejected_entries")))
239 dis_gen = generators.get(
"DISgen")
240 if dis_gen
is not None:
241 generator_stats.append((
"Generated DIS events", dis_gen.GetCounter(
"generated_events")))
242 generator_stats.append((
"Interaction sampling trials", dis_gen.GetCounter(
"interaction_sampling_trials")))
243 generator_stats.append((
"Stored DIS particles", dis_gen.GetCounter(
"dis_particles_stored")))
244 generator_stats.append((
"Stored soft particles", dis_gen.GetCounter(
"soft_particles_stored")))
245 generator_stats.append((
"Skipped soft particles", dis_gen.GetCounter(
"soft_particles_skipped")))
246 genie_gen = generators.get(
"Geniegen")
247 if genie_gen
is not None:
248 generator_stats.append((
"Generated GENIE events", genie_gen.GetCounter(
"generated_events")))
249 generator_stats.append((
"CC events", genie_gen.GetCounter(
"cc_events")))
250 generator_stats.append((
"nu-e elastic events", genie_gen.GetCounter(
"nue_elastic_events")))
251 generator_stats.append((
"Interaction sampling trials", genie_gen.GetCounter(
"interaction_sampling_trials")))
252 generator_stats.append((
"Stored outgoing leptons", genie_gen.GetCounter(
"outgoing_leptons_stored")))
253 generator_stats.append((
"Stored outgoing hadrons", genie_gen.GetCounter(
"outgoing_hadrons_stored")))
254 return generator_stats
261 for label, value
in generator_stats:
265 summary_file = ROOT.TFile.Open(output_filename,
"READ")
267 print(
"Could not reopen output file for summary:", output_filename)
271 keys = list(summary_file.GetListOfKeys())
273 print_kv(
"Requested events", requested_events)
275 tree = summary_file.Get(
"cbmsim")
277 print(
"No cbmsim tree found in output file.")
280 n_entries = tree.GetEntries()
281 print_kv(
"Final cbmsim entries", n_entries)
284 branch_names = [branch.GetName()
for branch
in tree.GetListOfBranches()]
285 print_kv(
"Branches in cbmsim", len(branch_names))
289 print(
"cbmsim tree is empty.")
294 track_counts = {
"total": 0,
"primary": 0,
"secondary": 0}
295 track_numeric_stats = {
301 pdg_counts: dict[int, int] = {}
303 for branch_name
in branch_names:
304 branch_stats[branch_name] = {
"total": 0,
"nonzero": 0,
"max": 0,
"sum_sq": 0.0}
306 for event_index
in range(n_entries):
307 tree.GetEntry(event_index)
308 for branch_name
in branch_names:
309 container = getattr(tree, branch_name,
None)
310 if container
is None:
315 value = float(container)
316 except (TypeError, ValueError):
318 if branch_name
not in scalar_stats:
323 stats = branch_stats[branch_name]
324 stats[
"total"] += count
326 stats[
"nonzero"] += 1
327 if count > stats[
"max"]:
329 stats[
"sum_sq"] += count * count
331 if branch_name ==
"MCTrack" and count > 0:
332 for track
in container:
333 track_counts[
"total"] += 1
334 if track.GetMotherId() < 0:
335 track_counts[
"primary"] += 1
337 track_counts[
"secondary"] += 1
342 pdg = int(track.GetPdgCode())
343 pdg_counts[pdg] = pdg_counts.get(pdg, 0) + 1
345 countable_branches = [
346 name
for name, stats
in branch_stats.items()
if stats[
"total"] > 0
or stats[
"nonzero"] > 0
348 print_kv(
"Countable branches", len(countable_branches))
350 if track_counts[
"total"] > 0:
352 print_kv(
"Total tracks", track_counts[
"total"])
353 print_kv(
"Primary tracks", track_counts[
"primary"])
354 print_kv(
"Secondary tracks", track_counts[
"secondary"])
355 print_kv(
"Tracks per event", f
"{track_counts['total'] / n_entries:.4g}")
360 top_pdgs = sorted(pdg_counts.items(), key=
lambda item: (-item[1], abs(item[0]), item[0]))[:10]
361 print_kv(
"Top PDG counts",
", ".join(f
"{pdg}:{count}" for pdg, count
in top_pdgs))
365 for branch_name
in sorted(scalar_stats):
369 for branch_name
in sorted(countable_branches):
370 stats = branch_stats[branch_name]
371 active = 100.0 * stats[
"nonzero"] / n_entries
374 f
"total={stats['total']}, mean/event={format_mean_std(n_entries, stats['total'], stats['sum_sq'])},"
375 f
" active={stats['nonzero']}/{n_entries} ({active:5.1f}%), max={stats['max']}",