8#include <gtest/gtest.h>
9#include <framework/utilities/TestHelpers.h>
10#include "utilities/TestParticleFactory.h"
11#include <analysis/dataobjects/Particle.h>
12#include <analysis/VariableManager/Manager.h>
13#include <analysis/dataobjects/RestOfEvent.h>
15#include <analysis/VariableManager/Utility.h>
16#include <analysis/utility/PCmsLabTransform.h>
17#include <analysis/utility/ReferenceFrame.h>
19#include <framework/datastore/StoreArray.h>
20#include <framework/logging/Logger.h>
21#include <mdst/dataobjects/Track.h>
22#include <mdst/dataobjects/ECLCluster.h>
23#include <mdst/dataobjects/KLMCluster.h>
24#include <framework/gearbox/Gearbox.h>
28using namespace Belle2::Variable;
29using namespace ROOT::Math;
32 class ROETest :
public ::testing::Test {
58 ROOT::Math::XYZVector ipposition(0, 0, 0);
59 PxPyPzEVector ksmomentum(1, 0, 0, 3);
60 ROOT::Math::XYZVector ksposition(1.0, 0, 0);
64 auto* ksParticle = factory.
produceParticle(
string(
"^K_S0 -> ^pi+ ^pi-"), ksmomentum, ksposition);
65 PxPyPzEVector d0momentum(-2, 0, 0, 4);
66 auto* d0Particle = factory.
produceParticle(
string(
"^D0 -> ^K+ ^pi-"), d0momentum, ipposition);
67 PxPyPzEVector pi0momentum(-0.2, 0, 0, 1);
68 auto* pi0Particle = factory.
produceParticle(
string(
"^pi0 -> ^gamma ^gamma"), pi0momentum, ipposition);
69 PxPyPzEVector b0momentum(3, 0, 0, 5);
70 factory.
produceParticle(
string(
"^B0 -> [^K_S0 -> ^pi+ ^pi-] [^pi0 -> ^gamma ^gamma] ^gamma"), b0momentum, ipposition);
73 vector<const Particle*> roeParticles;
74 roeParticles.push_back(ksParticle->getDaughter(0));
75 roeParticles.push_back(ksParticle->getDaughter(1));
76 roeParticles.push_back(d0Particle->getDaughter(0));
77 roeParticles.push_back(d0Particle->getDaughter(1));
78 roeParticles.push_back(pi0Particle->getDaughter(0));
79 roeParticles.push_back(pi0Particle->getDaughter(1));
83 std::shared_ptr<Variable::Cut> trackSelection = std::shared_ptr<Variable::Cut>(
Variable::Cut::compile(
"p > 1.5"));
85 std::shared_ptr<Variable::Cut> eclSelection = std::shared_ptr<Variable::Cut>(
Variable::Cut::compile(
"p > 1"));
88 vector<const Particle*> excludeParticles = {ksParticle->getDaughter(1), d0Particle->getDaughter(0)};
101 void TearDown()
override
107 TEST_F(ROETest, hasParticle)
110 gearbox.setBackends({std::string(
"file:")});
112 gearbox.open(
"geometry/Belle2.xml",
false);
130 TEST_F(ROETest, useROERecoilFrame)
133 gearbox.setBackends({std::string(
"file:")});
135 gearbox.open(
"geometry/Belle2.xml",
false);
143 myParticles[14]->addRelationTo(myROEs[0]);
144 myROEObject.
assign(myROEs[0]);
154 ASSERT_NE(var,
nullptr);
155 EXPECT_FLOAT_EQ(std::get<double>(var->function(myParticles[5])),
156 frame.getMomentum(myParticles[5]->get4Vector()).P());
157 EXPECT_FLOAT_EQ(std::get<double>(var->function(myParticles[14])),
158 frame.getMomentum(myParticles[14]->get4Vector()).P());
160 ASSERT_NE(var,
nullptr);
161 EXPECT_FLOAT_EQ(std::get<double>(var->function(myParticles[5])),
162 frame.getMomentum(myParticles[5]->get4Vector()).E());
163 EXPECT_FLOAT_EQ(std::get<double>(var->function(myParticles[14])),
164 frame.getMomentum(myParticles[14]->get4Vector()).E());
171 TEST_F(ROETest, getParticles)
184 TEST_F(ROETest, updateMaskWithCuts)
190 EXPECT_FALSE(roe->
hasParticle(myParticles[0],
"cutMask"));
191 EXPECT_FALSE(roe->
hasParticle(myParticles[1],
"cutMask"));
192 EXPECT_TRUE(roe->
hasParticle(myParticles[3],
"cutMask"));
193 EXPECT_TRUE(roe->
hasParticle(myParticles[4],
"cutMask"));
194 EXPECT_FALSE(roe->
hasParticle(myParticles[6],
"cutMask"));
195 EXPECT_FALSE(roe->
hasParticle(myParticles[7],
"cutMask"));
197 TEST_F(ROETest, excludeParticlesFromMask)
203 EXPECT_TRUE(roe->
hasParticle(myParticles[0],
"excludeMask"));
204 EXPECT_FALSE(roe->
hasParticle(myParticles[1],
"excludeMask"));
205 EXPECT_FALSE(roe->
hasParticle(myParticles[3],
"excludeMask"));
206 EXPECT_TRUE(roe->
hasParticle(myParticles[4],
"excludeMask"));
207 EXPECT_TRUE(roe->
hasParticle(myParticles[6],
"excludeMask"));
208 EXPECT_TRUE(roe->
hasParticle(myParticles[7],
"excludeMask"));
210 EXPECT_TRUE(!roe->
hasParticle(myParticles[0],
"keepMask"));
211 EXPECT_FALSE(!roe->
hasParticle(myParticles[1],
"keepMask"));
212 EXPECT_FALSE(!roe->
hasParticle(myParticles[3],
"keepMask"));
213 EXPECT_TRUE(!roe->
hasParticle(myParticles[4],
"keepMask"));
215 EXPECT_TRUE(roe->
hasParticle(myParticles[6],
"keepMask"));
216 EXPECT_TRUE(roe->
hasParticle(myParticles[7],
"keepMask"));
218 TEST_F(ROETest, updateMaskWithV0)
224 EXPECT_TRUE(roe->
hasParticle(myParticles[0],
"V0Mask"));
225 EXPECT_TRUE(roe->
hasParticle(myParticles[1],
"V0Mask"));
226 EXPECT_TRUE(roe->
hasParticle(myParticles[3],
"V0Mask"));
227 EXPECT_TRUE(roe->
hasParticle(myParticles[4],
"V0Mask"));
228 EXPECT_TRUE(roe->
hasParticle(myParticles[6],
"V0Mask"));
229 EXPECT_TRUE(roe->
hasParticle(myParticles[7],
"V0Mask"));
231 auto v0maskParticles = roe->
getParticles(
"V0Mask",
false);
233 auto v0maskParticlesUnpacked = roe->
getParticles(
"V0Mask",
true);
234 B2INFO(
"packed size is " << v0maskParticles.size());
235 for (
auto* particle : v0maskParticles) {
236 B2INFO(
"My pdg: " << particle->getPDGCode());
238 B2INFO(
"unpacked size is " << v0maskParticlesUnpacked.size());
239 for (
auto* particle : v0maskParticlesUnpacked) {
240 B2INFO(
"My pdg: " << particle->getPDGCode());
242 EXPECT_FLOAT_EQ(v0maskParticles.size(), 5);
243 EXPECT_FLOAT_EQ(v0maskParticlesUnpacked.size(), 6);
246 TEST_F(ROETest, maskNamingConventions)
250 EXPECT_B2FATAL(roe.
initializeMask(
"clean-mask",
"maskNamingConventionTest"));
251 EXPECT_B2FATAL(roe.
initializeMask(
"1mask",
"maskNamingConventionTest"));
252 EXPECT_B2FATAL(roe.
initializeMask(
"",
"maskNamingConventionTest"));
253 EXPECT_B2FATAL(roe.
initializeMask(
"all",
"maskNamingConventionTest"));
256 EXPECT_TRUE(roe.
hasMask(
"Clean_mask"));
259 EXPECT_TRUE(roe.
hasMask(
"cl3an_mask"));
@ c_DontWriteOut
Object/array should be NOT saved by output modules.
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.
StoreEntry * getEntry(const StoreAccessorBase &accessor)
Check whether an entry with the correct type is registered in the DataStore map and return it.
Singleton class responsible for loading detector parameters from an XML file.
static std::unique_ptr< GeneralCut > compile(const std::string &cut)
Creates an instance of a cut and returns a unique_ptr to it, if you need a copy-able object instead y...
Class to store reconstructed particles.
Rest frame of a particle.
This is a general purpose class for collecting reconstructed MDST data objects that are not used in r...
std::vector< const Particle * > getParticles(const std::string &maskName=c_defaultMaskName, bool unpackComposite=true) const
Get all Particles from ROE mask.
std::vector< const Particle * > getChargedParticles(const std::string &maskName=c_defaultMaskName, unsigned int pdg=0, bool unpackComposite=true) const
Get charged particles from ROE mask.
void print(const std::string &maskName=c_defaultMaskName, bool unpackComposite=true) const
Prints the contents of a RestOfEvent object to screen.
void initializeMask(const std::string &name, const std::string &origin="unknown")
Initialize new mask.
void updateMaskWithCuts(const std::string &name, const std::shared_ptr< Variable::Cut > &trackCut=nullptr, const std::shared_ptr< Variable::Cut > &eclCut=nullptr, const std::shared_ptr< Variable::Cut > &klmCut=nullptr, bool updateExisting=false)
Update mask with cuts.
bool hasMask(const std::string &name) const
True if this ROE object has mask.
std::vector< const Particle * > getPhotons(const std::string &maskName=c_defaultMaskName, bool unpackComposite=true) const
Get photons from ROE mask.
bool hasParticle(const Particle *particle, const std::string &maskName=c_defaultMaskName) const
Check if ROE has StoreArray index of given to the list of unused tracks in the event.
void addParticles(const std::vector< const Particle * > &particle)
Add StoreArray indices of given Particles to the list of unused particles in the event.
void updateMaskWithV0(const std::string &name, const Particle *particleV0)
Update mask with composite particle.
std::vector< const Particle * > getHadrons(const std::string &maskName=c_defaultMaskName, bool unpackComposite=true) const
Get hadrons from ROE mask.
void excludeParticlesFromMask(const std::string &maskName, const std::vector< const Particle * > &particles, Particle::EParticleSourceObject listType, bool discard)
Update mask by keeping or excluding particles.
bool assign(TObject *object, bool replace=false)
Assign 'object' to this accessor.
bool registerInDataStore(DataStore::EStoreFlags storeFlags=DataStore::c_WriteOut)
Register the object/array in the DataStore.
Accessor to arrays stored in the data store.
T * appendNew()
Construct a new T object at the end of the array.
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.
Type-safe access to single objects in the data store.
const Var * getVariable(std::string name)
Get the variable belonging to the given key.
static Manager & Instance()
get singleton instance.
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.
static Gearbox & getInstance()
Return reference to the Gearbox instance.
Abstract base class for different kinds of events.
TObject * object
The pointer to the actual object.
A variable returning a floating-point value for a given Particle.