Belle II Software development
NewV0Fitter Class Reference

Improved V0 fitter class. More...

#include <NewV0Fitter.h>

Classes

struct  FittedTrack
 Structure to save track data of the last successful iteration. More...
 

Public Member Functions

 NewV0Fitter (const std::string &trackFitResultsName="", const std::string &v0sName="", const std::string &v0ValidationVerticesName="", const std::string &recoTracksName="", const std::string &copiedRecoTracksName="CopiedRecoTracks", bool enableValidation=false)
 Constructor.
 
void initializeCuts (double vertexDistanceCut, double vertexChi2Cut, const std::tuple< double, double > &invMassRangeKshort, const std::tuple< double, double > &invMassRangeLambda, const std::tuple< double, double > &invMassRangePhoton)
 Initialization of cuts applied during the fit and store process.
 
void setFitterMode (int fitterMode)
 Setter for the fitter mode.
 
void setVertexFitter (std::unique_ptr< V0VertexFitter > vertexFitter)
 Setter for the vertex fitter, replacing the default one.
 
bool fitAndStore (const Track *trackPlus, const Track *trackMinus, const Const::ParticleType &v0Hypothesis, bool &isForceStored, bool &isHitRemoved)
 Fit V0 with given hypothesis and store results if fit is successful.
 

Static Public Member Functions

static std::pair< Const::ParticleType, Const::ParticleTypegetTrackHypotheses (const Const::ParticleType &v0Hypothesis)
 Returns daughter particle types for a given V0 hypothesis.
 

Private Types

enum  ErrorStatus {
  c_NoTrackRepresentation = -4 ,
  c_VertexFitFailed = -3 ,
  c_ExtrapolationFailed = -2 ,
  c_NotSelected = -1
}
 Error status codes returned by the vertexFit method. More...
 
enum  EInnerHitBits {
  c_BitTrackPlus = 0x1 ,
  c_BitTrackMinus = 0x2
}
 Bits used to signal that track has hits inside the V0 vertex. More...
 

Private Member Functions

int vertexFit (const RecoTrack *recoTrackPlus, const RecoTrack *recoTrackMinus, int pdgTrackPlus, int pdgTrackMinus, const Const::ParticleType &v0Hypothesis)
 Performs a vertex fit.
 
RecoTrackcopyRecoTrack (const RecoTrack *origRecoTrack, const genfit::MeasuredStateOnPlane &state)
 Make a copy of reco track.
 
const RecoTrackremoveHitsAndRefit (const RecoTrack *origRecoTrack, const RecoTrack *lastRecoTrack, const Const::ParticleType &ptype)
 Remove track inner hits and refit the track.
 
int isInnermostClusterShared (const RecoTrack *recoTrackPlus, const RecoTrack *recoTrackMinus)
 Returns bit flags indicating that the innermost cluster is shared between both tracks.
 
const TrackFitResultsaveTrackFitResult (const FittedTrack &trk, int sharedInnermostCluster)
 Append track fit result to the collection.
 

Static Private Member Functions

static const genfit::AbsTrackRep * getTrackRepresentation (const RecoTrack *recoTrack, int pdgCode)
 Returns track representation for a given PDG code.
 
static bool setCardinalRep (genfit::Track &gfTrack, int pdgCode)
 Sets cardinal representation of a given genfit track and PDG code.
 
static int extrapolateToVertex (genfit::MeasuredStateOnPlane &statePlus, genfit::MeasuredStateOnPlane &stateMinus, const genfit::GFRaveVertex &vertex)
 Extrapolation of both tracks to the vertex.
 

Private Attributes

std::string m_recoTracksName
 name of the RecoTracks collection
 
StoreArray< RecoTrackm_recoTracks
 RecoTracks collection.
 
StoreArray< TrackFitResultm_trackFitResults
 TrackFitResults collection.
 
StoreArray< V0m_v0s
 V0s collection.
 
StoreArray< V0ValidationVertexm_validationV0s
 V0ValidationVertex collection (optional)
 
StoreArray< RecoTrackm_copiedRecoTracks
 copied RecoTracks collection
 
double m_vertexDistanceCut = 0
 cut on the transverse radius
 
double m_vertexChi2Cut = 0
 Chi2 cut.
 
std::map< int, std::pair< double, double > > m_invMassCuts
 invariant mass cuts, key = abs(PDG)
 
std::unique_ptr< V0VertexFitterm_vertexFitter
 vertex fitter used to fit the V0 vertex
 
int m_fitterMode = 1
 fitter mode
 
bool m_validation = false
 validation flag
 
genfit::GFRaveVertex m_fittedVertex
 last successfully fitted vertex
 
double m_momentum = 0
 momentum of last successfully fitted vertex
 
double m_invMass = 0
 invariant mass of last successfully fitted vertex
 
FittedTrack m_trkPlus
 positively charged track data of last successfully fitted vertex
 
FittedTrack m_trkMinus
 negatively charged track data of last successfully fitted vertex
 

Detailed Description

Improved V0 fitter class.

Definition at line 33 of file NewV0Fitter.h.

Member Enumeration Documentation

◆ EInnerHitBits

enum EInnerHitBits
private

Bits used to signal that track has hits inside the V0 vertex.

Enumerator
c_BitTrackPlus 

positive track has inner hits

c_BitTrackMinus 

negative track has inner hits

Definition at line 149 of file NewV0Fitter.h.

