00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #include <iostream>
00011 #include <string>
00012 #include <vector>
00013 #include <cmath>
00014 #include <sstream>
00015
00016 #include "HepPDT/defs.h"
00017 #include "HepPDT/TempParticleData.hh"
00018 #include "HepPDT/TableBuilder.hh"
00019
00020 namespace HepPDT {
00021
00022 bool addPDGParticles( std::istream & pdfile, TableBuilder & tb )
00023 {
00024
00025 std::vector<int> idlist;
00026 std::vector<std::string> names;
00027 std::string pdline;
00028
00029 while( std::getline( pdfile, pdline) ) {
00030 detail::getPDGpid( idlist, pdline );
00031 detail::getPDGnames( names, pdline );
00032 if ( idlist.size() != names.size() ) {
00033 std::cout << "addPDGParticles ERROR: cannot make sense of line:" << std::endl;
00034 std::cout << " " << pdline << std::endl;
00035 } else {
00036 for( unsigned int i = 0; i < idlist.size(); ++i )
00037 {
00038 TempParticleData& tpd = tb.getParticleData( ParticleID( idlist[i] ) );
00039 tpd.tempSource = "PDG table";
00040 tpd.tempOriginalID = idlist[i];
00041 tpd.tempParticleName = names[i];
00042 detail::parsePDGline( tpd, pdline );
00043 }
00044 }
00045 }
00046 std::cout << "found " << tb.size() << " particles" << std::endl;
00047 return true;
00048 }
00049
00050 namespace detail {
00051 void parsePDGline( TempParticleData & tpd, std::string & pdline )
00052 {
00053 double v, e1, e2, err;
00054 std::string name, ckey, charges, fullname, chg;
00055
00056
00057
00058 ckey = pdline.substr(0,1);
00059 name = charges = fullname = "";
00060 v = e1 = e2 = 0.0;
00061 std::istringstream val( pdline.substr(34,33).c_str() );
00062 val >> v >> e1 >> e2;
00063 err = sqrt( (e1*e1 + e2*e2)/2.0 );
00064 CheckPDGEntry( tpd, ckey, v, err );
00065 }
00066
00067 bool CheckPDGEntry( TempParticleData & tpd, const std::string & ckey,
00068 double val, double err )
00069 {
00070
00071 if( ckey.find("M") == 0 ) {
00072 tpd.tempMass = Measurement( val, err );
00073 } else if( ckey.find("W") == 0 ) {
00074 tpd.tempWidth = Measurement( val, err );
00075 } else {
00076 std::cout << "unrecognized key " << ckey << std::endl;
00077 return false;
00078 }
00079 return true;
00080 }
00081 }
00082
00083 }