![]() |
HepPDT Reference DocumentationHepPDT |
00001 // ---------------------------------------------------------------------- 00002 // 00003 // ParticleDataTable.cc 00004 // Author: Lynn Garren, Walter Brown 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 // default constructor 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 // write header 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 // write particle info 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 // write header 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 // write particle info 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 // write particle info 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 // write header 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 // write particle info 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 // pad the name 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 // return to default settings 00132 os.precision(6); 00133 os.setf(std::ios::fmtflags(0), std::ios::floatfield); 00134 // end the line 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 // call special lookup function and return that value 00149 return DealWithUnknownID(key); 00150 } 00151 } 00152 00153 ParticleData const * ParticleDataTable::particle( ParticleID key ) const 00154 { 00155 const_iterator cit; 00156 //int id = key.pid(); 00157 cit = itsMap.find( key ); 00158 if( cit != itsMap.end() ) { 00159 return & cit->second; 00160 } else { 00161 // call special lookup function and return that value 00162 return DealWithUnknownID(key); 00163 } 00164 } 00165 00166 ParticleData * ParticleDataTable::DealWithUnknownID( ParticleID & key ) const 00167 { 00168 // call special lookup function and return that value 00169 ParticleData * pd = itsProcessUnknownID->callProcessUnknownID( key, *this ); 00170 if( !pd ) return 0; 00171 addParticle( *pd ); 00172 ParticleID id = pd->ID(); 00173 delete pd; 00174 return & itsMap.find( id )->second; 00175 } 00176 00177 ParticleData * ParticleDataTable::particle( std::string nkey) 00178 { 00179 nameIterator it = itsNameMap.find( nkey ); 00180 if( it != itsNameMap.end() ) { 00181 return particle(it->second); 00182 } else { 00183 //std::cerr << "cannot find particle " << nkey << " in map" << std::endl; 00184 return 0; 00185 } 00186 } 00187 00188 ParticleData const * ParticleDataTable::particle( std::string nkey ) const 00189 { 00190 const_iteratorByName cit = itsNameMap.find( nkey ); 00191 if( cit != itsNameMap.end() ) { 00192 return particle(cit->second); 00193 } else { 00194 //std::cerr << "cannot find particle " << nkey << " in map" << std::endl; 00195 return 0; 00196 } 00197 } 00198 00199 void ParticleDataTable::addParticle( ParticleData const & p ) const 00200 { 00201 // private method 00202 ParticleID id=p.ID(); 00203 //std::string nid(p.name()); 00204 itsMap.insert( std::make_pair( id, p )); 00205 itsNameMap.insert( std::make_pair( p.name(), id )); 00206 } 00207 00208 } // HepPDT