149 {
150 c_BitTrackPlus = 0x1,
151 c_BitTrackMinus = 0x2
152 };

◆ ErrorStatus

enum ErrorStatus
private

Error status codes returned by the vertexFit method.

Enumerator
c_NoTrackRepresentation 

no track representation for given PDG code

c_VertexFitFailed 

vertex fit failed

c_ExtrapolationFailed 

track extrapolation failed

c_NotSelected 

fitted vertex not passing the cuts

Definition at line 138 of file NewV0Fitter.h.

138 {
139 c_NoTrackRepresentation = -4,
140 c_VertexFitFailed = -3,
141 c_ExtrapolationFailed = -2,
142 c_NotSelected = -1
143 };

Constructor & Destructor Documentation

◆ NewV0Fitter()

NewV0Fitter ( const std::string & trackFitResultsName = "",
const std::string & v0sName = "",
const std::string & v0ValidationVerticesName = "",
const std::string & recoTracksName = "",
const std::string & copiedRecoTracksName = "CopiedRecoTracks",
bool enableValidation = false )
explicit

Constructor.

Parameters
trackFitResultsNamename of the StoreArray TrackFitResults
v0sNamename of the StoreArray V0s
v0ValidationVerticesNamename of the StoreArray V0ValidationVertex
recoTracksNamename of the StoreArray RecoTracks
copiedRecoTracksNamename of the StoreArray of copied RecoTracks
enableValidationon true store additional data for validation

Definition at line 24 of file NewV0Fitter.cc.

28 m_validation(enableValidation)
29{
30 B2ASSERT("V0Fitter: material effects not set up. Please use SetupGenfitExtrapolationModule.",
31 genfit::MaterialEffects::getInstance()->isInitialized());
32 B2ASSERT("V0Fitter: magnetic field not set up. Please use SetupGenfitExtrapolationModule.",
33 genfit::FieldManager::getInstance()->isInitialized());
34
36 m_trackFitResults.isRequired(trackFitResultsName);
37
39 m_copiedRecoTracks.registerInDataStore(copiedRecoTracksName, DataStore::c_ErrorIfAlreadyRegistered);
41 m_copiedRecoTracks.registerRelationTo(m_recoTracks);
42
43 if (m_validation) {
44 m_validationV0s.registerInDataStore(v0ValidationVerticesName, DataStore::c_ErrorIfAlreadyRegistered);
45 m_v0s.registerRelationTo(m_validationV0s);
46 }
47
48}
@ c_WriteOut
Object/array should be saved by output modules.
Definition DataStore.h:70
@ c_ErrorIfAlreadyRegistered
If the object/array was already registered, produce an error (aborting initialisation).
Definition DataStore.h:72
StoreArray< V0ValidationVertex > m_validationV0s
V0ValidationVertex collection (optional)
StoreArray< RecoTrack > m_copiedRecoTracks
copied RecoTracks collection
bool m_validation
validation flag
StoreArray< V0 > m_v0s
V0s collection.
StoreArray< TrackFitResult > m_trackFitResults
TrackFitResults collection.
std::string m_recoTracksName
name of the RecoTracks collection
StoreArray< RecoTrack > m_recoTracks
RecoTracks collection.
std::unique_ptr< V0VertexFitter > m_vertexFitter
vertex fitter used to fit the V0 vertex
static void registerRequiredRelations(const StoreArray< RecoTrack > &recoTracks, std::string const &pxdHitsStoreArrayName="", std::string const &svdHitsStoreArrayName="", std::string const &cdcHitsStoreArrayName="", std::string const &bklmHitsStoreArrayName="", std::string const &eklmHitsStoreArrayName="", std::string const &recoHitInformationStoreArrayName="")
Convenience method which registers all relations required to fully use a RecoTrack.
Definition RecoTrack.cc:53
static std::unique_ptr< V0VertexFitter > create(const std::string &name)
Create the fitter registered under the given name.

Member Function Documentation

◆ copyRecoTrack()

RecoTrack * copyRecoTrack ( const RecoTrack * origRecoTrack,
const genfit::MeasuredStateOnPlane & state )
private

Make a copy of reco track.

Parameters
origRecoTracksource
statemeasured state for the track fit seeding
Returns
a copy of source

Definition at line 361 of file NewV0Fitter.cc.

362{
363 RecoTrack* newRecoTrack = origRecoTrack->copyToStoreArrayUsing(m_copiedRecoTracks,
364 ROOT::Math::XYZVector(state.getPos()),
365 ROOT::Math::XYZVector(state.getMom()),
366 state.getCharge(),
367 state.get6DCov(), state.getTime());
368 newRecoTrack->addHitsFromRecoTrack(origRecoTrack);
369 newRecoTrack->addRelationTo(origRecoTrack);
370 return newRecoTrack;
371}
size_t addHitsFromRecoTrack(const RecoTrack *recoTrack, unsigned int sortingParameterOffset=0, bool reversed=false, std::optional< double > optionalMinimalWeight=std::nullopt)
Add all hits from another RecoTrack to this RecoTrack.
Definition RecoTrack.cc:240
RecoTrack * copyToStoreArrayUsing(StoreArray< RecoTrack > &storeArray, const ROOT::Math::XYZVector &position, const ROOT::Math::XYZVector &momentum, short charge, const TMatrixDSym &covariance, double timeSeed) const
Append a new RecoTrack to the given store array and copy its general properties, but not the hits the...
Definition RecoTrack.cc:511
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).

