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) {
91 static const SG::AuxElement::Accessor<char> acc_isLRT(
"isLRT");
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);
118 ATH_MSG_WARNING(
"Muon has no MSTP, check your input! "<<muon->muonType()<<
", "<<muon->author());
128 if (MuSAMSTP->
pt() > 13000000) {
129 ATH_MSG_DEBUG(
"Skipping SA muon with pT " << (MuSAMSTP->
pt() / 1000.) <<
" GeV!");
134 float spectrometerFieldIntegral = 0.0;
135 muon->parameter(spectrometerFieldIntegral, xAOD::Muon::ParamDef::spectrometerFieldIntegral);
136 if (spectrometerFieldIntegral < 0.1) {
137 ATH_MSG_DEBUG(
"Skipping SA muon with spectrometerFieldIntegral " << spectrometerFieldIntegral <<
" T*m!");
141 candidateSAmuons.push_back(muon);
145 if (candidateSAmuons.size() < 2) {
147 return StatusCode::SUCCESS;
151 std::vector<std::shared_ptr<xAOD::TrackParticle>> extrapolatedMuSATracks;
152 std::map<const xAOD::TrackParticle*, const xAOD::Muon*> muonToExtrapolatedTrackMap;
153 for (
const auto muon : candidateSAmuons) {
154 const xAOD::TrackParticle* MuSAMSTP = muon->trackParticle(xAOD::Muon::MuonSpectrometerTrackParticle);
155 auto extrapolatedMuSATrack =
extrapolateMuSA(*MuSAMSTP, eventInfo, ctx);
156 if (extrapolatedMuSATrack->definingParameters()[
Trk::d0] > 8000) {
157 ATH_MSG_DEBUG(
"Failed to extrapolate MuSA track, skipping!");
161 extrapolatedMuSATracks.emplace_back(extrapolatedMuSATrack.release());
162 muonToExtrapolatedTrackMap[extrapolatedMuSATracks.back().get()] = muon;
163 ATH_MSG_VERBOSE(
"Extrapolated MuSA track! Total extrapolated so far: " << extrapolatedMuSATracks.size());
166 if (extrapolatedMuSATracks.size() < 2) {
168 return StatusCode::SUCCESS;
171 std::unique_ptr<Trk::IVKalState> state =
m_vertexFitter->makeState(ctx);
172 std::vector<const xAOD::TrackParticle*> tracksToFit(2);
173 std::vector<const xAOD::NeutralParticle*> dummyNeutrals;
175 for (
unsigned int i = 0; i < extrapolatedMuSATracks.size(); i++) {
176 for (
unsigned int j = i+1; j < extrapolatedMuSATracks.size(); j++) {
178 tracksToFit[0] = extrapolatedMuSATracks[i].get();
179 tracksToFit[1] = extrapolatedMuSATracks[j].get();
181 MuSACandidate.
pos, MuSACandidate.
mom,
184 MuSACandidate.
chi2, *state);
185 if (
res.isSuccess()) {
190 muonToExtrapolatedTrackMap[tracksToFit[0]],
191 muonToExtrapolatedTrackMap[tracksToFit[1]]
193 MuSACandidate.
minOpAng = muonToExtrapolatedTrackMap[tracksToFit[0]]->p4().DeltaR(
194 muonToExtrapolatedTrackMap[tracksToFit[1]]->p4());
195 workVerticesContainer.emplace_back(std::move(MuSACandidate));
203 return StatusCode::SUCCESS;
209 for (
auto& workVertex : workVerticesContainer) {
211 ATH_MSG_DEBUG(
"SA vertex chi2 too high, removing from consideration");
212 workVertex.isGood =
false;
217 workVerticesContainer.erase(
std::remove_if(workVerticesContainer.begin(), workVerticesContainer.end(),
220 return StatusCode::SUCCESS;
232 if (workVerticesContainer.size() < 2) {
234 return StatusCode::SUCCESS;
239 ATH_MSG_VERBOSE(
"Sorted vertices by chi2! Lowest chi2: " << workVerticesContainer.front().chi2 <<
" Highest chi2: " << workVerticesContainer.back().chi2);
242 for (
unsigned int i = 0; i < workVerticesContainer.size(); i++) {
243 auto& vertex = workVerticesContainer.at(i);
244 if (!vertex.isGood) {
247 for (
unsigned int j = i+1; j < workVerticesContainer.size(); j++) {
248 auto& otherVertex = workVerticesContainer.at(j);
249 for (
const auto& muon : vertex.muonCandidates) {
250 if (std::find(otherVertex.muonCandidates.begin(), otherVertex.muonCandidates.end(), muon) != otherVertex.muonCandidates.end()) {
252 ATH_MSG_VERBOSE(
"Found a vertex re-using a muon with chi2: " << otherVertex.chi2 <<
" removing from consideration!");
253 otherVertex.isGood =
false;
260 workVerticesContainer.erase(
std::remove_if(workVerticesContainer.begin(), workVerticesContainer.end(),
263 return StatusCode::SUCCESS;
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_WARNING(x)
std::pair< std::vector< unsigned int >, bool > res
xAOD::MuonContainer * muonContainer
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
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".