00001
00002
00003
00004
00005
00006
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
00025 std::string pdline, aname;
00026 int id;
00027
00028 while( std::getline( pdfile, pdline) ) {
00029 if( detail::getParticleID( id, pdline ) ) {
00030 ParticleID pid( id );
00031 if( validate ) {
00032 if( pid.isValid() ) {
00033
00034 TempParticleData& tpd = tb.getParticleData( pid );
00035 detail::parseParticleLine( tpd, pdline );
00036 }
00037 } else {
00038
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
00055 if( sl < 30 ) return false;
00056
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
00062
00063 std::istringstream var1(pdline.c_str());
00064 var1 >> id;
00065 if( id == 0 ) return false;
00066
00067 return true;
00068 }
00069
00070 void parseParticleLine( TempParticleData & tpd, const std::string & pdline )
00071 {
00072
00073 std::string name1;
00074 int id, chg;
00075 double mass, width, lifet;
00076
00077
00078 if( tpd.tempID.pid() == 0 ) { return; }
00079
00080 std::istringstream particle( pdline.c_str() );
00081 particle >> id >> name1 >> chg >> mass >> width >> lifet ;
00082
00083
00084
00085
00086 tpd.tempParticleName = name1;
00087 tpd.tempSource = "ParticleTable";
00088 tpd.tempOriginalID = id;
00089 tpd.tempCharge = double(chg)/3.0;
00090 tpd.tempMass = Measurement( mass, 0.0 );
00091
00092 if( width > 0. ) {
00093 tpd.tempWidth = Measurement( width, 0.0 );
00094 } else if( width == -1. ) {
00095 tpd.tempWidth = Measurement( -1., 0.0 );
00096 } else if( lifet > 0. ) {
00097 tpd.tempWidth = Measurement( calculateWidthFromLifetime( lifet ), 0.0 );
00098 } else {
00099 tpd.tempWidth = Measurement( 0.0, 0.0 );
00100 }
00101 }
00102 }
00103
00104 }