4 #ifndef EPOS_EntriesAllocation 5 #define EPOS_EntriesAllocation 99900 6 #endif // EPOS_EntriesAllocation 9 #ifndef HEPMC_EPOS_COMMON_H 10 #define HEPMC_EPOS_COMMON_H 72 #ifdef _WIN32 // Platform: Windows MS Visual C++ 76 extern "C" HEPCOM_DEF HEPCOM;
85 #define hepcom hepcom_ 89 #endif // HEPMC_EPOS_COMMON_H 92 #ifndef HEPMC_EPOS_WRAPPER_H 93 #define HEPMC_EPOS_WRAPPER_H 135 static void print_hepcom( std::ostream& ostr =
std::cout );
137 static void print_hepcom_particle(
int index,
140 static void zero_everything();
145 static int event_number();
146 static int number_entries();
147 static int status(
int index );
148 static int id(
int index );
149 static int first_parent(
int index );
150 static int last_parent(
int index );
151 static int number_parents(
int index );
152 static int first_child(
int index );
153 static int last_child(
int index );
154 static int number_children(
int index );
155 static double px(
int index );
156 static double py(
int index );
157 static double pz(
int index );
158 static double e(
int index );
159 static double m(
int index );
160 static double x(
int index );
161 static double y(
int index );
162 static double z(
int index );
163 static double t(
int index );
170 static void set_event_number(
int evtno );
172 static void set_number_entries(
int noentries );
174 static void set_status(
int index,
int status );
176 static void set_id(
int index,
int id );
178 static void set_parents(
int index,
int firstparent,
int lastparent );
180 static void set_children(
int index,
int firstchild,
int lastchild );
182 static void set_momentum(
int index,
double px,
double py,
183 double pz,
double e );
185 static void set_mass(
int index,
double mass );
187 static void set_position(
int index,
double x,
double y,
double z,
192 static unsigned int sizeof_int();
193 static unsigned int sizeof_real();
194 static int max_number_entries();
195 static void set_sizeof_int(
unsigned int);
196 static void set_sizeof_real(
unsigned int);
197 static void set_max_number_entries(
unsigned int);
201 static double byte_num_to_double(
unsigned int );
203 static int byte_num_to_int(
unsigned int );
205 static void write_byte_num(
double,
unsigned int );
207 static void write_byte_num(
int,
unsigned int );
209 static void print_legend( std::ostream& ostr =
std::cout );
221 inline unsigned int EPOS_Wrapper::sizeof_int(){
return s_sizeof_int; }
223 inline unsigned int EPOS_Wrapper::sizeof_real(){
return s_sizeof_real; }
225 inline int EPOS_Wrapper::max_number_entries()
226 {
return (
int)s_max_number_entries; }
228 inline void EPOS_Wrapper::set_sizeof_int(
unsigned int size )
230 if ( size !=
sizeof(
short int) && size !=
sizeof(
long int) && size !=
sizeof(
int) ) {
231 std::cerr <<
"HepMC is not able to handle integers " 232 <<
" of size other than 2 or 4." 233 <<
" You requested: " << size << std::endl;
238 inline void EPOS_Wrapper::set_sizeof_real(
unsigned int size ) {
239 if ( size !=
sizeof(
float) && size !=
sizeof(
double) ) {
240 std::cerr <<
"HepMC is not able to handle floating point numbers" 241 <<
" of size other than 4 or 8." 242 <<
" You requested: " << size << std::endl;
244 s_sizeof_real =
size;
247 inline void EPOS_Wrapper::set_max_number_entries(
unsigned int size ) {
248 s_max_number_entries =
size;
251 inline double EPOS_Wrapper::byte_num_to_double(
unsigned int b ) {
253 <<
"EPOS_Wrapper: requested hepcom data exceeds allocation" 255 if ( s_sizeof_real ==
sizeof(
float) ) {
256 float* myfloat = (
float*)&
hepcom.data[b];
257 return (
double)(*myfloat);
258 }
else if ( s_sizeof_real ==
sizeof(
double) ) {
259 double* mydouble = (
double*)&
hepcom.data[b];
263 <<
"EPOS_Wrapper: illegal floating point number length." 264 << s_sizeof_real << std::endl;
269 inline int EPOS_Wrapper::byte_num_to_int(
unsigned int b ) {
271 <<
"EPOS_Wrapper: requested hepcom data exceeds allocation" 273 if ( s_sizeof_int ==
sizeof(
short int) ) {
274 short int* myshortint = (
short int*)&
hepcom.data[b];
275 return (
int)(*myshortint);
276 }
else if ( s_sizeof_int ==
sizeof(
long int) ) {
277 long int* mylongint = (
long int*)&
hepcom.data[b];
280 }
else if ( s_sizeof_int ==
sizeof(
int) ) {
281 int* myint = (
int*)&
hepcom.data[b];
285 <<
"EPOS_Wrapper: illegal integer number length." 286 << s_sizeof_int << std::endl;
291 inline void EPOS_Wrapper::write_byte_num(
double in,
unsigned int b ) {
293 <<
"EPOS_Wrapper: requested hepcom data exceeds allocation" 295 if ( s_sizeof_real ==
sizeof(
float) ) {
296 float* myfloat = (
float*)&
hepcom.data[b];
297 (*myfloat) = (
float)in;
298 }
else if ( s_sizeof_real ==
sizeof(
double) ) {
299 double* mydouble = (
double*)&
hepcom.data[b];
300 (*mydouble) = (double)in;
303 <<
"EPOS_Wrapper: illegal floating point number length." 304 << s_sizeof_real << std::endl;
308 inline void EPOS_Wrapper::write_byte_num(
int in,
unsigned int b ) {
310 <<
"EPOS_Wrapper: requested hepcom data exceeds allocation" 312 if ( s_sizeof_int ==
sizeof(
short int) ) {
313 short int* myshortint = (
short int*)&
hepcom.data[b];
314 (*myshortint) = (
short int)in;
315 }
else if ( s_sizeof_int ==
sizeof(
long int) ) {
316 long int* mylongint = (
long int*)&
hepcom.data[b];
317 (*mylongint) = (
int)in;
319 }
else if ( s_sizeof_int ==
sizeof(
int) ) {
320 int* myint = (
int*)&
hepcom.data[b];
324 <<
"EPOS_Wrapper: illegal integer number length." 325 << s_sizeof_int << std::endl;
333 inline int EPOS_Wrapper::event_number()
334 {
return byte_num_to_int(0); }
336 inline int EPOS_Wrapper::number_entries()
338 int nhep = byte_num_to_int( 1*sizeof_int() );
339 return ( nhep <= max_number_entries() ?
340 nhep : max_number_entries() );
344 {
return byte_num_to_int( (2+index-1) * sizeof_int() ); }
348 return byte_num_to_int( (2+max_number_entries()+index-1)
352 inline int EPOS_Wrapper::first_parent(
int index )
354 int parent = byte_num_to_int( (2+2*max_number_entries()+2*(index-1))
356 return ( parent > 0 && parent <= number_entries() ) ?
360 inline int EPOS_Wrapper::last_parent(
int index )
371 int firstparent = first_parent(index);
372 int parent = byte_num_to_int( (2+2*max_number_entries()+2*(index-1)+1)
374 return ( parent > firstparent && parent <= number_entries() )
375 ? parent : firstparent;
378 inline int EPOS_Wrapper::number_parents(
int index ) {
379 int firstparent = first_parent(index);
380 return ( firstparent>0 ) ?
381 ( 1+last_parent(index)-firstparent ) : 0;
384 inline int EPOS_Wrapper::first_child(
int index )
386 int child = byte_num_to_int( (2+4*max_number_entries()+2*(index-1))
388 return ( child > 0 && child <= number_entries() ) ?
392 inline int EPOS_Wrapper::last_child(
int index )
403 int firstchild = first_child(index);
404 int child = byte_num_to_int( (2+4*max_number_entries()+2*(index-1)+1)
406 return ( child > firstchild && child <= number_entries() )
407 ? child : firstchild;
410 inline int EPOS_Wrapper::number_children(
int index )
412 int firstchild = first_child(index);
413 return ( firstchild>0 ) ?
414 ( 1+last_child(index)-firstchild ) : 0;
417 inline double EPOS_Wrapper::px(
int index )
419 return byte_num_to_double( (2+6*max_number_entries())*sizeof_int()
420 + (5*(index-1)+0) *sizeof_real() );
423 inline double EPOS_Wrapper::py(
int index )
425 return byte_num_to_double( (2+6*max_number_entries())*sizeof_int()
426 + (5*(index-1)+1) *sizeof_real() );
430 inline double EPOS_Wrapper::pz(
int index )
432 return byte_num_to_double( (2+6*max_number_entries())*sizeof_int()
433 + (5*(index-1)+2) *sizeof_real() );
438 return byte_num_to_double( (2+6*max_number_entries())*sizeof_int()
439 + (5*(index-1)+3) *sizeof_real() );
444 return byte_num_to_double( (2+6*max_number_entries())*sizeof_int()
445 + (5*(index-1)+4) *sizeof_real() );
450 return byte_num_to_double( (2+6*max_number_entries())*sizeof_int()
451 + ( 5*max_number_entries()
452 + (4*(index-1)+0) ) *sizeof_real() );
457 return byte_num_to_double( (2+6*max_number_entries())*sizeof_int()
458 + ( 5*max_number_entries()
459 + (4*(index-1)+1) ) *sizeof_real() );
464 return byte_num_to_double( (2+6*max_number_entries())*sizeof_int()
465 + ( 5*max_number_entries()
466 + (4*(index-1)+2) ) *sizeof_real() );
471 return byte_num_to_double( (2+6*max_number_entries())*sizeof_int()
472 + ( 5*max_number_entries()
473 + (4*(index-1)+3) ) *sizeof_real() );
476 inline void EPOS_Wrapper::set_event_number(
int evtno )
477 { write_byte_num( evtno, 0 ); }
479 inline void EPOS_Wrapper::set_number_entries(
int noentries )
480 { write_byte_num( noentries, 1*sizeof_int() ); }
484 if ( index <= 0 || index > max_number_entries() )
return;
485 write_byte_num( status, (2+index-1) * sizeof_int() );
488 inline void EPOS_Wrapper::set_id(
int index,
int id )
490 if ( index <= 0 || index > max_number_entries() )
return;
491 write_byte_num(
id, (2+max_number_entries()+index-1) *sizeof_int() );
494 inline void EPOS_Wrapper::set_parents(
int index,
int firstparent,
497 if ( index <= 0 || index > max_number_entries() )
return;
498 write_byte_num( firstparent, (2+2*max_number_entries()+2*(index-1))
500 write_byte_num( lastparent, (2+2*max_number_entries()+2*(index-1)+1)
504 inline void EPOS_Wrapper::set_children(
int index,
int firstchild,
507 if ( index <= 0 || index > max_number_entries() )
return;
508 write_byte_num( firstchild, (2+4*max_number_entries()+2*(index-1))
510 write_byte_num( lastchild, (2+4*max_number_entries()+2*(index-1)+1)
514 inline void EPOS_Wrapper::set_momentum(
int index,
double px,
515 double py,
double pz,
double e )
517 if ( index <= 0 || index > max_number_entries() )
return;
518 write_byte_num( px, (2+6*max_number_entries()) *sizeof_int()
519 + (5*(index-1)+0) *sizeof_real() );
520 write_byte_num( py, (2+6*max_number_entries())*sizeof_int()
521 + (5*(index-1)+1) *sizeof_real() );
522 write_byte_num( pz, (2+6*max_number_entries())*sizeof_int()
523 + (5*(index-1)+2) *sizeof_real() );
524 write_byte_num( e, (2+6*max_number_entries())*sizeof_int()
525 + (5*(index-1)+3) *sizeof_real() );
528 inline void EPOS_Wrapper::set_mass(
int index,
double mass )
530 if ( index <= 0 || index > max_number_entries() )
return;
531 write_byte_num( mass, (2+6*max_number_entries())*sizeof_int()
532 + (5*(index-1)+4) *sizeof_real() );
535 inline void EPOS_Wrapper::set_position(
int index,
double x,
double y,
538 if ( index <= 0 || index > max_number_entries() )
return;
539 write_byte_num( x, (2+6*max_number_entries())*sizeof_int()
540 + ( 5*max_number_entries()
541 + (4*(index-1)+0) ) *sizeof_real() );
542 write_byte_num( y, (2+6*max_number_entries())*sizeof_int()
543 + ( 5*max_number_entries()
544 + (4*(index-1)+1) ) *sizeof_real() );
545 write_byte_num( z, (2+6*max_number_entries())*sizeof_int()
546 + ( 5*max_number_entries()
547 + (4*(index-1)+2) ) *sizeof_real() );
548 write_byte_num( t, (2+6*max_number_entries())*sizeof_int()
549 + ( 5*max_number_entries()
550 + (4*(index-1)+3) ) *sizeof_real() );
553 inline void EPOS_Wrapper::zero_everything()
555 set_event_number( 0 );
556 set_number_entries( 0 );
557 for (
int i = 1;
i<=max_number_entries(); ++
i ) {
560 set_parents(
i, 0, 0 );
561 set_children(
i, 0, 0 );
562 set_momentum(
i, 0, 0, 0, 0 );
564 set_position(
i, 0, 0, 0, 0 );
568 inline void EPOS_Wrapper::print_hepcom( std::ostream& ostr )
570 ostr <<
"________________________________________" 571 <<
"________________________________________" << std::endl;
572 ostr <<
"***** HEPEVT Common Event#: " 574 <<
", " << number_entries() <<
" particles (max " 575 << max_number_entries() <<
") *****";
576 ostr << sizeof_int() <<
"-byte integers, " 577 << sizeof_real() <<
"-byte floating point numbers, " 578 << max_number_entries() <<
"-allocated entries." 581 ostr <<
"________________________________________" 582 <<
"________________________________________" << std::endl;
583 for (
int i=1;
i <= number_entries(); ++
i ) {
584 print_hepcom_particle(
i, ostr );
586 ostr <<
"________________________________________" 587 <<
"________________________________________" << std::endl;
590 inline void EPOS_Wrapper::print_hepcom_particle(
int i, std::ostream& ostr )
594 "%4d %+4d %4d %4d (%9.3g, %9.3g, %9.3g, %9.3g, %9.3g)" 595 ,i,
status(i), first_parent(i), first_child(i),
596 px(i), py(i), pz(i),
e(i),
m(i) );
597 ostr << outline <<
"\n";
598 sprintf( outline,
"%+9d %4d %4d (%9.3g, %9.3g, %9.3g, %9.3g)",
600 id(i), last_parent(i), last_child(i),
601 x(i),
y(i),
z(i),
t(i) );
602 ostr << outline << std::endl;
605 inline void EPOS_Wrapper::print_legend( std::ostream& ostr )
608 sprintf( outline,
"%4s %4s %4s %5s %10s, %9s, %9s, %9s, %10s",
609 "Indx",
"Stat",
"Par-",
"chil-",
610 "( P_x",
"P_y",
"P_z",
"Energy",
"M ) ");
611 ostr << outline << std::endl;
612 sprintf( outline,
"%9s %4s %4s %10s, %9s, %9s, %9s) %9s",
614 "Prod ( X",
"Y",
"Z",
"cT",
"[mm]");
615 ostr << outline << std::endl;
620 #endif // HEPMC_EPOS_WRAPPER_H
#define EPOS_EntriesAllocation
Generic Wrapper for the fortran EPOS common block.
static unsigned int s_max_number_entries
static unsigned int s_sizeof_real
const unsigned int epos_bytes_allocation
char data[epos_bytes_allocation]
static unsigned int s_sizeof_int