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#include <mdst/dataobjects/PIDLikelihood.h>
19
20#include "utilities/TestParticleFactory.h"
21using namespace std;
22using namespace Belle2;
23using namespace Belle2::Variable;
24
25namespace {
26
27
28 class InclusiveVariablesTest : public ::testing::Test {
29 protected:
31 void SetUp() override
32 {
33
35 StoreArray<ECLCluster> myECLClusters;
36 StoreArray<KLMCluster> myKLMClusters;
37 StoreArray<TrackFitResult> myTFRs;
38 StoreArray<Track> myTracks;
39 StoreArray<Particle> myParticles;
40 StoreArray<RestOfEvent> myROEs;
41 StoreArray<PIDLikelihood> myPIDLikelihoods;
42 myECLClusters.registerInDataStore();
43 myKLMClusters.registerInDataStore();
44 myTFRs.registerInDataStore();
45 myTracks.registerInDataStore();
46 myParticles.registerInDataStore();
47 myROEs.registerInDataStore();
48 myPIDLikelihoods.registerInDataStore();
49 myParticles.registerRelationTo(myROEs);
50 myTracks.registerRelationTo(myPIDLikelihoods);
52
53 TestUtilities::TestParticleFactory factory;
54 ROOT::Math::XYZVector ipposition(0, 0, 0);
55 ROOT::Math::PxPyPzEVector b0momentum(3, 0, 0, 5);
56 factory.produceParticle(string("^B0 -> [^K*0 -> [^K_S0 -> ^pi+ ^pi-] [^pi0 -> ^gamma ^gamma]] ^e+ ^e-"),
57 b0momentum, ipposition);
58 }
59
61 void TearDown() override
62 {
64 }
65 };
66 TEST_F(InclusiveVariablesTest, nCompositeDaughters)
67 {
68 StoreArray<Particle> myParticles;
69 auto* var = Manager::Instance().getVariable("nCompositeDaughters()");
70 EXPECT_EQ(std::get<int>(var->function(myParticles[9])), 1);
71 var = Manager::Instance().getVariable("nCompositeDaughters(313)");
72 EXPECT_EQ(std::get<int>(var->function(myParticles[9])), 1);
73 var = Manager::Instance().getVariable("nCompositeDaughters(111)");
74 EXPECT_EQ(std::get<int>(var->function(myParticles[9])), 0);
75 var = Manager::Instance().getVariable("nCompositeDaughters(310)");
76 EXPECT_EQ(std::get<int>(var->function(myParticles[9])), 0);
77 }
78 TEST_F(InclusiveVariablesTest, nCompositeAllGenerationDaughters)
79 {
80 StoreArray<Particle> myParticles;
81 auto* var = Manager::Instance().getVariable("nCompositeAllGenerationDaughters()");
82 EXPECT_EQ(std::get<int>(var->function(myParticles[9])), 3);
83 var = Manager::Instance().getVariable("nCompositeAllGenerationDaughters(313)");
84 EXPECT_EQ(std::get<int>(var->function(myParticles[9])), 1);
85 var = Manager::Instance().getVariable("nCompositeAllGenerationDaughters(111)");
86 EXPECT_EQ(std::get<int>(var->function(myParticles[9])), 1);
87 var = Manager::Instance().getVariable("nCompositeAllGenerationDaughters(310)");
88 EXPECT_EQ(std::get<int>(var->function(myParticles[9])), 1);
89 }
90 TEST_F(InclusiveVariablesTest, nPhotonDaughters)
91 {
92 StoreArray<Particle> myParticles;
93 auto* var = Manager::Instance().getVariable("nDaughterPhotons");
94 EXPECT_EQ(std::get<int>(var->function(myParticles[9])), 2);
95 }
96 TEST_F(InclusiveVariablesTest, nDaughterNeutralHadrons)
97 {
98 StoreArray<Particle> myParticles;
99 auto* var = Manager::Instance().getVariable("nDaughterNeutralHadrons");
100 EXPECT_EQ(std::get<int>(var->function(myParticles[9])), 0);
101 }
102 TEST_F(InclusiveVariablesTest, nChargedDaughters)
103 {
104 StoreArray<Particle> myParticles;
105 auto* var = Manager::Instance().getVariable("nDaughterCharged()");
106 EXPECT_EQ(std::get<int>(var->function(myParticles[9])), 4);
107 var = Manager::Instance().getVariable("nDaughterCharged(11)");
108 EXPECT_EQ(std::get<int>(var->function(myParticles[9])), 2);
109 var = Manager::Instance().getVariable("nDaughterCharged(211)");
110 EXPECT_EQ(std::get<int>(var->function(myParticles[9])), 2);
111
112 }
113 TEST_F(InclusiveVariablesTest, daughterAverageOf)
114 {
115 StoreArray<Particle> myParticles;
116 auto* var = Manager::Instance().getVariable("daughterAverageOf(PDG)");
117 EXPECT_FLOAT_EQ(std::get<double>(var->function(myParticles[9])), float(313 + 11 - 11) / 3);
118 }
119
120}
121
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
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.