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>
30 using namespace Belle2::Variable;
31 using namespace ROOT::Math;
34 class ROEVariablesTest :
public ::testing::Test {
42 DataStore::Instance().setInitializeActive(
true);
43 pi0ParticleList.registerInDataStore(DataStore::c_DontWriteOut);
44 b0ParticleList.registerInDataStore(DataStore::c_DontWriteOut);
63 DataStore::Instance().setInitializeActive(
false);
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>
127 (Variable::Cut::compile(
"charge > 0"));
128 std::shared_ptr<Variable::Cut> photonSelection = std::shared_ptr<Variable::Cut>
129 (Variable::Cut::compile(
"p > 1.5"));
130 std::shared_ptr<Variable::Cut> klSelection = std::shared_ptr<Variable::Cut>
131 (Variable::Cut::compile(
"E < 0"));
133 savedROE->
updateMaskWithCuts(
"my_mask", chargedSelection, photonSelection, klSelection);
134 savedROE->
print(
"my_mask");
136 pi0ParticleList->addParticle(5, 111, Particle::c_Unflavored);
137 b0ParticleList->addParticle(2, 521, Particle::c_Unflavored);
141 void TearDown()
override
143 DataStore::Instance().reset();
150 TEST_F(ROEVariablesTest, ROEParticleCompositionVariables)
153 auto part = myParticles[2];
154 auto* var = Manager::Instance().getVariable(
"nROE_Charged()");
155 ASSERT_NE(var,
nullptr);
156 EXPECT_FLOAT_EQ(std::get<double>(var->function(part)), 2.0);
158 var = Manager::Instance().getVariable(
"nROE_Charged(my_mask)");
159 ASSERT_NE(var,
nullptr);
160 EXPECT_FLOAT_EQ(std::get<double>(var->function(part)), 1.0);
162 var = Manager::Instance().getVariable(
"nROE_Charged(all)");
163 ASSERT_NE(var,
nullptr);
164 EXPECT_FLOAT_EQ(std::get<double>(var->function(part)), 2.0);
166 var = Manager::Instance().getVariable(
"nROE_Charged(my_mask, 13)");
167 ASSERT_NE(var,
nullptr);
168 EXPECT_FLOAT_EQ(std::get<double>(var->function(part)), 0.0);
170 var = Manager::Instance().getVariable(
"nROE_Charged(all, 13)");
171 ASSERT_NE(var,
nullptr);
172 EXPECT_FLOAT_EQ(std::get<double>(var->function(part)), 0.0);
174 var = Manager::Instance().getVariable(
"nROE_Charged(my_mask, 211)");
175 ASSERT_NE(var,
nullptr);
176 EXPECT_FLOAT_EQ(std::get<double>(var->function(part)), 1.0);
178 var = Manager::Instance().getVariable(
"nROE_Photons()");
179 ASSERT_NE(var,
nullptr);
180 EXPECT_FLOAT_EQ(std::get<double>(var->function(part)), 2.0);
182 var = Manager::Instance().getVariable(
"nROE_Photons(my_mask)");
183 ASSERT_NE(var,
nullptr);
184 EXPECT_FLOAT_EQ(std::get<double>(var->function(part)), 1.0);
186 var = Manager::Instance().getVariable(
"nROE_NeutralHadrons()");
187 ASSERT_NE(var,
nullptr);
188 EXPECT_FLOAT_EQ(std::get<double>(var->function(part)), 1.0);
190 var = Manager::Instance().getVariable(
"nROE_NeutralHadrons(my_mask)");
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];
203 auto* var = Manager::Instance().getVariable(
"nROE_Tracks()");
204 ASSERT_NE(var,
nullptr);
205 EXPECT_FLOAT_EQ(std::get<double>(var->function(part)), 2.0);
207 var = Manager::Instance().getVariable(
"nROE_Tracks(my_mask)");
208 ASSERT_NE(var,
nullptr);
209 EXPECT_FLOAT_EQ(std::get<double>(var->function(part)), 1.0);
211 var = Manager::Instance().getVariable(
"nROE_Tracks(all)");
212 ASSERT_NE(var,
nullptr);
213 EXPECT_FLOAT_EQ(std::get<double>(var->function(part)), 2.0);
215 var = Manager::Instance().getVariable(
"nROE_ECLClusters()");
216 ASSERT_NE(var,
nullptr);
217 EXPECT_FLOAT_EQ(std::get<double>(var->function(part)), 2.0);
219 var = Manager::Instance().getVariable(
"nROE_ECLClusters(my_mask)");
220 ASSERT_NE(var,
nullptr);
221 EXPECT_FLOAT_EQ(std::get<double>(var->function(part)), 1.0);
223 var = Manager::Instance().getVariable(
"nROE_NeutralECLClusters()");
224 ASSERT_NE(var,
nullptr);
225 EXPECT_FLOAT_EQ(std::get<double>(var->function(part)), 2.0);
227 var = Manager::Instance().getVariable(
"nROE_NeutralECLClusters(my_mask)");
228 ASSERT_NE(var,
nullptr);
229 EXPECT_FLOAT_EQ(std::get<double>(var->function(part)), 1.0);
231 var = Manager::Instance().getVariable(
"nROE_KLMClusters");
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];
245 auto* var = Manager::Instance().getVariable(
"useROERecoilFrame(E)");
246 ASSERT_NE(var,
nullptr);
247 EXPECT_FLOAT_EQ(std::get<double>(var->function(part)), 5.2986979);
249 DataStore::StoreEntry& roeobjptr = DataStore::Instance().getStoreEntryMap(DataStore::c_Event).at(
"RestOfEvent");
250 roeobjptr.
object = myROEs[0];
251 roeobjptr.
ptr = myROEs[0];
253 var = Manager::Instance().getVariable(
"useROERecoilFrame(E)");
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();
288 auto* var = Manager::Instance().getVariable(
"roeCharge()");
289 ASSERT_NE(var,
nullptr);
290 EXPECT_FLOAT_EQ(std::get<double>(var->function(part)), 0.0);
292 var = Manager::Instance().getVariable(
"roeCharge(all)");
293 ASSERT_NE(var,
nullptr);
294 EXPECT_FLOAT_EQ(std::get<double>(var->function(part)), 0.0);
296 var = Manager::Instance().getVariable(
"roeCharge(my_mask)");
297 ASSERT_NE(var,
nullptr);
298 EXPECT_FLOAT_EQ(std::get<double>(var->function(part)), 1.0);
300 var = Manager::Instance().getVariable(
"roeEextra()");
301 ASSERT_NE(var,
nullptr);
302 EXPECT_FLOAT_EQ(std::get<double>(var->function(part)), myParticles[3]->getEnergy() + myParticles[4]->getEnergy());
304 var = Manager::Instance().getVariable(
"roeE()");
305 ASSERT_NE(var,
nullptr);
306 EXPECT_FLOAT_EQ(std::get<double>(var->function(part)), roe4Vec.E());
308 var = Manager::Instance().getVariable(
"useCMSFrame(roeE())");
309 ASSERT_NE(var,
nullptr);
310 EXPECT_FLOAT_EQ(std::get<double>(var->function(part)), roe4VecCMS.E());
312 var = Manager::Instance().getVariable(
"roeM()");
313 ASSERT_NE(var,
nullptr);
314 EXPECT_FLOAT_EQ(std::get<double>(var->function(part)), roe4Vec.mag());
316 var = Manager::Instance().getVariable(
"roeP()");
317 ASSERT_NE(var,
nullptr);
318 EXPECT_FLOAT_EQ(std::get<double>(var->function(part)), roe4Vec.P());
320 var = Manager::Instance().getVariable(
"useCMSFrame(roeP())");
321 ASSERT_NE(var,
nullptr);
322 EXPECT_FLOAT_EQ(std::get<double>(var->function(part)), roe4VecCMS.P());
324 var = Manager::Instance().getVariable(
"roePTheta()");
325 ASSERT_NE(var,
nullptr);
326 EXPECT_FLOAT_EQ(std::get<double>(var->function(part)), roe4Vec.Theta());
328 var = Manager::Instance().getVariable(
"useCMSFrame(roePTheta())");
329 ASSERT_NE(var,
nullptr);
330 EXPECT_FLOAT_EQ(std::get<double>(var->function(part)), roe4VecCMS.Theta());
332 var = Manager::Instance().getVariable(
"roeDeltae()");
333 ASSERT_NE(var,
nullptr);
334 EXPECT_FLOAT_EQ(std::get<double>(var->function(part)), roe4VecCMS.E() - E0);
336 var = Manager::Instance().getVariable(
"roeDeltae(my_mask)");
337 ASSERT_NE(var,
nullptr);
338 EXPECT_FLOAT_EQ(std::get<double>(var->function(part)), mask4VecCMS.E() - E0);
340 var = Manager::Instance().getVariable(
"roeMbc()");
341 ASSERT_NE(var,
nullptr);
342 EXPECT_FLOAT_EQ(std::get<double>(var->function(part)), TMath::Sqrt(E0 * E0 - roe4VecCMS.P2()));
344 var = Manager::Instance().getVariable(
"roeMbc(my_mask)");
345 ASSERT_NE(var,
nullptr);
346 EXPECT_FLOAT_EQ(std::get<double>(var->function(part)), TMath::Sqrt(E0 * E0 - mask4VecCMS.P2()));
348 var = Manager::Instance().getVariable(
"weDeltae(my_mask,0)");
349 ASSERT_NE(var,
nullptr);
350 EXPECT_FLOAT_EQ(std::get<double>(var->function(part)), mask4VecCMS.E() + sig4VecCMS.E() - E0);
352 var = Manager::Instance().getVariable(
"weMbc(my_mask,0)");
353 ASSERT_NE(var,
nullptr);
354 EXPECT_FLOAT_EQ(std::get<double>(var->function(part)), TMath::Sqrt(E0 * E0 - mask4VecCMS.P2()));
356 var = Manager::Instance().getVariable(
"weMbc(all,0)");
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()));
363 var = Manager::Instance().getVariable(
"weMissM2(my_mask,0)");
364 ASSERT_NE(var,
nullptr);
365 EXPECT_FLOAT_EQ(std::get<double>(var->function(part)), miss4VecCMS.mag2());
367 var = Manager::Instance().getVariable(
"weMissP(my_mask,0)");
368 ASSERT_NE(var,
nullptr);
369 EXPECT_FLOAT_EQ(std::get<double>(var->function(part)), miss4VecCMS.P());
371 var = Manager::Instance().getVariable(
"weMissE(my_mask,0)");
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];
384 auto* var = Manager::Instance().getVariable(
"weCosThetaEll()");
385 ASSERT_NE(var,
nullptr);
386 EXPECT_FLOAT_EQ(std::get<double>(var->function(part)), -0.99899036);
388 var = Manager::Instance().getVariable(
"weXiZ()");
389 ASSERT_NE(var,
nullptr);
390 EXPECT_FLOAT_EQ(std::get<double>(var->function(part)), 0.31122509);
392 var = Manager::Instance().getVariable(
"weQ2lnuSimple(my_mask,0)");
393 ASSERT_NE(var,
nullptr);
394 EXPECT_FLOAT_EQ(std::get<double>(var->function(part)), -1.7763568e-14);
398 var = Manager::Instance().getVariable(
"weQ2lnu(my_mask,0)");
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];
411 DataStore::StoreEntry& roeobjptr = DataStore::Instance().getStoreEntryMap(DataStore::c_Event).at(
"RestOfEvent");
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];
423 auto* var = Manager::Instance().getVariable(
"isInRestOfEvent");
424 ASSERT_NE(var,
nullptr);
425 EXPECT_EQ(std::get<double>(var->function(partROE1)), 1);
427 var = Manager::Instance().getVariable(
"isInRestOfEvent");
428 ASSERT_NE(var,
nullptr);
429 EXPECT_EQ(std::get<double>(var->function(partROE2)), 1);
431 var = Manager::Instance().getVariable(
"isInRestOfEvent");
432 ASSERT_NE(var,
nullptr);
433 EXPECT_EQ(std::get<double>(var->function(partROE3)), 1);
435 var = Manager::Instance().getVariable(
"isInRestOfEvent");
436 ASSERT_NE(var,
nullptr);
437 EXPECT_EQ(std::get<double>(var->function(partNotROE)), 0);
439 var = Manager::Instance().getVariable(
"isInRestOfEvent");
440 ASSERT_NE(var,
nullptr);
441 EXPECT_EQ(std::get<double>(var->function(partNotROE)), 0);
443 var = Manager::Instance().getVariable(
"passesROEMask(my_mask)");
444 ASSERT_NE(var,
nullptr);
445 EXPECT_FLOAT_EQ(std::get<double>(var->function(partROE1)), 1.0);
447 var = Manager::Instance().getVariable(
"passesROEMask(all)");
448 ASSERT_NE(var,
nullptr);
449 EXPECT_FLOAT_EQ(std::get<double>(var->function(partROE1)), 1.0);
451 var = Manager::Instance().getVariable(
"passesROEMask(all)");
452 ASSERT_NE(var,
nullptr);
453 EXPECT_FLOAT_EQ(std::get<double>(var->function(partNotROE)), 0.0);
455 var = Manager::Instance().getVariable(
"passesROEMask(my_mask)");
456 ASSERT_NE(var,
nullptr);
457 EXPECT_FLOAT_EQ(std::get<double>(var->function(partROEnotFromMask)), 0.0);
459 var = Manager::Instance().getVariable(
"nROE_ParticlesInList(pi0:vartest)");
460 ASSERT_NE(var,
nullptr);
461 EXPECT_FLOAT_EQ(std::get<double>(var->function(part)), 1.0);
463 var = Manager::Instance().getVariable(
"currentROEIsInList(B0:vartest)");
464 ASSERT_NE(var,
nullptr);
465 EXPECT_FLOAT_EQ(std::get<double>(var->function(partROE1)), 1.0);
467 var = Manager::Instance().getVariable(
"currentROEIsInList(pi0:vartest)");
468 ASSERT_NE(var,
nullptr);
469 EXPECT_FLOAT_EQ(std::get<double>(var->function(partROE1)), 0.0);
471 var = Manager::Instance().getVariable(
"particleRelatedToCurrentROE(PDG)");
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;
Class to store reconstructed particles.
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.
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.
TEST_F(GlobalLabelTest, LargeNumberOfTimeDependentParameters)
Test large number of time-dep params for registration and retrieval.
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.