HepMC3 event record library
HEPEVT_Wrapper_Runtime_Static.h
Go to the documentation of this file.
1// -*- C++ -*-
2//
3// This file is part of HepMC
4// Copyright (C) 2014-2021 The HepMC collaboration (see AUTHORS for details)
5//
6#ifndef HEPMC3_HEPEVT_WRAPPER_RUNTIME_STATIC_H
7#define HEPMC3_HEPEVT_WRAPPER_RUNTIME_STATIC_H
8#include <iostream>
9#include <cstdio>
10#include <set>
11#include <map>
12#include <cstring> // memset
13#include <algorithm> //min max for VS2017
14#include "HepMC3/GenEvent.h"
15#include "HepMC3/GenParticle.h"
16#include "HepMC3/GenVertex.h"
18
19/**
20 * @file HEPEVT_Wrapper_Runtime_Static.h
21 * @brief Definition of \b class HEPEVT_Wrapper_Runtime_Static
22 *
23 * @class HepMC3::HEPEVT_Wrapper_Runtime_Static
24 * @brief A static interface to HEPEVT common block implemented to deal with varying block size in runtime
25 */
26namespace HepMC3
27{
28
29
31{
32
33//
34// Functions
35//
36public:
37 /** @brief Print information from HEPEVT common block */
38 static void print_hepevt( std::ostream& ostr = std::cout );
39 /** @brief Print particle information */
40 static void print_hepevt_particle( int index, std::ostream& ostr = std::cout );
41 /** @brief Set all entries in HEPEVT to zero */
42 static void zero_everything();
43 /** @brief Convert GenEvent to HEPEVT*/
44 static bool GenEvent_to_HEPEVT( const GenEvent* evt ) { return GenEvent_to_HEPEVT_static<HEPEVT_Wrapper_Runtime_Static>(evt);};
45 /** @brief Convert HEPEVT to GenEvent*/
46 static bool HEPEVT_to_GenEvent( GenEvent* evt ) { return HEPEVT_to_GenEvent_static<HEPEVT_Wrapper_Runtime_Static>(evt);};
47 /** @brief Tries to fix list of daughters */
48 static bool fix_daughters();
49private:
50 /** @brief Fortran common block HEPEVT */
51 HEPMC3_EXPORT_API static std::shared_ptr<struct HEPEVT_Pointers<double> > m_hepevtptr;
52 /** @brief Block size */
53 HEPMC3_EXPORT_API static int m_max_particles;
54//
55// Accessors
56//
57public:
58 static void set_max_number_entries( unsigned int size ) { m_max_particles = size; }//!< Set block size
59 static void set_hepevt_address(char *c); //!< Set Fortran block address
60 static int max_number_entries() { return m_max_particles; } //!< Block size
61 static int event_number() { return *(m_hepevtptr->nevhep); } //!< Get event number
62 static int number_entries() { return *(m_hepevtptr->nhep); } //!< Get number of entries
63 static int status(const int index ) { return m_hepevtptr->isthep[index-1]; } //!< Get status code
64 static int id(const int index ) { return m_hepevtptr->idhep[index-1]; } //!< Get PDG particle id
65 static int first_parent(const int index ) { return m_hepevtptr->jmohep[2*(index-1)]; } //!< Get index of 1st mother
66 static int last_parent(const int index ) { return m_hepevtptr->jmohep[2*(index-1)+1]; } //!< Get index of last mother
67 static int first_child(const int index ) { return m_hepevtptr->jdahep[2*(index-1)]; } //!< Get index of 1st daughter
68 static int last_child(const int index ) { return m_hepevtptr->jdahep[2*(index-1)+1]; } //!< Get index of last daughter
69 static double px(const int index ) { return m_hepevtptr->phep[5*(index-1)]; } //!< Get X momentum
70 static double py(const int index ) { return m_hepevtptr->phep[5*(index-1)+1]; } //!< Get Y momentum
71 static double pz(const int index ) { return m_hepevtptr->phep[5*(index-1)+2]; } //!< Get Z momentum
72 static double e(const int index ) { return m_hepevtptr->phep[5*(index-1)+3]; } //!< Get Energy
73 static double m(const int index ) { return m_hepevtptr->phep[5*(index-1)+4]; } //!< Get generated mass
74 static double x(const int index ) { return m_hepevtptr->vhep[4*(index-1)]; } //!< Get X Production vertex
75 static double y(const int index ) { return m_hepevtptr->vhep[4*(index-1)+1]; } //!< Get Y Production vertex
76 static double z(const int index ) { return m_hepevtptr->vhep[4*(index-1)+2]; } //!< Get Z Production vertex
77 static double t(const int index ) { return m_hepevtptr->vhep[4*(index-1)+3]; } //!< Get production time
78 static int number_parents(const int index ); //!< Get number of parents
79 static int number_children(const int index ); //!< Get number of children from the range of daughters
80 static int number_children_exact(const int index ); //!< Get number of children by counting
81 static void set_event_number( const int evtno ) { *(m_hepevtptr->nevhep) = evtno; } //!< Set event number
82 static void set_number_entries( const int noentries ) { *(m_hepevtptr->nhep) = noentries; } //!< Set number of entries
83 static void set_status( const int index, const int status ) { m_hepevtptr->isthep[index-1] = status; } //!< Set status code
84 static void set_id(const int index, const int id ) { m_hepevtptr->idhep[index-1] = id; } //!< Set PDG particle id
85 static void set_parents( const int index, const int firstparent, const int lastparent ); //!< Set parents
86 static void set_children( const int index, const int firstchild, const int lastchild ); //!< Set children
87 static void set_momentum( const int index, const double px, const double py, const double pz, const double e ); //!< Set 4-momentum
88 static void set_mass( const int index, double mass ); //!< Set mass
89 static void set_position( const int index, const double x, const double y, const double z, const double t ); //!< Set position in time-space
90};
91
92//
93// inline definitions
94//
95
97 m_hepevtptr = std::make_shared<struct HEPEVT_Pointers<double> >();
98 char* x = c;
99 m_hepevtptr->nevhep = (int*)x;
100 x += sizeof(int);
101 m_hepevtptr->nhep = (int*)(x);
102 x += sizeof(int);
103 m_hepevtptr->isthep = (int*)(x);
104 x += sizeof(int)*m_max_particles;
105 m_hepevtptr->idhep = (int*)(x);
106 x += sizeof(int)*m_max_particles;
107 m_hepevtptr->jmohep = (int*)(x);
108 x += sizeof(int)*m_max_particles*2;
109 m_hepevtptr->jdahep = (int*)(x);
110 x += sizeof(int)*m_max_particles*2;
111 m_hepevtptr->phep = (double*)(x);
112 x += sizeof(double)*m_max_particles*5;
113 m_hepevtptr->vhep = (double*)(x);
114}
115
116inline void HEPEVT_Wrapper_Runtime_Static::print_hepevt( std::ostream& ostr )
117{
118 ostr << " Event No.: " << *(m_hepevtptr->nevhep) << std::endl;
119 ostr << " Nr Type Parent(s) Daughter(s) Px Py Pz E Inv. M." << std::endl;
120 for ( int i = 1; i <= *(m_hepevtptr->nhep); ++i )
121 {
122 print_hepevt_particle( i, ostr );
123 }
124}
125
126inline void HEPEVT_Wrapper_Runtime_Static::print_hepevt_particle( int index, std::ostream& ostr )
127{
128 char buf[255];//Note: the format is fixed, so no reason for complicated treatment
129
130 sprintf(buf, "%5i %6i", index, m_hepevtptr->idhep[index-1]);
131 ostr << buf;
132 sprintf(buf, "%4i - %4i ", m_hepevtptr->jmohep[2*(index-1)], m_hepevtptr->jmohep[2*(index-1)+1]);
133 ostr << buf;
134 sprintf(buf, "%4i - %4i ", m_hepevtptr->jdahep[2*(index-1)], m_hepevtptr->jdahep[2*(index-1)+1]);
135 ostr << buf;
136 sprintf(buf, "%8.2f %8.2f %8.2f %8.2f %8.2f", m_hepevtptr->phep[5*(index-1)], m_hepevtptr->phep[5*(index-1)+1], m_hepevtptr->phep[5*(index-1)+2],
137 m_hepevtptr->phep[5*(index-1)+3], m_hepevtptr->phep[5*(index-1)+4]);
138 ostr << buf << std::endl;
139}
140
142{
143 *(m_hepevtptr->nevhep) = 0;
144 *(m_hepevtptr->nhep) = 0;
145 memset(m_hepevtptr->isthep, 0, sizeof(int)*m_max_particles);
146 memset(m_hepevtptr->idhep, 0, sizeof(int)*m_max_particles);
147 memset(m_hepevtptr->jmohep, 0, sizeof(int)*m_max_particles*2);
148 memset(m_hepevtptr->jdahep, 0, sizeof(int)*m_max_particles*2);
149 memset(m_hepevtptr->phep, 0, sizeof(double)*m_max_particles*5);
150 memset(m_hepevtptr->vhep, 0, sizeof(double)*m_max_particles*4);
151}
152
154{
155 return (m_hepevtptr->jmohep[2*(index-1)]) ? (m_hepevtptr->jmohep[2*(index-1)+1]) ? m_hepevtptr->jmohep[2*(index-1)+1]
156 -m_hepevtptr->jmohep[2*(index-1)] : 1 : 0;
157}
158
160{
161 return (m_hepevtptr->jdahep[2*(index-1)]) ? (m_hepevtptr->jdahep[2*(index-1)+1]) ? m_hepevtptr->jdahep[2*(index-1)+1]-m_hepevtptr->jdahep[2*(index-1)] : 1 : 0;
162}
163
165{
166 int nc = 0;
167 for ( int i = 1; i <= *(m_hepevtptr->nhep); ++i )
168 if (((m_hepevtptr->jmohep[2*(i-1)] <= index && m_hepevtptr->jmohep[2*(i-1)+1] >= index)) || (m_hepevtptr->jmohep[2*(i-1)] == index) ||
169 (m_hepevtptr->jmohep[2*(index-1)+1]==index)) nc++;
170 return nc;
171}
172
173
174inline void HEPEVT_Wrapper_Runtime_Static::set_parents( const int index, const int firstparent, const int lastparent )
175{
176 m_hepevtptr->jmohep[2*(index-1)] = firstparent;
177 m_hepevtptr->jmohep[2*(index-1)+1] = lastparent;
178}
179
180inline void HEPEVT_Wrapper_Runtime_Static::set_children( const int index, const int firstchild, const int lastchild )
181{
182 m_hepevtptr->jdahep[2*(index-1)] = firstchild;
183 m_hepevtptr->jdahep[2*(index-1)+1] = lastchild;
184}
185
186inline void HEPEVT_Wrapper_Runtime_Static::set_momentum( const int index, const double px, const double py, const double pz, const double e )
187{
188 m_hepevtptr->phep[5*(index-1)] = px;
189 m_hepevtptr->phep[5*(index-1)+1] = py;
190 m_hepevtptr->phep[5*(index-1)+2] = pz;
191 m_hepevtptr->phep[5*(index-1)+3] = e;
192}
193
194inline void HEPEVT_Wrapper_Runtime_Static::set_mass( const int index, double mass )
195{
196 m_hepevtptr->phep[5*(index-1)+4] = mass;
197}
198
199inline void HEPEVT_Wrapper_Runtime_Static::set_position( const int index, const double x, const double y, const double z, const double t )
200{
201 m_hepevtptr->vhep[4*(index-1)] = x;
202 m_hepevtptr->vhep[4*(index-1)+1] = y;
203 m_hepevtptr->vhep[4*(index-1)+2] = z;
204 m_hepevtptr->vhep[4*(index-1)+3] = t;
205}
206
208{
209 /*AV The function should be called for a record that has correct particle ordering and mother ids.
210 As a result it produces a record with ranges where the daughters can be found.
211 Not every particle in the range will be a daughter. It is true only for proper events.
212 The return tells if the record was fixed succesfully.
213 */
214 for ( int i = 1; i <= number_entries(); i++ )
215 for ( int k=1; k <= number_entries(); k++ ) if (i != k)
216 if ((first_parent(k) <= i) && (i <= last_parent(k)))
217 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)));
218 bool is_fixed = true;
219 for ( int i = 1; i <= number_entries(); i++ )
220 is_fixed = (is_fixed && (number_children_exact(i) == number_children(i)));
221 return is_fixed;
222}
223
224} // namespace HepMC3
225#endif
Definition of class GenEvent.
Definition of class GenParticle.
Definition of class GenVertex.
Helper functions used to manipulate with HEPEVT block.
Stores event-related information.
Definition: GenEvent.h:41
A static interface to HEPEVT common block implemented to deal with varying block size in runtime.
static void set_number_entries(const int noentries)
Set number of entries.
static int status(const int index)
Get status code.
static void set_status(const int index, const int status)
Set status code.
static bool HEPEVT_to_GenEvent(GenEvent *evt)
Convert HEPEVT to GenEvent.
static void print_hepevt_particle(int index, std::ostream &ostr=std::cout)
Print particle information.
static void print_hepevt(std::ostream &ostr=std::cout)
Print information from HEPEVT common block.
static double e(const int index)
Get Energy.
static void zero_everything()
Set all entries in HEPEVT to zero.
static void set_parents(const int index, const int firstparent, const int lastparent)
Set parents.
static HEPMC3_EXPORT_API int m_max_particles
Block size.
static void set_max_number_entries(unsigned int size)
Set block size.
static void set_momentum(const int index, const double px, const double py, const double pz, const double e)
Set 4-momentum.
static void set_children(const int index, const int firstchild, const int lastchild)
Set children.
static double z(const int index)
Get Z Production vertex.
static void set_position(const int index, const double x, const double y, const double z, const double t)
Set position in time-space.
static bool fix_daughters()
Tries to fix list of daughters.
static void set_hepevt_address(char *c)
Set Fortran block address.
static double m(const int index)
Get generated mass.
static int number_children(const int index)
Get number of children from the range of daughters.
static bool GenEvent_to_HEPEVT(const GenEvent *evt)
Convert GenEvent to HEPEVT.
static double px(const int index)
Get X momentum.
static double pz(const int index)
Get Z momentum.
static int last_parent(const int index)
Get index of last mother.
static void set_mass(const int index, double mass)
Set mass.
static int id(const int index)
Get PDG particle id.
static int number_children_exact(const int index)
Get number of children by counting.
static void set_event_number(const int evtno)
Set event number.
static void set_id(const int index, const int id)
Set PDG particle id.
static double x(const int index)
Get X Production vertex.
static double y(const int index)
Get Y Production vertex.
static int first_child(const int index)
Get index of 1st daughter.
static int number_entries()
Get number of entries.
static int first_parent(const int index)
Get index of 1st mother.
static int last_child(const int index)
Get index of last daughter.
static HEPMC3_EXPORT_API std::shared_ptr< struct HEPEVT_Pointers< double > > m_hepevtptr
Fortran common block HEPEVT.
static int number_parents(const int index)
Get number of parents.
static double t(const int index)
Get production time.
static double py(const int index)
Get Y momentum.
HepMC3 main namespace.