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
77 std::vector<const xAOD::Muon*> candidateSAmuons;
79 bool isSA = (muon->muonType() == xAOD::Muon::MuonStandAlone);
80 bool isCalo = (muon->muonType() == xAOD::Muon::CaloTagged);
81 bool isSegment = (muon->muonType() == xAOD::Muon::SegmentTagged);
82 bool isSiForward = (muon->muonType() == xAOD::Muon::SiliconAssociatedForwardMuon);
88 const xAOD::TrackParticle* MuSAMSTP = muon->trackParticle(xAOD::Muon::MuonSpectrometerTrackParticle);
90 if (isCalo || isSegment || isSiForward) {
91 ATH_MSG_VERBOSE(
"Skipping non-SA, non-Combined muon type in validation mode!");
104 if (MuSAMSTP->
pt() > 13000000) {
105 ATH_MSG_DEBUG(
"Skipping SA muon with pT " << (MuSAMSTP->
pt() / 1000.) <<
" GeV!");
110 float spectrometerFieldIntegral = 0.0;
111 muon->parameter(spectrometerFieldIntegral, xAOD::Muon::spectrometerFieldIntegral);
112 if (spectrometerFieldIntegral < 0.1) {
113 ATH_MSG_DEBUG(
"Skipping SA muon with spectrometerFieldIntegral " << muon->spectrometerFieldIntegral <<
" T*m!");
117 candidateSAmuons.push_back(muon);
121 if (candidateSAmuons.size() < 2) {
123 return StatusCode::SUCCESS;
127 std::vector<std::unique_ptr<xAOD::TrackParticle>> extrapolatedMuSATracks;
128 std::map<const xAOD::TrackParticle*, const xAOD::Muon*> muonToExtrapolatedTrackMap;
129 for (
const auto muon : candidateSAmuons) {
130 const xAOD::TrackParticle* MuSAMSTP = muon->trackParticle(xAOD::Muon::MuonSpectrometerTrackParticle);
131 auto extrapolatedMuSATrack =
extrapolateMuSA(*MuSAMSTP, eventInfo, ctx);
132 if (extrapolatedMuSATrack->definingParameters()[
Trk::d0] > 8000) {
133 ATH_MSG_DEBUG(
"Failed to extrapolate MuSA track, skipping!");
136 extrapolatedMuSATracks.push_back(std::move(extrapolatedMuSATrack));
137 muonToExtrapolatedTrackMap[extrapolatedMuSATracks.back().get()] = muon;
138 ATH_MSG_VERBOSE(
"Extrapolated MuSA track! Total extrapolated so far: " << extrapolatedMuSATracks.size());
141 if (extrapolatedMuSATracks.size() < 2) {
143 return StatusCode::SUCCESS;
146 std::unique_ptr<Trk::IVKalState> state =
m_vertexFitter->makeState(ctx);
148 for (
unsigned int i = 0; i < extrapolatedMuSATracks.size(); i++) {
149 for (
unsigned int j = i+1; j < extrapolatedMuSATracks.size(); j++) {
151 std::vector<const xAOD::TrackParticle*> tracksToFit = {
152 extrapolatedMuSATracks[i].get(),
153 extrapolatedMuSATracks[j].get()
155 std::vector<const xAOD::NeutralParticle*> dummyNeutrals;
157 MuSACandidate.
pos, MuSACandidate.
mom,
160 MuSACandidate.
chi2, *state);
161 if (
res.isSuccess()) {
165 auto sharedTrack1 = std::make_shared<const xAOD::TrackParticle>(*extrapolatedMuSATracks[i]);
166 auto sharedTrack2 = std::make_shared<const xAOD::TrackParticle>(*extrapolatedMuSATracks[j]);
170 muonToExtrapolatedTrackMap[tracksToFit[0]],
171 muonToExtrapolatedTrackMap[tracksToFit[1]]
173 MuSACandidate.
minOpAng = muonToExtrapolatedTrackMap[tracksToFit[0]]->p4().DeltaR(
174 muonToExtrapolatedTrackMap[tracksToFit[1]]->p4());
175 workVerticesContainer.emplace_back(MuSACandidate);
183 return StatusCode::SUCCESS;
189 for (
auto& workVertex : workVerticesContainer) {
191 ATH_MSG_DEBUG(
"SA vertex chi2 too high, removing from consideration");
192 workVertex.isGood =
false;
197 workVerticesContainer.erase(
std::remove_if(workVerticesContainer.begin(), workVerticesContainer.end(),
200 return StatusCode::SUCCESS;
212 if (workVerticesContainer.size() < 2) {
214 return StatusCode::SUCCESS;
219 ATH_MSG_VERBOSE(
"Sorted vertices by chi2! Lowest chi2: " << workVerticesContainer.front().chi2 <<
" Highest chi2: " << workVerticesContainer.back().chi2);
222 for (
unsigned int i = 0; i < workVerticesContainer.size(); i++) {
223 auto& vertex = workVerticesContainer.at(i);
224 if (!vertex.isGood) {
227 for (
unsigned int j = i+1; j < workVerticesContainer.size(); j++) {
228 auto& otherVertex = workVerticesContainer.at(j);
229 for (
const auto& muon : vertex.muonCandidates) {
230 if (std::find(otherVertex.muonCandidates.begin(), otherVertex.muonCandidates.end(), muon) != otherVertex.muonCandidates.end()) {
232 ATH_MSG_VERBOSE(
"Found a vertex re-using a muon with chi2: " << otherVertex.chi2 <<
" removing from consideration!");
233 otherVertex.isGood =
false;
240 workVerticesContainer.erase(
std::remove_if(workVerticesContainer.begin(), workVerticesContainer.end(),
243 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 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".