59 m_messageHelper->setMessage(0,
"combinedFit:: missing MeasuredPerigee for indet track");
60 m_messageHelper->setMessage(1,
"combinedFit:: fail with MS removed by cleaner");
61 m_messageHelper->setMessage(2,
"combinedFit:: fail with perigee outside indet");
62 m_messageHelper->setMessage(3,
"combinedFit:: fail with missing caloEnergy");
63 m_messageHelper->setMessage(4,
"combinedFit:: final combined track lost, this should not happen");
64 m_messageHelper->setMessage(5,
"indetExtension:: reject with insufficient MS measurements");
65 m_messageHelper->setMessage(6,
"standaloneFit:: input vertex fails dynamic_cast");
66 m_messageHelper->setMessage(7,
"standaloneFit:: missing MeasuredPerigee for spectrometer track");
67 m_messageHelper->setMessage(8,
"standaloneFit:: missing TrackParameters on prefit");
68 m_messageHelper->setMessage(9,
"standaloneFit:: prefit fails parameter extrapolation to calo");
69 m_messageHelper->setMessage(10,
"standaloneFit:: extrapolated track missing TrackParameters at calo scatterer");
70 m_messageHelper->setMessage(11,
"standaloneFit:: final track lost, this should not happen");
71 m_messageHelper->setMessage(12,
"standaloneFit:: fail as calo incorrectly described");
72 m_messageHelper->setMessage(13,
"standaloneRefit:: fail track as no TSOS with type CaloDeposit");
74 m_messageHelper->setMessage(15,
"standaloneRefit:: no inner parameters");
75 m_messageHelper->setMessage(16,
"standaloneRefit:: innerScattering dynamic_cast failed");
76 m_messageHelper->setMessage(17,
"standaloneRefit:: no TSOS of type CaloDeposit found");
77 m_messageHelper->setMessage(18,
"standaloneRefit:: no inner scattering TSOS found");
78 m_messageHelper->setMessage(19,
"standaloneRefit:: no middle material");
79 m_messageHelper->setMessage(20,
"standaloneRefit:: no middle parameters");
80 m_messageHelper->setMessage(21,
"standaloneRefit:: no CaloDeposit TSOS found");
82 m_messageHelper->setMessage(23,
"standaloneRefit:: no outer parameters");
83 m_messageHelper->setMessage(24,
"standaloneRefit:: outerScattering dynamic_cast failed");
84 m_messageHelper->setMessage(25,
"standaloneRefit:: no outerScattering or CaloDeposit TSOS found");
85 m_messageHelper->setMessage(26,
"standaloneRefit:: failed propagation to innerTSOS");
86 m_messageHelper->setMessage(27,
"standaloneRefit:: failed propagation to middleTSOS");
87 m_messageHelper->setMessage(28,
"standaloneRefit:: fail as calo incorrectly described");
88 m_messageHelper->setMessage(29,
"fit:: particle hypothesis must be 0 or 2 (nonInteracting or muon). Requested: ");
89 m_messageHelper->setMessage(30,
"fit:: about to add the TSOS's describing calorimeter association to a combined muon");
90 m_messageHelper->setMessage(31,
"fit:: particle hypothesis must be 0 or 2 (nonInteracting or muon). Requested: ");
91 m_messageHelper->setMessage(32,
"fit:: particle hypothesis must be 0 or 2 (nonInteracting or muon). Requested: ");
92 m_messageHelper->setMessage(33,
"fit:: combined muon track is missing the TSOS's describing calorimeter association");
93 m_messageHelper->setMessage(34,
"appendSelectedTSOS:: skip duplicate measurement ");
94 m_messageHelper->setMessage(35,
"caloEnergyParameters:: muonTrack without caloEnergy association");
95 m_messageHelper->setMessage(36,
"caloEnergyParameters:: combinedTrack without caloEnergy association");
96 m_messageHelper->setMessage(37,
"createMuonTrack:: should never happen: FSR caloEnergy delete");
97 m_messageHelper->setMessage(38,
"createSpectrometerTSOS:: missing MeasuredPerigee for spectrometer track");
98 m_messageHelper->setMessage(39,
"createSpectrometerTSOS:: skip unrecognized TSOS without TrackParameters. Type: ");
99 m_messageHelper->setMessage(40,
"createSpectrometerTSOS:: skip duplicate measurement on same Surface. Type: ");
100 m_messageHelper->setMessage(41,
"entrancePerigee:: missing TrackingGeometrySvc - no perigee will be added at MS entrance");
101 m_messageHelper->setMessage(42,
"extrapolatedParameters:: missing MeasuredPerigee for spectrometer track");
102 m_messageHelper->setMessage(43,
"extrapolatedParameters:: missing spectrometer parameters on spectrometer track");
103 m_messageHelper->setMessage(44,
"final track lost, this should not happen");
104 m_messageHelper->setMessage(45,
"momentumUpdate:: update failed, keeping original value");
105 m_messageHelper->setMessage(46,
"reallocateMaterial:: null perigeeStartValue");
107 m_messageHelper->setMessage(48,
"standaloneFit:: insufficient measurements on input spectrometer track");
108 m_messageHelper->setMessage(49,
"standaloneFit:: inconsistent TSOS on input spectrometer track");
136 return StatusCode::SUCCESS;
146 return StatusCode::SUCCESS;
152 <<
m_printer->printMeasurements(track) << std::endl
157 std::stringstream
ss;
158 ss << particleHypothesis;
182 std::unique_ptr<Trk::Track> fittedTrack = std::make_unique<Trk::Track>(track);
183 if (isCombined && particleHypothesis ==
Trk::muon && !
m_trackQuery->isCaloAssociated(*fittedTrack, ctx)) {
185 ATH_MSG_VERBOSE(
"fit:: about to add the TSOS's describing calorimeter association to a combined muon" );
187 auto combinedTSOS = std::make_unique<Trk::TrackStates>();
189 combinedTSOS->reserve(fittedTrack->trackStateOnSurfaces()->size() + 3);
190 bool caloAssociated =
false;
194 ATH_MSG_VERBOSE(
"Updating Calorimeter TSOS in Muon Combined (re)Fit ...");
196 caloAssociated =
true;
200 if (caloAssociated) {
201 combinedTSOS->push_back(in_tsos->clone());
202 }
else if ((in_tsos->measurementOnTrack() &&
m_indetVolume->inside(in_tsos->measurementOnTrack()->globalPosition())) ||
203 (in_tsos->trackParameters() &&
m_indetVolume->inside(in_tsos->trackParameters()->position()))) {
204 combinedTSOS->push_back(in_tsos->clone());
206 std::unique_ptr<const Trk::TrackStateOnSurface> tsos =
m_caloTSOS->innerTSOS(ctx, *fittedTrack->perigeeParameters());
208 combinedTSOS->push_back(std::move(tsos));
211 combinedTSOS->push_back(in_tsos->clone());
212 tsos =
m_caloTSOS->outerTSOS(ctx, *parameters);
213 if (tsos) combinedTSOS->push_back(std::move(tsos));
215 tsos =
m_caloTSOS->middleTSOS(ctx, *parameters);
216 if (tsos) combinedTSOS->push_back(std::move(tsos));
217 tsos =
m_caloTSOS->outerTSOS(ctx, *parameters);
218 if (tsos) combinedTSOS->push_back(std::move(tsos));
219 combinedTSOS->push_back(in_tsos->clone());
222 caloAssociated =
true;
226 std::unique_ptr<Trk::Track> combinedTrack = std::make_unique<Trk::Track>(fittedTrack->info(), std::move(combinedTSOS),
nullptr);
228 if (msgLevel(MSG::DEBUG))
countAEOTs(*combinedTrack,
" combinedTrack track before fit ");
230 caloAssociated =
m_trackQuery->isCaloAssociated(*combinedTrack, ctx);
234 ATH_MSG_VERBOSE(
"Updating Calorimeter TSOS in Muon Combined (re)Fit ...");
238 fittedTrack = fitter->
fit(ctx, *combinedTrack,
false, particleHypothesis);
242 ATH_MSG_VERBOSE(
"Updating Calorimeter TSOS in Muon Standalone Fit ...");
247 fittedTrack = fitter->
fit(ctx, *fittedTrack,
false, particleHypothesis);
251 if (!fittedTrack)
return nullptr;
254 if (!
checkTrack(
"fitInterface1", fittedTrack.get()))
return nullptr;
266 ATH_MSG_VERBOSE(
" perform spectrometer error optimization after cleaning ");
267 std::unique_ptr<Trk::Track> optimizedTrack =
m_muonErrorOptimizer->optimiseErrors(*fittedTrack, ctx);
268 if (
checkTrack(
"fitInterface1Opt", optimizedTrack.get()) && chi2BeforeOptimizer >
normalizedChi2(*optimizedTrack)) {
269 fittedTrack.swap(optimizedTrack);
270 if (msgLevel(MSG::DEBUG))
countAEOTs(*fittedTrack,
" re fit scaled errors Track ");
278 ATH_MSG_VERBOSE(__FILE__<<
":"<<__LINE__<<
" perform track cleaning... " <<
m_printer->print(*fittedTrack) << std::endl
279 <<
m_printer->printStations(*fittedTrack));
281 if (msgLevel(MSG::DEBUG))
countAEOTs(*fittedTrack,
" refit: fitted track before cleaning ");
283 std::unique_ptr<Trk::Track> cleanTrack =
m_cleaner->clean(*fittedTrack, ctx);
285 if (msgLevel(MSG::DEBUG))
countAEOTs(*cleanTrack,
" refit: after cleaning");
287 if (!
checkTrack(
"fitInterface1Cleaner", cleanTrack.get())) { cleanTrack.reset(); }
295 ATH_MSG_DEBUG(
" keep original standalone track despite cleaner veto ");
297 }
else if (!(*cleanTrack->perigeeParameters() == *fittedTrack->perigeeParameters())) {
300 if (chi2After <
m_badFitChi2 || chi2After < chi2Before) {
302 fittedTrack.swap(cleanTrack);
311 <<
m_printer->printStations(*fittedTrack));
324 std::stringstream
ss;
325 ss << particleHypothesis;
347 std::unique_ptr<Trk::TrackParameters> perigee = perigeeStartValue.
uniqueClone();
348 std::unique_ptr<Trk::PerigeeSurface> perigeeSurface;
352 perigeeSurface = std::make_unique<Trk::PerigeeSurface>(origin);
354 perigee = std::make_unique<Trk::Perigee>(perigeeStartValue.
position(), perigeeStartValue.
momentum(), perigeeStartValue.
charge(),
359 std::unique_ptr<Trk::Track> fittedTrack(fitter->
fit(ctx, measurementSet, *perigee,
false, particleHypothesis));
361 if (!
checkTrack(
"fitInterface2", fittedTrack.get())) {
return nullptr; }
372 ATH_MSG_VERBOSE(
" perform spectrometer error optimization after cleaning ");
373 std::unique_ptr<Trk::Track> optimizedTrack =
m_muonErrorOptimizer->optimiseErrors(*fittedTrack, ctx);
374 if (
checkTrack(
"fitInterface2Opt", optimizedTrack.get())) {
375 fittedTrack.swap(optimizedTrack);
376 if (msgLevel(MSG::DEBUG))
countAEOTs(*fittedTrack,
" fit mstSet scaled errors Track ");
385 ATH_MSG_VERBOSE(__FILE__<<
":"<<__LINE__<<
" perform track cleaning... ");
387 if (msgLevel(MSG::DEBUG))
countAEOTs(*fittedTrack,
" fit mstSet before cleaning ");
389 std::unique_ptr<Trk::Track> cleanTrack =
m_cleaner->clean(*fittedTrack, ctx);
391 if (msgLevel(MSG::DEBUG))
countAEOTs(*cleanTrack,
" fit mstSet clean Track ");
393 if (!
checkTrack(
"fitInterface2Cleaner", cleanTrack.get())) { cleanTrack.reset(); }
401 ATH_MSG_DEBUG(
" keep original extension track despite cleaner veto ");
403 }
else if (!(*cleanTrack->perigeeParameters() == *fittedTrack->perigeeParameters())) {
405 if (chi2After <
m_badFitChi2 || chi2After < chi2Before) {
407 fittedTrack.swap(cleanTrack);
427 std::stringstream
ss;
428 ss << particleHypothesis;
460 <<
m_printer->print(indetTrack) << std::endl
463 std::unique_ptr<Trk::Track> fittedTrack(fitter->
fit(ctx, indetTrack, extrapolatedTrack,
false, particleHypothesis));
465 if (!fittedTrack)
return nullptr;
472 ATH_MSG_VERBOSE(
" perform spectrometer error optimization after cleaning ");
473 std::unique_ptr<Trk::Track> optimizedTrack =
m_muonErrorOptimizer->optimiseErrors(*fittedTrack, ctx);
474 if (
checkTrack(
"Error opt", optimizedTrack.get()) &&
476 fittedTrack.swap(optimizedTrack);
477 if (msgLevel(MSG::DEBUG))
countAEOTs(*fittedTrack,
" cbfit scaled errors Track ");
485 ATH_MSG_VERBOSE(__FILE__<<
":"<<__LINE__<<
" perform track cleaning... " <<
m_printer->print(*fittedTrack) << std::endl
486 <<
m_printer->printStations(*fittedTrack));
488 if (msgLevel(MSG::DEBUG)) {
countAEOTs(*fittedTrack,
" cb before clean Track "); }
489 std::unique_ptr<Trk::Track> cleanTrack =
m_cleaner->clean(*fittedTrack, ctx);
490 if (cleanTrack && msgLevel(MSG::DEBUG)) {
countAEOTs(*cleanTrack,
" cb after clean Track "); }
498 ATH_MSG_DEBUG(
" keep original combined track despite cleaner veto ");
500 }
else if (!(*cleanTrack->perigeeParameters() == *fittedTrack->perigeeParameters())) {
502 if (chi2After <
m_badFitChi2 || chi2After < chi2Before) {
504 fittedTrack.swap(cleanTrack);
519 double chi2 = 999999.;
520 if (track.fitQuality()) {
521 if (track.fitQuality()->numberDoF()) {
522 chi2 = track.fitQuality()->chiSquared() / track.fitQuality()->doubleNumberDoF();
537 fieldCondObj->getInitializedCache(fieldCache);
545 muonSummary = summary->muonTrackSummary();
548 summary = track.trackSummary();
549 muonSummary = summary->muonTrackSummary();
552 if (!muonSummary)
return false;
555 unsigned int optimize{0},nBarrel{0}, nEndcap{0}, nSmall{0}, nLarge{0};
560 if (!isMdt)
continue;
579 if (nBarrel > 0 && nEndcap > 0) { optimize += 10; }
581 if (nSmall > 0 && nLarge > 0) { optimize += 100; }
583 if (optimize > 0) {
ATH_MSG_DEBUG(
" OptimizeErrors with value " << optimize); }
589 if (!newTrack)
return false;
592 if (!pars || pars->empty() || !newTrack->
fitQuality()) {
return false; }
595 if ((*it)->position().dot((*it)->momentum()) < 0) {
597 ATH_MSG_DEBUG(txt <<
" "<< __FILE__<<
":"<<__LINE__<<
" ALARM position " << (*it)->position() <<
" direction " << (*it)->momentum().unit());
599 ATH_MSG_DEBUG(txt <<
" "<< __FILE__<<
":"<<__LINE__<<
" OK position " << (*it)->position() <<
" direction " << (*it)->momentum().unit());
603 if (!par->covariance()) {
continue; }
605 ATH_MSG_DEBUG(txt<<
" "<<__FILE__<<
":"<<__LINE__<<
"covariance matrix has negative diagonal element, killing track "
610 unsigned int numberMS{0}, numberMSPrec{0};
614 for (;
r != rEnd; ++
r) {
625 ATH_MSG_VERBOSE( txt<<
" "<<__FILE__<<
":"<<__LINE__<<
" "<< numberMS <<
"/"<< numberMSPrec<<
" fitted MS measurements ");
627 if (numberMS < 5 || numberMSPrec < 3) {
636 unsigned int naeots = 0;
643 for (
const auto* m : *trackTSOS) {
644 if (m && m->alignmentEffectsOnTrack()) naeots++;
652 int tsos{0}, nperigee{0};
661 if (it->trackParameters()) {
663 <<
" r " << it->trackParameters()->position().perp() <<
" z "
664 << it->trackParameters()->position().z() <<
" momentum "
665 << it->trackParameters()->momentum().mag());
666 }
else if (it->measurementOnTrack()) {
668 <<
" r " << it->measurementOnTrack()->associatedSurface().center().perp() <<
" z "
669 << it->measurementOnTrack()->associatedSurface().center().z());
670 }
else if (it->materialEffectsOnTrack()) {
673 << it->materialEffectsOnTrack()->associatedSurface().globalReferencePoint().perp()
674 <<
" z " << it->materialEffectsOnTrack()->associatedSurface().globalReferencePoint().z());
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_VERBOSE(x)
Wrapper to avoid constant divisions when using units.
DataModel_detail::const_iterator< DataVector > const_iterator
Standard const_iterator.
const_reverse_iterator rend() const noexcept
Return a const_reverse_iterator pointing at the beginning of the collection.
const_reverse_iterator rbegin() const noexcept
Return a const_reverse_iterator pointing past the end of the collection.
std::reverse_iterator< const_iterator > const_reverse_iterator
bool fit(const LArSamples::AbsShape &data, const AbsShape &reference, double &k, double &deltaT, double &chi2, const ScaledErrorData *sed=0) const
Local cache for magnetic field (based on MagFieldServices/AtlasFieldSvcTLS.h)
bool solenoidOn() const
status of the magnets
std::atomic_uint m_countExtensionCleanerVeto
virtual ~CombinedMuonTrackFitter()
SG::ReadCondHandleKey< AtlasFieldCacheCondObj > m_fieldCacheCondObjInputKey
ToolHandle< Muon::IMuonErrorOptimisationTool > m_muonErrorOptimizer
bool optimizeErrors(const EventContext &ctx, Trk::Track &track) const
ToolHandle< Trk::ITrkMaterialProviderTool > m_materialUpdator
Gaudi::Property< unsigned > m_maxWarnings
Gaudi::Property< bool > m_useCaloTG
Gaudi::Property< double > m_badFitChi2
Gaudi::Property< double > m_zECToroid
ServiceHandle< Muon::IMuonIdHelperSvc > m_idHelperSvc
virtual StatusCode initialize() override
std::unique_ptr< MessageHelper > m_messageHelper
ServiceHandle< Trk::ITrackingVolumesSvc > m_trackingVolumesSvc
ToolHandle< Trk::ITrackSummaryTool > m_trackSummary
ToolHandle< Muon::IMuonTrackCleaner > m_cleaner
ToolHandle< Trk::ITrackFitter > m_fitterSL
ToolHandle< Rec::IMuidCaloTrackStateOnSurface > m_caloTSOS
virtual std::unique_ptr< Trk::Track > fit(const EventContext &ctx, const Trk::Track &track, const Trk::RunOutlierRemoval runOutlier, const Trk::ParticleHypothesis particleHypothesis) const override
double normalizedChi2(const Trk::Track &track) const
unsigned int countAEOTs(const Trk::Track &track, const std::string &txt) const
std::unique_ptr< const Trk::Volume > m_calorimeterVolume
bool checkTrack(std::string_view txt, const Trk::Track *newTrack) const
std::atomic_uint m_countCombinedCleanerVeto
ToolHandle< Trk::ITrackFitter > m_fitter
virtual StatusCode finalize() override
bool loadMagneticField(const EventContext &ctx, MagField::AtlasFieldCache &field_cache) const
PublicToolHandle< Muon::MuonEDMPrinterTool > m_printer
std::atomic_uint m_countStandaloneCleanerVeto
Gaudi::Property< bool > m_updateWithCaloTG
std::unique_ptr< const Trk::Volume > m_indetVolume
Gaudi::Property< bool > m_allowCleanerVeto
ToolHandle< Rec::IMuonTrackQuery > m_trackQuery
Provides the abstract interface for track fitting in the common ATLAS Tracking EDM.
@ CalorimeterEntryLayer
Tracking Volume which defines the entrance srufaces of the calorimeter.
@ MuonSpectrometerEntryLayer
Tracking Volume which defines the entrance surfaces of the MS.
Detailed track summary for the muon system Give access to hit counts per chamber.
const std::vector< ChamberHitSummary > & chamberHitSummary() const
access to the vector of chamber hit summaries on the track
const Amg::Vector3D & momentum() const
Access method for the momentum.
const Amg::Vector3D & position() const
Access method for the position.
double charge() const
Returns the charge.
std::unique_ptr< ParametersBase< DIM, T > > uniqueClone() const
clone method for polymorphic deep copy returning unique_ptr; it is not overriden, but uses the existi...
Class to handle RIO On Tracks ROT) for InDet and Muons, it inherits from the common MeasurementBase.
Identifier identify() const
return the identifier -extends MeasurementBase
@ StraightTrack
A straight track.
represents the track state (measurement, material, fit parameters and quality) at a surface.
const MeasurementBase * measurementOnTrack() const
returns MeasurementBase const overload
const TrackParameters * trackParameters() const
return ptr to trackparameters const overload
@ Perigee
This represents a perigee, and so will contain a Perigee object only.
@ CaloDeposit
This TSOS contains a CaloEnergy object.
A summary of the information contained by a track.
const Trk::TrackStates * trackStateOnSurfaces() const
return a pointer to a const DataVector of const TrackStateOnSurfaces.
const DataVector< const TrackParameters > * trackParameters() const
Return a pointer to a vector of TrackParameters.
const FitQuality * fitQuality() const
return a pointer to the fit quality const-overload
double chi2(TH1 *h0, TH1 *h1)
std::string toString(const Translation3D &translation, int precision=4)
GeoPrimitvesToStringConverter.
bool hasPositiveDiagElems(const AmgSymMatrix(N) &mat)
Returns true if all diagonal elements of the covariance matrix are finite aka sane in the above defin...
Eigen::Matrix< double, 3, 1 > Vector3D
bool isSmall(const ChIndex index)
Returns true if the chamber index is in a small sector.
bool isBarrel(const ChIndex index)
Returns true if the chamber index points to a barrel chamber.
ChIndex
enum to classify the different chamber layers in the muon spectrometer
std::vector< const MeasurementBase * > MeasurementSet
vector of fittable measurements
DataVector< const Trk::TrackStateOnSurface > TrackStates
bool RunOutlierRemoval
switch to toggle quality processing after fit
ParticleHypothesis
Enumeration for Particle hypothesis respecting the interaction with material.
ParametersBase< TrackParametersDim, Charged > TrackParameters
structure to hold information per chamber in the muon system