◆ extrapolateToVertex()

int extrapolateToVertex ( genfit::MeasuredStateOnPlane & statePlus,
genfit::MeasuredStateOnPlane & stateMinus,
const genfit::GFRaveVertex & vertex )
staticprivate

Extrapolation of both tracks to the vertex.

On success the return value indicates if tracks have inner hits (see EInnerHitBits).

Parameters
statePlusmeasured state of positively charged track from which the extrapolation is performed [in/out]
stateMinusmeasured state of negatively charged track from which the extrapolation is performed [in/out]
vertexvertex
Returns
value >= 0 on success, value < 0 on failure

extrapolate the first (innermost) hit to the V0 vertex position the value will be positive (negative) if the direction of the extrapolation is (counter)momentum-wise

plus track has hits inside the V0 vertex.

minus track has hits inside the V0 vertex.

This shouldn't ever happen, but I can see the extrapolation code trying several windings before giving up, so this happens occasionally. Something more stable would perhaps be desirable.

Definition at line 251 of file NewV0Fitter.cc.

253{
254 try {
257 double extralengthPlus = statePlus.extrapolateToPoint(vertex.getPos());
258 double extralengthMinus = stateMinus.extrapolateToPoint(vertex.getPos());
259 unsigned status = 0;
260 if (extralengthPlus > 0) status |= c_BitTrackPlus;
261 if (extralengthMinus > 0) status |= c_BitTrackMinus;
262 return status;
263 } catch (...) {
267 B2DEBUG(22, "Could not extrapolate track to vertex.");
269 }
270}
@ c_ExtrapolationFailed
track extrapolation failed
@ c_BitTrackMinus
negative track has inner hits
@ c_BitTrackPlus
positive track has inner hits

◆ fitAndStore()

bool fitAndStore ( const Track * trackPlus,
const Track * trackMinus,
const Const::ParticleType & v0Hypothesis,
bool & isForceStored,
bool & isHitRemoved )

Fit V0 with given hypothesis and store results if fit is successful.

Parameters
trackPluspositively charged track
trackMinusnegatively charged track
v0HypothesisV0 hypothesis
isForceStoredtrue if V0 is forced to store when hit removal failed [out]
isHitRemovedtrue if inner hits have been removed (or at least tried to be removed) [out]
Returns
true on success

Initialize status flags and result storage

Get related recoTracks

PDG codes actually used in track fitting

initial vertex fit

try to refit tracks by removing inner hits and refit the vertex

Usually this procedure converges in up to 3 iterations (mostly in a single iteration), but for a small fraction of track pairs it does not converge at all, so we set the limit at 5.

save the results

Definition at line 81 of file NewV0Fitter.cc.

