Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:11:20

0001 #ifndef FASTSIM_PARTICLE_H
0002 #define FASTSIM_PARTICLE_H
0003 
0004 #include "DataFormats/Math/interface/LorentzVector.h"
0005 
0006 ///////////////////////////////////////////////
0007 // Author: L. Vanelderen, S. Kurz
0008 // Date: 29 May 2017
0009 //////////////////////////////////////////////////////////
0010 
0011 namespace fastsim {
0012   //! Definition of a generic FastSim Particle which can be propagated through the detector (formerly ParticlePropagator)
0013   /*!
0014         Contains all information necessary for the propagation and tracking of a particle:
0015     */
0016   class Particle {
0017   public:
0018     //! Constructor.
0019     /*!
0020             \param pdgId The pdgId of the particle.
0021             \param position The position of the particle.
0022             \param momentum The momentum of the particle.
0023         */
0024     Particle(int pdgId, const math::XYZTLorentzVector& position, const math::XYZTLorentzVector& momentum)
0025         : pdgId_(pdgId),
0026           charge_(-999.),
0027           position_(position),
0028           momentum_(momentum),
0029           remainingProperLifeTimeC_(-999.)  // lifetime in ct
0030           ,
0031           simTrackIndex_(-1),
0032           simVertexIndex_(-1),
0033           genParticleIndex_(-1),
0034           isOnForwardLayer_(false),
0035           isOnLayerIndex_(-1),
0036           energyDeposit_(0),
0037           isLooper_(false),
0038           motherDeltaR_(-1),
0039           motherPpdId_(0),
0040           motherSimTrackIndex_(-999) {
0041       ;
0042     }
0043 
0044     ////////
0045     // setters
0046     //////////
0047 
0048     //! Set the index of the SimTrack of this particle.
0049     void setSimTrackIndex(int index) { simTrackIndex_ = index; }
0050 
0051     //! Set the index of the origin SimVertex of this particle.
0052     void setSimVertexIndex(int index) { simVertexIndex_ = index; }
0053 
0054     //! Set index of the particle in the genParticle vector (if applies).
0055     void setGenParticleIndex(int index) { genParticleIndex_ = index; }
0056 
0057     //! Particle is stable
0058     void setStable() { remainingProperLifeTimeC_ = -1.; }
0059 
0060     //! Set the particle's remaining proper lifetime if not stable [in ct]
0061     /*!
0062         \param remainingProperLifeTimeC Important: defined in units of c*t!
0063     */
0064     void setRemainingProperLifeTimeC(double remainingProperLifeTimeC) {
0065       remainingProperLifeTimeC_ = remainingProperLifeTimeC;
0066     }
0067 
0068     //! Set the charge of the particle.
0069     void setCharge(double charge) { charge_ = charge; }
0070 
0071     //! Set layer this particle is currently on
0072     void setOnLayer(bool isForward, int index) {
0073       isOnForwardLayer_ = isForward;
0074       isOnLayerIndex_ = index;
0075     }
0076 
0077     //! Reset layer this particle is currently on (i.e. particle is not on a layer anyomre)
0078     void resetOnLayer() { isOnLayerIndex_ = -1; }
0079 
0080     //! Set the energy the particle deposited in the tracker layer that was last hit (ionization).
0081     /*!
0082         This energy is then assigned with a SimHit (if any).
0083         \param energyDeposit The energy loss of the particle in the tracker material layer.
0084         \sa fastsim::EnergyLoss::interact(fastsim::Particle & particle, const SimplifiedGeometry & layer,std::vector<std::unique_ptr<fastsim::Particle> > & secondaries,const RandomEngineAndDistribution & random)
0085         \sa fastsim::TrackerSimHitProducer::interact(Particle & particle,const SimplifiedGeometry & layer,std::vector<std::unique_ptr<Particle> > & secondaries,const RandomEngineAndDistribution & random)
0086     */
0087     void setEnergyDeposit(double energyDeposit) { energyDeposit_ = energyDeposit; }
0088 
0089     //! This particle is about to do a loop in the tracker or the direction of the momentum is going inwards.
0090     /*!
0091         The TrackerSimHitProducer has the option not to store SimHits in this case, since tracking not possible (just leads to fakes).
0092         \sa fastsim::TrackerSimHitProducer::interact(Particle & particle,const SimplifiedGeometry & layer,std::vector<std::unique_ptr<Particle> > & secondaries,const RandomEngineAndDistribution & random)
0093     */
0094     void setLooper() { isLooper_ = true; }
0095 
0096     //! Set delta R to mother particle (only necessary if mother and daughter charged).
0097     /*!
0098         Needed for FastSim (cheat) tracking: daughter can continue the track of the mother.
0099         \param motherMomentum The momentum 4-vector of the mother particle.
0100         \sa fastsim::ParticleManager::addSecondaries(const math::XYZTLorentzVector & vertexPosition, int parentSimTrackIndex, std::vector<std::unique_ptr<Particle> > & secondaries)
0101     */
0102     void setMotherDeltaR(const math::XYZTLorentzVector& motherMomentum) {
0103       motherDeltaR_ = (momentum_.Vect().Unit().Cross(motherMomentum.Vect().Unit())).R();
0104     }
0105 
0106     //! Set pdgId of the mother particle (only necessary if mother and daughter charged).
0107     /*!
0108         Needed for FastSim (cheat) tracking: daughter can continue the track of the mother.
0109         \param motherPpdId The pdgId of the mother particle.
0110         \sa fastsim::ParticleManager::addSecondaries(const math::XYZTLorentzVector & vertexPosition, int parentSimTrackIndex, std::vector<std::unique_ptr<Particle> > & secondaries)
0111     */
0112     void setMotherPdgId(int motherPpdId) { motherPpdId_ = motherPpdId; }
0113 
0114     //! Set the index of the SimTrack of the mother particle (only necessary if mother and daughter charged).
0115     /*!
0116         Needed for FastSim (cheat) tracking: daughter can continue the track of the mother.
0117         \param id The Id of the SimTrack of the mother particle.
0118         \sa fastsim::ParticleManager::addSecondaries(const math::XYZTLorentzVector & vertexPosition, int parentSimTrackIndex, std::vector<std::unique_ptr<Particle> > & secondaries)
0119     */
0120     void setMotherSimTrackIndex(int id) { motherSimTrackIndex_ = id; }
0121 
0122     //! Reset all information stored about the mother particle.
0123     void resetMother() {
0124       motherDeltaR_ = -1;
0125       motherPpdId_ = 0;
0126       motherSimTrackIndex_ = -999;
0127     }
0128 
0129     ////////
0130     // ordinary getters
0131     //////////
0132 
0133     //! Return pdgId of the particle.
0134     int pdgId() const { return pdgId_; }
0135 
0136     //! Return charge of the particle.
0137     double charge() const { return charge_; }
0138 
0139     //! Return position of the particle.
0140     const math::XYZTLorentzVector& position() const { return position_; }
0141 
0142     //! Return momentum of the particle.
0143     const math::XYZTLorentzVector& momentum() const { return momentum_; }
0144 
0145     //! Return the particle's remaining proper lifetime[in ct]
0146     /*!
0147         Returns -1 in case particle is stable.
0148         \return Important: defined in units of c*t!
0149     */
0150     double remainingProperLifeTimeC() const { return remainingProperLifeTimeC_; }
0151 
0152     //! Return index of the SimTrack.
0153     int simTrackIndex() const { return simTrackIndex_; }
0154 
0155     //! Return index of the origin vertex.
0156     /*!
0157         Returns -1 for primary vertex.
0158     */
0159     int simVertexIndex() const { return simVertexIndex_; }
0160 
0161     //! Return index of the particle in the genParticle vector.
0162     /*!
0163         Returns -1 if not a genParticle.
0164     */
0165     int genParticleIndex() const { return genParticleIndex_; }
0166 
0167     //! Check if particle is on layer
0168     bool isOnLayer(bool isForward, int index) { return isOnForwardLayer_ == isForward && isOnLayerIndex_ == index; }
0169 
0170     //! Returns true if particle is considered stable.
0171     bool isStable() const { return remainingProperLifeTimeC_ == -1.; }
0172 
0173     //! Check if charge of particle was set.
0174     bool chargeIsSet() const { return charge_ != -999.; }
0175 
0176     //! Check if remaining proper lifetime of particle is set.
0177     bool remainingProperLifeTimeIsSet() const { return remainingProperLifeTimeC_ != -999.; }
0178 
0179     //! Return Lorentz' gamma factor
0180     double gamma() const { return momentum().Gamma(); }
0181 
0182     //! Return the energy the particle deposited in the tracker layer that was last hit (ionization).
0183     /*!
0184         This energy can then be assigned with a SimHit (if any).
0185         \sa fastsim::EnergyLoss::interact(fastsim::Particle & particle, const SimplifiedGeometry & layer,std::vector<std::unique_ptr<fastsim::Particle> > & secondaries,const RandomEngineAndDistribution & random)
0186         \sa fastsim::TrackerSimHitProducer::interact(Particle & particle,const SimplifiedGeometry & layer,std::vector<std::unique_ptr<Particle> > & secondaries,const RandomEngineAndDistribution & random)
0187     */
0188     double getEnergyDeposit() const { return energyDeposit_; }
0189 
0190     //! Check if this particle is about to do a loop in the tracker or the direction of the momentum is going inwards.
0191     /*!
0192         The TrackerSimHitProducer has the option not to store SimHits in this case, since tracking not possible (just leads to fakes).
0193         \sa fastsim::TrackerSimHitProducer::interact(Particle & particle,const SimplifiedGeometry & layer,std::vector<std::unique_ptr<Particle> > & secondaries,const RandomEngineAndDistribution & random)
0194     */
0195     double isLooper() const { return isLooper_; }
0196 
0197     //! Get delta R to mother particle (only makes sense if mother and daughter charged).
0198     /*!
0199         Needed for FastSim (cheat) tracking: daughter can continue the track of the mother.
0200         \sa fastsim::ParticleManager::addSecondaries(const math::XYZTLorentzVector & vertexPosition, int parentSimTrackIndex, std::vector<std::unique_ptr<Particle> > & secondaries)
0201     */
0202     double getMotherDeltaR() const { return motherDeltaR_; }
0203 
0204     //! Get pdgIdto mother particle (only makes sense if mother and daughter charged).
0205     /*!
0206         Needed for FastSim (cheat) tracking: daughter can continue the track of the mother.
0207         \sa fastsim::ParticleManager::addSecondaries(const math::XYZTLorentzVector & vertexPosition, int parentSimTrackIndex, std::vector<std::unique_ptr<Particle> > & secondaries)
0208     */
0209     int getMotherPdgId() const { return motherPpdId_; }
0210 
0211     //! Get index of simTrack of mother particle (only makes sense if mother and daughter charged).
0212     /*!
0213         Needed for FastSim (cheat) tracking: daughter can continue the track of the mother.
0214         \sa fastsim::ParticleManager::addSecondaries(const math::XYZTLorentzVector & vertexPosition, int parentSimTrackIndex, std::vector<std::unique_ptr<Particle> > & secondaries)
0215     */
0216     int getMotherSimTrackIndex() const { return motherSimTrackIndex_; }
0217 
0218     ////////
0219     // non-const getters
0220     //////////
0221 
0222     //! Return position of the particle.
0223     math::XYZTLorentzVector& position() { return position_; }
0224 
0225     //! Return momentum of the particle.
0226     math::XYZTLorentzVector& momentum() { return momentum_; }
0227 
0228     friend std::ostream& operator<<(std::ostream& os, const Particle& particle);
0229 
0230   private:
0231     const int pdgId_;                   //!< pdgId of the particle
0232     double charge_;                     //!< charge of the particle in elemntary units
0233     math::XYZTLorentzVector position_;  //!< position of the particle
0234     math::XYZTLorentzVector momentum_;  //!< momentum of the particle
0235     double remainingProperLifeTimeC_;   //!< remaining proper lifetime of the particle in units of t*c
0236     int simTrackIndex_;                 //!< index of the simTrack
0237     int simVertexIndex_;                //!< index of the origin vertex
0238     int genParticleIndex_;              //!< index of the particle in the vector of genParticles (if applies)
0239     bool isOnForwardLayer_;             //!< the layer this particle is currently on: is it a ForwardLayer
0240     int isOnLayerIndex_;                //!< the layer this particle is currently on: the index of the layer
0241     double energyDeposit_;              //!< energy deposit through ionization in the previous tracker layer
0242     bool isLooper_;                     //!< this particle is about to do a loop or momentum goes inwards
0243     double motherDeltaR_;               //!< delta R to mother particle if both charged
0244     int motherPpdId_;                   //!< pdgId of mother particle if both charged
0245     int motherSimTrackIndex_;           //!< simTrack index of mother particle if both charged
0246   };
0247 
0248   //! Some basic output.
0249   std::ostream& operator<<(std::ostream& os, const Particle& particle);
0250 
0251 }  // namespace fastsim
0252 
0253 #endif