StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
testHepMCMethods.cc
1 // testHepMCMethods.cc
3 //
4 // garren@fnal.gov, March 2009
5 //
6 // various methods used by the test jobs
8 
9 #include "testHepMCMethods.h"
10 
11 double findPiZero( HepMC::GenEvent * evt )
12 {
14  = evt->particles_begin(); p != evt->particles_end(); ++p ){
15  if ( (*p)->pdg_id() == 111 ) {
16  return (*p)->generated_mass();
17  }
18  }
19  return 0.;
20 }
21 
22 void particleTypes( HepMC::GenEvent * evt, std::ostream & os )
23 {
24  int numDecayed = 0, numUndecayed = 0, numBeam = 0;
25  int numDecayed2 = 0, numUndecayed2 = 0, numBeam2 = 0;
27  = evt->particles_begin(); p != evt->particles_end(); ++p ){
28  if ( (*p)->is_undecayed() ) {
29  ++numUndecayed;
30  }
31  if ( (*p)->has_decayed() ) {
32  ++numDecayed;
33  }
34  if ( (*p)->is_beam() ) {
35  ++numBeam;
36  }
37  if ( (*p)->status() == 1 ) {
38  ++numUndecayed2;
39  }
40  if ( (*p)->status() == 2 ) {
41  ++numDecayed2;
42  }
43  if ( (*p)->status() == 4 ) {
44  ++numBeam2;
45  }
46  }
47  if( numUndecayed != numUndecayed2 ) {
48  std::cerr << "ERROR: incorrect count of undecayed particles: "
49  << numUndecayed << " does not match "
50  << numUndecayed2 << std::endl;
51  }
52  if( numDecayed != numDecayed2 ) {
53  std::cerr << "ERROR: incorrect count of undecayed particles: "
54  << numDecayed << " does not match "
55  << numDecayed2 << std::endl;
56  }
57  if( numBeam != numBeam2 ) {
58  std::cerr << "ERROR: incorrect count of undecayed particles: "
59  << numBeam << " does not match "
60  << numBeam2 << std::endl;
61  }
62  int ndcy = numUndecayed + numDecayed;
63  if( ndcy > evt->particles_size() ) {
64  std::cerr << "ERROR: count does not add up: "
65  << ndcy << " is greater than the number of particles in the event: "
66  << evt->particles_size() << std::endl;
67  }
68  os << "Event " << evt->event_number()
69  << " has " << evt->particles_size()
70  << " particles, " << numDecayed
71  << " decayed particles, " << numUndecayed
72  << " undecayed particles, and " << numBeam
73  << " beam particles "
74  << std::endl;
75  return;
76 }
77 
78 void repairUnits(HepMC::GenEvent* evt,
79  HepMC::Units::MomentumUnit from,
80  HepMC::Units::MomentumUnit to )
81 {
82  //
83  const double factor = HepMC::Units::conversion_factor( from, to );
84  // multiply all momenta by 'factor',
85  // loop is entered only if particle list is not empty
87  p != evt->particles_end(); ++p )
88  {
89  HepMC::FourVector mom = (*p)->momentum();
90  double gm = (*p)->generatedMass();
91  (*p)->set_momentum( HepMC::FourVector( factor*mom.px(),
92  factor*mom.py(),
93  factor*mom.pz(),
94  factor*mom.e() ) );
95  if( gm > 0. ) (*p)->set_generated_mass( factor*gm );
96  }
97 }
const particle iterator
Definition: GenEvent.h:464
int particles_size() const
how many particle barcodes exist?
Definition: GenEvent.h:830
particle_const_iterator particles_begin() const
begin particle iteration
Definition: GenEvent.h:507
double e() const
return E
Definition: SimpleVector.h:73
non-const particle iterator
Definition: GenEvent.h:520
double px() const
return px
Definition: SimpleVector.h:70
The GenEvent class is the core of HepMC.
Definition: GenEvent.h:155
double pz() const
return pz
Definition: SimpleVector.h:72
particle_const_iterator particles_end() const
end particle iteration
Definition: GenEvent.h:511
FourVector is a simple representation of a physics 4 vector.
Definition: SimpleVector.h:42
int event_number() const
event number
Definition: GenEvent.h:682
double py() const
return py
Definition: SimpleVector.h:71