9#include <analysis/DecayDescriptor/DecayDescriptor.h>
10#include <analysis/dataobjects/Particle.h>
12#include <framework/datastore/StoreArray.h>
13#include <framework/utilities/TestHelpers.h>
14#include <framework/gearbox/Const.h>
16#include <gtest/gtest.h>
23 TEST(DecayDescriptorTest, TrivialUse)
27 bool initok = dd.
init(std::string{
"K+"});
28 EXPECT_EQ(initok,
true);
37 TEST(DecayDescriptorTest, NormalBehaviour)
40 bool initok = dd.
init(std::string{
"B0:cand -> K+:loose pi-:loose"});
42 EXPECT_EQ(initok,
true);
70 TEST(DecayDescriptorTest, Granddaughters)
73 bool initok = dd.
init(
74 std::string{
"B0:cand -> [D0:dau1 -> K+:grandau pi-:grandau] [pi0:dau2 -> gamma:grandau [gamma:converted -> e+:gtgrandau e-:gtgrandau]]"}
76 EXPECT_EQ(initok,
true);
112 TEST(DecayDescriptorTest, ArrowsDecaysGrammar)
116 bool initok = dd1.
init(std::string{
"B0:candidates =direct=> K+:loose pi-:loose gamma:clean"});
117 EXPECT_EQ(initok,
true);
123 initok = dd2.
init(std::string{
"B0:candidates =norad=> K+:loose pi-:loose gamma:clean"});
124 EXPECT_EQ(initok,
true);
130 initok = dd3.
init(std::string{
"B0:candidates =exact=> K+:loose pi-:loose gamma:clean"});
131 EXPECT_EQ(initok,
true);
137 TEST(DecayDescriptorTest, KeywordDecaysGrammar)
141 bool initok = dd1.
init(std::string{
"B0:candidates -> K+:loose gamma:clean ..."});
142 EXPECT_EQ(initok,
true);
152 initok = dd2.
init(std::string{
"B0:candidates -> K+:loose pi-:loose ?nu"});
153 EXPECT_EQ(initok,
true);
163 initok = dd3.
init(std::string{
"B0:candidates -> K+:loose pi-:loose !nu"});
164 EXPECT_EQ(initok,
true);
174 initok = dd4.
init(std::string{
"B0:candidates -> K+:loose pi-:loose ?gamma"});
175 EXPECT_EQ(initok,
true);
185 initok = dd5.
init(std::string{
"B0:candidates -> K+:loose pi-:loose !gamma"});
186 EXPECT_EQ(initok,
true);
196 initok = dd6.
init(std::string{
"B0:candidates -> e-:loose ... ?nu ?gamma"});
197 EXPECT_EQ(initok,
true);
207 initok = dd7.
init(std::string{
"B0:candidates -> K+:loose pi-:loose ?addbrems"});
208 EXPECT_EQ(initok,
true);
218 TEST(DecayDescriptorTest, UnspecifiedParticleGrammar)
222 bool initok = dd1.
init(std::string{
"@Xsd:candidates -> K+:loose pi-:loose"});
223 EXPECT_EQ(initok,
true);
231 initok = dd2.
init(std::string{
"^@Xsd:candidates -> K+:loose pi-:loose"});
232 EXPECT_EQ(initok,
true);
238 initok = dd3.
init(std::string{
"@^Xsd:candidates -> K+:loose pi-:loose"});
239 EXPECT_EQ(initok,
true);
246 initok = dd4.
init(std::string{
"B0:Xsdee -> @Xsd e+:loose e-:loose"});
247 EXPECT_EQ(initok,
true);
257 initok = dd5.
init(std::string{
"B0:Xsdee -> ^@Xsd e+:loose e-:loose"});
258 EXPECT_EQ(initok,
true);
264 initok = dd6.
init(std::string{
"B0:Xsdee -> @^Xsd e+:loose e-:loose"});
265 EXPECT_EQ(initok,
true);
272 TEST(DecayDescriptorTest, GrammarWithNestedDecay)
276 bool initok = dd1.
init(std::string{
"B0:candidates =direct=> [D-:pi =norad=> pi-:loose ... ?gamma] e+:loose ?nu ?addbrems"});
277 EXPECT_EQ(initok,
true);
297 TEST(DecayDescriptorTest, SelectionParticles)
300 bool initok = dd1.
init(std::string{
"B0:B2Dzpipi -> [D0 -> ^K+:loose pi-:loose] pi+:loose pi-:loose"});
301 EXPECT_EQ(initok,
true);
304 ASSERT_EQ(names.size(), 1);
305 EXPECT_EQ(names[0],
"B0_D0_K");
306 ASSERT_EQ(pdgs.size(), 1);
307 EXPECT_EQ(pdgs[0], 321);
311 initok = dd1.
init(std::string{
"B0:B2Dzpipi -> [D0 -> K+:loose ^pi-:loose] pi+:loose pi-:loose"});
312 EXPECT_EQ(initok,
true);
315 ASSERT_EQ(names.size(), 2);
316 EXPECT_EQ(names[0],
"B0_D0_K");
317 EXPECT_EQ(names[1],
"B0_D0_pi");
318 ASSERT_EQ(pdgs.size(), 2);
319 EXPECT_EQ(pdgs[0], 321);
320 EXPECT_EQ(pdgs[1], -211);
324 initok = dd2.
init(std::string{
"vpho:complex -> [D0 -> ^K+:loose pi-:loose] ^e+:loose ^e-:loose ^gamma:loose"});
325 EXPECT_EQ(initok,
true);
328 ASSERT_EQ(names.size(), 4);
329 EXPECT_EQ(names[0],
"vpho_D0_K");
330 EXPECT_EQ(names[1],
"vpho_e0");
331 EXPECT_EQ(names[2],
"vpho_e1");
332 EXPECT_EQ(names[3],
"vpho_gamma");
333 ASSERT_EQ(pdgs.size(), 4);
334 EXPECT_EQ(pdgs[0], 321);
335 EXPECT_EQ(pdgs[1], -11);
336 EXPECT_EQ(pdgs[2], 11);
337 EXPECT_EQ(pdgs[3], 22);
340 TEST(DecayDescriptorTest, MisIDandDecayInFlightGrammar)
344 bool initok = dd1.
init(std::string{
"B0:sig -> (misID)K+:loose pi-:loose"});
345 EXPECT_EQ(initok,
true);
360 initok = dd2.
init(std::string{
"B0:sig -> K+:loose (misID)pi-:loose"});
361 EXPECT_EQ(initok,
true);
372 initok = dd3.
init(std::string{
"B0:sig -> (misID)K+:loose (misID)pi-:loose"});
373 EXPECT_EQ(initok,
true);
385 initok = dd4.
init(std::string{
"B0:sig -> (decay)K+:loose pi-:loose"});
386 EXPECT_EQ(initok,
true);
397 initok = dd5.
init(std::string{
"B0:sig -> K+:loose (decay)pi-:loose"});
398 EXPECT_EQ(initok,
true);
409 initok = dd6.
init(std::string{
"B0:sig -> (decay)K+:loose (decay)pi-:loose"});
410 EXPECT_EQ(initok,
true);
422 initok = dd7.
init(std::string{
"B0:sig -> (misID)(decay)K+:loose (decay)(misID)pi-:loose"});
423 EXPECT_EQ(initok,
true);
438 initok = dd8.
init(std::string{
"B0:sig -> ^(misID)K+:loose (decay)@pi-:loose"});
439 EXPECT_EQ(initok,
true);
454 initok = dd9.
init(std::string{
"B0:sig -> ^@(misID)(decay)K+:loose (decay)@^(misID)pi-:loose"});
455 EXPECT_EQ(initok,
true);
471 TEST(DecayDescriptorTest, BadLabelTest)
475 bool initok = dd1.
init(std::string{
"B0:lab[el -> K+:loose pi-:loose"});
476 EXPECT_EQ(initok,
false);
481 initok = dd2.
init(std::string{
"B0:lab^el -> K+:loose pi-:loose"});
482 EXPECT_EQ(initok,
false);
487 initok = dd3.
init(std::string{
"B0:lab]el -> K+:loose pi-:loose"});
488 EXPECT_EQ(initok,
false);
493 initok = dd4.
init(std::string{
"B0:lab>el -> K+:loose pi-:loose"});
494 EXPECT_EQ(initok,
false);
499 initok = dd5.
init(std::string{
"B0:lab:el -> K+:loose pi-:loose"});
500 EXPECT_EQ(initok,
false);
505 TEST(DecayDescriptorTest, UnicodeTest)
510 const std::string weird =
"β¨Οβ°=πΌπ°";
512 bool initok = dd1.
init(std::string{
"B0:" + weird +
" -> K+:π©π pi-:π―ππ¦"});
513 ASSERT_EQ(initok,
true);
523 TEST(DecayDescriptorTest, BadGrammarTest)
526 bool initok = dd1.
init(std::string{
"B0:label ---> K+:loose pi-:loose"});
527 EXPECT_EQ(initok,
false);
530 initok = dd2.
init(std::string{
"B0:label > K+:loose pi-:loose"});
531 EXPECT_EQ(initok,
false);
534 initok = dd3.
init(std::string{
"B0:label -> K+::loose pi-:loose"});
535 EXPECT_EQ(initok,
false);
538 initok = dd4.
init(std::string{
"B0:label K+:loose pi-:loose"});
539 EXPECT_EQ(initok,
false);
542 initok = dd5.
init(std::string{
"B0:label <- K+:loose pi-:loose"});
543 EXPECT_EQ(initok,
false);
546 initok = dd6.
init(std::string{
"B0:label => K+:loose pi-:loose"});
547 EXPECT_EQ(initok,
false);
550 initok = dd7.
init(std::string{
"B0:label --> K+:loose pi-:loose"});
551 EXPECT_EQ(initok,
false);
554 initok = dd8.
init(std::string{
"B0:label ==> K+:loose pi-:loose"});
555 EXPECT_EQ(initok,
false);
558 TEST(DecayDescriptorTest, B2ParticleInterface)
563 particles.registerInDataStore();
567 ROOT::Math::PxPyPzEVector zeroes(0, 0, 0, 0);
573 D0->appendDaughter(0);
574 D0->appendDaughter(1);
582 bool initok = dd.
init(std::string{
"B0:B2Dzpipi -> [D0 -> K+:loose ^pi-:loose] ^pi+:loose pi-:loose"});
583 ASSERT_EQ(initok,
true);
586 EXPECT_EQ(selectionparticles.size(), 2);
587 EXPECT_EQ(selectionparticles[0], pim1);
588 EXPECT_EQ(selectionparticles[1], pip);
602 TEST(DecayDescriptorTest, HierarchyDefinitionTest)
605 bool initok = dd.
init(std::string{
"B+ -> [ D+ -> ^K+ pi0 ] ^pi0"});
606 EXPECT_EQ(initok,
true);
610 std::vector<std::vector<std::pair<int, std::string>>> expected_hierarchies;
611 std::vector<std::pair<int, std::string>> K_path;
612 std::vector<std::pair<int, std::string>> pi0_path;
614 K_path.emplace_back(0, std::string(
"B"));
615 K_path.emplace_back(0, std::string(
"D"));
616 K_path.emplace_back(0, std::string(
"K"));
618 pi0_path.emplace_back(0, std::string(
"B"));
619 pi0_path.emplace_back(1, std::string(
"pi0"));
621 EXPECT_NE(expected_hierarchies, selected_hierarchies);
622 expected_hierarchies.push_back(K_path);
623 expected_hierarchies.push_back(pi0_path);
624 EXPECT_EQ(expected_hierarchies, selected_hierarchies);
int getPDGCode() const
PDG code.
static const ParticleType pi0
neutral pion particle
static const ChargedStable pion
charged pion particle
static const ChargedStable kaon
charged kaon particle
static const ParticleType photon
photon particle
static const ChargedStable electron
electron particle
static DataStore & Instance()
Instance of singleton Store.
void setInitializeActive(bool active)
Setter for m_initializeActive.
void reset(EDurability durability)
Frees memory occupied by data store items and removes all objects from the map.
int getPDGCode() const
Return PDG code.
bool isUnspecified() const
Is the particle unspecified?
std::string getFullName() const
returns the full name of the particle full_name = name:label
bool isSelected() const
Is the particle selected in the decay string?
bool isIgnoreDecayInFlight() const
Check if decayInFlight shall be ignored.
std::string getName() const
evt.pdl name of the particle.
std::string getLabel() const
The label of this particle, "default" returned, when no label set.
bool isIgnoreMisID() const
Check if misID shall be ignored.
The DecayDescriptor stores information about a decay tree or parts of a decay tree.
bool isIgnoreBrems() const
Check if added Brems gammas shall be ignored.
bool isIgnoreRadiatedPhotons() const
Check if additional radiated photons shall be ignored.
bool init(const std::string &str)
Initialise the DecayDescriptor from given string.
const DecayDescriptor * getDaughter(int i) const
return i-th daughter (0 based index).
bool isIgnoreNeutrino() const
Check if missing neutrinos shall be ignored.
std::vector< int > getSelectionPDGCodes()
Return list of PDG codes of selected particles.
int getNDaughters() const
return number of direct daughters.
bool isIgnoreMassive() const
Check if missing massive final state particles shall be ignored.
std::vector< std::vector< std::pair< int, std::string > > > getHierarchyOfSelected()
Function to get hierarchy of selected particles and their names (for python use)
bool isIgnoreGamma() const
Check if missing gammas shall be ignored.
std::vector< std::string > getSelectionNames()
Return list of human readable names of selected particles.
std::vector< const Particle * > getSelectionParticles(const Particle *particle)
Get a vector of pointers with selected daughters in the decay tree.
bool isIgnoreIntermediate() const
Check if intermediate resonances/particles shall be ignored.
const DecayDescriptorParticle * getMother() const
return mother.
Class to store reconstructed particles.
void appendDaughter(const Particle *daughter, const bool updateType=true, const int daughterProperty=c_Ordinary)
Appends index of daughter to daughters index array.
Accessor to arrays stored in the data store.
Abstract base class for different kinds of events.