83{
85 isForceStored = false;
86 isHitRemoved = false;
87 m_trkPlus.recoTrack = nullptr;
88 m_trkMinus.recoTrack = nullptr;
89
91 const RecoTrack* recoTrackPlus = trackPlus->getRelated<RecoTrack>(m_recoTracksName);
92 if (not recoTrackPlus) return false;
93 const RecoTrack* recoTrackMinus = trackMinus->getRelated<RecoTrack>(m_recoTracksName);
94 if (not recoTrackMinus) return false;
95
97 auto trackHypotheses = getTrackHypotheses(v0Hypothesis);
98 auto ptypeTrackPlus = trackPlus->getTrackFitResultWithClosestMass(trackHypotheses.first)->getParticleType();
99 auto ptypeTrackMinus = trackMinus->getTrackFitResultWithClosestMass(trackHypotheses.second)->getParticleType();
100 int pdgTrackPlus = std::abs(ptypeTrackPlus.getPDGCode());
101 int pdgTrackMinus = std::abs(ptypeTrackMinus.getPDGCode());
102
104 int status = vertexFit(recoTrackPlus, recoTrackMinus, pdgTrackPlus, pdgTrackMinus, v0Hypothesis);
105 if (status < 0) return false;
106
107 if (m_fitterMode > 0) {
109 const RecoTrack* origRecoTrackPlus = recoTrackPlus;
110 const RecoTrack* origRecoTrackMinus = recoTrackMinus;
111 int counter = 0;
112 while (status != 0 and counter < 5) {
113 counter++;
116 const RecoTrack* trkPlus = recoTrackPlus;
117 if (status & c_BitTrackPlus) {
118 trkPlus = removeHitsAndRefit(origRecoTrackPlus, recoTrackPlus, ptypeTrackPlus);
119 if (not trkPlus) return false;
120 isHitRemoved = true;
121 }
122 const RecoTrack* trkMinus = recoTrackMinus;
123 if (status & c_BitTrackMinus) {
124 trkMinus = removeHitsAndRefit(origRecoTrackMinus, recoTrackMinus, ptypeTrackMinus);
125 if (not trkMinus) return false;
126 isHitRemoved = true;
127 }
128 if (trkPlus == recoTrackPlus and trkMinus == recoTrackMinus) break; // vertex fit already done, so exit the loop
129 status = vertexFit(trkPlus, trkMinus, pdgTrackPlus, pdgTrackMinus, v0Hypothesis);
130 if (status < 0) break; // save the results of the last successful iteration
131 recoTrackPlus = trkPlus;
132 recoTrackMinus = trkMinus;
133 }
134
135 isForceStored = (status != 0);
136 }
137
139 int sharedCluster = isInnermostClusterShared(recoTrackPlus, recoTrackMinus);
140 const auto* fitPlus = saveTrackFitResult(m_trkPlus, sharedCluster);
141 if (not fitPlus) return false;
142 const auto* fitMinus = saveTrackFitResult(m_trkMinus, sharedCluster);
143 if (not fitMinus) return false;
144
145 const auto* v0 = m_v0s.appendNew(std::make_pair(trackPlus, fitPlus),
146 std::make_pair(trackMinus, fitMinus),
147 m_fittedVertex.getPos().X(), m_fittedVertex.getPos().Y(), m_fittedVertex.getPos().Z());
148
149 if (m_validation) {
150 const auto* validationV0 = m_validationV0s.appendNew(std::make_pair(trackPlus, fitPlus),
151 std::make_pair(trackMinus, fitMinus),
152 ROOT::Math::XYZVector(m_fittedVertex.getPos()),
153 m_fittedVertex.getCov(),
155 m_fittedVertex.getChi2());
156 v0->addRelationTo(validationV0);
157 }
158
159 return true;
160}
FittedTrack m_trkPlus
positively charged track data of last successfully fitted vertex
double m_momentum
momentum of last successfully fitted vertex
const TrackFitResult * saveTrackFitResult(const FittedTrack &trk, int sharedInnermostCluster)
Append track fit result to the collection.
int isInnermostClusterShared(const RecoTrack *recoTrackPlus, const RecoTrack *recoTrackMinus)
Returns bit flags indicating that the innermost cluster is shared between both tracks.
genfit::GFRaveVertex m_fittedVertex
last successfully fitted vertex
static std::pair< Const::ParticleType, Const::ParticleType > getTrackHypotheses(const Const::ParticleType &v0Hypothesis)
Returns daughter particle types for a given V0 hypothesis.
double m_invMass
invariant mass of last successfully fitted vertex
int m_fitterMode
fitter mode
FittedTrack m_trkMinus
negatively charged track data of last successfully fitted vertex
int vertexFit(const RecoTrack *recoTrackPlus, const RecoTrack *recoTrackMinus, int pdgTrackPlus, int pdgTrackMinus, const Const::ParticleType &v0Hypothesis)
Performs a vertex fit.
const RecoTrack * removeHitsAndRefit(const RecoTrack *origRecoTrack, const RecoTrack *lastRecoTrack, const Const::ParticleType &ptype)
Remove track inner hits and refit the track.
T * getRelated(const std::string &name="", const std::string &namedRelation="") const
Get the object to or from which this object has a relation.
Const::ParticleType getParticleType() const
Getter for ParticleType of the mass hypothesis of the track fit.
const TrackFitResult * getTrackFitResultWithClosestMass(const Const::ChargedStable &requestedType) const
Return the track fit for the fit hypothesis with the closest mass.
Definition Track.cc:104

◆ getTrackHypotheses()

std::pair< Const::ParticleType, Const::ParticleType > getTrackHypotheses ( const Const::ParticleType & v0Hypothesis)
static

Returns daughter particle types for a given V0 hypothesis.

Parameters
v0HypothesisV0 hypothesis
Returns
a pair of daughter particle types

Definition at line 65 of file NewV0Fitter.cc.

66{
67 if (v0Hypothesis == Const::Kshort) {
68 return std::make_pair(Const::pion, Const::pion);
69 } else if (v0Hypothesis == Const::photon) {
70 return std::make_pair(Const::electron, Const::electron);
71 } else if (v0Hypothesis == Const::Lambda) {
72 return std::make_pair(Const::proton, Const::pion);
73 } else if (v0Hypothesis == Const::antiLambda) {
74 return std::make_pair(Const::pion, Const::proton);
75 }
76 B2FATAL("V0Fitter: given V0 hypothesis not available.");
77 return std::make_pair(Const::invalidParticle, Const::invalidParticle); // return something to avoid triggering cppcheck
78}
static const ParticleType Lambda
Lambda particle.
Definition Const.h:680
static const ChargedStable pion
charged pion particle
Definition Const.h:662
static const ParticleType antiLambda
Anti-Lambda particle.
Definition Const.h:681
static const ChargedStable proton
proton particle
Definition Const.h:664
static const ParticleType invalidParticle
Invalid particle, used internally.
Definition Const.h:682
static const ParticleType Kshort
K^0_S particle.
Definition Const.h:678
static const ParticleType photon
photon particle
Definition Const.h:674
static const ChargedStable electron
electron particle
Definition Const.h:660

◆ getTrackRepresentation()

const genfit::AbsTrackRep * getTrackRepresentation ( const RecoTrack * recoTrack,
int pdgCode )
staticprivate

Returns track representation for a given PDG code.

Parameters
recoTracktrack
pdgCodePDG code
Returns
track representation on success or nullptr on failure

Definition at line 227 of file NewV0Fitter.cc.

228{
229 const auto* rep = recoTrack->getTrackRepresentationForPDG(pdgCode);
230 if (rep and recoTrack->wasFitSuccessful(rep)) return rep;
231
232 B2ERROR("V0Fitter: track hypothesis with closest mass not available. Should never happen!");
233 return nullptr;
234}
bool wasFitSuccessful(const genfit::AbsTrackRep *representation=nullptr) const
Returns true if the last fit with the given representation was successful.
Definition RecoTrack.cc:337
genfit::AbsTrackRep * getTrackRepresentationForPDG(int pdgCode) const
Return an already created track representation of the given reco track for the PDG.
Definition RecoTrack.cc:476

