Belle II Software light-2406-ragdoll
decayhashmap.cc
1/**************************************************************************
2 * basf2 (Belle II Analysis Software Framework) *
3 * Author: The Belle II Collaboration *
4 * *
5 * See git log for contributors and copyright holders. *
6 * This file is licensed under LGPL-3.0, see LICENSE.md. *
7 **************************************************************************/
8#include <analysis/utility/DecayNode.h>
9#include <analysis/utility/DecayTree.h>
10#include <analysis/utility/DecayForest.h>
11#include <framework/gearbox/Const.h>
12
13#include <gtest/gtest.h>
14
15using namespace std;
16using namespace Belle2;
17
18
19namespace {
20
21 TEST(DecayNodeTest, Constructor)
22 {
23 DecayNode photon_1(22);
24 DecayNode photon_2(22);
25 DecayNode pi0(111, {photon_1, photon_2});
26
27 EXPECT_EQ(photon_1.pdg, Const::photon.getPDGCode());
28 EXPECT_EQ(photon_1.daughters.size(), 0);
29
30 EXPECT_EQ(pi0.pdg, Const::pi0.getPDGCode());
31 EXPECT_EQ(pi0.daughters.size(), 2);
32
33 }
34
35 TEST(DecayNodeTest, FindDecay)
36 {
37 DecayNode photon_1(22);
38 DecayNode photon_2(22);
39 DecayNode photon_3(22);
40 DecayNode pi0_1(111, {photon_1, photon_2});
41 DecayNode pi0_2(111);
42
43 DecayNode e_1(11);
44 DecayNode e_2(-11);
45 DecayNode pi0_3(111, {e_1, e_2});
46
47 DecayNode pi(211);
48
49 DecayNode D_1(321, {pi, pi0_1});
50 DecayNode D_2(321, {pi, pi0_2});
51 DecayNode D_3(321, {pi, pi0_3});
52
53 EXPECT_TRUE(D_1.find_decay(D_1));
54 EXPECT_TRUE(D_1.find_decay(D_2));
55 EXPECT_FALSE(D_1.find_decay(D_3));
56 EXPECT_TRUE(D_1.find_decay(pi0_1));
57 EXPECT_TRUE(D_1.find_decay(pi0_2));
58 EXPECT_FALSE(D_1.find_decay(pi0_3));
59
60 EXPECT_TRUE(D_2.find_decay(D_1));
61 EXPECT_TRUE(D_2.find_decay(D_2));
62 EXPECT_TRUE(D_2.find_decay(D_3));
63 EXPECT_TRUE(D_2.find_decay(pi0_1));
64 EXPECT_TRUE(D_2.find_decay(pi0_2));
65 EXPECT_TRUE(D_2.find_decay(pi0_3));
66
67 EXPECT_FALSE(D_3.find_decay(D_1));
68 EXPECT_TRUE(D_3.find_decay(D_2));
69 EXPECT_TRUE(D_3.find_decay(D_3));
70 EXPECT_FALSE(D_3.find_decay(pi0_1));
71 EXPECT_TRUE(D_3.find_decay(pi0_2));
72 EXPECT_TRUE(D_3.find_decay(pi0_3));
73
74 EXPECT_TRUE(pi0_1.find_decay(photon_1));
75 EXPECT_TRUE(pi0_1.find_decay(photon_2));
76 EXPECT_TRUE(pi0_1.find_decay(photon_3));
77 EXPECT_FALSE(pi0_1.find_decay(e_1));
78 }
79
80 TEST(DecayTreeTest, FindDecay)
81 {
82 DecayTree photon_1("22");
83 DecayTree pi0_1("111 (--> 22 22)");
84 DecayTree pi0_2("111 ");
85
86 DecayTree e_1("11");
87 DecayTree e_2("-11");
88 DecayTree pi0_3("111 (--> 11 -11)");
89
90 DecayTree D_1("321 (--> 11 111 (--> 22 22))");
91 DecayTree D_2("321 (--> 11 111)");
92 DecayTree D_3("321 (--> 11 111 (--> 11 -11))");
93
94 EXPECT_TRUE(D_1.find_decay(D_1));
95 EXPECT_TRUE(D_1.find_decay(D_2));
96 EXPECT_FALSE(D_1.find_decay(D_3));
97 EXPECT_TRUE(D_1.find_decay(pi0_1));
98 EXPECT_TRUE(D_1.find_decay(pi0_2));
99 EXPECT_FALSE(D_1.find_decay(pi0_3));
100
101 EXPECT_TRUE(D_2.find_decay(D_1));
102 EXPECT_TRUE(D_2.find_decay(D_2));
103 EXPECT_TRUE(D_2.find_decay(D_3));
104 EXPECT_TRUE(D_2.find_decay(pi0_1));
105 EXPECT_TRUE(D_2.find_decay(pi0_2));
106 EXPECT_TRUE(D_2.find_decay(pi0_3));
107
108 EXPECT_FALSE(D_3.find_decay(D_1));
109 EXPECT_TRUE(D_3.find_decay(D_2));
110 EXPECT_TRUE(D_3.find_decay(D_3));
111 EXPECT_FALSE(D_3.find_decay(pi0_1));
112 EXPECT_TRUE(D_3.find_decay(pi0_2));
113 EXPECT_TRUE(D_3.find_decay(pi0_3));
114
115 EXPECT_TRUE(pi0_1.find_decay(photon_1));
116 EXPECT_FALSE(pi0_1.find_decay(e_1));
117 EXPECT_TRUE(pi0_3.find_decay(e_2));
118
119 }
120
121 TEST(DecayTreeTest, IsValid)
122 {
123 DecayTree photon_1("22");
124 DecayTree pi0_1("111 (--> 22 22)");
125
126 EXPECT_TRUE(photon_1.isValid());
127 EXPECT_TRUE(pi0_1.isValid());
128
129 DecayTree no_match(" No match ");
130 EXPECT_FALSE(no_match.isValid());
131
132 }
133
134 TEST(DecayTreeTest, MatchSymbolPosition)
135 {
136
137 DecayTree D_0("321 (--> 11 111 (--> 11 -11))");
138 DecayTree D_1("321 (--> 11 111 (--> ^11 -11))");
139 DecayTree D_2("321 (--> ^11 111 (--> 11 -11))");
140 DecayTree D_3("^321 (--> 11 111 (--> 11 -11))");
141
142 EXPECT_EQ(D_0.getMatchSymbolPosition(), -1);
143 EXPECT_EQ(D_0.getNumberOfDecayNodes(), 5);
144
145 EXPECT_EQ(D_1.getMatchSymbolPosition(), 3);
146 EXPECT_EQ(D_1.getNumberOfDecayNodes(), 5);
147 EXPECT_EQ(D_1.getDecayNode(3).pdg, Const::electron.getPDGCode());
148 EXPECT_EQ(D_1.getDecayNode(3).daughters.size(), 0);
149
150 EXPECT_EQ(D_2.getMatchSymbolPosition(), 1);
151 EXPECT_EQ(D_2.getNumberOfDecayNodes(), 5);
152 EXPECT_EQ(D_2.getDecayNode(1).pdg, Const::electron.getPDGCode());
153 EXPECT_EQ(D_2.getDecayNode(1).daughters.size(), 0);
154
155 EXPECT_EQ(D_3.getMatchSymbolPosition(), 0);
156 EXPECT_EQ(D_3.getNumberOfDecayNodes(), 5);
157 EXPECT_EQ(D_3.getDecayNode(0).pdg, Const::kaon.getPDGCode());
158 EXPECT_EQ(D_3.getDecayNode(0).daughters.size(), 2);
159
160 }
161
162 TEST(DecayTreeTest, Constructor)
163 {
164
165 DecayTree photon("22");
166 EXPECT_EQ(photon.getNumberOfDecayNodes(), 1);
167 EXPECT_EQ(photon.getDecayNode(0).pdg, Const::photon.getPDGCode());
168 EXPECT_EQ(photon.getDecayNode(0).daughters.size(), 0);
169
170 DecayTree pi0("111 (--> 22 22)");
171 EXPECT_EQ(pi0.getNumberOfDecayNodes(), 3);
172 EXPECT_EQ(pi0.getDecayNode(0).pdg, Const::pi0.getPDGCode());
173 EXPECT_EQ(pi0.getDecayNode(0).daughters.size(), 2);
174 EXPECT_EQ(pi0.getDecayNode(1).pdg, Const::photon.getPDGCode());
175 EXPECT_EQ(pi0.getDecayNode(1).daughters.size(), 0);
176 EXPECT_EQ(pi0.getDecayNode(2).pdg, Const::photon.getPDGCode());
177 EXPECT_EQ(pi0.getDecayNode(2).daughters.size(), 0);
178
179 DecayTree D("321 (--> 11 111 (--> 11 -11))");
180 EXPECT_EQ(D.getNumberOfDecayNodes(), 5);
181 EXPECT_EQ(D.getDecayNode(0).pdg, Const::kaon.getPDGCode());
182 EXPECT_EQ(D.getDecayNode(0).daughters.size(), 2);
183 EXPECT_EQ(D.getDecayNode(1).pdg, Const::electron.getPDGCode());
184 EXPECT_EQ(D.getDecayNode(1).daughters.size(), 0);
185 EXPECT_EQ(D.getDecayNode(2).pdg, Const::pi0.getPDGCode());
186 EXPECT_EQ(D.getDecayNode(2).daughters.size(), 2);
187 EXPECT_EQ(D.getDecayNode(3).pdg, Const::electron.getPDGCode());
188 EXPECT_EQ(D.getDecayNode(3).daughters.size(), 0);
189 EXPECT_EQ(D.getDecayNode(4).pdg, -Const::electron.getPDGCode());
190 EXPECT_EQ(D.getDecayNode(4).daughters.size(), 0);
191
192 }
193
194 TEST(DecayForestTest, Constructor)
195 {
196 DecayForest D("321 (--> 11 111 (--> 11 -11)) | No match | 111 (--> 11 -11) | 512 (--> 321 (--> 11 111 (--> 11 -11)) ) ", false);
197
198 EXPECT_EQ(D.getNumberOfTrees(), 4);
199 EXPECT_EQ(D.getOriginalTreeNumber(), 2);
200
201 auto& reconstructed_decay_tree = D.getReconstructedTree();
202 EXPECT_EQ(reconstructed_decay_tree.getNumberOfDecayNodes(), 5);
203 EXPECT_EQ(reconstructed_decay_tree.getDecayNode(0).pdg, Const::kaon.getPDGCode());
204
205 auto& no_match_decay_tree = D.getTree(1);
206 EXPECT_FALSE(no_match_decay_tree.isValid());
207
208 auto& original_decay_tree = D.getOriginalTree();
209 EXPECT_TRUE(original_decay_tree.isValid());
210 EXPECT_EQ(original_decay_tree.getDecayNode(0).pdg, Const::pi0.getPDGCode());
211
212 }
213
214 TEST(DecayForestTest, SaveMemory)
215 {
216 DecayForest D("321 (--> 11 111 (--> 11 -11)) | No match | 111 (--> 11 -11) | 512 (--> 321 (--> 11 111 (--> 11 -11)) ) ", true);
217
218 EXPECT_EQ(D.getNumberOfTrees(), 3);
219 EXPECT_EQ(D.getOriginalTreeNumber(), 2);
220
221 auto& reconstructed_decay_tree = D.getReconstructedTree();
222 EXPECT_EQ(reconstructed_decay_tree.getNumberOfDecayNodes(), 5);
223 EXPECT_EQ(reconstructed_decay_tree.getDecayNode(0).pdg, Const::kaon.getPDGCode());
224
225 auto& no_match_decay_tree = D.getTree(1);
226 EXPECT_FALSE(no_match_decay_tree.isValid());
227
228 auto& original_decay_tree = D.getOriginalTree();
229 EXPECT_TRUE(original_decay_tree.isValid());
230 EXPECT_EQ(original_decay_tree.getDecayNode(0).pdg, Const::pi0.getPDGCode());
231
232 }
233
234 TEST(DecayForestTest, FindB2TauNuDecay)
235 {
237 Y(" 300553 (--> -521 (--> 15 (--> -211)) 521 (--> -423 (--> -421 (--> 321 11) 22) 211 211 -211 111 (--> 22 22))) | ^300553 (--> 521 (--> -423 (--> -421 (--> 321 11 -12) 22) 10223 (--> 213 (--> 211 111 (--> 22 22)) -211) 211) -521 (--> 15 (--> 16 -211 111 (--> 22 22)) -16)) | 300553 (--> 521 (--> -423 (--> -421 (--> 321 11 -12) 22) 10223 (--> 213 (--> 211 111 (--> 22 22)) -211) 211) ^-521 (--> 15 (--> 16 -211 111 (--> 22 22)) -16)) | 300553 (--> 521 (--> -423 (--> -421 (--> 321 11 -12) 22) 10223 (--> 213 (--> 211 111 (--> 22 22)) -211) 211) -521 (--> ^15 (--> 16 -211 111 (--> 22 22)) -16)) | 300553 (--> 521 (--> -423 (--> -421 (--> 321 11 -12) 22) 10223 (--> 213 (--> 211 111 (--> 22 22)) -211) 211) -521 (--> 15 (--> 16 ^-211 111 (--> 22 22)) -16)) | 300553 (--> ^521 (--> -423 (--> -421 (--> 321 11 -12) 22) 10223 (--> 213 (--> 211 111 (--> 22 22)) -211) 211) -521 (--> 15 (--> 16 -211 111 (--> 22 22)) -16)) | 300553 (--> 521 (--> ^-423 (--> -421 (--> 321 11 -12) 22) 10223 (--> 213 (--> 211 111 (--> 22 22)) -211) 211) -521 (--> 15 (--> 16 -211 111 (--> 22 22)) -16)) | 300553 (--> 521 (--> -423 (--> ^-421 (--> 321 11 -12) 22) 10223 (--> 213 (--> 211 111 (--> 22 22)) -211) 211) -521 (--> 15 (--> 16 -211 111 (--> 22 22)) -16)) | 300553 (--> 521 (--> -423 (--> -421 (--> ^321 11 -12) 22) 10223 (--> 213 (--> 211 111 (--> 22 22)) -211) 211) -521 (--> 15 (--> 16 -211 111 (--> 22 22)) -16)) | 300553 (--> 521 (--> -423 (--> -421 (--> 321 ^11 -12) 22) 10223 (--> 213 (--> 211 111 (--> 22 22)) -211) 211) -521 (--> 15 (--> 16 -211 111 (--> 22 22)) -16)) | 300553 (--> 521 (--> -423 (--> -421 (--> 321 11 -12) ^22) 10223 (--> 213 (--> 211 111 (--> 22 22)) -211) 211) -521 (--> 15 (--> 16 -211 111 (--> 22 22)) -16)) | 300553 (--> 521 (--> -423 (--> -421 (--> 321 11 -12) 22) 10223 (--> 213 (--> ^211 111 (--> 22 22)) -211) 211) -521 (--> 15 (--> 16 -211 111 (--> 22 22)) -16)) | 300553 (--> 521 (--> -423 (--> -421 (--> 321 11 -12) 22) 10223 (--> 213 (--> 211 111 (--> 22 22)) -211) ^211) -521 (--> 15 (--> 16 -211 111 (--> 22 22)) -16)) | 300553 (--> 521 (--> -423 (--> -421 (--> 321 11 -12) 22) 10223 (--> 213 (--> 211 111 (--> 22 22)) ^-211) 211) -521 (--> 15 (--> 16 -211 111 (--> 22 22)) -16)) | 300553 (--> 521 (--> -423 (--> -421 (--> 321 11 -12) 22) 10223 (--> 213 (--> 211 ^111 (--> 22 22)) -211) 211) -521 (--> 15 (--> 16 -211 111 (--> 22 22)) -16)) | 300553 (--> 521 (--> -423 (--> -421 (--> 321 11 -12) 22) 10223 (--> 213 (--> 211 111 (--> ^22 22)) -211) 211) -521 (--> 15 (--> 16 -211 111 (--> 22 22)) -16)) | 300553 (--> 521 (--> -423 (--> -421 (--> 321 11 -12) 22) 10223 (--> 213 (--> 211 111 (--> 22 ^22)) -211) 211) -521 (--> 15 (--> 16 -211 111 (--> 22 22)) -16))");
238
239 DecayTree b2taunu_cc("521 (--> -15 16)");
240 DecayTree b2taunu("-521 (--> 15 -16)");
241 DecayTree b2taunu2e("-521 (--> 15 (11 -12 16) -16)");
242 DecayTree b2taunu2rho("-521 (--> 15 (16 -211 111 (--> 22 22)) -16)");
243
244 EXPECT_FALSE(Y.getOriginalTree().find_decay(b2taunu_cc));
245 EXPECT_TRUE(Y.getOriginalTree().find_decay(b2taunu));
246 EXPECT_FALSE(Y.getOriginalTree().find_decay(b2taunu2e));
247 EXPECT_TRUE(Y.getOriginalTree().find_decay(b2taunu2rho));
248
249 }
250
251 TEST(DecayForestTest, RemoveRadiativePhotons)
252 {
253 DecayForest B("521 (--> -421 (--> 325 (--> 321 111 (--> 22 22)) -211) -13 14 22)", false, true);
254 DecayForest B2("521 (--> -11 12 22)", false, true);
255 DecayForest B3("521 (--> -11 12 22)", false, false);
256
257 DecayTree case1(" 521 (--> -421 (--> 325 (--> 321 111 (--> 22 22)) -211) -13 14)", true);
258 DecayTree case2(" 521 (--> -11 12 22)", true);
259 DecayTree case3(" 521 (--> -11 12 22)", false);
260 DecayTree case4(" 521 (--> -11 12)", false);
261
262
263 DecayTree case5(" 521 (--> -11 12 22)", false);
264 DecayTree case6(" 521 (--> -11 12 22)", true);
265 DecayTree case7(" 521 (--> -11 12)", false);
266
267 EXPECT_TRUE(B.getOriginalTree().find_decay(case1));
268
269 EXPECT_TRUE(B2.getOriginalTree().find_decay(case2));
270 EXPECT_FALSE(B2.getOriginalTree().find_decay(case3));
271 EXPECT_TRUE(B2.getOriginalTree().find_decay(case4));
272
273 EXPECT_TRUE(B3.getOriginalTree().find_decay(case5));
274 EXPECT_FALSE(B3.getOriginalTree().find_decay(case6));
275 EXPECT_FALSE(B3.getOriginalTree().find_decay(case7));
276 }
277
278} // namespace
int getPDGCode() const
PDG code.
Definition: Const.h:473
static const ParticleType pi0
neutral pion particle
Definition: Const.h:674
static const ChargedStable kaon
charged kaon particle
Definition: Const.h:662
static const ParticleType photon
photon particle
Definition: Const.h:673
static const ChargedStable electron
electron particle
Definition: Const.h:659
Contains several DecayTree objects, which belong all to the same candidate.
Definition: DecayForest.h:24
DecayNode describes the decay of a particle identified by its pdg code, into list of daughters.
Definition: DecayNode.h:23
This is a helper class for the MCDecayFinderModule.
Definition: DecayTree.h:20
Abstract base class for different kinds of events.
Definition: ClusterUtils.h:24
STL namespace.