ATLAS Offline Software
Loading...
Searching...
No Matches
FastCaloSimCaloTransportation.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3*/
4
5/* Athena includes */
7#include "GaudiKernel/ToolHandle.h"
8#include "GaudiKernel/IPartPropSvc.h"
9
11/* Header include */
13
14/* ISF includes */
17
18/* Tracking includes */
20
21/* Geometry primitives */
23
24/* Particle data */
25#include "HepPDT/ParticleDataTable.hh"
26
27/* Transport steps will be return as G4FieldTracks*/
28#include "G4FieldTrack.hh"
30
31
32FastCaloSimCaloTransportation::FastCaloSimCaloTransportation(const std::string& t, const std::string& n, const IInterface* p)
33 : base_class(t,n,p)
34{
35
36}
37
39{
40 ATH_MSG_INFO( "Initializing FastCaloSimCaloTransportation" );
41
42 // Get TimedExtrapolator
43 if(!m_extrapolator.empty()){
44 ATH_CHECK(m_extrapolator.retrieve());
45 ATH_MSG_INFO("Extrapolator retrieved "<< m_extrapolator);
46 }
47
48 return StatusCode::SUCCESS;
49
50}
51
52
54 ATH_MSG_INFO( "Finalizing FastCaloSimCaloTransportation" );
55 return StatusCode::SUCCESS;
56}
57
58
59std::vector<G4FieldTrack> FastCaloSimCaloTransportation::transport(const TFCSTruthState* truth, bool forceNeutral) const{
60 // Start calo extrapolation
61 ATH_MSG_DEBUG ("[ fastCaloSim transport ] processing particle "<<truth->pdgid() );
62
63 auto hitVector = std::make_unique<std::vector<Trk::HitInfo>>();
64
65 int pdgId = truth->pdgid();
66 double charge = HepPDT::ParticleID(pdgId).charge();
67 if (forceNeutral) charge = 0.;
68
69 // particle Hypothesis for the extrapolation
70 Trk::ParticleHypothesis pHypothesis = m_pdgToParticleHypothesis.convert(pdgId, charge);
71
72 ATH_MSG_DEBUG ("particle hypothesis "<< pHypothesis);
73
74 // geantinos not handled by PdgToParticleHypothesis - fix there
75 if (pdgId == 999) pHypothesis = Trk::geantino;
76
77 Amg::Vector3D pos = Amg::Vector3D(truth->vertex().X(), truth->vertex().Y(), truth->vertex().Z());
78
79 Amg::Vector3D mom(truth->X(), truth->Y(), truth->Z());
80
81 ATH_MSG_DEBUG( "[ fastCaloSim transport ] x from position eta="<<pos.eta()<<" phi="<<pos.phi()<<" d="<<pos.mag()<<" pT="<<mom.perp() );
82
83 // input parameters : curvilinear parameters
84 Trk::CurvilinearParameters inputPar(pos,mom,charge);
85
86 double freepath = -1.;
87 double tDec = freepath > 0. ? freepath : -1.;
88 int decayProc = 0;
89
90 Trk::TimeLimit timeLim(tDec, 0., decayProc);
91 Trk::PathLimit pathLim(-1., 0);
93
94 // first extrapolation to reach the ID boundary
95 ATH_MSG_DEBUG( "[ fastCaloSim transport ] before calo entrance ");
96
97 // get CaloEntrance if not done already
98 if(!m_caloEntrance.get()){
99 m_caloEntrance.set(m_extrapolator->trackingGeometry()->trackingVolume(m_caloEntranceName));
100 if(!m_caloEntrance.get())
101 ATH_MSG_WARNING("CaloEntrance not found");
102 else
103 ATH_MSG_DEBUG("CaloEntrance found");
104 }
105
106 ATH_MSG_DEBUG( "[ fastCaloSim transport ] after calo entrance ");
107
108 std::unique_ptr<const Trk::TrackParameters> caloEntry = nullptr;
109
110 if(m_caloEntrance.get() && m_caloEntrance.get()->inside(pos, 0.001) && !m_extrapolator->trackingGeometry()->atVolumeBoundary(pos,m_caloEntrance.get(), 0.001)){
111 std::vector<Trk::HitInfo>* dummyHitVector = nullptr;
112 if (charge == 0){
113 caloEntry =
114 m_extrapolator->transportNeutralsWithPathLimit(inputPar,
115 pathLim,
116 timeLim,
118 pHypothesis,
119 dummyHitVector,
120 nextGeoID,
121 m_caloEntrance.get());
122 }else{
123 caloEntry = m_extrapolator->extrapolateWithPathLimit(inputPar,
124 pathLim,
125 timeLim,
127 pHypothesis,
128 dummyHitVector,
129 nextGeoID,
130 m_caloEntrance.get());
131 }
132 } else
133 caloEntry = inputPar.uniqueClone();
134
135 ATH_MSG_DEBUG( "[ fastCaloSim transport ] after calo caloEntry ");
136
137 if(caloEntry){
138 std::unique_ptr<const Trk::TrackParameters> eParameters = nullptr;
139
140 // save Calo entry hit (fallback info)
141 hitVector->push_back(Trk::HitInfo(caloEntry->uniqueClone(), timeLim.time, nextGeoID, 0.));
142
144 "[ fastCaloSim transport ] starting Calo transport from position eta="
145 << caloEntry->position().eta() << " phi=" << caloEntry->position().phi()
146 << " d=" << caloEntry->position().mag());
147
148 std::vector<Trk::HitInfo>* rawHitVector = hitVector.get();
149 if (charge == 0){
150 eParameters =
151 m_extrapolator->transportNeutralsWithPathLimit(*caloEntry,
152 pathLim,
153 timeLim,
155 pHypothesis,
156 rawHitVector,
157 nextGeoID);
158 }else{
159 eParameters =
160 m_extrapolator->extrapolateWithPathLimit(*caloEntry,
161 pathLim,
162 timeLim,
164 pHypothesis,
165 rawHitVector,
166 nextGeoID);
167 }
168 // save Calo exit hit (fallback info)
169 if(eParameters) hitVector->push_back(Trk::HitInfo(std::move(eParameters), timeLim.time, nextGeoID, 0.));
170 } //if caloEntry
171
172 //used to identify ID-Calo boundary in tracking tools
173 int IDCaloBoundary = 3000;
174
175 if(msgLvl(MSG::DEBUG)){
176 std::vector<Trk::HitInfo>::iterator it = hitVector->begin();
177 while (it < hitVector->end()){
178 int sample=(*it).detID;
179 Amg::Vector3D hitPos = (*it).trackParms->position();
180 ATH_MSG_DEBUG(" HIT: layer="<<sample<<" sample="<<sample-IDCaloBoundary<<" eta="<<hitPos.eta()<<" phi="<<hitPos.phi()<<" d="<<hitPos.mag());
181 ++it;
182 }
183 }
184
185 std::vector<Trk::HitInfo>::iterator it2 = hitVector->begin();
186 while(it2 < hitVector->end()){
187 int sample=(*it2).detID;
188 Amg::Vector3D hitPos = (*it2).trackParms->position();
189 ATH_MSG_DEBUG(" HIT: layer="<<sample<<" sample="<<sample-IDCaloBoundary<<" eta="<<hitPos.eta()<<" phi="<<hitPos.phi()<<" r="<<hitPos.perp()<<" z="<<hitPos[Amg::z]);
190 ++it2;
191 }
192
193 // Extrapolation may fail for very low pT charged particles. Enforce charge 0 to prevent this
194 if (!forceNeutral && hitVector->empty()){
195 ATH_MSG_DEBUG("forcing neutral charge in FastCaloSimCaloTransportation::caloHits");
196 transport(truth, true);
197 }
198 // Don't expect this ever to happen. Nevertheless, error handling should be improved.
199 // This may require changes in periphery (adjustments after setting function type to StatusCode)
200 else if(hitVector->empty()) ATH_MSG_ERROR("Empty hitVector even after forcing neutral charge. This may cause a segfault soon.");
201
202
203 std::vector<G4FieldTrack> caloSteps = convertToFieldTrack(*hitVector);
204
205 return caloSteps;
206
207}
208
209
210std::vector<G4FieldTrack> FastCaloSimCaloTransportation::convertToFieldTrack(const std::vector<Trk::HitInfo>& vec) const{
211
212 std::vector<G4FieldTrack> caloSteps;
213 for (auto& step : vec){
214 G4FieldTrack track = G4FieldTrack(' ');
215 track.SetPosition(Amg::EigenToHep3Vector(step.trackParms->position()));
216 track.SetMomentum(Amg::EigenToHep3Vector(step.trackParms->momentum()));
217 track.SetChargeAndMoments(step.trackParms->charge());
218 caloSteps.push_back(track);
219 }
220
221 return caloSteps;
222
223}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
double charge(const T &p)
Definition AtlasPID.h:997
std::vector< size_t > vec
std::vector< FPGATrackSimHit > hitVector
virtual std::vector< G4FieldTrack > transport(const TFCSTruthState *truth, bool forceNeutral=false) const override final
Trk::PdgToParticleHypothesis m_pdgToParticleHypothesis
virtual StatusCode initialize() override final
CxxUtils::CachedPointer< const Trk::TrackingVolume > m_caloEntrance
FastCaloSimCaloTransportation(const std::string &t, const std::string &n, const IInterface *p)
virtual StatusCode finalize() override final
PublicToolHandle< Trk::ITimedExtrapolator > m_extrapolator
std::vector< G4FieldTrack > convertToFieldTrack(const std::vector< Trk::HitInfo > &vec) const
int pdgid() const
const TLorentzVector & vertex() const
std::unique_ptr< ParametersBase< DIM, T > > uniqueClone() const
clone method for polymorphic deep copy returning unique_ptr; it is not overriden, but uses the existi...
CLHEP::Hep3Vector EigenToHep3Vector(const Amg::Vector3D &eigenvector)
Converts an Eigen-based Amg::Vector3D into a CLHEP-based CLHEP::Hep3Vector.
Eigen::Matrix< double, 3, 1 > Vector3D
@ alongMomentum
CurvilinearParametersT< TrackParametersDim, Charged, PlaneSurface > CurvilinearParameters
ParticleHypothesis
Enumeration for Particle hypothesis respecting the interaction with material.