2 #include "../include/candidatevertex.h"
4 #include "../include/vertexfitter.h"
5 #include "../include/vertexfitterlsm.h"
6 #include "../include/vertexresolver.h"
7 #include "../include/vertexresolverequalsteps.h"
8 #include "../include/vertexfuncmaxfinder.h"
9 #include "../include/vertexfuncmaxfinderclassicstepper.h"
10 #include "../../inc/trackstate.h"
11 #include "../include/vertexfunction.h"
12 #include "../../util/inc/util.h"
13 #include "../../util/inc/memorymanager.h"
23 VertexFitter* CandidateVertex::_FallbackFitter;
24 VertexResolver* CandidateVertex::_FallbackResolver;
25 VertexFuncMaxFinder* CandidateVertex::_FallbackMaxFinder;
29 : _Fitter(Fitter),_Resolver(Resolver),_MaxFinder(MaxFinder),_IP(0),_TrackStates(Tracks),_VertexFunction(VertexFunction),_VertexFuncMaxIsValid(0),_FitIsValid(0),_ErrorOfFitIsValid(0)
34 : _Fitter(Fitter),_Resolver(Resolver),_MaxFinder(MaxFinder),_IP(IP),_TrackStates(Tracks),_VertexFunction(VertexFunction),_VertexFuncMaxIsValid(0),_FitIsValid(0),_ErrorOfFitIsValid(0)
38 :_Position(Position),_PositionError(PositionError),_ChiSquaredOfFit(ChiSquaredOfFit),_ChiSquaredOfTrack(ChiSquaredOfTrack),_ChiSquaredOfIP(ChiSquaredOfIP),_FitIsValid(1),_ErrorOfFitIsValid(1)
42 : _Fitter(Fitter),_Resolver(Resolver),_MaxFinder(MaxFinder),_VertexFuncMaxIsValid(0),_FitIsValid(0),_ErrorOfFitIsValid(0)
44 if (Vertices.size()>0)
49 for (std::vector<CandidateVertex*>::const_iterator iCV = Vertices.begin();iCV != Vertices.end();++iCV)
51 for (std::vector<TrackState*>::const_iterator iTrack = (*iCV)->trackStateList().begin();iTrack != (*iCV)->trackStateList().end();++iTrack)
54 if (!this->
hasTrack((*iTrack)->parentTrack()))
60 if ((*iCV)->interactionPoint())
61 this->
setIP((*iCV)->interactionPoint());
68 std::vector<TrackState*>::iterator
position = find(_TrackStates.begin(), _TrackStates.end(), TrackToRemove);
69 if (position!=_TrackStates.end())
71 _TrackStates.erase(position);
81 std::vector<TrackState*>::iterator iTrack;
82 for (iTrack = _TrackStates.begin();iTrack!=_TrackStates.end() && ((*iTrack)->parentTrack() != TrackToRemove);++iTrack)
85 if (iTrack!=_TrackStates.end())
87 _TrackStates.erase(iTrack);
97 _TrackStates.push_back(TrackToAdd);
133 std::vector<TrackState*> SourceList = SourceVertex->
trackStateList();
134 for (std::vector<TrackState*>::iterator iSourceTrack = SourceList.begin();iSourceTrack != SourceList.end();++iSourceTrack)
144 for (std::list<CandidateVertex*>::const_iterator iLosingVertex = LosingVertices.begin();iLosingVertex != LosingVertices.end();++iLosingVertex)
148 (*iLosingVertex)->removeIP();
150 for (std::vector<TrackState*>::iterator iTrackState = _TrackStates.begin();iTrackState != _TrackStates.end();++iTrackState)
152 (*iLosingVertex)->removeTrack((*iTrackState)->parentTrack());
166 if (Prob < ProbThreshold)
170 double HighChiSquared = -1;
171 for (std::vector<TrackState*>::iterator iTrackState = _TrackStates.begin();iTrackState != _TrackStates.end();++iTrackState)
176 HighTrack = *iTrackState;
208 double HighChiSquared = -1;
209 for (std::vector<TrackState*>::iterator iTrackState = _TrackStates.begin();iTrackState != _TrackStates.end();++iTrackState)
214 HighTrack = *iTrackState;
218 if (HighChiSquared > Chi2Threshold)
244 double HighChiSquared = -1;
245 for (std::vector<TrackState*>::iterator iTrackState = _TrackStates.begin();iTrackState != _TrackStates.end();++iTrackState)
250 HighTrack = *iTrackState;
254 if (HighChiSquared > Chi2Threshold)
274 _ErrorOfFitIsValid=0;
287 _Fitter->fitVertex(this->
trackStateList(), this->
interactionPoint(),_Position,_PositionError,_ChiSquaredOfFit,_ChiSquaredOfTrack,_ChiSquaredOfIP);
290 _ErrorOfFitIsValid=CalculateError;
304 _ErrorOfFitIsValid=CalculateError;
309 _VertexFuncMaxPosition = _MaxFinder->findNearestMaximum(this->
position(), _VertexFunction);
310 _VertexFuncMaxValue = _VertexFunction->valueAt(_VertexFuncMaxPosition);
311 _VertexFuncMaxIsValid = 1;
321 return _Resolver->areResolved(this->
position(), Vertex->
position(), _VertexFunction, Threshold);
337 return _Resolver->areResolved(this->
position(), Vertex->
position(), _VertexFunction, Threshold);
349 for (std::vector<TrackState*>::const_iterator iTrack = _TrackStates.begin();iTrack != _TrackStates.end();++iTrack)
350 if ((*iTrack)->parentTrack() == Track)
return 1;
364 if (!_ErrorOfFitIsValid)
366 return _PositionError;
373 return _Position.distanceTo(Point);
380 return (_Position.subtract(Vertex->
position())).mag();
387 if(!_VertexFuncMaxIsValid)
389 return _VertexFuncMaxValue;
395 return _VertexFunction->valueAt(this->
position());
400 if(!_VertexFuncMaxIsValid)
402 return _VertexFuncMaxPosition;
410 std::map<TrackState*,double>::iterator iTrack = _ChiSquaredOfTrack.find(Track);
411 if(iTrack == _ChiSquaredOfTrack.end())
414 return _ChiSquaredOfTrack[Track];
423 return _ChiSquaredOfIP;
433 return _ChiSquaredOfTrack;
440 return _ChiSquaredOfFit;
449 double HighChiSquared = 0;
450 for (std::vector<TrackState*>::const_iterator iTrackState = _TrackStates.begin();iTrackState != _TrackStates.end();++iTrackState)
461 return HighChiSquared;
466 if (!_FallbackFitter)
472 return _FallbackFitter;
475 VertexResolver* CandidateVertex::_getFallbackResolver()
477 if (!_FallbackResolver)
482 return _FallbackResolver;
485 VertexFuncMaxFinder* CandidateVertex::_getFallbackMaxFinder()
487 if (!_FallbackMaxFinder)
492 return _FallbackMaxFinder;
double vertexFuncMaxValue() const
Return the value of the vertex function at this vertexes local maximum.
void mergeCandidateVertex(const CandidateVertex *SourceVertex)
Merge another vertex into this one.
bool removeTrack(Track *const TrackToRemove)
Remove the first TrackState from this vertices track list which has parent track TrackToRemove.
double chiSquaredOfIP() const
Return the chi squared contribution of the IP if this vertex has one.
VertexFuncMaxFinderClassicStepper FallbackVertexFuncMaxFinder
double prob(double ChiSquared, double DegreesOfFreedom)
Calculate probability from Chi Squared and Degrees of freedom.
eResolveType
Type of resolution to perform - vertex position or the nearest found maximum.
Interaction Point representation.
Vertex Function Interface.
void refit(bool CalculateError=0) const
Refit the vertex.
int trimByChi2(const double Chi2Threshold)
Trim trackstates with chi squared contributions bigger than the threshold.
double chiSquaredOfTrack(TrackState *Track) const
Return the chi squared contribution of a trackstate in this vertex.
double maxChiSquaredOfTrackIP() const
Return the chi squared contribution of the Track or IP with the highest chi square contribution...
A collection of TrackState objects with a fit and vertex function maximum.
double distanceTo(const Vector3 &Point) const
Return the distance from this Vertex to a point.
double vertexFuncValue() const
Return the value of the vertex function at the vertices position.
void setIP(InteractionPoint *IP)
Add an InteractionPoint.
int trimByProb(const double ProbThreshold)
Trim trackstates in order of decreasing chi squared until the vertex has a probabilty below that of t...
static MemoryManager< T > * Run()
Returns the Run duration singleton instance of the MemoryManager for type T.
void claimTracksFrom(const std::list< CandidateVertex * > &LosingVertices)
Claim tracks and IP from another vertex.
const Vector3 & position() const
Return the fitted position of this Vertex.
VertexResolverEqualSteps FallbackVertexResolver
Spatial point on a Track.
InteractionPoint * interactionPoint() const
Return the InteractionPoint in this Vertex.
bool removeTrackState(TrackState *const TrackToRemove)
Remove the first reference to a TrackState from this vertices track list.
Unique Track representation.
const Matrix3x3 & positionError() const
Return the fitted position error matrix of this Vertex.
bool hasTrack(Track *Track) const
Return if this Vertex contains the passed track.
const std::vector< TrackState * > & trackStateList() const
Return the TrackStates in this Vertex.
CandidateVertex(const std::vector< TrackState * > &Tracks, VertexFunction *VertexFunction, VertexFitter *Fitter=_getFallbackFitter(), VertexResolver *Resolver=_getFallbackResolver(), VertexFuncMaxFinder *MaxFinder=_getFallbackMaxFinder())
Constuct with just Track list and VertexFunction.
VertexFitterLSM FallbackVertexFitter
void invalidateFit() const
Invalidate the fit so that the refit() is called when needed.
double chiSquaredOfFit() const
Return the chi squared of the fit.
const Vector3 & vertexFuncMaxPosition() const
Return the position of this vertexes local maximum.
Vertex Function Maximum Finder Interface.
bool removeIP()
Remove this vertices InteractionPoint.
bool isResolvedFrom(CandidateVertex *const Vertex, const double Threshold, eResolveType Type) const
Resolve two vertices with this vertices resolver.
Vertex Resolver Interface.
const std::map< TrackState *, double > & chiSquaredOfAllTracks() const
Return the chi squared contribution of all the trackstates in this vertex.
void addTrackState(TrackState *TrackToAdd)
Add a TrackState to this vertex.
bool findVertexFuncMax() const
Find the local vertex function maximum.