Back to home page

sPhenix code displayed by LXR

 
 

    


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
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 /** @addtogroup genfit
0020  * @{ */
0021 
0022 #ifndef genfit_TrackCand_h
0023 #define genfit_TrackCand_h
0024 
0025 #include "TrackCandHit.h"
0026 
0027 #include <vector>
0028 #include <set>
0029 #include <assert.h>
0030 
0031 #include <TObject.h>
0032 #include <TVector3.h>
0033 #include <TVectorD.h>
0034 #include <TMatrixD.h>
0035 #include <TMatrixDSym.h>
0036 #include <TDatabasePDG.h>
0037 
0038 #include <cmath>
0039 
0040 
0041 namespace genfit {
0042 
0043 /** @brief Track candidate -- seed values and indices
0044  *
0045  *  @author Christian H&ouml;ppner (Technische Universit&auml;t M&uuml;nchen, original author)
0046  *  @author Sebastian Neubert  (Technische Universit&auml;t M&uuml;nchen, original author)
0047  *  @author Moritz Nadler (maintainer during 2012)
0048  *
0049  * The main task of the TrackCand object is to store a list of indices to
0050  * cluster objects. Each cluster in the Track is identified by it's
0051  * detector ID and it's index in the corresponding TClonesArray.
0052  * Also there is a ordering parameter to order hits.
0053  * Optionally, plane indices for the hits can be stored (most importantly
0054  * for fitting with the Daf).
0055  * This information is used by the RecoHitFactory to automatically load
0056  * RecoHits into a Track. Through this it is possible to define Tracks over
0057  * an arbitrary number of different detectors.
0058  *
0059  * In addition TrackCand offers members to store starting values for the fit.
0060  * The starting values (seeds) for the fit are stored as a 6D state (x,y,z,px,py,pz) and its
0061  * corresponding 6x6 covariance matrix. All seed getter and setter manipulate these two members
0062  * but the user can chose using TVector3 or TMatrixD to get/set the seed state.
0063  * However this information is not automatically used in genfit.
0064  * But a pointer to a TrackCand can be passed to the a RKTrackRep constructor
0065  * to make use of this information without manually extracting it from the TrackCand object.
0066  *
0067  * @sa RecoHitFactory
0068  */
0069 class TrackCand : public TObject {
0070 
0071 
0072  public:
0073 
0074 
0075   // Constructors/Destructors ---------
0076   TrackCand();
0077   ~TrackCand();
0078 
0079   //! copy constructor
0080   TrackCand( const TrackCand& other );
0081   //! assignment operator
0082   TrackCand& operator=(TrackCand other);
0083   void swap(TrackCand& other); // nothrow
0084 
0085   //! == operator checks equality of TrackCandHits. Does not check for sorting parameters.
0086   friend bool operator== (const TrackCand& lhs, const TrackCand& rhs);
0087   friend bool operator!= (const TrackCand& lhs, const TrackCand& rhs) {return !(lhs == rhs);}
0088 
0089   static bool compareTrackCandHits(const TrackCandHit* lhs, const TrackCandHit* rhs) {return (*lhs < *rhs);} // operator< defined in TrackCandHit.h
0090 
0091   // Accessors -----------------------
0092   TrackCandHit* getHit(int i) const;
0093 
0094   //!Get detector Id and hit Id for hit number i
0095   void getHit(int i, int& detId, int& hitId) const;
0096 
0097   //! Get detector Id, hit Id and sorting parameter for hit number i
0098   void getHit(int i, int& detId, int& hitId, double& sortingParameter) const;
0099 
0100   //! Get detector Id, hit Id and plane id for hit number i
0101   void getHitWithPlane(int i, int& detId, int& hitId, int& planeId) const;
0102 
0103   unsigned int getNHits() const {return hits_.size();}
0104 
0105   /**
0106    * @brief Get hit ids of from a specific detector.
0107    *
0108    * DetId -1 gives hitIds of hits with default detId -1. The default argument -2 gives hit Ids of all hits.
0109    */
0110   std::vector<int>    getHitIDs(int detId = -2) const;
0111 
0112   //! Get detector IDs of all hits
0113   std::vector<int>    getDetIDs() const;
0114   //! Get sorting parameterts of all hits
0115   std::vector<double> getSortingParameters() const;
0116   std::set<int>       getUniqueDetIDs() const;
0117 
0118   //! Get the MCT track id, for MC simulations - default value = -1
0119   int getMcTrackId() const {return mcTrackId_;}
0120 
0121   //! Get the time at which the seed state is defined
0122   double getTimeSeed() const { return time_; }
0123 
0124   /** @brief get the seed value for track: pos. Identical to the first 3 components of getStateSeed*/
0125   TVector3 getPosSeed() const {return TVector3(state6D_(0), state6D_(1), state6D_(2));}
0126 
0127   /** @brief get the seed value for track: mom. Identical to the last 3 components of getStateSeed*/
0128   TVector3 getMomSeed() const {return TVector3(state6D_(3), state6D_(4), state6D_(5));}
0129 
0130   /** @brief get the covariance matrix seed (6D).  */
0131   const TMatrixDSym& getCovSeed() const {return cov6D_;}
0132 
0133   //! Returns the 6D seed state; should be in global coordinates.
0134   const TVectorD& getStateSeed() const {return state6D_;}
0135 
0136   double getChargeSeed() const {return q_;}
0137 
0138   //! Get the PDG code
0139   int getPdgCode() const {return pdg_;}
0140 
0141   //! Is there a hit with detId and hitId in the TrackCand?
0142   bool hitInTrack(int detId, int hitId) const;
0143 
0144   // Modifiers -----------------------
0145 
0146   void addHit(int detId, int hitId, int planeId = -1, double sortingParameter = 0);
0147 
0148   void addHit(TrackCandHit* hit) {hits_.push_back(hit);}
0149 
0150   //! Set the MCT track id, for MC simulations
0151   void setMcTrackId(int i) {mcTrackId_ = i;}
0152 
0153   //! Set a particle hypothesis in form of a PDG code. This will also set the charge attribute
0154   void setPdgCode(int pdgCode);
0155 
0156   //! Clone the TrackCandHit objects from the other TrackCand and append them to this TrackCand
0157   void append(const TrackCand&);
0158 
0159   //! Sort the hits that were already added to the trackCand using the sorting parameters.
0160   void sortHits();
0161 
0162   void sortHits(const std::vector<unsigned int>& indices);
0163 
0164   // Operations ----------------------
0165   //! Delete and clear the TrackCandHits
0166   void reset();
0167 
0168   //! Write the content of all private attributes to the terminal
0169   void Print(const Option_t* = "") const ;
0170 
0171   //! Set the time at which the seed is defined
0172   void setTimeSeed(double time) { time_ = time; }
0173 
0174   /** @brief set the covariance matrix seed (6D).  */
0175   void setCovSeed(const TMatrixDSym& cov6D) {cov6D_ = cov6D; /* always 6D, no need to resize */}
0176 
0177   /** @brief sets the state to seed the track fitting. State has to be a TVectorD(6). First 3 elements are the staring postion second 3 elements the starting momentum. Everything in global coordinates
0178    * charge is the charge hypotheses of the particle charge
0179    */
0180   void set6DSeed(const TVectorD& state6D, const double charge);
0181 
0182   /** @brief This function works the same as set6DSeed but instead of a charge hypothesis you can set a pdg code which will set the charge automatically
0183    */
0184   void set6DSeedAndPdgCode(const TVectorD& state6D, const int pdgCode);
0185 
0186   /** @brief sets the state to seed the track fitting. State has to be a TVector3 for position and a TVector3 for momentum. Everything in global coordinates
0187    * charge is the charge hypotheses of the particle charge
0188    */
0189   void setPosMomSeed(const TVector3& pos, const TVector3& mom, const double charge);
0190 
0191   /** @brief This function works the same as setPosMomSeed but instead of a charge hypothesis you can set a pdg code which will set the charge automatically
0192    */
0193   void setPosMomSeedAndPdgCode(const TVector3& pos, const TVector3& mom, const int pdgCode);
0194 
0195   /** @brief sets the state to seed the track fitting and its
0196      time. State has to be a TVectorD(6). First 3 elements are the
0197      staring postion second 3 elements the starting
0198      momentum. Everything in global coordinates charge is the charge
0199      hypotheses of the particle charge.
0200    */
0201   void setTime6DSeed(double time, const TVectorD& state6D, const double charge);
0202 
0203   /** @brief This function works the same as set6DSeed but instead of
0204       a charge hypothesis you can set a pdg code which will set the
0205       charge automatically.
0206    */
0207   void setTime6DSeedAndPdgCode(double time, const TVectorD& state6D, const int pdgCode);
0208 
0209   /** @brief sets the state to seed the track fitting and its time. State has to be
0210      a TVector3 for position and a TVector3 for momentum. Everything
0211      in global coordinates charge is the charge hypotheses of the
0212      particle charge.
0213    */
0214   void setTimePosMomSeed(double time, const TVector3& pos, const TVector3& mom,
0215              const double charge);
0216 
0217   /** @brief This function works the same as setPosMomSeed but instead
0218       of a charge hypothesis you can set a pdg code which will set the
0219       charge automatically.
0220    */
0221   void setTimePosMomSeedAndPdgCode(double time, const TVector3& pos,
0222                    const TVector3& mom, const int pdgCode);
0223 
0224 
0225  private:
0226 
0227   // Private Data Members ------------
0228   std::vector<TrackCandHit*> hits_; //->
0229 
0230   int mcTrackId_; /**< if MC simulation, store the mc track id here */
0231   int pdg_; /**< particle data groupe's id for a particle*/
0232 
0233   double time_; /**< Time at which the seed is given */
0234   TVectorD state6D_; /**< global 6D position plus momentum state */
0235   TMatrixDSym cov6D_; /**< global 6D position plus momentum state */
0236   double q_; /**< the charge of the particle in units of elementary charge */
0237 
0238 
0239  public:
0240 
0241   ClassDef(TrackCand,2)
0242   // Version history:
0243   // ver 2: keep track of time in state (schema evolution rule added).
0244 };
0245 
0246 } /* End of namespace genfit */
0247 /** @} */
0248 
0249 #endif // genfit_TrackCand_h