Belle II Software  release-05-02-19
TrackBuilder Class Reference

TrackBuilder class to create the Track/TrackFitResult mdst output from the RecoTrack. More...

#include <TrackBuilder.h>

Collaboration diagram for TrackBuilder:

Public Member Functions

 TrackBuilder (const std::string &trackColName, const std::string &trackFitResultColName, const std::string &mcParticleColName, const TVector3 &beamSpot=TVector3(0., 0., 0.), const TVector3 &beamAxis=TVector3(0., 0., 1.))
 Constructor of the class. More...
 
bool storeTrackFromRecoTrack (RecoTrack &recoTrack, const bool useClosestHitToIP=false, const bool useBFieldAtHit=false)
 Stores a Belle2 Track from a Reco Track. More...
 

Static Public Member Functions

static uint32_t getHitPatternVXDInitializer (const RecoTrack &recoTrack)
 Get the HitPattern in the VXD.
 
static uint64_t getHitPatternCDCInitializer (const RecoTrack &recoTrack)
 Get the HitPattern in the CDC.
 

Private Attributes

std::string m_trackColName
 TrackColName (output).
 
std::string m_trackFitResultColName
 TrackFitResultColName (output).
 
std::string m_mcParticleColName
 MCParticleColName (input, optional).
 
TVector3 m_beamSpot
 Extrapolation target, origin.
 
TVector3 m_beamAxis
 Extrapolation target, positive z direction.
 

Detailed Description

TrackBuilder class to create the Track/TrackFitResult mdst output from the RecoTrack.

To use this class, iterate over all Reco tracks and call trackBuilder.storeTrackFromRecoTrack. All fitted hypotheses will be stored into one Track with the TrackFitResult array indices stored in the Track. for (auto& recoTrack : recoTracks) { trackBuilder.storeTrackFromRecoTrack(recoTrack); }

If you want to make sure that all hypotheses are fitted and stored, call the fitter again. If the tracks are fitted already, this produces no overhead. TrackFitter trackFitter; TrackBuilder trackBuilder; for (auto& recoTrack : recoTracks) { for (const auto& pdg : m_pdgCodes) { trackFitter.fit(recoTrack, Const::ParticleType(abs(pdg))); } trackBuilder.storeTrackFromRecoTrack(recoTrack); }

Definition at line 50 of file TrackBuilder.h.

Constructor & Destructor Documentation

◆ TrackBuilder()

TrackBuilder ( const std::string &  trackColName,
const std::string &  trackFitResultColName,
const std::string &  mcParticleColName,
const TVector3 &  beamSpot = TVector3(0., 0., 0.),
const TVector3 &  beamAxis = TVector3(0., 0., 1.) 
)
inline

Constructor of the class.

Parameters
trackColNameName of the store array for tracks (output).
trackFitResultColNameName of the store array for track fit results (output).
mcParticleColNameName of the store array for MC particles (input, optional). If given, the tracks are matched to MCParticles.
beamSpotOrigin.
beamAxisPositive z-direction.

Definition at line 61 of file TrackBuilder.h.

65  {};
66 

Member Function Documentation

◆ storeTrackFromRecoTrack()

bool storeTrackFromRecoTrack ( RecoTrack recoTrack,
const bool  useClosestHitToIP = false,
const bool  useBFieldAtHit = false 
)

Stores a Belle2 Track from a Reco Track.

Every fitted hypothesis will be extrapolated to the perigee and stored as a TrackFitResult when the fit and the extrapolation were successful. We will only create a Track mdst object, when we are sure that we have at least one valid hypothesis available. If we do not have this, we discard the track no matter what.

The StoreArrayIndex is stored in the Belle2 Track, no relation is set.

Parameters
recoTrackThe reco track the fit results are stored for
useClosestHitInIPFlag to turn on special handling which measurement to choose; especially useful for Cosmics
useBFiledAtHitFlag to calculate the BField at the used hit (closest to IP or first one), instead of the one at the POCA. This is also useful for cosmics only.
Returns

Definition at line 28 of file TrackBuilder.cc.

