ATLAS Offline Software
StoppedParticleFastSim.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 
7 
9 
10 #include "G4FastTrack.hh"
11 #include "G4Track.hh"
12 #include "G4DynamicParticle.hh"
13 #include "G4ParticleDefinition.hh"
14 #include "G4Material.hh"
15 #include "G4ElementVector.hh"
16 #include "G4SDManager.hh"
17 #include "G4VSensitiveDetector.hh"
18 
19 #include "CLHEP/Units/PhysicalConstants.h"
20 
21 #include <G4Region.hh>
22 #include <cmath>
23 
24 StoppedParticleFastSim::StoppedParticleFastSim(const std::string& name, G4Region* region, const std::string& fsSDname)
25  : G4VFastSimulationModel(name, region)
26  , m_fsSDname(fsSDname)
27 {
28 }
29 
30 G4bool StoppedParticleFastSim::IsApplicable(const G4ParticleDefinition&)
31 {
32  return true;
33 }
34 
35 G4bool StoppedParticleFastSim::ModelTrigger(const G4FastTrack& fastTrack)
36 {
37  // Trigger if the energy is below our threshold or if the time is over 150 ns
38  int id = fastTrack.GetPrimaryTrack()->GetDynamicParticle()->GetDefinition()->GetPDGEncoding();
39  if (id<1000000 || id>1100000) return true; // skip SM particles and super-partners of RH-fermions
40  if (MC::isSquarkLH(id) ||
41  id == 1000021 || // gluino
42  MC::isRHadron(id)) {
43  G4Material * mat = fastTrack.GetPrimaryTrack()->GetMaterial();
44  double minA=1500000.;
45  for (unsigned int i=0;i<mat->GetNumberOfElements();++i){
46  if (mat->GetElement(i) &&
47  minA>mat->GetElement(i)->GetN()){
48  minA=mat->GetElement(i)->GetN();
49  }
50  }
51  if (fastTrack.GetPrimaryTrack()->GetVelocity()<0.15*std::pow(minA,-2./3.)*CLHEP::c_light) return true;
52  return false;
53  }
54  return true;
55 }
56 
57 void StoppedParticleFastSim::DoIt(const G4FastTrack& fastTrack, G4FastStep& fastStep)
58 {
59  if (!m_init){
60  m_init = true;
61 
62  G4SDManager *sdm = G4SDManager::GetSDMpointer();
63  G4VSensitiveDetector * vsd = sdm->FindSensitiveDetector( m_fsSDname );
64  if (vsd) {
65  m_fsSD = dynamic_cast<TrackFastSimSD*>(vsd);
66  if (!m_fsSD) {
67  G4ExceptionDescription description;
68  description << "DoIt: Could not cast the SD into an instance of TrackFasSimSD.";
69  G4Exception("StoppedParticleFastSim", "MissingTrackFastSimSD", FatalException, description);
70  abort();
71  }
72  }
73  else {
74  G4cout << "StoppedParticleFastSim::DoIt INFO Could not get TrackFastSimSD sensitive detector. If you are not writing track records this is expected." << G4endl;
75  }
76  // found the SD
77  } // End of lazy init
78  const int id = fastTrack.GetPrimaryTrack()->GetDynamicParticle()->GetDefinition()->GetPDGEncoding();
79  if (m_fsSD &&
80  (MC::isSquarkLH(id) ||
81  id == 1000021 || // gluino
82  MC::isRHadron(id))) {
83  m_fsSD->WriteTrack( fastTrack.GetPrimaryTrack() , false , true );
84  }
85  fastStep.KillPrimaryTrack();
86 }
StoppedParticleFastSim::m_fsSD
TrackFastSimSD * m_fsSD
Definition: StoppedParticleFastSim.h:31
TrackFastSimSD
Definition: TrackFastSimSD.h:24
TrackFastSimSD.h
mat
GeoMaterial * mat
Definition: LArDetectorConstructionTBEC.cxx:55
StoppedParticleFastSim.h
StoppedParticleFastSim::m_fsSDname
std::string m_fsSDname
Definition: StoppedParticleFastSim.h:33
StoppedParticleFastSim::m_init
bool m_init
Definition: StoppedParticleFastSim.h:32
lumiFormat.i
int i
Definition: lumiFormat.py:85
StoppedParticleFastSim::IsApplicable
G4bool IsApplicable(const G4ParticleDefinition &) override final
Definition: StoppedParticleFastSim.cxx:30
StoppedParticleFastSim::StoppedParticleFastSim
StoppedParticleFastSim(const std::string &name, G4Region *region, const std::string &fsSDname)
Definition: StoppedParticleFastSim.cxx:24
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:240
python.PhysicalConstants.c_light
float c_light
Definition: PhysicalConstants.py:73
StoppedParticleFastSim::ModelTrigger
virtual G4bool ModelTrigger(const G4FastTrack &) override final
Definition: StoppedParticleFastSim.cxx:35
TrackFastSimSD::WriteTrack
void WriteTrack(const G4Track *, const bool, const bool)
Definition: TrackFastSimSD.cxx:97
isSquarkLH
bool isSquarkLH(const T &p)
Definition: AtlasPID.h:463
isRHadron
bool isRHadron(const T &p)
Definition: AtlasPID.h:600
pow
constexpr int pow(int base, int exp) noexcept
Definition: ap_fixedTest.cxx:15
StoppedParticleFastSim::DoIt
void DoIt(const G4FastTrack &, G4FastStep &) override final
Definition: StoppedParticleFastSim.cxx:57
HepMCHelpers.h
description
std::string description
glabal timer - how long have I taken so far?
Definition: hcg.cxx:88