00001
00002
00003
00004
00005
00006
00007
00008 #include <iostream>
00009 #include <string>
00010 #include <map>
00011
00012 #include "HepPDT/defs.h"
00013 #include "HepPDT/ParticleDataTable.hh"
00014
00015 namespace HepPDT {
00016
00017
00018 ParticleDataTable::ParticleDataTable( std::string name,
00019 ProcessUnknownID* process )
00020 : itsTableName ( name ), itsProcessUnknownID( process )
00021 {
00022 version();
00023 }
00024
00025 void ParticleDataTable::writeParticleData( std::ostream & outstr )
00026 {
00027
00028 outstr << std::endl;
00029 outstr << "HepPDT-ParticleDataTable-begin" << std::endl;
00030 outstr << " ***** ParticleDataTable *****" << std::endl;
00031 writeVersion( outstr );
00032 outstr << " Table Name : " << tableName() << std::endl;
00033 outstr << " ( " << size() << " entries )" << std::endl;
00034 outstr << "PARTICLE NAME ID CHARGE COLOR"
00035 << " SPIN: J S L"
00036 << " MASS"
00037 << " WIDTH"
00038 << " LOW CUT HIGH CUT"
00039 << " LIFETIME"
00040 << std::endl;
00041
00042 const_iterator cit;
00043 for( cit=begin(); cit != end(); ++cit ) {
00044 const ParticleData & pd = cit->second;
00045 pd.write( outstr );
00046 }
00047 outstr << "HepPDT-ParticleDataTable-end" << std::endl;
00048 return;
00049 }
00050
00051 void ParticleDataTable::writeParticleInfo( std::ostream & outstr )
00052 {
00053
00054 outstr << std::endl;
00055 outstr << "HepPDT-ParticleDataTable-Particle-Information-begin" << std::endl;
00056 outstr << " ***** ParticleDataTable *****" << std::endl;
00057 writeVersion( outstr );
00058 outstr << " Table Name : " << tableName() << std::endl;
00059 outstr << " ( " << size() << " entries )" << std::endl;
00060 outstr << "PARTICLE NAME ID CHARGE COLOR"
00061 << " SPIN: J S L"
00062 << " MASS"
00063 << " WIDTH"
00064 << " LOW CUT HIGH CUT"
00065 << " LIFETIME"
00066 << std::endl;
00067
00068 const_iterator cit;
00069 for( cit=begin(); cit != end(); ++cit ) {
00070 const ParticleData & pd = cit->second;
00071 pd.writeParticleInfo( outstr );
00072 }
00073 outstr << "HepPDT-ParticleDataTable-Particle-Information-end" << std::endl;
00074 return;
00075 }
00076
00077 void ParticleDataTable::writeParticleTranslation( std::ostream & outstr )
00078 {
00079
00080 const_iterator cit;
00081 for( cit=begin(); cit != end(); ++cit ) {
00082 const ParticleData & pd = cit->second;
00083 pd.writeParticleTranslation( outstr );
00084 }
00085 return;
00086 }
00087
00088 void ParticleDataTable::writeParticleStatus( std::ostream & os )
00089 {
00092
00093 os << std::endl;
00094 os << "HepPDT-Particle-Status-begin" << std::endl;
00095 os << " HepPDT Version : " << versionName() << std::endl;
00096 os << " Table Name : " << tableName()
00097 << " ( " << size() << " entries )" << std::endl;
00098 os << " ID NAME MASS"
00099 << " WIDTH"
00100 << " LIFETIME"
00101 << " STABLE?"
00102 << std::endl;
00103
00104 const_iterator cit;
00105 for( cit=begin(); cit != end(); ++cit ) {
00106 const ParticleData & pd = cit->second;
00107 int il = pd.name().length();
00108 os.width(11);
00109 os << pd.pid() << " ";
00110 os << pd.name() ;
00111
00112 int pad;
00113 for( pad = 0; pad < 21 - il; ++pad ) {
00114 os << " " ;
00115 }
00116 os.width(13);
00117 os.precision(5);
00118 os.setf(std::ios::scientific, std::ios::floatfield);
00119 os << pd.mass().value();
00120 os.width(13);
00121 os.precision(4);
00122 os << pd.totalWidth().value();
00123 os.width(13);
00124 os.precision(4);
00125 os << pd.lifetime().value();
00126 if( pd.isStable() ) {
00127 os << " stable";
00128 } else {
00129 os << " decays";
00130 }
00131
00132 os.precision(6);
00133 os.setf(std::ios::fmtflags(0), std::ios::floatfield);
00134
00135 os << std::endl;
00136 }
00137 os << "HepPDT-Particle-Status-end" << std::endl;
00138 return;
00139 }
00140
00141 ParticleData * ParticleDataTable::particle( ParticleID key )
00142 {
00143 iterator it;
00144 it = itsMap.find( key );
00145 if( it != itsMap.end() ) {
00146 return & it->second;
00147 } else {
00148
00149 return DealWithUnknownID(key);
00150 }
00151 }
00152
00153 ParticleData const * ParticleDataTable::particle( ParticleID key ) const
00154 {
00155 const_iterator cit;
00156
00157 cit = itsMap.find( key );
00158 if( cit != itsMap.end() ) {
00159 return & cit->second;
00160 } else {
00161
00162 return DealWithUnknownID(key);
00163 }
00164 }
00165
00166 ParticleData * ParticleDataTable::DealWithUnknownID( ParticleID & key ) const
00167 {
00168
00169 ParticleData * pd = itsProcessUnknownID->callProcessUnknownID( key, *this );
00170 if( pd ) {
00171 addParticle( *pd );
00172 }
00173 return pd;
00174 }
00175
00176 ParticleData * ParticleDataTable::particle( std::string nkey)
00177 {
00178 nameIterator it = itsNameMap.find( nkey );
00179 if( it != itsNameMap.end() ) {
00180 return particle(it->second);
00181 } else {
00182
00183 return 0;
00184 }
00185 }
00186
00187 ParticleData const * ParticleDataTable::particle( std::string nkey ) const
00188 {
00189 const_iteratorByName cit = itsNameMap.find( nkey );
00190 if( cit != itsNameMap.end() ) {
00191 return particle(cit->second);
00192 } else {
00193
00194 return 0;
00195 }
00196 }
00197
00198 void ParticleDataTable::addParticle( ParticleData const & p ) const
00199 {
00200
00201 ParticleID id=p.ID();
00202
00203 itsMap.insert( std::make_pair( id, p ));
00204 itsNameMap.insert( std::make_pair( p.name(), id ));
00205 }
00206
00207 }