6#ifndef HEPMC3_HEPEVT_WRAPPER_TEMPLATE_H
7#define HEPMC3_HEPEVT_WRAPPER_TEMPLATE_H
30template <
int max_particles,
typename momentum_type =
double>
64 void set_max_number_entries(
unsigned int size ) {
if (size != max_particles) printf(
"This implementation does not support change of the block size.\n"); assert(size == max_particles); }
75 double px(
const int index )
const {
return m_hepevtptr->phep[index-1][0]; }
76 double py(
const int index )
const {
return m_hepevtptr->phep[index-1][1]; }
77 double pz(
const int index )
const {
return m_hepevtptr->phep[index-1][2]; }
78 double e(
const int index )
const {
return m_hepevtptr->phep[index-1][3]; }
79 double m(
const int index )
const {
return m_hepevtptr->phep[index-1][4]; }
80 double x(
const int index )
const {
return m_hepevtptr->vhep[index-1][0]; }
81 double y(
const int index )
const {
return m_hepevtptr->vhep[index-1][1]; }
82 double z(
const int index )
const {
return m_hepevtptr->vhep[index-1][2]; }
83 double t(
const int index )
const {
return m_hepevtptr->vhep[index-1][3]; }
91 void set_parents(
const int index,
const int firstparent,
const int lastparent );
92 void set_children(
const int index,
const int firstchild,
const int lastchild );
93 void set_momentum(
const int index,
const double px,
const double py,
const double pz,
const double e );
95 void set_position(
const int index,
const double x,
const double y,
const double z,
const double t );
101template <
int max_particles,
typename momentum_type>
104 ostr <<
" Event No.: " << m_hepevtptr->nevhep << std::endl;
105 ostr <<
" Nr Type Parent(s) Daughter(s) Px Py Pz E Inv. M." << std::endl;
106 for (
int i = 1; i <= m_hepevtptr->nhep; ++i )
108 print_hepevt_particle( i, ostr );
111template <
int max_particles,
typename momentum_type>
116 sprintf(buf,
"%5i %6i", index, m_hepevtptr->idhep[index-1]);
118 sprintf(buf,
"%4i - %4i ", m_hepevtptr->jmohep[index-1][0], m_hepevtptr->jmohep[index-1][1]);
120 sprintf(buf,
"%4i - %4i ", m_hepevtptr->jdahep[index-1][0], m_hepevtptr->jdahep[index-1][1]);
122 sprintf(buf,
"%8.2f %8.2f %8.2f %8.2f %8.2f", m_hepevtptr->phep[index-1][0], m_hepevtptr->phep[index-1][1], m_hepevtptr->phep[index-1][2], m_hepevtptr->phep[index-1][3], m_hepevtptr->phep[index-1][4]);
123 ostr << buf << std::endl;
126template <
int max_particles,
typename momentum_type>
129 m_internal_storage = std::make_shared<struct HEPEVT_Templated<max_particles, momentum_type>>();
130 m_hepevtptr = m_internal_storage.get();
133template <
int max_particles,
typename momentum_type>
136 if ( N < 1 || N > max_particles)
return;
137 m_internal_storage = std::make_shared<struct HEPEVT_Templated<max_particles, momentum_type>>();
138 m_hepevtptr = m_internal_storage.get();
140 m_hepevtptr->nevhep = *((
int*)x);
142 m_hepevtptr->nhep = *((
int*)x);
144 memcpy(m_hepevtptr->isthep, x, N*
sizeof(
int));
146 memcpy(m_hepevtptr->idhep, x, N*
sizeof(
int));
148 memcpy(m_hepevtptr->jmohep, x, 2*N*
sizeof(
int));
149 x +=
sizeof(int)*N*2;
150 memcpy(m_hepevtptr->jdahep, x, 2*N*
sizeof(
int));
151 x +=
sizeof(int)*N*2;
152 memcpy(m_hepevtptr->phep, x, 5*N*
sizeof(momentum_type));
153 x +=
sizeof(momentum_type)*N*5;
154 memcpy(m_hepevtptr->vhep, x, 4*N*
sizeof(momentum_type));
157template <
int max_particles,
typename momentum_type>
163template <
int max_particles,
typename momentum_type>
166 return (m_hepevtptr->jmohep[index-1][0]) ? (m_hepevtptr->jmohep[index-1][1]) ? m_hepevtptr->jmohep[index-1][1]-m_hepevtptr->jmohep[index-1][0] : 1 : 0;
169template <
int max_particles,
typename momentum_type>
172 return (m_hepevtptr->jdahep[index-1][0]) ? (m_hepevtptr->jdahep[index-1][1]) ? m_hepevtptr->jdahep[index-1][1]-m_hepevtptr->jdahep[index-1][0] : 1 : 0;
175template <
int max_particles,
typename momentum_type>
179 for (
int i = 1; i <= m_hepevtptr->nhep; ++i )
180 if (((m_hepevtptr->jmohep[i-1][0] <= index && m_hepevtptr->jmohep[i-1][1] >= index)) || (m_hepevtptr->jmohep[i-1][0] == index) || (m_hepevtptr->jmohep[i-1][1]==index)) nc++;
184template <
int max_particles,
typename momentum_type>
187 m_hepevtptr->jmohep[index-1][0] = firstparent;
188 m_hepevtptr->jmohep[index-1][1] = lastparent;
191template <
int max_particles,
typename momentum_type>
194 m_hepevtptr->jdahep[index-1][0] = firstchild;
195 m_hepevtptr->jdahep[index-1][1] = lastchild;
198template <
int max_particles,
typename momentum_type>
201 m_hepevtptr->phep[index-1][0] = px;
202 m_hepevtptr->phep[index-1][1] = py;
203 m_hepevtptr->phep[index-1][2] = pz;
204 m_hepevtptr->phep[index-1][3] = e;
207template <
int max_particles,
typename momentum_type>
210 m_hepevtptr->phep[index-1][4] = mass;
213template <
int max_particles,
typename momentum_type>
216 m_hepevtptr->vhep[index-1][0] = x;
217 m_hepevtptr->vhep[index-1][1] = y;
218 m_hepevtptr->vhep[index-1][2] = z;
219 m_hepevtptr->vhep[index-1][3] = t;
222template <
int max_particles,
typename momentum_type>
230 for (
int i = 1; i <= number_entries(); i++ )
231 for (
int k=1; k <= number_entries(); k++ )
if (i != k)
232 if ((first_parent(k) <= i) && (i <= last_parent(k)))
233 set_children(i, (first_child(i) == 0 ? k : std::min(first_child(i), k)), (last_child(i) == 0 ? k : std::max(last_child(i), k)));
234 bool is_fixed =
true;
235 for (
int i = 1; i <= number_entries(); i++ )
236 is_fixed = (is_fixed && (number_children_exact(i) == number_children(i)));
Definition of class GenEvent.
Definition of class GenParticle.
Definition of class GenVertex.
Helper functions used to manipulate with HEPEVT block.
Stores event-related information.
An interface to HEPEVT common block implemented as template class.
int first_child(const int index) const
Get index of 1st daughter.
int last_parent(const int index) const
Get index of last mother.
~HEPEVT_Wrapper_Template()
Default destructor.
void set_id(const int index, const int id)
Set PDG particle id.
int event_number() const
Get event number.
bool HEPEVT_to_GenEvent(GenEvent *evt) const
Convert HEPEVT to GenEvent.
bool GenEvent_to_HEPEVT(const GenEvent *evt)
Convert GenEvent to HEPEVT.
int last_child(const int index) const
Get index of last daughter.
void allocate_internal_storage()
Allocates m_internal_storage storage in smart pointer to hold HEPEVT of fixed size.
int first_parent(const int index) const
Get index of 1st mother.
double pz(const int index) const
Get Z momentum.
void zero_everything()
Set all entries in HEPEVT to zero.
double py(const int index) const
Get Y momentum.
void set_parents(const int index, const int firstparent, const int lastparent)
Set parents.
int number_children_exact(const int index) const
Get number of children by counting.
void print_hepevt_particle(int index, std::ostream &ostr=std::cout) const
Print particle information.
int id(const int index) const
Get PDG particle id.
double t(const int index) const
Get production time.
void set_momentum(const int index, const double px, const double py, const double pz, const double e)
Set 4-momentum.
void set_children(const int index, const int firstchild, const int lastchild)
Set children.
int number_parents(const int index) const
Get number of parents.
void set_position(const int index, const double x, const double y, const double z, const double t)
Set position in time-space.
double y(const int index) const
Get Y Production vertex.
bool fix_daughters()
Tries to fix list of daughters.
void set_max_number_entries(unsigned int size)
Set block size.
int number_entries() const
Get number of entries.
void set_hepevt_address(char *c)
Set Fortran block address.
double m(const int index) const
Get generated mass.
int status(const int index) const
Get status code.
std::shared_ptr< struct HEPEVT_Templated< max_particles, momentum_type > > m_internal_storage
Internalstorage storage. Optional.
double px(const int index) const
Get X momentum.
int number_children(const int index) const
Get number of children from the range of daughters.
double z(const int index) const
Get Z Production vertex.
struct HEPEVT_Templated< max_particles, momentum_type > * m_hepevtptr
Fortran common block HEPEVT.
void print_hepevt(std::ostream &ostr=std::cout) const
Print information from HEPEVT common block.
void set_mass(const int index, double mass)
Set mass.
int max_number_entries() const
Block size.
double x(const int index) const
Get X Production vertex.
void set_event_number(const int evtno)
Set event number.
void copy_to_internal_storage(char *c, int N)
Copies the content of foreight common block into the internal storage.
void set_status(const int index, const int status)
Set status code.
HEPEVT_Wrapper_Template()
Default constructor.
void set_number_entries(const int noentries)
Set number of entries.
double e(const int index) const
Get Energy.
bool HEPEVT_to_GenEvent_nonstatic(GenEvent *evt, T *A)
Converts HEPEVT into GenEvent.
bool GenEvent_to_HEPEVT_nonstatic(const GenEvent *evt, T *A)
Converts GenEvent into HEPEVT.
C structure representing Fortran common block HEPEVT T. Sjöstrand et al., "A proposed standard event ...