ATLAS Offline Software
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 
17 namespace Trk {
18 
19  //________________________________________________________________________
21  const std::string & name,
22  const IInterface * 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 
39  if (m_useSingleFitter) {
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) )
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
138  if (m_refitTracks &!m_selectHits) {
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: ");
159  ATH_MSG_DEBUG("after refit: ");
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 }
LArSamples::FitterData::fitter
const ShapeFitter * fitter
Definition: ShapeFitter.cxx:23
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
DataModel_detail::const_iterator
Const iterator class for DataVector/DataList.
Definition: DVLIterator.h:82
Trk::AlignTrackPreProcessor::initialize
StatusCode initialize()
Definition: AlignTrackPreProcessor.cxx:29
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
Trk::IGlobalTrackFitter::AlignmentCache::m_derivMatrix
Amg::MatrixX * m_derivMatrix
access to the matrix of derivatives used during the latest global-chi2 track fit.
Definition: IGlobalTrackFitter.h:42
Trk::AlignTrackPreProcessor::m_refitTracks
BooleanProperty m_refitTracks
Definition: AlignTrackPreProcessor.h:63
Trk::Track::trackStateOnSurfaces
const Trk::TrackStates * trackStateOnSurfaces() const
return a pointer to a const DataVector of const TrackStateOnSurfaces.
Trk::AlignTrackPreProcessor::m_selectTracks
BooleanProperty m_selectTracks
Definition: AlignTrackPreProcessor.h:77
skel.it
it
Definition: skel.GENtoEVGEN.py:407
AthCommonMsg< AlgTool >::msgLvl
bool msgLvl(const MSG::Level lvl) const
Definition: AthCommonMsg.h:30
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
Trk::AlignTrack::isSLTrack
bool isSLTrack() const
method to determine whether a straight line track or not
Definition: AlignTrack.cxx:263
LArSamples::ShapeFitter::fit
bool fit(const LArSamples::AbsShape &data, const AbsShape &reference, double &k, double &deltaT, double &chi2, const ScaledErrorData *sed=0) const
Definition: ShapeFitter.cxx:32
python.CaloAddPedShiftConfig.type
type
Definition: CaloAddPedShiftConfig.py:42
Trk::AlignTrack::setFullCovarianceMatrix
void setFullCovarianceMatrix(const Amg::SymMatrixX *matrix)
Definition: AlignTrack.h:274
Trk::IGlobalTrackFitter::AlignmentCache::m_fullCovarianceMatrix
Amg::MatrixX * m_fullCovarianceMatrix
access to the global fitter's full covariance matrix.
Definition: IGlobalTrackFitter.h:45
Trk::AlignTrackPreProcessor::m_selectHits
BooleanProperty m_selectHits
Definition: AlignTrackPreProcessor.h:79
Track.h
Trk::ParticleHypothesis
ParticleHypothesis
Definition: ParticleHypothesis.h:28
Trk::AlignTrackPreProcessor::performSiliconHitSelection
Track * performSiliconHitSelection(const Track *, const ToolHandle< Trk::IGlobalTrackFitter > &)
select silicon hits by quality.
Definition: AlignTrackPreProcessor.cxx:196
AlignTrack.h
Trk::IGlobalTrackFitter::AlignmentCache
Definition: IGlobalTrackFitter.h:38
Trk::AlignTrackPreProcessor::AlignTrackPreProcessor
AlignTrackPreProcessor(const std::string &type, const std::string &name, const IInterface *parent)
Definition: AlignTrackPreProcessor.cxx:20
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
Trk::AlignTrackPreProcessor::m_useSingleFitter
BooleanProperty m_useSingleFitter
Definition: AlignTrackPreProcessor.h:74
TrackCollection.h
test_pyathena.parent
parent
Definition: test_pyathena.py:15
Trk::AlignTrackPreProcessor::m_trackSelectorTool
ToolHandle< InDet::IInDetTrackSelectionTool > m_trackSelectorTool
Definition: AlignTrackPreProcessor.h:55
Trk::AlignTrackPreProcessor::processTrackCollection
DataVector< Track > * processTrackCollection(const DataVector< Track > *trks)
creates AlignTrack containing all TSOS on track
Definition: AlignTrackPreProcessor.cxx:84
Trk::AlignTrackPreProcessor::m_trackFitterTool
ToolHandle< IGlobalTrackFitter > m_trackFitterTool
Definition: AlignTrackPreProcessor.h:50
Trk::AlignTrackPreProcessor::m_particleHypothesis
IntegerProperty m_particleHypothesis
Definition: AlignTrackPreProcessor.h:70
DataVector
Derived DataVector<T>.
Definition: DataVector.h:794
ParticleHypothesis.h
EventPrimitives.h
Trk::Track::perigeeParameters
const Perigee * perigeeParameters() const
return Perigee.
Definition: Tracking/TrkEvent/TrkTrack/src/Track.cxx:163
Trk
Ensure that the ATLAS eigen extensions are properly loaded.
Definition: FakeTrackBuilder.h:9
Trk::AlignTrackPreProcessor::m_runOutlierRemoval
BooleanProperty m_runOutlierRemoval
Definition: AlignTrackPreProcessor.h:68
Trk::TrackStateOnSurface
represents the track state (measurement, material, fit parameters and quality) at a surface.
Definition: TrackStateOnSurface.h:71
python.EventInfoMgtInit.release
release
Definition: EventInfoMgtInit.py:23
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:240
DataVector::push_back
value_type push_back(value_type pElem)
Add an element to the end of the collection.
Trk::AlignTrack
Definition: AlignTrack.h:41
Trk::AlignTrackPreProcessor::m_storeFitMatricesAfterRefit
BooleanProperty m_storeFitMatricesAfterRefit
Definition: AlignTrackPreProcessor.h:64
DataVector::end
const_iterator end() const noexcept
Return a const_iterator pointing past the end of the collection.
Trk::AlignTrackPreProcessor::m_fixMomentum
BooleanProperty m_fixMomentum
Definition: AlignTrackPreProcessor.h:81
AlignTrackPreProcessor.h
Trk::AlignTrackPreProcessor::m_hitQualityTool
ToolHandle< IInDetAlignHitQualSelTool > m_hitQualityTool
Definition: AlignTrackPreProcessor.h:57
DEBUG
#define DEBUG
Definition: page_access.h:11
AthCommonMsg< AlgTool >::msg
MsgStream & msg() const
Definition: AthCommonMsg.h:24
Trk::AlignTrackPreProcessor::m_SLTrackFitterTool
ToolHandle< IGlobalTrackFitter > m_SLTrackFitterTool
Definition: AlignTrackPreProcessor.h:52
Trk::AlignTrack::dumpLessTrackInfo
static void dumpLessTrackInfo(const Track &track, MsgStream &msg)
dump less track information
Definition: AlignTrack.cxx:276
Track
Definition: TriggerChamberClusterOnTrackCreator.h:21
Trk::AlignTrackPreProcessor::finalize
StatusCode finalize()
Definition: AlignTrackPreProcessor.cxx:78
AthAlgTool
Definition: AthAlgTool.h:26
Trk::AlignTrack::setDerivativeMatrix
void setDerivativeMatrix(const Amg::MatrixX *matrix)
Definition: AlignTrack.h:269
DataVector::size
size_type size() const noexcept
Returns the number of elements in the collection.
DataVector::empty
bool empty() const noexcept
Returns true if the collection is empty.
DataVector::begin
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.