ATLAS Offline Software
Loading...
Searching...
No Matches
NeutronFastSim.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3*/
4
8
9#include "G4Neutron.hh"
10#include "G4SDManager.hh"
11#include "G4VSensitiveDetector.hh"
13
15
16NeutronFastSim::NeutronFastSim(const std::string& name, G4Region* region, const std::string& fsSDname, const double etaCut, const double timeCut)
17 : G4VFastSimulationModel(name, region)
18 , m_Energy(5)
19 , m_fsSD(0)
20 , m_init(false)
21 , m_fsSDname(fsSDname)
22 , m_etaCut(etaCut)
23 , m_timeCut(timeCut)
24{
25}
26
27G4bool NeutronFastSim::IsApplicable(const G4ParticleDefinition&)
28{
29 if (!m_init){
30 m_init = true;
31
32 G4SDManager *sdm = G4SDManager::GetSDMpointer();
33 G4VSensitiveDetector * vsd = sdm->FindSensitiveDetector( m_fsSDname );
34 if (!vsd) {
35 G4cout << "NeutronFastSim::IsApplicable WARNING Could not get TrackFastSimSD sensitive detector. If you are not writing track records this is expected." << G4endl;
36 } else {
37 m_fsSD = dynamic_cast<TrackFastSimSD*>(vsd);
38 if (!m_fsSD) {
39 G4cout << "NeutronFastSim::IsApplicable WARNING Could not cast the SD. If you are not writing track records this is expected." << G4endl;
40 }
41 } // found the SD
42 } // End of lazy init
43 return true;
44}
45
46G4bool NeutronFastSim::ModelTrigger(const G4FastTrack& fastTrack)
47{
48 // Trigger if the neutron energy is below our threshold or if the time is over 150 ns
49 if (fastTrack.GetPrimaryTrack()->GetDefinition() == G4Neutron::NeutronDefinition() ){
50 return (m_Energy<0?true:fastTrack.GetPrimaryTrack()->GetKineticEnergy()<m_Energy) || fastTrack.GetPrimaryTrack()->GetGlobalTime()>m_timeCut;
51 }
52
53 // Not a neutron... Pick it up if the primary had eta>6.0
54 TrackHelper trackHelper(fastTrack.GetPrimaryTrack());
55 HepMC::ConstGenParticlePtr primaryGenParticle = trackHelper.GetPrimaryGenParticle();
56 if (!primaryGenParticle) {
57 return false;
58 }
59 if (std::abs(primaryGenParticle->momentum().eta())>m_etaCut && !HepMC::is_simulation_particle(primaryGenParticle)){
60 return true;
61 } else {
62 return false;
63 }
64}
65
66void NeutronFastSim::DoIt(const G4FastTrack& fastTrack, G4FastStep& fastStep)
67{
68 if (m_fsSD) m_fsSD->WriteTrack( fastTrack.GetPrimaryTrack() , false , false );
69 fastStep.KillPrimaryTrack();
70}
virtual G4bool ModelTrigger(const G4FastTrack &) override final
std::string m_fsSDname
void DoIt(const G4FastTrack &, G4FastStep &) override final
TrackFastSimSD * m_fsSD
G4bool IsApplicable(const G4ParticleDefinition &) override final
NeutronFastSim(const std::string &name, G4Region *region, const std::string &fsSDname, const double etaCut, const double timeCut)
HepMC::GenParticlePtr GetPrimaryGenParticle()
Return the primary truth particle associated with this track.
HepMC3::ConstGenParticlePtr ConstGenParticlePtr
Definition GenParticle.h:20
bool is_simulation_particle(const T &p)
Method to establish if a particle (or barcode) was created during the simulation (TODO update to be s...