![]() |
|
|||
File indexing completed on 2025-08-05 08:18:21
0001 /* Copyright 2008-2010, Technische Universitaet Muenchen, 0002 Authors: Christian Hoeppner & Sebastian Neubert & Johannes Rauch & Tobias Schlüter 0003 0004 This file is part of GENFIT. 0005 0006 GENFIT is free software: you can redistribute it and/or modify 0007 it under the terms of the GNU Lesser General Public License as published 0008 by the Free Software Foundation, either version 3 of the License, or 0009 (at your option) any later version. 0010 0011 GENFIT is distributed in the hope that it will be useful, 0012 but WITHOUT ANY WARRANTY; without even the implied warranty of 0013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0014 GNU Lesser General Public License for more details. 0015 0016 You should have received a copy of the GNU Lesser General Public License 0017 along with GENFIT. If not, see <http://www.gnu.org/licenses/>. 0018 */ 0019 0020 /** @addtogroup genfit 0021 * @{ 0022 */ 0023 0024 #ifndef genfit_Track_h 0025 #define genfit_Track_h 0026 0027 #include "AbsTrackRep.h" 0028 #include "FitStatus.h" 0029 #include "MeasurementFactory.h" 0030 #include "TrackCand.h" 0031 #include "TrackPoint.h" 0032 0033 #include <vector> 0034 #include <TObject.h> 0035 #include <TVectorD.h> 0036 0037 0038 namespace genfit { 0039 0040 class KalmanFitStatus; 0041 0042 /** 0043 * @brief Helper class for TrackPoint sorting, used in Track::sort(). 0044 */ 0045 class TrackPointComparator { 0046 public: 0047 /** 0048 * Comparison operator used in Track::sort(). Compares sorting parameter. 0049 */ 0050 bool operator() (const TrackPoint* lhs, const TrackPoint* rhs) const { 0051 return lhs->getSortingParameter() < rhs->getSortingParameter(); 0052 } 0053 }; 0054 0055 0056 /** 0057 * @brief Collection of TrackPoint objects, AbsTrackRep objects and FitStatus objects 0058 * 0059 * Holds a number of AbsTrackRep objects, which correspond to the 0060 * different particle hypotheses or track models which should be fitted. 0061 * A 6D seed #stateSeed_ (x,y,z,p_x,p_y,p_z) and 6x6 #covSeed_ should be provided as start values for fitting. 0062 * When fitting the Track with a AbsFitter, 0063 * a FitStatus object will be created, containing information about the fit. 0064 * The fitted states will be stored in AbsFitterInfo objects in every TrackPoints. 0065 * 0066 * The fit will be performed for every AbsTrackRep, 0067 * so after the fit there will be one AbsFitterInfo for each AbsTrackRep 0068 * in every TrackPoint, as well as one FitStatus for every AbsTrackRep. 0069 * 0070 */ 0071 class Track : public TObject { 0072 0073 public: 0074 0075 Track(); 0076 0077 /** 0078 * @ brief Construct Track from TrackCand, using a MeasurementFactory 0079 * 0080 * The MeasurementFactory will be used to create AbsMeasuremen objects. 0081 * TrackPoints will be created. 0082 * If two or more consecutive PlanarMeasurement objects with the same detector- and planeId 0083 * are created by the factory, they will be put into the same TrackPoint. 0084 * 0085 * Optionally, a AbsTrackRep can be provided. 0086 * 0087 * The stateSeed_ of the Track will be filled with the seed of the TrackCand. 0088 * A guess for covSeed_ will be made using the largest entry of the cov of the first measurement 0089 * and the number of measurements (For the covSeed_, it is just important that it will be 0090 * big enough not to bias the fit too much, but not too big in order to avoid 0091 * numerical problems). 0092 */ 0093 Track(const TrackCand& trackCand, const MeasurementFactory<genfit::AbsMeasurement>& factory, AbsTrackRep* rep = nullptr); 0094 0095 Track(AbsTrackRep* trackRep, const TVectorD& stateSeed); 0096 Track(AbsTrackRep* trackRep, const TVector3& posSeed, const TVector3& momSeed); 0097 Track(AbsTrackRep* trackRep, const TVectorD& stateSeed, const TMatrixDSym& covSeed); 0098 0099 Track(const Track&); // copy constructor 0100 Track& operator=(Track); // assignment operator 0101 void swap(Track& other); // nothrow 0102 0103 virtual ~Track(); 0104 virtual void Clear(Option_t* = ""); 0105 0106 void createMeasurements(const TrackCand& trackCand, const MeasurementFactory<genfit::AbsMeasurement>& factory); 0107 0108 TrackPoint* getPoint(int id) const; 0109 const std::vector< genfit::TrackPoint* > & getPoints() const {return trackPoints_;} 0110 unsigned int getNumPoints() const {return trackPoints_.size();} 0111 0112 TrackPoint* getPointWithMeasurement(int id) const; 0113 const std::vector< genfit::TrackPoint* > & getPointsWithMeasurement() const {return trackPointsWithMeasurement_;} 0114 unsigned int getNumPointsWithMeasurement() const {return trackPointsWithMeasurement_.size();} 0115 0116 TrackPoint* getPointWithMeasurementAndFitterInfo(int id, const AbsTrackRep* rep = nullptr) const; 0117 TrackPoint* getPointWithFitterInfo(int id, const AbsTrackRep* rep = nullptr) const; 0118 0119 /** 0120 * @brief Shortcut to get FittedStates. 0121 * 0122 * Uses getPointWithFitterInfo(id, rep). 0123 * Gets the fitted state at trackpoint id for the track representation rep. 0124 * Per default, the fitted state of the fitterInfo of the first TrackPoint 0125 * with one or more AbsFitterInfo objects 0126 * is returned. If no AbsTrackRep is specified, the AbsFitterInfo of the cardinal rep will be used. 0127 */ 0128 const MeasuredStateOnPlane& getFittedState(int id = 0, const AbsTrackRep* rep = nullptr, bool biased = true) const; 0129 0130 AbsTrackRep* getTrackRep(int id) const {return trackReps_.at(id);} 0131 /// Return the track representations as a list of pointers. 0132 const std::vector<genfit::AbsTrackRep*>& getTrackReps() const {return trackReps_;} 0133 unsigned int getNumReps() const {return trackReps_.size();} 0134 0135 //! This is used when streaming TrackPoints. 0136 int getIdForRep(const AbsTrackRep* rep) const; 0137 0138 /** @brief Get cardinal track representation 0139 * 0140 * The user has to choose which AbsTrackRep should be considered the 0141 * best one after the fit. E.g. the track representation giving the 0142 * smallest chi2 could be chosen. By default the first in the list is returned. 0143 * @sa #determineCardinalRep() 0144 */ 0145 AbsTrackRep* getCardinalRep() const {return trackReps_.at(cardinalRep_);} 0146 unsigned int getCardinalRepId() const {return cardinalRep_;} 0147 0148 //! Get the MCT track id, for MC simulations - default value = -1 0149 int getMcTrackId() const {return mcTrackId_;} 0150 0151 //! Check if track has a FitStatus for given AbsTrackRep. Per default, check for cardinal rep. 0152 bool hasFitStatus(const AbsTrackRep* rep = nullptr) const; 0153 //! Get FitStatus for a AbsTrackRep. Per default, return FitStatus for cardinalRep. 0154 FitStatus* getFitStatus(const AbsTrackRep* rep = nullptr) const {if (rep == nullptr) rep = getCardinalRep(); return fitStatuses_.at(rep);} 0155 0156 //! Check if track has a KalmanFitStatus for given AbsTrackRep. Per default, check for cardinal rep. 0157 bool hasKalmanFitStatus(const AbsTrackRep* rep = nullptr) const; 0158 //! If FitStatus is a KalmanFitStatus, return it. Otherwise return nullptr 0159 KalmanFitStatus* getKalmanFitStatus(const AbsTrackRep* rep = nullptr) const; 0160 0161 void setFitStatus(FitStatus* fitStatus, const AbsTrackRep* rep); 0162 0163 double getTimeSeed() const {return timeSeed_;} 0164 void setTimeSeed(double time) {timeSeed_ = time;} 0165 0166 const TVectorD& getStateSeed() const {return stateSeed_;} 0167 void setStateSeed(const TVectorD& s) {stateSeed_.ResizeTo(s); stateSeed_ = s;} 0168 void setStateSeed(const TVector3& pos, const TVector3& mom); 0169 0170 const TMatrixDSym& getCovSeed() const {return covSeed_;} 0171 void setCovSeed(const TMatrixDSym& c) {covSeed_.ResizeTo(c); covSeed_ = c;} 0172 0173 //! Set the MCT track id, for MC simulations 0174 void setMcTrackId(int i) {mcTrackId_ = i;} 0175 0176 /** 0177 * @brief Insert TrackPoint BEFORE TrackPoint with position id, if id >= 0. 0178 * 0179 * Id -1 means after last TrackPoint. Id -2 means before last TrackPoint. ... 0180 * Also deletes backwardInfos before new point and forwardInfos after new point. 0181 * Also sets Track backpointer of point accordingly. 0182 */ 0183 void insertPoint(TrackPoint* point, int id = -1); 0184 0185 /** 0186 * @brief Insert TrackPoints BEFORE TrackPoint with position id, if id >= 0. 0187 * 0188 * Id -1 means after last TrackPoint. Id -2 means before last TrackPoint. ... 0189 * Also deletes backwardInfos before and for new points and forwardInfos after and for new points. 0190 * Also sets Track backpointers of points accordingly. 0191 */ 0192 void insertPoints(std::vector<genfit::TrackPoint*> points, int id = -1); 0193 0194 void deletePoint(int id); 0195 0196 //! Creates a new TrackPoint containing the measurement, and adds it to the track 0197 void insertMeasurement(AbsMeasurement* measurement, int id = -1); 0198 0199 //! Delete all measurement information and the track points of the track. Does not delete track representations. 0200 void deleteTrackPointsAndFitStatus(); 0201 /** 0202 * @brief Merge two tracks. 0203 * 0204 * The TrackPoint objects of other will be cloned and inserted 0205 * after id (per default, they will be appended at the end). 0206 * The other Track will not be altered, the TrackPoint objects will be (deep) copied. 0207 * Only copies the TrackPoint objects, NOT the AbsTrackRep, FitStatus, seed state and other objects of the other track. 0208 */ 0209 void mergeTrack(const Track* other, int id = -1); 0210 0211 void addTrackRep(AbsTrackRep* trackRep); 0212 0213 //! Delete a AbsTrackRep and all corresponding AbsFitterInfo objects in every TrackPoint. 0214 void deleteTrackRep(int id); 0215 0216 void setCardinalRep(int id); 0217 //! See with which AbsTrackRep the track was fitted best (converged fit w/ smallest chi2) and set the cardinal rep accordingly. 0218 void determineCardinalRep(); 0219 0220 /** 0221 * @brief Sort TrackPoint and according to their sorting parameters. 0222 * 0223 * Returns if the order of the TrackPoint has actually changed. 0224 */ 0225 bool sort(); 0226 0227 //! Try to set the fitted state as seed. Return if it was successfull. 0228 //! Adapt the sign of all TrackReps' pdg to the actual fitted charge. 0229 bool udpateSeed(int id = 0, AbsTrackRep* rep = nullptr, bool biased = true); 0230 0231 //! Flip the ordering of the TrackPoints 0232 void reverseTrackPoints(); 0233 0234 //! Flip direction of momentum seed 0235 void reverseMomSeed() { 0236 stateSeed_(3) *= -1; stateSeed_(4) *= -1; stateSeed_(5) *= -1; 0237 } 0238 0239 //! Switch the pdg signs of specified rep (of all reps if rep == nullptr). 0240 void switchPDGSigns(AbsTrackRep* rep = nullptr); 0241 0242 //! Make track ready to be fitted in reverse direction 0243 /** 0244 * Flip the order of TrackPoints and the momentum direction of the seed state. 0245 * If possible, take the smoothed state of the last hit as new seed state. 0246 * Flip charge of the TrackReps. 0247 */ 0248 void reverseTrack(); 0249 0250 0251 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. 0252 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. 0253 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. 0254 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. 0255 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. 0256 0257 //! get TrackLength between to trackPoints (if nullptr, for cardinal rep) 0258 double getTrackLen(AbsTrackRep* rep = nullptr, int startId = 0, int endId = -1) const; 0259 //! get time of flight in ns between to trackPoints (if nullptr, for cardinal rep) 0260 double getTOF(AbsTrackRep* rep = nullptr, int startId = 0, int endId = -1) const; 0261 0262 /** 0263 * Delete the fit status and all the FitStates of the TrackPoints 0264 * for the given hypothesis. 0265 * This is equal to resetting the track for the rep, so another fit 0266 * can start from scratch. 0267 * Useful if you have changed some seeds. 0268 */ 0269 void deleteFittedState(const genfit::AbsTrackRep* rep); 0270 0271 //! Construct a new TrackCand containing the hit IDs of the measurements 0272 /** 0273 * The idea is hat you can get a TrackCand for storing the hit IDs after a track has been fitted. 0274 * His could have been reordered, added or removed, so that the original TackCand no longer 0275 * represents the Track correctly. 0276 * You might want to call determineCardinalRep() and/or udpateSeed() before. 0277 */ 0278 TrackCand* constructTrackCand() const; 0279 0280 //! Helper function: For all KalmanFitterInfos belonging to rep (if nullptr, for all reps), 0281 //! call the fixWeights() function, so that e.g. the DAF will not alter weights anymore. 0282 void fixWeights(AbsTrackRep* rep = nullptr, int startId = 0, int endId = -1); 0283 0284 /** 0285 * @brief Delete unneeded information from the Track. 0286 * 0287 * Possible options: (see also PruneFlags defined in FitStatus.h) 0288 * C: prune all reps except cardinalRep 0289 * F: prune all points except first point (also prune referenceInfo from fitterInfos) 0290 * L: prune all points except last point (also prune referenceInfo from fitterInfos) 0291 * FL: prune all points except first and last point (also prune referenceInfo from fitterInfos) 0292 * W: prune rawMeasurements from TrackPoints 0293 * R: prune referenceInfo from fitterInfos 0294 * M: prune measurementInfo from fitterInfos 0295 * I: if F, L, or FL is set, prune forward (backward) info of first (last) point 0296 * U: if fitterInfo is a KalmanFitterInfo, prune predictions and keep updates 0297 */ 0298 void prune(const Option_t* = "CFLWRMIU"); 0299 0300 void Print(const Option_t* = "") const; 0301 0302 void checkConsistency() const; 0303 0304 private: 0305 0306 void trackHasChanged(); 0307 0308 void fillPointsWithMeasurement(); 0309 0310 std::vector<AbsTrackRep*> trackReps_; // Ownership 0311 unsigned int cardinalRep_; // THE selected rep, default = 0; 0312 0313 std::vector<TrackPoint*> trackPoints_; // Ownership 0314 std::vector<TrackPoint*> trackPointsWithMeasurement_; //! helper 0315 0316 std::map< const AbsTrackRep*, FitStatus* > fitStatuses_; // Ownership over FitStatus* 0317 0318 int mcTrackId_; /**< if MC simulation, store the mc track id here */ 0319 double timeSeed_; 0320 TVectorD stateSeed_; // 6D: position, momentum 0321 TMatrixDSym covSeed_; // 6D 0322 0323 0324 public: 0325 ClassDef(Track,3) 0326 // Class version history: 0327 // ver 3: introduces timeSeed_ 0328 }; 0329 0330 } /* End of namespace genfit */ 0331 /** @} */ 0332 0333 #endif // genfit_Track_h
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
![]() ![]() |