StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
HEPEVT_Wrapper.cc
1 // Matt.Dobbs@Cern.CH June 30, 2000
3 // Generic Wrapper for the fortran HEPEVT common block
4 //
5 // The static data member's initializations must be separate from .h file.
6 //
8 
9 #include "HepMC/HEPEVT_Wrapper.h"
10 
11 namespace HepMC {
12 
14  // static data member initializations //
16 
17  unsigned int HEPEVT_Wrapper::s_sizeof_int = 4;
18 
19  unsigned int HEPEVT_Wrapper::s_sizeof_real = sizeof(double);
20 
21  unsigned int HEPEVT_Wrapper::s_max_number_entries = 4000;
22 
24  // Print Methods //
26 
27  void HEPEVT_Wrapper::print_hepevt( std::ostream& ostr )
28  {
30  ostr << "________________________________________"
31  << "________________________________________" << std::endl;
32  ostr << "***** HEPEVT Common Event#: "
33  << event_number()
34  << ", " << number_entries() << " particles (max "
35  << max_number_entries() << ") *****";
36  if ( is_double_precision() ) {
37  ostr << " Double Precision" << std::endl;
38  } else {
39  ostr << " Single Precision" << std::endl;
40  }
41  ostr << sizeof_int() << "-byte integers, "
42  << sizeof_real() << "-byte floating point numbers, "
43  << max_number_entries() << "-allocated entries."
44  << std::endl;
45  print_legend(ostr);
46  ostr << "________________________________________"
47  << "________________________________________" << std::endl;
48  for ( int i=1; i <= number_entries(); ++i ) {
49  print_hepevt_particle( i, ostr );
50  }
51  ostr << "________________________________________"
52  << "________________________________________" << std::endl;
53  }
54 
55  void HEPEVT_Wrapper::print_legend( std::ostream& ostr )
56  {
57  char outline[81];
58  sprintf( outline,"%4s %4s %4s %5s %10s, %9s, %9s, %9s, %10s",
59  "Indx","Stat","Par-","chil-",
60  "( P_x","P_y","P_z","Energy","M ) ");
61  ostr << outline << std::endl;
62  sprintf( outline,"%9s %4s %4s %10s, %9s, %9s, %9s) %9s",
63  "ID ","ents","dren",
64  "Prod ( X","Y","Z","cT", "[mm]");
65  ostr << outline << std::endl;
66  }
67 
68  void HEPEVT_Wrapper::print_hepevt_particle( int i, std::ostream& ostr )
69  {
74  char outline[81];
75  sprintf( outline,
76  "%4d %+4d %4d %4d (%9.3g, %9.3g, %9.3g, %9.3g, %9.3g)"
77  ,i, status(i), first_parent(i), first_child(i),
78  px(i), py(i), pz(i), e(i), m(i) );
79  ostr << outline << "\n";
80  sprintf( outline,"%+9d %4d %4d (%9.3g, %9.3g, %9.3g, %9.3g)",
81  // old version was:" (%+9.2e, %+9.2e, %+9.2e, %+9.2e)"
82  id(i), last_parent(i), last_child(i),
83  x(i), y(i), z(i), t(i) );
84  ostr << outline << std::endl;
85  }
86 
87 
89  {
92  bool isConsistent=true;
93  char header[81];
94  sprintf( header,
95  "\n\n\t**** WARNINGInconsistent HEPEVT input, Event %10d ****"
97 
98  for ( int i = 1; i <= HEPEVT_Wrapper::number_entries(); ++i ) {
99  // 1. check its mothers
100  int moth1 = HEPEVT_Wrapper::first_parent( i );
101  int moth2 = HEPEVT_Wrapper::last_parent( i );
102  if ( moth2<moth1 ) {
103  if ( isConsistent ) {
104  os << header << std::endl;
105  isConsistent = false;
106  print_legend(os);
107  }
108  os << "Inconsistent entry " << i
109  << " first parent > last parent " << std::endl;
111  }
112  for ( int m = moth1; m<=moth2 && m!=0; ++m ) {
113  if ( m>HEPEVT_Wrapper::number_entries() || m < 0 ) {
114  if ( isConsistent ) {
115  os << header << std::endl;
116  isConsistent = false;
117  print_legend(os);
118  }
119  os << "Inconsistent entry " << i
120  << " mother points out of range " << std::endl;
122  }
123  int mChild1 = HEPEVT_Wrapper::first_child(m);
124  int mChild2 = HEPEVT_Wrapper::last_child(m);
125  // we don't consider null pointers as inconsistent
126  if ( mChild1==0 && mChild2==0 ) continue;
127  if ( i<mChild1 || i>mChild2 ) {
128  if ( isConsistent ) {
129  os << header << std::endl;
130  isConsistent = false;
131  print_legend(os);
132  }
133  os << "Inconsistent mother-daughter relationship between "
134  << i << " & " << m
135  << " (try !trust_mother)" << std::endl;
138  }
139  }
140  // 2. check its daughters
141  int dau1 = HEPEVT_Wrapper::first_child( i );
142  int dau2 = HEPEVT_Wrapper::last_child( i );
143  if ( dau2<dau1 ) {
144  if ( isConsistent ) {
145  os << header << std::endl;
146  isConsistent = false;
147  print_legend(os);
148  }
149  os << "Inconsistent entry " << i
150  << " first child > last child " << std::endl;
152  }
153  for ( int d = dau1; d<=dau2 && d!=0; ++d ) {
154  if ( d>HEPEVT_Wrapper::number_entries() || d < 0 ) {
155  if ( isConsistent ) {
156  os << header << std::endl;
157  isConsistent = false;
158  print_legend(os);
159  }
160  os << "Inconsistent entry " << i
161  << " child points out of range " << std::endl;
163  }
164  int d_moth1 = HEPEVT_Wrapper::first_parent(d);
165  int d_moth2 = HEPEVT_Wrapper::last_parent(d);
166  // we don't consider null pointers as inconsistent
167  if ( d_moth1==0 && d_moth2==0 ) continue;
168  if ( i<d_moth1 || i>d_moth2 ) {
169  if ( isConsistent ) {
170  os << header << std::endl;
171  isConsistent = false;
172  print_legend(os);
173  }
174  os << "Inconsistent mother-daughter relationship between "
175  << i << " & " << d
176  << " (try trust_mothers)"<< std::endl;
179  }
180  }
181  }
182  if (!isConsistent) {
183  os << "Above lists all the inconsistencies in the HEPEVT common "
184  << "\n block which has been provided as input to HepMC. "
185  << "\n HepMC WILL have trouble interpreting the mother-daughter"
186  << "\n relationships ... but all other information "
187  << "\n (4-vectors etc) will be correctly transferred."
188  << "\n In order for HepMC to be able to interpret the mother/"
189  << "\n daughter hierachy, it MUST be given consistent input."
190  << "\n This is one of the design criteria of HepMC: "
191  << "\n consistency is enforced by the code.";
192  os << "\nThere is a switch in IO_HEPEVT, set-able using "
193  << "\n IO_HEPEVT::set_trust_mothers_before_daughters( bool )"
194  << "\n which you may want to try.";
195  os << "\nNote: if HEPEVT common block has been filled by pythia"
196  << "\n pyhepc, then the switch MSTP(128)=2 should be used in"
197  << "\n pythia, which instructs pythia not to put multiple "
198  << "\n copies of resonances in the event record.\n";
199  os << "To obtain a file summarizing the inconsistency, you should:"
200  << "\n\t ofstream myFile(\"myInconsistentEvent.txt\"); "
201  << "\n\t HEPEVT_Wrapper::check_hepevt_consistency(myFile); "
202  << "\n\t HEPEVT_Wrapper::print_hepevt(myFile); "
203  << "\n[now write the event to HepMC using something like"
204  << "\n\t\t myIO_HEPEVT->write_event(myEvent); ]"
205  << "\n\t myEvent->print( myFile ); "
206  << " // print event as HepMC sees it"
207  << "\n ------------------------- Thank-you. \n\n" << std::endl;
208  }
209  return isConsistent;
210  }
211 
213  {
214  set_event_number( 0 );
215  set_number_entries( 0 );
216  for ( int i = 1; i<=max_number_entries(); ++i ) {
217  set_status( i, 0 );
218  set_id( i, 0 );
219  set_parents( i, 0, 0 );
220  set_children( i, 0, 0 );
221  set_momentum( i, 0, 0, 0, 0 );
222  set_mass( i, 0 );
223  set_position( i, 0, 0, 0, 0 );
224  }
225  }
226 
227 } // HepMC
228 
static void set_children(int index, int firstchild, int lastchild)
define children of a particle
static double y(int index)
Y Production vertex.
static void set_mass(int index, double mass)
set particle mass
static double z(int index)
Z Production vertex.
static int status(int index)
status code
static void set_number_entries(int noentries)
set number of entries in HEPEVT
static int first_parent(int index)
index of 1st mother
static void print_hepevt(std::ostream &ostr=std::cout)
write information from HEPEVT common block
static double x(int index)
X Production vertex.
static int event_number()
event number
static void set_momentum(int index, double px, double py, double pz, double e)
set particle momentum
static void print_hepevt_particle(int index, std::ostream &ostr=std::cout)
write particle information to ostr
static double e(int index)
Energy.
static unsigned int sizeof_int()
size of integer in bytes
static int last_parent(int index)
index of last mother
static void print_legend(std::ostream &ostr=std::cout)
print output legend
static unsigned int sizeof_real()
size of real in bytes
static double px(int index)
X momentum.
static bool check_hepevt_consistency(std::ostream &ostr=std::cout)
check for problems with HEPEVT common block
static double t(int index)
production time
static int last_child(int index)
index of last daughter
static void set_parents(int index, int firstparent, int lastparent)
define parents of a particle
static void set_status(int index, int status)
set particle status
static int number_entries()
num entries in current evt
static int first_child(int index)
index of 1st daughter
static double py(int index)
Y momentum.
static double pz(int index)
Z momentum.
static void set_event_number(int evtno)
set event number
static bool is_double_precision()
True if common block uses double.
static void zero_everything()
set all entries in HEPEVT to zero
static int max_number_entries()
size of common block
static void set_id(int index, int id)
set particle ID
static double m(int index)
generated mass
static void set_position(int index, double x, double y, double z, double t)
set particle production vertex