◆ initializeCuts()

void initializeCuts ( double vertexDistanceCut,
double vertexChi2Cut,
const std::tuple< double, double > & invMassRangeKshort,
const std::tuple< double, double > & invMassRangeLambda,
const std::tuple< double, double > & invMassRangePhoton )

Initialization of cuts applied during the fit and store process.

Parameters
vertexDistanceCutcut on the transverse radius to cut-off vertices within the beam pipe
vertexChi2Cutcut on the vertex chi^2
invMassRangeKshortselection mass window for Ks
invMassRangeLambdaselection mass window for Lambda
invMassRangePhotonselection mass window for converted gamma

Definition at line 51 of file NewV0Fitter.cc.

56{
57 m_vertexDistanceCut = vertexDistanceCut;
58 m_vertexChi2Cut = vertexChi2Cut;
59 m_invMassCuts[22] = std::make_pair(std::get<0>(invMassRangePhoton), std::get<1>(invMassRangePhoton));
60 m_invMassCuts[310] = std::make_pair(std::get<0>(invMassRangeKshort), std::get<1>(invMassRangeKshort));
61 m_invMassCuts[3122] = std::make_pair(std::get<0>(invMassRangeLambda), std::get<1>(invMassRangeLambda));
62}
double m_vertexDistanceCut
cut on the transverse radius
double m_vertexChi2Cut
Chi2 cut.
std::map< int, std::pair< double, double > > m_invMassCuts
invariant mass cuts, key = abs(PDG)

◆ isInnermostClusterShared()

int isInnermostClusterShared ( const RecoTrack * recoTrackPlus,
const RecoTrack * recoTrackMinus )
private

Returns bit flags indicating that the innermost cluster is shared between both tracks.

Bit 0 is set if U cluster is shared, bit 1 is set if V cluster is shared, and both if shared cluster is PXD.

Parameters
recoTrackPluspositively charged track
recoTrackMinusnegatively charged track
Returns
bit flags

Definition at line 374 of file NewV0Fitter.cc.

375{
376 const auto& recoHitInformationsPlus = recoTrackPlus->getRecoHitInformations(true); // true to get sorted hits info
377 std::vector<RecoHitInformation*> innerHitsPlus;
378 for (const auto& hitInfo : recoHitInformationsPlus) {
379 if (hitInfo->useInFit()) innerHitsPlus.push_back(hitInfo);
380 if (innerHitsPlus.size() == 2) break;
381 }
382 if (innerHitsPlus.empty()) return 0;
383
384 const auto& recoHitInformationsMinus = recoTrackMinus->getRecoHitInformations(true); // true to get sorted hits info
385 std::vector<RecoHitInformation*> innerHitsMinus;
386 for (const auto& hitInfo : recoHitInformationsMinus) {
387 if (hitInfo->useInFit()) innerHitsMinus.push_back(hitInfo);
388 if (innerHitsMinus.size() == 2) break;
389 }
390 if (innerHitsMinus.empty()) return 0;
391
392 if (innerHitsPlus.front()->getTrackingDetector() != innerHitsMinus.front()->getTrackingDetector()) return 0;
393
394 if (innerHitsPlus.front()->getTrackingDetector() == RecoHitInformation::c_PXD) {
395 const auto* clusterPlus = innerHitsPlus.front()->getRelatedTo<PXDCluster>();
396 const auto* clusterMinus = innerHitsMinus.front()->getRelatedTo<PXDCluster>();
397 if (clusterPlus and clusterPlus == clusterMinus) return 0x03; // PXD cluster the same: set both bits
398 return 0;
399 }
400
401 int flag = 0;
402 VxdID sensorID = 0;
403 if (innerHitsPlus.front()->getTrackingDetector() == RecoHitInformation::c_SVD) {
404 const auto* clusterPlus = innerHitsPlus.front()->getRelatedTo<SVDCluster>();
405 const auto* clusterMinus = innerHitsMinus.front()->getRelatedTo<SVDCluster>();
406 if (clusterPlus and clusterPlus == clusterMinus) {
407 sensorID = clusterPlus->getSensorID();
408 if (clusterPlus->isUCluster()) flag = 0x01; // SVD U-cluster the same: set first bit
409 else flag = 0x02; // SVD V-cluster the same: set second bit
410 }
411 }
412
413 if (innerHitsPlus.size() != 2 or innerHitsMinus.size() != 2) return flag;
414
415 if (innerHitsPlus.back()->getTrackingDetector() == RecoHitInformation::c_SVD) {
416 const auto* clusterPlus = innerHitsPlus.back()->getRelatedTo<SVDCluster>();
417 const auto* clusterMinus = innerHitsMinus.back()->getRelatedTo<SVDCluster>();
418 if (clusterPlus and clusterPlus == clusterMinus and clusterPlus->getSensorID() == sensorID) {
419 if (clusterPlus->isUCluster()) flag |= 0x01; // SVD U-cluster the same: set first bit
420 else flag |= 0x02; // SVD V-cluster the same: set second bit
421 }
422 }
423
424 return flag;
425}
std::vector< RecoHitInformation * > getRecoHitInformations(bool getSorted=false) const
Return a list of all RecoHitInformations associated with the RecoTrack.
Definition RecoTrack.cc:558

