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>
30 #include <TLorentzVector.h>
34 using namespace Belle2::Variable;
38 class FlavorTaggingVariablesTest :
public ::testing::Test {
43 DataStore::Instance().setInitializeActive(
true);
61 roe.registerInDataStore();
70 DataStore::Instance().setInitializeActive(
false);
74 void TearDown()
override
76 DataStore::Instance().reset();
81 TEST_F(FlavorTaggingVariablesTest, VariablesRunningForEachROE)
89 Gearbox& gearbox = Gearbox::getInstance();
90 gearbox.setBackends({std::string(
"file:")});
92 gearbox.open(
"geometry/Belle2.xml",
false);
102 vector<const Particle*> roeNeutralParticles;
105 vector<vector<int>> roeNeutralECLClusterIds{{4, 1}, {6, 1}, {9, 1}, {12, 1}, {17, 1}};
108 vector<vector<double>> roeNeutralECLClusterProperties{{0.0487526, 0.493606, -2.65695, 239.246},
109 {0.485431, 0.768093, 0.905049, 199.805},
110 {0.436428, 0.99517, 1.6799, 167.271},
111 {0.0230045, 1.05471, -1.20024, 161.013},
112 {0.174332, 1.49141, 1.3059, 141.107}};
115 for (
unsigned i = 0; i < roeNeutralECLClusterIds.size(); ++i) {
119 ROEECL.
setHypothesis(ECLCluster::EHypothesisBit::c_nPhotons);
122 ROEECL.
setEnergy(roeNeutralECLClusterProperties[i][0]);
123 ROEECL.
setTheta(roeNeutralECLClusterProperties[i][1]);
124 ROEECL.
setPhi(roeNeutralECLClusterProperties[i][2]);
125 ROEECL.
setR(roeNeutralECLClusterProperties[i][3]);
128 roeNeutralParticles.push_back(roeECLParticle);
133 vector<const Particle*> roeChargedParticles;
134 const float bField = 1.5;
138 vector<vector<float>> roeTFRProperties{{ -0.578196, 0.252548, 0.158642, -0.520087, -1.19071, 0.417451, 0.139206},
139 {0.00434622, -0.0191058, 0.231542, 0.664887, 0.15125, 0.463762, 0.0313268},
140 {0.0738595, -0.00294903, 0.242319, 0.0186749, 0.467721, 0.288627, 0.0415814},
141 {1.3887, -2.43016, 1.00615, -0.27093, -0.15482, 0.0639155, 0.0132331},
142 {0.0041096, -0.0152487, 0.264326, 0.294061, 0.079251, 0.0389014, 0.00200114},
143 { -0.00371803, -5.22544e-05, 0.210148, 0.0019418, -0.138163, -0.0287232, 0.000622186},
144 {1.02296, 0.608721, 0.32273, -0.0505521, 0.0849532, 0.0839057, 0},
145 {6.49062, 3.20227, 117.684, 0.0469579, -0.0951783, -0.0706371, 0.117562}};
148 vector<short int> roeTRFCharges{1, 1, 1, -1, -1, -1, 1, -1};
151 vector<uint64_t> roeTRFCDCValues{3098476543630901248, 3026418949592973312, 3170534137668829184, 3386706919782612992,
152 3242591731706757120, 2954361355555045376, 1080863910568919040, 504403158265495552};
155 vector<uint32_t> roeTRFVXDValues{5570560, 5592320, 5592320, 5570560, 5592320, 5264640, 328960, 0};
159 vector<vector<int>> roeChargedECLClusterIds{{14, 1}, {10, 1}, {7, 1}, {8, 1}, {15, 1}};
162 vector<vector<double>> roeChargedECLClusterProperties{{0.964336, 1.23481, -2.25428, 148.729},
163 {0.214864, 0.965066, -0.232973, 170.008},
164 {0.0148855, 0.914396, 1.01693 , 175.861},
165 {0.524092, 0.956389, 0.854331 , 171.378},
166 {0.230255, 1.33317, -1.45326 , 144.849}};
168 unsigned int chargedECLCLusterCounter = 0;
171 for (
unsigned i = 0; i < roeTRFCharges.size(); ++i) {
173 TVector3 position(roeTFRProperties[i][0], roeTFRProperties[i][1], roeTFRProperties[i][2]);
174 TVector3 momentum(roeTFRProperties[i][3], roeTFRProperties[i][4], roeTFRProperties[i][5]);
176 testsTFRs.
appendNew(position, momentum, cov6, roeTRFCharges[i], Const::pion, roeTFRProperties[i][6], bField, roeTRFCDCValues[i],
177 roeTRFVXDValues[i], 0);
184 if (i == 0 || i == 1 || i == 2 || i == 3) {
187 ROEChargedECL.
setHypothesis(ECLCluster::EHypothesisBit::c_nPhotons);
189 ROEChargedECL.
setClusterId(roeChargedECLClusterIds[chargedECLCLusterCounter][1]);
190 ROEChargedECL.
setEnergy(roeChargedECLClusterProperties[chargedECLCLusterCounter][0]);
191 ROEChargedECL.
setTheta(roeChargedECLClusterProperties[chargedECLCLusterCounter][1]);
192 ROEChargedECL.
setPhi(roeChargedECLClusterProperties[chargedECLCLusterCounter][2]);
193 ROEChargedECL.
setR(roeChargedECLClusterProperties[chargedECLCLusterCounter][3]);
196 chargedECLCLusterCounter++;
202 ROEChargedECL2.
setHypothesis(ECLCluster::EHypothesisBit::c_nPhotons);
204 ROEChargedECL2.
setClusterId(roeChargedECLClusterIds[chargedECLCLusterCounter][1]);
205 ROEChargedECL2.
setEnergy(roeChargedECLClusterProperties[chargedECLCLusterCounter][0]);
206 ROEChargedECL2.
setTheta(roeChargedECLClusterProperties[chargedECLCLusterCounter][1]);
207 ROEChargedECL2.
setPhi(roeChargedECLClusterProperties[chargedECLCLusterCounter][2]);
208 ROEChargedECL2.
setR(roeChargedECLClusterProperties[chargedECLCLusterCounter][3]);
211 chargedECLCLusterCounter++;
215 Particle* roeTrackParticle = testsParticles.
appendNew(savedROETrack, Const::pion);
216 roeChargedParticles.push_back(roeTrackParticle);
222 roe->addParticles(roeNeutralParticles);
223 roe->addParticles(roeChargedParticles);
225 B2INFO(
"Is the ROE valid? " << roe.isValid());
226 ASSERT_TRUE(roe.isValid());
230 TLorentzVector roe1FourVectorECLClusters = roe -> get4VectorNeutralECLClusters();
232 B2INFO(
"The total four momentum of the neutral clusters in the first test ROE is = ("
233 << roe1FourVectorECLClusters.E() <<
", "
234 << roe1FourVectorECLClusters.X() <<
", "
235 << roe1FourVectorECLClusters.Y() <<
", "
236 << roe1FourVectorECLClusters.Z() <<
")");
238 EXPECT_NEAR(roe1FourVectorECLClusters.E(), 1.16795, 0.00005);
239 EXPECT_NEAR(roe1FourVectorECLClusters.X(), 0.20075, 0.00005);
240 EXPECT_NEAR(roe1FourVectorECLClusters.Y(), 0.76747, 0.00005);
241 EXPECT_NEAR(roe1FourVectorECLClusters.Z(), 0.65482, 0.00005);
244 const Manager::Var* var = Manager::Instance().getVariable(
"BtagToWBosonVariables(recoilMass)");
248 ASSERT_NE(var,
nullptr);
252 vector<double> refsBtagToWBosonRecoilMass{3.2093, 4.1099, 4.3019, 4.4436, 4.4924, 4.5995, 4.6493, 4.5963};
256 for (
unsigned i = 0; i < roeChargedParticles.size(); i++) {
258 double output = var ->
function(roeChargedParticles[i]);
263 EXPECT_NEAR(output, refsBtagToWBosonRecoilMass[i], 0.0005);
269 var = Manager::Instance().getVariable(
"BtagToWBosonVariables(recoilMassSqrd)");
270 ASSERT_NE(var,
nullptr);
272 vector<double> refsBtagToWBosonRecoilMassSqrd{10.300, 16.891, 18.506, 19.746, 20.182, 21.155, 21.616, 21.126};
274 for (
unsigned i = 0; i < roeChargedParticles.size(); i++) {
276 double output = var ->
function(roeChargedParticles[i]);
278 EXPECT_NEAR(output, refsBtagToWBosonRecoilMassSqrd[i], 0.0005);
282 var = Manager::Instance().getVariable(
"BtagToWBosonVariables(pMissCMS)");
283 ASSERT_NE(var,
nullptr);
285 double refsBtagToWBosonPMissCMS = 0.542734;
287 for (
auto& roeChargedParticle : roeChargedParticles) {
289 double output = var ->
function(roeChargedParticle);
291 EXPECT_NEAR(output, refsBtagToWBosonPMissCMS, 0.000005);
295 var = Manager::Instance().getVariable(
"BtagToWBosonVariables(cosThetaMissCMS)");
296 ASSERT_NE(var,
nullptr);
298 vector<double> refsBtagToWBosonCosThetaMissCMS{0.0621, -0.6164, -0.2176, 0.3516, -0.1165, 0.4694, -0.0754, 0.6302};
300 for (
unsigned i = 0; i < roeChargedParticles.size(); i++) {
302 double output = var ->
function(roeChargedParticles[i]);
304 EXPECT_NEAR(output, refsBtagToWBosonCosThetaMissCMS[i], 0.0005);
309 var = Manager::Instance().getVariable(
"BtagToWBosonVariables(EW90)");
310 ASSERT_NE(var,
nullptr);
312 vector<double> refsBtagToWBosonEW90{0.3020, 1.63517, 1.09619, 0.96434, 0.17433, 1.19459, 1.13867, 1.36892};
314 for (
unsigned i = 0; i < roeChargedParticles.size(); i++) {
316 double output = var ->
function(roeChargedParticles[i]);
318 EXPECT_NEAR(output, refsBtagToWBosonEW90[i], 0.0005);
326 TEST_F(FlavorTaggingVariablesTest, isSignalVariable)
348 Particle B0({ -0.129174, -0.148899, 2.09292, 5.67644}, 511);
350 savedB0->addRelationTo(savedMCB0);
353 const Manager::Var* var = Manager::Instance().getVariable(
"isSignal");
354 ASSERT_NE(var,
nullptr);
358 savedB0->addExtraInfo(MCMatching::c_extraInfoMCErrors, 0);
359 double output1 = var ->
function(savedB0);
360 ASSERT_EQ(output1, 1.0);
366 savedB0->setExtraInfo(MCMatching::c_extraInfoMCErrors, 0);
367 savedB0->setProperty(6);
368 double output2 = var ->
function(savedB0);
369 ASSERT_EQ(output2, 1.0);
373 vector<int> notAcceptedMCErrorFlags{4, 8, 16, 32, 64, 128, 256, 512};
375 for (
int notAcceptedMCErrorFlag : notAcceptedMCErrorFlags) {
377 savedB0->setExtraInfo(MCMatching::c_extraInfoMCErrors, notAcceptedMCErrorFlag);
378 double output = var ->
function(savedB0);
379 ASSERT_EQ(output, 0);
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 setMomentum(const TVector3 &momentum)
Set particle momentum.
void setEnergy(float energy)
Set energy.
void setPDG(int pdg)
Set PDG code of the particle.
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 (with negative values) for a specific mass ...
TEST_F(GlobalLabelTest, LargeNumberOfTimeDependentParameters)
Test large number of time-dep params for registration and retrieval.
Abstract base class for different kinds of events.
A variable returning a floating-point value for a given Particle.