FairShip
Loading...
Searching...
No Matches
BaseDetector.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"""Base class for detector digitization."""
5
6from abc import ABC, abstractmethod
7
8import ROOT
9
10
11class BaseDetector(ABC):
12 """Abstract base class for detector digitization using template method pattern."""
13
15 self,
16 name,
17 intree,
18 branchName=None,
19 mcBranchType=None,
20 mcBranchName=None,
21 splitLevel: int = 99,
22 outtree=None,
23 ) -> None:
24 """Initialize the detector digitizer."""
25 self.name = name
26 self.intree = intree
27 # If outtree provided, use it for output; else intree for compatibility
28 self.outtree = outtree if outtree is not None else intree
29 self.det = ROOT.std.vector(f"{name}Hit")()
30 self.MCdet = None
31 self.mcBranch = None
32 if mcBranchName:
33 self.MCdet = ROOT.std.vector("std::vector< int >")()
34 self.mcBranch = self.outtree.Branch(mcBranchName, self.MCdet, 32000, splitLevel)
35
36 if branchName:
37 self.branch = self.outtree.Branch(f"Digi_{branchName}Hits", self.det, 32000, splitLevel)
38 else:
39 self.branch = self.outtree.Branch(f"Digi_{name}Hits", self.det, 32000, splitLevel)
40
41 def delete(self) -> None:
42 """Clear detector hit containers."""
43 self.det.clear()
44 if self.MCdet:
45 self.MCdet.clear()
46
47 def fill(self) -> None: # noqa: B027
48 """Fill detector hit branches.
49
50 Note: This method is now a no-op to prevent double-filling.
51 All branches are filled synchronously by recoTree.Fill() in the main loop.
52 """
53 pass
54
55 @abstractmethod
56 def digitize(self) -> None:
57 """Digitize detector hits.
58
59 This method must be implemented by all detector subclasses to convert
60 MC hits into digitized detector responses.
61 """
62 pass
63
64 def process(self) -> None:
65 """Process one event: delete, digitize, and fill."""
66 self.delete()
67 self.digitize()
68 self.fill()
None __init__(self, name, intree, branchName=None, mcBranchType=None, mcBranchName=None, int splitLevel=99, outtree=None)
Definition: BaseDetector.py:23