HepPDT Reference Documentation

HepPDT

addParticleTable.cc

Go to the documentation of this file.
00001 // ----------------------------------------------------------------------
00002 //
00003 // addParticleTable.cc
00004 // Author: Lynn Garren
00005 //
00006 // this has the functions used by addParticleTable
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   //    validate => verify that the ParticleID is valid
00025   std::string pdline, aname;
00026   int id;
00027   // read and parse each line
00028   while( std::getline( pdfile, pdline) ) {
00029     if( detail::getParticleID( id, pdline ) ) {
00030       ParticleID pid( id );
00031       if( validate ) {
00032         if( pid.isValid() ) {
00033           // this is a new particle definition
00034           TempParticleData& tpd = tb.getParticleData( pid );
00035           detail::parseParticleLine( tpd, pdline );
00036         }
00037       } else {
00038         // this is a new particle definition
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     // line is too short
00055     if( sl < 30 ) return false;
00056     // now check for possible comments 
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     // hope that this is now a valid line
00062     //std::istringstream var1(pdline.substr(21,12).c_str());
00063     std::istringstream var1(pdline.c_str());
00064     var1 >> id;
00065     if( id == 0 ) return false;
00066     // have non-zero ID
00067     return true;
00068 }
00069 
00070 void parseParticleLine( TempParticleData & tpd, const std::string & pdline )
00071 {
00072     // this line defines a particle
00073     std::string name1;
00074     int id, chg;
00075     double mass, width, lifet;
00076     
00077     // check for valid TempParticleData
00078     if( tpd.tempID.pid() == 0 ) { return; }
00079     // have a valid PID, so proceed
00080     std::istringstream particle( pdline.c_str() );
00081     particle >> id >> name1 >> chg >> mass >> width >> lifet ;
00082     // std::cout << id << " " << tpd.tempID.pid() << " " 
00083     //      << name1 << " " << chg << " " 
00084     //      << mass << " " << width << " " << lifet << std::endl; 
00085     // old:  tpd.tempParticleName = HepPID::particleName( tpd.tempID.pid() );
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     // either width or lifetime is defined - not both
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 }  // namespace detail
00103 
00104 }       // HepPDT

Generated on Fri Oct 24 13:41:35 2008 for HepPDT by  doxygen 1.5.1-3