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"
16#include "HepMC3TestUtils.h"
17using namespace HepMC3;
18
19GenEvent 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
49int main()
50{
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}
Definition of class GenEvent.
Definition of class GenParticle.
Definition of class GenVertex.
Definition of class HEPEVT_Wrapper.
#define HEPMC3_HEPEVT_NMXHEP
Definition of class HEPEVT_Wrapper_Runtime.
Definition of class HEPEVT_Wrapper_Runtime_Static.
Definition of class HEPEVT_Wrapper_Template.
Definition of class WriterAscii.
Generic 4-vector.
Definition: FourVector.h:36
Stores event-related information.
Definition: GenEvent.h:41
void add_vertex(GenVertexPtr v)
Add vertex.
Definition: GenEvent.cc:96
void set_run_info(std::shared_ptr< GenRunInfo > run)
Set the GenRunInfo object by smart pointer.
Definition: GenEvent.h:141
const std::vector< ConstGenParticlePtr > & particles() const
Get list of particles (const)
Definition: GenEvent.cc:39
static bool HEPEVT_to_GenEvent(GenEvent *evt)
Convert HEPEVT to GenEvent.
static void print_hepevt(std::ostream &ostr=std::cout)
Print information from HEPEVT common block.
static void set_max_number_entries(unsigned int size)
Set block size.
static void set_hepevt_address(char *c)
Set Fortran block address.
An interface to HEPEVT common block implemented to deal with varying block size in runtime.
bool HEPEVT_to_GenEvent(GenEvent *evt) const
Convert HEPEVT to GenEvent.
bool GenEvent_to_HEPEVT(const GenEvent *evt)
Convert GenEvent to HEPEVT.
void allocate_internal_storage()
Allocates m_internal_storage storage in smart pointer to hold HEPEVT of fixed size.
void set_max_number_entries(unsigned int size)
Set block size.
void set_hepevt_address(char *c)
Set Fortran block address.
void copy_to_internal_storage(char *c, int N)
Copies the content of foreight common block into the internal storage.
An interface to HEPEVT common block implemented as template class.
bool HEPEVT_to_GenEvent(GenEvent *evt) const
Convert HEPEVT to GenEvent.
void allocate_internal_storage()
Allocates m_internal_storage storage in smart pointer to hold HEPEVT of fixed size.
void set_hepevt_address(char *c)
Set Fortran block address.
void copy_to_internal_storage(char *c, int N)
Copies the content of foreight common block into the internal storage.
static bool HEPEVT_to_GenEvent(GenEvent *evt)
Convert HEPEVT to GenEvent.
static void set_hepevt_address(char *c)
Set Fortran block address.
HepMC3 main namespace.
C structure representing Fortran common block HEPEVT T. Sjöstrand et al., "A proposed standard event ...