8 #include <tracking/trackFitting/trackBuilder/factories/TrackBuilder.h>
11 #include <framework/datastore/StoreArray.h>
12 #include <mdst/dataobjects/MCParticle.h>
13 #include <mdst/dataobjects/HitPatternVXD.h>
14 #include <mdst/dataobjects/HitPatternCDC.h>
15 #include <mdst/dataobjects/Track.h>
16 #include <mdst/dataobjects/TrackFitResult.h>
17 #include <cdc/dataobjects/CDCRecoHit.h>
18 #include <pxd/reconstruction/PXDRecoHit.h>
19 #include <svd/reconstruction/SVDRecoHit.h>
20 #include <svd/reconstruction/SVDRecoHit2D.h>
21 #include <tracking/dataobjects/RecoTrack.h>
24 #include <TMatrixDSym.h>
26 #include <genfit/FitStatus.h>
27 #include <genfit/KalmanFitterInfo.h>
28 #include <genfit/Track.h>
29 #include <genfit/TrackPoint.h>
30 #include <genfit/MeasuredStateOnPlane.h>
31 #include <genfit/FieldManager.h>
36 const bool useClosestHitToIP,
const bool useBFieldAtHit)
42 B2DEBUG(100, trackReps.size() <<
" track representations available.");
45 bool repAlreadySet =
false;
46 unsigned int repIDPlusOne = 0;
47 for (
const auto& trackRep : trackReps) {
53 B2DEBUG(100,
"Track fitted with hypothesis that is not a ChargedStable (PDG code = " << particleType.
getPDGCode() <<
")");
59 B2DEBUG(100,
"The fit with the given track representation (" << std::abs(trackRep->getPDG()) <<
60 ") was not successful. Skipping ...");
64 if (not repAlreadySet) {
72 if (useClosestHitToIP) {
78 B2WARNING(exception.
what());
86 B2WARNING(
"Could not extrapolate the fit result for pdg " << particleType.
getPDGCode() <<
87 " to the perigee point. Why, I don't know.");
93 TVector3 poca(0., 0., 0.);
94 TVector3 dirInPoca(0., 0., 0.);
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());
105 if (useBFieldAtHit) {
106 const TVector3& hitPosition = msop.getPos();
116 const auto newTrackFitResult = trackFitResults.
appendNew(
117 poca, dirInPoca, cov, charge, particleType, pValue, Bz,
118 hitPatternCDCInitializer, hitPatternVXDInitializer, nDF
121 const int newTrackFitResultArrayIndex = newTrackFitResult->getArrayIndex();
127 Track* addedTrack = tracks.appendNew(newTrack);
130 const MCParticle* mcParticle = mcParticleWithWeight.first;
132 B2DEBUG(200,
"Relation to MCParticle set.");
133 addedTrack->
addRelationTo(mcParticle, mcParticleWithWeight.second);
135 B2DEBUG(200,
"Relation to MCParticle not set. No related MCParticle to RecoTrack.");
139 B2DEBUG(200,
"Relation to MCParticle not set. No related MCParticle to RecoTrack.");
150 int nNotFittedVXDhits = 0;
152 for (
const auto& trackPoint : hitPointsWithMeasurements) {
154 for (
size_t measurementId = 0; measurementId < trackPoint->getNumRawMeasurements(); measurementId++) {
160 const double weight = kalmanInfo->
getWeights().at(measurementId);
171 const int currentHits = hitPatternVXD.
getPXDLayer(layerNumber, HitPatternVXD::PXDMode::normal);
172 hitPatternVXD.
setPXDLayer(layerNumber, currentHits + 1, HitPatternVXD::PXDMode::normal);
179 const auto& currentHits = hitPatternVXD.
getSVDLayer(layerNumber);
180 hitPatternVXD.
setSVDLayer(layerNumber, currentHits.first + 1, currentHits.second + 1);
183 const auto& currentHits = hitPatternVXD.
getSVDLayer(layerNumber);
186 hitPatternVXD.
setSVDLayer(layerNumber, currentHits.first + 1, currentHits.second);
188 hitPatternVXD.
setSVDLayer(layerNumber, currentHits.first , currentHits.second + 1);
194 if (nNotFittedVXDhits > 0) {
195 B2DEBUG(100,
" No KalmanFitterInfo associated to some TrackPoints with VXD hits, not filling the HitPatternVXD");
196 B2DEBUG(100, nNotFittedVXDhits <<
" had no FitterInfo");
207 int nNotFittedCDChits = 0;
211 for (
const auto& trackPoint : hitPointsWithMeasurements) {
213 for (
size_t measurementId = 0; measurementId < trackPoint->getNumRawMeasurements(); measurementId++) {
219 const double weight = kalmanInfo->
getWeights().at(measurementId);
237 if (nNotFittedCDChits > 0) {
238 B2DEBUG(100,
" No KalmanFitterInfo associated to some TrackPoints with CDC hits, not filling the HitPatternCDC");
239 B2DEBUG(100, nNotFittedCDChits <<
" out of " << nCDChits <<
" had no FitterInfo");
This class is used to transfer CDC information to the track fit.
WireID getWireID() const
Getter for WireID object.
The ParticleType class for identifying different particle types.
int getPDGCode() const
PDG code.
static const ParticleSet chargedStableSet
set of charged stable particles
Hit pattern of CDC hits within a track.
void setNHits(unsigned short nHits)
Sets the 8 MSBs to the total number of hits in the CDC.
void setLayer(const unsigned short layer)
Set bit corresponding to layer to true.
ULong64_t getInteger() const
Getter for underlying integer type.
Hit pattern of the VXD within a track.
unsigned int getInteger() const
Getter for the underlying integer.
void setSVDLayer(const unsigned short layerId, unsigned short uHits, unsigned short vHits)
Set the number of hits in a specific layer of the SVD.
void setPXDLayer(const unsigned short layerId, unsigned short nHits, const PXDMode &mode=PXDMode::normal)
Set the number of hits in a specific layer of the PXD.
unsigned short getPXDLayer(const unsigned short layerId, const PXDMode &mode=PXDMode::normal) const
Get the number of hits in a specific layer of the PXD.
std::pair< const unsigned short, const unsigned short > getSVDLayer(const unsigned short layerId) const
Get the number of hits in a specific layer of the SVD.
A Class to store the Monte Carlo particle information.
PXDRecoHit - an extended form of PXDCluster containing geometry information.
VxdID getSensorID() const
Get the compact ID.
static genfit::Track & getGenfitTrack(RecoTrack &recoTrack)
Give access to the RecoTrack's genfit::Track.
This is the Reconstruction Event-Data Model Track.
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...
bool wasFitSuccessful(const genfit::AbsTrackRep *representation=nullptr) const
Returns true if the last fit with the given representation was successful.
const std::vector< genfit::TrackPoint * > & getHitPointsWithMeasurement() const
Return a list of measurements and track points, which can be used e.g. to extrapolate....
const std::vector< genfit::AbsTrackRep * > & getRepresentations() const
Return a list of track representations. You are not allowed to modify or delete them!
float getQualityIndicator() const
Get the quality index attached to this RecoTrack given by one of the reconstruction algorithms....
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...
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...
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.
SVDRecoHit - an extended form of SVDHit containing geometry information.
VxdID getSensorID() const
Get the compact ID.
SVDRecoHit - an extended form of SVDHit containing geometry information.
bool isU() const
Is the coordinate u or v?
VxdID getSensorID() const
Get the compact ID.
Accessor to arrays stored in the data store.
T * appendNew()
Construct a new T object at the end of the array.
bool storeTrackFromRecoTrack(RecoTrack &recoTrack, const bool useClosestHitToIP=false, const bool useBFieldAtHit=false)
Stores a Belle2 Track from a Reco Track.
static uint32_t getHitPatternVXDInitializer(const RecoTrack &recoTrack)
Get the HitPattern in the VXD.
TVector3 m_beamAxis
Extrapolation target, positive z direction.
std::string m_trackColName
TrackColName (output).
std::string m_mcParticleColName
MCParticleColName (input, optional).
std::string m_trackFitResultColName
TrackFitResultColName (output).
TVector3 m_beamSpot
Extrapolation target, origin.
static uint64_t getHitPatternCDCInitializer(const RecoTrack &recoTrack)
Get the HitPattern in the CDC.
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 ...
unsigned int getNumberOfFittedHypotheses() const
Returns the number of fitted hypothesis which are stored in this track.
baseType getLayerNumber() const
Get the layer id.
Class to identify a wire inside the CDC.
unsigned short getICLayer() const
Getter for continuous layer numbering.
Contains the measurement and covariance in raw detector coordinates.
Exception class for error handling in GENFIT (provides storage for diagnostic information)
virtual const char * what() const noexcept
Standard error message handling for exceptions. use like "std::cerr << e.what();".
TVector3 getFieldVal(const TVector3 &position)
This does NOT use the cache!
static FieldManager * getInstance()
Get singleton instance.
virtual double getPVal() const
Get the p value of the fit.
double getCharge() const
Get the fitted charge.
double getNdf() const
Get the degrees of freedom of the fit.
Collects information needed and produced by a AbsKalmanFitter implementations and is specific to one ...
std::vector< double > getWeights() const
Get weights of measurements.
#StateOnPlane with additional covariance matrix.
Abstract base class for different kinds of events.