Changeset View
Changeset View
Standalone View
Standalone View
src/EvtGenBase/EvtHepMCEvent.cpp
Show All 19 Lines | |||||
#include "EvtGenBase/EvtHepMCEvent.hh" | #include "EvtGenBase/EvtHepMCEvent.hh" | ||||
#include "EvtGenBase/EvtPDL.hh" | #include "EvtGenBase/EvtPDL.hh" | ||||
#include "EvtGenBase/EvtParticle.hh" | #include "EvtGenBase/EvtParticle.hh" | ||||
#include "EvtGenBase/EvtPatches.hh" | #include "EvtGenBase/EvtPatches.hh" | ||||
EvtHepMCEvent::EvtHepMCEvent() : | EvtHepMCEvent::EvtHepMCEvent() : | ||||
_theEvent( 0 ), _translation( 0.0, 0.0, 0.0, 0.0 ) | _theEvent( nullptr ), _translation( 0.0, 0.0, 0.0, 0.0 ) | ||||
{ | { | ||||
} | } | ||||
EvtHepMCEvent::~EvtHepMCEvent() | EvtHepMCEvent::~EvtHepMCEvent() | ||||
{ | { | ||||
this->deleteEvent(); | this->deleteEvent(); | ||||
} | } | ||||
void EvtHepMCEvent::deleteEvent() | void EvtHepMCEvent::deleteEvent() | ||||
{ | { | ||||
if ( _theEvent != 0 ) { | if ( _theEvent != nullptr ) { | ||||
_theEvent->clear(); | _theEvent->clear(); | ||||
delete _theEvent; | delete _theEvent; | ||||
_theEvent = 0; | _theEvent = nullptr; | ||||
} | } | ||||
} | } | ||||
void EvtHepMCEvent::constructEvent( EvtParticle* baseParticle ) | void EvtHepMCEvent::constructEvent( EvtParticle* baseParticle ) | ||||
{ | { | ||||
EvtVector4R origin( 0.0, 0.0, 0.0, 0.0 ); | EvtVector4R origin( 0.0, 0.0, 0.0, 0.0 ); | ||||
this->constructEvent( baseParticle, origin ); | this->constructEvent( baseParticle, origin ); | ||||
} | } | ||||
void EvtHepMCEvent::constructEvent( EvtParticle* baseParticle, | void EvtHepMCEvent::constructEvent( EvtParticle* baseParticle, | ||||
EvtVector4R& translation ) | EvtVector4R& translation ) | ||||
{ | { | ||||
// This class does not take ownership of the base particle pointer. | // This class does not take ownership of the base particle pointer. | ||||
// Rather, it uses the base particle to construct the event. | // Rather, it uses the base particle to construct the event. | ||||
this->deleteEvent(); | this->deleteEvent(); | ||||
if ( baseParticle == 0 ) { | if ( baseParticle == nullptr ) { | ||||
return; | return; | ||||
} | } | ||||
_theEvent = new GenEvent( Units::GEV, Units::MM ); | _theEvent = new GenEvent( Units::GEV, Units::MM ); | ||||
_translation = translation; | _translation = translation; | ||||
// Use the recursive function addVertex to add a vertex with incoming/outgoing | // Use the recursive function addVertex to add a vertex with incoming/outgoing | ||||
// particles. Adds a new vertex for any EvtParticles with decay daughters. | // particles. Adds a new vertex for any EvtParticles with decay daughters. | ||||
// All particles are in the rest frame of the base particle ("lab frame"). | // All particles are in the rest frame of the base particle ("lab frame"). | ||||
GenParticlePtr hepMCGenParticle = | GenParticlePtr hepMCGenParticle = | ||||
this->createGenParticle( baseParticle, EvtHepMCEvent::LAB ); | this->createGenParticle( baseParticle, EvtHepMCEvent::LAB ); | ||||
this->addVertex( baseParticle, hepMCGenParticle ); | this->addVertex( baseParticle, hepMCGenParticle ); | ||||
} | } | ||||
GenParticlePtr EvtHepMCEvent::createGenParticle( EvtParticle* theParticle, | GenParticlePtr EvtHepMCEvent::createGenParticle( EvtParticle* theParticle, | ||||
int frameType ) | int frameType ) | ||||
{ | { | ||||
// Create an HepMC GenParticle, with the 4-momenta in the frame given by the frameType integer | // Create an HepMC GenParticle, with the 4-momenta in the frame given by the frameType integer | ||||
GenParticlePtr genParticle{nullptr}; | GenParticlePtr genParticle{nullptr}; | ||||
if ( theParticle != 0 ) { | if ( theParticle != nullptr ) { | ||||
// Set the particle status integer to either stable or decayed | // Set the particle status integer to either stable or decayed | ||||
int status( EvtHepMCEvent::STABLE ); | int status( EvtHepMCEvent::STABLE ); | ||||
int nDaug = theParticle->getNDaug(); | int nDaug = theParticle->getNDaug(); | ||||
if ( nDaug > 0 ) { | if ( nDaug > 0 ) { | ||||
status = EvtHepMCEvent::DECAYED; | status = EvtHepMCEvent::DECAYED; | ||||
} | } | ||||
// Get the 4-momentum (E, px, py, pz) for the EvtParticle. | // Get the 4-momentum (E, px, py, pz) for the EvtParticle. | ||||
Show All 31 Lines | void EvtHepMCEvent::addVertex( EvtParticle* inEvtParticle, | ||||
// the incoming EvtParticle and its daughters. We use two separate | // the incoming EvtParticle and its daughters. We use two separate | ||||
// pointers for the EvtParticle and GenParticle information: the former | // pointers for the EvtParticle and GenParticle information: the former | ||||
// to obtain the PDGId, 4-momenta, daughter and vertex positions, the latter to | // to obtain the PDGId, 4-momenta, daughter and vertex positions, the latter to | ||||
// set the incoming particle to the vertex. Note that the outgoing particle for | // set the incoming particle to the vertex. Note that the outgoing particle for | ||||
// one vertex might be the incoming particle for another vertex - this needs to | // one vertex might be the incoming particle for another vertex - this needs to | ||||
// be the same GenParticle pointer, hence the reason for using it as a 2nd argument | // be the same GenParticle pointer, hence the reason for using it as a 2nd argument | ||||
// in this function. | // in this function. | ||||
if ( _theEvent == 0 || inEvtParticle == 0 || inGenParticle == 0 ) { | if ( _theEvent == nullptr || inEvtParticle == nullptr || | ||||
inGenParticle == nullptr ) { | |||||
return; | return; | ||||
} | } | ||||
// Create the decay vertex | // Create the decay vertex | ||||
FourVector vtxCoord = this->getVertexCoord( inEvtParticle ); | FourVector vtxCoord = this->getVertexCoord( inEvtParticle ); | ||||
GenVertexPtr theVertex = newGenVertexPtr( vtxCoord ); | GenVertexPtr theVertex = newGenVertexPtr( vtxCoord ); | ||||
// Add the vertex to the event | // Add the vertex to the event | ||||
_theEvent->add_vertex( theVertex ); | _theEvent->add_vertex( theVertex ); | ||||
// Set the incoming particle | // Set the incoming particle | ||||
theVertex->add_particle_in( inGenParticle ); | theVertex->add_particle_in( inGenParticle ); | ||||
// Set the outgoing particles (decay products) | // Set the outgoing particles (decay products) | ||||
int nDaug = inEvtParticle->getNDaug(); | int nDaug = inEvtParticle->getNDaug(); | ||||
int iDaug( 0 ); | int iDaug( 0 ); | ||||
// Loop over the daughters | // Loop over the daughters | ||||
for ( iDaug = 0; iDaug < nDaug; iDaug++ ) { | for ( iDaug = 0; iDaug < nDaug; iDaug++ ) { | ||||
EvtParticle* evtDaughter = inEvtParticle->getDaug( iDaug ); | EvtParticle* evtDaughter = inEvtParticle->getDaug( iDaug ); | ||||
GenParticlePtr genDaughter = | GenParticlePtr genDaughter = | ||||
this->createGenParticle( evtDaughter, EvtHepMCEvent::LAB ); | this->createGenParticle( evtDaughter, EvtHepMCEvent::LAB ); | ||||
if ( genDaughter != 0 ) { | if ( genDaughter != nullptr ) { | ||||
// Add a new GenParticle (outgoing) particle daughter to the vertex | // Add a new GenParticle (outgoing) particle daughter to the vertex | ||||
theVertex->add_particle_out( genDaughter ); | theVertex->add_particle_out( genDaughter ); | ||||
// Find out if the daughter also has decay products. | // Find out if the daughter also has decay products. | ||||
// If so, recursively run this function again. | // If so, recursively run this function again. | ||||
int nDaugProducts = evtDaughter->getNDaug(); | int nDaugProducts = evtDaughter->getNDaug(); | ||||
if ( nDaugProducts > 0 ) { | if ( nDaugProducts > 0 ) { | ||||
// Recursively process daughter particles and add their vertices to the event | // Recursively process daughter particles and add their vertices to the event | ||||
this->addVertex( evtDaughter, genDaughter ); | this->addVertex( evtDaughter, genDaughter ); | ||||
} // Have daughter products | } // Have daughter products | ||||
} // hepMCDaughter != 0 | } // hepMCDaughter != 0 | ||||
} // Loop over daughters | } // Loop over daughters | ||||
} | } | ||||
FourVector EvtHepMCEvent::getVertexCoord( EvtParticle* theParticle ) | FourVector EvtHepMCEvent::getVertexCoord( EvtParticle* theParticle ) | ||||
{ | { | ||||
FourVector vertexCoord( 0.0, 0.0, 0.0, 0.0 ); | FourVector vertexCoord( 0.0, 0.0, 0.0, 0.0 ); | ||||
if ( theParticle != 0 && theParticle->getNDaug() != 0 ) { | if ( theParticle != nullptr && theParticle->getNDaug() != 0 ) { | ||||
// Get the position (t,x,y,z) of the EvtParticle, offset by the translation vector. | // Get the position (t,x,y,z) of the EvtParticle, offset by the translation vector. | ||||
// This position will be the point where the particle decays. So we ask | // This position will be the point where the particle decays. So we ask | ||||
// the position of the (1st) daughter particle. | // the position of the (1st) daughter particle. | ||||
EvtParticle* daugParticle = theParticle->getDaug( 0 ); | EvtParticle* daugParticle = theParticle->getDaug( 0 ); | ||||
if ( daugParticle != 0 ) { | if ( daugParticle != nullptr ) { | ||||
EvtVector4R vtxPosition = daugParticle->get4Pos() + _translation; | EvtVector4R vtxPosition = daugParticle->get4Pos() + _translation; | ||||
// Create the HepMC 4 vector of the position (x,y,z,t) | // Create the HepMC 4 vector of the position (x,y,z,t) | ||||
vertexCoord.setX( vtxPosition.get( 1 ) ); | vertexCoord.setX( vtxPosition.get( 1 ) ); | ||||
vertexCoord.setY( vtxPosition.get( 2 ) ); | vertexCoord.setY( vtxPosition.get( 2 ) ); | ||||
vertexCoord.setZ( vtxPosition.get( 3 ) ); | vertexCoord.setZ( vtxPosition.get( 3 ) ); | ||||
vertexCoord.setT( vtxPosition.get( 0 ) ); | vertexCoord.setT( vtxPosition.get( 0 ) ); | ||||
} | } | ||||
} | } | ||||
return vertexCoord; | return vertexCoord; | ||||
} | } |