ATLAS Offline Software
Loading...
Searching...
No Matches
ForwardTransportModel Class Reference

#include <ForwardTransportModel.h>

Inheritance diagram for ForwardTransportModel:
Collaboration diagram for ForwardTransportModel:

Public Member Functions

 ForwardTransportModel (const std::string &name, G4Region *region, const int verboseLevel, const std::string &FwdTrSvcName)
G4bool IsApplicable (const G4ParticleDefinition &) override final
G4bool ModelTrigger (const G4FastTrack &) override final
void DoIt (const G4FastTrack &, G4FastStep &) override final

Private Member Functions

void KillPrimaryTrack (const G4FastTrack &, G4FastStep &)
PrimaryParticleInformationgetPrimaryParticleInformation (const G4FastTrack &fastTrack) const

Private Attributes

ServiceHandle< IForwardTransportSvcm_fwdSvc
ForwardTrack m_fwdTrack
ForwardTracker::Particle m_fwdParticle
const int m_verboseLevel {0}

Detailed Description

Definition at line 16 of file ForwardTransportModel.h.

Constructor & Destructor Documentation

◆ ForwardTransportModel()

ForwardTransportModel::ForwardTransportModel ( const std::string & name,
G4Region * region,
const int verboseLevel,
const std::string & FwdTrSvcName )

Definition at line 26 of file ForwardTransportModel.cxx.

27 : G4VFastSimulationModel(name, region)
28 , m_fwdSvc(FwdTrSvcName, "ForwardTransportModel")
29 , m_verboseLevel(verboseLevel)
30{
31 if (m_fwdSvc.retrieve().isFailure()) {
32 G4ExceptionDescription description;
33 description << "ForwardTransportModel::ForwardTransportModel Attempt to access ForwardTransportSvc failed.";
34 G4Exception("ForwardTransportModel", "ForwardTransportModel01", FatalException, description);
35 abort(); // to keep Coverity happy
36 }
37
38 m_fwdTrack.initialize(m_fwdSvc->getConfigData());
39
40 if (m_verboseLevel>5) {
41 G4cout << " transportFlag " << m_fwdSvc->getTransportFlag() << G4endl;
42 G4cout << " etaCut " << m_fwdSvc->getEtaCut() << G4endl;
43 G4cout << " xiCut " << m_fwdSvc->getXiCut() << G4endl;
44 }
45 return;
46}
ServiceHandle< IForwardTransportSvc > m_fwdSvc
std::string description
glabal timer - how long have I taken so far?
Definition hcg.cxx:91

Member Function Documentation

◆ DoIt()

void ForwardTransportModel::DoIt ( const G4FastTrack & fastTrack,
G4FastStep & fastStep )
finaloverride

Special cases for Geantinos

Standard particles

Definition at line 65 of file ForwardTransportModel.cxx.

