00001
00002
00004
00005
00006
00008
00009 #include <ctype.h>
00010 #include <string>
00011 #include <vector>
00012 #include <cstdlib>
00013 #include <cstring>
00014 #include "HepMC/IO_PDG_ParticleDataTable.h"
00015
00016 namespace HepMC {
00017
00018 IO_PDG_ParticleDataTable::IO_PDG_ParticleDataTable( const char* filename )
00019 : m_filename(filename), m_file(filename) {
00020 std::cout << "-------------------------------------------------------" << std::endl;
00021 std::cout << "Use of HepMC/IO_PDG_ParticleDataTable is deprecated" << std::endl;
00022 std::cout << "Use of HepMC/ParticleDataTable is deprecated" << std::endl;
00023 std::cout << "-------------------------------------------------------" << std::endl;
00024 }
00025
00026 IO_PDG_ParticleDataTable::~IO_PDG_ParticleDataTable() {
00027 m_file.close();
00028 }
00029
00030 bool IO_PDG_ParticleDataTable::fill_particle_data_table(
00031 ParticleDataTable* pdt)
00032 {
00033
00034
00035 if ( !pdt ) {
00036 std::cerr
00037 << "IO_Ascii::fill_particle_data_table - passed null table."
00038 << std::endl;
00039 return 0;
00040 }
00041
00042
00043 if (!m_file ) {
00044
00045 std::cerr << "IO_PDG_ParticleDataTable::fill_particle_data_table "
00046 << " ERROR, file " << m_filename << " does not exist, "
00047 << " ABORT." << std::endl;
00048 abort();
00049 }
00050 m_file.seekg( 0 );
00051 if ( !search_for_key_end(m_file,"\nM") ) {
00052 std::cerr << "IO_PDG_ParticleDataTable: "
00053 << "Error advancing to first entry."
00054 << std::endl;
00055 return 0;
00056 }
00057
00058 std::string description = "Read from " + m_filename
00059 + " by IO_PDG_ParticleDataTable";
00060 pdt->set_description( description );
00061 m_file.putback('M');
00062
00063 while ( m_file.rdstate() == 0 ) {
00064 read_entry( pdt );
00065 }
00066 return 1;
00067 }
00068
00069 void IO_PDG_ParticleDataTable::read_entry( ParticleDataTable* pdt ) {
00070 int position = m_file.tellg();
00071
00072 char code;
00073 int id[4] = { 0,0,0,0 };
00074 int charge[4] = { 999, 999, 999, 999 };
00075 double value;
00076 std::string name;
00077
00078 code = m_file.get();
00079 if ( code == EOF ) {
00080 m_file.clear( std::ios::eofbit );
00081 return;
00082 }
00083
00084 if ( code == '\n' ) return;
00085
00086 if ( code!='M' && code!='W' ) {
00087 std::cerr << "IO_PDG_ParticleDataTable::read_entry cannot "
00088 << "understand syntax, setting badbit."
00089 << std::endl;
00090 m_file.putback( code );
00091 m_file.clear( std::ios::badbit );
00092 return;
00093 }
00094
00095
00096 for ( int id_i1 = 0; id_i1 < 4; ++id_i1 ) {
00097 m_file.seekg( position+1+(id_i1*8) );
00098 for ( int i = 0; i < 8; ++i ) {
00099 if ( !isspace(m_file.peek()) ) {
00100
00101
00102
00103 m_file >> id[id_i1];
00104 break;
00105 }
00106 m_file.ignore();
00107 }
00108 }
00109
00110 m_file.seekg(position+33);
00111 m_file >> value;
00112 m_file.seekg(position+66);
00113 m_file >> name;
00114
00115
00116
00117
00118
00119 int id_i2 = 0;
00120 while ( m_file.rdstate() == 0 ) {
00121 char c = m_file.get();
00122 if ( c == '\n' || c == EOF ) break;
00123 if ( isspace(c) || c==',' ) {
00124 } else if ( c=='-' ) {
00125 charge[id_i2] = -1;
00126 ++id_i2;
00127 } else if ( c=='0' ) {
00128 charge[id_i2] = 0;
00129 ++id_i2;
00130 } else if ( c=='+' ) {
00131 charge[id_i2] = 1;
00132 if ( m_file.peek() == '+' ) {
00133 charge[id_i2] = 2;
00134 m_file.ignore();
00135 }
00136 ++id_i2;
00137 }
00138 }
00139
00140 for ( int id_i3 = 0; id_i3 < 4; ++id_i3 ) {
00141 if ( id[id_i3] == 0 ) continue;
00142 std::string scharge;
00143 if ( charge[id_i3] == -1 ) {
00144 scharge = "-";
00145 } else if ( charge[id_i3] == 1 ) {
00146 scharge = "+";
00147 } else if ( charge[id_i3] == 2 ) {
00148 scharge = "++";
00149 }
00150 ParticleData* pdata = pdt->find( id[id_i3] );
00151 if ( pdata ) {
00152 if ( code == 'M' ) {
00153 pdata->set_mass( value );
00154 } else if ( code == 'W' ) {
00155 pdata->set_clifetime( clifetime_from_width(value) );
00156 }
00157 } else if ( code == 'M' ) {
00158 pdata = new ParticleData( name+scharge,
00159 id[id_i3], (double)charge[id_i3],
00160 value );
00161 pdt->insert(pdata);
00162 } else if ( code == 'W' ) {
00163 pdata = new ParticleData( name+scharge,
00164 id[id_i3], (double)charge[id_i3],
00165 0, clifetime_from_width(value) );
00166 pdt->insert(pdata);
00167 }
00168 }
00169 }
00170
00171 void IO_PDG_ParticleDataTable::add_quarks_to_table(
00172 ParticleDataTable& pdt ) {
00174
00175 std::vector<std::string> name(6);
00176 name[0] = "d";
00177 name[1] = "u";
00178 name[2] = "s";
00179 name[3] = "c";
00180 name[4] = "b";
00181 name[5] = "t";
00182 int id[6] = { 1, 2, 3, 4, 5, 6 };
00183 double charge[6] = { -1./3., 2./3., -1./3., 2./3., -1./3., 2./3. };
00184
00185 double mass[6] = { 0.006, 0.00325, 0.115, 1.25, 4.25, 173.8 };
00186 for ( int i = 0; i<6; ++i ) {
00187
00188 ParticleData* pdata = pdt.find(id[i]);
00189 if ( pdata ) {
00190 mass[i] = pdata->mass();
00191 pdt.erase(pdata);
00192 delete pdata;
00193 }
00194 pdata = new ParticleData( name[i], id[i], charge[i], mass[i], -1.,
00195 .5 );
00196 pdt.insert(pdata);
00197
00198 pdata = pdt.find(-1*id[i]);
00199 if ( pdata ) {
00200 pdt.erase(pdata);
00201 delete pdata;
00202 }
00203 pdata = new ParticleData( name[i]+"~", -1*id[i], -1*charge[i],
00204 mass[i], -1., .5 );
00205 pdt.insert(pdata);
00206 }
00207 }
00208
00209 bool IO_PDG_ParticleDataTable::search_for_key_end( std::istream& in,
00210 const char* key ) {
00215
00216 char c[1];
00217 unsigned int index = 0;
00218 while ( in.get(c[0]) ) {
00219 if ( c[0] == key[index] ) {
00220 ++index;
00221 } else { index = 0; }
00222 if ( index == strlen(key) ) return 1;
00223 }
00224 return 0;
00225 }
00226
00227 }
00228
00229
00230
00231
00232
00233
00234
00235
00236