51 declareInterface<ICombinedMuonTrackFitter>(
this);
65 m_messageHelper->setMessage(0,
"combinedFit:: missing MeasuredPerigee for indet track");
66 m_messageHelper->setMessage(1,
"combinedFit:: fail with MS removed by cleaner");
67 m_messageHelper->setMessage(2,
"combinedFit:: fail with perigee outside indet");
68 m_messageHelper->setMessage(3,
"combinedFit:: fail with missing caloEnergy");
69 m_messageHelper->setMessage(4,
"combinedFit:: final combined track lost, this should not happen");
70 m_messageHelper->setMessage(5,
"indetExtension:: reject with insufficient MS measurements");
71 m_messageHelper->setMessage(6,
"standaloneFit:: input vertex fails dynamic_cast");
72 m_messageHelper->setMessage(7,
"standaloneFit:: missing MeasuredPerigee for spectrometer track");
73 m_messageHelper->setMessage(8,
"standaloneFit:: missing TrackParameters on prefit");
74 m_messageHelper->setMessage(9,
"standaloneFit:: prefit fails parameter extrapolation to calo");
75 m_messageHelper->setMessage(10,
"standaloneFit:: extrapolated track missing TrackParameters at calo scatterer");
76 m_messageHelper->setMessage(11,
"standaloneFit:: final track lost, this should not happen");
77 m_messageHelper->setMessage(12,
"standaloneFit:: fail as calo incorrectly described");
78 m_messageHelper->setMessage(13,
"standaloneRefit:: fail track as no TSOS with type CaloDeposit");
80 m_messageHelper->setMessage(15,
"standaloneRefit:: no inner parameters");
81 m_messageHelper->setMessage(16,
"standaloneRefit:: innerScattering dynamic_cast failed");
82 m_messageHelper->setMessage(17,
"standaloneRefit:: no TSOS of type CaloDeposit found");
83 m_messageHelper->setMessage(18,
"standaloneRefit:: no inner scattering TSOS found");
84 m_messageHelper->setMessage(19,
"standaloneRefit:: no middle material");
85 m_messageHelper->setMessage(20,
"standaloneRefit:: no middle parameters");
86 m_messageHelper->setMessage(21,
"standaloneRefit:: no CaloDeposit TSOS found");
88 m_messageHelper->setMessage(23,
"standaloneRefit:: no outer parameters");
89 m_messageHelper->setMessage(24,
"standaloneRefit:: outerScattering dynamic_cast failed");
90 m_messageHelper->setMessage(25,
"standaloneRefit:: no outerScattering or CaloDeposit TSOS found");
91 m_messageHelper->setMessage(26,
"standaloneRefit:: failed propagation to innerTSOS");
92 m_messageHelper->setMessage(27,
"standaloneRefit:: failed propagation to middleTSOS");
93 m_messageHelper->setMessage(28,
"standaloneRefit:: fail as calo incorrectly described");
94 m_messageHelper->setMessage(29,
"fit:: particle hypothesis must be 0 or 2 (nonInteracting or muon). Requested: ");
95 m_messageHelper->setMessage(30,
"fit:: about to add the TSOS's describing calorimeter association to a combined muon");
96 m_messageHelper->setMessage(31,
"fit:: particle hypothesis must be 0 or 2 (nonInteracting or muon). Requested: ");
97 m_messageHelper->setMessage(32,
"fit:: particle hypothesis must be 0 or 2 (nonInteracting or muon). Requested: ");
98 m_messageHelper->setMessage(33,
"fit:: combined muon track is missing the TSOS's describing calorimeter association");
99 m_messageHelper->setMessage(34,
"appendSelectedTSOS:: skip duplicate measurement ");
100 m_messageHelper->setMessage(35,
"caloEnergyParameters:: muonTrack without caloEnergy association");
101 m_messageHelper->setMessage(36,
"caloEnergyParameters:: combinedTrack without caloEnergy association");
102 m_messageHelper->setMessage(37,
"createMuonTrack:: should never happen: FSR caloEnergy delete");
103 m_messageHelper->setMessage(38,
"createSpectrometerTSOS:: missing MeasuredPerigee for spectrometer track");
104 m_messageHelper->setMessage(39,
"createSpectrometerTSOS:: skip unrecognized TSOS without TrackParameters. Type: ");
105 m_messageHelper->setMessage(40,
"createSpectrometerTSOS:: skip duplicate measurement on same Surface. Type: ");
106 m_messageHelper->setMessage(41,
"entrancePerigee:: missing TrackingGeometrySvc - no perigee will be added at MS entrance");
107 m_messageHelper->setMessage(42,
"extrapolatedParameters:: missing MeasuredPerigee for spectrometer track");
108 m_messageHelper->setMessage(43,
"extrapolatedParameters:: missing spectrometer parameters on spectrometer track");
109 m_messageHelper->setMessage(44,
"final track lost, this should not happen");
110 m_messageHelper->setMessage(45,
"momentumUpdate:: update failed, keeping original value");
111 m_messageHelper->setMessage(46,
"reallocateMaterial:: null perigeeStartValue");
113 m_messageHelper->setMessage(48,
"standaloneFit:: insufficient measurements on input spectrometer track");
114 m_messageHelper->setMessage(49,
"standaloneFit:: inconsistent TSOS on input spectrometer track");
142 return StatusCode::SUCCESS;
152 return StatusCode::SUCCESS;
163 std::stringstream
ss;
164 ss << particleHypothesis;
188 std::unique_ptr<Trk::Track> fittedTrack = std::make_unique<Trk::Track>(
track);
189 if (isCombined && particleHypothesis ==
Trk::muon && !
m_trackQuery->isCaloAssociated(*fittedTrack, ctx)) {
193 auto combinedTSOS = std::make_unique<Trk::TrackStates>();
196 bool caloAssociated =
false;
200 ATH_MSG_VERBOSE(
"Updating Calorimeter TSOS in Muon Combined (re)Fit ...");
202 caloAssociated =
true;
206 if (caloAssociated) {
207 combinedTSOS->push_back(in_tsos->clone());
208 }
else if ((in_tsos->measurementOnTrack() &&
m_indetVolume->inside(in_tsos->measurementOnTrack()->globalPosition())) ||
209 (in_tsos->trackParameters() &&
m_indetVolume->inside(in_tsos->trackParameters()->position()))) {
210 combinedTSOS->push_back(in_tsos->clone());
214 combinedTSOS->push_back(std::move(tsos));
217 combinedTSOS->push_back(in_tsos->clone());
219 if (tsos) combinedTSOS->push_back(std::move(tsos));
222 if (tsos) combinedTSOS->push_back(std::move(tsos));
224 if (tsos) combinedTSOS->push_back(std::move(tsos));
225 combinedTSOS->push_back(in_tsos->clone());
228 caloAssociated =
true;
232 std::unique_ptr<Trk::Track>
combinedTrack = std::make_unique<Trk::Track>(fittedTrack->
info(), std::move(combinedTSOS),
nullptr);
240 ATH_MSG_VERBOSE(
"Updating Calorimeter TSOS in Muon Combined (re)Fit ...");
248 ATH_MSG_VERBOSE(
"Updating Calorimeter TSOS in Muon Standalone Fit ...");
253 fittedTrack =
fitter->
fit(ctx, *fittedTrack,
false, particleHypothesis);
257 if (!fittedTrack)
return nullptr;
260 if (!
checkTrack(
"fitInterface1", fittedTrack.get()))
return nullptr;
272 ATH_MSG_VERBOSE(
" perform spectrometer error optimization after cleaning ");
273 std::unique_ptr<Trk::Track> optimizedTrack =
m_muonErrorOptimizer->optimiseErrors(*fittedTrack, ctx);
274 if (
checkTrack(
"fitInterface1Opt", optimizedTrack.get()) && chi2BeforeOptimizer >
normalizedChi2(*optimizedTrack)) {
275 fittedTrack.swap(optimizedTrack);
284 ATH_MSG_VERBOSE(__FILE__<<
":"<<__LINE__<<
" perform track cleaning... " <<
m_printer->print(*fittedTrack) << std::endl
285 <<
m_printer->printStations(*fittedTrack));
289 std::unique_ptr<Trk::Track> cleanTrack =
m_cleaner->clean(*fittedTrack, ctx);
293 if (!
checkTrack(
"fitInterface1Cleaner", cleanTrack.get())) { cleanTrack.reset(); }
301 ATH_MSG_DEBUG(
" keep original standalone track despite cleaner veto ");
306 if (chi2After <
m_badFitChi2 || chi2After < chi2Before) {
308 fittedTrack.swap(cleanTrack);
317 <<
m_printer->printStations(*fittedTrack));
330 std::stringstream
ss;
331 ss << particleHypothesis;
353 std::unique_ptr<Trk::TrackParameters> perigee = perigeeStartValue.
uniqueClone();
354 std::unique_ptr<Trk::PerigeeSurface> perigeeSurface;
358 perigeeSurface = std::make_unique<Trk::PerigeeSurface>(origin);
360 perigee = std::make_unique<Trk::Perigee>(perigeeStartValue.
position(), perigeeStartValue.
momentum(), perigeeStartValue.
charge(),
365 std::unique_ptr<Trk::Track> fittedTrack(
fitter->
fit(ctx, measurementSet, *perigee,
false, particleHypothesis));
367 if (!
checkTrack(
"fitInterface2", fittedTrack.get())) {
return nullptr; }
378 ATH_MSG_VERBOSE(
" perform spectrometer error optimization after cleaning ");
379 std::unique_ptr<Trk::Track> optimizedTrack =
m_muonErrorOptimizer->optimiseErrors(*fittedTrack, ctx);
380 if (
checkTrack(
"fitInterface2Opt", optimizedTrack.get())) {
381 fittedTrack.swap(optimizedTrack);
391 ATH_MSG_VERBOSE(__FILE__<<
":"<<__LINE__<<
" perform track cleaning... ");
395 std::unique_ptr<Trk::Track> cleanTrack =
m_cleaner->clean(*fittedTrack, ctx);
399 if (!
checkTrack(
"fitInterface2Cleaner", cleanTrack.get())) { cleanTrack.reset(); }
407 ATH_MSG_DEBUG(
" keep original extension track despite cleaner veto ");
411 if (chi2After <
m_badFitChi2 || chi2After < chi2Before) {
413 fittedTrack.swap(cleanTrack);
433 std::stringstream
ss;
434 ss << particleHypothesis;
466 <<
m_printer->print(indetTrack) << std::endl
469 std::unique_ptr<Trk::Track> fittedTrack(
fitter->
fit(ctx, indetTrack, extrapolatedTrack,
false, particleHypothesis));
471 if (!fittedTrack)
return nullptr;
478 ATH_MSG_VERBOSE(
" perform spectrometer error optimization after cleaning ");
479 std::unique_ptr<Trk::Track> optimizedTrack =
m_muonErrorOptimizer->optimiseErrors(*fittedTrack, ctx);
480 if (
checkTrack(
"Error opt", optimizedTrack.get()) &&
482 fittedTrack.swap(optimizedTrack);
491 ATH_MSG_VERBOSE(__FILE__<<
":"<<__LINE__<<
" perform track cleaning... " <<
m_printer->print(*fittedTrack) << std::endl
492 <<
m_printer->printStations(*fittedTrack));
495 std::unique_ptr<Trk::Track> cleanTrack =
m_cleaner->clean(*fittedTrack, ctx);
504 ATH_MSG_DEBUG(
" keep original combined track despite cleaner veto ");
508 if (chi2After <
m_badFitChi2 || chi2After < chi2Before) {
510 fittedTrack.swap(cleanTrack);
525 double chi2 = 999999.;
526 if (
track.fitQuality()) {
527 if (
track.fitQuality()->numberDoF()) {
528 chi2 =
track.fitQuality()->chiSquared() /
track.fitQuality()->doubleNumberDoF();
539 if (!fieldCondObj.isValid()) {
543 fieldCondObj->getInitializedCache(fieldCache);
551 muonSummary =
summary->muonTrackSummary();
555 muonSummary =
summary->muonTrackSummary();
558 if (!muonSummary)
return false;
561 unsigned int optimize{0},nBarrel{0}, nEndcap{0}, nSmall{0}, nLarge{0};
566 if (!isMdt)
continue;
594 if (nBarrel > 0 && nEndcap > 0) { optimize += 10; }
596 if (nSmall > 0 && nLarge > 0) { optimize += 100; }
598 if (optimize > 0) {
ATH_MSG_DEBUG(
" OptimizeErrors with value " << optimize); }
604 if (!newTrack)
return false;
610 if ((*it)->position().dot((*it)->momentum()) < 0) {
612 ATH_MSG_DEBUG(txt <<
" "<< __FILE__<<
":"<<__LINE__<<
" ALARM position " << (*it)->position() <<
" direction " << (*it)->momentum().unit());
614 ATH_MSG_DEBUG(txt <<
" "<< __FILE__<<
":"<<__LINE__<<
" OK position " << (*it)->position() <<
" direction " << (*it)->momentum().unit());
618 if (!
par->covariance()) {
continue; }
620 ATH_MSG_DEBUG(txt<<
" "<<__FILE__<<
":"<<__LINE__<<
"covariance matrix has negative diagonal element, killing track "
625 unsigned int numberMS{0}, numberMSPrec{0};
629 for (;
r != rEnd; ++
r) {
631 if (tsos->trackParameters() &&
m_calorimeterVolume->inside(tsos->trackParameters()->position()))
break;
633 if (tsos->measurementOnTrack()) {
640 ATH_MSG_VERBOSE( txt<<
" "<<__FILE__<<
":"<<__LINE__<<
" "<< numberMS <<
"/"<< numberMSPrec<<
" fitted MS measurements ");
642 if (numberMS < 5 || numberMSPrec < 3) {
651 unsigned int naeots = 0;
658 for (
const auto*
m : *trackTSOS) {
659 if (
m &&
m->alignmentEffectsOnTrack()) naeots++;
667 int tsos{0}, nperigee{0};
676 if (
it->trackParameters()) {
678 <<
" r " <<
it->trackParameters()->position().perp() <<
" z "
679 <<
it->trackParameters()->position().z() <<
" momentum "
680 <<
it->trackParameters()->momentum().mag());
681 }
else if (
it->measurementOnTrack()) {
683 <<
" r " <<
it->measurementOnTrack()->associatedSurface().center().perp() <<
" z "
684 <<
it->measurementOnTrack()->associatedSurface().center().z());
685 }
else if (
it->materialEffectsOnTrack()) {
688 <<
it->materialEffectsOnTrack()->associatedSurface().globalReferencePoint().perp()
689 <<
" z " <<
it->materialEffectsOnTrack()->associatedSurface().globalReferencePoint().z());