65 {
66 // Depending on particle type and kinematics one can decide to kill the track,
67 // modify it or change it into something else (e.g. a parameterised shower).
68 if (m_verboseLevel>4) {
69 G4cout <<"ForwardTransportModel::DoIt" << G4endl;
70 }
71
72 const int pdgcode = fastTrack.GetPrimaryTrack()->GetDefinition()->GetPDGEncoding();
73 const G4ThreeVector& initialMomentum = fastTrack.GetPrimaryTrack()->GetMomentum();
74 if (!m_fwdSvc->selectedParticle(initialMomentum, pdgcode)) { // FIXME Move method to this class?
75 KillPrimaryTrack(fastTrack, fastStep);
76 return;
77 }
78
79 const double charge = fastTrack.GetPrimaryTrack()->GetDefinition()->GetPDGCharge();
80 const G4ThreeVector& initialPosition = fastTrack.GetPrimaryTrack()->GetPosition();
81 const double time = fastTrack.GetPrimaryTrack()->GetGlobalTime();
82 const double energy = fastTrack.GetPrimaryTrack()->GetTotalEnergy();
83
84 if (m_verboseLevel>5) {
85 G4cout <<" pdgCode: " << pdgcode << " energy[GeV]: " << energy/CLHEP::GeV << " charge: " << charge << G4endl;
86 }
87 ForwardTracker::Particle fParticle = ForwardTracker::Particle(initialPosition.x()/CLHEP::m,
88 initialPosition.y()/CLHEP::m,
89 initialPosition.z()/CLHEP::m,
90 initialMomentum.x()/CLHEP::GeV,
91 initialMomentum.y()/CLHEP::GeV,
92 initialMomentum.z()/CLHEP::GeV,
93 std::abs(charge)>0);
94 if (m_verboseLevel>5) {
95 G4cout << fParticle << G4endl;
96 }
97
98 bool isTransported = m_fwdTrack.TrackParticle(fParticle);
99 if (!isTransported) {
100 KillPrimaryTrack(fastTrack, fastStep);
101 return;
102 }
103
104 if (m_verboseLevel>5) {
105 G4cout << m_fwdTrack.fPar() << G4endl;
106 }
107
108 ForwardTracker::Point fPos = m_fwdTrack.fPos();
109 G4ThreeVector postTransportPosition(fPos.x()*CLHEP::m, fPos.y()*CLHEP::m, fPos.z()*CLHEP::m);
110
111 ForwardTracker::Point fMom = m_fwdTrack.fMom();
112 G4ThreeVector postTransportMomentum(fMom.x()*CLHEP::GeV, fMom.y()*CLHEP::GeV, fMom.z()*CLHEP::GeV);
113
114 PrimaryParticleInformation *ppi = this->getPrimaryParticleInformation(fastTrack);
116 HepMC::GenEvent* gEvent = (part) ? const_cast<HepMC::GenEvent*>(part->parent_event()) : nullptr;
117 if (!gEvent) {
118 G4ExceptionDescription description;
119 description << "ForwardTransportModel::DoIt Cannot get HepMC::GenEvent pointer";
120 G4Exception("ForwardTransportModel", "ForwardTransportModel03", FatalException, description);
121 abort(); // to keep Coverity happy
122 }
123 // Update HepMC::GenEvent
125 HepMC::FourVector(
126 postTransportPosition.x(),
127 postTransportPosition.y(),
128 postTransportPosition.z(),
129 time)); // TODO Update this value?
130 gEvent->add_vertex(gVertex);
131 gVertex->add_particle_in(part);
133 HepMC::FourVector(
134 postTransportMomentum.x(),
135 postTransportMomentum.y(),
136 postTransportMomentum.z(),
137 energy),
138 pdgcode,
140 gVertex->add_particle_out(gParticle);
142
143 // Create secondary on the Geant4 side
144 fastStep.SetNumberOfSecondaryTracks(1);
145
146 const G4ParticleDefinition *aParticleDefinition{};
148 if (pdgcode == MC::GEANTINOPLUS) {
149 aParticleDefinition = G4ChargedGeantino::Definition();
150 }
151 if (pdgcode == MC::GEANTINO0) {
152 aParticleDefinition = G4Geantino::GeantinoDefinition();
153 }
154 if (!aParticleDefinition) {
156 G4ParticleTable *ptable = G4ParticleTable::GetParticleTable();
157 if (ptable) {
158 aParticleDefinition = ptable->FindParticle(pdgcode);
159 }
160 }
161 G4DynamicParticle dp2(aParticleDefinition, energy, postTransportMomentum);
162
163 // Create UserInformation
164 const ISF::ISFParticle* initialISP = ppi->GetISFParticle();
165 std::unique_ptr<ISF::ISFParticle> postTransportISP{};
166 if (initialISP) {
167 // Create postTransportISP if required.
168 const auto pBarcode = HepMC::barcode(gParticle);
169 const auto particleID = HepMC::uniqueID(gParticle);
170 const int status = gParticle->status();
171 auto tBinding = std::make_unique<ISF::TruthBinding>(gParticle);
172 auto hmpl = std::make_unique<HepMcParticleLink>(pBarcode, gEvent->event_number(), HepMcParticleLink::IS_EVENTNUM, HepMcParticleLink::IS_BARCODE); // FIXME barcode-based
173 const Amg::Vector3D pos(postTransportPosition.x(), postTransportPosition.y(), postTransportPosition.z());
174 const Amg::Vector3D mom(postTransportMomentum.x(), postTransportMomentum.y(), postTransportMomentum.z());
175 postTransportISP = std::make_unique<ISF::ISFParticle>(pos,
176 mom,
177 initialISP->mass(),
178 initialISP->charge(),
179 initialISP->pdgCode(),
180 status,
181 time, // TODO Update??
182 *initialISP,
183 particleID,
184 pBarcode,
185 tBinding.release(),
186 hmpl.release());
187 }
188 std::unique_ptr<PrimaryParticleInformation> ppi2 = std::make_unique<PrimaryParticleInformation>(gParticle,postTransportISP.release());
189 std::unique_ptr<G4PrimaryParticle> pp2 = std::make_unique<G4PrimaryParticle>(
190 aParticleDefinition,
191 postTransportMomentum.x(),
192 postTransportMomentum.y(),
193 postTransportMomentum.z());
194 pp2->SetUserInformation(ppi2.release());
195 dp2.SetPrimaryParticle(pp2.release());
196
197 G4Track* postTransportTrack =
198 fastStep.CreateSecondaryTrack(
199 dp2,
200 postTransportPosition,
201 time,
202 false); // position in global coordinates
203 if (!postTransportTrack) {
204 G4ExceptionDescription description;
205 description << "ForwardTransportModel::DoIt Failed to create secondary G4Track.";
206 G4Exception("ForwardTransportModel", "ForwardTransportModel04", FatalException, description);
207 abort(); // to keep Coverity happy
208 }
209 fastStep.ProposePrimaryTrackFinalPosition(postTransportPosition, false); // position in global coordinates
210 fastStep.ProposePrimaryTrackFinalMomentumDirection(postTransportMomentum, false); // FIXME This only sets the normalised direction of the momentum - possible use ProposePrimaryTrackFinalKineticEnergyAndDirection instead?
211 fastStep.KillPrimaryTrack();
212}
double charge(const T &p)
Definition AtlasPID.h:997
PrimaryParticleInformation * getPrimaryParticleInformation(const G4FastTrack &fastTrack) const
void KillPrimaryTrack(const G4FastTrack &, G4FastStep &)
double charge() const
charge of the particle
int pdgCode() const
PDG value.
double mass() const
mass of the particle
const ISF::ISFParticle * GetISFParticle() const
return a pointer to the ISFParticle used to create the G4PrimaryParticle
HepMC::ConstGenParticlePtr GetHepMCParticle() const
return a pointer to the GenParticle used to create the G4PrimaryParticle
Eigen::Matrix< double, 3, 1 > Vector3D
time(flags, cells_name, *args, **kw)
int barcode(const T *p)
Definition Barcode.h:16
int uniqueID(const T &p)
constexpr int SIM_STATUS_INCREMENT
Constant defining the barcode threshold for regenerated particles, i.e. particles surviving an intera...
HepMC::GenVertex * GenVertexPtr
Definition GenVertex.h:59
bool suggest_barcode(T &p, int i)
Definition GenEvent.h:672
GenVertexPtr newGenVertexPtr(const HepMC::FourVector &pos=HepMC::FourVector(0.0, 0.0, 0.0, 0.0), const int i=0)
Definition GenVertex.h:64
GenParticlePtr newGenParticlePtr(const HepMC::FourVector &mom=HepMC::FourVector(0.0, 0.0, 0.0, 0.0), int pid=0, int status=0)
Definition GenParticle.h:39
GenParticle * GenParticlePtr
Definition GenParticle.h:37
constexpr int SIM_REGENERATION_INCREMENT
Constant defining the barcode threshold for regenerated particles, i.e. particles surviving an intera...
static const int GEANTINOPLUS
PDG rule 10: Codes 81–100 are reserved for generator-specific pseudoparticles and concepts.
static const int GEANTINO0
status
Definition merge.py:16

