19#include "GaudiKernel/ISvcLocator.h"
22#include "CLHEP/Units/SystemOfUnits.h"
23#include "CLHEP/Units/PhysicalConstants.h"
25#include "CLHEP/Vector/LorentzVector.h"
26#include "CLHEP/Random/RandFlat.h"
30#include "G4RunManager.hh"
31#include "G4ParticleDefinition.hh"
32#include "G4DecayTable.hh"
33#include "G4DecayProducts.hh"
38 constexpr double s_speedOfLightSI = CLHEP::c_light*CLHEP::s/CLHEP::mm;
54 m_pdgToG4Conv(
"iFatras::PDGToG4Particle/PDGToG4ParticleConverter"),
59 declareProperty(
"ParticleBroker",
m_particleBroker,
"ISF Particle Broker Svc");
60 declareProperty(
"ParticleTruthSvc",
m_truthRecordSvc,
"ISF Particle Truth Svc");
62 declareProperty(
"RandomNumberService",
m_rndmSvc,
"Random number generator");
63 declareProperty(
"RandomStreamName",
m_randomEngineName,
"Name of the random number stream");
64 declareProperty(
"G4RandomStreamName",
m_G4RandomEngineName,
"Name of the random number stream for G4 tools");
96 return StatusCode::FAILURE;
100 return StatusCode::FAILURE;
104 if (
m_rndmSvc.retrieve().isFailure() ) {
106 return StatusCode::FAILURE;
112 return StatusCode::FAILURE;
121 return StatusCode::FAILURE;
123 CLHEP::HepRandom::setTheEngine(engine);
128 return StatusCode::FAILURE;
138 return StatusCode::SUCCESS;
149 return StatusCode::SUCCESS;
158 if (!g4mgr)
ATH_MSG_WARNING(
"initialization of G4RunManager failed in G4ParticleDecayHelper" );
162 G4ParticleDefinition* pDef =
m_pdgToG4Conv->getParticleDefinition(pdgCode);
165 bool isStable =
true;
168 ATH_MSG_WARNING(
"[ decay ] could not find particle properties" <<
" for PDG code " << pdgCode );
172 isStable = pDef->GetPDGStable();
174 if ( std::abs(pdgCode) == 13) isStable =
true;
176 if (isStable)
return -1.;
178 double mass = pDef->GetPDGMass();
180 CLHEP::HepLorentzVector particleMom( isp.
momentum().x(),
183 sqrt(isp.
momentum().mag2()+mass*mass) );
186 double tau = pDef->GetPDGLifeTime()*1e-9;
188 double lifeTime = -tau*log(CLHEP::RandFlat::shoot(
m_randomEngine));
191 lifeTime*s_speedOfLightSI*particleMom.gamma()*particleMom.beta();
198 double timeStamp)
const
204 ATH_MSG_DEBUG(
"[ decay ] calling G4ParticleDecayCreator with " << particleToDecay );
220 if (!decayProducts.size()) {
222 <<
" decay products for particle with PDG code "
223 << particle.pdgCode() );
226 std::ostringstream productSummaryString;
227 productSummaryString <<
"[ decay ] products:";
230 productSummaryString <<
" - " << (*decayProduct) <<
'\n';
235 if (particle.getUserInformation()) validInfo->
setGeneration(particle.getUserInformation()->generation()+1);
237 decayProduct->setUserInformation(validInfo);
240 decayProduct->setNextGeoID( particle.nextGeoID() );
247 particle.nextGeoID(),
264 m_validationTool->saveISFVertexInfo(
process,particle.position(),particle,particle.momentum(),nMom,decayProducts);
271std::vector<ISF::ISFParticle*>
275 double timeStamp)
const
279 std::vector<ISF::ISFParticle*> children;
283 if (!g4mgr)
ATH_MSG_WARNING(
"initialization of G4RunManager failed in G4ParticleDecayHelper" );
289 if( msgLvl(MSG::VERBOSE)) {
295 int pdgCode = parent.pdgCode();
297 G4ParticleDefinition* pDef =
m_pdgToG4Conv->getParticleDefinition( pdgCode);
301 <<
" for particle with pdg id " << pdgCode );
305 ATH_MSG_DEBUG(
"[ decay ] Decaying " << pDef->GetParticleName() );
307 G4DecayTable* dt = pDef->GetDecayTable();
311 <<
" particle with pdg id " << pdgCode );
315 if( msgLvl(MSG::VERBOSE))
321 G4VDecayChannel* channel = dt->SelectADecayChannel();
325 <<
" particle with pdg id " << pdgCode );
329 if( msgLvl(MSG::DEBUG))
335 G4DecayProducts* products = channel->DecayIt();
339 <<
" for particle with pdg id " << pdgCode );
343 if( msgLvl(MSG::VERBOSE))
346 products->DumpInfo();
350 double parentE = std::sqrt( std::pow( pDef->GetPDGMass(), 2) +
353 products->Boost( momentum.x()/parentE,
354 momentum.y()/parentE,
355 momentum.z()/parentE);
356 if( msgLvl(MSG::VERBOSE))
359 products->DumpInfo();
362 G4int nProducts = products->entries();
363 for( G4int i=0; i < nProducts; ++i)
365 G4DynamicParticle* prod = products->PopProducts();
373 const G4ThreeVector &mom= prod->GetMomentum();
388 children.push_back( childParticle);
398 return helper_nc->fastG4RunManager();
401 return g4runManager ? true :
false;
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_WARNING(x)
Define macros for attributes used to control the static checker.
#define ATLAS_NOT_THREAD_SAFE
getNoisyStrip() Find noisy strips from hitmaps and write out into xml/db formats
#define ATLAS_THREAD_SAFE
The generic ISF particle definition,.
const Amg::Vector3D & momentum() const
The current momentum vector of the ISFParticle.
int pdgCode() const
PDG value.
Interface class for all truth incidents handled by the ISF.
void updateChildParticleProperties()
Update the id and particleLink properties of the child particles (to be called after registerTruthInc...
Each ISFParticle carries a pointer to this class.
void setGeneration(int gen)
void setProcess(int proc)
bool initG4RunManager() const
initialize G4RunManager on first call if not done by then
std::vector< ISF::ISFParticle * > decayParticle(const ISF::ISFParticle &parent, const Amg::Vector3D &vertex, const Amg::Vector3D &mom, double timeStamp=0) const
decay
std::string m_randomEngineName
Name of the random number stream.
StatusCode finalize()
AlgTool finalize method.
ToolHandle< PDGToG4Particle > m_pdgToG4Conv
Handle for the PDGToG4Particle converter tool.
CLHEP::HepRandomEngine * m_randomEngine
Random engine (updated to streams)
ServiceHandle< IAtRndmGenSvc > m_rndmSvc
Random Svc.
void handleDecayParticles(const ISF::ISFParticle &isp, const ISF::ISFParticleVector &children) const
fill decay products: into broker svc, truth svc
void decay(const ISF::ISFParticle &isp, const Amg::Vector3D &vertex, const Amg::Vector3D &mom, double timeStamp=0) const
decay handling secondaries
ToolHandle< IPhysicsValidationTool > m_validationTool
the ntuple
bool m_validationMode
Validation output with histogram service.
ServiceHandle< ISF::ITruthSvc > m_truthRecordSvc
Truth Svc for truth tree.
G4ParticleDecayHelper(const std::string &, const std::string &, const IInterface *)
AlgTool constructor for ParticleDecayHelper.
double freePath(const ISF::ISFParticle &isp) const
free path estimator (-1 for stable particle)
ToolHandle< ISF::IG4RunManagerHelper > m_g4RunManagerHelper
G4RunManager needs to be initialized before G4 tables are accessed.
StatusCode initialize()
AlgTool initailize method.
ServiceHandle< ISF::IParticleBroker > m_particleBroker
Broker Svc for ISF particles.
std::string m_G4RandomEngineName
Name of the random number stream for G4 tools.
~G4ParticleDecayHelper()
Destructor.
const std::string process
Eigen::Matrix< double, 3, 1 > Vector3D
constexpr int UNDEFINED_ID
constexpr int SIM_STATUS_THRESHOLD
Constant definiting the status threshold for simulated particles, eg. can be used to separate generat...
std::vector< ISF::ISFParticle * > ISFParticleVector
ISFParticle vector.