9#include <tracking/modules/mcMatcher/Chi2MCTrackMatcherModule.h>
12#include <framework/datastore/StoreArray.h>
13#include <mdst/dataobjects/Track.h>
14#include <tracking/dataobjects/RecoTrack.h>
15#include <mdst/dataobjects/MCParticle.h>
16#include <framework/gearbox/Const.h>
35 setDescription(R
"DOC(Monte Carlo matcher using the helix parameters for matching by chi2-method)DOC");
40 "Defines the chi2-cut-off values for each charged particle. The cut-offs define the maximal size for a matching pair candidate`s chi2 value. If a matching pair candidate has a chi2 value smaller than the cut-off a relation is set. Defaults determined from small study on events with trivial matching. The pdg order is [11,13,211,2212,321,1000010020].",
45 "Parameter to switch between ROOT and Eigen, to invert the covariance5 matrix. ROOT has shown a shorter runtime therefore its recommended. false: ROOT is used; true: Eigen is used",
49 "Name of the StoreArray of MC RecoTracks which will be related to the PR RecoTracks, "
50 "using the relations to Belle2::MCParticles and Belle2::Tracks",
54 "Name of the StoreArray of PR RecoTracks which will be related to the MC RecoTracks, "
55 "using the relations to Belle2::MCParticles and Belle2::Tracks",
84 B2DEBUG(27,
"m_event = " <<
m_event);
86 auto default_gErrorIgnoreLevel = gErrorIgnoreLevel;
87 gErrorIgnoreLevel = 5000;
94 if (not nMCParticles or not nTracks) {
102 B2DEBUG(27,
"Relation already set continue with next track");
107 double chi2Min = std::numeric_limits<double>::infinity();
117 auto trackFitResult = track.getTrackFitResultWithClosestMass(mcParticleType);
118 TMatrixD Covariance5 = trackFitResult->getCovariance5();
122 double det = Covariance5.Determinant();
130 double charge_sign = 1;
131 if (mcParticle.getCharge() < 0) { charge_sign = -1;}
134 auto mcParticleHelix =
Helix(mcParticle.getVertex(), mcParticle.getMomentum(), charge_sign, b_field);
141 Eigen::VectorXd delta(5);
142 delta(0) = trackFitResult->getD0() - mcParticleHelix.getD0();
143 delta(1) = trackFitResult->getPhi0() - mcParticleHelix.getPhi0();
144 delta(2) = trackFitResult->getOmega() - mcParticleHelix.getOmega();
145 delta(3) = trackFitResult->getZ0() - mcParticleHelix.getZ0();
146 delta(4) = trackFitResult->getTanLambda() - mcParticleHelix.getTanLambda();
148 Eigen::MatrixXd covariance5Eigen(5, 5);
149 for (
int i = 0; i < 5; i++) {
150 for (
int j = 0; j < 5; j++) {
151 covariance5Eigen(i, j) = Covariance5[i][j];
155 chi2Cur = ((delta.transpose()) * (covariance5Eigen.inverse() * delta))(0, 0);
159 TMatrixD delta(5, 1);
160 delta[0][0] = trackFitResult->getD0() - mcParticleHelix.getD0();
161 delta[1][0] = trackFitResult->getPhi0() - mcParticleHelix.getPhi0();
162 delta[2][0] = trackFitResult->getOmega() - mcParticleHelix.getOmega();
163 delta[3][0] = trackFitResult->getZ0() - mcParticleHelix.getZ0();
164 delta[4][0] = trackFitResult->getTanLambda() - mcParticleHelix.getTanLambda();
166 Covariance5.InvertFast();
168 TMatrixD deltaT = delta;
171 chi2Cur = ((deltaT) * (Covariance5 * delta))[0][0];
174 if (chi2Min > chi2Cur) {
176 mcPart_matched = &mcParticle;
180 if (not mcPart_matched) {
189 int mcMinPDG = abs(mcPart_matched->
getPDG());
203 B2WARNING(
"The pdg for minimal chi2 was not in chargedstable particle list: MinPDG = " << mcMinPDG);
206 if (chi2Min < cutOff) {
207 track.addRelationTo(mcPart_matched);
211 if (mcRecoTrack and prRecoTrack) {
213 prRecoTrack->addRelationTo(mcRecoTrack);
215 prRecoTrack->addRelationTo(mcPart_matched);
223 gErrorIgnoreLevel = default_gErrorIgnoreLevel;
228 "%) tracks no relation was found.");
230 "%) tracks got no matching candidate");
bool m_param_linalg
Parameter: Possibility to switch between ROOT and Eigen for inversion of the covariance matrix false:...
Chi2MCTrackMatcherModule()
Constructor: Sets the description, the properties and the parameters of the module.
std::string m_PRRecoTracksArrayName
Variable: Name of the RecoTracks StoreArray of PR tracks.
int m_noMatchCount
Variable: Counts the number of tracks without a relation.
std::vector< double > m_param_CutOffs
Parameter : Defines the chi2 cut-off values for each charged particle.
void initialize() override
Register input and output data.
void event() override
Do matching for each event.
int m_event
Variable: Counts total event number.
std::string m_MCRecoTracksArrayName
Variable: Name of the RecoTracks StoreArray of MC tracks.
void terminate() override
Provides debug statistics.
int m_noMatchingCandidateCount
Variable: Counts the total number of tracks without a possible MCParticle as matching candidate.
int m_notInvertableCount
Variables for Debug module statistics.
int m_trackCount
Variable: Counts the total number of tracks to calculate a percentage feedback.
int m_covarianceMatrixCount
Variable: Counts the total number of Covaraince5 matrices.
StoreArray< Track > m_Tracks
Variable: Makes m_Tracks available in whole class.
StoreArray< MCParticle > m_MCParticles
Variable: Makes m_MCParticles available in whole class.
The ParticleType class for identifying different particle types.
static const ChargedStable muon
muon particle
static const ParticleSet chargedStableSet
set of charged stable particles
static const ChargedStable pion
charged pion particle
static const ChargedStable proton
proton particle
static const ChargedStable kaon
charged kaon particle
static const ChargedStable electron
electron particle
static const ChargedStable deuteron
deuteron particle
A Class to store the Monte Carlo particle information.
int getPDG() const
Return PDG code of particle.
void setDescription(const std::string &description)
Sets the description of the module.
This is the Reconstruction Event-Data Model Track.
void setMatchingStatus(MatchingStatus matchingStatus)
Set the matching status (used by the TrackMatcher module)
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).
T * getRelated(const std::string &name="", const std::string &namedRelation="") const
Get the object to or from which this object has a relation.
bool isRequired(const std::string &name="")
Ensure this array/object has been registered previously.
bool isOptional(const std::string &name="")
Tell the DataStore about an optional input.
Accessor to arrays stored in the data store.
bool isValid() const
Check wether the array was registered.
int getEntries() const
Get the number of objects in 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.
This class represents an ideal helix in perigee parameterization including the covariance matrix of t...
static const double T
[tesla]
void addParam(const std::string &name, T ¶mVariable, const std::string &description, const T &defaultValue)
Adds a new parameter to the module.
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
static void getField(const double *pos, double *field)
return the magnetic field at a given position.
Abstract base class for different kinds of events.