evtgen is hosted by Hepforge, IPPP Durham
EvtGen  2.0.0
Monte Carlo generator of particle decays, in particular the weak decays of heavy flavour particles such as B mesons.
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 #include "EvtGenBase/EvtPatches.hh"
26 
28  _theEvent( 0 ), _translation( 0.0, 0.0, 0.0, 0.0 )
29 {
30 }
31 
33 {
34  this->deleteEvent();
35 }
36 
38 {
39  if ( _theEvent != 0 ) {
40  _theEvent->clear();
41  delete _theEvent;
42  _theEvent = 0;
43  }
44 }
45 
47 {
48  EvtVector4R origin( 0.0, 0.0, 0.0, 0.0 );
49  this->constructEvent( baseParticle, origin );
50 }
51 
53  EvtVector4R& translation )
54 {
55  // This class does not take ownership of the base particle pointer.
56  // Rather, it uses the base particle to construct the event.
57 
58  this->deleteEvent();
59  if ( baseParticle == 0 ) {
60  return;
61  }
62 
63  _theEvent = new GenEvent( Units::GEV, Units::MM );
64  _translation = translation;
65 
66  // Use the recursive function addVertex to add a vertex with incoming/outgoing
67  // particles. Adds a new vertex for any EvtParticles with decay daughters.
68  // All particles are in the rest frame of the base particle ("lab frame").
69 
70  GenParticlePtr hepMCGenParticle =
71  this->createGenParticle( baseParticle, EvtHepMCEvent::LAB );
72 
73  this->addVertex( baseParticle, hepMCGenParticle );
74 }
75 
77  int frameType )
78 {
79  // Create an HepMC GenParticle, with the 4-momenta in the frame given by the frameType integer
80  GenParticlePtr genParticle{nullptr};
81 
82  if ( theParticle != 0 ) {
83  // Set the particle status integer to either stable or decayed
84  int status( EvtHepMCEvent::STABLE );
85  int nDaug = theParticle->getNDaug();
86  if ( nDaug > 0 ) {
87  status = EvtHepMCEvent::DECAYED;
88  }
89 
90  // Get the 4-momentum (E, px, py, pz) for the EvtParticle.
91  EvtVector4R p4( 0.0, 0.0, 0.0, 0.0 );
92 
93  if ( frameType == EvtHepMCEvent::RESTFRAME ) {
94  p4 = theParticle->getP4Restframe();
95  } else if ( frameType == EvtHepMCEvent::LAB ) {
96  p4 = theParticle->getP4Lab();
97  } else {
98  p4 = theParticle->getP4();
99  }
100 
101  // Convert this to the HepMC 4-momentum
102  double E = p4.get( 0 );
103  double px = p4.get( 1 );
104  double py = p4.get( 2 );
105  double pz = p4.get( 3 );
106 
107  FourVector hepMC_p4( px, py, pz, E );
108 
109  // Get the particle PDG integer id
110  int PDGInt = EvtPDL::getStdHep( theParticle->getId() );
111 
112  genParticle = newGenParticlePtr( hepMC_p4, PDGInt, status );
113  }
114 
115  return genParticle;
116 }
117 
119  GenParticlePtr inGenParticle )
120 {
121  // This is a recursive function that adds GenVertices to the GenEvent for
122  // the incoming EvtParticle and its daughters. We use two separate
123  // pointers for the EvtParticle and GenParticle information: the former
124  // to obtain the PDGId, 4-momenta, daughter and vertex positions, the latter to
125  // set the incoming particle to the vertex. Note that the outgoing particle for
126  // one vertex might be the incoming particle for another vertex - this needs to
127  // be the same GenParticle pointer, hence the reason for using it as a 2nd argument
128  // in this function.
129 
130  if ( _theEvent == 0 || inEvtParticle == 0 || inGenParticle == 0 ) {
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  _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 != 0 ) {
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 != 0 && 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 != 0 ) {
183  EvtVector4R vtxPosition = daugParticle->get4Pos() + _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 }
void constructEvent(EvtParticle *baseParticle)
EvtVector4R _translation
HepMC::GenParticle * GenParticlePtr
GenEvent * _theEvent
EvtVector4R getP4Lab() const
virtual ~EvtHepMCEvent()
void addVertex(EvtParticle *inEvtParticle, GenParticlePtr inGenParticle)
EvtId getId() const
EvtVector4R get4Pos() const
GenParticlePtr createGenParticle(EvtParticle *theParticle, int frameType)
HepMC::FourVector FourVector
GenVertexPtr newGenVertexPtr(const FourVector &pos=FourVector(0.0, 0.0, 0.0, 0.0))
size_t getNDaug() const
double get(int i) const
Definition: EvtVector4R.hh:162
HepMC::GenEvent GenEvent
const EvtVector4R & getP4() const
HepMC::GenVertex * GenVertexPtr
EvtParticle * getDaug(int i)
Definition: EvtParticle.cpp:91
EvtVector4R getP4Restframe() const
GenParticlePtr newGenParticlePtr(const FourVector &mom=FourVector(0.0, 0.0, 0.0, 0.0), int pid=0, int status=0)
FourVector getVertexCoord(EvtParticle *theParticle)
static int getStdHep(EvtId id)
Definition: EvtPDL.cpp:362