30 {
33 
34  const auto& trackReps = recoTrack.getRepresentations();
35  B2DEBUG(100, trackReps.size() << " track representations available.");
36  Track newTrack(recoTrack.getQualityIndicator());
37 
38  bool repAlreadySet = false;
39  unsigned int repIDPlusOne = 0;
40  for (const auto& trackRep : trackReps) {
41  repIDPlusOne++;
42 
43  // Check if the fitted particle type is in our charged stable set.
44  const Const::ParticleType particleType(std::abs(trackRep->getPDG()));
45  if (not Const::chargedStableSet.contains(particleType)) {
46  B2DEBUG(100, "Track fitted with hypothesis that is not a ChargedStable (PDG code = " << particleType.getPDGCode() << ")");
47  continue;
48  }
49 
50  // Check if the fit worked.
51  if (not recoTrack.wasFitSuccessful(trackRep)) {
52  B2DEBUG(100, "The fit with the given track representation (" << std::abs(trackRep->getPDG()) <<
53  ") was not successful. Skipping ...");
54  continue;
55  }
56 
57  if (not repAlreadySet) {
58  RecoTrackGenfitAccess::getGenfitTrack(recoTrack).setCardinalRep(repIDPlusOne - 1);
59  repAlreadySet = true;
60  }
61 
62  // Extrapolate the tracks to the perigee.
64  try {
65  if (useClosestHitToIP) {
66  msop = recoTrack.getMeasuredStateOnPlaneClosestTo(TVector3(0, 0, 0), trackRep);
67  } else {
68  msop = recoTrack.getMeasuredStateOnPlaneFromFirstHit(trackRep);
69  }
70  } catch (genfit::Exception& exception) {
71  B2WARNING(exception.what());
72  continue;
73  }
74 
75  genfit::MeasuredStateOnPlane extrapolatedMSoP = msop;
76  try {
77  extrapolatedMSoP.extrapolateToLine(m_beamSpot, m_beamAxis);
78  } catch (...) {
79  B2WARNING("Could not extrapolate the fit result for pdg " << particleType.getPDGCode() <<
80  " to the perigee point. Why, I don't know.");
81  continue;
82  }
83 
84  // Build track fit result.
85 
86  TVector3 poca(0., 0., 0.);
87  TVector3 dirInPoca(0., 0., 0.);
88  TMatrixDSym cov(6);
89  extrapolatedMSoP.getPosMomCov(poca, dirInPoca, cov);
90  B2DEBUG(149, "Point of closest approach: " << poca.x() << " " << poca.y() << " " << poca.z());
91  B2DEBUG(149, "Track direction in POCA: " << dirInPoca.x() << " " << dirInPoca.y() << " " << dirInPoca.z());
92 
93  const int charge = recoTrack.getTrackFitStatus(trackRep)->getCharge();
94  const double pValue = recoTrack.getTrackFitStatus(trackRep)->getPVal();
95  const int nDF = recoTrack.getTrackFitStatus(trackRep)->getNdf();
96 
97  double Bx, By, Bz; // In cgs units
98  if (useBFieldAtHit) {
99  const TVector3& hitPosition = msop.getPos();
100  genfit::FieldManager::getInstance()->getFieldVal(hitPosition.X(), hitPosition.Y(), hitPosition.Z(), Bx, By, Bz);
101  } else {
102  genfit::FieldManager::getInstance()->getFieldVal(poca.X(), poca.Y(), poca.Z(), Bx, By, Bz);
103  }
104  Bz = Bz / 10.; // In SI-Units
105 
106  const uint64_t hitPatternCDCInitializer = getHitPatternCDCInitializer(recoTrack);
107  const uint32_t hitPatternVXDInitializer = getHitPatternVXDInitializer(recoTrack);
108 
109  const auto newTrackFitResult = trackFitResults.appendNew(
110  poca, dirInPoca, cov, charge, particleType, pValue, Bz,
111  hitPatternCDCInitializer, hitPatternVXDInitializer, nDF
112  );
113 
114  const int newTrackFitResultArrayIndex = newTrackFitResult->getArrayIndex();
115  newTrack.setTrackFitResultIndex(particleType, newTrackFitResultArrayIndex);
116  }
117 
118  B2DEBUG(100, "Number of fitted hypothesis = " << newTrack.getNumberOfFittedHypotheses());
119  if (newTrack.getNumberOfFittedHypotheses() > 0) {
120  Track* addedTrack = tracks.appendNew(newTrack);
121  addedTrack->addRelationTo(&recoTrack);
122  const auto& mcParticleWithWeight = recoTrack.getRelatedToWithWeight<MCParticle>(m_mcParticleColName);
123  const MCParticle* mcParticle = mcParticleWithWeight.first;
124  if (mcParticle) {
125  B2DEBUG(200, "Relation to MCParticle set.");
126  addedTrack->addRelationTo(mcParticle, mcParticleWithWeight.second);
127  } else {
128  B2DEBUG(200, "Relation to MCParticle not set. No related MCParticle to RecoTrack.");
129  }
130  return true;
131  } else {
132  B2DEBUG(200, "Relation to MCParticle not set. No related MCParticle to RecoTrack.");
133  }
134  return true;
135 }

