16 #include "GaudiKernel/TypeNameString.h"
38 m_trackName(
"Tracks"),
39 m_newTrackName(
"ReFitted_Tracks"),
42 m_ParticleHypothesis(
Trk::
pion),
44 m_ITrackFitter(
"TrkKalmanFitter/KalmanFitter"),
45 m_ITrackFitterTRT(
""),
47 m_trkSelectorTool(
""),
48 m_constrainFitMode(0),
49 m_vxContainerName(
"VxPrimaryCandidate"),
50 m_extrapolator(
"Trk::Extrapolator/InDetExtrapolator"),
78 if (m_ITrackFitter.retrieve().isFailure()) {
80 return StatusCode::FAILURE;
82 msg(MSG::INFO) <<
"Retrieved general fitter " << m_ITrackFitter.typeAndName() <<
endmsg;
84 if (!m_ITrackFitterTRT.name().empty()){
85 if (m_ITrackFitterTRT.retrieve().isFailure()) {
87 return StatusCode::FAILURE;
89 msg(MSG::INFO) <<
"Retrieved fitter for TRT-only tracks " << m_ITrackFitterTRT.typeAndName() <<
endmsg;
92 if (!m_trkSummaryTool.name().empty()){
93 if (m_trkSummaryTool.retrieve().isFailure()) {
95 return StatusCode::FAILURE;
97 msg(MSG::INFO) <<
"Retrieved tool " << m_trkSummaryTool.typeAndName() <<
endmsg;
99 if ( m_assoTool.retrieve().isFailure() ) {
101 return StatusCode::FAILURE;
104 if (!m_trkSelectorTool.empty()){
105 if (m_trkSelectorTool.retrieve().isFailure()) {
106 msg(
MSG::FATAL) <<
"Failed to retrieve tool " << m_trkSelectorTool <<
". No Track Selection will be done." <<
endmsg;
107 return StatusCode::FAILURE;
109 msg(MSG::INFO) <<
"Retrieved tool " << m_trkSelectorTool.typeAndName() <<
endmsg;
113 if (m_constrainFitMode) {
118 if (m_constrainFitMode && m_extrapolator.retrieve().isFailure()){
120 return StatusCode::FAILURE;
127 ATH_CHECK( m_vxContainerName.initialize() );
128 ATH_CHECK( m_newTrackName.initialize() );
129 ATH_CHECK( m_pixelDetEleCollKey.initialize() );
130 ATH_CHECK( m_SCTDetEleCollKey.initialize() );
132 return StatusCode::SUCCESS;
139 std::unique_ptr<Trk::PRDtoTrackMap> prd_to_track_map(m_assoTool->createPRDtoTrackMap());
140 const EventContext& ctx = Gaudi::Hive::currentContext();
144 msg(MSG::ERROR) <<
"Track collection named " << m_trackName.key()
145 <<
" not found, exit ReFitTrack." <<
endmsg;
146 return StatusCode::SUCCESS;
148 ATH_MSG_DEBUG (
"Tracks collection '" << m_trackName.key() <<
"' retrieved from EventStore.");
151 ATH_MSG_DEBUG(
"Track fit configured with constrain option : " << m_constrainFitMode );
154 std::unique_ptr<const Trk::PerigeeSurface> constrainSf;
155 std::unique_ptr<const Trk::RecVertex> constrainVx;
157 if (m_constrainFitMode > 0){
158 constrainVx.reset( setupConstrainedFit() );
163 constrainSf = std::make_unique<Trk::PerigeeSurface>( constrainVx->
position());
170 std::vector<std::unique_ptr<Trk::Track> > new_tracks;
177 if (m_usetrackhypo) hypo=(**itr).info().particleHypothesis();
178 std::unique_ptr<Trk::Track> newtrack;
181 bool passedSelection =
true;
183 if (*itr && !m_trkSelectorTool.empty()){
184 passedSelection = m_trkSelectorTool->decision(**itr);
188 if (!m_ITrackFitterTRT.name().empty() && !m_trkSummaryTool.name().empty()){
191 unsigned int n_trt_hits;
192 if ((*itr)->trackSummary()) {
196 std::unique_ptr<const Trk::TrackSummary>
summary( m_trkSummaryTool->summaryNoHoleSearch(**itr));
199 if ( (**itr).measurementsOnTrack()->size() - n_trt_hits<3 )
203 if (passedSelection) {
206 const Trk::Perigee* origPerigee = (*itr)->perigeeParameters();
208 double od0 = origPerigee->parameters()[
Trk::d0];
209 double oz0 = origPerigee->parameters()[
Trk::z0];
210 double ophi0 = origPerigee->parameters()[
Trk::phi0];
211 double otheta = origPerigee->parameters()[
Trk::theta];
212 double oqOverP = origPerigee->parameters()[
Trk::qOverP];
213 ATH_MSG_DEBUG (
"Original parameters " << od0 <<
" " << oz0 <<
" " << ophi0 <<
" " << otheta <<
" " << oqOverP);
217 if (constrainVx && origPerigee){
221 std::unique_ptr<const Trk::TrackParameters>
tp( m_extrapolator->extrapolateTrack(ctx,
227 std::unique_ptr<Trk::VertexOnTrack> bsvxOnTrack( tpConstrainedSf ?
new Trk::VertexOnTrack(*constrainVx,*tpConstrainedSf) :
nullptr );
228 std::vector<const MeasurementBase*>
vec;
229 if (tpConstrainedSf)
vec.push_back(bsvxOnTrack.get() );
237 for ( ; measIter != measIterEnd; ++measIter)
238 vec.push_back((*measIter));
246 newtrack = ((trtonly ? m_ITrackFitterTRT : m_ITrackFitter)
247 ->
fit(Gaudi::Hive::currentContext(),
255 ((trtonly ? m_ITrackFitterTRT : m_ITrackFitter)
256 ->
fit(Gaudi::Hive::currentContext(), **itr, m_runOutlier, hypo));
267 if (aMeasPer==
nullptr){
268 msg(MSG::ERROR) <<
"Could not get Trk::MeasuredPerigee" <<
endmsg;
271 double d0 = aMeasPer->parameters()[
Trk::d0];
272 double z0 = aMeasPer->parameters()[
Trk::z0];
281 new_tracks.push_back(std::move(newtrack));
289 for(
const std::unique_ptr<Trk::Track> &new_track : new_tracks ) {
290 if((m_assoTool->addPRDs(*prd_to_track_map, *new_track)).isFailure()) {
ATH_MSG_WARNING(
"Failed to add PRDs to map");}
295 std::unique_ptr<TrackCollection> new_track_collection = std::make_unique<TrackCollection>();
296 new_track_collection->
reserve(new_tracks.size());
297 for(std::unique_ptr<Trk::Track> &new_track : new_tracks ) {
298 m_trkSummaryTool->computeAndReplaceTrackSummary(*new_track,
false );
299 new_track_collection->
push_back(std::move(new_track));
305 return StatusCode::SUCCESS;
311 msg(MSG::INFO) <<
"ReFitTrack::finalize()" <<
endmsg;
312 return StatusCode::SUCCESS;
319 if ( m_constrainFitMode == 2 ){
324 ATH_MSG_DEBUG(
"Track fit with BeamSpot constraint (x/y/z) = "
325 << constrainVx->
position().x() <<
", "
326 << constrainVx->
position().y() <<
", "
328 }
else if (m_constrainFitMode ==1){
331 ATH_MSG_DEBUG(
"Track fit with vertex from collection '" << m_vxContainerName.key() <<
"'.");
333 ATH_MSG_WARNING(
"Track fit configured to use vertex constraint, but '" << m_vxContainerName.key() <<
"' could not be retrieved.");
334 else if (vxContainer->
size() == 1 ) {
335 ATH_MSG_WARNING(
"Track fit configured to use vertex constraint, but '" << m_vxContainerName.key() <<
"' contains only dummy vertex.");
338 constrainVx =
new Trk::RecVertex( (*vxContainer)[0]->recVertex() );
340 << constrainVx->
position().x() <<
", "
341 << constrainVx->
position().y() <<
", "