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>
23#include <TMatrixDSym.h>
25#include <genfit/FitStatus.h>
26#include <genfit/KalmanFitterInfo.h>
27#include <genfit/Track.h>
28#include <genfit/TrackPoint.h>
29#include <genfit/MeasuredStateOnPlane.h>
30#include <genfit/FieldManager.h>
35 const bool useClosestHitToIP,
const bool useBFieldAtHit)
41 B2DEBUG(27, trackReps.size() <<
" track representations available.");
44 bool repAlreadySet =
false;
45 unsigned int repIDPlusOne = 0;
46 for (
const auto& trackRep : trackReps) {
52 B2DEBUG(27,
"Track fitted with hypothesis that is not a ChargedStable (PDG code = " << particleType.
getPDGCode() <<
")");
58 B2DEBUG(27,
"The fit with the given track representation (" << std::abs(trackRep->getPDG()) <<
59 ") was not successful. Skipping ...");
63 if (not repAlreadySet) {
69 genfit::MeasuredStateOnPlane msop;
71 if (useClosestHitToIP) {
76 }
catch (genfit::Exception& exception) {
77 B2WARNING(exception.what());
79 }
catch (
const std::runtime_error& er) {
80 B2WARNING(
"Runtime error encountered: " << er.what());
83 B2WARNING(
"Undefined exception encountered.");
87 genfit::MeasuredStateOnPlane extrapolatedMSoP = msop;
91 B2DEBUG(29,
"Could not extrapolate the fit result for pdg " << particleType.
getPDGCode() <<
92 " to the perigee point.");
98 TVector3 poca(0., 0., 0.);
99 TVector3 dirInPoca(0., 0., 0.);
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());
110 if (useBFieldAtHit) {
111 const B2Vector3D& hitPosition = msop.getPos();
112 genfit::FieldManager::getInstance()->getFieldVal(hitPosition.
X(), hitPosition.
Y(), hitPosition.
Z(), Bx, By, Bz);
114 genfit::FieldManager::getInstance()->getFieldVal(poca.X(), poca.Y(), poca.Z(), Bx, By, Bz);
121 const auto newTrackFitResult = trackFitResults.
appendNew(
122 ROOT::Math::XYZVector(poca), ROOT::Math::XYZVector(dirInPoca), cov, charge, particleType, pValue, Bz,
123 hitPatternCDCInitializer, hitPatternVXDInitializer, nDF
126 const int newTrackFitResultArrayIndex = newTrackFitResult->getArrayIndex();
132 Track* addedTrack = tracks.appendNew(newTrack);
136 B2DEBUG(28,
"No valid fit for any given hypothesis. No Track is added to the Tracks StoreArray.");
147 int nNotFittedVXDhits = 0;
149 for (
const auto& trackPoint : hitPointsWithMeasurements) {
151 genfit::KalmanFitterInfo* kalmanInfo = trackPoint->getKalmanFitterInfo(representation);
153 for (
size_t measurementId = 0; measurementId < trackPoint->getNumRawMeasurements(); measurementId++) {
155 genfit::AbsMeasurement* absMeas = trackPoint->getRawMeasurement(measurementId);
161 if (!pxdHit && !svdHit2D && !svdHit)
166 if (kalmanInfo->getNumMeasurements() > 1)
167 B2WARNING(
"VXD TrackPoint contains more than one KalmanFitterInfo: only the first will be considered");
169 const double weight = kalmanInfo->getWeights().at(0);
175 const int currentHits = hitPatternVXD.
getPXDLayer(layerNumber, HitPatternVXD::PXDMode::normal);
176 hitPatternVXD.
setPXDLayer(layerNumber, currentHits + 1, HitPatternVXD::PXDMode::normal);
181 const auto& currentHits = hitPatternVXD.
getSVDLayer(layerNumber);
182 hitPatternVXD.
setSVDLayer(layerNumber, currentHits.first + 1, currentHits.second + 1);
185 const auto& currentHits = hitPatternVXD.
getSVDLayer(layerNumber);
188 hitPatternVXD.
setSVDLayer(layerNumber, currentHits.first + 1, currentHits.second);
190 hitPatternVXD.
setSVDLayer(layerNumber, currentHits.first, currentHits.second + 1);
203 if (nNotFittedVXDhits > 0) {
204 B2DEBUG(27,
" No KalmanFitterInfo associated to some TrackPoints with VXD hits, not filling the HitPatternVXD");
205 B2DEBUG(27, nNotFittedVXDhits <<
" had no FitterInfo");
216 int nNotFittedCDChits = 0;
220 for (
const auto& trackPoint : hitPointsWithMeasurements) {
222 genfit::KalmanFitterInfo* kalmanInfo = trackPoint->getKalmanFitterInfo(representation);
224 for (
size_t measurementId = 0; measurementId < trackPoint->getNumRawMeasurements(); measurementId++) {
226 genfit::AbsMeasurement* absMeas = trackPoint->getRawMeasurement(measurementId);
233 bool isValidWeight =
false;
234 for (
unsigned int kfinfoId = 0; kfinfoId < kalmanInfo->getNumMeasurements(); kfinfoId++) {
235 const double weight = kalmanInfo->getWeights().at(kfinfoId);
239 isValidWeight =
true;
240 B2DEBUG(27,
"CDC: " << nCDChits <<
"\t" << cdcHit->
getWireID().
getEWire() <<
"\t" << kfinfoId <<
"\t" << weight);
261 if (nNotFittedCDChits > 0) {
262 B2DEBUG(27,
" No KalmanFitterInfo associated to some TrackPoints with CDC hits, not filling the HitPatternCDC");
263 B2DEBUG(27, nNotFittedCDChits <<
" out of " << nCDChits <<
" had no FitterInfo");
DataType Z() const
access variable Z (= .at(2) without boundary check)
DataType X() const
access variable X (= .at(0) without boundary check)
DataType Y() const
access variable Y (= .at(1) without boundary check)
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.
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 std::vector< genfit::AbsTrackRep * > & getRepresentations() const
Return a list of track representations. You are not allowed to modify or delete them!
bool wasFitSuccessful(const genfit::AbsTrackRep *representation=nullptr) const
Returns true if the last fit with the given representation was successful.
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...
float getQualityIndicator() const
Get the quality index attached to this RecoTrack given by one of the reconstruction algorithms....
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...
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...
const std::vector< genfit::TrackPoint * > & getHitPointsWithMeasurement() const
Return a list of measurements and track points, which can be used e.g. to extrapolate....
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).
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.
static uint32_t getHitPatternVXDInitializer(const RecoTrack &recoTrack, const genfit::AbsTrackRep *representation=nullptr)
Get the HitPattern in the VXD.
bool storeTrackFromRecoTrack(RecoTrack &recoTrack, const bool useClosestHitToIP=false, const bool useBFieldAtHit=false)
Stores a Belle2 Track from a Reco Track.
B2Vector3D m_beamSpot
Extrapolation target, origin.
std::string m_trackColName
TrackColName (output).
static uint64_t getHitPatternCDCInitializer(const RecoTrack &recoTrack, const genfit::AbsTrackRep *representation=nullptr)
Get the HitPattern in the CDC.
std::string m_trackFitResultColName
TrackFitResultColName (output).
B2Vector3D m_beamAxis
Extrapolation target, positive z direction.
Class that bundles various TrackFitResults.
void setTrackFitResultIndex(const Const::ChargedStable &chargedStable, short index)
Set an index (for positive values) or unavailability-code (index = -1) for a specific mass hypothesis...
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.
unsigned short getEWire() const
Getter for encoded wire number.
Abstract base class for different kinds of events.