ATLAS Offline Software
Loading...
Searching...
No Matches
AlignTrackPreProcessor.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 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 const EventContext& ctx = Gaudi::Hive::currentContext();
92
93 // the output collection of AlignTracks
94 // we define it as collection of Tracks but fill AlignTracks inside
95 DataVector<Track> * newTracks = new DataVector<Track>;
96
97 int itrk(0);
98 // loop over tracks and create AlignTracks
100 TrackCollection::const_iterator it_end = tracks->end();
101
102 for ( ; it != it_end ; ++it, ++itrk) {
103
104 ATH_MSG_DEBUG(" ** processTrackCollection ** Processing track "<<itrk);
105 const Track * origTrack = *it;
106 const Track * newTrack = *it;
107 AlignTrack* at;
108
109 // check whether the original track passes selection
110 if (m_selectTracks) {
111 if(!m_trackSelectorTool->accept(*origTrack)) {
112 ATH_MSG_VERBOSE(" ** processTrackCollection ** Original track did not pass the selection."<<itrk);
113 continue;
114 }
115
116 ToolHandle<Trk::IGlobalTrackFitter> fitter=m_trackFitterTool;
117 if (!m_useSingleFitter && AlignTrack::isSLTrack(origTrack) )
118 fitter = m_SLTrackFitterTool;
119
120 if (m_selectHits) {
122 ATH_MSG_DEBUG(" ** processTrackCollection ** entering the silicon hit selection ");
123 newTrack = performSiliconHitSelection(origTrack, fitter);
124
125 if (!newTrack) {
126 ATH_MSG_DEBUG(" ** processTrackCollection ** Track refit yielded no track. Skipping the track.");
127 continue;
128 }
129
130 // check whether the track passes selection
131 if(!m_trackSelectorTool->accept(*newTrack)) {
132 ATH_MSG_DEBUG(" ** processTrackCollection ** Track did not pass the selection.");
133 delete newTrack;
134 continue;
135 }
136 }
137
139 // refit track
141
142 newTrack=fitter->alignmentFit(ctx,alignCache,*origTrack,m_runOutlierRemoval,
143 static_cast<ParticleHypothesis>(m_particleHypothesis.value()));
144 if (!newTrack) {
145 ATH_MSG_DEBUG("Track refit yielded no track. Skipping the track.");
146 continue;
147 }
148 // check that the refitted track satisfies the aligntrack selection
149 if(!m_trackSelectorTool->accept(*newTrack)) {
150 ATH_MSG_DEBUG("New track did not pass the selection.");
151 delete newTrack;
152 continue;
153 }
154 }
155
156 at = new AlignTrack(*newTrack);
157
158 if (msgLvl(MSG::DEBUG)) {
159 ATH_MSG_DEBUG("before refit: ");
160 AlignTrack::dumpLessTrackInfo(*origTrack,msg(MSG::DEBUG));
161 ATH_MSG_DEBUG("after refit: ");
162 AlignTrack::dumpLessTrackInfo(*newTrack,msg(MSG::DEBUG));
163 }
164
165 // store fit matrices
167 at->setFullCovarianceMatrix(alignCache.m_fullCovarianceMatrix.get());
168 at->setDerivativeMatrix(alignCache.m_derivMatrix.get());
169 }
170 if (m_fixMomentum)
171 {
172 at->AlignTrack::setRefitQovP(false);
173 }
174 // delete newTrack since it's copied in AlignTrack
175 delete newTrack;
176 }
177 else { // in case no selection is performed, keep all tracks
178 at=new AlignTrack(*newTrack);
179 }
180 if (m_fixMomentum)
181 {
182 at->AlignTrack::setRefitQovP(false);
183 }
184
185 newTracks->push_back(at);
186 }
187
188
189 if (newTracks->empty()) {
190 delete newTracks;
191 return nullptr;
192 }
193
194 return newTracks;
195 }
196
197 //________________________________________________________________________
198 Track * AlignTrackPreProcessor::performSiliconHitSelection(const Track * inputTrack, const ToolHandle<Trk::IGlobalTrackFitter> & fitter)
199 {
201 ATH_MSG_DEBUG(" -- performSiliconHitSelection -- before removing bad Silicon hits, this track has "<< inputTrack->trackStateOnSurfaces()->size()<< " tsos");
202
203 Track * newTrack;
204 std::vector<const Trk::MeasurementBase*> selectedMeasurementSet;
205 const EventContext& ctx = Gaudi::Hive::currentContext();
206
207 // loop on track hits
208 int nhits = 0;
209 for (const Trk::TrackStateOnSurface* tsos : *inputTrack->trackStateOnSurfaces())
210 {
211 nhits++;
212 if (m_hitQualityTool->isGoodSiHit(tsos)) {
213 selectedMeasurementSet.push_back( tsos->measurementOnTrack() );
214 }
215 else {
216 ATH_MSG_DEBUG(" -- performSiliconHitSelection -- hit # "<< nhits << " status = BAD HIT ");
217 }
218 }
219 ATH_MSG_DEBUG(" -- performSiliconHitSelection -- after removing bad Silicon hits, the selected measurement collection has "<< selectedMeasurementSet.size()<< " elements");
220
221 newTrack = (fitter->fit(ctx,
222 selectedMeasurementSet,
223 *inputTrack->perigeeParameters(),
225 static_cast<ParticleHypothesis>(m_particleHypothesis.value()))).release();
226
227 return newTrack;
228 }
229}
#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
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.
std::unique_ptr< Amg::MatrixX > m_fullCovarianceMatrix
access to the global fitter's full covariance matrix.
std::unique_ptr< Amg::MatrixX > m_derivMatrix
access to the matrix of derivatives used during the latest global-chi2 track fit.