8#include <gtest/gtest.h>
9#include "utilities/TestParticleFactory.h"
11#include <analysis/VariableManager/Manager.h>
12#include <analysis/variables/SpecificKinematicVariables.h>
13#include <analysis/variables/Variables.h>
14#include <analysis/variables/ROEVariables.h>
15#include <analysis/dataobjects/Particle.h>
16#include <analysis/dataobjects/ParticleList.h>
17#include <analysis/utility/PCmsLabTransform.h>
19#include <mdst/dataobjects/Track.h>
20#include <mdst/dataobjects/ECLCluster.h>
21#include <mdst/dataobjects/KLMCluster.h>
23#include <framework/datastore/StoreArray.h>
24#include <framework/logging/Logger.h>
25#include <framework/gearbox/Gearbox.h>
26#include <framework/utilities/TestHelpers.h>
30using namespace Belle2::Variable;
31using namespace ROOT::Math;
34 class ROEVariablesTest :
public ::testing::Test {
65 pi0ParticleList.create();
66 pi0ParticleList->initialize(111,
"pi0:vartest");
67 b0ParticleList.create();
68 b0ParticleList->initialize(521,
"B0:vartest");
73 ROOT::Math::XYZVector ipposition(0, 0, 0);
76 PxPyPzEVector e_momentum(0., 0, halfEcms / 2, halfEcms / 2);
78 PxPyPzEVector p_momentum(0., 0, -halfEcms / 2, halfEcms / 2);
81 PxPyPzEVector b0_momentum(0, 0, 0, halfEcms);
83 factory.
produceParticle(
string(
"^B0 -> e- e+"), b0_momentum, ipposition);
85 myParticles[0]->set4Vector(e_momentum);
86 myParticles[1]->set4Vector(p_momentum);
88 myParticles[0]->print();
89 PxPyPzEVector fsp1_momentum(0., 0, halfEcms / 4, halfEcms / 4);
91 PxPyPzEVector fsp2_momentum(0., 0, -halfEcms / 4, halfEcms / 4);
93 PxPyPzEVector kl_momentum(0., 0, 0.1, 0.5);
95 factory.
produceParticle(
string(
"^B0 -> [pi0 -> gamma gamma] [K_S0 -> pi+ pi-]"), b0_momentum, ipposition);
101 myParticles[3]->set4Vector(fsp1_momentum);
102 myParticles[4]->set4Vector(fsp2_momentum);
103 myECLClusters[0]->setEnergy(fsp1_momentum.E());
104 myECLClusters[1]->setEnergy(fsp2_momentum.E());
105 myParticles[6]->set4Vector(fsp1_momentum);
106 myParticles[7]->set4Vector(fsp2_momentum);
107 myParticles[3]->print();
108 myParticles[4]->print();
109 myParticles[7]->set4Vector(kl_momentum);
110 myParticles[7]->print();
113 vector<const Particle*> roeParticlesToAdd;
115 roeParticlesToAdd.push_back(myParticles[3]);
116 roeParticlesToAdd.push_back(myParticles[4]);
117 roeParticlesToAdd.push_back(myParticles[6]);
118 roeParticlesToAdd.push_back(myParticles[7]);
119 roeParticlesToAdd.push_back(roeKLMParticle);
123 myParticles[2]->addRelationTo(savedROE);
126 std::shared_ptr<Variable::Cut> chargedSelection = std::shared_ptr<Variable::Cut>
128 std::shared_ptr<Variable::Cut> photonSelection = std::shared_ptr<Variable::Cut>
130 std::shared_ptr<Variable::Cut> klSelection = std::shared_ptr<Variable::Cut>
133 savedROE->
updateMaskWithCuts(
"my_mask", chargedSelection, photonSelection, klSelection);
134 savedROE->
print(
"my_mask");
141 void TearDown()
override
150 TEST_F(ROEVariablesTest, ROEParticleCompositionVariables)
153 auto part = myParticles[2];
155 ASSERT_NE(var,
nullptr);
156 EXPECT_FLOAT_EQ(std::get<double>(var->function(part)), 2.0);
159 ASSERT_NE(var,
nullptr);
160 EXPECT_FLOAT_EQ(std::get<double>(var->function(part)), 1.0);
163 ASSERT_NE(var,
nullptr);
164 EXPECT_FLOAT_EQ(std::get<double>(var->function(part)), 2.0);
167 ASSERT_NE(var,
nullptr);
168 EXPECT_FLOAT_EQ(std::get<double>(var->function(part)), 0.0);
171 ASSERT_NE(var,
nullptr);
172 EXPECT_FLOAT_EQ(std::get<double>(var->function(part)), 0.0);
175 ASSERT_NE(var,
nullptr);
176 EXPECT_FLOAT_EQ(std::get<double>(var->function(part)), 1.0);
179 ASSERT_NE(var,
nullptr);
180 EXPECT_FLOAT_EQ(std::get<double>(var->function(part)), 2.0);
183 ASSERT_NE(var,
nullptr);
184 EXPECT_FLOAT_EQ(std::get<double>(var->function(part)), 1.0);
187 ASSERT_NE(var,
nullptr);
188 EXPECT_FLOAT_EQ(std::get<double>(var->function(part)), 1.0);
191 ASSERT_NE(var,
nullptr);
192 EXPECT_FLOAT_EQ(std::get<double>(var->function(part)), 0.0);
198 TEST_F(ROEVariablesTest, ROETrackClusterCompositionVariables)
201 auto part = myParticles[2];
204 ASSERT_NE(var,
nullptr);
205 EXPECT_FLOAT_EQ(std::get<double>(var->function(part)), 2.0);
208 ASSERT_NE(var,
nullptr);
209 EXPECT_FLOAT_EQ(std::get<double>(var->function(part)), 1.0);
212 ASSERT_NE(var,
nullptr);
213 EXPECT_FLOAT_EQ(std::get<double>(var->function(part)), 2.0);
216 ASSERT_NE(var,
nullptr);
217 EXPECT_FLOAT_EQ(std::get<double>(var->function(part)), 2.0);
220 ASSERT_NE(var,
nullptr);
221 EXPECT_FLOAT_EQ(std::get<double>(var->function(part)), 1.0);
224 ASSERT_NE(var,
nullptr);
225 EXPECT_FLOAT_EQ(std::get<double>(var->function(part)), 2.0);
228 ASSERT_NE(var,
nullptr);
229 EXPECT_FLOAT_EQ(std::get<double>(var->function(part)), 1.0);
232 ASSERT_NE(var,
nullptr);
233 EXPECT_FLOAT_EQ(std::get<double>(var->function(part)), 1.0);
238 TEST_F(ROEVariablesTest, ROERecoilFrameVariable)
242 auto part = myParticles[2];
243 auto partNotROE = myParticles[0];
246 ASSERT_NE(var,
nullptr);
247 EXPECT_FLOAT_EQ(std::get<double>(var->function(part)), 5.2986979);
250 roeobjptr.
object = myROEs[0];
251 roeobjptr.
ptr = myROEs[0];
254 ASSERT_NE(var,
nullptr);
255 EXPECT_FLOAT_EQ(std::get<double>(var->function(partNotROE)), 2.801749);
258 roeobjptr.
object =
nullptr;
259 roeobjptr.
ptr =
nullptr;
264 TEST_F(ROEVariablesTest, ROEKinematicsVariables)
267 auto part = myParticles[2];
270 PxPyPzEVector roe4Vec(0, 0, 0, 0);
271 roe4Vec += myParticles[3]->get4Vector();
272 roe4Vec += myParticles[4]->get4Vector();
273 roe4Vec += myParticles[6]->get4Vector();
274 roe4Vec += myParticles[7]->get4Vector();
276 PxPyPzEVector mask4Vec(0, 0, 0, 0);
277 mask4Vec += myParticles[3]->get4Vector();
278 mask4Vec += myParticles[6]->get4Vector();
280 PxPyPzEVector sig4Vec = part->get4Vector();
289 ASSERT_NE(var,
nullptr);
290 EXPECT_FLOAT_EQ(std::get<double>(var->function(part)), 0.0);
293 ASSERT_NE(var,
nullptr);
294 EXPECT_FLOAT_EQ(std::get<double>(var->function(part)), 0.0);
297 ASSERT_NE(var,
nullptr);
298 EXPECT_FLOAT_EQ(std::get<double>(var->function(part)), 1.0);
301 ASSERT_NE(var,
nullptr);
302 EXPECT_FLOAT_EQ(std::get<double>(var->function(part)), myParticles[3]->getEnergy() + myParticles[4]->getEnergy());
305 ASSERT_NE(var,
nullptr);
306 EXPECT_FLOAT_EQ(std::get<double>(var->function(part)), roe4Vec.E());
309 ASSERT_NE(var,
nullptr);
310 EXPECT_FLOAT_EQ(std::get<double>(var->function(part)), roe4VecCMS.E());
313 ASSERT_NE(var,
nullptr);
314 EXPECT_FLOAT_EQ(std::get<double>(var->function(part)), roe4Vec.mag());
317 ASSERT_NE(var,
nullptr);
318 EXPECT_FLOAT_EQ(std::get<double>(var->function(part)), roe4Vec.P());
321 ASSERT_NE(var,
nullptr);
322 EXPECT_FLOAT_EQ(std::get<double>(var->function(part)), roe4VecCMS.P());
325 ASSERT_NE(var,
nullptr);
326 EXPECT_FLOAT_EQ(std::get<double>(var->function(part)), roe4Vec.Theta());
329 ASSERT_NE(var,
nullptr);
330 EXPECT_FLOAT_EQ(std::get<double>(var->function(part)), roe4VecCMS.Theta());
333 ASSERT_NE(var,
nullptr);
334 EXPECT_FLOAT_EQ(std::get<double>(var->function(part)), roe4VecCMS.E() - E0);
337 ASSERT_NE(var,
nullptr);
338 EXPECT_FLOAT_EQ(std::get<double>(var->function(part)), mask4VecCMS.E() - E0);
341 ASSERT_NE(var,
nullptr);
342 EXPECT_FLOAT_EQ(std::get<double>(var->function(part)), TMath::Sqrt(E0 * E0 - roe4VecCMS.P2()));
345 ASSERT_NE(var,
nullptr);
346 EXPECT_FLOAT_EQ(std::get<double>(var->function(part)), TMath::Sqrt(E0 * E0 - mask4VecCMS.P2()));
349 ASSERT_NE(var,
nullptr);
350 EXPECT_FLOAT_EQ(std::get<double>(var->function(part)), mask4VecCMS.E() + sig4VecCMS.E() - E0);
353 ASSERT_NE(var,
nullptr);
354 EXPECT_FLOAT_EQ(std::get<double>(var->function(part)), TMath::Sqrt(E0 * E0 - mask4VecCMS.P2()));
357 ASSERT_NE(var,
nullptr);
358 EXPECT_FLOAT_EQ(std::get<double>(var->function(part)), TMath::Sqrt(E0 * E0 - roe4VecCMS.P2()));
360 PxPyPzEVector miss4VecCMS = - (sig4VecCMS + mask4VecCMS);
361 miss4VecCMS.SetE(2 * E0 - (sig4VecCMS.E() + mask4VecCMS.E()));
364 ASSERT_NE(var,
nullptr);
365 EXPECT_FLOAT_EQ(std::get<double>(var->function(part)), miss4VecCMS.mag2());
368 ASSERT_NE(var,
nullptr);
369 EXPECT_FLOAT_EQ(std::get<double>(var->function(part)), miss4VecCMS.P());
372 ASSERT_NE(var,
nullptr);
373 EXPECT_FLOAT_EQ(std::get<double>(var->function(part)), miss4VecCMS.E());
379 TEST_F(ROEVariablesTest, ROESpecificKinematicVariables)
382 auto part = myParticles[2];
385 ASSERT_NE(var,
nullptr);
386 EXPECT_FLOAT_EQ(std::get<double>(var->function(part)), -0.99899036);
389 ASSERT_NE(var,
nullptr);
390 EXPECT_FLOAT_EQ(std::get<double>(var->function(part)), 0.31122509);
393 ASSERT_NE(var,
nullptr);
394 EXPECT_FLOAT_EQ(std::get<double>(var->function(part)), -1.7763568e-14);
399 ASSERT_NE(var,
nullptr);
400 EXPECT_FLOAT_EQ(std::get<double>(var->function(part)), -1.7763568e-14);
405 TEST_F(ROEVariablesTest, IsInROEVariables)
408 auto part = myParticles[2];
412 roeobjptr.
object = myROEs[0];
413 roeobjptr.
ptr = myROEs[0];
415 auto partROE1 = myParticles[3];
416 auto partROE2 = myParticles[5];
417 auto partROE3 = myParticles[10];
418 auto partROEnotFromMask = myParticles[7];
419 partROEnotFromMask->print();
421 auto partNotROE = myParticles[0];
424 ASSERT_NE(var,
nullptr);
425 EXPECT_EQ(std::get<double>(var->function(partROE1)), 1);
428 ASSERT_NE(var,
nullptr);
429 EXPECT_EQ(std::get<double>(var->function(partROE2)), 1);
432 ASSERT_NE(var,
nullptr);
433 EXPECT_EQ(std::get<double>(var->function(partROE3)), 1);
436 ASSERT_NE(var,
nullptr);
437 EXPECT_EQ(std::get<double>(var->function(partNotROE)), 0);
440 ASSERT_NE(var,
nullptr);
441 EXPECT_EQ(std::get<double>(var->function(partNotROE)), 0);
444 ASSERT_NE(var,
nullptr);
445 EXPECT_FLOAT_EQ(std::get<double>(var->function(partROE1)), 1.0);
448 ASSERT_NE(var,
nullptr);
449 EXPECT_FLOAT_EQ(std::get<double>(var->function(partROE1)), 1.0);
452 ASSERT_NE(var,
nullptr);
453 EXPECT_FLOAT_EQ(std::get<double>(var->function(partNotROE)), 0.0);
456 ASSERT_NE(var,
nullptr);
457 EXPECT_FLOAT_EQ(std::get<double>(var->function(partROEnotFromMask)), 0.0);
460 ASSERT_NE(var,
nullptr);
461 EXPECT_FLOAT_EQ(std::get<double>(var->function(part)), 1.0);
464 ASSERT_NE(var,
nullptr);
465 EXPECT_FLOAT_EQ(std::get<double>(var->function(partROE1)), 1.0);
468 ASSERT_NE(var,
nullptr);
469 EXPECT_FLOAT_EQ(std::get<double>(var->function(partROE1)), 0.0);
472 ASSERT_NE(var,
nullptr);
473 EXPECT_FLOAT_EQ(std::get<double>(var->function(partROE1)), 511.0);
476 roeobjptr.
object =
nullptr;
477 roeobjptr.
ptr =
nullptr;
@ c_DontWriteOut
Object/array should be NOT saved by output modules.
StoreEntryMap & getStoreEntryMap(EDurability durability)
Get a reference to the object/array map.
@ c_Event
Different object in each event, all objects/arrays are invalidated after event() function has been ca...
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.
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.
@ c_Unflavored
Is its own antiparticle or we don't know whether it is a particle/antiparticle.
This is a general purpose class for collecting reconstructed MDST data objects that are not used in r...
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.
void addParticles(const std::vector< const Particle * > &particle)
Add StoreArray indices of given Particles to the list of unused particles in the event.
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.
Abstract base class for different kinds of events.
Wraps a stored array/object, stored under unique (name, durability) key.
TObject * ptr
The pointer to the returned object, either equal to 'object' or null, depending on wether the object ...
TObject * object
The pointer to the actual object.