ATLAS Offline Software
Loading...
Searching...
No Matches
AlignTrackPreProcessor.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4
6
7#include "TrkTrack/Track.h"
9
10//Need to update the code to TrackParticles? The track Parameters of the track particles will be calculated wrt the new Beam Spot position.
11
13
16
17namespace Trk {
18
19 //________________________________________________________________________
21 const std::string & name,
22 const IInterface * parent)
23 : AthAlgTool(type,name,parent)
24 {
25 declareInterface<IAlignTrackPreProcessor>(this);
26 }
27
28 //________________________________________________________________________
30 {
31 // get track fitter tools
32 if (m_trackFitterTool.retrieve().isSuccess())
33 ATH_MSG_INFO("Retrieved " << m_trackFitterTool);
34 else{
35 ATH_MSG_FATAL("Could not get " << m_trackFitterTool);
36 return StatusCode::FAILURE;
37 }
38
40
41 if (m_SLTrackFitterTool.retrieve().isSuccess())
42 ATH_MSG_INFO("Retrieved " << m_SLTrackFitterTool);
43 else {
44 ATH_MSG_FATAL("Could not get " << m_SLTrackFitterTool);
45 return StatusCode::FAILURE;
46 }
47 }
48
49 if(m_selectTracks) {
50 if(m_trackSelectorTool.empty()) {
51 ATH_MSG_FATAL("TrackSelectorTool not specified : " << m_trackSelectorTool);
52 return StatusCode::FAILURE;
53 }
54 else if(m_trackSelectorTool.retrieve().isFailure())
55 {
56 ATH_MSG_FATAL("Could not get " << m_trackSelectorTool);
57 return StatusCode::FAILURE;
58 }
59 ATH_MSG_INFO("Retrieved " << m_trackSelectorTool);
60 }
61
62 if (m_selectHits) {
63 if(m_hitQualityTool.empty()) {
64 ATH_MSG_FATAL("HitQualityTool not specified : " << m_hitQualityTool);
65 return StatusCode::FAILURE;
66 }
67 else if(m_hitQualityTool.retrieve().isFailure()){
68 ATH_MSG_FATAL("Could not get " << m_trackSelectorTool);
69 return StatusCode::FAILURE;
70 }
71 ATH_MSG_INFO("Retrieved " << m_hitQualityTool);
72 }
73
74 return StatusCode::SUCCESS;
75 }
76
77 //________________________________________________________________________
79 {
80 return StatusCode::SUCCESS;
81 }
82
83 //________________________________________________________________________
85 {
86 ATH_MSG_DEBUG("AlignTrackPreProcessor::processTrackCollection()");
87
88 if (!tracks || tracks->empty())
89 return nullptr;
90
91 // the output collection of AlignTracks
92 // we define it as collection of Tracks but fill AlignTracks inside
93 DataVector<Track> * newTracks = new DataVector<Track>;
94
95 int itrk(0);
96 // loop over tracks and create AlignTracks
98 TrackCollection::const_iterator it_end = tracks->end();
99
100 for ( ; it != it_end ; ++it, ++itrk) {
101
102 ATH_MSG_DEBUG(" ** processTrackCollection ** Processing track "<<itrk);
103 const Track * origTrack = *it;
104 const Track * newTrack = *it;
105 AlignTrack* at;
106
107 // check whether the original track passes selection
108 if (m_selectTracks) {
109 if(!m_trackSelectorTool->accept(*origTrack)) {
110 ATH_MSG_VERBOSE(" ** processTrackCollection ** Original track did not pass the selection."<<itrk);
111 continue;
112 }
113
114 ToolHandle<Trk::IGlobalTrackFitter> fitter=m_trackFitterTool;
115 if (!m_useSingleFitter && AlignTrack::isSLTrack(origTrack) )
116 fitter = m_SLTrackFitterTool;
117
118 if (m_selectHits) {
120 ATH_MSG_DEBUG(" ** processTrackCollection ** entering the silicon hit selection ");
121 newTrack = performSiliconHitSelection(origTrack, fitter);
122
123 if (!newTrack) {
124 ATH_MSG_DEBUG(" ** processTrackCollection ** Track refit yielded no track. Skipping the track.");
125 continue;
126 }
127
128 // check whether the track passes selection
129 if(!m_trackSelectorTool->accept(*newTrack)) {
130 ATH_MSG_DEBUG(" ** processTrackCollection ** Track did not pass the selection.");
131 delete newTrack;
132 continue;
133 }
134 }
135
137 // refit track
139
140 newTrack=fitter->alignmentFit(alignCache,*origTrack,m_runOutlierRemoval,
141 static_cast<ParticleHypothesis>(m_particleHypothesis.value()));
142 if (!newTrack) {
143 ATH_MSG_DEBUG("Track refit yielded no track. Skipping the track.");
144 continue;
145 }
146 // check that the refitted track satisfies the aligntrack selection
147 if(!m_trackSelectorTool->accept(*newTrack)) {
148 ATH_MSG_DEBUG("New track did not pass the selection.");
149 delete newTrack;
150 continue;
151 }
152 }
153
154 at = new AlignTrack(*newTrack);
155
156 if (msgLvl(MSG::DEBUG)) {
157 ATH_MSG_DEBUG("before refit: ");
158 AlignTrack::dumpLessTrackInfo(*origTrack,msg(MSG::DEBUG));
159 ATH_MSG_DEBUG("after refit: ");
160 AlignTrack::dumpLessTrackInfo(*newTrack,msg(MSG::DEBUG));
161 }
162
163 // store fit matrices
166 at->setDerivativeMatrix(alignCache.m_derivMatrix);
167 }
168 if (m_fixMomentum)
169 {
170 at->AlignTrack::setRefitQovP(false);
171 }
172 // delete newTrack since it's copied in AlignTrack
173 delete newTrack;
174 }
175 else { // in case no selection is performed, keep all tracks
176 at=new AlignTrack(*newTrack);
177 }
178 if (m_fixMomentum)
179 {
180 at->AlignTrack::setRefitQovP(false);
181 }
182
183 newTracks->push_back(at);
184 }
185
186
187 if (newTracks->empty()) {
188 delete newTracks;
189 return nullptr;
190 }
191
192 return newTracks;
193 }
194
195 //________________________________________________________________________
196 Track * AlignTrackPreProcessor::performSiliconHitSelection(const Track * inputTrack, const ToolHandle<Trk::IGlobalTrackFitter> & fitter)
197 {
199 ATH_MSG_DEBUG(" -- performSiliconHitSelection -- before removing bad Silicon hits, this track has "<< inputTrack->trackStateOnSurfaces()->size()<< " tsos");
200 Track * newTrack;
201
202 std::vector<const Trk::MeasurementBase*> selectedMeasurementSet;
203
204 // loop on track hits
205 int nhits = 0;
206 for (const Trk::TrackStateOnSurface* tsos : *inputTrack->trackStateOnSurfaces())
207 {
208 nhits++;
209 if (m_hitQualityTool->isGoodSiHit(tsos)) {
210 selectedMeasurementSet.push_back( tsos->measurementOnTrack() );
211 }
212 else {
213 ATH_MSG_DEBUG(" -- performSiliconHitSelection -- hit # "<< nhits << " status = BAD HIT ");
214 }
215 }
216 ATH_MSG_DEBUG(" -- performSiliconHitSelection -- after removing bad Silicon hits, the selected measurement collection has "<< selectedMeasurementSet.size()<< " elements");
217
218 newTrack = (fitter->fit(Gaudi::Hive::currentContext(),
219 selectedMeasurementSet,
220 *inputTrack->perigeeParameters(),
222 static_cast<ParticleHypothesis>(m_particleHypothesis.value()))).release();
223
224 return newTrack;
225 }
226}
#define ATH_MSG_FATAL(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_DEBUG(x)
AthAlgTool(const std::string &type, const std::string &name, const IInterface *parent)
Constructor with parameters:
bool msgLvl(const MSG::Level lvl) const
MsgStream & msg() const
Derived DataVector<T>.
Definition DataVector.h:795
DataModel_detail::const_iterator< DataVector > const_iterator
Definition DataVector.h:838
value_type push_back(value_type pElem)
Add an element to the end of the collection.
const_iterator end() const noexcept
Return a const_iterator pointing past the end of the collection.
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.
size_type size() const noexcept
Returns the number of elements in the collection.
bool empty() const noexcept
Returns true if the collection is empty.
bool fit(const LArSamples::AbsShape &data, const AbsShape &reference, double &k, double &deltaT, double &chi2, const ScaledErrorData *sed=0) const
Track * performSiliconHitSelection(const Track *, const ToolHandle< Trk::IGlobalTrackFitter > &)
select silicon hits by quality.
ToolHandle< IGlobalTrackFitter > m_SLTrackFitterTool
AlignTrackPreProcessor(const std::string &type, const std::string &name, const IInterface *parent)
ToolHandle< InDet::IInDetTrackSelectionTool > m_trackSelectorTool
DataVector< Track > * processTrackCollection(const DataVector< Track > *trks)
creates AlignTrack containing all TSOS on track
ToolHandle< IInDetAlignHitQualSelTool > m_hitQualityTool
ToolHandle< IGlobalTrackFitter > m_trackFitterTool
static void dumpLessTrackInfo(const Track &track, MsgStream &msg)
dump less track information
void setDerivativeMatrix(const Amg::MatrixX *matrix)
Definition AlignTrack.h:269
void setFullCovarianceMatrix(const Amg::SymMatrixX *matrix)
Definition AlignTrack.h:274
bool isSLTrack() const
method to determine whether a straight line track or not
represents the track state (measurement, material, fit parameters and quality) at a surface.
const Trk::TrackStates * trackStateOnSurfaces() const
return a pointer to a const DataVector of const TrackStateOnSurfaces.
const Perigee * perigeeParameters() const
return Perigee.
Ensure that the ATLAS eigen extensions are properly loaded.
ParticleHypothesis
Enumeration for Particle hypothesis respecting the interaction with material.
Amg::MatrixX * m_derivMatrix
access to the matrix of derivatives used during the latest global-chi2 track fit.
Amg::MatrixX * m_fullCovarianceMatrix
access to the global fitter's full covariance matrix.