hepmc - Blame information for rev 236
Subversion Repositories:
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 17 | garren | 1 | ////////////////////////////////////////////////////////////////////////// |
| 2 | // testHepMC.cc.in | ||
| 3 | // | ||
| 4 | // garren@fnal.gov, March 2006 | ||
| 128 | garren | 5 | // based on example_EventSelection |
| 17 | garren | 6 | // Apply an event selection to the events in testHepMC.input |
| 7 | // Events containing a photon of pT > 25 GeV pass the selection and are | ||
| 8 | // written to "testHepMC.out" | ||
| 88 | garren | 9 | // Add arbitrary PDF information to the good events |
| 128 | garren | 10 | // Also write events using IO_AsciiParticles |
| 17 | garren | 11 | ////////////////////////////////////////////////////////////////////////// |
| 12 | // | ||
| 13 | |||
| 195 | garren | 14 | #include "HepMC/GenEvent.h" |
| 128 | garren | 15 | #include "HepMC/IO_GenEvent.h" |
| 195 | garren | 16 | #include "HepMC/IO_Ascii.h" |
| 35 | garren | 17 | #include "HepMC/IO_AsciiParticles.h" |
| 17 | garren | 18 | |
| 88 | garren | 19 | // define methods and classes used by this test |
| 20 | #include "IsGoodEvent.h" | ||
| 85 | garren | 21 | |
| 194 | garren | 22 | void read_testIOGenEvent(); |
| 23 | void read_testAscii(); | ||
| 24 | void read_testExtendedAscii(); | ||
| 197 | garren | 25 | void read_various(); |
| 194 | garren | 26 | |
| 17 | garren | 27 | int main() { |
| 194 | garren | 28 | read_testIOGenEvent(); |
| 29 | read_testAscii(); | ||
| 30 | read_testExtendedAscii(); | ||
| 197 | garren | 31 | read_various(); |
| 194 | garren | 32 | return 0; |
| 33 | } | ||
| 34 | |||
| 35 | void read_testIOGenEvent() | ||
| 36 | { | ||
| 17 | garren | 37 | // declare an input strategy to read the data produced with the |
| 38 | // example_MyPythia | ||
| 128 | garren | 39 | HepMC::IO_GenEvent ascii_in("@srcdir@/testIOGenEvent.input",std::ios::in); |
| 40 | // declare another IO_GenEvent for writing out the good events | ||
| 41 | HepMC::IO_GenEvent ascii_out("testHepMC.out",std::ios::out); | ||
| 35 | garren | 42 | // declare an IO_AsciiParticle for output |
| 43 | HepMC::IO_AsciiParticles particle_out("testHepMCParticle.out",std::ios::out); | ||
| 17 | garren | 44 | // declare an instance of the event selection predicate |
| 45 | IsGoodEvent is_good_event; | ||
| 46 | //........................................EVENT LOOP | ||
| 47 | int icount=0; | ||
| 48 | int num_good_events=0; | ||
| 49 | HepMC::GenEvent* evt = ascii_in.read_next_event(); | ||
| 50 | while ( evt ) { | ||
| 51 | icount++; | ||
| 52 | if ( icount%50==1 ) std::cout << "Processing Event Number " << icount | ||
| 53 | << " its # " << evt->event_number() | ||
| 54 | << std::endl; | ||
| 55 | if ( is_good_event(evt) ) { | ||
| 56 | ascii_out << evt; | ||
| 35 | garren | 57 | particle_out << evt; |
| 17 | garren | 58 | ++num_good_events; |
| 59 | } | ||
| 85 | garren | 60 | |
| 61 | // clean up and get next event | ||
| 17 | garren | 62 | delete evt; |
| 63 | ascii_in >> evt; | ||
| 64 | } | ||
| 65 | //........................................PRINT RESULT | ||
| 66 | std::cout << num_good_events << " out of " << icount | ||
| 67 | << " processed events passed the cuts. Finished." << std::endl; | ||
| 68 | } | ||
| 194 | garren | 69 | |
| 70 | void read_testAscii() | ||
| 71 | { | ||
| 72 | // declare an input strategy to read the data produced with the | ||
| 73 | // example_MyPythia | ||
| 74 | HepMC::IO_GenEvent ascii_in("@srcdir@/testAscii.input",std::ios::in); | ||
| 200 | garren | 75 | if ( ascii_in.rdstate() == std::ios::failbit ) { |
| 76 | std::cerr << "ERROR input file @srcdir@/testAscii.input is needed " | ||
| 77 | << "and does not exist. Exit." << std::endl; | ||
| 78 | return; | ||
| 79 | } | ||
| 195 | garren | 80 | // use IO_Ascii because we are checking against the original input file |
| 81 | HepMC::IO_Ascii ascii_out("testIOAscii.dat",std::ios::out); | ||
| 200 | garren | 82 | if ( ascii_out.rdstate() == std::ios::failbit ) { |
| 83 | std::cerr << "ERROR opening output file testAscii.dat. Exit." | ||
| 84 | << std::endl; | ||
| 85 | return; | ||
| 86 | } | ||
| 194 | garren | 87 | //........................................EVENT LOOP |
| 88 | int icount=0; | ||
| 89 | HepMC::GenEvent* evt = ascii_in.read_next_event(); | ||
| 90 | while ( evt ) { | ||
| 91 | icount++; | ||
| 92 | if ( icount%50==1 ) std::cout << "Processing Event Number " << icount | ||
| 93 | << " its # " << evt->event_number() | ||
| 94 | << std::endl; | ||
| 95 | ascii_out << evt; | ||
| 96 | |||
| 97 | // clean up and get next event | ||
| 98 | delete evt; | ||
| 99 | ascii_in >> evt; | ||
| 100 | } | ||
| 101 | //........................................PRINT RESULT | ||
| 102 | std::cout << icount << " events processed. Finished." << std::endl; | ||
| 103 | } | ||
| 104 | |||
| 105 | void read_testExtendedAscii() | ||
| 106 | { | ||
| 107 | // extended (complete) output | ||
| 108 | HepMC::IO_GenEvent xin("@srcdir@/testHepMCExtended.input",std::ios::in); | ||
| 109 | // declare another IO_GenEvent for output | ||
| 110 | HepMC::IO_GenEvent xout("testIOHepMCExtended.dat",std::ios::out); | ||
| 111 | //........................................EVENT LOOP | ||
| 112 | int icount=0; | ||
| 113 | HepMC::GenEvent* evt = xin.read_next_event(); | ||
| 114 | while ( evt ) { | ||
| 115 | icount++; | ||
| 116 | if ( icount%50==1 ) std::cout << "Processing Event Number " << icount | ||
| 117 | << " its # " << evt->event_number() | ||
| 118 | << std::endl; | ||
| 119 | xout << evt; | ||
| 120 | |||
| 121 | // clean up and get next event | ||
| 122 | delete evt; | ||
| 123 | xin >> evt; | ||
| 124 | } | ||
| 125 | std::cout << icount << " events processed. Finished." << std::endl; | ||
| 126 | } | ||
| 197 | garren | 127 | |
| 128 | void read_various() | ||
| 129 | { | ||
| 130 | // declare an input strategy | ||
| 131 | HepMC::IO_GenEvent ascii_in("@srcdir@/testHepMCVarious.input",std::ios::in); | ||
| 132 | // declare another IO_GenEvent for writing out the good events | ||
| 133 | HepMC::IO_GenEvent ascii_out("testHepMCVarious.out",std::ios::out); | ||
| 134 | //........................................EVENT LOOP | ||
| 135 | int icount=0; | ||
| 136 | HepMC::GenEvent* evt = ascii_in.read_next_event(); | ||
| 137 | while ( evt ) { | ||
| 138 | icount++; | ||
| 139 | if ( icount%50==1 ) std::cout << "Processing Event Number " << icount | ||
| 140 | << " its # " << evt->event_number() | ||
| 141 | << std::endl; | ||
| 142 | ascii_out << evt; | ||
| 143 | // clean up and get next event | ||
| 144 | delete evt; | ||
| 145 | ascii_in >> evt; | ||
| 146 | } | ||
| 147 | //........................................PRINT RESULT | ||
| 148 | std::cout << icount << " events processed. Finished." << std::endl; | ||
| 149 | } |
