Belle II Software  release-06-01-15
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 40 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 51 of file TrackBuilder.h.

57  :
58  m_trackColName(trackColName),
59  m_trackFitResultColName(trackFitResultColName),
60  m_mcParticleColName(mcParticleColName),
61  m_beamSpot(beamSpot),
62  m_beamAxis(beamAxis)
63  {};
TVector3 m_beamAxis
Extrapolation target, positive z direction.
Definition: TrackBuilder.h:98
std::string m_trackColName
TrackColName (output).
Definition: TrackBuilder.h:90
std::string m_mcParticleColName
MCParticleColName (input, optional).
Definition: TrackBuilder.h:94
std::string m_trackFitResultColName
TrackFitResultColName (output).
Definition: TrackBuilder.h:92
TVector3 m_beamSpot
Extrapolation target, origin.
Definition: TrackBuilder.h:96

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
useClosestHitToIPFlag to turn on special handling which measurement to choose; especially useful for Cosmics
useBFieldAtHitFlag 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 35 of file TrackBuilder.cc.

37 {
40 
41  const auto& trackReps = recoTrack.getRepresentations();
42  B2DEBUG(100, trackReps.size() << " track representations available.");
43  Track newTrack(recoTrack.getQualityIndicator());
44 
45  bool repAlreadySet = false;
46  unsigned int repIDPlusOne = 0;
47  for (const auto& trackRep : trackReps) {
48  repIDPlusOne++;
49 
50  // Check if the fitted particle type is in our charged stable set.
51  const Const::ParticleType particleType(std::abs(trackRep->getPDG()));
52  if (not Const::chargedStableSet.contains(particleType)) {
53  B2DEBUG(100, "Track fitted with hypothesis that is not a ChargedStable (PDG code = " << particleType.getPDGCode() << ")");
54  continue;
55  }
56 
57  // Check if the fit worked.
58  if (not recoTrack.wasFitSuccessful(trackRep)) {
59  B2DEBUG(100, "The fit with the given track representation (" << std::abs(trackRep->getPDG()) <<
60  ") was not successful. Skipping ...");
61  continue;
62  }
63 
64  if (not repAlreadySet) {
65  RecoTrackGenfitAccess::getGenfitTrack(recoTrack).setCardinalRep(repIDPlusOne - 1);
66  repAlreadySet = true;
67  }
68 
69  // Extrapolate the tracks to the perigee.
71  try {
72  if (useClosestHitToIP) {
73  msop = recoTrack.getMeasuredStateOnPlaneClosestTo(TVector3(0, 0, 0), trackRep);
74  } else {
75  msop = recoTrack.getMeasuredStateOnPlaneFromFirstHit(trackRep);
76  }
77  } catch (genfit::Exception& exception) {
78  B2WARNING(exception.what());
79  continue;
80  }
81 
82  genfit::MeasuredStateOnPlane extrapolatedMSoP = msop;
83  try {
84  extrapolatedMSoP.extrapolateToLine(m_beamSpot, m_beamAxis);
85  } catch (...) {
86  B2WARNING("Could not extrapolate the fit result for pdg " << particleType.getPDGCode() <<
87  " to the perigee point. Why, I don't know.");
88  continue;
89  }
90 
91  // Build track fit result.
92 
93  TVector3 poca(0., 0., 0.);
94  TVector3 dirInPoca(0., 0., 0.);
95  TMatrixDSym cov(6);
96  extrapolatedMSoP.getPosMomCov(poca, dirInPoca, cov);
97  B2DEBUG(149, "Point of closest approach: " << poca.x() << " " << poca.y() << " " << poca.z());
98  B2DEBUG(149, "Track direction in POCA: " << dirInPoca.x() << " " << dirInPoca.y() << " " << dirInPoca.z());
99 
100  const int charge = recoTrack.getTrackFitStatus(trackRep)->getCharge();
101  const double pValue = recoTrack.getTrackFitStatus(trackRep)->getPVal();
102  const int nDF = recoTrack.getTrackFitStatus(trackRep)->getNdf();
103 
104  double Bx, By, Bz; // In cgs units
105  if (useBFieldAtHit) {
106  const TVector3& hitPosition = msop.getPos();
107  genfit::FieldManager::getInstance()->getFieldVal(hitPosition.X(), hitPosition.Y(), hitPosition.Z(), Bx, By, Bz);
108  } else {
109  genfit::FieldManager::getInstance()->getFieldVal(poca.X(), poca.Y(), poca.Z(), Bx, By, Bz);
110  }
111  Bz = Bz / 10.; // In SI-Units
112 
113  const uint64_t hitPatternCDCInitializer = getHitPatternCDCInitializer(recoTrack);
114  const uint32_t hitPatternVXDInitializer = getHitPatternVXDInitializer(recoTrack);
115 
116  const auto newTrackFitResult = trackFitResults.appendNew(
117  poca, dirInPoca, cov, charge, particleType, pValue, Bz,
118  hitPatternCDCInitializer, hitPatternVXDInitializer, nDF
119  );
120 
121  const int newTrackFitResultArrayIndex = newTrackFitResult->getArrayIndex();
122  newTrack.setTrackFitResultIndex(particleType, newTrackFitResultArrayIndex);
123  }
124 
125  B2DEBUG(100, "Number of fitted hypothesis = " << newTrack.getNumberOfFittedHypotheses());
126  if (newTrack.getNumberOfFittedHypotheses() > 0) {
127  Track* addedTrack = tracks.appendNew(newTrack);
128  addedTrack->addRelationTo(&recoTrack);
129  const auto& mcParticleWithWeight = recoTrack.getRelatedToWithWeight<MCParticle>(m_mcParticleColName);
130  const MCParticle* mcParticle = mcParticleWithWeight.first;
131  if (mcParticle) {
132  B2DEBUG(200, "Relation to MCParticle set.");
133  addedTrack->addRelationTo(mcParticle, mcParticleWithWeight.second);
134  } else {
135  B2DEBUG(200, "Relation to MCParticle not set. No related MCParticle to RecoTrack.");
136  }
137  return true;
138  } else {
139  B2DEBUG(200, "Relation to MCParticle not set. No related MCParticle to RecoTrack.");
140  }
141  return true;
142 }
The ParticleType class for identifying different particle types.
Definition: Const.h:289
static const ParticleSet chargedStableSet
set of charged stable particles
Definition: Const.h:499
A Class to store the Monte Carlo particle information.
Definition: MCParticle.h:32
static genfit::Track & getGenfitTrack(RecoTrack &recoTrack)
Give access to the RecoTrack's genfit::Track.
Definition: RecoTrack.cc:396
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:536
bool wasFitSuccessful(const genfit::AbsTrackRep *representation=nullptr) const
Returns true if the last fit with the given representation was successful.
Definition: RecoTrack.cc:333
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:553
float getQualityIndicator() const
Get the quality index attached to this RecoTrack given by one of the reconstruction algorithms....
Definition: RecoTrack.h:729
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:418
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:586
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).
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.
Accessor to arrays stored in the data store.
Definition: StoreArray.h:113
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.
Class that bundles various TrackFitResults.
Definition: Track.h:25
Exception class for error handling in GENFIT (provides storage for diagnostic information)
Definition: Exception.h:48
virtual const char * what() const noexcept
Standard error message handling for exceptions. use like "std::cerr << e.what();".
Definition: Exception.cc:52
TVector3 getFieldVal(const TVector3 &position)
This does NOT use the cache!
Definition: FieldManager.h:63
static FieldManager * getInstance()
Get singleton instance.
Definition: FieldManager.h:119
virtual double getPVal() const
Get the p value of the fit.
Definition: FitStatus.h:128
double getCharge() const
Get the fitted charge.
Definition: FitStatus.h:118
double getNdf() const
Get the degrees of freedom of the fit.
Definition: FitStatus.h:122
#StateOnPlane with additional covariance matrix.
TVector3 poca(TVector3 const &trackPos, TVector3 const &trackP, TVector3 const &vtxPos)
Returns the Point Of Closest Approach of a track to a vertex.
double charge(int pdgCode)
Returns electric charge of a particle with given pdg code.
Definition: EvtPDLUtil.cc:44

The documentation for this class was generated from the following files: