StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
example_EventSelection.cc
1 // 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"
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 
16 
20 class IsEventGood {
21 public:
23  bool operator()( const HepMC::GenEvent* evt ) {
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 
example class
const particle iterator
Definition: GenEvent.h:464
particle_const_iterator particles_begin() const
begin particle iteration
Definition: GenEvent.h:507
The GenEvent class is the core of HepMC.
Definition: GenEvent.h:155
IO_GenEvent also deals with HeavyIon and PdfInfo.
Definition: IO_GenEvent.h:63
bool operator()(const HepMC::GenEvent *evt)
check this event for goodness
particle_const_iterator particles_end() const
end particle iteration
Definition: GenEvent.h:511
int event_number() const
event number
Definition: GenEvent.h:682