◆ removeHitsAndRefit()

const RecoTrack * removeHitsAndRefit ( const RecoTrack * origRecoTrack,
const RecoTrack * lastRecoTrack,
const Const::ParticleType & ptype )
private

Remove track inner hits and refit the track.

On success return the refitted one, otherwise return the track of last iteration (or the original one if no hits need to be removed).

Parameters
origRecoTrackoriginal track
lastRecoTracktrack at last hit-removal iteration
ptypeparticle type for refit
Returns
refitted track on success, lastRecoTrack on failure, origRecoTrack if no hits removed

This shouldn't ever happen, but I can see the extrapolation code trying several windings before giving up, so this happens occasionally. Something more stable would perhaps be desirable.

Definition at line 273 of file NewV0Fitter.cc.

275{
276 // make a copy of useInFit flags
277 std::vector<bool> useInFit;
278 const auto& recoHitInformations = origRecoTrack->getRecoHitInformations(true); // true to get sorted hits info
279 useInFit.reserve(recoHitInformations.size());
280 for (const auto* hitInfo : recoHitInformations) useInFit.push_back(hitInfo->useInFit());
281
282 // get track representation for a given particle
283 const auto* rep = getTrackRepresentation(origRecoTrack, abs(ptype.getPDGCode()));
284 if (not rep) return lastRecoTrack;
285
286 // remove inner hits by setting useInFit flags to false
287 int removedHits = 0;
288 unsigned firstHit = 0;
289 for (unsigned i = 0; i < recoHitInformations.size(); i++) {
290 const auto* hitInfo = recoHitInformations[i];
291 if (not hitInfo->useInFit()) continue;
292 try {
293 auto state = origRecoTrack->getMeasuredStateOnPlaneFromRecoHit(hitInfo, rep); // a copy of
294 double extraLength = state.extrapolateToPoint(m_fittedVertex.getPos());
295 if (extraLength > 0) {
296 useInFit[i] = false;
297 removedHits++;
298 } else {
299 firstHit = i;
300 break;
301 }
302 } catch (NoTrackFitResult()) {
303 B2WARNING("V0Fitter exception: no FitterInfo assigned for TrackPoint created from this RecoHit.");
304 useInFit[i] = false;
305 removedHits++;
306 continue;
307 } catch (...) {
311 B2DEBUG(22, "Could not extrapolate track to vertex when removing inner hits.");
312 return lastRecoTrack;
313 }
314 }
315
316 if (m_fitterMode == 2) {
317 // remove SVD hits if there is only one or two left just after the vertex
318 std::vector<unsigned> svdIndex;
319 for (unsigned i = 0; i < useInFit.size(); i++) {
320 if (not useInFit[i]) continue;
321 const auto* hitInfo = recoHitInformations[i];
322 if (hitInfo->getTrackingDetector() == RecoHitInformation::c_SVD) svdIndex.push_back(i);
323 else break;
324 }
325 if (not svdIndex.empty() and svdIndex.size() < 3) {
326 for (unsigned i : svdIndex) {
327 useInFit[i] = false;
328 removedHits++;
329 }
330 }
331 }
332
333 if (removedHits == 0) return origRecoTrack; // in this case track doesn't need to be refitted
334
335 // count remaining hits and return if there is no hope for the fit to succeed
336 int nHits = 0;
337 for (auto x : useInFit) if (x) nHits++;
338 if (nHits < 5) return lastRecoTrack;
339
340 // make a copy of recoTrack
341 const auto& state = origRecoTrack->getMeasuredStateOnPlaneFromRecoHit(recoHitInformations[firstHit], rep);
342 auto* recoTrack_copy = copyRecoTrack(origRecoTrack, state);
343
344 // set useInFit flags in a copy of recoTrack
345 const auto& recoHitInfos = recoTrack_copy->getRecoHitInformations(true); // true to get sorted hits info
346 if (recoHitInfos.size() != useInFit.size()) {
347 B2ERROR("V0Fitter: copied recoTrack has different number of hits than the original one");
348 return lastRecoTrack;
349 }
350 for (unsigned i = 0; i < recoHitInfos.size(); i++) recoHitInfos[i]->setUseInFit(useInFit[i]);
351
352 // fit a copy of recoTrack
353 TrackFitter fitter;
354 bool ok = fitter.fit(*recoTrack_copy, ptype);
355 if (not ok) return lastRecoTrack;
356
357 return recoTrack_copy;
358}
int getPDGCode() const
PDG code.
Definition Const.h:474
static const genfit::AbsTrackRep * getTrackRepresentation(const RecoTrack *recoTrack, int pdgCode)
Returns track representation for a given PDG code.
RecoTrack * copyRecoTrack(const RecoTrack *origRecoTrack, const genfit::MeasuredStateOnPlane &state)
Make a copy of reco track.
const genfit::MeasuredStateOnPlane & getMeasuredStateOnPlaneFromRecoHit(const RecoHitInformation *recoHitInfo, const genfit::AbsTrackRep *representation=nullptr) const
Return genfit's MeasuredStateOnPlane on plane for associated with one RecoHitInformation.
Definition RecoTrack.cc:580

◆ saveTrackFitResult()

const TrackFitResult * saveTrackFitResult ( const FittedTrack & trk,
int sharedInnermostCluster )
private

Append track fit result to the collection.

