Subversion Repositories hepmc

Rev

Rev 76 | Details | Compare with Previous | Last modification | View Log | RSS feed

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();
60
            // add some information to the event
61
            evt->set_event_number(i);
62
            evt->set_signal_process_id(20);
63
            // write the event out to the ascii file
64
            ascii_io << evt;
65
            // we also need to delete the created event from memory
66
            delete evt;
67
        }
68
        //........................................TERMINATION
69
        // write out some information from Pythia to the screen
70
        call_pystat( 1 );    
71
    }  // ascii_io destructor is called here
72
    //
73
    //........................................define an input scope
74
    {
75
        // now read the file we wrote
129 garren 76
        HepMC::IO_GenEvent ascii_in("example_MyPythiaRead.dat",std::ios::in);
77
        HepMC::IO_GenEvent ascii_io2("example_MyPythiaRead2.dat",std::ios::out);
62 garren 78
        int icount=0;
79
        HepMC::GenEvent* evt = ascii_in.read_next_event();
80
        while ( evt ) {
81
            icount++;
82
            if ( icount%50==1 ) std::cout << "Processing Event Number " << icount
83
                                          << " its # " << evt->event_number()
84
                                          << std::endl;
85
            // write the event out to the ascii file
86
            ascii_io2 << evt;
87
            delete evt;
88
            ascii_in >> evt;
89
        }
90
        //........................................PRINT RESULT
91
        std::cout << icount << " events found. Finished." << std::endl;
92
    } // ascii_io2 and ascii_in destructors are called here
93
 
94
    return 0;
95
}
96
 
97
 
98