◆ getPrimaryParticleInformation()

PrimaryParticleInformation * ForwardTransportModel::getPrimaryParticleInformation ( const G4FastTrack & fastTrack) const
private

Definition at line 49 of file ForwardTransportModel.cxx.

50{
51 const G4Track *track = fastTrack.GetPrimaryTrack();
52 const G4DynamicParticle *dp = track->GetDynamicParticle();
53 if (dp) {
54 const G4PrimaryParticle *pp = dp->GetPrimaryParticle();
55 if (pp) {
56 // Extract the PrimaryParticleInformation
57 return dynamic_cast<PrimaryParticleInformation*>
58 ( pp->GetUserInformation() );
59 }
60 }
61 return nullptr;
62}

◆ IsApplicable()

G4bool ForwardTransportModel::IsApplicable ( const G4ParticleDefinition & )
inlinefinaloverride

Definition at line 23 of file ForwardTransportModel.h.

23{ return true; } // IDLE: we do selection in DoIt method

◆ KillPrimaryTrack()

void ForwardTransportModel::KillPrimaryTrack ( const G4FastTrack & fastTrack,
G4FastStep & fastStep )
private

Definition at line 215 of file ForwardTransportModel.cxx.

215 {
216 PrimaryParticleInformation *ppi = this->getPrimaryParticleInformation(fastTrack);
218 HepMC::GenEvent* gEvent = (part) ? const_cast<HepMC::GenEvent*>(part->parent_event()) : nullptr;
219 if (!gEvent) {
220 G4ExceptionDescription description;
221 description << "ForwardTransportModel::KillPrimaryTrack Cannot get HepMC::GenEvent pointer";
222 G4Exception("ForwardTransportModel", "ForwardTransportModel02", FatalException, description);
223 abort(); // to keep Coverity happy
224 }
225 const G4ThreeVector& initialPosition = fastTrack.GetPrimaryTrack()->GetPosition();
226 // Add dummy end vertex in Truth
228 HepMC::FourVector(
229 initialPosition.x(),
230 initialPosition.y(),
231 initialPosition.z(),
232 fastTrack.GetPrimaryTrack()->GetGlobalTime()));
233 // Flag the fact that Forward Transport has occurred using the vertex status
234#ifdef HEPMC3
236#else
238#endif
239 gEvent->add_vertex(gVertex);
240 gVertex->add_particle_in(part);
241 // Kill track and deposit all energy in the current volume
242 fastStep.KillPrimaryTrack();
243 fastStep.ProposePrimaryTrackPathLength(0.0);
244 fastStep.ProposeTotalEnergyDeposited(fastTrack.GetPrimaryTrack()->GetTotalEnergy());
245}
constexpr int SIM_STATUS_THRESHOLD
Constant definiting the status threshold for simulated particles, eg. can be used to separate generat...
constexpr int FORWARD_TRANSPORT_MODEL_PROCESS
Special Forward transport Geant process for vertices.

◆ ModelTrigger()

G4bool ForwardTransportModel::ModelTrigger ( const G4FastTrack & )
inlinefinaloverride

Definition at line 24 of file ForwardTransportModel.h.

24{ return true; } // IDLE: we do selection in DoIt method

Member Data Documentation

◆ m_fwdParticle

ForwardTracker::Particle ForwardTransportModel::m_fwdParticle
private

Definition at line 34 of file ForwardTransportModel.h.

◆ m_fwdSvc

ServiceHandle<IForwardTransportSvc> ForwardTransportModel::m_fwdSvc
private

Definition at line 32 of file ForwardTransportModel.h.

◆ m_fwdTrack

ForwardTrack ForwardTransportModel::m_fwdTrack
private

Definition at line 33 of file ForwardTransportModel.h.

◆ m_verboseLevel

const int ForwardTransportModel::m_verboseLevel {0}
private

Definition at line 35 of file ForwardTransportModel.h.

35{0};

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