FairShip
Loading...
Searching...
No Matches
ubt_hits_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
5"""Print UBT hits with the MC points they were made from (digiUBT2MC, digiUBT2MCADC)."""
6
7from argparse import ArgumentParser
8
9import ROOT
10
11
12def main() -> None:
13 parser = ArgumentParser(description=__doc__)
14 parser.add_argument("-f", "--simfile", help="MC simulation file", required=True)
15 parser.add_argument("-r", "--recofile", help="Reconstruction file", required=True)
16 parser.add_argument("-n", "--nEvents", help="Number of events to print", type=int, default=5)
17 options = parser.parse_args()
18
19 # Keep the files open while their trees are used.
20 sim_file = ROOT.TFile.Open(options.simfile, "read")
21 sim = sim_file["cbmsim"]
22 reco_file = ROOT.TFile.Open(options.recofile, "read")
23 reco = reco_file["ship_reco_sim"]
24
25 for event in range(min(options.nEvents, reco.GetEntries())):
26 # Entry i of the reco tree belongs to entry i of the simulation tree.
27 sim.GetEntry(event)
28 reco.GetEntry(event)
29 print(f"Event {event}: {reco.Digi_UpstreamTaggerHits.size()} UBT hits")
30
31 # One entry per hit in each of the three branches, in the same order.
32 for hit, indices, signals in zip(reco.Digi_UpstreamTaggerHits, reco.digiUBT2MC, reco.digiUBT2MCADC):
33 print(f" tile {hit.GetTileID()}: ADC {hit.GetADC()}, triggered {bool(hit.IsTriggered())}")
34 # Each point index goes with the ADC signal of that point.
35 for index, signal in zip(indices, signals):
36 point = sim.UpstreamTaggerPoint[index]
37 print(
38 f" point {index}: PDG {point.PdgCode()}, track {point.GetTrackID()}, "
39 f"Edep {1000.0 * point.GetEnergyLoss():.3f} MeV, ADC {signal:.1f}"
40 )
41
42
43if __name__ == "__main__":
44 main()