FairShip
Loading...
Searching...
No Matches
calo_scoring_plane_pid_example.py
Go to the documentation of this file.
1#!/usr/bin/env python
2# SPDX-License-Identifier: LGPL-3.0-or-later
3# SPDX-FileCopyrightText: Copyright CERN for the benefit of the SHiP Collaboration
4"""Apply CaloScoringPlanePID to the CaloScoringPlanePoints of a simulation file.
5
6python examples/calo_scoring_plane_pid_example.py -f sim.root -p $FAIRSHIP/geometry/caloScoringPlane_pid_provided.yaml
7"""
8
9import argparse
10from collections import Counter
11
12import ROOT
13from caloScoringPlanePID import load_pid
14
15parser = argparse.ArgumentParser()
16parser.add_argument("-f", "--sim", required=True, help="simulation file")
17parser.add_argument("-p", "--pid", default="", help="PID YAML file (default: perfect PID)")
18args = parser.parse_args()
19
20pid = load_pid(args.pid)
21rng = ROOT.TRandom3(4357)
22pid.Print()
23
24f = ROOT.TFile.Open(args.sim)
25tree = f["cbmsim"]
26table = Counter() # (true species, identified species) -> count
27for event in tree:
28 for point in event.CaloScoringPlanePoint:
29 true_species = pid.TrueSpecies(point.PdgCode())
30 table[(true_species, pid.Identify(point, rng))] += 1
31
32name = ROOT.CaloScoringPlanePID.SpeciesName
33print("true -> identified: count")
34for (t, r), n in sorted(table.items()):
35 print(f" {name(t):>8} -> {name(r):<8}: {n}")