ATLAS Offline Software
Loading...
Searching...
No Matches
MuonCreatorAlg.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3*/
4
5#include "MuonCreatorAlg.h"
6
7#include <vector>
8
10#include "GaudiKernel/SystemOfUnits.h"
25
26namespace {
27 constexpr const double MeVtoGeV = 1 / Gaudi::Units::GeV;
28}
29
30MuonCreatorAlg::MuonCreatorAlg(const std::string& name, ISvcLocator* pSvcLocator) : AthReentrantAlgorithm(name, pSvcLocator) {}
31
33 ATH_CHECK(m_muonCreatorTool.retrieve());
34 ATH_CHECK(m_muonCollectionName.initialize());
38 // Can't use a flag in intialize for an array of keys
39 if (!m_doSA) ATH_CHECK(m_tagMaps.initialize());
40 else m_tagMaps.clear();
42 ATH_CHECK(m_segAssocMapKey.initialize(!m_segAssocMapKey.empty()));
44 m_combinedCollectionName = m_combinedCollectionName.key() + "TrackParticles";
58
59 if (not m_monTool.name().empty()) { ATH_CHECK(m_monTool.retrieve()); }
60 ATH_MSG_INFO("MuonCreatorAlg has been setup successfully");
61 ATH_MSG_INFO(" *** CombinedTrackContainer: " << m_combinedTrkCollectionName);
62 ATH_MSG_INFO(" *** xAOD::CombinedTrackContainer: " << m_combinedCollectionName);
63
64 ATH_MSG_INFO(" *** xAOD::ExtrpolatedTrackContainer: " << m_extrapolatedCollectionName);
65 ATH_MSG_INFO(" *** ExtrpolatedTrackContainer: " << m_extrapolatedTrkCollectionName);
66 ATH_MSG_INFO(" *** xAOD::MSOnlyTrackContainer: " << m_msOnlyExtrapolatedCollectionName);
67 ATH_MSG_INFO(" *** ExtrpolatedTackContainer: " << m_msOnlyExtrapolatedTrkCollectionName);
68
69 return StatusCode::SUCCESS;
70}
71
72StatusCode MuonCreatorAlg::execute(const EventContext& ctx) const {
73 std::vector<const MuonCombined::InDetCandidateToTagMap*> tagMaps;
74 tagMaps.reserve(m_tagMaps.size());
75 if (!m_doSA) {
76 for (SG::ReadHandle<MuonCombined::InDetCandidateToTagMap>& h : m_tagMaps.makeHandles(ctx)) tagMaps.push_back(h.cptr());
77 }
78
79 // Create the xAOD container and its auxiliary store:
81 ATH_CHECK(wh_muons.recordNonConst(std::make_unique<xAOD::MuonContainer>(), std::make_unique<xAOD::MuonAuxContainer>()));
82 ATH_MSG_DEBUG("Recorded Muons with key: " << m_muonCollectionName.key());
84
85 // Create and record track particles:
86 // combined tracks
89 ATH_CHECK(wh_combtp.record(std::make_unique<xAOD::TrackParticleContainer>(), std::make_unique<xAOD::TrackParticleAuxContainer>()));
90 ATH_CHECK(wh_combtrk.record(std::make_unique<TrackCollection>()));
91 output.combinedTrackParticleContainer = wh_combtp.ptr();
92 output.combinedTrackCollection = wh_combtrk.ptr();
93
94 // extrapolated tracks
97 ATH_CHECK(wh_extrtp.record(std::make_unique<xAOD::TrackParticleContainer>(), std::make_unique<xAOD::TrackParticleAuxContainer>()));
98 ATH_CHECK(wh_extrtrk.record(std::make_unique<TrackCollection>()));
99 output.extrapolatedTrackParticleContainer = wh_extrtp.ptr();
100 output.extrapolatedTrackCollection = wh_extrtrk.ptr();
101
102 // msonly tracks
105 ATH_CHECK(wh_msextrtp.record(std::make_unique<xAOD::TrackParticleContainer>(), std::make_unique<xAOD::TrackParticleAuxContainer>()));
106 ATH_CHECK(wh_msextrtrk.record(std::make_unique<TrackCollection>()));
107 output.msOnlyExtrapolatedTrackParticleContainer = wh_msextrtp.ptr();
108 output.msOnlyExtrapolatedTrackCollection = wh_msextrtrk.ptr();
109
110 // segments
111 if (!m_segContainerName.empty()) {
113 output.xaodSegmentContainer = rh_segment.ptr();
114 }
115 if (!m_segAssocMapKey.empty()) {
117 output.tagToSegmentAssocMap = rh_segAssocMap.ptr();
118 }
119
120 // calo clusters
121 std::unique_ptr<xAOD::CaloClusterContainer> caloclusters{nullptr};
122 std::unique_ptr<xAOD::CaloClusterAuxContainer> caloclustersaux{nullptr};
123
124 if (m_makeClusters) {
125 caloclusters = std::make_unique<xAOD::CaloClusterContainer>();
126 caloclustersaux = std::make_unique<xAOD::CaloClusterAuxContainer>();
127 caloclusters->setStore(caloclustersaux.get());
128 output.clusterContainer = caloclusters.get();
129 }
130
134
135 if (m_buildSlowMuon) {
137 ATH_CHECK(wh_slowmuon.record(std::make_unique<xAOD::SlowMuonContainer>(), std::make_unique<xAOD::SlowMuonAuxContainer>()));
138 output.slowMuonContainer = wh_slowmuon.ptr();
139 } else {
140 for (SG::ReadHandle<MuonCandidateCollection>& muonCandidateRH : m_muonCandidateKeys.makeHandles(ctx)) {
141 if (!muonCandidateRH.isValid()) {
142 ATH_MSG_ERROR("Could not read " << muonCandidateRH.fullKey());
143 return StatusCode::FAILURE;
144 }
145 muon_candidates.insert(muon_candidates.end(), muonCandidateRH->begin(), muonCandidateRH->end());
146 }
147 }
148 m_muonCreatorTool->create(ctx, muon_candidates.asDataVector(), tagMaps, output);
149
150 if (m_makeClusters) {
153 std::unique_ptr<CaloClusterCellLinkContainer> clusterlinks = std::make_unique<CaloClusterCellLinkContainer>();
154 auto* sg = wh_clusters.storeHandle().get();
155 for (xAOD::CaloCluster* cl : *output.clusterContainer) { cl->setLink(clusterlinks.get(), sg); }
156 ATH_CHECK(wh_clusterslink.record(std::move(clusterlinks)));
157 ATH_CHECK(wh_clusters.record(std::move(caloclusters), std::move(caloclustersaux)));
158 }
159
160 //---------------------------------------------------------------------------------------------------------------------//
161 //------------ Monitoring of the reconstructed muons inside the trigger algs ------------//
162 //------------ Author: Laurynas Mince ------------//
163 //------------ Created: 26.07.2019 ------------//
164 //---------------------------------------------------------------------------------------------------------------------//
165
166 // Only run monitoring for online algorithms
167 if (!m_monTool.name().empty()) {
168 // Monitoring histograms and variables
169 auto muon_n = Monitored::Scalar<int>("muon_n", wh_muons->size());
170 auto muon_pt =
171 Monitored::Collection("muon_pt", *(wh_muons.ptr()), [](auto const& mu) { return mu->pt() * MeVtoGeV; }); // converted to GeV
172 auto muon_eta = Monitored::Collection("muon_eta", *(wh_muons.ptr()), &xAOD::Muon_v1::eta);
173 auto muon_phi = Monitored::Collection("muon_phi", *(wh_muons.ptr()), &xAOD::Muon_v1::phi);
174
175 std::vector<float> MDT_R, MDT_dR;
176 for( const auto mu : *wh_muons ) {
177 if (!(mu->muonType() == xAOD::Muon::CaloTagged || mu->muonType() == xAOD::Muon::SegmentTagged)) {
178 const Trk::Track* trk = mu->primaryTrackParticle()->track();
179 for (const Trk::TrackStateOnSurface* tsos : *trk->trackStateOnSurfaces()) {
180 const Muon::MdtDriftCircleOnTrack* mdt = dynamic_cast <const Muon::MdtDriftCircleOnTrack*>(tsos->measurementOnTrack());
181 if (!mdt) continue;
182 MDT_R.push_back(std::abs(mdt->driftRadius()));
183 MDT_dR.push_back(Amg::error(mdt->localCovariance(), Trk::locX));
184 }
185 }
186 }
187 auto muon_MDT_R = Monitored::Collection("muon_MDT_R", MDT_R);
188 auto muon_MDT_dR = Monitored::Collection("muon_MDT_dR", MDT_dR);
189
190 auto satrks_n = Monitored::Scalar<int>("satrks_n", wh_extrtp->size());
191 auto satrks_pt = Monitored::Collection("satrks_pt", *(wh_extrtp.ptr()),
192 [](auto const& satrk) { return satrk->pt() * MeVtoGeV; }); // converted to GeV
193 auto satrks_eta = Monitored::Collection("satrks_eta", *(wh_extrtp.ptr()), &xAOD::TrackParticle_v1::eta);
194 auto satrks_phi = Monitored::Collection("satrks_phi", *(wh_extrtp.ptr()), &xAOD::TrackParticle_v1::phi);
195
196 auto cbtrks_n = Monitored::Scalar<int>("cbtrks_n", wh_combtp->size());
197 auto cbtrks_pt = Monitored::Collection("cbtrks_pt", *(wh_combtp.ptr()),
198 [](auto const& cbtrk) { return cbtrk->pt() * MeVtoGeV; }); // converted to GeV
199 auto cbtrks_eta = Monitored::Collection("cbtrks_eta", *(wh_combtp.ptr()), &xAOD::TrackParticle_v1::eta);
200 auto cbtrks_phi = Monitored::Collection("cbtrks_phi", *(wh_combtp.ptr()), &xAOD::TrackParticle_v1::phi);
201
202 if (!m_doSA) {
204
205 auto idtrks_n = Monitored::Scalar<int>("idtrks_n", indetCandidateCollection->size());
206 auto idtrks_pt = Monitored::Collection("idtrks_pt", *indetCandidateCollection,
207 [](auto const& idtrk) { return idtrk->indetTrackParticle().pt() * MeVtoGeV; });
208 auto idtrks_eta = Monitored::Collection("idtrks_eta", *indetCandidateCollection,
209 [](auto const& idtrk) { return idtrk->indetTrackParticle().eta(); });
210 auto idtrks_phi = Monitored::Collection("idtrks_phi", *indetCandidateCollection,
211 [](auto const& idtrk) { return idtrk->indetTrackParticle().phi(); });
212 auto monitorIt = Monitored::Group(m_monTool, muon_n, muon_pt, muon_eta, muon_phi, muon_MDT_R, muon_MDT_dR, satrks_n, satrks_pt, satrks_eta, satrks_phi,
213 cbtrks_n, cbtrks_pt, cbtrks_eta, cbtrks_phi, idtrks_n, idtrks_pt, idtrks_eta, idtrks_phi);
214 } else
215 auto monitorIt = Monitored::Group(m_monTool, muon_n, muon_pt, muon_eta, muon_phi, muon_MDT_R, muon_MDT_dR, satrks_n, satrks_pt, satrks_eta, satrks_phi,
216 cbtrks_n, cbtrks_pt, cbtrks_eta, cbtrks_phi);
217 }
218
219 return StatusCode::SUCCESS;
220}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_DEBUG(x)
DataVector adapter that acts like it holds const pointers.
Header file for AthHistogramAlgorithm.
An algorithm that can be simultaneously executed in multiple threads.
DataVector adapter that acts like it holds const pointers.
iterator end() noexcept
Return an iterator pointing past the end of the collection.
iterator insert(iterator position, value_type pElem)
Add a new element to the collection.
const DV * asDataVector() const
Return a pointer to this object, as a const DataVector.
Group of local monitoring quantities and retain correlation when filling histograms
Declare a monitored scalar variable.
SG::WriteHandleKey< xAOD::TrackParticleContainer > m_combinedCollectionName
SG::ReadHandleKeyArray< MuonCandidateCollection > m_muonCandidateKeys
SG::ReadHandleKey< MuonCombined::MuonTagToSegMap > m_segAssocMapKey
MuonCreatorAlg(const std::string &name, ISvcLocator *pSvcLocator)
SG::ReadHandleKey< InDetCandidateCollection > m_indetCandidateCollectionName
SG::WriteHandleKey< xAOD::SlowMuonContainer > m_slowMuonCollectionName
SG::WriteHandleKey< xAOD::MuonContainer > m_muonCollectionName
SG::WriteHandleKey< TrackCollection > m_extrapolatedTrkCollectionName
SG::WriteHandleKey< TrackCollection > m_msOnlyExtrapolatedTrkCollectionName
virtual StatusCode execute(const EventContext &ctx) const override
SG::WriteHandleKey< CaloClusterCellLinkContainer > m_clusterContainerLinkName
ToolHandle< MuonCombined::IMuonCreatorTool > m_muonCreatorTool
SG::WriteHandleKey< xAOD::CaloClusterContainer > m_clusterContainerName
virtual StatusCode initialize() override
SG::WriteHandleKey< xAOD::TrackParticleContainer > m_msOnlyExtrapolatedCollectionName
Gaudi::Property< bool > m_makeClusters
Gaudi::Property< bool > m_buildSlowMuon
Gaudi::Property< bool > m_doSA
SG::WriteHandleKey< TrackCollection > m_combinedTrkCollectionName
SG::WriteHandleKey< xAOD::TrackParticleContainer > m_extrapolatedCollectionName
SG::ReadHandleKeyArray< MuonCombined::InDetCandidateToTagMap > m_tagMaps
ToolHandle< GenericMonitoringTool > m_monTool
SG::ReadHandleKey< xAOD::MuonSegmentContainer > m_segContainerName
This class represents the corrected MDT measurements, where the corrections include the effects of wi...
double driftRadius() const
Returns the value of the drift radius.
const_pointer_type ptr()
Dereference the pointer.
const ServiceHandle< IProxyDict > & storeHandle() const
Return handle to the referenced store.
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
StatusCode recordNonConst(std::unique_ptr< T > data)
Record a non-const object to the store.
pointer_type ptr()
Dereference the pointer.
const Amg::MatrixX & localCovariance() const
Interface method to get the localError.
represents the track state (measurement, material, fit parameters and quality) at a surface.
const Trk::TrackStates * trackStateOnSurfaces() const
return a pointer to a const DataVector of const TrackStateOnSurfaces.
virtual double eta() const
The pseudorapidity ( ) of the particle.
virtual double phi() const
The azimuthal angle ( ) of the particle.
virtual double phi() const override final
The azimuthal angle ( ) of the particle (has range to .)
virtual double eta() const override final
The pseudorapidity ( ) of the particle.
double error(const Amg::MatrixX &mat, int index)
return diagonal error of the matrix caller should ensure the matrix is symmetric and the index is in ...
constexpr float MeVtoGeV
ValuesCollection< T > Collection(std::string name, const T &collection)
Declare a monitored (double-convertible) collection.
@ VIEW_ELEMENTS
this data object is a view, it does not own its elmts
@ locX
Definition ParamDefs.h:37
CaloCluster_v1 CaloCluster
Define the latest version of the calorimeter cluster class.