00001
00002
00003
00004
00005
00007 #include "HepMC/GenEvent.h"
00008 #include "HepMC/GenVertex.h"
00009 #include "HepMC/GenParticle.h"
00010 #include <iomanip>
00011
00012 namespace HepMC {
00013
00014 GenParticle::GenParticle( void ) :
00015 m_momentum(0), m_pdg_id(0), m_status(0), m_flow(this),
00016 m_polarization(0), m_production_vertex(0), m_end_vertex(0),
00017 m_barcode(0), m_generated_mass(0.)
00018 {
00019 s_counter++;
00020 }
00021
00022 GenParticle::GenParticle( const FourVector& momentum,
00023 int pdg_id, int status,
00024 const Flow& itsflow,
00025 const Polarization& polar ) :
00026 m_momentum(momentum), m_pdg_id(pdg_id), m_status(status), m_flow(this),
00027 m_polarization(polar), m_production_vertex(0), m_end_vertex(0),
00028 m_barcode(0), m_generated_mass(momentum.m())
00029 {
00030
00031
00032 set_flow(itsflow);
00033 s_counter++;
00034 }
00035
00036 GenParticle::GenParticle( const GenParticle& inparticle ) :
00037 m_momentum( inparticle.momentum() ),
00038 m_pdg_id( inparticle.pdg_id() ),
00039 m_status( inparticle.status() ),
00040 m_flow(this),
00041 m_polarization( inparticle.polarization() ),
00042 m_production_vertex(0),
00043 m_end_vertex(0),
00044 m_barcode(0),
00045 m_generated_mass( inparticle.generated_mass() )
00046 {
00051 set_production_vertex_( 0 );
00052 set_end_vertex_( 0 );
00053 suggest_barcode( inparticle.barcode() );
00054 s_counter++;
00055 }
00056
00057 GenParticle::~GenParticle() {
00058 if ( parent_event() ) parent_event()->remove_barcode(this);
00059 s_counter--;
00060 }
00061
00062 void GenParticle::swap( GenParticle & other)
00063 {
00064
00065 m_momentum.swap( other.m_momentum );
00066 std::swap( m_pdg_id, other.m_pdg_id );
00067 std::swap( m_status, other.m_status );
00068 m_flow.swap( other.m_flow );
00069 m_polarization.swap( other.m_polarization );
00070 std::swap( m_production_vertex, other.m_production_vertex );
00071 std::swap( m_end_vertex, other.m_end_vertex );
00072 std::swap( m_barcode, other.m_barcode );
00073 std::swap( m_generated_mass, other.m_generated_mass );
00074 }
00075
00076 GenParticle& GenParticle::operator=( const GenParticle& inparticle ) {
00081
00082
00083 GenParticle tmp( inparticle );
00084 swap( tmp );
00085 return *this;
00086 }
00087
00088 bool GenParticle::operator==( const GenParticle& a ) const {
00092 if ( a.momentum() != this->momentum() ) return 0;
00093 if ( a.generated_mass() != this->generated_mass() ) return 0;
00094 if ( a.pdg_id() != this->pdg_id() ) return 0;
00095 if ( a.status() != this->status() ) return 0;
00096 if ( a.m_flow != this->m_flow ) return 0;
00097 if ( a.polarization() != this->polarization() ) return 0;
00098 return 1;
00099 }
00100
00101 bool GenParticle::operator!=( const GenParticle& a ) const {
00102 return !( a == *this );
00103 }
00104
00105 void GenParticle::print( std::ostream& ostr ) const {
00108 ostr << "GenParticle: "
00109 << barcode() << " ID:" << pdg_id()
00110 << " (P,E)=" << momentum().px() << "," << momentum().py()
00111 << "," << momentum().pz() << "," << momentum().e()
00112 << " Stat:" << status();
00113 if ( production_vertex() && production_vertex()->barcode()!=0 ) {
00114 ostr << " PV:" << production_vertex()->barcode();
00115 } else ostr << " PV:" << production_vertex();
00116 if ( end_vertex() && end_vertex()->barcode()!=0 ) {
00117 ostr << " EV:" << end_vertex()->barcode();
00118 } else ostr << " EV:" << end_vertex();
00119 ostr << " Pol:" << polarization() << " F:" << m_flow << std::endl;
00120 }
00121
00122 GenEvent* GenParticle::parent_event() const {
00123 if ( production_vertex() ) return production_vertex()->parent_event();
00124 if ( end_vertex() ) return end_vertex()->parent_event();
00125 return 0;
00126 }
00127
00128 void GenParticle::set_production_vertex_( GenVertex* prodvertex )
00129 {
00130 GenEvent* its_orig_event = parent_event();
00131 m_production_vertex = prodvertex;
00132 GenEvent* its_new_event = parent_event();
00133
00134
00135 if ( its_orig_event != its_new_event ) {
00136 if ( its_new_event ) its_new_event->set_barcode( this, barcode() );
00137 if ( its_orig_event ) its_orig_event->remove_barcode( this );
00138 }
00139 }
00140
00141 void GenParticle::set_end_vertex_( GenVertex* decayvertex )
00142 {
00143 GenEvent* its_orig_event = parent_event();
00144 m_end_vertex = decayvertex;
00145 GenEvent* its_new_event = parent_event();
00146 if ( its_orig_event != its_new_event ) {
00147 if ( its_new_event ) its_new_event->set_barcode( this, barcode() );
00148 if ( its_orig_event ) its_orig_event->remove_barcode( this );
00149 }
00150 }
00151
00152 bool GenParticle::suggest_barcode( int the_bar_code )
00153 {
00163 if ( the_bar_code <0 ) {
00164 std::cerr << "GenParticle::suggest_barcode WARNING, particle bar "
00165 << "\n codes MUST be positive integers. Negative "
00166 << "\n integers are reserved for vertices only. Your "
00167 << "\n suggestion has been rejected." << std::endl;
00168 return false;
00169 }
00170 bool success = false;
00171 if ( parent_event() ) {
00172 success = parent_event()->set_barcode( this, the_bar_code );
00173 } else { set_barcode_( the_bar_code ); }
00174 return success;
00175 }
00176
00178
00180 unsigned int GenParticle::counter() { return s_counter; }
00181 unsigned int GenParticle::s_counter = 0U;
00182
00184
00186
00188 std::ostream& operator<<( std::ostream& ostr, const GenParticle& part ) {
00189 ostr << " ";
00190 ostr.width(9);
00191 ostr << part.barcode();
00192 ostr.width(9);
00193 ostr << part.pdg_id() << " ";
00194 ostr.width(9);
00195 ostr.precision(2);
00196 ostr.setf(std::ios::scientific, std::ios::floatfield);
00197 ostr.setf(std::ios_base::showpos);
00198 ostr << part.momentum().px() << ",";
00199 ostr.width(9);
00200 ostr.precision(2);
00201 ostr << part.momentum().py() << ",";
00202 ostr.width(9);
00203 ostr.precision(2);
00204 ostr << part.momentum().pz() << ",";
00205 ostr.width(9);
00206 ostr.precision(2);
00207 ostr << part.momentum().e() << " ";
00208 ostr.setf(std::ios::fmtflags(0), std::ios::floatfield);
00209 ostr.unsetf(std::ios_base::showpos);
00210 if ( part.end_vertex() && part.end_vertex()->barcode()!=0 ) {
00211 ostr.width(3);
00212 ostr << part.status() << " ";
00213 ostr.width(9);
00214 ostr << part.end_vertex()->barcode();
00215 } else if ( !part.end_vertex() ) {
00216
00217
00218 ostr.width(3);
00219 ostr << part.status();
00220 } else {
00221
00222
00223 ostr.width(3);
00224 ostr << part.status() << " ";
00225 ostr.width(9);
00226 ostr << (void*)part.end_vertex();
00227 }
00228 return ostr;
00229 }
00230
00231
00232 double GenParticle::generated_mass() const {
00233 return m_generated_mass;
00234 }
00235
00236 void GenParticle::set_generated_mass( const double & m ) {
00237 m_generated_mass = m;
00238 }
00239
00240 }
00241