ATLAS Offline Software
Loading...
Searching...
No Matches
iFatras::G4ParticleDecayHelper Class Reference

This Tool is a helper tool wrapping the IParticleDecayCreator, and organised the flight distance to. More...

#include <G4ParticleDecayHelper.h>

Inheritance diagram for iFatras::G4ParticleDecayHelper:
Collaboration diagram for iFatras::G4ParticleDecayHelper:

Public Member Functions

 G4ParticleDecayHelper (const std::string &, const std::string &, const IInterface *)
 AlgTool constructor for ParticleDecayHelper.
 ~G4ParticleDecayHelper ()
 Destructor.
StatusCode initialize ()
 AlgTool initailize method.
StatusCode finalize ()
 AlgTool finalize method.
double freePath (const ISF::ISFParticle &isp) const
 free path estimator (-1 for stable particle)
void decay (const ISF::ISFParticle &isp, const Amg::Vector3D &vertex, const Amg::Vector3D &mom, double timeStamp=0) const
 decay handling secondaries
std::vector< ISF::ISFParticle * > decayParticle (const ISF::ISFParticle &parent, const Amg::Vector3D &vertex, const Amg::Vector3D &mom, double timeStamp=0) const
 decay

Private Member Functions

bool initG4RunManager () const
 initialize G4RunManager on first call if not done by then
void handleDecayParticles (const ISF::ISFParticle &isp, const ISF::ISFParticleVector &children) const
 fill decay products: into broker svc, truth svc

Private Attributes

ServiceHandle< ISF::IParticleBrokerm_particleBroker
 Broker Svc for ISF particles.
ServiceHandle< ISF::ITruthSvcm_truthRecordSvc
 Truth Svc for truth tree.
ServiceHandle< IAtRndmGenSvcm_rndmSvc
 Random Svc.
CLHEP::HepRandomEngine * m_randomEngine
 Random engine (updated to streams)
std::string m_randomEngineName
 Name of the random number stream.
std::string m_G4RandomEngineName
 Name of the random number stream for G4 tools.
ToolHandle< ISF::IG4RunManagerHelperm_g4RunManagerHelper
 G4RunManager needs to be initialized before G4 tables are accessed.
ToolHandle< PDGToG4Particlem_pdgToG4Conv
 Handle for the PDGToG4Particle converter tool.
bool m_validationMode
 Validation output with histogram service.
ToolHandle< IPhysicsValidationToolm_validationTool
 the ntuple

Detailed Description

This Tool is a helper tool wrapping the IParticleDecayCreator, and organised the flight distance to.

Author
Andre.nosp@m.as.S.nosp@m.alzbu.nosp@m.rger.nosp@m.@cern.nosp@m..ch, Joerg.nosp@m..Mec.nosp@m.hnich.nosp@m.@cer.nosp@m.n.ch

Definition at line 45 of file G4ParticleDecayHelper.h.

Constructor & Destructor Documentation

◆ G4ParticleDecayHelper()

iFatras::G4ParticleDecayHelper::G4ParticleDecayHelper ( const std::string & t,
const std::string & n,
const IInterface * p )

AlgTool constructor for ParticleDecayHelper.

Definition at line 45 of file G4ParticleDecayHelper.cxx.

45 :
46 base_class(t,n,p),
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),
57{
58 // ISF: truth and broker service
59 declareProperty("ParticleBroker", m_particleBroker, "ISF Particle Broker Svc");
60 declareProperty("ParticleTruthSvc", m_truthRecordSvc, "ISF Particle Truth Svc");
61 // random number initializations
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");
65
66 // tool declarations -------------------------------------------------
67 declareProperty("G4RunManagerHelper" , m_g4RunManagerHelper);
68 declareProperty("PDGToG4ParticleConverter", m_pdgToG4Conv);
69 // validation output section
70 declareProperty( "ValidationMode", m_validationMode );
71 declareProperty( "PhysicsValidationTool", m_validationTool );
72
73}
std::string m_randomEngineName
Name of the random number stream.
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.
ToolHandle< IPhysicsValidationTool > m_validationTool
the ntuple
bool m_validationMode
Validation output with histogram service.
ServiceHandle< ISF::ITruthSvc > m_truthRecordSvc
Truth Svc for truth tree.
ToolHandle< ISF::IG4RunManagerHelper > m_g4RunManagerHelper
G4RunManager needs to be initialized before G4 tables are accessed.
ServiceHandle< ISF::IParticleBroker > m_particleBroker
Broker Svc for ISF particles.
std::string m_G4RandomEngineName
Name of the random number stream for G4 tools.

