// ParticleTable.cpp #include "ParticleTable.hpp" #include #include #include #include using std::string; using std::ifstream; using std::ios; using std::cerr; using std::endl; using std::istringstream; using std::vector; using namespace pdg; //********************************************************************** // Constructor. ParticleTable::ParticleTable(string filename) { ifstream in(filename.c_str(), ios::in); if ( ! in.is_open() ) { cerr << "ParticleTable::Unable to open file " << filename << "." << endl; return; } string line; while ( in ) { char buffer[200]; in.getline(buffer, 200); if ( ! in ) break; assert( in.gcount() <= 200 ); int idx = 0; string line(buffer); bool mass = false; bool width = false; // Fetch the line type. { char ch = line[idx++]; if ( ch == '*' ) { continue; } else if ( ch == 'M' ) { mass = true; } else if ( ch == 'W' ) { width = true; } else { cerr << "ParticleTable::Invalid line:" << endl; cerr << line << endl; continue; } } assert ( mass || width ); Map* pval = &_mass; Map* pd1 = &_dmass1; Map* pd2 = &_dmass2; if ( ! mass ) { pval = &_width; pd1 = &_dwidth1; pd2 = &_dwidth2; } // Fetch the particle ID's. vector pids; for ( int ipid=0; ipid<4; ++ipid ) { string word = line.substr(idx, 8); idx += 8; if ( word != " " ) { istringstream strm(word.c_str()); int pid; strm >> pid; pids.push_back(pid); } } assert( pids.size() > 0 ); // Fetch the value. { double value; istringstream word(line.substr(34,15)); word >> value; assert( value >= 0.0 ); int oldsize = pval->size(); for ( vector::const_iterator ipid=pids.begin(); ipid!=pids.end(); ++ipid ) { (*pval)[*ipid] = value; } assert( pval->size() == oldsize+pids.size() ); } // Fetch the errors. { double d1; istringstream word(line.substr(50,8)); word >> d1; assert( d1 >= 0.0 ); for ( vector::const_iterator ipid=pids.begin(); ipid!=pids.end(); ++ipid ) { (*pd1)[*ipid] = d1; } assert( pd1->size() == pval->size() ); } { double d2; istringstream word(line.substr(59,8)); word >> d2; assert( d2 <= 0.0 ); for ( vector::const_iterator ipid=pids.begin(); ipid!=pids.end(); ++ipid ) { (*pd2)[*ipid] = d2; } assert( pd2->size() == pval->size() ); } // Fetch the names. { istringstream word(line.substr(68,21)); string prefix; word >> prefix; string suffix; word >> suffix; int iwdx = 0; for ( vector::const_iterator ipid=pids.begin(); ipid!=pids.end(); ++ipid ) { assert( iwdx < suffix.length() ); int jwdx = iwdx; while ( suffix[jwdx]!=',' && jwdxsecond; } //********************************************************************** // Return the mass. double ParticleTable::mass(int pid) const { if ( ! has_mass(pid) ) return 0.0; return _mass.find(pid)->second; } double ParticleTable::dmass1(int pid) const { if ( ! has_mass(pid) ) return 0.0; return _dmass1.find(pid)->second; } double ParticleTable::dmass2(int pid) const { if ( ! has_mass(pid) ) return 0.0; return _dmass2.find(pid)->second; } //********************************************************************** // Return the width. double ParticleTable::width(int pid) const { if ( ! has_width(pid) ) return 0.0; return _width.find(pid)->second; } double ParticleTable::dwidth1(int pid) const { if ( ! has_width(pid) ) return 0.0; return _dwidth1.find(pid)->second; } double ParticleTable::dwidth2(int pid) const { if ( ! has_width(pid) ) return 0.0; return _dwidth2.find(pid)->second; } //**********************************************************************