Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:01:09

0001 //--------------------------------------------------------------------------
0002 #ifndef HEPMC_GEN_PARTICLE_H
0003 #define HEPMC_GEN_PARTICLE_H
0004 
0005 //////////////////////////////////////////////////////////////////////////
0006 // Matt.Dobbs@Cern.CH, September 1999, refer to:
0007 // M. Dobbs and J.B. Hansen, "The HepMC C++ Monte Carlo Event Record for
0008 // High Energy Physics", Computer Physics Communications (to be published).
0009 //
0010 // particle within an event coming in/out of a vertex
0011 // particle is the basic building block or unit of the event record
0012 //////////////////////////////////////////////////////////////////////////
0013 //
0014 // example:
0015 //      GenParticle* p = new GenParticle( FourVector(1,1,1,3), 11, 1 );
0016 // creates a particle with 4-vector (p,E)=1,1,1,3 - with pdg id 11 (electron)
0017 // and give this particle status =1.
0018 //
0019 // the pointers to end/production vertices can only be set by the
0020 //  vertices themselves - thus to set the production vertex for a particle,
0021 //  you add the particle to that vertex with GenVertex::add_particle_out()
0022 //
0023 // We decide not to have a separate 4 vector for the momentum 
0024 //  at decay time (which MC++ includes to allow dE/dX losses etc). 
0025 //  If you want that, just add a decay vertex with the
0026 //  same particle (modified momentum) going out
0027 //
0028 
0029 #include "HepMC/Flow.h"
0030 #include "HepMC/Polarization.h"
0031 #include "HepMC/SimpleVector.h"
0032 #include "HepMC/IteratorRange.h"
0033 #include <iostream>
0034 #ifdef _WIN32
0035 #define hepmc_uint64_t  __int64
0036 #else
0037 #include <stdint.h> // for uint64_t
0038 #define hepmc_uint64_t   uint64_t
0039 #endif
0040 
0041 namespace HepMC {
0042 
0043     class GenVertex;
0044     class GenEvent; 
0045 
0046     class GenParticleProductionRange;
0047     class ConstGenParticleProductionRange;
0048     class GenParticleEndRange;
0049     class ConstGenParticleEndRange;
0050 
0051     //! The GenParticle class contains information about generated particles
0052 
0053     ///
0054     /// \class GenParticle 
0055     /// HepMC::GenParticle 
0056     /// contains momentum, generated mass, particle ID, decay status, 
0057     /// flow, polarization, pointers to production and decay vertices
0058     /// and a unique barcode identfier.
0059     ///
0060     class GenParticle {
0061 
0062     friend class GenVertex; // so vertex can set decay/production vertexes
0063     friend class GenEvent;  // so event can set the barCodes
0064     /// print particle
0065     friend std::ostream& operator<<( std::ostream&, const GenParticle& );
0066 
0067     public:
0068         /// default constructor
0069         GenParticle(void);
0070         /// constructor requires momentum and particle ID
0071     GenParticle( const FourVector& momentum, int pdg_id,
0072              int status = 0, const Flow& itsflow = Flow(),
0073              const Polarization& polar = Polarization(0,0) );
0074     GenParticle( const GenParticle& inparticle ); //!< shallow copy.
0075     virtual ~GenParticle();
0076 
0077         void swap( GenParticle & other); //!< swap
0078     GenParticle& operator=( const GenParticle& inparticle ); //!< shallow.
0079         /// check for equality
0080     bool         operator==( const GenParticle& ) const;
0081         /// check for inequality
0082     bool         operator!=( const GenParticle& ) const;
0083 
0084     /// dump this particle's full info to ostr
0085     void       print( std::ostream& ostr = std::cout ) const; 
0086 
0087     operator HepMC::FourVector() const; //!< conversion operator
0088 
0089     ////////////////////
0090     // access methods //
0091     ////////////////////
0092 
0093     /// standard 4 momentum
0094     const FourVector &          momentum() const;
0095     /// particle ID
0096     int                  pdg_id() const;
0097     /// HEPEVT decay status
0098     int                  status() const;
0099     /// particle flow
0100     const Flow &         flow() const;
0101     /// particle flow index
0102     int                  flow( int code_index ) const;
0103         /// polarization information
0104     const Polarization & polarization() const;
0105     /// pointer to the production vertex
0106     GenVertex*           production_vertex() const;
0107     /// pointer to the decay vertex
0108     GenVertex*           end_vertex() const;
0109     /// pointer to the event that owns this particle
0110     GenEvent*            parent_event() const;
0111 
0112         /// Because of precision issues, the generated mass is not always the 
0113     /// same as the mass calculated from the momentum 4 vector.
0114         /// If the generated mass has been set, then generated_mass() 
0115     /// returns that value.
0116         /// If the generated mass has not been set, then generated_mass() 
0117     /// returns the mass calculated from the momentum 4 vector.
0118         double               generated_mass() const; //!< mass as generated
0119 
0120     /// generatedMass() is included for backwards compatibility with CLHEP HepMC
0121         double               generatedMass() const { return generated_mass(); }
0122 
0123 
0124     ///
0125     /// The barcode is the particle's reference number, every vertex in the
0126     /// event has a unique barcode. Particle barcodes are positive numbers,
0127     /// vertex barcodes are negative numbers.
0128     /// 
0129     /// Please note that the barcodes are intended for internal use within 
0130     /// HepMC as a unique identifier for the particles and vertices.
0131     /// Using the barcode to encode extra information is an abuse of 
0132     /// the barcode data member and causes confusion among users. 
0133     /// 
0134     int                  barcode() const; //!< particle barcode
0135     
0136     /// Convenience method.  Returns true if status==1
0137     bool                 is_undecayed() const;
0138     /// Convenience method.  Returns true if status==2
0139     bool                 has_decayed() const;
0140     /// Convenience method.  Returns true if status==4
0141     /// Note that using status 4 for beam particles is a new convention which
0142     /// may not have been implemented by the code originating this GenEvent.
0143     bool                 is_beam() const;
0144 
0145     /// incoming particle range
0146     GenParticleProductionRange particles_in( IteratorRange range = relatives );
0147     /// incoming particle range
0148     ConstGenParticleProductionRange particles_in( IteratorRange range = relatives ) const;
0149     /// outgoing particle range
0150     GenParticleEndRange particles_out( IteratorRange range = relatives );
0151     /// outgoing particle range
0152     ConstGenParticleEndRange particles_out( IteratorRange range = relatives ) const;
0153 
0154     /////////////////////
0155     // mutator methods //
0156     /////////////////////
0157 
0158     /// In general there is no reason to "suggest_barcode"
0159     bool                 suggest_barcode( int the_bar_code );
0160 
0161     void   set_momentum( const FourVector& vec4 ); //!< set standard 4 momentum
0162     void   set_pdg_id( int id ); //!< set particle ID
0163     void   set_status( int status = 0 ); //!< set decay status
0164     void   set_flow( const Flow& f ); //!< set particle flow
0165     void   set_flow( int code_index, int code = 0 ); //!< set particle flow index
0166     /// set polarization
0167     void   set_polarization( const Polarization& pol = Polarization(0,0) );
0168         ///  If you do not call set_generated_mass(), then 
0169         ///  generated_mass() will simply return the mass calculated from momentum()
0170         void   set_generated_mass( const double & m ); //!< define the actual generated mass
0171 
0172     ///  setGeneratedMass() is included for backwards compatibility with CLHEP HepMC
0173         void   setGeneratedMass( const double & m )  
0174                      { return set_generated_mass(m); }
0175 
0176     protected: // for internal use only by friend GenVertex class
0177 
0178     //static unsigned int counter(); //!< temporary for debugging
0179 
0180         /// set production vertex - for internal use only
0181     void   set_production_vertex_( GenVertex* productionvertex = 0);
0182         /// set decay vertex - for internal use only
0183     void   set_end_vertex_( GenVertex* decayvertex = 0 );
0184     void   set_barcode_( int the_bar_code ); //!< for use by GenEvent only
0185 
0186         /// scale the momentum vector and generated mass 
0187         /// this method is only for use by GenEvent
0188     void convert_momentum( const double& );
0189 
0190     private:
0191     FourVector       m_momentum;          // momentum vector
0192     int              m_pdg_id;            // id according to PDG convention
0193     int              m_status;            // As defined for HEPEVT
0194     Flow             m_flow;
0195     Polarization     m_polarization;
0196     GenVertex*       m_production_vertex; // null if vacuum or beam
0197     GenVertex*       m_end_vertex;        // null if not-decayed
0198     int              m_barcode;           // unique identifier in the event
0199         double           m_generated_mass;    // mass of this particle when it was generated
0200 
0201     //static unsigned int       s_counter;
0202     };  
0203 
0204     //////////////
0205     // INLINES  //
0206     //////////////
0207 
0208     inline GenParticle::operator HepMC::FourVector() const 
0209     { return m_momentum; }
0210 
0211     inline const FourVector & GenParticle::momentum() const 
0212     { return m_momentum; }
0213 
0214     inline int GenParticle::pdg_id() const { return m_pdg_id; }
0215 
0216     inline int GenParticle::status() const { return m_status; }
0217 
0218     inline GenVertex* GenParticle::production_vertex() const 
0219     { return m_production_vertex; }
0220 
0221     inline GenVertex* GenParticle::end_vertex() const { return m_end_vertex; }
0222 
0223     inline const Flow & GenParticle::flow() const { return m_flow; }
0224 
0225     inline int GenParticle::flow( int code_index ) const
0226     { return m_flow.icode( code_index ); }
0227 
0228     inline const Polarization & GenParticle::polarization() const 
0229     { return m_polarization; }
0230 
0231     inline void GenParticle::set_momentum( const FourVector& vec4 )
0232     { m_momentum = vec4; }
0233 
0234     inline void GenParticle::set_pdg_id( int id ) { m_pdg_id = id; }
0235 
0236     inline void GenParticle::set_status( int st ) { m_status = st; }
0237 
0238     inline void GenParticle::set_flow( const Flow& f ) { m_flow = f; }
0239 
0240     inline void GenParticle::set_flow( int code_index, int code ) 
0241     {
0242     if ( code == 0 ) { 
0243         m_flow.set_unique_icode( code_index );
0244     } else { 
0245         m_flow.set_icode( code_index, code );
0246     }
0247     }
0248 
0249     inline void GenParticle::set_polarization( const Polarization& polar )
0250     { m_polarization = polar; }
0251 
0252     inline int  GenParticle::barcode() const { return m_barcode; }
0253 
0254     inline void GenParticle::set_barcode_( int bc ) { m_barcode = bc; }
0255 
0256     inline bool GenParticle::is_undecayed() const {
0257         return ( m_status==1 ) ?  true : false;
0258     }
0259     inline bool GenParticle::has_decayed() const {
0260         return ( m_status==2 ) ?  true : false;
0261     }
0262     inline bool GenParticle::is_beam() const {
0263         return ( m_status==4 ) ?  true : false;
0264     }
0265 
0266 } // HepMC
0267 
0268 #endif  // HEPMC_GEN_PARTICLE_H
0269 //--------------------------------------------------------------------------
0270