Parameters
trktrack data
sharedInnermostClusterbit flags of shared innermost clusters
Returns
track fit result

Definition at line 428 of file NewV0Fitter.cc.

429{
430
431 const auto* recoTrack = trk.recoTrack;
432 if (not recoTrack) {
433 B2ERROR("V0Fitter: bug in saving track fit result, recoTrack is nullptr");
434 return nullptr;
435 }
436
437 auto hitPatternCDC = TrackBuilder::getHitPatternCDCInitializer(*recoTrack);
438 auto hitPatternVXD = TrackBuilder::getHitPatternVXDInitializer(*recoTrack);
439 if (sharedInnermostCluster > 0) {
440 auto pattern = HitPatternVXD(hitPatternVXD);
441 pattern.setInnermostHitShareStatus(sharedInnermostCluster);
442 hitPatternVXD = pattern.getInteger();
443 }
444 double Bz = BFieldManager::getFieldInTesla({0, 0, 0}).Z();
445 const auto& state = trk.state;
446
447 auto* fit = m_trackFitResults.appendNew(ROOT::Math::XYZVector(state.getPos()), ROOT::Math::XYZVector(state.getMom()),
448 state.get6DCov(), state.getCharge(), trk.ptype, trk.pValue,
449 Bz, hitPatternCDC, hitPatternVXD, trk.Ndf);
450 return fit;
451}
static ROOT::Math::XYZVector getFieldInTesla(const ROOT::Math::XYZVector &pos)
return the magnetic field at a given position in Tesla.
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.

◆ setCardinalRep()

bool setCardinalRep ( genfit::Track & gfTrack,
int pdgCode )
staticprivate

Sets cardinal representation of a given genfit track and PDG code.

Parameters
gfTrackgenfit track [in/out]
pdgCodePDG code
Returns
true on success

Definition at line 237 of file NewV0Fitter.cc.

238{
239 const auto& reps = gfTrack.getTrackReps();
240 for (unsigned id = 0; id < reps.size(); id++) {
241 if (abs(reps[id]->getPDG()) == pdgCode) {
242 gfTrack.setCardinalRep(id);
243 return true;
244 }
245 }
246
247 B2ERROR("V0Fitter: cannot set cardinal representation for PDG = " << pdgCode);
248 return false;
249}

◆ setFitterMode()

void setFitterMode ( int fitterMode)
inline

Setter for the fitter mode.

0: store V0 at the first vertex fit, regardless of inner hits 1: remove hits inside the V0 vertex position (default) 2: mode 1 + don't use SVD hits if there is only one available SVD hit-pair

Parameters
fitterModefitter mode

Definition at line 104 of file NewV0Fitter.h.

104{m_fitterMode = fitterMode;}

◆ setVertexFitter()

void setVertexFitter ( std::unique_ptr< V0VertexFitter > vertexFitter)
inline

Setter for the vertex fitter, replacing the default one.

The instances are created by the V0VertexFitterFactory.

Parameters
vertexFittervertex fitter to be used

Definition at line 111 of file NewV0Fitter.h.

111{m_vertexFitter = std::move(vertexFitter);}

◆ vertexFit()

int vertexFit ( const RecoTrack * recoTrackPlus,
const RecoTrack * recoTrackMinus,
int pdgTrackPlus,
int pdgTrackMinus,
const Const::ParticleType & v0Hypothesis )
private

Performs a vertex fit.

On success the return value indicates if tracks have inner hits or not (see EInnerHitBits). On failure it returns ErrorStatus code.

Parameters
recoTrackPluspositively charged track
recoTrackMinusnegatively charged track
pdgTrackPlusPDG code used in the fit of positively charged track (closest mass to V0 daughter)
pdgTrackMinusPDG code used in the fit of negatively charged track (closest mass to V0 daughter)
v0HypothesisV0 hypothesis
Returns
value >= 0 on success, value < 0 on failure

Definition at line 163 of file NewV0Fitter.cc.

