00001
00002
00003
00004
00005
00006
00008
00009 #include "HepMC/HEPEVT_Wrapper.h"
00010
00011 namespace HepMC {
00012
00014
00016
00017 unsigned int HEPEVT_Wrapper::s_sizeof_int = 4;
00018
00019 unsigned int HEPEVT_Wrapper::s_sizeof_real = sizeof(double);
00020
00021 unsigned int HEPEVT_Wrapper::s_max_number_entries = 4000;
00022
00024
00026
00027 void HEPEVT_Wrapper::print_hepevt( std::ostream& ostr )
00028 {
00030 ostr << "________________________________________"
00031 << "________________________________________" << std::endl;
00032 ostr << "***** HEPEVT Common Event#: "
00033 << event_number()
00034 << ", " << number_entries() << " particles (max "
00035 << max_number_entries() << ") *****";
00036 if ( is_double_precision() ) {
00037 ostr << " Double Precision" << std::endl;
00038 } else {
00039 ostr << " Single Precision" << std::endl;
00040 }
00041 ostr << sizeof_int() << "-byte integers, "
00042 << sizeof_real() << "-byte floating point numbers, "
00043 << max_number_entries() << "-allocated entries."
00044 << std::endl;
00045 print_legend(ostr);
00046 ostr << "________________________________________"
00047 << "________________________________________" << std::endl;
00048 for ( int i=1; i <= number_entries(); ++i ) {
00049 print_hepevt_particle( i, ostr );
00050 }
00051 ostr << "________________________________________"
00052 << "________________________________________" << std::endl;
00053 }
00054
00055 void HEPEVT_Wrapper::print_legend( std::ostream& ostr )
00056 {
00057 char outline[81];
00058 sprintf( outline,"%4s %4s %4s %5s %10s, %9s, %9s, %9s, %10s",
00059 "Indx","Stat","Par-","chil-",
00060 "( P_x","P_y","P_z","Energy","M ) ");
00061 ostr << outline << std::endl;
00062 sprintf( outline,"%9s %4s %4s %10s, %9s, %9s, %9s) %9s",
00063 "ID ","ents","dren",
00064 "Prod ( X","Y","Z","cT", "[mm]");
00065 ostr << outline << std::endl;
00066 }
00067
00068 void HEPEVT_Wrapper::print_hepevt_particle( int i, std::ostream& ostr )
00069 {
00074 char outline[81];
00075 sprintf( outline,
00076 "%4d %+4d %4d %4d (%9.3g, %9.3g, %9.3g, %9.3g, %9.3g)"
00077 ,i, status(i), first_parent(i), first_child(i),
00078 px(i), py(i), pz(i), e(i), m(i) );
00079 ostr << outline << "\n";
00080 sprintf( outline,"%+9d %4d %4d (%9.3g, %9.3g, %9.3g, %9.3g)",
00081
00082 id(i), last_parent(i), last_child(i),
00083 x(i), y(i), z(i), t(i) );
00084 ostr << outline << std::endl;
00085 }
00086
00087
00088 bool HEPEVT_Wrapper::check_hepevt_consistency( std::ostream& os )
00089 {
00092 bool isConsistent=true;
00093 char header[81];
00094 sprintf( header,
00095 "\n\n\t**** WARNINGInconsistent HEPEVT input, Event %10d ****"
00096 , HEPEVT_Wrapper::event_number() );
00097
00098 for ( int i = 1; i <= HEPEVT_Wrapper::number_entries(); ++i ) {
00099
00100 int moth1 = HEPEVT_Wrapper::first_parent( i );
00101 int moth2 = HEPEVT_Wrapper::last_parent( i );
00102 if ( moth2<moth1 ) {
00103 if ( isConsistent ) {
00104 os << header << std::endl;
00105 isConsistent = false;
00106 print_legend(os);
00107 }
00108 os << "Inconsistent entry " << i
00109 << " first parent > last parent " << std::endl;
00110 HEPEVT_Wrapper::print_hepevt_particle( i, os );
00111 }
00112 for ( int m = moth1; m<=moth2 && m!=0; ++m ) {
00113 if ( m>HEPEVT_Wrapper::number_entries() || m < 0 ) {
00114 if ( isConsistent ) {
00115 os << header << std::endl;
00116 isConsistent = false;
00117 print_legend(os);
00118 }
00119 os << "Inconsistent entry " << i
00120 << " mother points out of range " << std::endl;
00121 HEPEVT_Wrapper::print_hepevt_particle( i, os );
00122 }
00123 int mChild1 = HEPEVT_Wrapper::first_child(m);
00124 int mChild2 = HEPEVT_Wrapper::last_child(m);
00125
00126 if ( mChild1==0 && mChild2==0 ) continue;
00127 if ( i<mChild1 || i>mChild2 ) {
00128 if ( isConsistent ) {
00129 os << header << std::endl;
00130 isConsistent = false;
00131 print_legend(os);
00132 }
00133 os << "Inconsistent mother-daughter relationship between "
00134 << i << " & " << m
00135 << " (try !trust_mother)" << std::endl;
00136 HEPEVT_Wrapper::print_hepevt_particle( i, os );
00137 HEPEVT_Wrapper::print_hepevt_particle( m, os );
00138 }
00139 }
00140
00141 int dau1 = HEPEVT_Wrapper::first_child( i );
00142 int dau2 = HEPEVT_Wrapper::last_child( i );
00143 if ( dau2<dau1 ) {
00144 if ( isConsistent ) {
00145 os << header << std::endl;
00146 isConsistent = false;
00147 print_legend(os);
00148 }
00149 os << "Inconsistent entry " << i
00150 << " first child > last child " << std::endl;
00151 HEPEVT_Wrapper::print_hepevt_particle( i, os );
00152 }
00153 for ( int d = dau1; d<=dau2 && d!=0; ++d ) {
00154 if ( d>HEPEVT_Wrapper::number_entries() || d < 0 ) {
00155 if ( isConsistent ) {
00156 os << header << std::endl;
00157 isConsistent = false;
00158 print_legend(os);
00159 }
00160 os << "Inconsistent entry " << i
00161 << " child points out of range " << std::endl;
00162 HEPEVT_Wrapper::print_hepevt_particle( i, os );
00163 }
00164 int d_moth1 = HEPEVT_Wrapper::first_parent(d);
00165 int d_moth2 = HEPEVT_Wrapper::last_parent(d);
00166
00167 if ( d_moth1==0 && d_moth2==0 ) continue;
00168 if ( i<d_moth1 || i>d_moth2 ) {
00169 if ( isConsistent ) {
00170 os << header << std::endl;
00171 isConsistent = false;
00172 print_legend(os);
00173 }
00174 os << "Inconsistent mother-daughter relationship between "
00175 << i << " & " << d
00176 << " (try trust_mothers)"<< std::endl;
00177 HEPEVT_Wrapper::print_hepevt_particle( i, os );
00178 HEPEVT_Wrapper::print_hepevt_particle( d, os );
00179 }
00180 }
00181 }
00182 if (!isConsistent) {
00183 os << "Above lists all the inconsistencies in the HEPEVT common "
00184 << "\n block which has been provided as input to HepMC. "
00185 << "\n HepMC WILL have trouble interpreting the mother-daughter"
00186 << "\n relationships ... but all other information "
00187 << "\n (4-vectors etc) will be correctly transferred."
00188 << "\n In order for HepMC to be able to interpret the mother/"
00189 << "\n daughter hierachy, it MUST be given consistent input."
00190 << "\n This is one of the design criteria of HepMC: "
00191 << "\n consistency is enforced by the code.";
00192 os << "\nThere is a switch in IO_HEPEVT, set-able using "
00193 << "\n IO_HEPEVT::set_trust_mothers_before_daughters( bool )"
00194 << "\n which you may want to try.";
00195 os << "\nNote: if HEPEVT common block has been filled by pythia"
00196 << "\n pyhepc, then the switch MSTP(128)=2 should be used in"
00197 << "\n pythia, which instructs pythia not to put multiple "
00198 << "\n copies of resonances in the event record.\n";
00199 os << "To obtain a file summarizing the inconsistency, you should:"
00200 << "\n\t ofstream myFile(\"myInconsistentEvent.txt\"); "
00201 << "\n\t HEPEVT_Wrapper::check_hepevt_consistency(myFile); "
00202 << "\n\t HEPEVT_Wrapper::print_hepevt(myFile); "
00203 << "\n[now write the event to HepMC using something like"
00204 << "\n\t\t myIO_HEPEVT->write_event(myEvent); ]"
00205 << "\n\t myEvent->print( myFile ); "
00206 << " // print event as HepMC sees it"
00207 << "\n ------------------------- Thank-you. \n\n" << std::endl;
00208 }
00209 return isConsistent;
00210 }
00211
00212 void HEPEVT_Wrapper::zero_everything()
00213 {
00214 set_event_number( 0 );
00215 set_number_entries( 0 );
00216 for ( int i = 1; i<=max_number_entries(); ++i ) {
00217 set_status( i, 0 );
00218 set_id( i, 0 );
00219 set_parents( i, 0, 0 );
00220 set_children( i, 0, 0 );
00221 set_momentum( i, 0, 0, 0, 0 );
00222 set_mass( i, 0 );
00223 set_position( i, 0, 0, 0, 0 );
00224 }
00225 }
00226
00227 }
00228