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"
47 m_particleBroker(
"ISF_ParticleBroker",
n),
48 m_truthRecordSvc(
"ISF_TruthRecordSvc",
n),
49 m_rndmSvc(
"AtDSFMTGenSvc",
n),
51 m_randomEngineName(
"FatrasRnd"),
52 m_G4RandomEngineName(
"FatrasG4"),
53 m_g4RunManagerHelper(
"iGeant4::G4RunManagerHelper/G4RunManagerHelper"),
54 m_pdgToG4Conv(
"iFatras::PDGToG4Particle/PDGToG4ParticleConverter"),
55 m_validationMode(false),
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");
92 ATH_CHECK( m_validationTool.retrieve( DisableTool{ m_validationTool.empty() || !m_validationMode } ) );
94 if ( m_particleBroker.retrieve().isFailure()){
96 return StatusCode::FAILURE;
98 if (m_truthRecordSvc.retrieve().isFailure()){
100 return StatusCode::FAILURE;
104 if ( m_rndmSvc.retrieve().isFailure() ) {
106 return StatusCode::FAILURE;
109 m_randomEngine = m_rndmSvc->GetEngine(m_randomEngineName);
110 if (!m_randomEngine) {
111 ATH_MSG_FATAL(
"Could not get random engine '" << m_randomEngineName <<
"'" );
112 return StatusCode::FAILURE;
118 CLHEP::HepRandomEngine* engine = m_rndmSvc->GetEngine(m_G4RandomEngineName);
120 ATH_MSG_FATAL(
"Could not get random engine '" << m_G4RandomEngineName <<
"'" );
121 return StatusCode::FAILURE;
123 CLHEP::HepRandom::setTheEngine(engine);
126 if (m_g4RunManagerHelper.retrieve().isFailure()) {
127 ATH_MSG_FATAL(
"Could not get g4RunManagerHelper '" << m_g4RunManagerHelper <<
"'" );
128 return StatusCode::FAILURE;
130 std::cout <<
"f4dec: g4RunManagerHelper retrieved:"<< m_g4RunManagerHelper<< std::endl;
135 m_pdgToG4Conv.disable();
138 return StatusCode::SUCCESS;
149 return StatusCode::SUCCESS;
157 bool g4mgr = initG4RunManager();
158 if (!g4mgr)
ATH_MSG_WARNING(
"initialization of G4RunManager failed in G4ParticleDecayHelper" );
160 if (!m_pdgToG4Conv && m_pdgToG4Conv.retrieve().isFailure())
return -1.;
162 G4ParticleDefinition* pDef = m_pdgToG4Conv->getParticleDefinition(pdgCode);
168 ATH_MSG_WARNING(
"[ decay ] could not find particle properties" <<
" for PDG code " << pdgCode );
174 if ( std::abs(pdgCode) == 13)
isStable =
true;
178 double mass = pDef->GetPDGMass();
180 CLHEP::HepLorentzVector particleMom( isp.
momentum().x(),
186 double tau = pDef->GetPDGLifeTime()*1
e-9;
188 double lifeTime = -tau*
log(CLHEP::RandFlat::shoot(m_randomEngine));
191 lifeTime*s_speedOfLightSI*particleMom.gamma()*particleMom.beta();
204 ATH_MSG_DEBUG(
"[ decay ] calling G4ParticleDecayCreator with " << particleToDecay );
210 handleDecayParticles(particleToDecay,decayProducts);
220 if (!decayProducts.size()) {
222 <<
" decay products for particle with PDG code "
226 std::ostringstream productSummaryString;
227 productSummaryString <<
"[ decay ] products:";
230 productSummaryString <<
" - " << (*decayProduct) <<
'\n';
232 if (m_validationMode) {
237 decayProduct->setUserInformation(validInfo);
240 decayProduct->setNextGeoID(
particle.nextGeoID() );
249 m_truthRecordSvc->registerTruthIncident( truth);
257 m_particleBroker->push(decayProduct, &
particle);
262 if (m_validationMode && m_validationTool.isEnabled()) {
271 std::vector<ISF::ISFParticle*>
279 std::vector<ISF::ISFParticle*>
children;
282 bool g4mgr = initG4RunManager();
283 if (!g4mgr)
ATH_MSG_WARNING(
"initialization of G4RunManager failed in G4ParticleDecayHelper" );
285 if (!m_pdgToG4Conv) {
287 if( m_pdgToG4Conv.retrieve().isFailure())
return children;
291 m_pdgToG4Conv->printListOfParticles(
true);
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 );
321 G4VDecayChannel*
channel =
dt->SelectADecayChannel();
325 <<
" particle with pdg id " << pdgCode );
335 G4DecayProducts* products =
channel->DecayIt();
339 <<
" for particle with pdg id " << pdgCode );
346 products->DumpInfo();
350 double parentE = std::sqrt(
std::pow( pDef->GetPDGMass(), 2) +
353 products->Boost(
momentum.x()/parentE,
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();
398 return helper_nc->fastG4RunManager();
401 return g4runManager ? true :
false;