HepMC3 event record library: HEPEVT_Wrapper_Runtime_Static.h Source File

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-2023 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"
17#include "HepMC3/HEPEVT_Helpers.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
30 class HEPEVT_Wrapper_Runtime_Static
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
96 inline void HEPEVT_Wrapper_Runtime_Static::set_hepevt_address(char *c) {
97 m_hepevtptr = std::make_shared<struct HEPEVT_Pointers<double> >();
98 char* x = c;
99 m_hepevtptr->nevhep = reinterpret_cast<int*> ((x));
100 x += sizeof(int);
101 m_hepevtptr->nhep = reinterpret_cast<int*> ((x));
102 x += sizeof(int);
103 m_hepevtptr->isthep = reinterpret_cast<int*> ((x));
104 x += sizeof(int)*m_max_particles;
105 m_hepevtptr->idhep = reinterpret_cast<int*> ((x));
106 x += sizeof(int)*m_max_particles;
107 m_hepevtptr->jmohep = reinterpret_cast<int*> ((x));
108 x += sizeof(int)*m_max_particles*2;
109 m_hepevtptr->jdahep = reinterpret_cast<int*> ((x));
110 x += sizeof(int)*m_max_particles*2;
111 m_hepevtptr->phep = reinterpret_cast<double*> ((x));
112 x += sizeof(double)*m_max_particles*5;
113 m_hepevtptr->vhep = reinterpret_cast<double*> ((x));
114}
115
116 inline 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
126 inline 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
141 inline void HEPEVT_Wrapper_Runtime_Static::zero_everything()
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
153 inline int HEPEVT_Wrapper_Runtime_Static::number_parents( const int index )
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
159 inline int HEPEVT_Wrapper_Runtime_Static::number_children( const int index )
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
164 inline int HEPEVT_Wrapper_Runtime_Static::number_children_exact( const int index )
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
174 inline 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
180 inline 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
186 inline 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
194 inline void HEPEVT_Wrapper_Runtime_Static::set_mass( const int index, double mass )
195{
196 m_hepevtptr->phep[5*(index-1)+4] = mass;
197}
198
199 inline 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
207 inline bool HEPEVT_Wrapper_Runtime_Static::fix_daughters()
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
GenEvent.h
Definition of class GenEvent.
GenParticle.h
Definition of class GenParticle.
GenVertex.h
Definition of class GenVertex.
HEPEVT_Helpers.h
Helper functions used to manipulate with HEPEVT block.
HepMC3::GenEvent
Stores event-related information.
Definition GenEvent.h:47
HepMC3::HEPEVT_Wrapper_Runtime_Static
A static interface to HEPEVT common block implemented to deal with varying block size in runtime.
Definition HEPEVT_Wrapper_Runtime_Static.h:31
HepMC3::HEPEVT_Wrapper_Runtime_Static::set_number_entries
static void set_number_entries(const int noentries)
Set number of entries.
Definition HEPEVT_Wrapper_Runtime_Static.h:82
HepMC3::HEPEVT_Wrapper_Runtime_Static::status
static int status(const int index)
Get status code.
Definition HEPEVT_Wrapper_Runtime_Static.h:63
HepMC3::HEPEVT_Wrapper_Runtime_Static::set_status
static void set_status(const int index, const int status)
Set status code.
Definition HEPEVT_Wrapper_Runtime_Static.h:83
HepMC3::HEPEVT_Wrapper_Runtime_Static::HEPEVT_to_GenEvent
static bool HEPEVT_to_GenEvent(GenEvent *evt)
Convert HEPEVT to GenEvent.
Definition HEPEVT_Wrapper_Runtime_Static.h:46
HepMC3::HEPEVT_Wrapper_Runtime_Static::print_hepevt_particle
static void print_hepevt_particle(int index, std::ostream &ostr=std::cout)
Print particle information.
Definition HEPEVT_Wrapper_Runtime_Static.h:126
HepMC3::HEPEVT_Wrapper_Runtime_Static::print_hepevt
static void print_hepevt(std::ostream &ostr=std::cout)
Print information from HEPEVT common block.
Definition HEPEVT_Wrapper_Runtime_Static.h:116
HepMC3::HEPEVT_Wrapper_Runtime_Static::e
static double e(const int index)
Get Energy.
Definition HEPEVT_Wrapper_Runtime_Static.h:72
HepMC3::HEPEVT_Wrapper_Runtime_Static::zero_everything
static void zero_everything()
Set all entries in HEPEVT to zero.
Definition HEPEVT_Wrapper_Runtime_Static.h:141
HepMC3::HEPEVT_Wrapper_Runtime_Static::set_parents
static void set_parents(const int index, const int firstparent, const int lastparent)
Set parents.
Definition HEPEVT_Wrapper_Runtime_Static.h:174
HepMC3::HEPEVT_Wrapper_Runtime_Static::m_max_particles
static HEPMC3_EXPORT_API int m_max_particles
Block size.
Definition HEPEVT_Wrapper_Runtime_Static.h:53
HepMC3::HEPEVT_Wrapper_Runtime_Static::set_max_number_entries
static void set_max_number_entries(unsigned int size)
Set block size.
Definition HEPEVT_Wrapper_Runtime_Static.h:58
HepMC3::HEPEVT_Wrapper_Runtime_Static::max_number_entries
static int max_number_entries()
Block size.
Definition HEPEVT_Wrapper_Runtime_Static.h:60
HepMC3::HEPEVT_Wrapper_Runtime_Static::set_momentum
static void set_momentum(const int index, const double px, const double py, const double pz, const double e)
Set 4-momentum.
Definition HEPEVT_Wrapper_Runtime_Static.h:186
HepMC3::HEPEVT_Wrapper_Runtime_Static::set_children
static void set_children(const int index, const int firstchild, const int lastchild)
Set children.
Definition HEPEVT_Wrapper_Runtime_Static.h:180
HepMC3::HEPEVT_Wrapper_Runtime_Static::z
static double z(const int index)
Get Z Production vertex.
Definition HEPEVT_Wrapper_Runtime_Static.h:76
HepMC3::HEPEVT_Wrapper_Runtime_Static::set_position
static void set_position(const int index, const double x, const double y, const double z, const double t)
Set position in time-space.
Definition HEPEVT_Wrapper_Runtime_Static.h:199
HepMC3::HEPEVT_Wrapper_Runtime_Static::fix_daughters
static bool fix_daughters()
Tries to fix list of daughters.
Definition HEPEVT_Wrapper_Runtime_Static.h:207
HepMC3::HEPEVT_Wrapper_Runtime_Static::set_hepevt_address
static void set_hepevt_address(char *c)
Set Fortran block address.
Definition HEPEVT_Wrapper_Runtime_Static.h:96
HepMC3::HEPEVT_Wrapper_Runtime_Static::m
static double m(const int index)
Get generated mass.
Definition HEPEVT_Wrapper_Runtime_Static.h:73
HepMC3::HEPEVT_Wrapper_Runtime_Static::number_children
static int number_children(const int index)
Get number of children from the range of daughters.
Definition HEPEVT_Wrapper_Runtime_Static.h:159
HepMC3::HEPEVT_Wrapper_Runtime_Static::GenEvent_to_HEPEVT
static bool GenEvent_to_HEPEVT(const GenEvent *evt)
Convert GenEvent to HEPEVT.
Definition HEPEVT_Wrapper_Runtime_Static.h:44
HepMC3::HEPEVT_Wrapper_Runtime_Static::px
static double px(const int index)
Get X momentum.
Definition HEPEVT_Wrapper_Runtime_Static.h:69
HepMC3::HEPEVT_Wrapper_Runtime_Static::pz
static double pz(const int index)
Get Z momentum.
Definition HEPEVT_Wrapper_Runtime_Static.h:71
HepMC3::HEPEVT_Wrapper_Runtime_Static::event_number
static int event_number()
Get event number.
Definition HEPEVT_Wrapper_Runtime_Static.h:61
HepMC3::HEPEVT_Wrapper_Runtime_Static::last_parent
static int last_parent(const int index)
Get index of last mother.
Definition HEPEVT_Wrapper_Runtime_Static.h:66
HepMC3::HEPEVT_Wrapper_Runtime_Static::set_mass
static void set_mass(const int index, double mass)
Set mass.
Definition HEPEVT_Wrapper_Runtime_Static.h:194
HepMC3::HEPEVT_Wrapper_Runtime_Static::id
static int id(const int index)
Get PDG particle id.
Definition HEPEVT_Wrapper_Runtime_Static.h:64
HepMC3::HEPEVT_Wrapper_Runtime_Static::number_children_exact
static int number_children_exact(const int index)
Get number of children by counting.
Definition HEPEVT_Wrapper_Runtime_Static.h:164
HepMC3::HEPEVT_Wrapper_Runtime_Static::set_event_number
static void set_event_number(const int evtno)
Set event number.
Definition HEPEVT_Wrapper_Runtime_Static.h:81
HepMC3::HEPEVT_Wrapper_Runtime_Static::set_id
static void set_id(const int index, const int id)
Set PDG particle id.
Definition HEPEVT_Wrapper_Runtime_Static.h:84
HepMC3::HEPEVT_Wrapper_Runtime_Static::x
static double x(const int index)
Get X Production vertex.
Definition HEPEVT_Wrapper_Runtime_Static.h:74
HepMC3::HEPEVT_Wrapper_Runtime_Static::y
static double y(const int index)
Get Y Production vertex.
Definition HEPEVT_Wrapper_Runtime_Static.h:75
HepMC3::HEPEVT_Wrapper_Runtime_Static::first_child
static int first_child(const int index)
Get index of 1st daughter.
Definition HEPEVT_Wrapper_Runtime_Static.h:67
HepMC3::HEPEVT_Wrapper_Runtime_Static::number_entries
static int number_entries()
Get number of entries.
Definition HEPEVT_Wrapper_Runtime_Static.h:62
HepMC3::HEPEVT_Wrapper_Runtime_Static::first_parent
static int first_parent(const int index)
Get index of 1st mother.
Definition HEPEVT_Wrapper_Runtime_Static.h:65
HepMC3::HEPEVT_Wrapper_Runtime_Static::last_child
static int last_child(const int index)
Get index of last daughter.
Definition HEPEVT_Wrapper_Runtime_Static.h:68
HepMC3::HEPEVT_Wrapper_Runtime_Static::m_hepevtptr
static HEPMC3_EXPORT_API std::shared_ptr< struct HEPEVT_Pointers< double > > m_hepevtptr
Fortran common block HEPEVT.
Definition HEPEVT_Wrapper_Runtime_Static.h:51
HepMC3::HEPEVT_Wrapper_Runtime_Static::number_parents
static int number_parents(const int index)
Get number of parents.
Definition HEPEVT_Wrapper_Runtime_Static.h:153
HepMC3::HEPEVT_Wrapper_Runtime_Static::t
static double t(const int index)
Get production time.
Definition HEPEVT_Wrapper_Runtime_Static.h:77
HepMC3::HEPEVT_Wrapper_Runtime_Static::py
static double py(const int index)
Get Y momentum.
Definition HEPEVT_Wrapper_Runtime_Static.h:70
HepMC3
HepMC3 main namespace.
Definition AnalysisExample.h:24
HepMC3::HEPEVT_to_GenEvent_static
bool HEPEVT_to_GenEvent_static(GenEvent *evt)
Converts HEPEVT into GenEvent.
Definition HEPEVT_Helpers.h:258
HepMC3::GenEvent_to_HEPEVT_static
bool GenEvent_to_HEPEVT_static(const GenEvent *evt)
Converts GenEvent into HEPEVT.
Definition HEPEVT_Helpers.h:330