ATLAS Offline Software
AlignTrackPreProcessor.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 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 
12 //#include "xAODTracking/TrackParticle.h"
13 //#include "xAODTracking/TrackParticleContainer.h"
14 
17 
18 //Old Interface
19 //#include "TrkToolInterfaces/ITrackSelectorTool.h"
20 
21 
22 
23 
26 
27 namespace Trk {
28 
29  //________________________________________________________________________
31  const std::string & name,
32  const IInterface * parent)
34  , m_trackFitterTool("Trk::GlobalChi2Fitter/InDetTrackFitter")
35  , m_SLTrackFitterTool("")
36  , m_trackSelectorTool("")
37  , m_runOutlierRemoval(false)
38  , m_particleHypothesis(Trk::nonInteracting)
39  , m_useSingleFitter(false)
40  , m_selectHits(false)
41  , m_fixMomentum(false)
42  {
43  declareInterface<IAlignTrackPreProcessor>(this);
44 
45  declareProperty("RefitTracks", m_refitTracks = true);
46 
47  declareProperty("TrackFitterTool", m_trackFitterTool);
48  declareProperty("SLTrackFitterTool", m_SLTrackFitterTool);
49  declareProperty("UseSingleFitter", m_useSingleFitter = false);
50 
51  declareProperty("StoreFitMatricesAfterRefit", m_storeFitMatricesAfterRefit = true);
52 
53  declareProperty("TrackSelectorTool", m_trackSelectorTool);
54  declareProperty("SelectTracks", m_selectTracks = false);
55 
56  declareProperty("ParticleHypothesis", m_particleHypothesis);
57  declareProperty("RunOutlierRemoval", m_runOutlierRemoval = false);
58 
59  declareProperty("HitQualityTool", m_hitQualityTool);
60  declareProperty("SelectHits", m_selectHits);
61  declareProperty("FixMomentum", m_fixMomentum);
62 
63  m_logStream = nullptr;
64  }
65 
66  //________________________________________________________________________
68  = default;
69 
70  //________________________________________________________________________
72  {
73  // get track fitter tools
74  if (m_trackFitterTool.retrieve().isSuccess())
75  ATH_MSG_INFO("Retrieved " << m_trackFitterTool);
76  else{
77  msg(MSG::FATAL) << "Could not get " << m_trackFitterTool << endmsg;
78  return StatusCode::FAILURE;
79  }
80 
81  if (m_useSingleFitter) {
82 
83  if (m_SLTrackFitterTool.retrieve().isSuccess())
84  ATH_MSG_INFO("Retrieved " << m_SLTrackFitterTool);
85  else {
86  msg(MSG::FATAL) << "Could not get " << m_SLTrackFitterTool << endmsg;
87  return StatusCode::FAILURE;
88  }
89  }
90 
91  if(m_selectTracks) {
92  if(m_trackSelectorTool.empty()) {
93  msg(MSG::FATAL) << "TrackSelectorTool not specified : " << m_trackSelectorTool << endmsg;
94  return StatusCode::FAILURE;
95  }
96  else if(m_trackSelectorTool.retrieve().isFailure())
97  {
98  msg(MSG::FATAL) << "Could not get " << m_trackSelectorTool << endmsg;
99  return StatusCode::FAILURE;
100  }
101  ATH_MSG_INFO("Retrieved " << m_trackSelectorTool);
102  }
103 
104  if (m_selectHits) {
105  if(m_hitQualityTool.empty()) {
106  msg(MSG::FATAL) << "HitQualityTool not specified : " << m_hitQualityTool << endmsg;
107  return StatusCode::FAILURE;
108  }
109  else if(m_hitQualityTool.retrieve().isFailure())
110  {
111  msg(MSG::FATAL) << "Could not get " << m_trackSelectorTool << endmsg;
112  return StatusCode::FAILURE;
113  }
114  ATH_MSG_INFO("Retrieved " << m_hitQualityTool);
115  }
116 
117  return StatusCode::SUCCESS;
118  }
119 
120  //________________________________________________________________________
122  {
123  return StatusCode::SUCCESS;
124  }
125 
126  //________________________________________________________________________
128  {
129  ATH_MSG_DEBUG("AlignTrackPreProcessor::processTrackCollection()");
130 
131  if (!tracks || tracks->empty())
132  return nullptr;
133 
134  // the output collection of AlignTracks
135  // we define it as collection of Tracks but fill AlignTracks inside
136  DataVector<Track> * newTracks = new DataVector<Track>;
137 
138  int itrk(0);
139  // loop over tracks and create AlignTracks
141  TrackCollection::const_iterator it_end = tracks->end();
142 
143  for ( ; it != it_end ; ++it, ++itrk) {
144 
145  ATH_MSG_DEBUG(" ** processTrackCollection ** Processing track "<<itrk);
146  const Track * origTrack = *it;
147  const Track * newTrack = *it;
148  AlignTrack* at;
149 
150  // check whether the original track passes selection
151  if (m_selectTracks) {
152  if(!m_trackSelectorTool->accept(*origTrack)) {
153  ATH_MSG_VERBOSE(" ** processTrackCollection ** Original track did not pass the selection."<<itrk);
154  continue;
155  }
156 
157  ToolHandle<Trk::IGlobalTrackFitter> fitter=m_trackFitterTool;
158  if (!m_useSingleFitter && AlignTrack::isSLTrack(origTrack) )
160 
161  if (m_selectHits) {
163  ATH_MSG_DEBUG(" ** processTrackCollection ** entering the silicon hit selection ");
164  newTrack = performSiliconHitSelection(origTrack, fitter);
165 
166  if (!newTrack) {
167  ATH_MSG_DEBUG(" ** processTrackCollection ** Track refit yielded no track. Skipping the track.");
168  continue;
169  }
170 
171  // check whether the track passes selection
172  if(!m_trackSelectorTool->accept(*newTrack)) {
173  ATH_MSG_DEBUG(" ** processTrackCollection ** Track did not pass the selection.");
174  delete newTrack;
175  continue;
176  }
177  }
178 
180  // refit track
181  if (m_refitTracks &!m_selectHits) {
182 
183  newTrack=fitter->alignmentFit(alignCache,*origTrack,m_runOutlierRemoval,ParticleHypothesis(m_particleHypothesis));
184  if (!newTrack) {
185  ATH_MSG_DEBUG("Track refit yielded no track. Skipping the track.");
186  continue;
187  }
188  // check that the refitted track satisfies the aligntrack selection
189  if(!m_trackSelectorTool->accept(*newTrack)) {
190  ATH_MSG_DEBUG("New track did not pass the selection.");
191  delete newTrack;
192  continue;
193  }
194  }
195 
196  at = new AlignTrack(*newTrack);
197 
198  if (msgLvl(MSG::DEBUG) && !msgLvl(MSG::VERBOSE)) {
199  msg(MSG::DEBUG)<<"before refit: "<<endmsg;
201  msg(MSG::DEBUG)<<"after refit: "<<endmsg;
204  }
205 
206  // store fit matrices
209  at->setDerivativeMatrix(alignCache.m_derivMatrix);
210  }
211  if (m_fixMomentum)
212  {
213  at->AlignTrack::setRefitQovP(false);
214  }
215  // delete newTrack since it's copied in AlignTrack
216  delete newTrack;
217  }
218  else { // in case no selection is performed, keep all tracks
219  at=new AlignTrack(*newTrack);
220  }
221  if (m_fixMomentum)
222  {
223  at->AlignTrack::setRefitQovP(false);
224  }
225 
226  newTracks->push_back(at);
227  }
228 
229 
230  if (newTracks->empty()) {
231  delete newTracks;
232  return nullptr;
233  }
234 
235  return newTracks;
236  }
237 
238  //________________________________________________________________________
239  Track * AlignTrackPreProcessor::performSiliconHitSelection(const Track * inputTrack, const ToolHandle<Trk::IGlobalTrackFitter> & fitter)
240  {
242  ATH_MSG_DEBUG(" -- performSiliconHitSelection -- before removing bad Silicon hits, this track has "<< inputTrack->trackStateOnSurfaces()->size()<< " tsos");
243  Track * newTrack;
244 
245  std::vector<const Trk::MeasurementBase*> selectedMeasurementSet;
246 
247  // loop on track hits
248  int nhits = 0;
249  for (const Trk::TrackStateOnSurface* tsos : *inputTrack->trackStateOnSurfaces())
250  {
251  nhits++;
252  if (m_hitQualityTool->isGoodSiHit(tsos)) {
253  selectedMeasurementSet.push_back( tsos->measurementOnTrack() );
254  }
255  else {
256  ATH_MSG_DEBUG(" -- performSiliconHitSelection -- hit # "<< nhits << " status = BAD HIT ");
257  }
258  }
259  ATH_MSG_DEBUG(" -- performSiliconHitSelection -- after removing bad Silicon hits, the selected measurement collection has "<< selectedMeasurementSet.size()<< " elements");
260 
261  newTrack = (fitter->fit(Gaudi::Hive::currentContext(),
262  selectedMeasurementSet,
263  *inputTrack->perigeeParameters(),
265 
266  return newTrack;
267  }
268 }
LArSamples::FitterData::fitter
const ShapeFitter * fitter
Definition: ShapeFitter.cxx:23
Trk::AlignTrackPreProcessor::m_selectTracks
bool m_selectTracks
do the track selection
Definition: AlignTrackPreProcessor.h:70
Trk::AlignTrackPreProcessor::~AlignTrackPreProcessor
virtual ~AlignTrackPreProcessor()
DataModel_detail::const_iterator
Const iterator class for DataVector/DataList.
Definition: DVLIterator.h:82
Trk::AlignTrackPreProcessor::initialize
StatusCode initialize()
Definition: AlignTrackPreProcessor.cxx:71
python.Constants.FATAL
int FATAL
Definition: Control/AthenaCommon/python/Constants.py:19
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
AthCommonDataStore< AthCommonMsg< AlgTool > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
Trk::Track::trackStateOnSurfaces
const Trk::TrackStates * trackStateOnSurfaces() const
return a pointer to a const DataVector of const TrackStateOnSurfaces.
Trk::AlignTrackPreProcessor::m_useSingleFitter
bool m_useSingleFitter
particle hypothesis in track refit
Definition: AlignTrackPreProcessor.h:68
skel.it
it
Definition: skel.GENtoEVGEN.py:423
AthCommonMsg< AlgTool >::msgLvl
bool msgLvl(const MSG::Level lvl) const
Definition: AthCommonMsg.h:30
Trk::IAlignTrackPreProcessor::m_logStream
std::ostream * m_logStream
logfile output stream
Definition: IAlignTrackPreProcessor.h:66
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
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_runOutlierRemoval
bool m_runOutlierRemoval
flag to store derivative and covariance matrices after refit
Definition: AlignTrackPreProcessor.h:65
Trk::AlignTrackPreProcessor::m_particleHypothesis
int m_particleHypothesis
run outlier removal in track refit
Definition: AlignTrackPreProcessor.h:66
Track.h
Trk::ParticleHypothesis
ParticleHypothesis
Definition: ParticleHypothesis.h:25
Trk::AlignTrackPreProcessor::performSiliconHitSelection
Track * performSiliconHitSelection(const Track *, const ToolHandle< Trk::IGlobalTrackFitter > &)
select silicon hits by quality.
Definition: AlignTrackPreProcessor.cxx:239
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:30
endmsg
#define endmsg
Definition: AnalysisConfig_Ntuple.cxx:63
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_storeFitMatricesAfterRefit
bool m_storeFitMatricesAfterRefit
flag to refit tracks
Definition: AlignTrackPreProcessor.h:63
TrackCollection.h
test_pyathena.parent
parent
Definition: test_pyathena.py:15
Trk::AlignTrackPreProcessor::m_trackSelectorTool
ToolHandle< InDet::IInDetTrackSelectionTool > m_trackSelectorTool
Definition: AlignTrackPreProcessor.h:56
Trk::AlignTrackPreProcessor::processTrackCollection
DataVector< Track > * processTrackCollection(const DataVector< Track > *trks)
creates AlignTrack containing all TSOS on track
Definition: AlignTrackPreProcessor.cxx:127
Trk::AlignTrackPreProcessor::m_trackFitterTool
ToolHandle< IGlobalTrackFitter > m_trackFitterTool
Definition: AlignTrackPreProcessor.h:52
DataVector
Derived DataVector<T>.
Definition: DataVector.h:581
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::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:24
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:192
Trk::AlignTrackPreProcessor::m_refitTracks
bool m_refitTracks
Definition: AlignTrackPreProcessor.h:62
Trk::nonInteracting
@ nonInteracting
Definition: ParticleHypothesis.h:25
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
DataVector::end
const_iterator end() const noexcept
Return a const_iterator pointing past the end of the collection.
AlignTrackPreProcessor.h
Trk::AlignTrackPreProcessor::m_selectHits
bool m_selectHits
perform the hit InnerDetector selection
Definition: AlignTrackPreProcessor.h:71
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
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:53
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:121
python.Constants.VERBOSE
int VERBOSE
Definition: Control/AthenaCommon/python/Constants.py:14
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.
IGlobalTrackFitter.h
DataVector::begin
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.
Trk::AlignTrackPreProcessor::m_fixMomentum
bool m_fixMomentum
Fix the momentum of the track so it is not refitted.
Definition: AlignTrackPreProcessor.h:72