HepMC3 event record library
testHEPEVTWrapper1.cc
1 // -*- C++ -*-
2 //
3 // This file is part of HepMC
4 // Copyright (C) 2014-2019 The HepMC collaboration (see AUTHORS for details)
5 //
6 ///We set some non-default value
7 #define HEPMC3_HEPEVT_NMXHEP 4000
8 #include "HepMC3/GenEvent.h"
9 #include "HepMC3/GenVertex.h"
10 #include "HepMC3/GenParticle.h"
11 #include "HepMC3/WriterAscii.h"
15 #include "HepMC3/HEPEVT_Wrapper.h"
16 #include "HepMC3TestUtils.h"
17 using namespace HepMC3;
18 
19 GenEvent generate1() {
20  GenEvent evt;
21  std::shared_ptr<GenRunInfo> run = std::make_shared<GenRunInfo>();
22  evt.set_run_info(run);
23  GenParticlePtr b2 = std::make_shared<GenParticle>( FourVector( 0.0, 0.0, 7000.0, 7000.0 ),2212, 3 );
24  GenParticlePtr b1 = std::make_shared<GenParticle>( FourVector( 0.750, -1.569, 32.191, 32.238), 1, 3 );
25  GenParticlePtr b3 = std::make_shared<GenParticle>( FourVector( 0.750, -1.569, 32.191, -32.238), 1, 3 );
26  GenVertexPtr v1 = std::make_shared<GenVertex>();
27  v1->add_particle_in (b1);
28  v1->add_particle_in(b2);
29  v1->add_particle_out(b3);
30  evt.add_vertex(v1);
31  for (size_t z= 0; z < 5; z++) {
32  std::vector<GenParticlePtr> particles = evt.particles();
33  for (auto p: particles) {
34  if (p->end_vertex()) continue;
35  GenParticlePtr p2 = std::make_shared<GenParticle>( FourVector( 0.0, 0.0, 7000.0+0.01*evt.particles().size(), 7000.0 ),2212, 3 );
36  GenParticlePtr p1 = std::make_shared<GenParticle>( FourVector( 0.750, -1.569, 32.191+0.01*evt.particles().size(), 32.238), 1, 3 );
37  GenVertexPtr v = std::make_shared<GenVertex>();
38  v->add_particle_in (p);
39  v->add_particle_out(p1);
40  v->add_particle_out(p2);
41  evt.add_vertex(v);
42  }
43  }
44  return evt;
45 }
46 
47 
48 
49 int main()
50 {
51  struct HEPEVT_Templated<HEPMC3_HEPEVT_NMXHEP,double> X;
52  GenEvent evt1 = generate1();
55  test1.set_hepevt_address((char*)&X);
56  test1.GenEvent_to_HEPEVT(&evt1);
57 
59  GenEvent evt2;
60  test2.set_hepevt_address((char*)&X);
61  test2.HEPEVT_to_GenEvent(&evt2);
62 
64  GenEvent evt3;
67  test3.HEPEVT_to_GenEvent(&evt3);
68 
69  GenEvent evt4;
74 
75 
76  GenEvent evt5;
79 
80 
81  GenEvent evt6;
83  test6.set_max_number_entries(20000);
86  test6.HEPEVT_to_GenEvent(&evt6);
87 
88 
89  std::shared_ptr<WriterAscii> w1 = std::make_shared<WriterAscii>("testHEPEVTWrapper1output1.txt");
90  w1->write_event(evt1);
91  w1->close();
92  std::shared_ptr<WriterAscii> w2= std::make_shared<WriterAscii>("testHEPEVTWrapper1output2.txt");
93  w2->write_event(evt2);
94  w2->close();
95  std::shared_ptr<WriterAscii> w3= std::make_shared<WriterAscii>("testHEPEVTWrapper1output3.txt");
96  w3->write_event(evt3);
97  w3->close();
98  std::shared_ptr<WriterAscii> w4= std::make_shared<WriterAscii>("testHEPEVTWrapper1output4.txt");
99  w4->write_event(evt4);
100  w4->close();
101  std::shared_ptr<WriterAscii> w5= std::make_shared<WriterAscii>("testHEPEVTWrapper1output5.txt");
102  w5->write_event(evt5);
103  w5->close();
104  std::shared_ptr<WriterAscii> w6= std::make_shared<WriterAscii>("testHEPEVTWrapper1output6.txt");
105  w6->write_event(evt6);
106  w6->close();
107  return COMPARE_ASCII_FILES("testHEPEVTWrapper1output1.txt","testHEPEVTWrapper1output2.txt") +
108  COMPARE_ASCII_FILES("testHEPEVTWrapper1output2.txt","testHEPEVTWrapper1output3.txt") +
109  COMPARE_ASCII_FILES("testHEPEVTWrapper1output3.txt","testHEPEVTWrapper1output4.txt") +
110  COMPARE_ASCII_FILES("testHEPEVTWrapper1output4.txt","testHEPEVTWrapper1output5.txt") +
111  COMPARE_ASCII_FILES("testHEPEVTWrapper1output5.txt","testHEPEVTWrapper1output6.txt")
112  ;
113 }
void copy_to_internal_storage(char *c, int N)
Copies the content of foreight common block into the internal storage.
C structure representing Fortran common block HEPEVT T. Sjöstrand et al., &quot;A proposed standard even...
void add_vertex(GenVertexPtr v)
Add vertex.
Definition: GenEvent.cc:96
void allocate_internal_storage()
Allocates m_internal_storage storage in smart pointer to hold HEPEVT of fixed size.
static void set_hepevt_address(char *c)
Set Fortran block address.
Definition of class GenParticle.
void allocate_internal_storage()
Allocates m_internal_storage storage in smart pointer to hold HEPEVT of fixed size.
bool HEPEVT_to_GenEvent(GenEvent *evt) const
Convert HEPEVT to GenEvent.
#define HEPMC3_HEPEVT_NMXHEP
Definition of class GenVertex.
Definition of class WriterAscii.
An interface to HEPEVT common block implemented to deal with varying block size in runtime...
static void print_hepevt(std::ostream &ostr=std::cout)
Print information from HEPEVT common block.
static void set_hepevt_address(char *c)
Set Fortran block address.
static bool HEPEVT_to_GenEvent(GenEvent *evt)
Convert HEPEVT to GenEvent.
void set_hepevt_address(char *c)
Set Fortran block address.
static void set_max_number_entries(unsigned int size)
Set block size.
Stores event-related information.
Definition: GenEvent.h:41
Generic 4-vector.
Definition: FourVector.h:36
static bool HEPEVT_to_GenEvent(GenEvent *evt)
Convert HEPEVT to GenEvent.
void set_run_info(std::shared_ptr< GenRunInfo > run)
Set the GenRunInfo object by smart pointer.
Definition: GenEvent.h:141
bool HEPEVT_to_GenEvent(GenEvent *evt) const
Convert HEPEVT to GenEvent.
Definition of class HEPEVT_Wrapper_Template.
An interface to HEPEVT common block implemented as template class.
bool GenEvent_to_HEPEVT(const GenEvent *evt)
Convert GenEvent to HEPEVT.
int main(int argc, char **argv)
Definition of class GenEvent.
void set_hepevt_address(char *c)
Set Fortran block address.
void set_max_number_entries(unsigned int size)
Set block size.
Definition of class HEPEVT_Wrapper_Runtime_Static.
const std::vector< ConstGenParticlePtr > & particles() const
Get list of particles (const)
Definition: GenEvent.cc:39
Definition of class HEPEVT_Wrapper_Runtime.
void copy_to_internal_storage(char *c, int N)
Copies the content of foreight common block into the internal storage.
Definition of class HEPEVT_Wrapper.