Belle II Software light-2406-ragdoll
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 <TMatrixFSym.h>
11#include <TRandom3.h>
12#include <TMath.h>
13
14#include <analysis/VariableManager/Manager.h>
15#include <analysis/VariableManager/Utility.h>
16
17#include <analysis/dataobjects/Particle.h>
18#include <analysis/dataobjects/ParticleExtraInfoMap.h>
19#include <analysis/dataobjects/ParticleList.h>
20#include <framework/dataobjects/EventExtraInfo.h>
21#include <analysis/dataobjects/RestOfEvent.h>
22#include <analysis/utility/ReferenceFrame.h>
23#include <framework/datastore/StoreArray.h>
24#include <framework/datastore/StoreObjPtr.h>
25#include <framework/utilities/TestHelpers.h>
26#include <framework/logging/Logger.h>
27#include <framework/gearbox/Gearbox.h>
28
29#include <mdst/dataobjects/Track.h>
30#include <mdst/dataobjects/ECLCluster.h>
31#include <mdst/dataobjects/KLMCluster.h>
32
33#include <analysis/variables/Variables.h>
34
35#include "utilities/TestParticleFactory.h"
36using namespace std;
37using namespace Belle2;
38using namespace Belle2::Variable;
39
40namespace {
41
42
43 class InclusiveVariablesTest : public ::testing::Test {
44 protected:
46 void SetUp() override
47 {
48
50 StoreArray<ECLCluster> myECLClusters;
51 StoreArray<KLMCluster> myKLMClusters;
53 StoreArray<Track> myTracks;
54 StoreArray<Particle> myParticles;
56 StoreArray<PIDLikelihood> myPIDLikelihoods;
57 myECLClusters.registerInDataStore();
58 myKLMClusters.registerInDataStore();
59 myTFRs.registerInDataStore();
60 myTracks.registerInDataStore();
61 myParticles.registerInDataStore();
62 myROEs.registerInDataStore();
63 myPIDLikelihoods.registerInDataStore();
64 myParticles.registerRelationTo(myROEs);
65 myTracks.registerRelationTo(myPIDLikelihoods);
67
69 ROOT::Math::XYZVector ipposition(0, 0, 0);
70 ROOT::Math::PxPyPzEVector b0momentum(3, 0, 0, 5);
71 factory.produceParticle(string("^B0 -> [^K*0 -> [^K_S0 -> ^pi+ ^pi-] [^pi0 -> ^gamma ^gamma]] ^e+ ^e-"),
72 b0momentum, ipposition);
73 }
74
76 void TearDown() override
77 {
79 }
80 };
81 TEST_F(InclusiveVariablesTest, nCompositeDaughters)
82 {
83 StoreArray<Particle> myParticles;
84 auto* var = Manager::Instance().getVariable("nCompositeDaughters()");
85 EXPECT_EQ(std::get<int>(var->function(myParticles[9])), 1);
86 var = Manager::Instance().getVariable("nCompositeDaughters(313)");
87 EXPECT_EQ(std::get<int>(var->function(myParticles[9])), 1);
88 var = Manager::Instance().getVariable("nCompositeDaughters(111)");
89 EXPECT_EQ(std::get<int>(var->function(myParticles[9])), 0);
90 var = Manager::Instance().getVariable("nCompositeDaughters(310)");
91 EXPECT_EQ(std::get<int>(var->function(myParticles[9])), 0);
92 }
93 TEST_F(InclusiveVariablesTest, nCompositeAllGenerationDaughters)
94 {
95 StoreArray<Particle> myParticles;
96 auto* var = Manager::Instance().getVariable("nCompositeAllGenerationDaughters()");
97 EXPECT_EQ(std::get<int>(var->function(myParticles[9])), 3);
98 var = Manager::Instance().getVariable("nCompositeAllGenerationDaughters(313)");
99 EXPECT_EQ(std::get<int>(var->function(myParticles[9])), 1);
100 var = Manager::Instance().getVariable("nCompositeAllGenerationDaughters(111)");
101 EXPECT_EQ(std::get<int>(var->function(myParticles[9])), 1);
102 var = Manager::Instance().getVariable("nCompositeAllGenerationDaughters(310)");
103 EXPECT_EQ(std::get<int>(var->function(myParticles[9])), 1);
104 }
105 TEST_F(InclusiveVariablesTest, nPhotonDaughters)
106 {
107 StoreArray<Particle> myParticles;
108 auto* var = Manager::Instance().getVariable("nDaughterPhotons");
109 EXPECT_EQ(std::get<int>(var->function(myParticles[9])), 2);
110 }
111 TEST_F(InclusiveVariablesTest, nDaughterNeutralHadrons)
112 {
113 StoreArray<Particle> myParticles;
114 auto* var = Manager::Instance().getVariable("nDaughterNeutralHadrons");
115 EXPECT_EQ(std::get<int>(var->function(myParticles[9])), 0);
116 }
117 TEST_F(InclusiveVariablesTest, nChargedDaughters)
118 {
119 StoreArray<Particle> myParticles;
120 auto* var = Manager::Instance().getVariable("nDaughterCharged()");
121 EXPECT_EQ(std::get<int>(var->function(myParticles[9])), 4);
122 var = Manager::Instance().getVariable("nDaughterCharged(11)");
123 EXPECT_EQ(std::get<int>(var->function(myParticles[9])), 2);
124 var = Manager::Instance().getVariable("nDaughterCharged(211)");
125 EXPECT_EQ(std::get<int>(var->function(myParticles[9])), 2);
126
127 }
128 TEST_F(InclusiveVariablesTest, daughterAverageOf)
129 {
130 StoreArray<Particle> myParticles;
131 auto* var = Manager::Instance().getVariable("daughterAverageOf(PDG)");
132 EXPECT_FLOAT_EQ(std::get<double>(var->function(myParticles[9])), float(313 + 11 - 11) / 3);
133 }
134
135}
136
static DataStore & Instance()
Instance of singleton Store.
Definition: DataStore.cc:54
void setInitializeActive(bool active)
Setter for m_initializeActive.
Definition: DataStore.cc:94
void reset(EDurability durability)
Frees memory occupied by data store items and removes all objects from the map.
Definition: DataStore.cc:86
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:57
static Manager & Instance()
get singleton instance.
Definition: Manager.cc:25
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.
Definition: ClusterUtils.h:24
STL namespace.