![]() |
HepMC Reference DocumentationHepMC |
00001 //-------------------------------------------------------------------------- 00002 00004 // Matt.Dobbs@Cern.CH, January 2000 00005 // Reads a particle data table from file supplied in PDG format 00006 // For the most recent table see: http://pdg.lbl.gov/computer_read.html 00008 00009 #include <ctype.h> // for isspace() etc. 00010 #include <string> 00011 #include <vector> 00012 #include <cstdlib> // needed for abort() 00013 #include "HepMC/IO_PDG_ParticleDataTable.h" 00014 00015 namespace HepMC { 00016 00017 IO_PDG_ParticleDataTable::IO_PDG_ParticleDataTable( const char* filename ) 00018 : m_filename(filename), m_file(filename) { 00019 std::cout << "-------------------------------------------------------" << std::endl; 00020 std::cout << "Use of HepMC/IO_PDG_ParticleDataTable is deprecated" << std::endl; 00021 std::cout << "Use of HepMC/ParticleDataTable is deprecated" << std::endl; 00022 std::cout << "-------------------------------------------------------" << std::endl; 00023 } 00024 00025 IO_PDG_ParticleDataTable::~IO_PDG_ParticleDataTable() { 00026 m_file.close(); 00027 } 00028 00029 bool IO_PDG_ParticleDataTable::fill_particle_data_table( 00030 ParticleDataTable* pdt) 00031 { 00032 // 00033 // test that pdt pointer is not null 00034 if ( !pdt ) { 00035 std::cerr 00036 << "IO_Ascii::fill_particle_data_table - passed null table." 00037 << std::endl; 00038 return 0; 00039 } 00040 // 00041 // test the file is good and advance to keyword 00042 if (!m_file ) { 00043 // return 0; 00044 std::cerr << "IO_PDG_ParticleDataTable::fill_particle_data_table " 00045 << " ERROR, file " << m_filename << " does not exist, " 00046 << " ABORT." << std::endl; 00047 abort(); 00048 } 00049 m_file.seekg( 0 ); 00050 if ( !search_for_key_end(m_file,"\nM") ) { 00051 std::cerr << "IO_PDG_ParticleDataTable: " 00052 << "Error advancing to first entry." 00053 << std::endl; 00054 return 0; 00055 } 00056 // set description 00057 std::string description = "Read from " + m_filename 00058 + " by IO_PDG_ParticleDataTable"; 00059 pdt->set_description( description ); 00060 m_file.putback('M'); 00061 // read in each entry one by one 00062 while ( m_file.rdstate() == 0 ) { 00063 read_entry( pdt ); 00064 } 00065 return 1; 00066 } 00067 00068 void IO_PDG_ParticleDataTable::read_entry( ParticleDataTable* pdt ) { 00069 int position = m_file.tellg(); 00070 // variables for input 00071 char code; 00072 int id[4] = { 0,0,0,0 }; 00073 int charge[4] = { 999, 999, 999, 999 }; 00074 double value; 00075 std::string name; 00076 00077 code = m_file.get(); 00078 if ( code == EOF ) { 00079 m_file.clear( std::ios::eofbit ); 00080 return; 00081 } 00082 00083 if ( code == '\n' ) return; // ignore empty lines. 00084 00085 if ( code!='M' && code!='W' ) { 00086 std::cerr << "IO_PDG_ParticleDataTable::read_entry cannot " 00087 << "understand syntax, setting badbit." 00088 << std::endl; 00089 m_file.putback( code ); 00090 m_file.clear( std::ios::badbit ); 00091 return; 00092 } 00093 // read the particle ID's -- here I assume there is atleast one 00094 // white space b/t the 4 id columns. 00095 for ( int id_i1 = 0; id_i1 < 4; ++id_i1 ) { 00096 m_file.seekg( position+1+(id_i1*8) ); 00097 for ( int i = 0; i < 8; ++i ) { 00098 if ( !isspace(m_file.peek()) ) { 00099 //m_file.width(8-i); // has no effect 00100 // how do I limit to reading only 8-i characters? 00101 // setw(8-i) has no effect either. 00102 m_file >> id[id_i1]; 00103 break; 00104 } 00105 m_file.ignore(); 00106 } 00107 } 00108 //m_file.width(0); 00109 m_file.seekg(position+33); 00110 m_file >> value; 00111 m_file.seekg(position+66); 00112 m_file >> name; 00113 // loop over all remaining columns of the name section, where the 00114 // charge is stored --- until \n is reached 00115 // Here I assume there is atleast one white space between the name 00116 // and the charge. This is true for the 1998 PDG table, and I expect 00117 // it will always be true. 00118 int id_i2 = 0; 00119 while ( m_file.rdstate() == 0 ) { 00120 char c = m_file.get(); 00121 if ( c == '\n' || c == EOF ) break; 00122 if ( isspace(c) || c==',' ) { 00123 } else if ( c=='-' ) { 00124 charge[id_i2] = -1; 00125 ++id_i2; 00126 } else if ( c=='0' ) { 00127 charge[id_i2] = 0; 00128 ++id_i2; 00129 } else if ( c=='+' ) { 00130 charge[id_i2] = 1; 00131 if ( m_file.peek() == '+' ) { 00132 charge[id_i2] = 2; 00133 m_file.ignore(); 00134 } 00135 ++id_i2; 00136 } 00137 } 00138 // add the new information to the particle data table. 00139 for ( int id_i3 = 0; id_i3 < 4; ++id_i3 ) { 00140 if ( id[id_i3] == 0 ) continue; 00141 std::string scharge; 00142 if ( charge[id_i3] == -1 ) { 00143 scharge = "-"; 00144 } else if ( charge[id_i3] == 1 ) { 00145 scharge = "+"; 00146 } else if ( charge[id_i3] == 2 ) { 00147 scharge = "++"; 00148 } 00149 ParticleData* pdata = pdt->find( id[id_i3] ); 00150 if ( pdata ) { 00151 if ( code == 'M' ) { 00152 pdata->set_mass( value ); 00153 } else if ( code == 'W' ) { 00154 pdata->set_clifetime( clifetime_from_width(value) ); 00155 } 00156 } else if ( code == 'M' ) { 00157 pdata = new ParticleData( name+scharge, 00158 id[id_i3], (double)charge[id_i3], 00159 value ); 00160 pdt->insert(pdata); 00161 } else if ( code == 'W' ) { 00162 pdata = new ParticleData( name+scharge, 00163 id[id_i3], (double)charge[id_i3], 00164 0, clifetime_from_width(value) ); 00165 pdt->insert(pdata); 00166 } 00167 } 00168 } 00169 00170 void IO_PDG_ParticleDataTable::add_quarks_to_table( 00171 ParticleDataTable& pdt ) { 00173 // in 00174 std::vector<std::string> name(6); 00175 name[0] = "d"; 00176 name[1] = "u"; 00177 name[2] = "s"; 00178 name[3] = "c"; 00179 name[4] = "b"; 00180 name[5] = "t"; 00181 int id[6] = { 1, 2, 3, 4, 5, 6 }; 00182 double charge[6] = { -1./3., 2./3., -1./3., 2./3., -1./3., 2./3. }; 00183 // take central values from PDG July 1998 for masses 00184 double mass[6] = { 0.006, 0.00325, 0.115, 1.25, 4.25, 173.8 }; 00185 for ( int i = 0; i<6; ++i ) { 00186 // build the particle 00187 ParticleData* pdata = pdt.find(id[i]); 00188 if ( pdata ) { 00189 mass[i] = pdata->mass(); 00190 pdt.erase(pdata); 00191 delete pdata; 00192 } 00193 pdata = new ParticleData( name[i], id[i], charge[i], mass[i], -1., 00194 .5 ); 00195 pdt.insert(pdata); 00196 // build the antiparticle 00197 pdata = pdt.find(-1*id[i]); 00198 if ( pdata ) { 00199 pdt.erase(pdata); 00200 delete pdata; 00201 } 00202 pdata = new ParticleData( name[i]+"~", -1*id[i], -1*charge[i], 00203 mass[i], -1., .5 ); 00204 pdt.insert(pdata); 00205 } 00206 } 00207 00208 bool IO_PDG_ParticleDataTable::search_for_key_end( std::istream& in, 00209 const char* key ) { 00214 // 00215 char c[1]; 00216 unsigned int index = 0; 00217 while ( in.get(c[0]) ) { 00218 if ( c[0] == key[index] ) { 00219 ++index; 00220 } else { index = 0; } 00221 if ( index == strlen(key) ) return 1; 00222 } 00223 return 0; 00224 } 00225 00226 } // HepMC 00227 00228 00229 00230 00231 00232 00233 00234 00235