![]() |
HepMC Reference DocumentationHepMC |
00001 //-------------------------------------------------------------------------- 00002 00003 #ifndef HEPEVT_EntriesAllocation 00004 #define HEPEVT_EntriesAllocation 10000 00005 #endif // HEPEVT_EntriesAllocation 00006 00007 //-------------------------------------------------------------------------- 00008 #ifndef HEPMC_HEPEVT_COMMON_H 00009 #define HEPMC_HEPEVT_COMMON_H 00011 // 00012 // PARAMETER (NMXHEP=2000) 00013 // COMMON/HEPEVT/NEVHEP,NHEP,ISTHEP(NMXHEP),IDHEP(NMXHEP), 00014 // & JMOHEP(2,NMXHEP),JDAHEP(2,NMXHEP),PHEP(5,NMXHEP),VHEP(4,NMXHEP) 00015 /**********************************************************/ 00016 /* D E S C R I P T I O N : */ 00017 /*--------------------------------------------------------*/ 00018 /* NEVHEP - event number (or some special meaning*/ 00019 /* (see documentation for details) */ 00020 /* NHEP - actual number of entries in current */ 00021 /* event. */ 00022 /* ISTHEP[IHEP] - status code for IHEP'th entry - see */ 00023 /* documentation for details */ 00024 /* IDHEP [IHEP] - IHEP'th particle identifier according*/ 00025 /* to PDG. */ 00026 /* JMOHEP[IHEP][0] - pointer to position of 1st mother */ 00027 /* JMOHEP[IHEP][1] - pointer to position of 2nd mother */ 00028 /* JDAHEP[IHEP][0] - pointer to position of 1st daughter */ 00029 /* JDAHEP[IHEP][1] - pointer to position of 2nd daughter */ 00030 /* PHEP [IHEP][0] - X momentum */ 00031 /* PHEP [IHEP][1] - Y momentum */ 00032 /* PHEP [IHEP][2] - Z momentum */ 00033 /* PHEP [IHEP][3] - Energy */ 00034 /* PHEP [IHEP][4] - Mass */ 00035 /* VHEP [IHEP][0] - X vertex */ 00036 /* VHEP [IHEP][1] - Y vertex */ 00037 /* VHEP [IHEP][2] - Z vertex */ 00038 /* VHEP [IHEP][3] - production time */ 00039 /*========================================================*/ 00040 // Remember, array(1) is the first entry in a fortran array, array[0] is the 00041 // first entry in a C array. 00042 // 00043 // This interface to HEPEVT common block treats the block as 00044 // an array of bytes --- the precision and number of entries 00045 // is determined "on the fly" by the wrapper and used to decode 00046 // each entry. 00047 // 00048 // HEPEVT_EntriesAllocation is the maximum size of the HEPEVT common block 00049 // that can be interfaced. 00050 // It is NOT the actual size of the HEPEVT common used in each 00051 // individual application. The actual size can be changed on 00052 // the fly using HEPEVT_Wrapper::set_max_number_entries(). 00053 // Thus HEPEVT_EntriesAllocation should typically be set 00054 // to the maximum possible number of entries --- 10000 is a good choice 00055 // (and is the number used by ATLAS versions of Pythia). 00056 // 00057 // Note: a statement like *( (int*)&hepevt.data[0] ) 00058 // takes the memory address of the first byte in HEPEVT, 00059 // interprets it as an integer pointer, 00060 // and dereferences the pointer. 00061 // i.e. it returns an integer corresponding to nevhep 00062 // 00063 00064 #include <ctype.h> 00065 00066 const unsigned int hepevt_bytes_allocation = 00067 sizeof(long int) * ( 2 + 6 * HEPEVT_EntriesAllocation ) 00068 + sizeof(double) * ( 9 * HEPEVT_EntriesAllocation ); 00069 00070 00071 #ifdef _WIN32 // Platform: Windows MS Visual C++ 00072 struct HEPEVT_DEF{ 00073 char data[hepevt_bytes_allocation]; 00074 }; 00075 extern "C" HEPEVT_DEF HEPEVT; 00076 #define hepevt HEPEVT 00077 00078 #else 00079 extern "C" { 00080 extern struct { 00081 char data[hepevt_bytes_allocation]; 00082 } hepevt_; 00083 } 00084 #define hepevt hepevt_ 00085 00086 #endif // Platform 00087 00088 #endif // HEPMC_HEPEVT_COMMON_H 00089 00090 //-------------------------------------------------------------------------- 00091 #ifndef HEPMC_HEPEVT_WRAPPER_H 00092 #define HEPMC_HEPEVT_WRAPPER_H 00093 00095 // Matt.Dobbs@Cern.CH, April 24, 2000, refer to: 00096 // M. Dobbs and J.B. Hansen, "The HepMC C++ Monte Carlo Event Record for 00097 // High Energy Physics", Computer Physics Communications (to be published). 00098 // 00099 // Generic Wrapper for the fortran HEPEVT common block 00100 // This class is intended for static use only - it makes no sense to 00101 // instantiate it. 00102 // Updated: June 30, 2000 (static initialization moved to separate .cxx file) 00104 // 00105 // The index refers to the fortran style index: 00106 // i.e. index=1 refers to the first entry in the HEPEVT common block. 00107 // all indices must be >0 00108 // number_entries --> integer between 0 and max_number_entries() giving total 00109 // number of sequential particle indices 00110 // first_parent/child --> index of first mother/child if there is one, 00111 // zero otherwise 00112 // last_parent/child --> if number children is >1, address of last parent/child 00113 // if number of children is 1, same as first_parent/child 00114 // if there are no children, returns zero. 00115 // is_double_precision --> T or F depending if floating point variables 00116 // are 8 or 4 bytes 00117 // 00118 00119 #include <iostream> 00120 #include <cstdio> // needed for formatted output using sprintf 00121 00122 namespace HepMC { 00123 00125 00130 class HEPEVT_Wrapper { 00131 public: 00132 00134 static void print_hepevt( std::ostream& ostr = std::cout ); 00136 static void print_hepevt_particle( int index, 00137 std::ostream& ostr = std::cout ); 00138 static bool is_double_precision(); 00139 00141 static bool check_hepevt_consistency( std::ostream& ostr = std::cout ); 00142 00144 static void zero_everything(); 00145 00147 // Access Methods // 00149 static int event_number(); 00150 static int number_entries(); 00151 static int status( int index ); 00152 static int id( int index ); 00153 static int first_parent( int index ); 00154 static int last_parent( int index ); 00155 static int number_parents( int index ); 00156 static int first_child( int index ); 00157 static int last_child( int index ); 00158 static int number_children( int index ); 00159 static double px( int index ); 00160 static double py( int index ); 00161 static double pz( int index ); 00162 static double e( int index ); 00163 static double m( int index ); 00164 static double x( int index ); 00165 static double y( int index ); 00166 static double z( int index ); 00167 static double t( int index ); 00168 00170 // Set Methods // 00172 00174 static void set_event_number( int evtno ); 00176 static void set_number_entries( int noentries ); 00178 static void set_status( int index, int status ); 00180 static void set_id( int index, int id ); 00182 static void set_parents( int index, int firstparent, int lastparent ); 00184 static void set_children( int index, int firstchild, int lastchild ); 00186 static void set_momentum( int index, double px, double py, 00187 double pz, double e ); 00189 static void set_mass( int index, double mass ); 00191 static void set_position( int index, double x, double y, double z, 00192 double t ); 00194 // HEPEVT Floorplan // 00196 static unsigned int sizeof_int(); 00197 static unsigned int sizeof_real(); 00198 static int max_number_entries(); 00199 static void set_sizeof_int(unsigned int); 00200 static void set_sizeof_real(unsigned int); 00201 static void set_max_number_entries(unsigned int); 00202 00203 protected: 00205 static double byte_num_to_double( unsigned int ); 00207 static int byte_num_to_int( unsigned int ); 00209 static void write_byte_num( double, unsigned int ); 00211 static void write_byte_num( int, unsigned int ); 00213 static void print_legend( std::ostream& ostr = std::cout ); 00214 00215 private: 00216 static unsigned int s_sizeof_int; 00217 static unsigned int s_sizeof_real; 00218 static unsigned int s_max_number_entries; 00219 00220 }; 00221 00223 // HEPEVT Floorplan Inlines // 00225 inline unsigned int HEPEVT_Wrapper::sizeof_int(){ return s_sizeof_int; } 00226 00227 inline unsigned int HEPEVT_Wrapper::sizeof_real(){ return s_sizeof_real; } 00228 00229 inline int HEPEVT_Wrapper::max_number_entries() 00230 { return (int)s_max_number_entries; } 00231 00232 inline void HEPEVT_Wrapper::set_sizeof_int( unsigned int size ) 00233 { 00234 if ( size != sizeof(short int) && size != sizeof(long int) && size != sizeof(int) ) { 00235 std::cerr << "HepMC is not able to handle integers " 00236 << " of size other than 2 or 4." 00237 << " You requested: " << size << std::endl; 00238 } 00239 s_sizeof_int = size; 00240 } 00241 00242 inline void HEPEVT_Wrapper::set_sizeof_real( unsigned int size ) { 00243 if ( size != sizeof(float) && size != sizeof(double) ) { 00244 std::cerr << "HepMC is not able to handle floating point numbers" 00245 << " of size other than 4 or 8." 00246 << " You requested: " << size << std::endl; 00247 } 00248 s_sizeof_real = size; 00249 } 00250 00251 inline void HEPEVT_Wrapper::set_max_number_entries( unsigned int size ) { 00252 s_max_number_entries = size; 00253 } 00254 00255 inline double HEPEVT_Wrapper::byte_num_to_double( unsigned int b ) { 00256 if ( b >= hepevt_bytes_allocation ) std::cerr 00257 << "HEPEVT_Wrapper: requested hepevt data exceeds allocation" 00258 << std::endl; 00259 if ( s_sizeof_real == sizeof(float) ) { 00260 float* myfloat = (float*)&hepevt.data[b]; 00261 return (double)(*myfloat); 00262 } else if ( s_sizeof_real == sizeof(double) ) { 00263 double* mydouble = (double*)&hepevt.data[b]; 00264 return (*mydouble); 00265 } else { 00266 std::cerr 00267 << "HEPEVT_Wrapper: illegal floating point number length." 00268 << s_sizeof_real << std::endl; 00269 } 00270 return 0; 00271 } 00272 00273 inline int HEPEVT_Wrapper::byte_num_to_int( unsigned int b ) { 00274 if ( b >= hepevt_bytes_allocation ) std::cerr 00275 << "HEPEVT_Wrapper: requested hepevt data exceeds allocation" 00276 << std::endl; 00277 if ( s_sizeof_int == sizeof(short int) ) { 00278 short int* myshortint = (short int*)&hepevt.data[b]; 00279 return (int)(*myshortint); 00280 } else if ( s_sizeof_int == sizeof(long int) ) { 00281 long int* mylongint = (long int*)&hepevt.data[b]; 00282 return (*mylongint); 00283 // on some 64 bit machines, int, short, and long are all different 00284 } else if ( s_sizeof_int == sizeof(int) ) { 00285 int* myint = (int*)&hepevt.data[b]; 00286 return (*myint); 00287 } else { 00288 std::cerr 00289 << "HEPEVT_Wrapper: illegal integer number length." 00290 << s_sizeof_int << std::endl; 00291 } 00292 return 0; 00293 } 00294 00295 inline void HEPEVT_Wrapper::write_byte_num( double in, unsigned int b ) { 00296 if ( b >= hepevt_bytes_allocation ) std::cerr 00297 << "HEPEVT_Wrapper: requested hepevt data exceeds allocation" 00298 << std::endl; 00299 if ( s_sizeof_real == sizeof(float) ) { 00300 float* myfloat = (float*)&hepevt.data[b]; 00301 (*myfloat) = (float)in; 00302 } else if ( s_sizeof_real == sizeof(double) ) { 00303 double* mydouble = (double*)&hepevt.data[b]; 00304 (*mydouble) = (double)in; 00305 } else { 00306 std::cerr 00307 << "HEPEVT_Wrapper: illegal floating point number length." 00308 << s_sizeof_real << std::endl; 00309 } 00310 } 00311 00312 inline void HEPEVT_Wrapper::write_byte_num( int in, unsigned int b ) { 00313 if ( b >= hepevt_bytes_allocation ) std::cerr 00314 << "HEPEVT_Wrapper: requested hepevt data exceeds allocation" 00315 << std::endl; 00316 if ( s_sizeof_int == sizeof(short int) ) { 00317 short int* myshortint = (short int*)&hepevt.data[b]; 00318 (*myshortint) = (short int)in; 00319 } else if ( s_sizeof_int == sizeof(long int) ) { 00320 long int* mylongint = (long int*)&hepevt.data[b]; 00321 (*mylongint) = (int)in; 00322 // on some 64 bit machines, int, short, and long are all different 00323 } else if ( s_sizeof_int == sizeof(int) ) { 00324 int* myint = (int*)&hepevt.data[b]; 00325 (*myint) = (int)in; 00326 } else { 00327 std::cerr 00328 << "HEPEVT_Wrapper: illegal integer number length." 00329 << s_sizeof_int << std::endl; 00330 } 00331 } 00332 00334 // INLINES // 00336 00337 inline bool HEPEVT_Wrapper::is_double_precision() 00338 { 00339 // true if 8byte floating point numbers are used in the HepEVT common. 00340 return ( sizeof(double) == sizeof_real() ); 00341 } 00342 00343 inline int HEPEVT_Wrapper::event_number() 00344 { return byte_num_to_int(0); } 00345 00346 inline int HEPEVT_Wrapper::number_entries() 00347 { 00348 int nhep = byte_num_to_int( 1*sizeof_int() ); 00349 return ( nhep <= max_number_entries() ? 00350 nhep : max_number_entries() ); 00351 } 00352 00353 inline int HEPEVT_Wrapper::status( int index ) 00354 { return byte_num_to_int( (2+index-1) * sizeof_int() ); } 00355 00356 inline int HEPEVT_Wrapper::id( int index ) 00357 { 00358 return byte_num_to_int( (2+max_number_entries()+index-1) 00359 * sizeof_int() ); 00360 } 00361 00362 inline int HEPEVT_Wrapper::first_parent( int index ) 00363 { 00364 int parent = byte_num_to_int( (2+2*max_number_entries()+2*(index-1)) 00365 * sizeof_int() ); 00366 return ( parent > 0 && parent <= number_entries() ) ? 00367 parent : 0; 00368 } 00369 00370 inline int HEPEVT_Wrapper::last_parent( int index ) 00371 { 00372 // Returns the Index of the LAST parent in the HEPEVT record 00373 // for particle with Index index. 00374 // If there is only one parent, the last parent is forced to 00375 // be the same as the first parent. 00376 // If there are no parents for this particle, both the first_parent 00377 // and the last_parent with return 0. 00378 // Error checking is done to ensure the parent is always 00379 // within range ( 0 <= parent <= nhep ) 00380 // 00381 int firstparent = first_parent(index); 00382 int parent = byte_num_to_int( (2+2*max_number_entries()+2*(index-1)+1) 00383 * sizeof_int() ); 00384 return ( parent > firstparent && parent <= number_entries() ) 00385 ? parent : firstparent; 00386 } 00387 00388 inline int HEPEVT_Wrapper::number_parents( int index ) { 00389 int firstparent = first_parent(index); 00390 return ( firstparent>0 ) ? 00391 ( 1+last_parent(index)-firstparent ) : 0; 00392 } 00393 00394 inline int HEPEVT_Wrapper::first_child( int index ) 00395 { 00396 int child = byte_num_to_int( (2+4*max_number_entries()+2*(index-1)) 00397 * sizeof_int() ); 00398 return ( child > 0 && child <= number_entries() ) ? 00399 child : 0; 00400 } 00401 00402 inline int HEPEVT_Wrapper::last_child( int index ) 00403 { 00404 // Returns the Index of the LAST child in the HEPEVT record 00405 // for particle with Index index. 00406 // If there is only one child, the last child is forced to 00407 // be the same as the first child. 00408 // If there are no children for this particle, both the first_child 00409 // and the last_child with return 0. 00410 // Error checking is done to ensure the child is always 00411 // within range ( 0 <= parent <= nhep ) 00412 // 00413 int firstchild = first_child(index); 00414 int child = byte_num_to_int( (2+4*max_number_entries()+2*(index-1)+1) 00415 * sizeof_int() ); 00416 return ( child > firstchild && child <= number_entries() ) 00417 ? child : firstchild; 00418 } 00419 00420 inline int HEPEVT_Wrapper::number_children( int index ) 00421 { 00422 int firstchild = first_child(index); 00423 return ( firstchild>0 ) ? 00424 ( 1+last_child(index)-firstchild ) : 0; 00425 } 00426 00427 inline double HEPEVT_Wrapper::px( int index ) 00428 { 00429 return byte_num_to_double( (2+6*max_number_entries())*sizeof_int() 00430 + (5*(index-1)+0) *sizeof_real() ); 00431 } 00432 00433 inline double HEPEVT_Wrapper::py( int index ) 00434 { 00435 return byte_num_to_double( (2+6*max_number_entries())*sizeof_int() 00436 + (5*(index-1)+1) *sizeof_real() ); 00437 } 00438 00439 00440 inline double HEPEVT_Wrapper::pz( int index ) 00441 { 00442 return byte_num_to_double( (2+6*max_number_entries())*sizeof_int() 00443 + (5*(index-1)+2) *sizeof_real() ); 00444 } 00445 00446 inline double HEPEVT_Wrapper::e( int index ) 00447 { 00448 return byte_num_to_double( (2+6*max_number_entries())*sizeof_int() 00449 + (5*(index-1)+3) *sizeof_real() ); 00450 } 00451 00452 inline double HEPEVT_Wrapper::m( int index ) 00453 { 00454 return byte_num_to_double( (2+6*max_number_entries())*sizeof_int() 00455 + (5*(index-1)+4) *sizeof_real() ); 00456 } 00457 00458 inline double HEPEVT_Wrapper::x( int index ) 00459 { 00460 return byte_num_to_double( (2+6*max_number_entries())*sizeof_int() 00461 + ( 5*max_number_entries() 00462 + (4*(index-1)+0) ) *sizeof_real() ); 00463 } 00464 00465 inline double HEPEVT_Wrapper::y( int index ) 00466 { 00467 return byte_num_to_double( (2+6*max_number_entries())*sizeof_int() 00468 + ( 5*max_number_entries() 00469 + (4*(index-1)+1) ) *sizeof_real() ); 00470 } 00471 00472 inline double HEPEVT_Wrapper::z( int index ) 00473 { 00474 return byte_num_to_double( (2+6*max_number_entries())*sizeof_int() 00475 + ( 5*max_number_entries() 00476 + (4*(index-1)+2) ) *sizeof_real() ); 00477 } 00478 00479 inline double HEPEVT_Wrapper::t( int index ) 00480 { 00481 return byte_num_to_double( (2+6*max_number_entries())*sizeof_int() 00482 + ( 5*max_number_entries() 00483 + (4*(index-1)+3) ) *sizeof_real() ); 00484 } 00485 00486 inline void HEPEVT_Wrapper::set_event_number( int evtno ) 00487 { write_byte_num( evtno, 0 ); } 00488 00489 inline void HEPEVT_Wrapper::set_number_entries( int noentries ) 00490 { write_byte_num( noentries, 1*sizeof_int() ); } 00491 00492 inline void HEPEVT_Wrapper::set_status( int index, int status ) 00493 { 00494 if ( index <= 0 || index > max_number_entries() ) return; 00495 write_byte_num( status, (2+index-1) * sizeof_int() ); 00496 } 00497 00498 inline void HEPEVT_Wrapper::set_id( int index, int id ) 00499 { 00500 if ( index <= 0 || index > max_number_entries() ) return; 00501 write_byte_num( id, (2+max_number_entries()+index-1) *sizeof_int() ); 00502 } 00503 00504 inline void HEPEVT_Wrapper::set_parents( int index, int firstparent, 00505 int lastparent ) 00506 { 00507 if ( index <= 0 || index > max_number_entries() ) return; 00508 write_byte_num( firstparent, (2+2*max_number_entries()+2*(index-1)) 00509 *sizeof_int() ); 00510 write_byte_num( lastparent, (2+2*max_number_entries()+2*(index-1)+1) 00511 * sizeof_int() ); 00512 } 00513 00514 inline void HEPEVT_Wrapper::set_children( int index, int firstchild, 00515 int lastchild ) 00516 { 00517 if ( index <= 0 || index > max_number_entries() ) return; 00518 write_byte_num( firstchild, (2+4*max_number_entries()+2*(index-1)) 00519 *sizeof_int() ); 00520 write_byte_num( lastchild, (2+4*max_number_entries()+2*(index-1)+1) 00521 *sizeof_int() ); 00522 } 00523 00524 inline void HEPEVT_Wrapper::set_momentum( int index, double px, 00525 double py, double pz, double e ) 00526 { 00527 if ( index <= 0 || index > max_number_entries() ) return; 00528 write_byte_num( px, (2+6*max_number_entries()) *sizeof_int() 00529 + (5*(index-1)+0) *sizeof_real() ); 00530 write_byte_num( py, (2+6*max_number_entries())*sizeof_int() 00531 + (5*(index-1)+1) *sizeof_real() ); 00532 write_byte_num( pz, (2+6*max_number_entries())*sizeof_int() 00533 + (5*(index-1)+2) *sizeof_real() ); 00534 write_byte_num( e, (2+6*max_number_entries())*sizeof_int() 00535 + (5*(index-1)+3) *sizeof_real() ); 00536 } 00537 00538 inline void HEPEVT_Wrapper::set_mass( int index, double mass ) 00539 { 00540 if ( index <= 0 || index > max_number_entries() ) return; 00541 write_byte_num( mass, (2+6*max_number_entries())*sizeof_int() 00542 + (5*(index-1)+4) *sizeof_real() ); 00543 } 00544 00545 inline void HEPEVT_Wrapper::set_position( int index, double x, double y, 00546 double z, double t ) 00547 { 00548 if ( index <= 0 || index > max_number_entries() ) return; 00549 write_byte_num( x, (2+6*max_number_entries())*sizeof_int() 00550 + ( 5*max_number_entries() 00551 + (4*(index-1)+0) ) *sizeof_real() ); 00552 write_byte_num( y, (2+6*max_number_entries())*sizeof_int() 00553 + ( 5*max_number_entries() 00554 + (4*(index-1)+1) ) *sizeof_real() ); 00555 write_byte_num( z, (2+6*max_number_entries())*sizeof_int() 00556 + ( 5*max_number_entries() 00557 + (4*(index-1)+2) ) *sizeof_real() ); 00558 write_byte_num( t, (2+6*max_number_entries())*sizeof_int() 00559 + ( 5*max_number_entries() 00560 + (4*(index-1)+3) ) *sizeof_real() ); 00561 } 00562 00563 } // HepMC 00564 00565 #endif // HEPMC_HEPEVT_WRAPPER_H 00566 //-------------------------------------------------------------------------- 00567