ATLAS Offline Software
Loading...
Searching...
No Matches
ReFitterAlg.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3*/
4
5#include "ReFitterAlg.h"
6
7// ATHENA
8#include "GaudiKernel/TypeNameString.h"
9
12
13
15#include "Identifier/Identifier.h"
16// Event includes
20#include "TrkTrack/Track.h"
21
22// STL
23#include <memory>
24#include <vector>
25#include <fstream>
26#include <string>
27
28using namespace Acts::UnitLiterals;
29
30namespace ActsTrk {
31
32ReFitterAlg::ReFitterAlg(const std::string &name,
33 ISvcLocator *pSvcLocator)
34 : AthReentrantAlgorithm(name, pSvcLocator){}
35
37
38 ATH_MSG_DEBUG(name() << "::" << __FUNCTION__);
39 ATH_CHECK(m_actsFitter.retrieve());
40 ATH_CHECK(m_trackName.initialize());
41 ATH_CHECK(m_newTrackName.initialize());
42
43 return StatusCode::SUCCESS;
44}
45
46StatusCode ReFitterAlg::execute(const EventContext &ctx) const {
47
48 ATH_MSG_DEBUG ("ReFitterAlg::execute()");
50
51 if (!tracks.isValid()){
52 ATH_MSG_ERROR("Track collection named " << m_trackName.key() << " not found, exit ReFitTrack.");
53 return StatusCode::SUCCESS;
54 } else {
55 ATH_MSG_DEBUG ("Tracks collection '" << m_trackName.key() << "' retrieved from EventStore.");
56 }
57
58 // Prepare the output data with MultiTrajectory
59 std::vector<std::unique_ptr<Trk::Track> > new_tracks;
60 new_tracks.reserve((*tracks).size());
61
62 //Prepare the output for uncalibrated measurments; only used if m_doReFitFromPRD=True.
63 std::vector<const Trk::PrepRawData*> PrepRawDataSet;
64
65 // Perform the fit for each input track
66 for (TrackCollection::const_iterator track = (*tracks).begin(); track < (*tracks).end(); ++track){
67
68 if (m_doReFitFromPRD){ //Fit from PrepRawData measurments
69 const Trk::Track* trackPtr = *track;
70 const Trk::TrackParameters* trkPar_perigee = trackPtr->perigeeParameters() ;
71
72 for (const Trk::TrackStateOnSurface* tsos : *trackPtr->trackStateOnSurfaces() ) {
73 //skipping outliers
74 if (!tsos->type(Trk::TrackStateOnSurface::Measurement)) continue;
75 const Trk::MeasurementBase* mesh = tsos->measurementOnTrack();
76 if (mesh == nullptr) continue;
77 const Trk::RIO_OnTrack* hit = dynamic_cast <const Trk::RIO_OnTrack*>(mesh);
78 if (hit == nullptr) continue;
79
80 const Trk::PrepRawData* prd = hit->prepRawData() ;
81 PrepRawDataSet.push_back(prd);
82 }//end of tsos loop
83
84 auto newtrack = m_actsFitter->fit(ctx, PrepRawDataSet , *trkPar_perigee );
85
86 if (newtrack) {
87 if (msgLvl(MSG::VERBOSE)) {
88 msg(MSG::VERBOSE) << "ATLAS param : " << endmsg;
89 msg(MSG::VERBOSE) << *((**track).perigeeParameters()) << endmsg;
90 msg(MSG::VERBOSE) << *((**track).perigeeParameters()->covariance()) << endmsg;
91 msg(MSG::VERBOSE) << "ACTS param : " << endmsg;
92 msg(MSG::VERBOSE) << *(newtrack->perigeeParameters()) << endmsg;
93 msg(MSG::VERBOSE) << *(newtrack->perigeeParameters()->covariance()) << endmsg;
94
95 msg(MSG::VERBOSE) << "ATLAS INFO : " << endmsg;
96 msg(MSG::VERBOSE) << *((**track).trackSummary()) << endmsg;
97 msg(MSG::VERBOSE) << "ACTS INFO : " << endmsg;
98 msg(MSG::VERBOSE) << *(newtrack->trackSummary()) << endmsg;
99 msg(MSG::VERBOSE) << "==========================" << endmsg;
100 }
101 new_tracks.push_back(std::move(newtrack));
102 }
103 else if (msgLvl(MSG::DEBUG)) { // newtrack might be equal to a nullptr
104 msg(MSG::DEBUG) << "The Acts Refitting (KF or GSF) has returned a nullptr. Below is information on the offending track." << endmsg; // TODO: solve the cases where we return a nullptr
105 msg(MSG::DEBUG) << "ATLAS param : " << endmsg;
106 msg(MSG::DEBUG) << *((**track).perigeeParameters()) << endmsg;
107 msg(MSG::DEBUG) << *((**track).perigeeParameters()->covariance()) << endmsg;
108
109 msg(MSG::DEBUG) << "ATLAS INFO : " << endmsg;
110 msg(MSG::DEBUG) << *((**track).trackSummary()) << endmsg;
111 msg(MSG::DEBUG) << "==========================" << endmsg;
112 }
113 }
114
115 else { //Fit from Rio_OnTrack measurments
116 auto newtrack = m_actsFitter->fit(ctx, (**track));
117
118 if (newtrack) {
119 if (msgLvl(MSG::VERBOSE)) {
120 msg(MSG::VERBOSE) << "ATLAS param : " << endmsg;
121 msg(MSG::VERBOSE) << *((**track).perigeeParameters()) << endmsg;
122 msg(MSG::VERBOSE) << *((**track).perigeeParameters()->covariance()) << endmsg;
123 msg(MSG::VERBOSE) << "ACTS param : " << endmsg;
124 msg(MSG::VERBOSE) << *(newtrack->perigeeParameters()) << endmsg;
125 msg(MSG::VERBOSE) << *(newtrack->perigeeParameters()->covariance()) << endmsg;
126
127 msg(MSG::VERBOSE) << "ATLAS INFO : " << endmsg;
128 msg(MSG::VERBOSE) << *((**track).trackSummary()) << endmsg;
129 msg(MSG::VERBOSE) << "ACTS INFO : " << endmsg;
130 msg(MSG::VERBOSE) << *(newtrack->trackSummary()) << endmsg;
131 msg(MSG::VERBOSE) << "==========================" << endmsg;
132 }
133 new_tracks.push_back(std::move(newtrack));
134 }
135 else if (msgLvl(MSG::DEBUG)) { // newtrack might be equal to a nullptr
136 msg(MSG::DEBUG) << "The Acts Refitting (KF or GSF) has returned a nullptr. Below is information on the offending track." << endmsg; // TODO: solve the cases where we return a nullptr
137 msg(MSG::DEBUG) << "ATLAS param : " << endmsg;
138 msg(MSG::DEBUG) << *((**track).perigeeParameters()) << endmsg;
139 msg(MSG::DEBUG) << *((**track).perigeeParameters()->covariance()) << endmsg;
140
141 msg(MSG::DEBUG) << "ATLAS INFO : " << endmsg;
142 msg(MSG::DEBUG) << *((**track).trackSummary()) << endmsg;
143 msg(MSG::DEBUG) << "==========================" << endmsg;
144 }
145 }
146
147 }
148
149 // Create a new track collection with the refitted tracks
150 std::unique_ptr<TrackCollection> new_track_collection = std::make_unique<TrackCollection>();
151
152 new_track_collection->reserve(new_tracks.size());
153 for(std::unique_ptr<Trk::Track> &new_track : new_tracks ) {
154 new_track_collection->push_back(std::move(new_track));
155 }
156
157 ATH_MSG_DEBUG ("Saving tracks");
158 ATH_CHECK(SG::WriteHandle<TrackCollection>(m_newTrackName, ctx).record(std::move(new_track_collection)));
159 return StatusCode::SUCCESS;
160}
161
162}
#define endmsg
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_DEBUG(x)
ToolHandle< Trk::ITrackFitter > m_actsFitter
Definition ReFitterAlg.h:42
Gaudi::Property< bool > m_doReFitFromPRD
Definition ReFitterAlg.h:50
ReFitterAlg(const std::string &name, ISvcLocator *pSvcLocator)
virtual StatusCode initialize() override
SG::WriteHandleKey< TrackCollection > m_newTrackName
Definition ReFitterAlg.h:45
virtual StatusCode execute(const EventContext &ctx) const override
SG::ReadHandleKey< TrackCollection > m_trackName
Definition ReFitterAlg.h:44
bool msgLvl(const MSG::Level lvl) const
An algorithm that can be simultaneously executed in multiple threads.
DataModel_detail::const_iterator< DataVector > const_iterator
Definition DataVector.h:838
virtual bool isValid() override final
Can the handle be successfully dereferenced?
This class is the pure abstract base class for all fittable tracking measurements.
Class to handle RIO On Tracks ROT) for InDet and Muons, it inherits from the common MeasurementBase.
Definition RIO_OnTrack.h:70
virtual const Trk::PrepRawData * prepRawData() const =0
returns the PrepRawData (also known as RIO) object to which this RIO_OnTrack is associated.
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.
const Trk::TrackStates * trackStateOnSurfaces() const
return a pointer to a const DataVector of const TrackStateOnSurfaces.
const Perigee * perigeeParameters() const
return Perigee.
The AlignStoreProviderAlg loads the rigid alignment corrections and pipes them through the readout ge...
ParametersBase< TrackParametersDim, Charged > TrackParameters