◆ ~G4ParticleDecayHelper()

iFatras::G4ParticleDecayHelper::~G4ParticleDecayHelper ( )

Destructor.

Definition at line 79 of file G4ParticleDecayHelper.cxx.

80{}

Member Function Documentation

◆ decay()

void iFatras::G4ParticleDecayHelper::decay ( const ISF::ISFParticle & isp,
const Amg::Vector3D & vertex,
const Amg::Vector3D & mom,
double timeStamp = 0 ) const

decay handling secondaries

Definition at line 195 of file G4ParticleDecayHelper.cxx.

199{
200
201 /*-------------------------------------------------------------------
202 * The actual decay
203 *-------------------------------------------------------------------*/
204 ATH_MSG_DEBUG( "[ decay ] calling G4ParticleDecayCreator with " << particleToDecay );
205
206 // perform the decay
207 const ISF::ISFParticleVector decayProducts = decayParticle(particleToDecay,vertex,momentum,timeStamp);
208
209 // fill them into broker & truth svc
210 handleDecayParticles(particleToDecay,decayProducts); // Registers TruthIncident internally
211}
#define ATH_MSG_DEBUG(x)
std::vector< ISF::ISFParticle * > decayParticle(const ISF::ISFParticle &parent, const Amg::Vector3D &vertex, const Amg::Vector3D &mom, double timeStamp=0) const
decay
void handleDecayParticles(const ISF::ISFParticle &isp, const ISF::ISFParticleVector &children) const
fill decay products: into broker svc, truth svc
std::vector< ISF::ISFParticle * > ISFParticleVector
ISFParticle vector.

◆ decayParticle()

std::vector< ISF::ISFParticle * > iFatras::G4ParticleDecayHelper::decayParticle ( const ISF::ISFParticle & parent,
const Amg::Vector3D & vertex,
const Amg::Vector3D & mom,
double timeStamp = 0 ) const

decay

Definition at line 272 of file G4ParticleDecayHelper.cxx.

276{
277 // Called from McMaterialEffectsUpdator::interact, McMaterialEffectsUpdator::interactLay and G4ParticleDecayHelper::decay
278 // return vector for children
279 std::vector<ISF::ISFParticle*> children;
280
281 // initialize G4RunManager if not done already
282 bool g4mgr = initG4RunManager();
283 if (!g4mgr) ATH_MSG_WARNING( "initialization of G4RunManager failed in G4ParticleDecayHelper" );
284
285 if (!m_pdgToG4Conv) {
286
287 if( m_pdgToG4Conv.retrieve().isFailure()) return children;
288
289 if( msgLvl(MSG::VERBOSE)) {
290 ATH_MSG_VERBOSE( "List of particles with decay info:" );
291 m_pdgToG4Conv->printListOfParticles( true);
292 }
293 }
294
295 int pdgCode = parent.pdgCode();
296
297 G4ParticleDefinition* pDef = m_pdgToG4Conv->getParticleDefinition( pdgCode);
298 if( !pDef)
299 {
300 ATH_MSG_WARNING( "[ decay ] could not find geant4 equivalent"
301 << " for particle with pdg id " << pdgCode );
302 return children;
303 }
304
305 ATH_MSG_DEBUG( "[ decay ] Decaying " << pDef->GetParticleName() );
306
307 G4DecayTable* dt = pDef->GetDecayTable();
308 if( !dt)
309 {
310 ATH_MSG_WARNING( "[ decay ] empty decay table for"
311 << " particle with pdg id " << pdgCode );
312 return children;
313 }
314
315 if( msgLvl(MSG::VERBOSE))
316 {
317 ATH_MSG_VERBOSE( "[ decay ] Decay table:" );
318 dt->DumpInfo();
319 }
320
321 G4VDecayChannel* channel = dt->SelectADecayChannel();
322 if( !channel)
323 {
324 ATH_MSG_ERROR( "[ decay ] error selecting decay channel for"
325 << " particle with pdg id " << pdgCode );
326 return children;
327 }
328
329 if( msgLvl(MSG::DEBUG))
330 {
331 ATH_MSG_DEBUG( "[ decay ] Decay channel:" );
332 channel->DumpInfo();
333 }
334
335 G4DecayProducts* products = channel->DecayIt();
336 if( !products)
337 {
338 ATH_MSG_ERROR( "[ decay ] error in decay product generation"
339 << " for particle with pdg id " << pdgCode );
340 return children;
341 }
342
343 if( msgLvl(MSG::VERBOSE))
344 {
345 ATH_MSG_VERBOSE( "[ decay ] Decay products:" );
346 products->DumpInfo();
347 }
348
349 // the parent energy
350 double parentE = std::sqrt( std::pow( pDef->GetPDGMass(), 2) +
351 momentum.mag2());
352
353 products->Boost( momentum.x()/parentE,
354 momentum.y()/parentE,
355 momentum.z()/parentE);
356 if( msgLvl(MSG::VERBOSE))
357 {
358 ATH_MSG_VERBOSE( "[ decay ] Decay products after boost:" );
359 products->DumpInfo();
360 }
361
362 G4int nProducts = products->entries();
363 for( G4int i=0; i < nProducts; ++i)
364 {
365 G4DynamicParticle* prod = products->PopProducts();
366 if( !prod)
367 {
368 ATH_MSG_WARNING( "[ decay ] Could not retrieve product " << i);
369 continue;
370 }
371
372 // the decay product
373 const G4ThreeVector &mom= prod->GetMomentum();
374 Amg::Vector3D amgMom( mom.x(), mom.y(), mom.z() );
375
376 const int status = 1 + HepMC::SIM_STATUS_THRESHOLD;
377 const int id = HepMC::UNDEFINED_ID;
378 ISF::ISFParticle* childParticle = new ISF::ISFParticle( vertex,
379 amgMom,
380 prod->GetMass(),
381 prod->GetCharge(),
382 prod->GetPDGcode(),
383 status,
384 timeStamp,
385 parent,
386 id );
387
388 children.push_back( childParticle);
389 }
390 return children;
391}
#define ATH_MSG_ERROR(x)
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_WARNING(x)
bool initG4RunManager() const
initialize G4RunManager on first call if not done by then
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...
status
Definition merge.py:16

