![]() |
HepPDT Reference DocumentationHepPDT |
00001 // ---------------------------------------------------------------------- 00002 // 00003 // addParticleTable.cc 00004 // Author: Lynn Garren 00005 // 00006 // this has the functions used by addParticleTable 00007 // 00008 // ---------------------------------------------------------------------- 00009 00010 #include <iostream> 00011 #include <string> 00012 #include <sstream> 00013 00014 #include "HepPDT/defs.h" 00015 #include "HepPDT/TempParticleData.hh" 00016 #include "HepPDT/TableBuilder.hh" 00017 #include "HepPID/ParticleName.hh" 00018 00019 namespace HepPDT { 00020 00021 bool addParticleTable( std::istream & pdfile, TableBuilder & tb, 00022 bool validate ) 00023 { 00024 // validate => verify that the ParticleID is valid 00025 std::string pdline, aname; 00026 int id; 00027 // read and parse each line 00028 while( std::getline( pdfile, pdline) ) { 00029 if( detail::getParticleID( id, pdline ) ) { 00030 ParticleID pid( id ); 00031 if( validate ) { 00032 if( pid.isValid() ) { 00033 // this is a new particle definition 00034 TempParticleData& tpd = tb.getParticleData( pid ); 00035 detail::parseParticleLine( tpd, pdline ); 00036 } 00037 } else { 00038 // this is a new particle definition 00039 TempParticleData& tpd = tb.getParticleData( pid ); 00040 detail::parseParticleLine( tpd, pdline ); 00041 } 00042 } 00043 } 00044 std::cout << "found " << tb.size() << " particles" << std::endl; 00045 return true; 00046 } 00047 00048 00049 namespace detail { 00050 bool getParticleID( int & id, const std::string & pdline ) 00051 { 00052 int sl = pdline.length(); 00053 id = 0; 00054 // line is too short 00055 if( sl < 30 ) return false; 00056 // now check for possible comments 00057 std::string firstc = pdline.substr(0,1); 00058 if( firstc == "#" ) return false; 00059 std::string first2c = pdline.substr(0,2); 00060 if( first2c == "//" ) return false; 00061 // hope that this is now a valid line 00062 //std::istringstream var1(pdline.substr(21,12).c_str()); 00063 std::istringstream var1(pdline.c_str()); 00064 var1 >> id; 00065 if( id == 0 ) return false; 00066 // have non-zero ID 00067 return true; 00068 } 00069 00070 void parseParticleLine( TempParticleData & tpd, const std::string & pdline ) 00071 { 00072 // this line defines a particle 00073 std::string name1; 00074 int id, chg; 00075 double mass, width, lifet; 00076 00077 // check for valid TempParticleData 00078 if( tpd.tempID.pid() == 0 ) { return; } 00079 // have a valid PID, so proceed 00080 std::istringstream particle( pdline.c_str() ); 00081 particle >> id >> name1 >> chg >> mass >> width >> lifet ; 00082 // allow for Q-balls 00083 if( tpd.tempID.isQBall() ) { 00084 // 10x the charge 00085 tpd.tempCharge = double(chg)/10.0; 00086 } else { 00087 // 3x the charge 00088 tpd.tempCharge = double(chg)/3.0; 00089 } 00090 tpd.tempParticleName = name1; 00091 tpd.tempSource = "ParticleTable"; 00092 tpd.tempOriginalID = id; 00093 tpd.tempMass = Measurement( mass, 0.0 ); 00094 // either width or lifetime is defined - not both 00095 if( width > 0. ) { 00096 tpd.tempWidth = Measurement( width, 0.0 ); 00097 } else if( width == -1. ) { 00098 tpd.tempWidth = Measurement( -1., 0.0 ); 00099 } else if( lifet > 0. ) { 00100 tpd.tempWidth = Measurement( calculateWidthFromLifetime( lifet ), 0.0 ); 00101 } else { 00102 tpd.tempWidth = Measurement( 0.0, 0.0 ); 00103 } 00104 } 00105 } // namespace detail 00106 00107 } // HepPDT