HepMC Reference Documentation

HepMC

example_MyPythiaWithEventSelection.cc

Go to the documentation of this file.
00001 
00002 // Matt.Dobbs@Cern.CH, December 1999
00003 // November 2000, updated to use Pythia 6.1
00004 // example of generating events with Pythia
00005 // using HepMC/PythiaWrapper.h 
00006 // Events are read into the HepMC event record from the FORTRAN HEPEVT 
00007 // common block using the IO_HEPEVT strategy and then a very simple event
00008 // selection is performed.
00010 // To Compile: go to the HepMC directory and type:
00011 // gmake examples/example_MyPythiaWithEventSelection.exe
00012 //
00013 // See comments in examples/example_MyPythia.cxx regarding the HEPEVT wrapper.
00014 //
00015 
00016 #include <iostream>
00017 #include "HepMC/PythiaWrapper.h"
00018 #include "HepMC/IO_HEPEVT.h"
00019 #include "HepMC/GenEvent.h"
00020 #include "PythiaHelper.h"
00021 
00022 
00024 
00028 class IsGoodEventMyPythia {
00029 public:
00031     bool operator()( const HepMC::GenEvent* evt ) { 
00032         for ( HepMC::GenEvent::particle_const_iterator p 
00033                   = evt->particles_begin(); p != evt->particles_end(); ++p ){
00034             if ( (*p)->pdg_id() == 22 && (*p)->momentum().perp() > 25. ) {
00035                 //std::cout << "Event " << evt->event_number()
00036                 //     << " is a good event." << std::endl;
00037                 //(*p)->print();
00038                 return 1;
00039             }
00040         }
00041         return 0;
00042     }
00043 };
00044     
00045 int main() { 
00046     //
00047     //........................................HEPEVT
00048     // Pythia 6.1 uses HEPEVT with 4000 entries and 8-byte floating point
00049     //  numbers. We need to explicitly pass this information to the 
00050     //  HEPEVT_Wrapper.
00051     //
00052     HepMC::HEPEVT_Wrapper::set_max_number_entries(4000);
00053     HepMC::HEPEVT_Wrapper::set_sizeof_real(8);
00054     //  
00055     //........................................PYTHIA INITIALIZATIONS
00056     initPythia();
00057     //
00058     //........................................HepMC INITIALIZATIONS
00059     // Instantiate an IO strategy for reading from HEPEVT.
00060     HepMC::IO_HEPEVT hepevtio;
00061     // declare an instance of the event selection predicate
00062     IsGoodEventMyPythia is_good_event;
00063     //........................................EVENT LOOP
00064     int icount=0;
00065     int num_good_events=0;
00066     for ( int i = 1; i <= 100; i++ ) {
00067         icount++;
00068         if ( i%50==1 ) std::cout << "Processing Event Number " 
00069                                  << i << std::endl;
00070         call_pyevnt(); // generate one event with Pythia
00071         // pythia pyhepc routine convert common PYJETS in common HEPEVT
00072         call_pyhepc( 1 );
00073         HepMC::GenEvent* evt = hepevtio.read_next_event();
00074         // set number of multi parton interactions
00075         evt->set_mpi( pypars.msti[31-1] );
00076         // do event selection
00077         if ( is_good_event(evt) ) ++num_good_events;
00078         // we also need to delete the created event from memory
00079         delete evt;
00080     }
00081     //........................................TERMINATION
00082     // write out some information from Pythia to the screen
00083     call_pystat( 1 );    
00084     //........................................PRINT RESULTS
00085     std::cout << num_good_events << " out of " << icount 
00086               << " processed events passed the cuts. Finished." << std::endl;
00087     return 0;
00088 }
00089 
00090 
00091  

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