◆ finalize()

StatusCode iFatras::G4ParticleDecayHelper::finalize ( )

AlgTool finalize method.

Definition at line 146 of file G4ParticleDecayHelper.cxx.

147{
148 ATH_MSG_DEBUG( "finalize() successful" );
149 return StatusCode::SUCCESS;
150}

◆ freePath()

double iFatras::G4ParticleDecayHelper::freePath ( const ISF::ISFParticle & isp) const

free path estimator (-1 for stable particle)

Definition at line 152 of file G4ParticleDecayHelper.cxx.

152 {
153 // get the particle properties
154 int pdgCode = isp.pdgCode();
155
156 // initialize G4RunManager if not done already
157 bool g4mgr = initG4RunManager();
158 if (!g4mgr) ATH_MSG_WARNING( "initialization of G4RunManager failed in G4ParticleDecayHelper" );
159
160 if (!m_pdgToG4Conv && m_pdgToG4Conv.retrieve().isFailure()) return -1.;
161
162 G4ParticleDefinition* pDef = m_pdgToG4Conv->getParticleDefinition(pdgCode);
163
164 // for the processing
165 bool isStable = true;
166
167 if( !pDef ) {
168 ATH_MSG_WARNING( "[ decay ] could not find particle properties" << " for PDG code " << pdgCode );
169 return -1.;
170 }
171 // set is stable from Geant4 particle definition
172 isStable = pDef->GetPDGStable();
173 // set muons to stable
174 if ( std::abs(pdgCode) == 13) isStable = true;
175 // we have a stable particle --- return
176 if (isStable) return -1.;
177
178 double mass = pDef->GetPDGMass();
179 // take momentum from ParticleState rather than associated truth
180 CLHEP::HepLorentzVector particleMom( isp.momentum().x(),
181 isp.momentum().y(),
182 isp.momentum().z(),
183 sqrt(isp.momentum().mag2()+mass*mass) );
184
185 // get average lifetime
186 double tau = pDef->GetPDGLifeTime()*1e-9;
187 // sample the lifetime
188 double lifeTime = -tau*log(CLHEP::RandFlat::shoot(m_randomEngine));
189 // distance in mm
190 double pathlength =
191 lifeTime*s_speedOfLightSI*particleMom.gamma()*particleMom.beta();
192 return pathlength;
193}
const Amg::Vector3D & momentum() const
The current momentum vector of the ISFParticle.
int pdgCode() const
PDG value.
bool isStable(const T &p)
Identify if the particle is stable, i.e. has not decayed.

