EvtGen
2.2.0
Monte Carlo generator of particle decays, in particular the weak decays of heavy flavour particles such as B mesons.
Toggle main menu visibility
Loading...
Searching...
No Matches
src
EvtGenBase
EvtHepMCEvent.cpp
Go to the documentation of this file.
1
2
/***********************************************************************
3
* Copyright 1998-2020 CERN for the benefit of the EvtGen authors *
4
* *
5
* This file is part of EvtGen. *
6
* *
7
* EvtGen is free software: you can redistribute it and/or modify *
8
* it under the terms of the GNU General Public License as published by *
9
* the Free Software Foundation, either version 3 of the License, or *
10
* (at your option) any later version. *
11
* *
12
* EvtGen is distributed in the hope that it will be useful, *
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15
* GNU General Public License for more details. *
16
* *
17
* You should have received a copy of the GNU General Public License *
18
* along with EvtGen. If not, see <https://www.gnu.org/licenses/>. *
19
***********************************************************************/
20
21
#include "
EvtGenBase/EvtHepMCEvent.hh
"
22
23
#include "
EvtGenBase/EvtPDL.hh
"
24
#include "
EvtGenBase/EvtParticle.hh
"
25
26
EvtHepMCEvent::EvtHepMCEvent
() :
27
m_theEvent
( nullptr ),
m_translation
( 0.0, 0.0, 0.0, 0.0 )
28
{
29
}
30
31
EvtHepMCEvent::~EvtHepMCEvent
()
32
{
33
this->
deleteEvent
();
34
}
35
36
void
EvtHepMCEvent::deleteEvent
()
37
{
38
if
(
m_theEvent
!=
nullptr
) {
39
m_theEvent
->clear();
40
delete
m_theEvent
;
41
m_theEvent
=
nullptr
;
42
}
43
}
44
45
void
EvtHepMCEvent::constructEvent
(
EvtParticle
* baseParticle )
46
{
47
EvtVector4R
origin( 0.0, 0.0, 0.0, 0.0 );
48
this->
constructEvent
( baseParticle, origin );
49
}
50
51
void
EvtHepMCEvent::constructEvent
(
EvtParticle
* baseParticle,
52
EvtVector4R
& translation )
53
{
54
// This class does not take ownership of the base particle pointer.
55
// Rather, it uses the base particle to construct the event.
56
57
this->
deleteEvent
();
58
if
( baseParticle ==
nullptr
) {
59
return
;
60
}
61
62
m_theEvent
=
new
GenEvent
( Units::GEV, Units::MM );
63
m_translation
= translation;
64
65
// Use the recursive function addVertex to add a vertex with incoming/outgoing
66
// particles. Adds a new vertex for any EvtParticles with decay daughters.
67
// All particles are in the rest frame of the base particle ("lab frame").
68
69
GenParticlePtr
hepMCGenParticle =
70
this->
createGenParticle
( baseParticle,
EvtHepMCEvent::LAB
);
71
72
this->
addVertex
( baseParticle, hepMCGenParticle );
73
}
74
75
GenParticlePtr
EvtHepMCEvent::createGenParticle
(
EvtParticle
* theParticle,
76
int
frameType )
77
{
78
// Create an HepMC GenParticle, with the 4-momenta in the frame given by the frameType integer
79
GenParticlePtr
genParticle{
nullptr
};
80
81
if
( theParticle !=
nullptr
) {
82
// Set the particle status integer to either stable or decayed
83
int
status(
EvtHepMCEvent::STABLE
);
84
int
nDaug = theParticle->
getNDaug
();
85
if
( nDaug > 0 ) {
86
status =
EvtHepMCEvent::DECAYED
;
87
}
88
89
// Get the 4-momentum (E, px, py, pz) for the EvtParticle.
90
EvtVector4R
p4( 0.0, 0.0, 0.0, 0.0 );
91
92
if
( frameType ==
EvtHepMCEvent::RESTFRAME
) {
93
p4 = theParticle->
getP4Restframe
();
94
}
else
if
( frameType ==
EvtHepMCEvent::LAB
) {
95
p4 = theParticle->
getP4Lab
();
96
}
else
{
97
p4 = theParticle->
getP4
();
98
}
99
100
// Convert this to the HepMC 4-momentum
101
double
E = p4.
get
( 0 );
102
double
px = p4.
get
( 1 );
103
double
py = p4.
get
( 2 );
104
double
pz = p4.
get
( 3 );
105
106
FourVector
hepMC_p4( px, py, pz, E );
107
108
// Get the particle PDG integer id
109
int
PDGInt =
EvtPDL::getStdHep
( theParticle->
getId
() );
110
111
genParticle =
newGenParticlePtr
( hepMC_p4, PDGInt, status );
112
}
113
114
return
genParticle;
115
}
116
117
void
EvtHepMCEvent::addVertex
(
EvtParticle
* inEvtParticle,
118
GenParticlePtr
inGenParticle )
119
{
120
// This is a recursive function that adds GenVertices to the GenEvent for
121
// the incoming EvtParticle and its daughters. We use two separate
122
// pointers for the EvtParticle and GenParticle information: the former
123
// to obtain the PDGId, 4-momenta, daughter and vertex positions, the latter to
124
// set the incoming particle to the vertex. Note that the outgoing particle for
125
// one vertex might be the incoming particle for another vertex - this needs to
126
// be the same GenParticle pointer, hence the reason for using it as a 2nd argument
127
// in this function.
128
129
if
(
m_theEvent
==
nullptr
|| inEvtParticle ==
nullptr
||
130
inGenParticle ==
nullptr
) {
131
return
;
132
}
133
134
// Create the decay vertex
135
FourVector
vtxCoord = this->
getVertexCoord
( inEvtParticle );
136
GenVertexPtr
theVertex =
newGenVertexPtr
( vtxCoord );
137
138
// Add the vertex to the event
139
m_theEvent
->add_vertex( theVertex );
140
141
// Set the incoming particle
142
theVertex->add_particle_in( inGenParticle );
143
144
// Set the outgoing particles (decay products)
145
int
nDaug = inEvtParticle->
getNDaug
();
146
int
iDaug( 0 );
147
// Loop over the daughters
148
for
( iDaug = 0; iDaug < nDaug; iDaug++ ) {
149
EvtParticle
* evtDaughter = inEvtParticle->
getDaug
( iDaug );
150
GenParticlePtr
genDaughter =
151
this->
createGenParticle
( evtDaughter,
EvtHepMCEvent::LAB
);
152
153
if
( genDaughter !=
nullptr
) {
154
// Add a new GenParticle (outgoing) particle daughter to the vertex
155
theVertex->add_particle_out( genDaughter );
156
157
// Find out if the daughter also has decay products.
158
// If so, recursively run this function again.
159
int
nDaugProducts = evtDaughter->
getNDaug
();
160
161
if
( nDaugProducts > 0 ) {
162
// Recursively process daughter particles and add their vertices to the event
163
this->
addVertex
( evtDaughter, genDaughter );
164
165
}
// Have daughter products
166
167
}
// hepMCDaughter != 0
168
169
}
// Loop over daughters
170
}
171
172
FourVector
EvtHepMCEvent::getVertexCoord
(
EvtParticle
* theParticle )
173
{
174
FourVector
vertexCoord( 0.0, 0.0, 0.0, 0.0 );
175
176
if
( theParticle !=
nullptr
&& theParticle->
getNDaug
() != 0 ) {
177
// Get the position (t,x,y,z) of the EvtParticle, offset by the translation vector.
178
// This position will be the point where the particle decays. So we ask
179
// the position of the (1st) daughter particle.
180
EvtParticle
* daugParticle = theParticle->
getDaug
( 0 );
181
182
if
( daugParticle !=
nullptr
) {
183
EvtVector4R
vtxPosition = daugParticle->
get4Pos
() +
m_translation
;
184
185
// Create the HepMC 4 vector of the position (x,y,z,t)
186
vertexCoord.setX( vtxPosition.
get
( 1 ) );
187
vertexCoord.setY( vtxPosition.
get
( 2 ) );
188
vertexCoord.setZ( vtxPosition.
get
( 3 ) );
189
vertexCoord.setT( vtxPosition.
get
( 0 ) );
190
}
191
}
192
193
return
vertexCoord;
194
}
EvtHepMCEvent.hh
GenVertexPtr
HepMC3::GenVertexPtr GenVertexPtr
Definition
EvtHepMCEvent.hh:33
newGenVertexPtr
GenVertexPtr newGenVertexPtr(const FourVector &pos=FourVector::ZERO_VECTOR())
Definition
EvtHepMCEvent.hh:43
GenEvent
HepMC3::GenEvent GenEvent
Definition
EvtHepMCEvent.hh:34
newGenParticlePtr
GenParticlePtr newGenParticlePtr(const FourVector &mom=FourVector::ZERO_VECTOR(), int pid=0, int status=0)
Definition
EvtHepMCEvent.hh:37
GenParticlePtr
HepMC3::GenParticlePtr GenParticlePtr
Definition
EvtHepMCEvent.hh:32
FourVector
HepMC3::FourVector FourVector
Definition
EvtHepMCEvent.hh:35
EvtPDL.hh
EvtParticle.hh
EvtHepMCEvent::m_theEvent
GenEvent * m_theEvent
Definition
EvtHepMCEvent.hh:120
EvtHepMCEvent::m_translation
EvtVector4R m_translation
Definition
EvtHepMCEvent.hh:121
EvtHepMCEvent::RESTFRAME
@ RESTFRAME
Definition
EvtHepMCEvent.hh:83
EvtHepMCEvent::LAB
@ LAB
Definition
EvtHepMCEvent.hh:84
EvtHepMCEvent::STABLE
@ STABLE
Definition
EvtHepMCEvent.hh:90
EvtHepMCEvent::DECAYED
@ DECAYED
Definition
EvtHepMCEvent.hh:91
EvtHepMCEvent::EvtHepMCEvent
EvtHepMCEvent()
Definition
EvtHepMCEvent.cpp:26
EvtHepMCEvent::createGenParticle
GenParticlePtr createGenParticle(EvtParticle *theParticle, int frameType)
Definition
EvtHepMCEvent.cpp:75
EvtHepMCEvent::constructEvent
void constructEvent(EvtParticle *baseParticle)
Definition
EvtHepMCEvent.cpp:45
EvtHepMCEvent::getVertexCoord
FourVector getVertexCoord(EvtParticle *theParticle)
Definition
EvtHepMCEvent.cpp:172
EvtHepMCEvent::addVertex
void addVertex(EvtParticle *inEvtParticle, GenParticlePtr inGenParticle)
Definition
EvtHepMCEvent.cpp:117
EvtHepMCEvent::deleteEvent
void deleteEvent()
Definition
EvtHepMCEvent.cpp:36
EvtHepMCEvent::~EvtHepMCEvent
virtual ~EvtHepMCEvent()
Definition
EvtHepMCEvent.cpp:31
EvtPDL::getStdHep
static int getStdHep(EvtId id)
Definition
EvtPDL.cpp:356
EvtParticle
Definition
EvtParticle.hh:45
EvtParticle::getId
EvtId getId() const
Definition
EvtParticle.cpp:124
EvtParticle::getP4Restframe
EvtVector4R getP4Restframe() const
Definition
EvtParticle.cpp:788
EvtParticle::getP4
const EvtVector4R & getP4() const
Definition
EvtParticle.cpp:144
EvtParticle::getDaug
EvtParticle * getDaug(const int i)
Definition
EvtParticle.hh:173
EvtParticle::getNDaug
size_t getNDaug() const
Definition
EvtParticle.cpp:154
EvtParticle::getP4Lab
EvtVector4R getP4Lab() const
Definition
EvtParticle.cpp:756
EvtParticle::get4Pos
EvtVector4R get4Pos() const
Definition
EvtParticle.cpp:793
EvtVector4R
Definition
EvtVector4R.hh:29
EvtVector4R::get
double get(int i) const
Definition
EvtVector4R.hh:163
Generated by
1.17.0