22 declareInterface<MuSAVtxFitterTool>(
this);
39 return StatusCode::SUCCESS;
49 auto newTrack = std::make_unique<xAOD::TrackParticle>();
50 newTrack->makePrivateStore();
58 newTrack->setDefiningParameters(1.e19, 1.e19, 1.e19, 1.e19, 0);
63 newTrack->setDefiningParametersCovMatrix(*entryPars->covariance());
72 const EventContext& ctx)
const
80 std::vector<const xAOD::Muon*> candidateSAmuons;
84 bool isStacoRecovery =
false;
86 muon->muonType() == xAOD::Muon::MuonType::Combined &&
87 muon->author() == xAOD::Muon::Author::STACO) {
92 if (acc_isLRT.
isAvailable(*muon) && acc_isLRT(*muon)) {
99 const xAOD::TrackParticle* msTrk = muon->trackParticle(xAOD::Muon::MuonSpectrometerTrackParticle);
100 const xAOD::TrackParticle* idTrk = muon->trackParticle(xAOD::Muon::InnerDetectorTrackParticle);
101 if (msTrk && idTrk) {
102 double dEta = std::abs(msTrk->
eta() - idTrk->
eta());
103 double dPhi = std::abs(msTrk->
phi() - idTrk->
phi());
104 if (dPhi >
M_PI) dPhi = 2.0 *
M_PI - dPhi;
106 ATH_MSG_DEBUG(
"Recovering Staco Combined muon with dEta=" << dEta <<
" dPhi=" << dPhi);
107 isStacoRecovery =
true;
112 if (muon->muonType()!= xAOD::Muon::MuonType::MuonStandAlone && !isStacoRecovery && !
m_doValidation) {
116 const xAOD::TrackParticle* MuSAMSTP = muon->trackParticle(xAOD::Muon::MuonSpectrometerTrackParticle);
129 if (MuSAMSTP->
pt() > 13000000) {
130 ATH_MSG_DEBUG(
"Skipping SA muon with pT " << (MuSAMSTP->
pt() / 1000.) <<
" GeV!");
135 float spectrometerFieldIntegral = 0.0;
136 muon->parameter(spectrometerFieldIntegral, xAOD::Muon::ParamDef::spectrometerFieldIntegral);
137 if (spectrometerFieldIntegral < 0.1) {
138 ATH_MSG_DEBUG(
"Skipping SA muon with spectrometerFieldIntegral " << spectrometerFieldIntegral <<
" T*m!");
142 candidateSAmuons.push_back(muon);
146 if (candidateSAmuons.size() < 2) {
148 return StatusCode::SUCCESS;
152 std::vector<std::shared_ptr<xAOD::TrackParticle>> extrapolatedMuSATracks;
153 std::map<const xAOD::TrackParticle*, const xAOD::Muon*> muonToExtrapolatedTrackMap;
154 for (
const auto muon : candidateSAmuons) {
155 const xAOD::TrackParticle* MuSAMSTP = muon->trackParticle(xAOD::Muon::MuonSpectrometerTrackParticle);
156 auto extrapolatedMuSATrack =
extrapolateMuSA(*MuSAMSTP, eventInfo, ctx);
157 if (extrapolatedMuSATrack->definingParameters()[
Trk::d0] > 8000) {
158 ATH_MSG_DEBUG(
"Failed to extrapolate MuSA track, skipping!");
162 extrapolatedMuSATracks.emplace_back(extrapolatedMuSATrack.release());
163 muonToExtrapolatedTrackMap[extrapolatedMuSATracks.back().get()] = muon;
164 ATH_MSG_VERBOSE(
"Extrapolated MuSA track! Total extrapolated so far: " << extrapolatedMuSATracks.size());
167 if (extrapolatedMuSATracks.size() < 2) {
169 return StatusCode::SUCCESS;
172 std::unique_ptr<Trk::IVKalState> state =
m_vertexFitter->makeState(ctx);
173 std::vector<const xAOD::TrackParticle*> tracksToFit(2);
174 std::vector<const xAOD::NeutralParticle*> dummyNeutrals;
176 for (
unsigned int i = 0; i < extrapolatedMuSATracks.size(); i++) {
177 for (
unsigned int j = i+1; j < extrapolatedMuSATracks.size(); j++) {
179 tracksToFit[0] = extrapolatedMuSATracks[i].get();
180 tracksToFit[1] = extrapolatedMuSATracks[j].get();
182 MuSACandidate.
pos, MuSACandidate.
mom,
185 MuSACandidate.
chi2, *state);
186 if (
res.isSuccess()) {
191 muonToExtrapolatedTrackMap[tracksToFit[0]],
192 muonToExtrapolatedTrackMap[tracksToFit[1]]
194 MuSACandidate.
minOpAng = muonToExtrapolatedTrackMap[tracksToFit[0]]->p4().DeltaR(
195 muonToExtrapolatedTrackMap[tracksToFit[1]]->p4());
196 workVerticesContainer.emplace_back(std::move(MuSACandidate));
204 return StatusCode::SUCCESS;
210 for (
auto& workVertex : workVerticesContainer) {
212 ATH_MSG_DEBUG(
"SA vertex chi2 too high, removing from consideration");
213 workVertex.isGood =
false;
218 workVerticesContainer.erase(
std::remove_if(workVerticesContainer.begin(), workVerticesContainer.end(),
221 return StatusCode::SUCCESS;
233 if (workVerticesContainer.size() < 2) {
235 return StatusCode::SUCCESS;
240 ATH_MSG_VERBOSE(
"Sorted vertices by chi2! Lowest chi2: " << workVerticesContainer.front().chi2 <<
" Highest chi2: " << workVerticesContainer.back().chi2);
243 for (
unsigned int i = 0; i < workVerticesContainer.size(); i++) {
244 auto& vertex = workVerticesContainer.at(i);
245 if (!vertex.isGood) {
248 for (
unsigned int j = i+1; j < workVerticesContainer.size(); j++) {
249 auto& otherVertex = workVerticesContainer.at(j);
250 for (
const auto& muon : vertex.muonCandidates) {
251 if (std::find(otherVertex.muonCandidates.begin(), otherVertex.muonCandidates.end(), muon) != otherVertex.muonCandidates.end()) {
253 ATH_MSG_VERBOSE(
"Found a vertex re-using a muon with chi2: " << otherVertex.chi2 <<
" removing from consideration!");
254 otherVertex.isGood =
false;
261 workVerticesContainer.erase(
std::remove_if(workVerticesContainer.begin(), workVerticesContainer.end(),
264 return StatusCode::SUCCESS;
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_DEBUG(x,...)
#define ATH_MSG_WARNING(x,...)
#define ATH_MSG_VERBOSE(x,...)
std::pair< std::vector< unsigned int >, bool > res
xAOD::MuonContainer * muonContainer
Helper class to provide type-safe access to aux data.
bool isAvailable(const ELT &e) const
Test to see if this variable exists in the store.
Class describing the Line to which the Perigee refers to.
float beamPosX() const
X coordinate of the beam spot position.
float beamPosZ() const
Z coordinate of the beam spot position.
float beamPosY() const
Y coordinate of the beam spot position.
const Trk::Perigee & perigeeParameters() const
Returns the Trk::MeasuredPerigee track parameters.
virtual double phi() const override final
The azimuthal angle ( ) of the particle (has range to .).
virtual double pt() const override final
The transverse momentum ( ) of the particle.
virtual double eta() const override final
The pseudorapidity ( ) of the particle.
Eigen::Matrix< double, 3, 1 > Vector3D
namespace for combined reconstruction tools and interfaces
PropDirection
PropDirection, enum for direction of the propagation.
void sort(typename DataModel_detail::iterator< DVL > beg, typename DataModel_detail::iterator< DVL > end)
Specialization of sort for DataVector/List.
DataModel_detail::iterator< DVL > remove_if(typename DataModel_detail::iterator< DVL > beg, typename DataModel_detail::iterator< DVL > end, Predicate pred)
Specialization of remove_if for DataVector/List.
EventInfo_v1 EventInfo
Definition of the latest event info version.
TrackParticle_v1 TrackParticle
Reference the current persistent version:
MuonContainer_v1 MuonContainer
Definition of the current "Muon container version".