165{
166
167 // get track representations for given PDG codes and check their existence
168
169 const auto* plusRepresentation = getTrackRepresentation(recoTrackPlus, pdgTrackPlus);
170 if (not plusRepresentation) return c_NoTrackRepresentation;
171
172 const auto* minusRepresentation = getTrackRepresentation(recoTrackMinus, pdgTrackMinus);
173 if (not minusRepresentation) return c_NoTrackRepresentation;
174
175 // make copies of genfit tracks which will be passed to vertex fit and set the cardinal representations
176
177 auto gfTrackPlus = recoTrackPlus->getGenfitTrack(); // a copy of
178 if (not setCardinalRep(gfTrackPlus, pdgTrackPlus)) return c_NoTrackRepresentation;
179
180 auto gfTrackMinus = recoTrackMinus->getGenfitTrack(); // a copy of
181 if (not setCardinalRep(gfTrackMinus, pdgTrackMinus)) return c_NoTrackRepresentation;
182
183 // fit vertex
184
185 genfit::GFRaveVertex vert;
186 if (not m_vertexFitter->fit(gfTrackPlus, gfTrackMinus, pdgTrackPlus, pdgTrackMinus, vert)) return c_VertexFitFailed;
187 auto vertexPos = ROOT::Math::XYZVector(vert.getPos());
188
189 // apply cuts on the vertex
190
191 if (vertexPos.Rho() < m_vertexDistanceCut) return c_NotSelected;
192 if (vert.getChi2() > m_vertexChi2Cut) return c_NotSelected;
193
194 // apply cut on the invariant mass
195
196 const auto& p1 = vert.getParameters(0)->getMom();
197 const auto& p2 = vert.getParameters(1)->getMom();
198 auto trackHypotheses = getTrackHypotheses(v0Hypothesis);
199 double mass1 = trackHypotheses.first.getMass();
200 double mass2 = trackHypotheses.second.getMass();
201 ROOT::Math::PxPyPzMVector fourVec1(p1.X(), p1.Y(), p1.Z(), mass1);
202 ROOT::Math::PxPyPzMVector fourVec2(p2.X(), p2.Y(), p2.Z(), mass2);
203 double invMass = (fourVec1 + fourVec2).M();
204 int pdgCode = abs(v0Hypothesis.getPDGCode());
205 const auto& cuts = m_invMassCuts[pdgCode];
206 if (invMass < cuts.first or invMass > cuts.second) return c_NotSelected;
207
208 // extrapolate tracks to fitted vertex; the return status, if positive, indicates whether there are inner hits
209
210 auto statePlus = recoTrackPlus->getMeasuredStateOnPlaneFromFirstHit(plusRepresentation); // a copy of
211 auto stateMinus = recoTrackMinus->getMeasuredStateOnPlaneFromFirstHit(minusRepresentation); // a copy of
212 int status = extrapolateToVertex(statePlus, stateMinus, vert);
213 if (status < 0) return c_ExtrapolationFailed;
214
215 // save fitted vertex and tracks
216
217 m_fittedVertex = vert;
218 m_momentum = (fourVec1 + fourVec2).P();
219 m_invMass = invMass;
220 m_trkPlus.set(recoTrackPlus, trackHypotheses.first, statePlus, plusRepresentation);
221 m_trkMinus.set(recoTrackMinus, trackHypotheses.second, stateMinus, minusRepresentation);
222
223 return status;
224}
static int extrapolateToVertex(genfit::MeasuredStateOnPlane &statePlus, genfit::MeasuredStateOnPlane &stateMinus, const genfit::GFRaveVertex &vertex)
Extrapolation of both tracks to the vertex.
@ c_NoTrackRepresentation
no track representation for given PDG code
@ c_NotSelected
fitted vertex not passing the cuts
@ c_VertexFitFailed
vertex fit failed
static bool setCardinalRep(genfit::Track &gfTrack, int pdgCode)
Sets cardinal representation of a given genfit track and PDG code.
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:606
const genfit::Track & getGenfitTrack() const
Returns genfit track.
Definition RecoTrack.h:503

Member Data Documentation

◆ m_copiedRecoTracks

StoreArray<RecoTrack> m_copiedRecoTracks
private

copied RecoTracks collection

Definition at line 237 of file NewV0Fitter.h.

◆ m_fittedVertex

genfit::GFRaveVertex m_fittedVertex
private

last successfully fitted vertex

Definition at line 249 of file NewV0Fitter.h.

◆ m_fitterMode

int m_fitterMode = 1
private

fitter mode

Definition at line 244 of file NewV0Fitter.h.

◆ m_invMass

double m_invMass = 0
private

invariant mass of last successfully fitted vertex

Definition at line 251 of file NewV0Fitter.h.

◆ m_invMassCuts

std::map<int, std::pair<double, double> > m_invMassCuts
private

invariant mass cuts, key = abs(PDG)

Definition at line 241 of file NewV0Fitter.h.

◆ m_momentum

double m_momentum = 0
private

momentum of last successfully fitted vertex

Definition at line 250 of file NewV0Fitter.h.

◆ m_recoTracks

StoreArray<RecoTrack> m_recoTracks
private

RecoTracks collection.

Definition at line 233 of file NewV0Fitter.h.

◆ m_recoTracksName

std::string m_recoTracksName
private

name of the RecoTracks collection

Definition at line 232 of file NewV0Fitter.h.

◆ m_trackFitResults

StoreArray<TrackFitResult> m_trackFitResults
private

TrackFitResults collection.

Definition at line 234 of file NewV0Fitter.h.

◆ m_trkMinus

FittedTrack m_trkMinus
private

negatively charged track data of last successfully fitted vertex

Definition at line 253 of file NewV0Fitter.h.

◆ m_trkPlus

FittedTrack m_trkPlus
private

positively charged track data of last successfully fitted vertex

Definition at line 252 of file NewV0Fitter.h.

◆ m_v0s

StoreArray<V0> m_v0s
private

V0s collection.

Definition at line 235 of file NewV0Fitter.h.

◆ m_validation

bool m_validation = false
private

validation flag

Definition at line 245 of file NewV0Fitter.h.

◆ m_validationV0s

StoreArray<V0ValidationVertex> m_validationV0s
private

V0ValidationVertex collection (optional)

Definition at line 236 of file NewV0Fitter.h.

◆ m_vertexChi2Cut

double m_vertexChi2Cut = 0
private

Chi2 cut.

Definition at line 240 of file NewV0Fitter.h.

◆ m_vertexDistanceCut

double m_vertexDistanceCut = 0
private

cut on the transverse radius

Definition at line 239 of file NewV0Fitter.h.

◆ m_vertexFitter

std::unique_ptr<V0VertexFitter> m_vertexFitter
private

vertex fitter used to fit the V0 vertex

Definition at line 243 of file NewV0Fitter.h.


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