12 #include <gtest/gtest.h>
15 #include <analysis/ParticleCombiner/ParticleCombiner.h>
18 #include <analysis/VariableManager/Manager.h>
19 #include <analysis/dataobjects/Particle.h>
20 #include <analysis/dataobjects/ParticleList.h>
23 #include <mdst/dataobjects/ECLCluster.h>
24 #include <mdst/dataobjects/KLMCluster.h>
25 #include <mdst/dataobjects/Track.h>
28 #include <framework/datastore/StoreArray.h>
29 #include <framework/datastore/StoreObjPtr.h>
30 #include <framework/utilities/TestHelpers.h>
31 #include <framework/gearbox/Const.h>
32 #include <framework/gearbox/Gearbox.h>
35 using namespace Belle2::Variable;
40 class ECLVariableTest :
public ::testing::Test {
50 particles.registerInDataStore();
54 tracks.registerInDataStore();
61 tracks.registerRelationTo(eclclusters);
67 tracks.appendNew(
Track());
72 tracks.appendNew(
Track());
73 tracks.appendNew(
Track());
78 auto CDCValue =
static_cast<unsigned long long int>(0x300000000000000);
80 for (
int i = 0; i < tracks.getEntries(); ++i) {
81 int charge = (i % 2 == 0) ? +1 : -1;
82 TVector2 d(generator.Uniform(-1, 1), generator.Uniform(-1, 1));
83 TVector2 pt(generator.Uniform(-1, 1), generator.Uniform(-1, 1));
84 d.Set(d.X(), -(d.X()*pt.Px()) / pt.Py());
85 TVector3 position(d.X(), d.Y(), generator.Uniform(-1, 1));
86 TVector3 momentum(pt.Px(), pt.Py(), generator.Uniform(-1, 1));
87 trackFits.
appendNew(position, momentum, cov6, charge,
Const::pion, 0.5, 1.5, CDCValue, 16777215, 0);
130 t1->addRelationTo(e4);
137 t2->addRelationTo(e5);
144 t3->addRelationTo(e6);
153 void TearDown()
override
159 TEST_F(ECLVariableTest, b2bKinematicsTest)
168 gearbox.setBackends({std::string(
"file:")});
170 gearbox.open(
"geometry/Belle2.xml",
false);
180 gammalist->initialize(22, gammalist.getName());
183 for (
int i = 0; i < eclclusters.
getEntries(); ++i) {
184 if (!eclclusters[i]->isTrack()) {
186 gammalist->addParticle(p);
197 EXPECT_EQ(gammalist->getListSize(), 3);
199 EXPECT_FLOAT_EQ(b2bClusterTheta->function(gammalist->getParticle(0)), 3.0276606);
200 EXPECT_FLOAT_EQ(b2bClusterPhi->function(gammalist->getParticle(0)), 0.0);
201 EXPECT_FLOAT_EQ(b2bClusterTheta->function(gammalist->getParticle(1)), 1.6036042);
202 EXPECT_FLOAT_EQ(b2bClusterPhi->function(gammalist->getParticle(1)), -1.0607308);
203 EXPECT_FLOAT_EQ(b2bClusterTheta->function(gammalist->getParticle(2)), 2.7840068);
204 EXPECT_FLOAT_EQ(b2bClusterPhi->function(gammalist->getParticle(2)), -1.3155469);
207 ASSERT_TRUE(std::isnan(b2bClusterTheta->function(noclustertrack)));
208 ASSERT_TRUE(std::isnan(b2bClusterPhi->function(noclustertrack)));
215 EXPECT_FLOAT_EQ(b2bClusterTheta->function(gammalist->getParticle(0)),
216 b2bTheta->function(gammalist->getParticle(0)));
217 EXPECT_FLOAT_EQ(b2bClusterPhi->function(gammalist->getParticle(0)),
218 b2bPhi->function(gammalist->getParticle(0)));
221 TEST_F(ECLVariableTest, clusterKinematicsTest)
230 gearbox.setBackends({std::string(
"file:")});
232 gearbox.open(
"geometry/Belle2.xml",
false);
242 gammalist->initialize(22, gammalist.getName());
245 for (
int i = 0; i < eclclusters.
getEntries(); ++i) {
246 if (!eclclusters[i]->isTrack()) {
248 gammalist->addParticle(p);
258 EXPECT_FLOAT_EQ(clusterPhi->
function(gammalist->getParticle(1)), 2.0);
259 EXPECT_FLOAT_EQ(clusterPhiCMS->
function(gammalist->getParticle(1)), 2.042609);
260 EXPECT_FLOAT_EQ(clusterTheta->
function(gammalist->getParticle(1)), 1.0);
261 EXPECT_FLOAT_EQ(clusterThetaCMS->
function(gammalist->getParticle(1)), 1.2599005);
264 EXPECT_FLOAT_EQ(clusterPhi->
function(gammalist->getParticle(0)), eclclusters[0]->getPhi());
265 EXPECT_FLOAT_EQ(clusterTheta->
function(gammalist->getParticle(0)), eclclusters[0]->getTheta());
268 TEST_F(ECLVariableTest, HypothesisVariables)
282 gammalist->initialize(22, gammalist.getName());
285 for (
int i = 0; i < eclclusters.
getEntries(); ++i)
286 if (!eclclusters[i]->isTrack()) {
288 gammalist->addParticle(p);
296 for (
size_t i = 0; i < gammalist->getListSize(); ++i) {
297 EXPECT_FLOAT_EQ(vHasNPhotons->
function(gammalist->getParticle(i)), 1.0);
299 EXPECT_FLOAT_EQ(vHasNeutHadr->
function(gammalist->getParticle(i)), 1.0);
301 EXPECT_FLOAT_EQ(vHasNeutHadr->
function(gammalist->getParticle(i)), 0.0);
306 TEST_F(ECLVariableTest, IsFromECL)
316 for (
int i = 0; i < eclclusters.
getEntries(); ++i)
317 if (!eclclusters[i]->isTrack()) {
319 EXPECT_TRUE(vIsFromECL->
function(p));
320 EXPECT_FALSE(vIsFromKLM->
function(p));
321 EXPECT_FALSE(vIsFromTrack->
function(p));
322 EXPECT_FALSE(vIsFromV0->
function(p));
326 TEST_F(ECLVariableTest, ECLThetaAndPhiId)
339 clusters[0]->setMaxECellId(1);
340 EXPECT_FLOAT_EQ(clusterThetaID->
function(p), 0);
341 EXPECT_FLOAT_EQ(clusterPhiID->
function(p), 0);
344 clusters[0]->setMaxECellId(6903);
345 EXPECT_FLOAT_EQ(clusterThetaID->
function(p), 52);
346 EXPECT_FLOAT_EQ(clusterPhiID->
function(p), 134);
349 clusters[0]->setMaxECellId(8457);
350 EXPECT_FLOAT_EQ(clusterThetaID->
function(p), 65);
351 EXPECT_FLOAT_EQ(clusterPhiID->
function(p), 8);
356 TEST_F(ECLVariableTest, WholeEventClosure)
377 gammalist->initialize(22, gammalist.getName());
379 pionslist->initialize(211, pionslist.getName());
381 apionslist->initialize(-211, apionslist.getName());
382 apionslist->bindAntiParticleList(*(pionslist));
385 double eclEnergy = 0.0;
386 for (
int i = 0; i < eclclusters.
getEntries(); ++i) {
388 if (!eclclusters[i]->isTrack()) {
390 gammalist->addParticle(p);
396 for (
int i = 0; i < tracks.getEntries(); ++i) {
398 pionslist->addParticle(p);
406 double totalNeutralClusterE = 0.0;
407 for (
size_t i = 0; i < gammalist->getListSize(); ++i)
408 totalNeutralClusterE += vClusterE->
function(gammalist->getParticle(i));
411 double totalTrackClusterE = 0.0;
412 for (
size_t i = 0; i < pionslist->getListSize(); ++i) {
413 double clusterE = vClusterE->
function(pionslist->getParticle(i));
414 double nOtherCl = vClNTrack->
function(pionslist->getParticle(i));
416 totalTrackClusterE += clusterE / nOtherCl;
419 EXPECT_FLOAT_EQ(totalNeutralClusterE + totalTrackClusterE, eclEnergy);
422 TEST_F(ECLVariableTest, eclClusterOnlyInvariantMass)
426 std::vector<int> daughterIndices, daughterIndices_noclst;
432 particles.registerRelationTo(eclclusters_new);
436 const float px_0 = 2.;
437 const float py_0 = 1.;
438 const float pz_0 = 3.;
439 const float px_1 = 1.5;
440 const float py_1 = 1.5;
441 const float pz_1 = 2.5;
443 E_0 = sqrt(pow(px_0, 2) + pow(py_0, 2) + pow(pz_0, 2));
444 E_1 = sqrt(pow(px_1, 2) + pow(py_1, 2) + pow(pz_1, 2));
445 TLorentzVector momentum;
446 TLorentzVector dau0_4vec(px_0, py_0, pz_0, E_0), dau1_4vec(px_1, py_1, pz_1, E_1);
449 Particle dau0_noclst(dau0_4vec, 22);
450 momentum += dau0_noclst.get4Vector();
451 Particle* newDaughter0_noclst = particles.appendNew(dau0_noclst);
452 daughterIndices_noclst.push_back(newDaughter0_noclst->
getArrayIndex());
453 Particle dau1_noclst(dau1_4vec, 22);
454 momentum += dau1_noclst.get4Vector();
455 Particle* newDaughter1_noclst = particles.appendNew(dau1_noclst);
456 daughterIndices_noclst.push_back(newDaughter1_noclst->
getArrayIndex());
463 ASSERT_NE(var,
nullptr);
464 EXPECT_TRUE(std::isnan(var->function(par_noclst)));
471 eclst0->
setTheta(dau0_4vec.Theta());
472 eclst0->
setPhi(dau0_4vec.Phi());
478 eclst1->
setTheta(dau1_4vec.Theta());
479 eclst1->
setPhi(dau1_4vec.Phi());
483 const Particle* newDaughter0 = particles.appendNew(
Particle(eclclusters_new[6]));
485 const Particle* newDaughter1 = particles.appendNew(
Particle(eclclusters_new[7]));
491 EXPECT_FLOAT_EQ(var->function(par), 0.73190731);
494 TEST_F(ECLVariableTest, averageECLTimeQuantities)
512 gammalist->initialize(22, gammalist.getName());
514 pionslist->initialize(111, pionslist.getName());
517 for (
int i = 0; i < eclclusters.
getEntries(); ++i) {
518 if (!eclclusters[i]->isTrack()) {
520 gammalist->addParticle(p);
525 ParticleGenerator combiner_pi0(
"pi0:testPizAllList -> gamma:testGammaAllList gamma:testGammaAllList");
527 while (combiner_pi0.loadNext()) {
528 const Particle& particle = combiner_pi0.getCurrentParticle();
530 particles.appendNew(particle);
531 int iparticle = particles.getEntries() - 1;
533 pionslist->addParticle(iparticle, particle.getPDGCode(), particle.getFlavorType());
541 EXPECT_TRUE(std::isnan(weightedAverageECLTime->function(gammalist->getParticle(0))));
544 EXPECT_FLOAT_EQ(weightedAverageECLTime->function(pionslist->getParticle(0)), 1.2);
547 EXPECT_FLOAT_EQ(maxDist->
function(pionslist->getParticle(0)), 4.0);
550 TEST_F(ECLVariableTest, photonHasOverlap)
571 gammalist->initialize(22, gammalist.getName());
574 for (
int i = 0; i < eclclusters.
getEntries(); ++i) {
575 if (!eclclusters[i]->isTrack()) {
577 gammalist->addParticle(p);
583 pionlist->initialize(211, pionlist.getName());
584 piminuslist.create();
585 piminuslist->initialize(-211, piminuslist.getName());
586 piminuslist->bindAntiParticleList(*(pionlist));
589 for (
int i = 0; i < tracks.getEntries(); ++i) {
591 pionlist->addParticle(p);
597 EXPECT_TRUE(std::isnan(photonHasOverlapNoArgs->
function(particles[0])));
602 EXPECT_TRUE(photonHasOverlapAll->
function(particles[0]));
604 EXPECT_TRUE(std::isnan(photonHasOverlapAll->
function(particles[3])));
609 EXPECT_FALSE(photonHasOverlapBarrel->
function(particles[0]));
612 class KLMVariableTest :
public ::testing::Test {
615 void SetUp()
override
622 particles.registerInDataStore();
626 tracks.registerInDataStore();
633 tracks.registerRelationTo(klmClusters);
640 void TearDown()
override
646 TEST_F(KLMVariableTest, WholeEventClosure)
668 kLongList->initialize(
Const::Klong.getPDGCode(), kLongList.getName());
670 muonsList->initialize(
Const::muon.getPDGCode(), muonsList.getName());
672 amuonsList->initialize(-
Const::muon.getPDGCode(), amuonsList.getName());
673 amuonsList->bindAntiParticleList(*(muonsList));
679 tracks.appendNew(
Track());
680 tracks.appendNew(
Track());
685 auto CDCValue =
static_cast<unsigned long long int>(0x300000000000000);
687 for (
int i = 0; i < tracks.getEntries(); ++i) {
688 int charge = (i % 2 == 0) ? +1 : -1;
689 TVector2 d(generator.Uniform(-1, 1), generator.Uniform(-1, 1));
690 TVector2 pt(generator.Uniform(-1, 1), generator.Uniform(-1, 1));
691 d.Set(d.X(), -(d.X()*pt.Px()) / pt.Py());
692 TVector3 position(d.X(), d.Y(), generator.Uniform(-1, 1));
693 TVector3 momentum(pt.Px(), pt.Py(), generator.Uniform(-1, 1));
694 trackFits.
appendNew(position, momentum, cov6, charge,
Const::muon, 0.5, 1.5, CDCValue, 16777215, 0);
707 klm2->setClusterPosition(1.2, 1.2, 2.0);
709 klm2->setInnermostLayer(2);
710 klm2->setMomentumMag(1.0);
726 t1->addRelationTo(klm4);
735 t2->addRelationTo(klm5);
736 t3->addRelationTo(klm5);
742 double klmMomentum = 0.0;
743 for (
int i = 0; i < klmClusters.
getEntries(); ++i) {
744 klmMomentum += klmClusters[i]->getMomentumMag();
745 if (!klmClusters[i]->getAssociatedTrackFlag()) {
747 kLongList->addParticle(p);
752 for (
int i = 0; i < tracks.getEntries(); ++i) {
754 muonsList->addParticle(p);
762 double totalKLongMomentum = 0.0;
763 for (
size_t i = 0; i < kLongList->getListSize(); ++i)
764 totalKLongMomentum += vClusterP->
function(kLongList->getParticle(i));
767 double totalMuonMomentum = 0.0;
768 for (
size_t i = 0; i < muonsList->getListSize(); ++i) {
769 double muonMomentum = vClusterP->
function(muonsList->getParticle(i));
770 double nOtherCl = vClNTrack->
function(muonsList->getParticle(i));
772 totalMuonMomentum += muonMomentum / nOtherCl;
775 EXPECT_FLOAT_EQ(5.0, klmMomentum);
776 EXPECT_FLOAT_EQ(totalKLongMomentum + totalMuonMomentum, klmMomentum);
779 TEST_F(KLMVariableTest, TrackToKLMClusterMatchingTest)
787 TVector3 position(1.0, 0, 0);
788 TVector3 momentum(0, 1.0, 0);
791 const float pValue = 0.5;
792 const float bField = 1.5;
793 auto CDCValue =
static_cast<unsigned long long int>(0x300000000000000);
794 trackFits.
appendNew(position, momentum, cov6, charge,
Const::muon, pValue, bField, CDCValue, 16777215, 0);
799 Track* muonTrack = tracks.appendNew(myTrack);
810 klm2->setClusterPosition(1.2, 1.2, 2.0);
812 klm2->setInnermostLayer(2);
813 klm2->setMomentumMag(1.0);
820 float distance1 = 11.1;
822 float distance2 = 2.2;
833 EXPECT_POSITIVE(vTrNClusters->
function(muon));
834 EXPECT_FLOAT_EQ(1.0, vClusterInnermostLayer->
function(muon));
835 EXPECT_FLOAT_EQ(distance1, vClusterTrackDistance->
function(muon));
838 trackFits.
appendNew(position, momentum, cov6, charge,
Const::pion, pValue, bField, CDCValue, 16777215, 0);
841 Track* pionTrack = tracks.appendNew(mySecondTrack);
844 EXPECT_FLOAT_EQ(0.0, vTrNClusters->
function(pion));
static const ChargedStable muon
muon particle
static const ChargedStable pion
charged pion particle
static const ParticleType Klong
K^0_L particle.
@ 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.
void addHypothesis(EHypothesisBit bitmask)
Add bitmask to current hypothesis.
void setTheta(double theta)
Set Theta of Shower (radian).
void setConnectedRegionId(int crid)
Set connected region id.
void setPhi(double phi)
Set Phi of Shower (radian).
void setTime(double time)
Set time information.
void setDeltaTime99(double dtime99)
Set 99% time containment range.
void setClusterId(int clusterid)
Set cluster id.
void setHypothesis(EHypothesisBit hypothesis)
Set hypotheses.
void setEnergy(double energy)
Set Corrected Energy (GeV).
void setIsTrack(bool istrack)
Set m_isTrack true if the cluster matches with a track.
@ c_nPhotons
CR is split into n photons (N1)
@ c_neutralHadron
CR is reconstructed as a neutral hadron (N2)
void setR(double r)
Set R (in cm).
Singleton class responsible for loading detector parameters from an XML file.
void setLayers(int layers)
Set number of layers with hits.
void setClusterPosition(float globalX, float globalY, float globalZ)
Set global position.
void setTime(float time)
Set time.
void setInnermostLayer(int innermostLayer)
Set number of the innermost layer with hits.
void setMomentumMag(float momentumMag)
Set momentum magnitude.
ParticleGenerator is a generator for all the particles combined from the given ParticleLists.
Class to store reconstructed particles.
@ c_Unflavored
Is its own antiparticle or we don't know whether it is a particle/antiparticle.
void addRelationTo(const RelationsInterface< BASE > *object, float weight=1.0, const std::string &namedRelation="") const
Add a relation from this object to another object (with caching).
int getArrayIndex() const
Returns this object's array index (in StoreArray), or -1 if not found.
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.
int getEntries() const
Get the number of objects in the array.
Type-safe access to single objects in the data store.
Class that bundles various TrackFitResults.
void setTrackFitResultIndex(const Const::ChargedStable &chargedStable, short index)
Set an index (for positive values) or unavailability-code (with negative values) for a specific mass ...
const Var * getVariable(std::string name)
Get the variable belonging to the given key.
static Manager & Instance()
get singleton instance.
TEST_F(GlobalLabelTest, LargeNumberOfTimeDependentParameters)
Test large number of time-dep params for registration and retrieval.
static Gearbox & getInstance()
Return reference to the Gearbox instance.
double charge(int pdgCode)
Returns electric charge of a particle with given pdg code.
Abstract base class for different kinds of events.
A variable returning a floating-point value for a given Particle.
FunctionPtr function
Pointer to function.