FairShip
Loading...
Searching...
No Matches
test_signal_particle.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
4import pytest
5from mc_truth import PRIMARY_PROCESS, find_signal_track, signal_weight
6
7
9 """Minimal stand-in for ShipMCTrack, so the tests need no ROOT."""
10
11 def __init__(self, pdg, mother, process=PRIMARY_PROCESS, weight=1.0):
12 self.pdg = pdg
13 self.mother = mother
14 self.process = process
15 self.weight = weight
16
17 def GetPdgCode(self):
18 return self.pdg
19
20 def GetMotherId(self):
21 return self.mother
22
23 def GetProcName(self):
24 return self.process
25
26 def GetWeight(self):
27 return self.weight
28
29
30# The five MCTrack layouts the SHiP generators produce. Each is (tracks,
31# expected signal index); see shipgen/HNLPythia8Generator.cxx:269-283,
32# shipgen/DPPythia8Generator.cxx:246-298 and shipgen/EvtCalcGenerator.cxx:205.
33LAYOUTS = {
34 "hnl_external_charm_file": (
35 [
36 FakeTrack(2212, -1), # grand mother from the input file
37 FakeTrack(431, 0), # charm hadron
38 FakeTrack(9900015, 1), # signal
39 FakeTrack(13, 2),
40 FakeTrack(-211, 2),
41 ],
42 2,
43 ),
44 "hnl_no_input_file": (
45 [
46 FakeTrack(431, -1), # charm hadron
47 FakeTrack(9900015, 0), # signal
48 FakeTrack(13, 1),
49 FakeTrack(-211, 1),
50 ],
51 1,
52 ),
53 "dark_photon_meson_production": (
54 [
55 FakeTrack(2212, -1),
56 FakeTrack(111, 0),
57 FakeTrack(4900023, 1), # signal
58 FakeTrack(13, 2),
59 FakeTrack(-13, 2),
60 ],
61 2,
62 ),
63 "dark_photon_proton_bremsstrahlung": (
64 [
65 FakeTrack(9900015, -1), # signal, no mother stored
66 FakeTrack(11, 0),
67 FakeTrack(-11, 0),
68 ],
69 0,
70 ),
71 "evtcalc_external_llp_file": (
72 [
73 FakeTrack(999, -1), # signal, geantino placeholder PDG
74 FakeTrack(13, 0),
75 FakeTrack(-13, 0),
76 ],
77 0,
78 ),
79}
80
81
82@pytest.mark.parametrize("layout", LAYOUTS)
84 tracks, expected = LAYOUTS[layout]
85 assert find_signal_track(tracks) == expected
86
87
89 """A delta ray crossing the tracker must not be mistaken for a daughter."""
90 tracks = [
91 FakeTrack(12345678, -1), # signal from an external file
92 FakeTrack(-13, 0),
93 FakeTrack(13, 0),
94 FakeTrack(11, 2, process="Delta ray"),
95 FakeTrack(22, 2, process="Bremstrahlung"),
96 ]
97 assert find_signal_track(tracks) == 0
98
99
101 tracks, _ = LAYOUTS["hnl_external_charm_file"]
102 assert find_signal_track(tracks, pdg=9900015) == 2
103 # Sign is irrelevant, as elsewhere in the analysis code.
104 assert find_signal_track(tracks, pdg=-9900015) == 2
105
106
108 tracks, _ = LAYOUTS["hnl_external_charm_file"]
109 assert find_signal_track(tracks, pdg=4900023) is None
110
111
113 """Not every decay product is kept; one daughter must be enough.
114
115 Seen in 7 of 2000 events of the issue-1371 dark-scalar sample.
116 """
117 tracks = [
118 FakeTrack(12345678, -1), # signal
119 FakeTrack(13, 0), # the only decay product stored
120 FakeTrack(11, 1, process="Delta ray"),
121 ]
122 assert find_signal_track(tracks) == 0
123
124
126 """A muon-background stack is a branching cascade with several roots."""
127 tracks = [
128 FakeTrack(2212, -1),
129 FakeTrack(2112, -1), # second root: not a single production chain
130 FakeTrack(1, 1),
131 FakeTrack(1, 2),
132 FakeTrack(213, 3),
133 FakeTrack(211, 4),
134 ]
135 assert find_signal_track(tracks) is None
136
137
139 """A single generator track with no daughters is not a signal decay."""
140 assert find_signal_track([FakeTrack(2212, -1)]) is None
141
142
144 assert find_signal_track([]) is None
145
146
148 tracks = [
149 FakeTrack(2212, -1, weight=1.0), # grandmother, weight hardcoded to 1
150 FakeTrack(431, 0, weight=0.25),
151 FakeTrack(9900015, 1, weight=0.25), # signal
152 FakeTrack(13, 2, weight=0.25),
153 FakeTrack(-211, 2, weight=0.25),
154 ]
155 assert signal_weight(tracks) == pytest.approx(0.25)
156
157
159 tracks = [FakeTrack(2212, -1, weight=0.5), FakeTrack(2112, -1, weight=0.5)]
160 assert signal_weight(tracks) == pytest.approx(1.0)
161
162
164 tracks = [
165 FakeTrack(9900015, -1, weight=0.0),
166 FakeTrack(13, 0),
167 FakeTrack(-13, 0),
168 ]
169 assert signal_weight(tracks) == pytest.approx(1.0)
__init__(self, pdg, mother, process=PRIMARY_PROCESS, weight=1.0)
test_signal_found_in_every_generator_layout(layout)