◆ handleDecayParticles()

void iFatras::G4ParticleDecayHelper::handleDecayParticles ( const ISF::ISFParticle & isp,
const ISF::ISFParticleVector & children ) const
private

fill decay products: into broker svc, truth svc

Definition at line 214 of file G4ParticleDecayHelper.cxx.

215 {
216 // process the decay products ---------------------------------------
217 int process = 201;
218
219 // (i) none
220 if (!decayProducts.size()) {
221 ATH_MSG_WARNING("[ decay ] Particle Decay Creator did not return any"
222 << " decay products for particle with PDG code "
223 << particle.pdgCode() );
224 } else {
225 // (ii) many
226 std::ostringstream productSummaryString;
227 productSummaryString << "[ decay ] products:";
228
229 for (ISF::ISFParticle *decayProduct : decayProducts) {
230 productSummaryString << " - " << (*decayProduct) << '\n';
231 // in the validation mode, add process info
232 if (m_validationMode) {
233 ISF::ParticleUserInformation* validInfo = new ISF::ParticleUserInformation();
234 validInfo->setProcess(process);
235 if (particle.getUserInformation()) validInfo->setGeneration(particle.getUserInformation()->generation()+1);
236 else validInfo->setGeneration(1); // assume parent is a primary track
237 decayProduct->setUserInformation(validInfo);
238 }
239 // register next geo (is current), next flavor can be defined by filter
240 decayProduct->setNextGeoID( particle.nextGeoID() );
241 }//loop over all decay products
242
243 // register TruthIncident
244 ISF::ISFTruthIncident truth( const_cast<ISF::ISFParticle&>(particle),
245 decayProducts,
246 process,
247 particle.nextGeoID(), // inherits from the parent
249 m_truthRecordSvc->registerTruthIncident( truth);
250 // At this point we need to update the properties of the
251 // ISFParticles produced in the interaction
252 truth.updateChildParticleProperties();
253
254 // simulate the tracks of the daughter particles ------- run over decay products
255 for (ISF::ISFParticle *decayProduct : decayProducts) {
256 // feed it the particle broker with parent information
257 m_particleBroker->push(decayProduct, &particle);
258 }//loop over all decay products
259 ATH_MSG_VERBOSE( productSummaryString.str() );
260
261 // save info for validation
262 if (m_validationMode && m_validationTool.isEnabled()) {
263 Amg::Vector3D* nMom = 0;
264 m_validationTool->saveISFVertexInfo(process,particle.position(),particle,particle.momentum(),nMom,decayProducts);
265 delete nMom;
266 }
267
268 }
269}
const std::string process
@ fKillsPrimary
constexpr ParticleHypothesis particle[PARTICLEHYPOTHESES]
the array of masses

◆ initG4RunManager()

bool iFatras::G4ParticleDecayHelper::initG4RunManager ( ) const
private

initialize G4RunManager on first call if not done by then

Definition at line 393 of file G4ParticleDecayHelper.cxx.

393 {
394
395 // safe because the static initialization ensures that this is only called once
396 static const G4RunManager* const g4runManager ATLAS_THREAD_SAFE = [&] ATLAS_NOT_THREAD_SAFE () {
397 auto helper_nc = const_cast<ISF::IG4RunManagerHelper*>(m_g4RunManagerHelper.get());
398 return helper_nc->fastG4RunManager();
399 }();
400
401 return g4runManager ? true : false;
402}
#define ATLAS_NOT_THREAD_SAFE
getNoisyStrip() Find noisy strips from hitmaps and write out into xml/db formats
#define ATLAS_THREAD_SAFE

◆ initialize()

StatusCode iFatras::G4ParticleDecayHelper::initialize ( )

AlgTool initailize method.

Definition at line 87 of file G4ParticleDecayHelper.cxx.

88{
89
90 ATH_MSG_DEBUG( "initialize()" );
91
92 ATH_CHECK( m_validationTool.retrieve( DisableTool{ m_validationTool.empty() || !m_validationMode } ) );
93 // ISF Services
94 if ( m_particleBroker.retrieve().isFailure()){
95 ATH_MSG_FATAL( "Could not retrieve " << m_particleBroker );
96 return StatusCode::FAILURE;
97 }
98 if (m_truthRecordSvc.retrieve().isFailure()){
99 ATH_MSG_FATAL( "Could not retrieve " << m_truthRecordSvc );
100 return StatusCode::FAILURE;
101 }
102
103 // Random number service
104 if ( m_rndmSvc.retrieve().isFailure() ) {
105 ATH_MSG_FATAL( "Could not retrieve " << m_rndmSvc );
106 return StatusCode::FAILURE;
107 }
108 //Get own engine with own seeds:
110 if (!m_randomEngine) {
111 ATH_MSG_FATAL( "Could not get random engine '" << m_randomEngineName << "'" );
112 return StatusCode::FAILURE;
113 }
114 // G4ParticleDecayCreator uses functions from G4 (G4VDecayChannel::DecayIt() and G4DecayTable::SelectADecayChannel())
115 // which use CLHEP::HepRandom directly with the default engine. Therefore we set the default engine to a special stream,
116 // analog to G4AtlasAlg.
117 // Set the random number generator to AtRndmGen
118 CLHEP::HepRandomEngine* engine = m_rndmSvc->GetEngine(m_G4RandomEngineName);
119 if (!engine) {
120 ATH_MSG_FATAL( "Could not get random engine '" << m_G4RandomEngineName << "'" );
121 return StatusCode::FAILURE;
122 }
123 CLHEP::HepRandom::setTheEngine(engine);
124
125 // get G4RunManagerHelper ( no G4RunManager initialization done )
126 if (m_g4RunManagerHelper.retrieve().isFailure()) {
127 ATH_MSG_FATAL( "Could not get g4RunManagerHelper '" << m_g4RunManagerHelper << "'" );
128 return StatusCode::FAILURE;
129 } else {
130 std::cout <<"f4dec: g4RunManagerHelper retrieved:"<< m_g4RunManagerHelper<< std::endl;
131 }
132
133 // Disable auto-retrieve of this tool: Geant will raise an exception
134 // if this happens before the run manager is created.
135 m_pdgToG4Conv.disable();
136
137 ATH_MSG_DEBUG("initialize() successful");
138 return StatusCode::SUCCESS;
139}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_FATAL(x)

Member Data Documentation

◆ m_G4RandomEngineName

std::string iFatras::G4ParticleDecayHelper::m_G4RandomEngineName
private

Name of the random number stream for G4 tools.

Definition at line 91 of file G4ParticleDecayHelper.h.

◆ m_g4RunManagerHelper

ToolHandle<ISF::IG4RunManagerHelper> iFatras::G4ParticleDecayHelper::m_g4RunManagerHelper
private

G4RunManager needs to be initialized before G4 tables are accessed.

Definition at line 96 of file G4ParticleDecayHelper.h.

◆ m_particleBroker

ServiceHandle<ISF::IParticleBroker> iFatras::G4ParticleDecayHelper::m_particleBroker
private

Broker Svc for ISF particles.

Definition at line 84 of file G4ParticleDecayHelper.h.

◆ m_pdgToG4Conv

ToolHandle<PDGToG4Particle> iFatras::G4ParticleDecayHelper::m_pdgToG4Conv
private

Handle for the PDGToG4Particle converter tool.

Definition at line 97 of file G4ParticleDecayHelper.h.

◆ m_randomEngine

CLHEP::HepRandomEngine* iFatras::G4ParticleDecayHelper::m_randomEngine
private

Random engine (updated to streams)

Definition at line 89 of file G4ParticleDecayHelper.h.

◆ m_randomEngineName

std::string iFatras::G4ParticleDecayHelper::m_randomEngineName
private

Name of the random number stream.

Definition at line 90 of file G4ParticleDecayHelper.h.

◆ m_rndmSvc

ServiceHandle<IAtRndmGenSvc> iFatras::G4ParticleDecayHelper::m_rndmSvc
private

Random Svc.

Definition at line 88 of file G4ParticleDecayHelper.h.

◆ m_truthRecordSvc

ServiceHandle<ISF::ITruthSvc> iFatras::G4ParticleDecayHelper::m_truthRecordSvc
private

Truth Svc for truth tree.

Definition at line 85 of file G4ParticleDecayHelper.h.

◆ m_validationMode

bool iFatras::G4ParticleDecayHelper::m_validationMode
private

Validation output with histogram service.

turn validation mode on/off

Definition at line 100 of file G4ParticleDecayHelper.h.

◆ m_validationTool

ToolHandle<IPhysicsValidationTool> iFatras::G4ParticleDecayHelper::m_validationTool
private

the ntuple

Definition at line 101 of file G4ParticleDecayHelper.h.


The documentation for this class was generated from the following files: