9#include <analysis/VariableManager/Manager.h>
11#include <analysis/dataobjects/Particle.h>
12#include <analysis/dataobjects/ParticleExtraInfoMap.h>
13#include <analysis/dataobjects/RestOfEvent.h>
14#include <analysis/utility/MCMatching.h>
16#include <framework/datastore/StoreArray.h>
17#include <framework/datastore/StoreObjPtr.h>
18#include <framework/logging/Logger.h>
19#include <framework/gearbox/Gearbox.h>
21#include <mdst/dataobjects/MCParticle.h>
22#include <mdst/dataobjects/PIDLikelihood.h>
23#include <mdst/dataobjects/Track.h>
24#include <mdst/dataobjects/ECLCluster.h>
25#include <mdst/dataobjects/KLMCluster.h>
27#include <gtest/gtest.h>
29#include <TMatrixFSym.h>
33using namespace Belle2::Variable;
37 class FlavorTaggingVariablesTest :
public ::testing::Test {
60 roe.registerInDataStore();
73 void TearDown()
override
80 TEST_F(FlavorTaggingVariablesTest, VariablesRunningForEachROE)
89 gearbox.setBackends({std::string(
"file:")});
91 gearbox.open(
"geometry/Belle2.xml",
false);
101 vector<const Particle*> roeNeutralParticles;
104 vector<vector<int>> roeNeutralECLClusterIds{{4, 1}, {6, 1}, {9, 1}, {12, 1}, {17, 1}};
107 vector<vector<double>> roeNeutralECLClusterProperties{{0.0487526, 0.493606, -2.65695, 239.246},
108 {0.485431, 0.768093, 0.905049, 199.805},
109 {0.436428, 0.99517, 1.6799, 167.271},
110 {0.0230045, 1.05471, -1.20024, 161.013},
111 {0.174332, 1.49141, 1.3059, 141.107}};
114 for (
unsigned i = 0; i < roeNeutralECLClusterIds.size(); ++i) {
118 ROEECL.
setHypothesis(ECLCluster::EHypothesisBit::c_nPhotons);
121 ROEECL.
setEnergy(roeNeutralECLClusterProperties[i][0]);
122 ROEECL.
setTheta(roeNeutralECLClusterProperties[i][1]);
123 ROEECL.
setPhi(roeNeutralECLClusterProperties[i][2]);
124 ROEECL.
setR(roeNeutralECLClusterProperties[i][3]);
127 roeNeutralParticles.push_back(roeECLParticle);
132 vector<const Particle*> roeChargedParticles;
133 const float bField = 1.5;
137 vector<vector<float>> roeTFRProperties{{ -0.578196, 0.252548, 0.158642, -0.520087, -1.19071, 0.417451, 0.139206},
138 {0.00434622, -0.0191058, 0.231542, 0.664887, 0.15125, 0.463762, 0.0313268},
139 {0.0738595, -0.00294903, 0.242319, 0.0186749, 0.467721, 0.288627, 0.0415814},
140 {1.3887, -2.43016, 1.00615, -0.27093, -0.15482, 0.0639155, 0.0132331},
141 {0.0041096, -0.0152487, 0.264326, 0.294061, 0.079251, 0.0389014, 0.00200114},
142 { -0.00371803, -5.22544e-05, 0.210148, 0.0019418, -0.138163, -0.0287232, 0.000622186},
143 {1.02296, 0.608721, 0.32273, -0.0505521, 0.0849532, 0.0839057, 0},
144 {6.49062, 3.20227, 117.684, 0.0469579, -0.0951783, -0.0706371, 0.117562}};
147 vector<short int> roeTRFCharges{1, 1, 1, -1, -1, -1, 1, -1};
150 vector<uint64_t> roeTRFCDCValues{3098476543630901248, 3026418949592973312, 3170534137668829184, 3386706919782612992,
151 3242591731706757120, 2954361355555045376, 1080863910568919040, 504403158265495552};
154 vector<uint32_t> roeTRFVXDValues{5570560, 5592320, 5592320, 5570560, 5592320, 5264640, 328960, 0};
158 vector<vector<int>> roeChargedECLClusterIds{{14, 1}, {10, 1}, {7, 1}, {8, 1}, {15, 1}};
161 vector<vector<double>> roeChargedECLClusterProperties{{0.964336, 1.23481, -2.25428, 148.729},
162 {0.214864, 0.965066, -0.232973, 170.008},
163 {0.0148855, 0.914396, 1.01693, 175.861},
164 {0.524092, 0.956389, 0.854331, 171.378},
165 {0.230255, 1.33317, -1.45326, 144.849}};
167 unsigned int chargedECLCLusterCounter = 0;
170 for (
unsigned i = 0; i < roeTRFCharges.size(); ++i) {
172 ROOT::Math::XYZVector position(roeTFRProperties[i][0], roeTFRProperties[i][1], roeTFRProperties[i][2]);
173 ROOT::Math::XYZVector momentum(roeTFRProperties[i][3], roeTFRProperties[i][4], roeTFRProperties[i][5]);
175 testsTFRs.
appendNew(position, momentum, cov6, roeTRFCharges[i],
Const::pion, roeTFRProperties[i][6], bField, roeTRFCDCValues[i],
176 roeTRFVXDValues[i], 0);
183 if (i == 0 || i == 1 || i == 2 || i == 3) {
186 ROEChargedECL.
setHypothesis(ECLCluster::EHypothesisBit::c_nPhotons);
188 ROEChargedECL.
setClusterId(roeChargedECLClusterIds[chargedECLCLusterCounter][1]);
189 ROEChargedECL.
setEnergy(roeChargedECLClusterProperties[chargedECLCLusterCounter][0]);
190 ROEChargedECL.
setTheta(roeChargedECLClusterProperties[chargedECLCLusterCounter][1]);
191 ROEChargedECL.
setPhi(roeChargedECLClusterProperties[chargedECLCLusterCounter][2]);
192 ROEChargedECL.
setR(roeChargedECLClusterProperties[chargedECLCLusterCounter][3]);
195 chargedECLCLusterCounter++;
201 ROEChargedECL2.
setHypothesis(ECLCluster::EHypothesisBit::c_nPhotons);
203 ROEChargedECL2.
setClusterId(roeChargedECLClusterIds[chargedECLCLusterCounter][1]);
204 ROEChargedECL2.
setEnergy(roeChargedECLClusterProperties[chargedECLCLusterCounter][0]);
205 ROEChargedECL2.
setTheta(roeChargedECLClusterProperties[chargedECLCLusterCounter][1]);
206 ROEChargedECL2.
setPhi(roeChargedECLClusterProperties[chargedECLCLusterCounter][2]);
207 ROEChargedECL2.
setR(roeChargedECLClusterProperties[chargedECLCLusterCounter][3]);
210 chargedECLCLusterCounter++;
215 roeChargedParticles.push_back(roeTrackParticle);
221 roe->addParticles(roeNeutralParticles);
222 roe->addParticles(roeChargedParticles);
224 B2INFO(
"Is the ROE valid? " << roe.isValid());
225 ASSERT_TRUE(roe.isValid());
229 ROOT::Math::PxPyPzEVector roe1FourVectorECLClusters = roe->get4VectorNeutralECLClusters();
231 B2INFO(
"The total four momentum of the neutral clusters in the first test ROE is = ("
232 << roe1FourVectorECLClusters.E() <<
", "
233 << roe1FourVectorECLClusters.X() <<
", "
234 << roe1FourVectorECLClusters.Y() <<
", "
235 << roe1FourVectorECLClusters.Z() <<
")");
237 EXPECT_NEAR(roe1FourVectorECLClusters.E(), 1.16795, 0.00005);
238 EXPECT_NEAR(roe1FourVectorECLClusters.X(), 0.20075, 0.00005);
239 EXPECT_NEAR(roe1FourVectorECLClusters.Y(), 0.76747, 0.00005);
240 EXPECT_NEAR(roe1FourVectorECLClusters.Z(), 0.65482, 0.00005);
247 ASSERT_NE(var,
nullptr);
251 vector<double> refsBtagToWBosonRecoilMass{3.2093, 4.1099, 4.3019, 4.4436, 4.4924, 4.5995, 4.6493, 4.5963};
255 for (
unsigned i = 0; i < roeChargedParticles.size(); i++) {
257 double output = std::get<double>(var->function(roeChargedParticles[i]));
262 EXPECT_NEAR(output, refsBtagToWBosonRecoilMass[i], 0.0005);
269 ASSERT_NE(var,
nullptr);
271 vector<double> refsBtagToWBosonRecoilMassSqrd{10.300, 16.891, 18.506, 19.746, 20.182, 21.155, 21.616, 21.126};
273 for (
unsigned i = 0; i < roeChargedParticles.size(); i++) {
275 double output = std::get<double>(var->function(roeChargedParticles[i]));
277 EXPECT_NEAR(output, refsBtagToWBosonRecoilMassSqrd[i], 0.0005);
282 ASSERT_NE(var,
nullptr);
284 double refsBtagToWBosonPMissCMS = 0.5425695;
286 for (
auto& roeChargedParticle : roeChargedParticles) {
288 double output = std::get<double>(var->function(roeChargedParticle));
290 EXPECT_NEAR(output, refsBtagToWBosonPMissCMS, 0.000005);
295 ASSERT_NE(var,
nullptr);
297 vector<double> refsBtagToWBosonCosThetaMissCMS{0.0621, -0.6164, -0.2176, 0.3516, -0.1165, 0.4694, -0.0754, 0.6302};
299 for (
unsigned i = 0; i < roeChargedParticles.size(); i++) {
301 double output = std::get<double>(var->function(roeChargedParticles[i]));
303 EXPECT_NEAR(output, refsBtagToWBosonCosThetaMissCMS[i], 0.0005);
309 ASSERT_NE(var,
nullptr);
311 vector<double> refsBtagToWBosonEW90{0.3020, 1.63517, 1.09619, 0.96434, 0.17433, 1.19459, 1.13867, 1.36892};
313 for (
unsigned i = 0; i < roeChargedParticles.size(); i++) {
315 double output = std::get<double>(var->function(roeChargedParticles[i]));
317 EXPECT_NEAR(output, refsBtagToWBosonEW90[i], 0.0005);
325 TEST_F(FlavorTaggingVariablesTest, isSignalVariable)
347 Particle B0({ -0.129174, -0.148899, 2.09292, 5.67644}, 511);
349 savedB0->addRelationTo(savedMCB0);
353 ASSERT_NE(var,
nullptr);
358 double output1 = std::get<double>(var->function(savedB0));
359 ASSERT_EQ(output1, 1.0);
366 savedB0->setProperty(6);
367 double output2 = std::get<double>(var->function(savedB0));
368 ASSERT_EQ(output2, 1.0);
372 vector<int> notAcceptedMCErrorFlags{4, 8, 16, 32, 64, 128, 256, 512};
374 for (
int notAcceptedMCErrorFlag : notAcceptedMCErrorFlags) {
377 double output = std::get<double>(var->function(savedB0));
378 ASSERT_EQ(output, 0);
static const ChargedStable pion
charged pion particle
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 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 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.
void setR(double r)
Set R (in cm).
Singleton class responsible for loading detector parameters from an XML file.
A Class to store the Monte Carlo particle information.
void setEnergy(float energy)
Set energy.
void setPDG(int pdg)
Set PDG code of the particle.
void setMomentum(const ROOT::Math::XYZVector &momentum)
Set particle momentum.
void setMassFromPDG()
Sets the mass for the particle from the particle's PDG code.
Class to store reconstructed particles.
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).
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.
Class that bundles various TrackFitResults.
void setTrackFitResultIndex(const Const::ChargedStable &chargedStable, short index)
Set an index (for positive values) or unavailability-code (index = -1) for a specific mass hypothesis...
const Var * getVariable(std::string name)
Get the variable belonging to the given key.
static Manager & Instance()
get singleton instance.
static Gearbox & getInstance()
Return reference to the Gearbox instance.
Abstract base class for different kinds of events.
static const std::string c_extraInfoMCErrors
Name of extra-info field stored in Particle.
A variable returning a floating-point value for a given Particle.