ATLAS Offline Software
Loading...
Searching...
No Matches
TruthTrackBuilder.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3*/
4
6// TruthTrackBuilder.cxx, (c) ATLAS Detector software
8
9// package include
10#include "TruthTrackBuilder.h"
11// Trk includes
12#include "TrkTrack/Track.h"
13
17// Gaudi
18#include "GaudiKernel/SystemOfUnits.h"
19// HepMC
24
26
28Trk::TruthTrackBuilder::TruthTrackBuilder(const std::string& t, const std::string& n, const IInterface* p) :
29 AthAlgTool(t,n,p),
30 m_DetID(nullptr)
31{
32 declareInterface<Trk::ITruthTrackBuilder>(this);
33}
34
35
36// Athena algtool's Hooks
38{
39 ATH_MSG_VERBOSE("Initializing ...");
40 if (m_rotcreator.retrieve().isFailure()) {
41 msg(MSG::FATAL) << "Could not get " << m_rotcreator.type() << endmsg;
42 return StatusCode::FAILURE;
43 }
44
45 if (m_rotcreatorbroad.retrieve().isFailure()) {
46 msg(MSG::FATAL) << "Could not get " << m_rotcreatorbroad.type() << endmsg;
47 return StatusCode::FAILURE;
48 }
49
50 // track fitter
51 if (m_trackFitter.retrieve().isFailure()){
52 ATH_MSG_ERROR("Could not retrieve " << m_trackFitter << ". Aborting ...");
53 return StatusCode::FAILURE;
54 }
55
56 // extrapolator
57 if (m_extrapolator.retrieve().isFailure()){
58 ATH_MSG_ERROR("Could not retrieve " << m_extrapolator << ". Aborting ...");
59 return StatusCode::FAILURE;
60 }
61
62 // need an Atlas id-helper to identify sub-detectors, take the one from detStore
63 if (detStore()->retrieve(m_DetID, "AtlasID").isFailure()) {
64 ATH_MSG_ERROR ("Could not get AtlasDetectorID helper" );
65 return StatusCode::FAILURE;
66 }
67 return StatusCode::SUCCESS;
68}
69
70
72{
73 ATH_MSG_VERBOSE("Finalizing ...");
74 return StatusCode::SUCCESS;
75}
76
77
79{
80 const EventContext& ctx = Gaudi::Hive::currentContext();
81 if( segs != nullptr ){
82 ATH_MSG_WARNING("Requested to fill segment collection but mode not implemented");
83 }
84 ATH_MSG_VERBOSE("The PRD Truth trajectory contains " << prdTraj.prds.size() << " PRDs.");
85
86 // get the associated GenParticle
87 auto genPart = prdTraj.genParticle;
88 if (!genPart) {
89 ATH_MSG_WARNING("No GenParticle associated to this PRD_TruthTrajectory. Ignoring track creation.");
90 return nullptr;
91 }
92 ATH_MSG_VERBOSE("Got PRD Truth trajectory with " << prdTraj.nDoF << " degrees of freedom.");
93 // check min degrees of freedom
94 if ( m_minNdof > 0 && prdTraj.nDoF < m_minNdof) return nullptr;
95 // get the startPosition : math library madness as usual
96 Amg::Vector3D startPos = genPart->production_vertex() ?
97 Amg::Vector3D(genPart->production_vertex()->position().x(),
98 genPart->production_vertex()->position().y(),
99 genPart->production_vertex()->position().z()) : Amg::Vector3D(0.,0.,0.);
100 Amg::Vector3D startMom(genPart->momentum().x(),
101 genPart->momentum().y(),
102 genPart->momentum().z());
104
105 const int pdgCode = genPart->pdg_id();
106 const double charge = MC::charge(pdgCode);
107
108 // ----------------------- get teh PRDS and start
109 const std::vector<const Trk::PrepRawData*> & clusters = prdTraj.prds;
110 // nominal 0,0,0 position for track fit seeding
111 Trk::PerigeeSurface persurf;
112 Trk::CurvilinearParameters startParams(startPos,startMom,charge);
113 //minimal conversion; ideally the extrapolator would return a unique_ptr
114 auto per = std::unique_ptr<Trk::TrackParameters>(
115 m_extrapolator->extrapolate(ctx,
116 startParams,
117 persurf,
119 false,
121 if (!per) {
122 ATH_MSG_DEBUG("Perigee creation for genParticle start position failed. "
123 "Skipping track creation.");
124 return nullptr;
125 }
126 // first TrackStateOnSurface is the Perigee
127 std::bitset<Trk::TrackStateOnSurface::NumberOfTrackStateOnSurfaceTypes> typePattern;
128 typePattern.set(Trk::TrackStateOnSurface::Perigee);
129
130 const Trk::TrackStateOnSurface *pertsos=new Trk::TrackStateOnSurface(nullptr,std::move(per),nullptr,typePattern);
131 auto traj = std::make_unique<Trk::TrackStates>();
132 traj->push_back(pertsos);
133
134
135
136 std::unique_ptr<const Trk::TrackParameters> prevpar(startParams.uniqueClone());
137 // First create a Trk::Track object 'traj' that will go into the fitter for refitting
138 int i=0;
139 for ( ;i<(int)clusters.size();i++){
140 if (m_DetID->is_trt(clusters[i]->identify())) break;
141 const Trk::Surface &surf=clusters[i]->detectorElement()->surface(clusters[i]->identify());
142 if (surf==prevpar->associatedSurface()) continue;
143 bool ispixel=false;
144 if (m_DetID->is_pixel(clusters[i]->identify())) ispixel=true;
145
146 auto thispar = std::unique_ptr<const Trk::TrackParameters>(
147 m_extrapolator->extrapolate(ctx,
148 *prevpar,
149 surf,
151 false,
153 if (!thispar)
154 break;
155 if (!surf.insideBounds(thispar->localPosition(),20*Gaudi::Units::mm,50*Gaudi::Units::mm)) {
156 continue;
157 }
158 AmgVector(5) params=thispar->parameters();
159 params[Trk::loc1]=clusters[i]->localPosition().x();
160 if (ispixel) params[Trk::loc2]=clusters[i]->localPosition().y();
161 std::bitset<Trk::TrackStateOnSurface::NumberOfTrackStateOnSurfaceTypes> typePattern;
163 std::unique_ptr<Trk::RIO_OnTrack> rot{m_rotcreator->correct(*clusters[i],*thispar,ctx)};
164 if (!rot) {
165 continue;
166 }
167 // create the ROTs for the reference trajectory
168 const Trk::TrackStateOnSurface *tsos=new Trk::TrackStateOnSurface(std::move(rot),thispar->uniqueClone(),nullptr,typePattern);
169 traj->push_back(tsos);
170 prevpar=std::move(thispar);
171 }
172 // this is the reference trajectory to be refitted
173 Trk::TrackInfo info;
174 Trk::Track track(info, std::move(traj), nullptr);
175 if (/* ndof<0 */ (track.measurementsOnTrack()->size() < m_minSiHits &&
176 std::abs(genPart->momentum().eta()) <= m_forwardBoundary) ||
177 (track.measurementsOnTrack()->size() < m_minSiHitsForward &&
178 std::abs(genPart->momentum().eta()) > m_forwardBoundary) ||
181 "Track does not fulfill requirements for refitting. Skipping it.");
182 return nullptr;
183 }
184 // choose the material effects
186
187 // create the refitted track
188 //
189 //
190 //
192
193 Trk::Track *refittedtrack=(m_trackFitter->fit(Gaudi::Hive::currentContext(),track,false,materialInteractions)).release();
194
196 Trk::Track *refittedtrack2=nullptr;
197 if (refittedtrack && (int)clusters.size()-i>=9){
198
199 //owner of measurements so they get cleaned up automatically if needs be
200 std::vector<std::unique_ptr<MeasurementBase>> meassetOwn;
201 //vector of plain ptr to the owned ones acts as a "view"
202 Trk::MeasurementSet measset;
203
204 std::unique_ptr<const Trk::TrackParameters> prevpar(refittedtrack->trackParameters()->back()->uniqueClone());
205 for (;i<(int)clusters.size();i++) {
206 const Trk::Surface *surf=&clusters[i]->detectorElement()->surface(clusters[i]->identify());
207 std::unique_ptr<const Trk::TrackParameters> thispar(m_extrapolator->extrapolate(ctx,*prevpar,*surf,Trk::alongMomentum,false,Trk::nonInteracting));
208 if (!thispar) break;
209 Trk::RIO_OnTrack *rot=m_rotcreatorbroad->correct(*clusters[i],*thispar,ctx);
210
211 if (rot) {
212 meassetOwn.emplace_back(rot);
213 measset.push_back(meassetOwn.back().get());
214 }
215 prevpar=std::move(thispar);
216 }
217
218 refittedtrack2=(m_trackFitter->fit(Gaudi::Hive::currentContext(),*refittedtrack,measset,false,materialInteractions)).release();
219
220 if (!refittedtrack2){
221 auto traj2 = std::make_unique<Trk::TrackStates>();
222 for (const Trk::TrackStateOnSurface *j : *refittedtrack->trackStateOnSurfaces()) traj2->push_back(new Trk::TrackStateOnSurface(*j));
223 std::bitset<Trk::TrackStateOnSurface::NumberOfTrackStateOnSurfaceTypes> typePattern2;
224 typePattern2.set(Trk::TrackStateOnSurface::Outlier);
225 //measset needs to be unique_ptr before progress further
226 for (auto & j : meassetOwn) {
227 traj2->push_back(new Trk::TrackStateOnSurface(
228 std::move(j),
229 nullptr,
230 nullptr,
231 typePattern2));
232 }
233 refittedtrack2 = new Trk::Track(refittedtrack->info(),
234 std::move(traj2),
235 refittedtrack->fitQuality()->uniqueClone());
236 }
237 } else if(!refittedtrack){
238 ATH_MSG_VERBOSE("Track fit of truth trajectory NOT successful, NO track created. ");
239 return nullptr;
240 }
241
242 if (refittedtrack2) delete refittedtrack;
243 if (!refittedtrack2 && refittedtrack) refittedtrack2=refittedtrack;
244
245 //
246 ATH_MSG_DEBUG("Track fit of truth trajectory successful, track created. ");
247 // return what you have
248 // Before returning, fix the creator
249 if (refittedtrack2){
251 }
252 return refittedtrack2;
253}
254
#define endmsg
#define ATH_MSG_ERROR(x)
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
This class provides an interface to generate or decode an identifier for the upper levels of the dete...
double charge(const T &p)
Definition AtlasPID.h:997
#define AmgVector(rows)
ATLAS-specific HepMC functions.
AthAlgTool(const std::string &type, const std::string &name, const IInterface *parent)
Constructor with parameters:
const ServiceHandle< StoreGateSvc > & detStore() const
std::unique_ptr< FitQuality > uniqueClone() const
NVI uniqueClone.
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...
Class describing the Line to which the Perigee refers to.
Class to handle RIO On Tracks ROT) for InDet and Muons, it inherits from the common MeasurementBase.
Definition RIO_OnTrack.h:70
Abstract Base Class for tracking surfaces.
Definition Surface.h:79
virtual bool insideBounds(const Amg::Vector2D &locpos, double tol1=0., double tol2=0.) const =0
virtual methods to be overwritten by the inherited surfaces
Contains information about the 'fitter' of this track.
void setPatternRecognitionInfo(const TrackPatternRecoInfo &patternReco)
Method setting the pattern recognition algorithm.
represents the track state (measurement, material, fit parameters and quality) at a surface.
@ Measurement
This is a measurement, and will at least contain a Trk::MeasurementBase.
@ Perigee
This represents a perigee, and so will contain a Perigee object only.
@ Outlier
This TSoS contains an outlier, that is, it contains a MeasurementBase/RIO_OnTrack which was not used ...
const Trk::TrackStates * trackStateOnSurfaces() const
return a pointer to a const DataVector of const TrackStateOnSurfaces.
const DataVector< const TrackParameters > * trackParameters() const
Return a pointer to a vector of TrackParameters.
const TrackInfo & info() const
Returns a const ref to info of a const tracks.
const FitQuality * fitQuality() const
return a pointer to the fit quality const-overload
ToolHandle< IRIO_OnTrackCreator > m_rotcreator
Gaudi::Property< unsigned int > m_minSiHits
min number of Si hits for refit
Gaudi::Property< float > m_forwardBoundary
Boundary eta value defining the forward region.
Gaudi::Property< unsigned int > m_minSiHitsForward
min number of Si hits for refit in forward region (ITk specific)
const AtlasDetectorID * m_DetID
TruthTrackBuilder(const std::string &t, const std::string &n, const IInterface *p)
Constructor.
Track * createTrack(const PRD_TruthTrajectory &prdTraj, SegmentCollection *segs=0) const
return a map of GenParticles to PRDs for further processing
Gaudi::Property< size_t > m_minNdof
checks min degrees of freedom if bigger -1
Gaudi::Property< bool > m_onlyPrimaries
restrict track creation to primaries
ToolHandle< ITrackFitter > m_trackFitter
fits the PRDs
Gaudi::Property< int > m_matEffects
ToolHandle< IRIO_OnTrackCreator > m_rotcreatorbroad
ToolHandle< IExtrapolator > m_extrapolator
extrapolator
Eigen::Matrix< double, 3, 1 > Vector3D
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...
double charge(const T &p)
constexpr ParticleHypothesis particle[PARTICLEHYPOTHESES]
the array of masses
@ alongMomentum
@ anyDirection
std::vector< const MeasurementBase * > MeasurementSet
vector of fittable measurements
Definition FitterTypes.h:30
DataVector< Trk::Segment > SegmentCollection
CurvilinearParametersT< TrackParametersDim, Charged, PlaneSurface > CurvilinearParameters
@ loc2
generic first and second local coordinate
Definition ParamDefs.h:35
@ loc1
Definition ParamDefs.h:34
ParticleHypothesis
Enumeration for Particle hypothesis respecting the interaction with material.
simple definitiion of a PRD_TruhtTrajectory
std::vector< const Trk::PrepRawData * > prds
public members
HepMC::ConstGenParticlePtr genParticle
MsgStream & msg
Definition testRead.cxx:32