Belle II Software  release-08-01-10
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 B2Vector3D &beamSpot=B2Vector3D(0., 0., 0.), const B2Vector3D &beamAxis=B2Vector3D(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, const genfit::AbsTrackRep *representation=nullptr)
 Get the HitPattern in the VXD.
 
static uint64_t getHitPatternCDCInitializer (const RecoTrack &recoTrack, const genfit::AbsTrackRep *representation=nullptr)
 Get the HitPattern in the CDC.
 

Private Attributes

std::string m_trackColName
 TrackColName (output).
 
std::string m_trackFitResultColName
 TrackFitResultColName (output).
 
B2Vector3D m_beamSpot
 Extrapolation target, origin.
 
B2Vector3D 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 41 of file TrackBuilder.h.

Constructor & Destructor Documentation

◆ TrackBuilder()

TrackBuilder ( const std::string &  trackColName,
const std::string &  trackFitResultColName,
const B2Vector3D beamSpot = B2Vector3D(0., 0., 0.),
const B2Vector3D beamAxis = B2Vector3D(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).
beamSpotOrigin.
beamAxisPositive z-direction.

Definition at line 50 of file TrackBuilder.h.

55  :
56  m_trackColName(trackColName),
57  m_trackFitResultColName(trackFitResultColName),
58  m_beamSpot(beamSpot),
59  m_beamAxis(beamAxis)
60  {};
B2Vector3D m_beamSpot
Extrapolation target, origin.
Definition: TrackBuilder.h:91
std::string m_trackColName
TrackColName (output).
Definition: TrackBuilder.h:87
std::string m_trackFitResultColName
TrackFitResultColName (output).
Definition: TrackBuilder.h:89
B2Vector3D m_beamAxis
Extrapolation target, positive z direction.
Definition: TrackBuilder.h:93

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 34 of file TrackBuilder.cc.

36 {
39 
40  const auto& trackReps = recoTrack.getRepresentations();
41  B2DEBUG(27, trackReps.size() << " track representations available.");
42  Track newTrack(recoTrack.getQualityIndicator());
43 
44  bool repAlreadySet = false;
45  unsigned int repIDPlusOne = 0;
46  for (const auto& trackRep : trackReps) {
47  repIDPlusOne++;
48 
49  // Check if the fitted particle type is in our charged stable set.
50  const Const::ParticleType particleType(std::abs(trackRep->getPDG()));
51  if (not Const::chargedStableSet.contains(particleType)) {
52  B2DEBUG(27, "Track fitted with hypothesis that is not a ChargedStable (PDG code = " << particleType.getPDGCode() << ")");
53  continue;
54  }
55 
56  // Check if the fit worked.
57  if (not recoTrack.wasFitSuccessful(trackRep)) {
58  B2DEBUG(27, "The fit with the given track representation (" << std::abs(trackRep->getPDG()) <<
59  ") was not successful. Skipping ...");
60  continue;
61  }
62 
63  if (not repAlreadySet) {
64  RecoTrackGenfitAccess::getGenfitTrack(recoTrack).setCardinalRep(repIDPlusOne - 1);
65  repAlreadySet = true;
66  }
67 
68  // Extrapolate the tracks to the perigee.
70  try {
71  if (useClosestHitToIP) {
72  msop = recoTrack.getMeasuredStateOnPlaneClosestTo(ROOT::Math::XYZVector(0, 0, 0), trackRep);
73  } else {
74  msop = recoTrack.getMeasuredStateOnPlaneFromFirstHit(trackRep);
75  }
76  } catch (genfit::Exception& exception) {
77  B2WARNING(exception.what());
78  continue;
79  } catch (const std::runtime_error& er) {
80  B2WARNING("Runtime error encountered: " << er.what());
81  continue;
82  } catch (...) {
83  B2WARNING("Undefined exception encountered.");
84  continue;
85  }
86 
87  genfit::MeasuredStateOnPlane extrapolatedMSoP = msop;
88  try {
89  extrapolatedMSoP.extrapolateToLine(m_beamSpot, m_beamAxis);
90  } catch (...) {
91  B2WARNING("Could not extrapolate the fit result for pdg " << particleType.getPDGCode() <<
92  " to the perigee point. Why, I don't know.");
93  continue;
94  }
95 
96  // Build track fit result.
97 
98  TVector3 poca(0., 0., 0.);
99  TVector3 dirInPoca(0., 0., 0.);
100  TMatrixDSym cov(6);
101  extrapolatedMSoP.getPosMomCov(poca, dirInPoca, cov);
102  B2DEBUG(29, "Point of closest approach: " << poca.x() << " " << poca.y() << " " << poca.z());
103  B2DEBUG(29, "Track direction in POCA: " << dirInPoca.x() << " " << dirInPoca.y() << " " << dirInPoca.z());
104 
105  const int charge = recoTrack.getTrackFitStatus(trackRep)->getCharge();
106  const double pValue = recoTrack.getTrackFitStatus(trackRep)->getPVal();
107  const double nDF = recoTrack.getTrackFitStatus(trackRep)->getNdf();
108 
109  double Bx, By, Bz; // In cgs units
110  if (useBFieldAtHit) {
111  const B2Vector3D& hitPosition = msop.getPos();
112  genfit::FieldManager::getInstance()->getFieldVal(hitPosition.X(), hitPosition.Y(), hitPosition.Z(), Bx, By, Bz);
113  } else {
114  genfit::FieldManager::getInstance()->getFieldVal(poca.X(), poca.Y(), poca.Z(), Bx, By, Bz);
115  }
116  Bz = Bz / 10.; // In SI-Units
117 
118  const uint64_t hitPatternCDCInitializer = getHitPatternCDCInitializer(recoTrack, trackRep);
119  const uint32_t hitPatternVXDInitializer = getHitPatternVXDInitializer(recoTrack, trackRep);
120 
121  const auto newTrackFitResult = trackFitResults.appendNew(
122  ROOT::Math::XYZVector(poca), ROOT::Math::XYZVector(dirInPoca), cov, charge, particleType, pValue, Bz,
123  hitPatternCDCInitializer, hitPatternVXDInitializer, nDF
124  );
125 
126  const int newTrackFitResultArrayIndex = newTrackFitResult->getArrayIndex();
127  newTrack.setTrackFitResultIndex(particleType, newTrackFitResultArrayIndex);
128  }
129 
130  B2DEBUG(27, "Number of fitted hypothesis = " << newTrack.getNumberOfFittedHypotheses());
131  if (newTrack.getNumberOfFittedHypotheses() > 0) {
132  Track* addedTrack = tracks.appendNew(newTrack);
133  addedTrack->addRelationTo(&recoTrack);
134  return true;
135  } else {
136  B2DEBUG(28, "No valid fit for any given hypothesis. No Track is added to the Tracks StoreArray.");
137  }
138  return true;
139 }
DataType Z() const
access variable Z (= .at(2) without boundary check)
Definition: B2Vector3.h:435
DataType X() const
access variable X (= .at(0) without boundary check)
Definition: B2Vector3.h:431
DataType Y() const
access variable Y (= .at(1) without boundary check)
Definition: B2Vector3.h:433
The ParticleType class for identifying different particle types.
Definition: Const.h:399
static const ParticleSet chargedStableSet
set of charged stable particles
Definition: Const.h:609
static genfit::Track & getGenfitTrack(RecoTrack &recoTrack)
Give access to the RecoTrack's genfit::Track.
Definition: RecoTrack.cc:404
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:621
bool wasFitSuccessful(const genfit::AbsTrackRep *representation=nullptr) const
Returns true if the last fit with the given representation was successful.
Definition: RecoTrack.cc:336
const genfit::MeasuredStateOnPlane & getMeasuredStateOnPlaneClosestTo(const ROOT::Math::XYZVector &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:426
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:638
float getQualityIndicator() const
Get the quality index attached to this RecoTrack given by one of the reconstruction algorithms....
Definition: RecoTrack.h:841
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:605
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).
Accessor to arrays stored in the data store.
Definition: StoreArray.h:113
static uint32_t getHitPatternVXDInitializer(const RecoTrack &recoTrack, const genfit::AbsTrackRep *representation=nullptr)
Get the HitPattern in the VXD.
static uint64_t getHitPatternCDCInitializer(const RecoTrack &recoTrack, const genfit::AbsTrackRep *representation=nullptr)
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.
ROOT::Math::XYZVector poca(ROOT::Math::XYZVector const &trackPos, ROOT::Math::XYZVector const &trackP, ROOT::Math::XYZVector 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: