FairShip
Loading...
Searching...
No Matches
CaloScoringPlaneDetector.py
Go to the documentation of this file.
1# SPDX-License-Identifier: LGPL-3.0-or-later
2# SPDX-FileCopyrightText: Copyright CERN for the benefit of the SHiP Collaboration
3
4"""Digitisation of the scoring plane with electron / hadron / muon identification.
5
6The identification itself is done by the C++ class CaloScoringPlanePID
7(CaloScoringPlane/CaloScoringPlanePID.h), which interpolates energy-dependent 3x3
8confusion matrices at the particle energy. The matrices are read from a YAML file
9(ShipReco.py --caloScoringPlanePID) by python/caloScoringPlanePID.py. See
10CaloScoringPlane/README.md.
11"""
12
13import logging
14
15import global_variables
16import ROOT
17from BaseDetector import BaseDetector
18from caloScoringPlanePID import load_pid
19
20logger = logging.getLogger(__name__)
21
22
24 """One CaloScoringPlaneHit per accepted CaloScoringPlanePoint.
25
26 Output branches: ``Digi_CaloScoringPlaneHits`` and ``digiCaloScoringPlane2MC``
27 (per hit, the list with the MC track index).
28 """
29
30 def __init__(self, name, intree, outtree=None) -> None:
31 super().__init__(name, intree, mcBranchName="digiCaloScoringPlane2MC", outtree=outtree)
32 cfg = global_variables.ShipGeo.CaloScoringPlane
33 self.pos_res = cfg.get("PositionResolution", 0.0)
34 self.time_res = cfg.get("TimeResolution", 0.0)
35 self.forward_only = cfg.get("ForwardOnly", True)
36 self.ignored = {abs(int(p)) for p in cfg.get("IgnoredPdg", [12, 14, 16])}
37 # Own generator, seeded like shipVeto.py's: drawing the identification and the
38 # smearing from it leaves the random sequences of the other detectors unchanged.
39 self.random = ROOT.TRandom3()
40 self.random.SetSeed(13)
41
42 pid_file = getattr(global_variables, "caloScoringPlanePIDFile", None)
43 if not pid_file:
44 logger.warning("CaloScoringPlane PID: no --caloScoringPlanePID file given, using perfect PID")
45 self.pid = load_pid(pid_file)
46 self.pid.Print()
47
48 def digitize(self) -> None:
49 t0 = self.intree.t0
50 for point in self.intree.CaloScoringPlanePoint:
51 if abs(point.PdgCode()) in self.ignored:
52 continue
53 if self.forward_only and point.GetPz() <= 0:
54 continue
55 species = self.pid.Identify(point, self.random)
56 self.det.push_back(ROOT.CaloScoringPlaneHit(point, t0, self.pos_res, self.time_res, species, self.random))
57 if self.MCdet is not None: # always set (mcBranchName given); narrows the type
58 links = ROOT.std.vector("int")()
59 links.push_back(point.GetTrackID())
60 self.MCdet.push_back(links)