HepPDT Reference Documentation

HepPDT

testHepPDT.cc

00001 // ----------------------------------------------------------------------
00002 // testHepPDT.cc
00003 // Author: Lynn Garren
00004 //
00005 // test by reading the PDG table
00006 // get filename and location of PDG table from input stream
00007 //
00008 // Usage:  testHepPDT 
00009 //
00010 // ----------------------------------------------------------------------
00011 
00012 #include <fstream>
00013 #include <iomanip>
00014 
00015 #include "HepPDT/defs.h"
00016 #include "HepPDT/TableBuilder.hh"
00017 #include "HepPDT/ParticleDataTable.hh"
00018 #include "HepPDT/HeavyIonUnknownID.hh"
00019 // local include
00020 #include "TestNuclearFragment.hh"
00021 
00022 void pdtSimpleTest( char[300], std::ofstream & );
00023 void pdtFragmentTest( char[300], std::ofstream & );
00024 void duplicateFragmentTest( char[300], std::ofstream & );
00025 void testPDMethods( HepPDT::ParticleDataTable&, std::ofstream & );
00026 
00027 int main()
00028 {
00029     char pdgfile[300] = "";
00030     const char outfile[] = "testHepPDT.out";
00031     std::cin >> pdgfile;
00032     // open output file
00033     std::ofstream wpdfile( outfile );
00034     if( !wpdfile ) { 
00035       std::cerr << "cannot open " << outfile << std::endl;
00036       exit(-1);
00037     }
00038 
00039     // construct a default PDT
00040     pdtSimpleTest( pdgfile, wpdfile );
00041     // now test the nuclear fragment option
00042     pdtFragmentTest( pdgfile, wpdfile );
00043     // check how we deal with duplicate fragments
00044     duplicateFragmentTest( pdgfile, wpdfile );
00045 
00046     return 0;
00047 }
00048 
00049 void pdtSimpleTest( char pdgfile[300], std::ofstream & wpdfile )
00050 {
00051     // open input file
00052     std::ifstream pdfile( pdgfile );
00053     if( !pdfile ) { 
00054       std::cerr << "cannot open " << pdgfile << std::endl;
00055       exit(-1);
00056     }
00057     // construct empty PDT
00058     HepPDT::ParticleDataTable datacol( "2006 PDG Table" );
00059     {
00060         // Construct table builder
00061         HepPDT::TableBuilder  tb(datacol);
00062         // read the input - put as many here as you want
00063         if( !HepPDT::addPDGParticles( pdfile, tb ) ) { 
00064             std::cout << "error reading PDG file " << std::endl; 
00065         }
00066     }   // the tb destructor fills datacol
00067     // done with pdfile, so close it
00068     pdfile.close();
00069 
00070     const char outfile1[] = "testHepPDTtable.out";
00071     // open output file
00072     std::ofstream wpdt1( outfile1 );
00073     if( !wpdt1 ) { 
00074       std::cerr << "cannot open " << outfile1 << std::endl;
00075       exit(-1);
00076     }
00077     datacol.writeParticleData(wpdt1);
00078 
00079     wpdfile << std::endl;
00080 
00081     // output some pion information
00082     HepPDT::ParticleData * pd;
00083     pd=datacol.particle(HepPDT::ParticleID(111));
00084     // test the ResonanceStructure cutoff methods here
00085     if(pd) { 
00086         pd->write(wpdfile);
00087         wpdfile << "Resonance info for 111 " 
00088                 << pd->totalWidth().value() << " " 
00089                 << pd->totalWidth().sigma() << " " 
00090                 << pd->lowerCutoff() << " " 
00091                 << pd->upperCutoff() << std::endl;
00092     }
00093     //  -111 is an illegal particle, no info will be written
00094     pd=datacol.particle(HepPDT::ParticleID(-111));
00095     if(pd) pd->write(wpdfile);
00096     pd=datacol.particle(HepPDT::ParticleID(211));
00097     if(pd) pd->write(wpdfile);
00098     // string lookup
00099     pd=datacol.particle(std::string("pi0"));
00100     if(pd) pd->write(wpdfile);
00101 
00102     // particle info
00103     datacol.writeParticleInfo(wpdfile);
00104        
00105     testPDMethods( datacol, wpdfile );
00106 }
00107 
00108 void pdtFragmentTest( char pdgfile[300], std::ofstream & wpdfile )
00109 {
00110     wpdfile << std::endl;
00111     wpdfile << " Begin test of HeavyIonUnknownID " << std::endl;
00112     // reopen input file
00113     std::ifstream pdfile2( pdgfile );
00114     if( !pdfile2 ) { 
00115       std::cerr << "cannot open " << pdgfile << std::endl;
00116       exit(-1);
00117     }
00118     // construct another PDT instance that knows how to deal with unknown heavy ions
00119     // NOTE: normally you would construct a single ParticleDataTable with this option
00120     HepPDT::ParticleDataTable pdt2( "Handle Heavy Ions", 
00121                                     new HepPDT::HeavyIonUnknownID );
00122     {
00123         // Construct table builder
00124         HepPDT::TableBuilder  tb2(pdt2);
00125         // read the input - put as many here as you want
00126         if( !HepPDT::addPDGParticles( pdfile2, tb2 ) ) { 
00127             std::cout << "error reading PDG file " << std::endl; 
00128         }
00129     }
00130     // done with pdfile, so close it
00131     pdfile2.close();
00132 
00133     // try a heavy ion
00134     HepPDT::ParticleData * pd=pdt2.particle(HepPDT::ParticleID(1000020040));
00135     wpdfile << " Printing information for unknown nuclear fragment " 
00136             << std::endl;
00137     if(pd) pd->write(wpdfile);
00138 }
00139 
00140 void duplicateFragmentTest( char pdgfile[300], std::ofstream & wpdfile )
00141 {
00142     wpdfile << std::endl;
00143     wpdfile << " Begin test of duplicate nuclear fragments " << std::endl;
00144     // reopen input file
00145     std::ifstream pdfile2( pdgfile );
00146     if( !pdfile2 ) { 
00147       std::cerr << "cannot open " << pdgfile << std::endl;
00148       exit(-1);
00149     }
00150     // this test checks to see if we have actually added a fragment to the table
00151     HepPDT::ParticleDataTable pdt( "Duplicate Nuclear Fragments", 
00152                                     new HepPDT::TestNuclearFragment );
00153     {
00154         // Construct table builder
00155         HepPDT::TableBuilder  tb2(pdt);
00156         // read the input - put as many here as you want
00157         if( !HepPDT::addPDGParticles( pdfile2, tb2 ) ) { 
00158             std::cout << "error reading PDG file " << std::endl; 
00159         }
00160     }
00161     // done with pdfile, so close it
00162     pdfile2.close();
00163 
00164     // try a heavy ion
00165     wpdfile << " Printing information for unknown nuclear fragments " 
00166             << std::endl;
00167     HepPDT::ParticleData * pd=pdt.particle(HepPDT::ParticleID(1000020040));
00168     if(pd) pd->write(wpdfile);
00169     pd=pdt.particle(HepPDT::ParticleID(1000020040));
00170     if(pd) pd->write(wpdfile);
00171     pd=pdt.particle(HepPDT::ParticleID(1000010040));
00172     if(pd) pd->write(wpdfile);
00173     pd=pdt.particle(HepPDT::ParticleID(1000020040));
00174     if(pd) pd->write(wpdfile);
00175     // what is the state of the table?
00176     const char outfile2[] = "testHepPDTfragment.out";
00177     std::ofstream wpdt( outfile2 );
00178     if( !wpdt ) { 
00179       std::cerr << "cannot open " << outfile2 << std::endl;
00180       exit(-1);
00181     }
00182     pdt.writeParticleData(wpdt);
00183 
00184     // check isStable
00185     const char outfile3[] = "testHepPDTstatus.out";
00186     std::ofstream wpdt3( outfile3 );
00187     if( !wpdt3 ) { 
00188       std::cerr << "cannot open " << outfile3 << std::endl;
00189       exit(-1);
00190     }
00191     pdt.writeParticleStatus(wpdt3);
00192 }
00193 
00194 void testPDMethods( HepPDT::ParticleDataTable& datacol, std::ofstream & wpdfile )
00195 {
00196     wpdfile << std::endl;
00197     wpdfile << "Begin test of ParticleData methods " << std::endl;
00198     HepPDT::ParticleData * pd;
00199     int id[27] = { 5, 24, 15, 213, 3214, 10213, 9050225, 541, 129050225,
00200                    2000025, 3101, 3301, 2212, 1000020040, 1000060120, 555,
00201                    5000040, 5100005, 24, 5100024, 5100025, 9221132, 
00202                    4111370, -4120240, 4110050, 10013730, 1000612 };
00203     int it;
00204     for( it=0; it < 27; it++ ) {
00205         pd=datacol.particle(HepPDT::ParticleID(id[it]));
00206         if(pd) {
00207             if( pd->hasUp() ) {
00208                 wpdfile << "Particle " << pd->name()  << " " << pd->pid() 
00209                           << " has an up quark" << std::endl;
00210             }
00211             if( pd->hasDown() ) {
00212                 wpdfile << "Particle " << pd->name()  << " " << pd->pid() 
00213                           << " has a down quark" << std::endl;
00214             }
00215             if( pd->hasStrange() ) {
00216                 wpdfile << "Particle " << pd->name()  << " " << pd->pid() 
00217                           << " has a strange quark" << std::endl;
00218             }
00219             if( pd->hasCharm() ) {
00220                 wpdfile << "Particle " << pd->name() << " " << pd->pid() 
00221                           << " has a charmed quark" << std::endl;
00222             }
00223             if( pd->hasBottom() ) {
00224                 wpdfile << "Particle " << pd->name() << " " << pd->pid() 
00225                           << " has a bottom quark" << std::endl;
00226             }
00227             if( pd->hasTop() ) {
00228                 wpdfile << "Particle " << pd->name() << " " << pd->pid() 
00229                           << " has a top quark" << std::endl;
00230             }
00231         }
00232     }
00233 }

Generated on Fri Dec 4 14:05:23 2009 for HepPDT by  doxygen 1.4.7