hepmc - Blame information for rev 280

Subversion Repositories:
Rev:
Rev Author Line No. Line
62 garren 1 //////////////////////////////////////////////////////////////////////////
65 garren 2 // garren@fnal.gov, January 2007
62 garren 3 // This example is an extension of example_MyPythia.cc
4 //  
5 // generate events with Pythia, write a file, and read the resulting output
6 // Notice that we use scope to explicitly close the ouput files.
7 // The two output files should be the same size, but because particles are
8 // saved as sets within a vertex, they will be written in arbitrary order.
9 //////////////////////////////////////////////////////////////////////////
10 // To Compile: go to the HepMC directory and type:
11 // gmake examples/example_MyPythiaRead.exe
12 //
13 // In this example the precision and number of entries for the HEPEVT
14 // fortran common block are explicitly defined to correspond to those
15 // used in the Pythia version of the HEPEVT common block.
16 //
17 // If you get funny output from HEPEVT in your own code, probably you have
18 // set these values incorrectly!
19 //
20  
21 #include <iostream>
22 #include "HepMC/PythiaWrapper.h"
23 #include "HepMC/IO_HEPEVT.h"
129 garren 24 #include "HepMC/IO_GenEvent.h"
62 garren 25 #include "HepMC/GenEvent.h"
76 garren 26 #include "PythiaHelper.h"
27  
62 garren 28 int main() {
29     //
30     //........................................HEPEVT
31     // Pythia 6.3 uses HEPEVT with 4000 entries and 8-byte floating point
32     //  numbers. We need to explicitly pass this information to the
33     //  HEPEVT_Wrapper.
34     //
35     HepMC::HEPEVT_Wrapper::set_max_number_entries(4000);
36     HepMC::HEPEVT_Wrapper::set_sizeof_real(8);
37     //
38     //........................................PYTHIA INITIALIZATIONS
76 garren 39     initPythia();
62 garren 40  
41     //........................................HepMC INITIALIZATIONS
42     //
43     // Instantiate an IO strategy for reading from HEPEVT.
44     HepMC::IO_HEPEVT hepevtio;
45     //
46     //........................................define the output scope
47     {
48         // Instantial an IO strategy to write the data to file - it uses the
49         //  same ParticleDataTable
129 garren 50         HepMC::IO_GenEvent ascii_io("example_MyPythiaRead.dat",std::ios::out);
62 garren 51         //
52         //........................................EVENT LOOP
53         for ( int i = 1; i <= 100; i++ ) {
54             if ( i%50==1 ) std::cout << "Processing Event Number "
55                                      << i << std::endl;
56             call_pyevnt();      // generate one event with Pythia
57             // pythia pyhepc routine converts common PYJETS in common HEPEVT
58             call_pyhepc( 1 );
59             HepMC::GenEvent* evt = hepevtio.read_next_event();
280 garren 60             // pythia uses GeV and mm
61             evt->set_units( HepMC::MomentumUnits::GeV, HepMC::PositionUnits::mm);
62 garren 62             // add some information to the event
63             evt->set_event_number(i);
64             evt->set_signal_process_id(20);
65             // write the event out to the ascii file
66             ascii_io << evt;
67             // we also need to delete the created event from memory
68             delete evt;
69         }
70         //........................................TERMINATION
71         // write out some information from Pythia to the screen
72         call_pystat( 1 );    
73     }  // ascii_io destructor is called here
74     //
75     //........................................define an input scope
76     {
77         // now read the file we wrote
129 garren 78         HepMC::IO_GenEvent ascii_in("example_MyPythiaRead.dat",std::ios::in);
79         HepMC::IO_GenEvent ascii_io2("example_MyPythiaRead2.dat",std::ios::out);
62 garren 80         int icount=0;
81         HepMC::GenEvent* evt = ascii_in.read_next_event();
82         while ( evt ) {
83             icount++;
84             if ( icount%50==1 ) std::cout << "Processing Event Number " << icount
85                                           << " its # " << evt->event_number()
86                                           << std::endl;
87             // write the event out to the ascii file
88             ascii_io2 << evt;
89             delete evt;
90             ascii_in >> evt;
91         }
92         //........................................PRINT RESULT
93         std::cout << icount << " events found. Finished." << std::endl;
94     } // ascii_io2 and ascii_in destructors are called here
95  
96     return 0;
97 }
98  
99  
100