Belle II Software  release-08-01-10
Track.h
1 /* Copyright 2008-2010, Technische Universitaet Muenchen,
2  Authors: Christian Hoeppner & Sebastian Neubert & Johannes Rauch & Tobias Schlüter
3 
4  This file is part of GENFIT.
5 
6  GENFIT is free software: you can redistribute it and/or modify
7  it under the terms of the GNU Lesser General Public License as published
8  by the Free Software Foundation, either version 3 of the License, or
9  (at your option) any later version.
10 
11  GENFIT is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU Lesser General Public License for more details.
15 
16  You should have received a copy of the GNU Lesser General Public License
17  along with GENFIT. If not, see <http://www.gnu.org/licenses/>.
18 */
19 
24 #ifndef genfit_Track_h
25 #define genfit_Track_h
26 
27 #include "AbsTrackRep.h"
28 #include "FitStatus.h"
29 #include "MeasurementFactory.h"
30 #include "TrackCand.h"
31 #include "TrackPoint.h"
32 
33 #include <vector>
34 #include <TObject.h>
35 #include <TVectorD.h>
36 
37 
38 namespace genfit {
39 
40 class KalmanFitStatus;
41 
46  public:
50  bool operator() (const TrackPoint* lhs, const TrackPoint* rhs) const {
51  return lhs->getSortingParameter() < rhs->getSortingParameter();
52  }
53 };
54 
55 
71 class Track : public TObject {
72 
73  public:
74 
75  Track();
76 
93  Track(const TrackCand& trackCand, const MeasurementFactory<genfit::AbsMeasurement>& factory, AbsTrackRep* rep = nullptr);
94 
95  Track(AbsTrackRep* trackRep, const TVectorD& stateSeed);
96  Track(AbsTrackRep* trackRep, const TVector3& posSeed, const TVector3& momSeed);
97  Track(AbsTrackRep* trackRep, const TVectorD& stateSeed, const TMatrixDSym& covSeed);
98 
99  Track(const Track&); // copy constructor
100  Track& operator=(Track); // assignment operator
101  void swap(Track& other); // nothrow
102 
103  virtual ~Track();
104  virtual void Clear(Option_t* = "");
105 
106  void createMeasurements(const TrackCand& trackCand, const MeasurementFactory<genfit::AbsMeasurement>& factory);
107 
108  TrackPoint* getPoint(int id) const;
109  const std::vector< genfit::TrackPoint* > & getPoints() const {return trackPoints_;}
110  unsigned int getNumPoints() const {return trackPoints_.size();}
111 
112  TrackPoint* getPointWithMeasurement(int id) const;
113  const std::vector< genfit::TrackPoint* > & getPointsWithMeasurement() const {return trackPointsWithMeasurement_;}
114  unsigned int getNumPointsWithMeasurement() const {return trackPointsWithMeasurement_.size();}
115 
116  TrackPoint* getPointWithMeasurementAndFitterInfo(int id, const AbsTrackRep* rep = nullptr) const;
117  TrackPoint* getPointWithFitterInfo(int id, const AbsTrackRep* rep = nullptr) const;
118 
128  const MeasuredStateOnPlane& getFittedState(int id = 0, const AbsTrackRep* rep = nullptr, bool biased = true) const;
129 
130  AbsTrackRep* getTrackRep(int id) const {return trackReps_.at(id);}
132  const std::vector<genfit::AbsTrackRep*>& getTrackReps() const {return trackReps_;}
133  unsigned int getNumReps() const {return trackReps_.size();}
134 
136  int getIdForRep(const AbsTrackRep* rep) const;
137 
145  AbsTrackRep* getCardinalRep() const {return trackReps_.at(cardinalRep_);}
146  unsigned int getCardinalRepId() const {return cardinalRep_;}
147 
149  int getMcTrackId() const {return mcTrackId_;}
150 
152  bool hasFitStatus(const AbsTrackRep* rep = nullptr) const;
154  FitStatus* getFitStatus(const AbsTrackRep* rep = nullptr) const {if (rep == nullptr) rep = getCardinalRep(); return fitStatuses_.at(rep);}
155 
157  bool hasKalmanFitStatus(const AbsTrackRep* rep = nullptr) const;
159  KalmanFitStatus* getKalmanFitStatus(const AbsTrackRep* rep = nullptr) const;
160 
161  void setFitStatus(FitStatus* fitStatus, const AbsTrackRep* rep);
162 
163  double getTimeSeed() const {return timeSeed_;}
164  void setTimeSeed(double time) {timeSeed_ = time;}
165 
166  const TVectorD& getStateSeed() const {return stateSeed_;}
167  void setStateSeed(const TVectorD& s) {stateSeed_.ResizeTo(s); stateSeed_ = s;}
168  void setStateSeed(const TVector3& pos, const TVector3& mom);
169 
170  const TMatrixDSym& getCovSeed() const {return covSeed_;}
171  void setCovSeed(const TMatrixDSym& c) {covSeed_.ResizeTo(c); covSeed_ = c;}
172 
174  void setMcTrackId(int i) {mcTrackId_ = i;}
175 
183  void insertPoint(TrackPoint* point, int id = -1);
184 
192  void insertPoints(std::vector<genfit::TrackPoint*> points, int id = -1);
193 
194  void deletePoint(int id);
195 
197  void insertMeasurement(AbsMeasurement* measurement, int id = -1);
198 
209  void mergeTrack(const Track* other, int id = -1);
210 
211  void addTrackRep(AbsTrackRep* trackRep);
212 
214  void deleteTrackRep(int id);
215 
216  void setCardinalRep(int id);
218  void determineCardinalRep();
219 
225  bool sort();
226 
229  bool udpateSeed(int id = 0, AbsTrackRep* rep = nullptr, bool biased = true);
230 
232  void reverseTrackPoints();
233 
235  void reverseMomSeed() {
236  stateSeed_(3) *= -1; stateSeed_(4) *= -1; stateSeed_(5) *= -1;
237  }
238 
240  void switchPDGSigns(AbsTrackRep* rep = nullptr);
241 
243 
248  void reverseTrack();
249 
250 
251  void deleteForwardInfo(int startId = 0, int endId = -1, const AbsTrackRep* rep = nullptr); // delete in range [startId, endId]. If rep == nullptr, delete for ALL reps, otherwise only for rep.
252  void deleteBackwardInfo(int startId = 0, int endId = -1, const AbsTrackRep* rep = nullptr); // delete in range [startId, endId]. If rep == nullptr, delete for ALL reps, otherwise only for rep.
253  void deleteReferenceInfo(int startId = 0, int endId = -1, const AbsTrackRep* rep = nullptr); // delete in range [startId, endId]. If rep == nullptr, delete for ALL reps, otherwise only for rep.
254  void deleteMeasurementInfo(int startId = 0, int endId = -1, const AbsTrackRep* rep = nullptr); // delete in range [startId, endId]. If rep == nullptr, delete for ALL reps, otherwise only for rep.
255  void deleteFitterInfo(int startId = 0, int endId = -1, const AbsTrackRep* rep = nullptr); // delete in range [startId, endId]. If rep == nullptr, delete for ALL reps, otherwise only for rep.
256 
258  double getTrackLen(AbsTrackRep* rep = nullptr, int startId = 0, int endId = -1) const;
260  double getTOF(AbsTrackRep* rep = nullptr, int startId = 0, int endId = -1) const;
261 
269  void deleteFittedState(const genfit::AbsTrackRep* rep);
270 
272 
278  TrackCand* constructTrackCand() const;
279 
282  void fixWeights(AbsTrackRep* rep = nullptr, int startId = 0, int endId = -1);
283 
298  void prune(const Option_t* = "CFLWRMIU");
299 
300  void Print(const Option_t* = "") const;
301 
302  void checkConsistency() const;
303 
304  private:
305 
306  void trackHasChanged();
307 
308  void fillPointsWithMeasurement();
309 
310  std::vector<AbsTrackRep*> trackReps_; // Ownership
311  unsigned int cardinalRep_; // THE selected rep, default = 0;
312 
313  std::vector<TrackPoint*> trackPoints_; // Ownership
314  std::vector<TrackPoint*> trackPointsWithMeasurement_;
315 
316  std::map< const AbsTrackRep*, FitStatus* > fitStatuses_; // Ownership over FitStatus*
317 
319  double timeSeed_;
320  TVectorD stateSeed_; // 6D: position, momentum
321  TMatrixDSym covSeed_; // 6D
322 
323 
324  public:
325  ClassDef(Track,3)
326  // Class version history:
327  // ver 3: introduces timeSeed_
328 };
329 
330 } /* End of namespace genfit */
333 #endif // genfit_Track_h
Contains the measurement and covariance in raw detector coordinates.
Abstract base class for a track representation.
Definition: AbsTrackRep.h:66
Class where important numbers and properties of a fit can be stored.
Definition: FitStatus.h:80
FitStatus for use with AbsKalmanFitter implementations.
#StateOnPlane with additional covariance matrix.
Track candidate – seed values and indices.
Definition: TrackCand.h:69
Helper class for TrackPoint sorting, used in Track::sort().
Definition: Track.h:45
bool operator()(const TrackPoint *lhs, const TrackPoint *rhs) const
Comparison operator used in Track::sort().
Definition: Track.h:50
Object containing AbsMeasurement and AbsFitterInfo objects.
Definition: TrackPoint.h:46
Collection of TrackPoint objects, AbsTrackRep objects and FitStatus objects.
Definition: Track.h:71
void determineCardinalRep()
See with which AbsTrackRep the track was fitted best (converged fit w/ smallest chi2) and set the car...
Definition: Track.cc:648
bool sort()
Sort TrackPoint and according to their sorting parameters.
Definition: Track.cc:674
KalmanFitStatus * getKalmanFitStatus(const AbsTrackRep *rep=nullptr) const
If FitStatus is a KalmanFitStatus, return it. Otherwise return nullptr.
Definition: Track.cc:345
int getMcTrackId() const
Get the MCT track id, for MC simulations - default value = -1.
Definition: Track.h:149
void deleteFittedState(const genfit::AbsTrackRep *rep)
Delete the fit status and all the FitStates of the TrackPoints for the given hypothesis.
Definition: Track.cc:529
double getTOF(AbsTrackRep *rep=nullptr, int startId=0, int endId=-1) const
get time of flight in ns between to trackPoints (if nullptr, for cardinal rep)
Definition: Track.cc:1023
void insertPoints(std::vector< genfit::TrackPoint * > points, int id=-1)
Insert TrackPoints BEFORE TrackPoint with position id, if id >= 0.
Definition: Track.cc:436
TrackCand * constructTrackCand() const
Construct a new TrackCand containing the hit IDs of the measurements.
Definition: Track.cc:987
void insertPoint(TrackPoint *point, int id=-1)
Insert TrackPoint BEFORE TrackPoint with position id, if id >= 0.
Definition: Track.cc:375
bool udpateSeed(int id=0, AbsTrackRep *rep=nullptr, bool biased=true)
Try to set the fitted state as seed.
Definition: Track.cc:724
int mcTrackId_
if MC simulation, store the mc track id here
Definition: Track.h:318
void fixWeights(AbsTrackRep *rep=nullptr, int startId=0, int endId=-1)
Helper function: For all KalmanFitterInfos belonging to rep (if nullptr, for all reps),...
Definition: Track.cc:1057
bool hasFitStatus(const AbsTrackRep *rep=nullptr) const
Check if track has a FitStatus for given AbsTrackRep. Per default, check for cardinal rep.
Definition: Track.cc:321
double getTrackLen(AbsTrackRep *rep=nullptr, int startId=0, int endId=-1) const
get TrackLength between to trackPoints (if nullptr, for cardinal rep)
Definition: Track.cc:942
void reverseMomSeed()
Flip direction of momentum seed.
Definition: Track.h:235
FitStatus * getFitStatus(const AbsTrackRep *rep=nullptr) const
Get FitStatus for a AbsTrackRep. Per default, return FitStatus for cardinalRep.
Definition: Track.h:154
void insertMeasurement(AbsMeasurement *measurement, int id=-1)
Creates a new TrackPoint containing the measurement, and adds it to the track.
Definition: Track.cc:524
const MeasuredStateOnPlane & getFittedState(int id=0, const AbsTrackRep *rep=nullptr, bool biased=true) const
Shortcut to get FittedStates.
Definition: Track.cc:294
bool hasKalmanFitStatus(const AbsTrackRep *rep=nullptr) const
Check if track has a KalmanFitStatus for given AbsTrackRep. Per default, check for cardinal rep.
Definition: Track.cc:333
std::map< const AbsTrackRep *, FitStatus * > fitStatuses_
helper
Definition: Track.h:316
void setMcTrackId(int i)
Set the MCT track id, for MC simulations.
Definition: Track.h:174
void reverseTrackPoints()
Flip the ordering of the TrackPoints.
Definition: Track.cc:747
void prune(const Option_t *="CFLWRMIU")
Delete unneeded information from the Track.
Definition: Track.cc:1090
void mergeTrack(const Track *other, int id=-1)
Merge two tracks.
Definition: Track.cc:545
void switchPDGSigns(AbsTrackRep *rep=nullptr)
Switch the pdg signs of specified rep (of all reps if rep == nullptr).
Definition: Track.cc:760
const std::vector< genfit::AbsTrackRep * > & getTrackReps() const
Return the track representations as a list of pointers.
Definition: Track.h:132
void deleteTrackPointsAndFitStatus()
Delete all measurement information and the track points of the track. Does not delete track represent...
Definition: Track.cc:1691
void reverseTrack()
Make track ready to be fitted in reverse direction.
Definition: Track.cc:773
AbsTrackRep * getCardinalRep() const
Get cardinal track representation.
Definition: Track.h:145
void deleteTrackRep(int id)
Delete a AbsTrackRep and all corresponding AbsFitterInfo objects in every TrackPoint.
Definition: Track.cc:604
int getIdForRep(const AbsTrackRep *rep) const
This is used when streaming TrackPoints.
Definition: Track.cc:309
Defines for I/O streams used for error and debug printing.