//////////////////////////////////////////////////////////////////// /// \class RAT::DS::MCTrack /// /// \brief This class represents a single simulated Monte Carlo track. /// /// \author Stan Seibert \n /// Phil G Jones /// /// REVISION HISTORY:\n /// 2013-1-21 : P. Jones - Refactor as part of ds review.\n /// /// \details This class represents the trajectory of a particle as it /// moves through the detector. /// //////////////////////////////////////////////////////////////////// #ifndef __RAT_DS_MCTrack___ #define __RAT_DS_MCTrack___ #include #include #include #include #include #include #include namespace RAT { namespace DS { class MCTrack : public TObject { public: /// Define the track summary flags enum ESummaryFlag { OpScintillation=0, OpReemission=1, OpCerenkov=2, OpAbsorption=3, OpRayleigh=4, OpMie=5, HitConc=6, HitPMT=7, Compton=8, OpRayleighH2O=9, OpRayleighAV=10, OpRayleighInnerAV=11, OpMieH2O=12, OpMieAV=13, OpMieInnerAV=14, CoulombScatter=15 }; /// Construct the MCTrack, set the summary flag to 0x0 MCTrack() : TObject(), trackID(0), parentID(0), pdgCode(0), length(0), depositedEnergy(0) {} /// Set the track ID /// /// This is Guaranteed to be unique for all tracks within this event, numbered starting from 1 /// /// @param[in] id void SetTrackID( const UInt_t id ) { trackID = id; } /// Get the track ID /// /// This is Guaranteed to be unique for all tracks within this event, numbered starting from 1 /// /// @return id UInt_t GetTrackID() const { return trackID; } /// Set the parent ID /// /// @param[in] id void SetParentID( const UInt_t id ) { parentID = id; } /// Get the parent ID /// /// @return id UInt_t GetParentID() const { return parentID; } /// Set the Particle Data Group, PDG, Code of the particle /// /// @param[in] code void SetPDGCode( const Int_t code ) { pdgCode = code; } /// Get the Particle Data Group, PDG, Code of the particle /// /// @return code Int_t GetPDGCode() const { return pdgCode; } /// Set the particle name /// /// @param[in] name of the particle this track represents void SetParticleName( const std::string& name ) { particleName = name; } /// Get the particle name /// /// @return the name of the particle this track represents std::string GetParticleName() const { return particleName; } /// Set the length /// /// @param[in] totalLength void SetLength( const Double_t totalLength ) { length = totalLength; } /// Get the length /// /// @return length Double_t GetLength() const { return length; } /// Set the deposited energy /// /// @param[in] totalDepositedEnergy void SetDepositedEnergy( const Double_t totalDepositedEnergy ) { depositedEnergy = totalDepositedEnergy; } /// Get the deposited energy /// /// @return depositedEnergy Double_t GetDepositedEnergy() const { return depositedEnergy; } /// Set the weight /// /// @param[in] weight_ void SetWeight( const Double_t weight_ ) { weight = weight_; } /// Get the weight /// /// @return weight Double_t GetWeight() const { return weight; } /// Set a summary flag. This indicates any process that has acted on the track during its lifetime. /// /// @param[in] flag to set /// @param[in] value of the flag, defaults to true void SetSummaryFlag( const ESummaryFlag flag, Bool_t value=true ) { summaryFlag.Set( flag, value ); } /// Get the value of a summary flag. This indicates any process that has acted on the track during its lifetime. /// /// @param[in] flag to query /// @return true if flag is set Bool_t GetSummaryFlag( const ESummaryFlag flag ) const { return summaryFlag.Get( flag ); } /// Add a new track step /// /// @param[in] trackStep the track step information void AddMCTrackStep( const MCTrackStep& trackStep ) { steps.push_back( trackStep ); length += trackStep.GetLength(); depositedEnergy += trackStep.GetDepositedEnergy(); } /// Get the total number of track steps /// /// @return the number of track steps size_t GetMCTrackStepCount() const { return steps.size(); } /// Get the first step /// /// @return reference to the first step in the collection /// @throws out_of_range if the index is out of range const MCTrackStep& GetFirstMCTrackStep() const { return steps.at( 0 ); } /// Get a MCTrackStep using the index in the track steps vector /// /// @param[in] index into the track steps array /// @return reference to the MCTrackStep /// @throws out_of_range if the index is out of range MCTrackStep& GetMCTrackStep( const size_t index ) { return steps.at( index ); } /// @copydoc GetMCTrackStep(size_t) const MCTrackStep& GetMCTrackStep( const size_t index ) const { return steps.at( index ); } /// Get the last step /// /// @return reference to the last step in the collection /// @throws out_of_range if the index is out of range const MCTrackStep& GetLastMCTrackStep() const { return steps.at( steps.size() - 1 ); } /// Prune/delete the MCTrackStep collection void PruneMCTrackSteps() { clear_vector( steps ); }; /// Prune specific tracks by index in the MCTrackStep collection /// /// @param[in] indices of the steps to prune inline void PruneMCTrackStepsByIndex( const std::set& indices ); /// Prune all but the first and last steps inline void PruneIntermediateMCTrackSteps(); // This ROOT macro adds dictionary methods to this class. // The number should be incremented whenever this class's members are changed. // It assumes this class has no virtual methods, use ClassDef if change this. ClassDefNV( MCTrack, 4 ); protected: std::vector steps; ///< The track steps for this track std::string particleName; ///< Particle name, often needed alongside the PDG Code BitMask summaryFlag; ///< A bitmask summarising what this track has done during the event UInt_t trackID; ///< The unique ID for the track UInt_t parentID; ///< The ID of the parent track Int_t pdgCode; ///< The PDG code for the particle type this track represents Double32_t length; ///< The total length of the track Double32_t depositedEnergy; ///< The total deposited energy of the track Double32_t weight; ///< The weight of the track }; inline void MCTrack::PruneMCTrackStepsByIndex( const std::set& indices ) { for( std::set::reverse_iterator iTer = indices.rbegin(); iTer != indices.rend(); iTer++ ) steps.erase( steps.begin() + *iTer ); } inline void MCTrack::PruneIntermediateMCTrackSteps() { if( steps.size() > 2 ) { MCTrackStep first = steps.front(); MCTrackStep last = steps.back(); PruneMCTrackSteps(); steps.push_back( first ); steps.push_back( last ); } } } // namespace DS } // namespace RAT #endif