18 #include "GaudiKernel/IPartPropSvc.h"
19 #include "GaudiKernel/SystemOfUnits.h"
24 #include "HepPDT/ParticleDataTable.hh"
32 m_particlePropSvc(
"PartPropSvc",
n),
33 m_particleDataTable(nullptr)
35 declareInterface<Trk::ITruthTrackBuilder>(
this);
43 if (m_rotcreator.retrieve().isFailure()) {
45 return StatusCode::FAILURE;
48 if (m_rotcreatorbroad.retrieve().isFailure()) {
50 return StatusCode::FAILURE;
54 if (m_trackFitter.retrieve().isFailure()){
55 ATH_MSG_ERROR(
"Could not retrieve " << m_trackFitter <<
". Aborting ...");
56 return StatusCode::FAILURE;
60 if (m_extrapolator.retrieve().isFailure()){
61 ATH_MSG_ERROR(
"Could not retrieve " << m_extrapolator <<
". Aborting ...");
62 return StatusCode::FAILURE;
66 if (m_particlePropSvc.retrieve().isFailure())
68 ATH_MSG_ERROR(
"Can not retrieve " << m_particlePropSvc <<
" . Aborting ... " );
69 return StatusCode::FAILURE;
73 m_particleDataTable = m_particlePropSvc->PDT();
74 if (m_particleDataTable==
nullptr)
76 ATH_MSG_ERROR(
"Could not get ParticleDataTable! Cannot associate pdg code with charge. Aborting. " );
77 return StatusCode::FAILURE;
83 return StatusCode::FAILURE;
85 return StatusCode::SUCCESS;
92 return StatusCode::SUCCESS;
98 const EventContext& ctx = Gaudi::Hive::currentContext();
99 if( segs !=
nullptr ){
100 ATH_MSG_WARNING(
"Requested to fill segment collection but mode not implemented");
107 ATH_MSG_WARNING(
"No GenParticle associated to this PRD_TruthTrajectory. Ignoring track creation.");
110 ATH_MSG_VERBOSE(
"Got PRD Truth trajectory with " << prdTraj.
nDoF <<
" degrees of freedom.");
112 if ( m_minNdof > 0 && prdTraj.
nDoF < m_minNdof)
return nullptr;
116 genPart->production_vertex()->position().y(),
117 genPart->production_vertex()->position().z()) :
Amg::Vector3D(0.,0.,0.);
119 genPart->momentum().y(),
120 genPart->momentum().z());
123 int pdgCode = genPart->pdg_id();
125 const HepPDT::ParticleData*
ap = m_particleDataTable->particle(std::abs(pdgCode));
129 charge *= (pdgCode > 0.) ? 1. : -1.;
132 const std::vector<const Trk::PrepRawData*> &
clusters = prdTraj.
prds;
137 auto per = std::unique_ptr<Trk::TrackParameters>(
138 m_extrapolator->extrapolate(ctx,
145 ATH_MSG_DEBUG(
"Perigee creation for genParticle start position failed. "
146 "Skipping track creation.");
150 std::bitset<Trk::TrackStateOnSurface::NumberOfTrackStateOnSurfaceTypes> typePattern;
154 auto traj = std::make_unique<Trk::TrackStates>();
155 traj->push_back(pertsos);
159 std::unique_ptr<const Trk::TrackParameters> prevpar(startParams.
uniqueClone());
163 if (m_DetID->is_trt(
clusters[
i]->identify()))
break;
167 if (m_DetID->is_pixel(
clusters[
i]->identify())) ispixel=
true;
169 auto thispar = std::unique_ptr<const Trk::TrackParameters>(
170 m_extrapolator->extrapolate(ctx,
184 std::bitset<Trk::TrackStateOnSurface::NumberOfTrackStateOnSurfaceTypes> typePattern;
186 std::unique_ptr<Trk::RIO_OnTrack> rot{m_rotcreator->correct(*
clusters[
i],*thispar,ctx)};
192 traj->push_back(tsos);
193 prevpar=std::move(thispar);
198 if ( (
track.measurementsOnTrack()->size() < m_minSiHits &&
199 std::abs(genPart->momentum().eta()) <= m_forwardBoundary) ||
200 (
track.measurementsOnTrack()->size() < m_minSiHitsForward &&
201 std::abs(genPart->momentum().eta()) > m_forwardBoundary) ||
204 "Track does not fulfill requirements for refitting. Skipping it.");
216 Trk::Track *refittedtrack=(m_trackFitter->fit(Gaudi::Hive::currentContext(),
track,
false,materialInteractions)).
release();
220 if (refittedtrack && (
int)
clusters.size()-
i>=9){
223 std::vector<std::unique_ptr<MeasurementBase>> meassetOwn;
227 std::unique_ptr<const Trk::TrackParameters> prevpar(refittedtrack->
trackParameters()->back()->uniqueClone());
235 meassetOwn.emplace_back(rot);
236 measset.push_back(meassetOwn.back().get());
238 prevpar=std::move(thispar);
241 refittedtrack2=(m_trackFitter->fit(Gaudi::Hive::currentContext(),*refittedtrack,measset,
false,materialInteractions)).
release();
243 if (!refittedtrack2){
244 auto traj2 = std::make_unique<Trk::TrackStates>();
246 std::bitset<Trk::TrackStateOnSurface::NumberOfTrackStateOnSurfaceTypes> typePattern2;
249 for (
auto & j : meassetOwn) {
260 }
else if(!refittedtrack){
261 ATH_MSG_VERBOSE(
"Track fit of truth trajectory NOT successful, NO track created. ");
265 if (refittedtrack2)
delete refittedtrack;
266 if (!refittedtrack2 && refittedtrack) refittedtrack2=refittedtrack;
269 ATH_MSG_DEBUG(
"Track fit of truth trajectory successful, track created. ");
275 return refittedtrack2;