EvtGen 2.2.0
Monte Carlo generator of particle decays, in particular the weak decays of heavy flavour particles such as B mesons.
Loading...
Searching...
No Matches
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
22
23#include "EvtGenBase/EvtPDL.hh"
25
27 m_theEvent( nullptr ), m_translation( 0.0, 0.0, 0.0, 0.0 )
28{
29}
30
35
37{
38 if ( m_theEvent != nullptr ) {
39 m_theEvent->clear();
40 delete m_theEvent;
41 m_theEvent = nullptr;
42 }
43}
44
46{
47 EvtVector4R origin( 0.0, 0.0, 0.0, 0.0 );
48 this->constructEvent( baseParticle, origin );
49}
50
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
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 ) {
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
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
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}
HepMC3::GenVertexPtr GenVertexPtr
GenVertexPtr newGenVertexPtr(const FourVector &pos=FourVector::ZERO_VECTOR())
HepMC3::GenEvent GenEvent
GenParticlePtr newGenParticlePtr(const FourVector &mom=FourVector::ZERO_VECTOR(), int pid=0, int status=0)
HepMC3::GenParticlePtr GenParticlePtr
HepMC3::FourVector FourVector
GenEvent * m_theEvent
EvtVector4R m_translation
GenParticlePtr createGenParticle(EvtParticle *theParticle, int frameType)
void constructEvent(EvtParticle *baseParticle)
FourVector getVertexCoord(EvtParticle *theParticle)
void addVertex(EvtParticle *inEvtParticle, GenParticlePtr inGenParticle)
virtual ~EvtHepMCEvent()
static int getStdHep(EvtId id)
Definition EvtPDL.cpp:356
EvtId getId() const
EvtVector4R getP4Restframe() const
const EvtVector4R & getP4() const
EvtParticle * getDaug(const int i)
size_t getNDaug() const
EvtVector4R getP4Lab() const
EvtVector4R get4Pos() const
double get(int i) const