CLHEP/HepMC/GenParticle.h

00001 //--------------------------------------------------------------------------
00002 #ifndef HEPMC_GEN_PARTICLE_H
00003 #define HEPMC_GEN_PARTICLE_H
00004 
00006 // Matt.Dobbs@Cern.CH, September 1999, refer to:
00007 // M. Dobbs and J.B. Hansen, "The HepMC C++ Monte Carlo Event Record for
00008 // High Energy Physics", Computer Physics Communications (to be published).
00009 //
00010 // particle within an event coming in/out of a vertex
00011 // particle is the basic building block or unit of the event record
00013 //
00014 // example:
00015 //      GenParticle* p = new GenParticle( HepLorentzVector(1,1,1,3), 11, 1 );
00016 // creates a particle with 4-vector (p,E)=1,1,1,3 - with pdg id 11 (electron)
00017 // and give this particle status =1.
00018 //
00019 // The definition of a HepLorentzVector scope resolution operator allows for
00020 //  the use of 4 vector algebra with GenParticles.
00021 //  i.e. if two particles are defined:
00022 //   HepMC::GenParticle p_electron( HepLorentzVector(0,0,5,5), 11, 1 );
00023 //   HepMC::GenParticle p_positron( HepLorentzVector(0,5,0,5), -11, 1 );
00024 //  then you can find their cms 4 vector:
00025 //   HepLorentzVector v_cms = (HepLorentzVector)p_electron 
00026 //                            + (HepLorentzVector)p_positron;
00027 //
00028 // the pointers to end/production vertices can only be set by the
00029 //  vertices themselves - thus to set the production vertex for a particle,
00030 //  you add the particle to that vertex with GenVertex::add_particle_out()
00031 //
00032 // We decide not to have a separate 4 vector for the momentum 
00033 //  at decay time (which MC++ includes to allow dE/dX losses etc). 
00034 //  If you want that, just add a decay vertex with the
00035 //  same particle (modified momentum) going out
00036 //
00037 
00038 #include "CLHEP/config/CLHEP.h"
00039 #include "CLHEP/config/iostream.h"
00040 #include "CLHEP/HepMC/Flow.h"
00041 #include "CLHEP/HepMC/Polarization.h"
00042 #include "CLHEP/Vector/LorentzVector.h"
00043 #include "CLHEP/HepMC/HepMCConfig.h"
00044 #include "CLHEP/HepPDT/ParticleID.hh"
00045 #include <vector>
00046 
00047 namespace HepMC {
00048 
00049     class GenVertex;
00050     class GenEvent; 
00051 
00056     class GenParticle {
00057 
00058         friend class GenVertex; // so vertex can set decay/production vertexes
00059         friend class GenEvent;  // so event can set the barCodes
00060         friend std::ostream& operator<<( std::ostream&, const GenParticle& );
00061 
00062     public:
00063 
00064         typedef  HepMCConfig::ParticleData   ParticleData;
00065         typedef  HepMCConfig::DecayData      DecayData;
00066 
00067         GenParticle( const HepLorentzVector& momentum, int pdg_id,
00068                      int status = 0, const Flow& itsflow = Flow(),
00069                      const Polarization& polar = Polarization(0,0) );
00070         GenParticle( const HepLorentzVector& momentum, 
00071                      ParticleData * pd, DecayData * dd = 0,
00072                      int status = 0, const Flow& itsflow = Flow(),
00073                      const Polarization& polar = Polarization(0,0) );
00074         GenParticle( const GenParticle& inparticle ); // shallow copy.
00075         virtual ~GenParticle();
00076         
00077         GenParticle& operator=( const GenParticle& inparticle ); // shallow.
00078         bool         operator==( const GenParticle& ) const;
00079         bool         operator!=( const GenParticle& ) const;
00080 
00081         // dump this particle's full info to ostr
00082         void       print( std::ostream& ostr = std::cout ) const; 
00083 
00084         operator HepLorentzVector() const; // conversion operator
00085 
00087         // access methods //
00089 
00090         HepLorentzVector     momentum() const;
00091         int                  pdg_id() const;
00092         int                  status() const;
00093         Flow                 flow() const;
00094         int                  flow( int code_index ) const;
00095         double               generatedMass() const;
00096         // You can ask for 3 masses:  ParticleData->mass()        [nominal mass]
00097         //                            GenParticle.generatedMass() [generated mass]
00098         //                            GenParticle.momentum().m()  [on shell mass]
00099         //
00100         Polarization         polarization() const;
00101         GenVertex*           production_vertex() const;
00102         GenVertex*           end_vertex() const;
00103         GenEvent*            parent_event() const;
00104 
00105         HepPDT::ParticleID   particleID()   const;
00106         ParticleData const & particledata() const { return *itsParticleData; }
00107         ParticleData       & particledata()       { return *itsParticleData; }
00108         DecayData    const & decaydata()    const { return *itsDecayData; }
00109         DecayData          & decaydata()          { return *itsDecayData; }
00110         
00111         // get pointers to mothers and daughters
00112         GenParticle *      mother()         const;
00113         GenParticle *      secondMother()   const;
00114         GenParticle *      beginDaughters() const;
00115         GenParticle *      endDaughters()   const;
00116         // get vectors of pointers to particles
00117         std::vector<GenParticle*> listChildren() const;
00118         std::vector<GenParticle*> listDescendants() const;
00119         std::vector<GenParticle*> listParents() const;
00120         std::vector<GenParticle*> listAncestors() const;
00121         // more utility methods
00122         bool hasParents() const;
00123         bool hasChildren() const;
00124         int  numParents() const;
00125         int  numChildren() const;
00126         
00127         // StdHep information
00128         int                collisionNumber() const;
00129         HepLorentzVector   creationVertex() const;      
00130         HepLorentzVector   decayVertex()    const;      
00131 
00132         //
00133         // The barcode is the particle's reference number, every vertex in the
00134         //  event has a unique barcode. Particle barcodes are positive numbers,
00135         //  vertex barcodes are negative numbers.
00136         // In general there is no reason to "suggest_barcode", if a particle is
00137         //  added to the event without a suggested barcode, the event will
00138         //  assign one for it.
00139         int                  barcode() const;
00140         bool                 suggest_barcode( int the_bar_code );
00141 
00143         // mutators       //
00145         
00146         void   set_momentum( const HepLorentzVector& vec4 );
00147         void   set_pdg_id( int id );
00148         void   set_status( int status = 0 );
00149         void   set_flow( const Flow& f );
00150         void   set_flow( int code_index, int code );
00151         void   set_polarization( const Polarization& polarization =
00152                                  Polarization(0,0) );
00153         void   setGeneratedMass( const double & m );
00154         //  If you do not call setGeneratedMass(), then 
00155         //  generatedMass() will simply return the mass calculated from
00156         //  momentum()
00157 
00158         // StdHep mutators
00159         void setParticleID      ( HepPDT::ParticleID pid );
00160         void setCollisionNumber ( int coll );
00161         void setMomentum        ( double px, double py, double pz, double E );
00162         void changeParticleType (ParticleData & pd) { itsParticleData = &pd; }
00163         void changeDecayData    (DecayData & dd)    { itsDecayData = &dd; }
00164 
00165         // old StdHepC++ methods
00166         // ---  accessors:
00167         //
00168         int               ParticleID()      const { return pdg_id(); }
00169         int               StatusCode()      const { return status(); }
00170         int               Mother()          const;
00171         int               SecondMother()    const;
00172         int               BeginDaughters()  const;
00173         int               EndDaughters()    const;
00174         int               CollisionNumber() const { return collisionNumber(); }
00175         HepLorentzVector  Momentum()        const { return momentum(); }
00176         double            Mass()            const { return generatedMass(); }
00177         HepLorentzVector  CreationVertex()  const { return creationVertex(); }
00178         HepLorentzVector  DecayVertex()     const { return decayVertex(); }
00179         // ---  mutators:
00180         //
00181         void  setStatusCode     ( int status )  { set_status(status); }
00182 
00183     protected: // for internal use only by friend GenVertex class
00184 
00185         static unsigned int counter(); // temporary for debugging
00186 
00187         void   set_production_vertex_( GenVertex* productionvertex = 0);
00188         void   set_end_vertex_( GenVertex* decayvertex = 0 );
00189         void   set_barcode_( int the_bar_code ); // for use by GenEvent only
00190 
00191     private:
00192         HepLorentzVector m_momentum;          // 4 vector in GeV
00193         int              m_pdg_id;            // id according to PDG convention
00194         int              m_status;            // As defined for HEPEVT
00195         Flow             m_flow;
00196         Polarization     m_polarization;
00197         GenVertex*       m_production_vertex; // null if vacuum or beam
00198         GenVertex*       m_end_vertex;        // null if not-decayed
00199         int              m_barcode;           // unique identifier in the event
00200         double           itsGeneratedMass;    // (in GeV/c**2)
00201         int              itsCollisionNumber;  // for StdHep
00202         ParticleData *   itsParticleData;       // should be null only if no 
00203                                                 //    particle data is desired
00204         DecayData *      itsDecayData;          // null if not customized
00205 
00206         static unsigned int s_counter;
00207     };  
00208 
00210     // INLINES  //
00212     inline GenParticle::operator HepLorentzVector() const 
00213     { return m_momentum; }
00214 
00215     inline HepLorentzVector GenParticle::momentum() const 
00216     { return m_momentum; }
00217 
00218     inline int GenParticle::pdg_id() const { return m_pdg_id; }
00219 
00220     inline int GenParticle::status() const { return m_status; }
00221 
00222     inline GenVertex* GenParticle::production_vertex() const 
00223     { return m_production_vertex; }
00224 
00225     inline GenVertex* GenParticle::end_vertex() const { return m_end_vertex; }
00226 
00227     inline Flow GenParticle::flow() const { return m_flow; }
00228 
00229     inline int GenParticle::flow( int code_index ) const
00230     { return m_flow.icode( code_index ); }
00231 
00232     inline Polarization GenParticle::polarization() const 
00233     { return m_polarization; }
00234 
00235     inline void GenParticle::set_momentum( const HepLorentzVector& vec4 )
00236     { m_momentum = vec4; }
00237 
00238     inline void GenParticle::set_pdg_id( int id ) 
00239     {  m_pdg_id = id;  }
00240 
00241     inline void GenParticle::set_status( int status ) { m_status = status; }
00242 
00243     inline void GenParticle::set_flow( const Flow& f ) { m_flow = f; }
00244 
00245     inline void GenParticle::set_flow( int code_index, int code ) 
00246     {  m_flow.set_icode( code_index, code ); }
00247 
00248     inline void GenParticle::set_polarization( const Polarization& polar )
00249     { m_polarization = polar; }
00250 
00251     inline int  GenParticle::barcode() const { return m_barcode; }
00252 
00253     inline void GenParticle::set_barcode_( int bc ) { m_barcode = bc; }
00254 
00255 } // HepMC
00256 
00257 #endif  // HEPMC_GEN_PARTICLE_H
00258 //--------------------------------------------------------------------------
00259 

Class Library for High Energy Physics (version 1.8)