HepMC Reference Documentation

HepMC

example_MyPythiaRead.cc

Go to the documentation of this file.
00001 
00002 // garren@fnal.gov, January 2007
00003 // This example is an extension of example_MyPythia.cc
00004 //  
00005 // generate events with Pythia, write a file, and read the resulting output
00006 // Notice that we use scope to explicitly close the ouput files.
00007 // The two output files should be the same size, but because particles are
00008 // saved as sets within a vertex, they will be written in arbitrary order.
00010 // To Compile: go to the HepMC directory and type:
00011 // gmake examples/example_MyPythiaRead.exe
00012 //
00013 // In this example the precision and number of entries for the HEPEVT 
00014 // fortran common block are explicitly defined to correspond to those 
00015 // used in the Pythia version of the HEPEVT common block. 
00016 //
00017 // If you get funny output from HEPEVT in your own code, probably you have
00018 // set these values incorrectly!
00019 //
00020 
00021 #include <iostream>
00022 #include "HepMC/PythiaWrapper.h"
00023 #include "HepMC/IO_HEPEVT.h"
00024 #include "HepMC/IO_GenEvent.h"
00025 #include "HepMC/GenEvent.h"
00026 #include "PythiaHelper.h"
00027 
00028 int main() { 
00029     //
00030     //........................................HEPEVT
00031     // Pythia 6.3 uses HEPEVT with 4000 entries and 8-byte floating point
00032     //  numbers. We need to explicitly pass this information to the 
00033     //  HEPEVT_Wrapper.
00034     //
00035     HepMC::HEPEVT_Wrapper::set_max_number_entries(4000);
00036     HepMC::HEPEVT_Wrapper::set_sizeof_real(8);
00037     //
00038     //........................................PYTHIA INITIALIZATIONS
00039     initPythia();
00040 
00041     //........................................HepMC INITIALIZATIONS
00042     //
00043     // Instantiate an IO strategy for reading from HEPEVT.
00044     HepMC::IO_HEPEVT hepevtio;
00045     //
00046     //........................................define the output scope
00047     {
00048         // Instantial an IO strategy to write the data to file - it uses the 
00049         //  same ParticleDataTable
00050         HepMC::IO_GenEvent ascii_io("example_MyPythiaRead.dat",std::ios::out);
00051         //
00052         //........................................EVENT LOOP
00053         for ( int i = 1; i <= 100; i++ ) {
00054             if ( i%50==1 ) std::cout << "Processing Event Number " 
00055                                      << i << std::endl;
00056             call_pyevnt();      // generate one event with Pythia
00057             // pythia pyhepc routine converts common PYJETS in common HEPEVT
00058             call_pyhepc( 1 );
00059             HepMC::GenEvent* evt = hepevtio.read_next_event();
00060             // add some information to the event
00061             evt->set_event_number(i);
00062             evt->set_signal_process_id(20);
00063             // write the event out to the ascii file
00064             ascii_io << evt;
00065             // we also need to delete the created event from memory
00066             delete evt;
00067         }
00068         //........................................TERMINATION
00069         // write out some information from Pythia to the screen
00070         call_pystat( 1 );    
00071     }  // ascii_io destructor is called here
00072     //
00073     //........................................define an input scope
00074     {
00075         // now read the file we wrote
00076         HepMC::IO_GenEvent ascii_in("example_MyPythiaRead.dat",std::ios::in);
00077         HepMC::IO_GenEvent ascii_io2("example_MyPythiaRead2.dat",std::ios::out);
00078         int icount=0;
00079         HepMC::GenEvent* evt = ascii_in.read_next_event();
00080         while ( evt ) {
00081             icount++;
00082             if ( icount%50==1 ) std::cout << "Processing Event Number " << icount
00083                                           << " its # " << evt->event_number() 
00084                                           << std::endl;
00085             // write the event out to the ascii file
00086             ascii_io2 << evt;
00087             delete evt;
00088             ascii_in >> evt;
00089         }
00090         //........................................PRINT RESULT
00091         std::cout << icount << " events found. Finished." << std::endl;
00092     } // ascii_io2 and ascii_in destructors are called here
00093 
00094     return 0;
00095 }
00096 
00097 
00098  

Generated on Wed Mar 12 13:08:08 2008 for HepMC by  doxygen 1.5.1-3