1 | ////////////////////////////////////////////////////////////////////////// |
---|
2 | // Matt.Dobbs@Cern.CH, Feb 2000 |
---|
3 | // Example of applying an event selection to the events written to file |
---|
4 | // using example_MyPythia.cxx |
---|
5 | // Events containing a photon of pT > 25 GeV pass the selection and are |
---|
6 | // written to "example_EventSelection.dat" |
---|
7 | ////////////////////////////////////////////////////////////////////////// |
---|
8 | // To Compile: go to the HepMC directory and type: |
---|
9 | // gmake examples/example_EventSelection.exe |
---|
10 | // |
---|
11 | |
---|
12 | #include "HepMC/IO_GenEvent.h" |
---|
13 | #include "HepMC/GenEvent.h" |
---|
14 | |
---|
15 | //! example class |
---|
16 | |
---|
17 | /// \class IsEventGood |
---|
18 | /// event selection predicate. returns true if the event contains |
---|
19 | /// a photon with pT > 50 GeV |
---|
20 | class IsEventGood { |
---|
21 | public: |
---|
22 | /// check this event for goodness |
---|
23 | bool operator()( const HepMC::GenEvent* evt ) { |
---|
24 | for ( HepMC::GenEvent::particle_const_iterator p |
---|
25 | = evt->particles_begin(); p != evt->particles_end(); ++p ){ |
---|
26 | if ( (*p)->pdg_id() == 22 && (*p)->momentum().perp() > 25. ) { |
---|
27 | //std::cout << "Event " << evt->event_number() |
---|
28 | // << " is a good event." << std::endl; |
---|
29 | //(*p)->print(); |
---|
30 | return 1; |
---|
31 | } |
---|
32 | } |
---|
33 | return 0; |
---|
34 | } |
---|
35 | }; |
---|
36 | |
---|
37 | int main() { |
---|
38 | // declare an input strategy to read the data produced with the |
---|
39 | // example_MyPythia |
---|
40 | { // begin scope of ascii_in and ascii_out |
---|
41 | HepMC::IO_GenEvent ascii_in("example_MyPythia.dat",std::ios::in); |
---|
42 | // declare another IO_GenEvent for writing out the good events |
---|
43 | HepMC::IO_GenEvent ascii_out("example_EventSelection.dat",std::ios::out); |
---|
44 | // declare an instance of the event selection predicate |
---|
45 | IsEventGood 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; |
---|
57 | ++num_good_events; |
---|
58 | } |
---|
59 | delete evt; |
---|
60 | ascii_in >> evt; |
---|
61 | } |
---|
62 | //........................................PRINT RESULT |
---|
63 | std::cout << num_good_events << " out of " << icount |
---|
64 | << " processed events passed the cuts. Finished." << std::endl; |
---|
65 | } // end scope of ascii_in and ascii_out |
---|
66 | return 0; |
---|
67 | } |
---|
68 | |
---|
69 | |
---|
70 | |
---|
71 | |
---|
72 | |
---|
73 | |
---|
74 | |
---|
75 | |
---|
76 | |
---|
77 | |
---|