Belle II Software development
inclusive_variables.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 <gtest/gtest.h>
9
10#include <analysis/VariableManager/Manager.h>
11
12#include <analysis/dataobjects/Particle.h>
13#include <analysis/dataobjects/RestOfEvent.h>
14
15#include <mdst/dataobjects/Track.h>
16#include <mdst/dataobjects/ECLCluster.h>
17#include <mdst/dataobjects/KLMCluster.h>
18
19#include "utilities/TestParticleFactory.h"
20using namespace std;
21using namespace Belle2;
22using namespace Belle2::Variable;
23
24namespace {
25
26
27 class InclusiveVariablesTest : public ::testing::Test {
28 protected:
30 void SetUp() override
31 {
32
34 StoreArray<ECLCluster> myECLClusters;
35 StoreArray<KLMCluster> myKLMClusters;
37 StoreArray<Track> myTracks;
38 StoreArray<Particle> myParticles;
40 StoreArray<PIDLikelihood> myPIDLikelihoods;
41 myECLClusters.registerInDataStore();
42 myKLMClusters.registerInDataStore();
43 myTFRs.registerInDataStore();
44 myTracks.registerInDataStore();
45 myParticles.registerInDataStore();
46 myROEs.registerInDataStore();
47 myPIDLikelihoods.registerInDataStore();
48 myParticles.registerRelationTo(myROEs);
49 myTracks.registerRelationTo(myPIDLikelihoods);
51
53 ROOT::Math::XYZVector ipposition(0, 0, 0);
54 ROOT::Math::PxPyPzEVector b0momentum(3, 0, 0, 5);
55 factory.produceParticle(string("^B0 -> [^K*0 -> [^K_S0 -> ^pi+ ^pi-] [^pi0 -> ^gamma ^gamma]] ^e+ ^e-"),
56 b0momentum, ipposition);
57 }
58
60 void TearDown() override
61 {
63 }
64 };
65 TEST_F(InclusiveVariablesTest, nCompositeDaughters)
66 {
67 StoreArray<Particle> myParticles;
68 auto* var = Manager::Instance().getVariable("nCompositeDaughters()");
69 EXPECT_EQ(std::get<int>(var->function(myParticles[9])), 1);
70 var = Manager::Instance().getVariable("nCompositeDaughters(313)");
71 EXPECT_EQ(std::get<int>(var->function(myParticles[9])), 1);
72 var = Manager::Instance().getVariable("nCompositeDaughters(111)");
73 EXPECT_EQ(std::get<int>(var->function(myParticles[9])), 0);
74 var = Manager::Instance().getVariable("nCompositeDaughters(310)");
75 EXPECT_EQ(std::get<int>(var->function(myParticles[9])), 0);
76 }
77 TEST_F(InclusiveVariablesTest, nCompositeAllGenerationDaughters)
78 {
79 StoreArray<Particle> myParticles;
80 auto* var = Manager::Instance().getVariable("nCompositeAllGenerationDaughters()");
81 EXPECT_EQ(std::get<int>(var->function(myParticles[9])), 3);
82 var = Manager::Instance().getVariable("nCompositeAllGenerationDaughters(313)");
83 EXPECT_EQ(std::get<int>(var->function(myParticles[9])), 1);
84 var = Manager::Instance().getVariable("nCompositeAllGenerationDaughters(111)");
85 EXPECT_EQ(std::get<int>(var->function(myParticles[9])), 1);
86 var = Manager::Instance().getVariable("nCompositeAllGenerationDaughters(310)");
87 EXPECT_EQ(std::get<int>(var->function(myParticles[9])), 1);
88 }
89 TEST_F(InclusiveVariablesTest, nPhotonDaughters)
90 {
91 StoreArray<Particle> myParticles;
92 auto* var = Manager::Instance().getVariable("nDaughterPhotons");
93 EXPECT_EQ(std::get<int>(var->function(myParticles[9])), 2);
94 }
95 TEST_F(InclusiveVariablesTest, nDaughterNeutralHadrons)
96 {
97 StoreArray<Particle> myParticles;
98 auto* var = Manager::Instance().getVariable("nDaughterNeutralHadrons");
99 EXPECT_EQ(std::get<int>(var->function(myParticles[9])), 0);
100 }
101 TEST_F(InclusiveVariablesTest, nChargedDaughters)
102 {
103 StoreArray<Particle> myParticles;
104 auto* var = Manager::Instance().getVariable("nDaughterCharged()");
105 EXPECT_EQ(std::get<int>(var->function(myParticles[9])), 4);
106 var = Manager::Instance().getVariable("nDaughterCharged(11)");
107 EXPECT_EQ(std::get<int>(var->function(myParticles[9])), 2);
108 var = Manager::Instance().getVariable("nDaughterCharged(211)");
109 EXPECT_EQ(std::get<int>(var->function(myParticles[9])), 2);
110
111 }
112 TEST_F(InclusiveVariablesTest, daughterAverageOf)
113 {
114 StoreArray<Particle> myParticles;
115 auto* var = Manager::Instance().getVariable("daughterAverageOf(PDG)");
116 EXPECT_FLOAT_EQ(std::get<double>(var->function(myParticles[9])), float(313 + 11 - 11) / 3);
117 }
118
119}
120
static DataStore & Instance()
Instance of singleton Store.
Definition: DataStore.cc:53
void setInitializeActive(bool active)
Setter for m_initializeActive.
Definition: DataStore.cc:93
void reset(EDurability durability)
Frees memory occupied by data store items and removes all objects from the map.
Definition: DataStore.cc:85
bool registerInDataStore(DataStore::EStoreFlags storeFlags=DataStore::c_WriteOut)
Register the object/array in the DataStore.
Accessor to arrays stored in the data store.
Definition: StoreArray.h:113
bool registerRelationTo(const StoreArray< TO > &toArray, DataStore::EDurability durability=DataStore::c_Event, DataStore::EStoreFlags storeFlags=DataStore::c_WriteOut, const std::string &namedRelation="") const
Register a relation to the given StoreArray.
Definition: StoreArray.h:140
const Var * getVariable(std::string name)
Get the variable belonging to the given key.
Definition: Manager.cc:58
static Manager & Instance()
get singleton instance.
Definition: Manager.cc:26
This is a class, which generates DataStore particles, according to the provided decay string e....
const Belle2::Particle * produceParticle(const std::string &decayString, const ROOT::Math::PxPyPzEVector &momentum, const ROOT::Math::XYZVector &vertex)
Main method to produce particles.
Abstract base class for different kinds of events.
STL namespace.