The documentation for this class was generated from the following files:
genfit::FitStatus::getCharge
double getCharge() const
Get the fitted charge.
Definition: FitStatus.h:118
Belle2::EvtPDLUtil::charge
double charge(int pdgCode)
Returns electric charge of a particle with given pdg code.
Definition: EvtPDLUtil.cc:46
Belle2::TrackBuilder::m_mcParticleColName
std::string m_mcParticleColName
MCParticleColName (input, optional).
Definition: TrackBuilder.h:104
genfit::Exception
Exception class for error handling in GENFIT (provides storage for diagnostic information)
Definition: Exception.h:48
Belle2::RecoTrack::getTrackFitStatus
const genfit::FitStatus * getTrackFitStatus(const genfit::AbsTrackRep *representation=nullptr) const
Return the track fit status for the given representation or for the cardinal one. You are not allowed...
Definition: RecoTrack.h:537
Belle2::RecoTrack::getQualityIndicator
float getQualityIndicator() const
Get the quality index attached to this RecoTrack given by one of the reconstruction algorithms....
Definition: RecoTrack.h:730
Belle2::RecoTrack::wasFitSuccessful
bool wasFitSuccessful(const genfit::AbsTrackRep *representation=nullptr) const
Returns true if the last fit with the given representation was successful.
Definition: RecoTrack.cc:326
genfit::MeasuredStateOnPlane
#StateOnPlane with additional covariance matrix.
Definition: MeasuredStateOnPlane.h:39
Belle2::RecoTrackGenfitAccess::getGenfitTrack
static genfit::Track & getGenfitTrack(RecoTrack &recoTrack)
Give access to the RecoTrack's genfit::Track.
Definition: RecoTrack.cc:389
Belle2::RecoTrack::getMeasuredStateOnPlaneFromFirstHit
const genfit::MeasuredStateOnPlane & getMeasuredStateOnPlaneFromFirstHit(const genfit::AbsTrackRep *representation=nullptr) const
Return genfit's MeasuredStateOnPlane for the first hit in a fit useful for extrapolation of measureme...
Definition: RecoTrack.cc:580
Belle2::TrackBuilder::m_trackFitResultColName
std::string m_trackFitResultColName
TrackFitResultColName (output).
Definition: TrackBuilder.h:102
genfit::FieldManager::getFieldVal
TVector3 getFieldVal(const TVector3 &position)
This does NOT use the cache!
Definition: FieldManager.h:63
Belle2::Const::chargedStableSet
static const ParticleSet chargedStableSet
set of charged stable particles
Definition: Const.h:494
Belle2::RelationsInterface::addRelationTo
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).
Definition: RelationsObject.h:144
Belle2::RecoTrack::getRepresentations
const std::vector< genfit::AbsTrackRep * > & getRepresentations() const
Return a list of track representations. You are not allowed to modify or delete them!
Definition: RecoTrack.h:554
Belle2::TrackBuilder::m_beamAxis
TVector3 m_beamAxis
Extrapolation target, positive z direction.
Definition: TrackBuilder.h:108
Belle2::TrackBuilder::getHitPatternCDCInitializer
static uint64_t getHitPatternCDCInitializer(const RecoTrack &recoTrack)
Get the HitPattern in the CDC.
Definition: TrackBuilder.cc:195
genfit::FitStatus::getPVal
virtual double getPVal() const
Get the p value of the fit.
Definition: FitStatus.h:128
Belle2::RelationsInterface::getRelatedToWithWeight
std::pair< TO *, float > getRelatedToWithWeight(const std::string &name="", const std::string &namedRelation="") const
Get first related object & weight of relation pointing to an array.
Definition: RelationsObject.h:299
Belle2::TrackBuilder::m_trackColName
std::string m_trackColName
TrackColName (output).
Definition: TrackBuilder.h:100
Belle2::TrackBuilder::getHitPatternVXDInitializer
static uint32_t getHitPatternVXDInitializer(const RecoTrack &recoTrack)
Get the HitPattern in the VXD.
Definition: TrackBuilder.cc:138
Belle2::RecoTrack::getMeasuredStateOnPlaneClosestTo
const genfit::MeasuredStateOnPlane & getMeasuredStateOnPlaneClosestTo(const TVector3 &closestPoint, const genfit::AbsTrackRep *representation=nullptr)
Return genfit's MasuredStateOnPlane, that is closest to the given point useful for extrapolation of m...
Definition: RecoTrack.cc:411
genfit::FitStatus::getNdf
double getNdf() const
Get the degrees of freedom of the fit.
Definition: FitStatus.h:122
Belle2::TrackBuilder::m_beamSpot
TVector3 m_beamSpot
Extrapolation target, origin.
Definition: TrackBuilder.h:106
Belle2::Const::ParticleType
The ParticleType class for identifying different particle types.
Definition: Const.h:284
Belle2::Track
Class that bundles various TrackFitResults.
Definition: Track.h:35
Belle2::MCParticle
A Class to store the Monte Carlo particle information.
Definition: MCParticle.h:43
Belle2::StoreArray
Accessor to arrays stored in the data store.
Definition: ECLMatchingPerformanceExpertModule.h:33
genfit::Exception::what
virtual const char * what() const noexcept
Standard error message handling for exceptions. use like "std::cerr << e.what();".
Definition: Exception.cc:52
genfit::FieldManager::getInstance
static FieldManager * getInstance()
Get singleton instance.
Definition: FieldManager.h:119
Belle2::DistanceTools::poca
TVector3 poca(TVector3 const &trackPos, TVector3 const &trackP, TVector3 const &vtxPos)
Returns the Point Of Closest Approach of a track to a vertex.
Definition: DistanceTools.cc:21