![]() |
HepPDT Reference DocumentationHepPDT |
00001 // ---------------------------------------------------------------------- 00002 // examMyPDT.cc 00003 // 00009 00010 #include "HepPDT/defs.h" 00011 #include <fstream> 00012 00013 #include <cstdlib> 00014 #include <string> 00015 00016 #include "HepPDT/TableBuilder.hh" 00017 #include "HepPDT/ParticleDataTable.hh" 00018 #include "HepPDT/TempParticleData.hh" 00019 00020 void addData( HepPDT::TableBuilder& tb, std::string const & name, int const id, 00021 double const mass, double const charge, double const width, 00022 double const tspin ); 00023 00024 int main() 00025 { 00026 const char outfile[] = "examMyPDT.out"; 00027 // construct empty PDT 00028 HepPDT::ParticleDataTable datacol; 00029 { 00030 // Construct table builder 00031 HepPDT::TableBuilder tb(datacol); 00032 // create my own particles here 00033 addData( tb, "p+", 2212, 0.938, +1.0, -1, .5 ); 00034 addData( tb, "d", 1, 0., -2./3, -1, .5 ); 00035 addData( tb, "u~", -2, 0., -1./3, -1, .5 ); 00036 addData( tb, "W-", -24, 80.396, -1.0, 2.06, 1.0 ); 00037 addData( tb, "gamma", 22, 0., 0., -1, 1.0 ); 00038 addData( tb, "badgamma", 122, 0., 0., -1, 1.0 ); 00039 tb.removeParticle( 122 ); 00040 } // the tb destructor fills datacol 00041 std::ofstream wpdfile( outfile ); 00042 if( !wpdfile ) { 00043 std::cerr << "cannot open " << outfile << std::endl; 00044 exit(-1); 00045 } 00046 datacol.writeParticleData(wpdfile); 00047 // access a particle 00048 // you get a null pointer if you reqest an undefined particle 00049 HepPDT::ParticleData * pd = datacol.particle( HepPDT::ParticleID(22) ); 00050 if( pd ) { 00051 std::cout << "particle " << pd->name() << " is defined" << std::endl; 00052 } else { 00053 std::cout << "ERROR: particle is not in particle data table" << std::endl; 00054 } 00055 pd = datacol[ HepPDT::ParticleID(-24) ]; 00056 // we expect this next line to produce an error 00057 std::cout << "the error is expected" << std::endl; 00058 if( datacol[ HepPDT::ParticleID(111) ] ) { 00059 std::cout << "particle " << datacol[ HepPDT::ParticleID(111) ]->name() << " is defined" << std::endl; 00060 } else { 00061 std::cout << "ERROR: particle " << HepPDT::ParticleID(111).pid() 00062 << " is not in particle data table" << std::endl; 00063 } 00064 00065 return 0; 00066 } 00067 00068 void addData( HepPDT::TableBuilder& tb, std::string const & name, int const id, 00069 double const mass, double const charge, double const width, 00070 double const tspin ) 00071 { 00072 HepPDT::TempParticleData& tpd = tb.getParticleData( HepPDT::ParticleID( id ) ); 00073 tpd.tempParticleName = name; 00074 tpd.tempCharge = charge; 00075 tpd.tempMass = HepPDT::Measurement( mass, 0. ); 00076 tpd.tempSpin = HepPDT::SpinState( tspin, 0., 0. ); 00077 tpd.tempWidth = HepPDT::Measurement( width, 0. ); 00078 tb.addParticle( tpd ); 00079 }