ATLAS Offline Software
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"
16 #include "xAODMuon/MuonContainer.h"
25 
26 namespace {
27  constexpr const double MeVtoGeV = 1 / Gaudi::Units::GeV;
28 }
29 
30 MuonCreatorAlg::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();
41  ATH_CHECK(m_segContainerName.initialize(!m_segContainerName.empty()));
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 
72 StatusCode 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 }
MuonCreatorAlg::m_slowMuonCollectionName
SG::WriteHandleKey< xAOD::SlowMuonContainer > m_slowMuonCollectionName
Definition: MuonCreatorAlg.h:41
MuonCreatorAlg::m_msOnlyExtrapolatedTrkCollectionName
SG::WriteHandleKey< TrackCollection > m_msOnlyExtrapolatedTrkCollectionName
Definition: MuonCreatorAlg.h:51
MuonCreatorAlg::m_segContainerName
SG::ReadHandleKey< xAOD::MuonSegmentContainer > m_segContainerName
Definition: MuonCreatorAlg.h:62
TrigDefs::Group
Group
Properties of a chain group.
Definition: GroupProperties.h:13
MuonCreatorAlg::m_muonCollectionName
SG::WriteHandleKey< xAOD::MuonContainer > m_muonCollectionName
Definition: MuonCreatorAlg.h:40
phi
Scalar phi() const
phi method
Definition: AmgMatrixBasePlugin.h:64
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
Trk::locX
@ locX
Definition: ParamDefs.h:43
MuonCreatorAlg::m_clusterContainerLinkName
SG::WriteHandleKey< CaloClusterCellLinkContainer > m_clusterContainerLinkName
Definition: MuonCreatorAlg.h:66
Trk::Track
The ATLAS Track class.
Definition: Tracking/TrkEvent/TrkTrack/TrkTrack/Track.h:73
SG::VIEW_ELEMENTS
@ VIEW_ELEMENTS
this data object is a view, it does not own its elmts
Definition: OwnershipPolicy.h:18
MuonCreatorAlg::m_combinedTrkCollectionName
SG::WriteHandleKey< TrackCollection > m_combinedTrkCollectionName
Definition: MuonCreatorAlg.h:44
eta
Scalar eta() const
pseudorapidity method
Definition: AmgMatrixBasePlugin.h:79
ConstDataVector.h
DataVector adapter that acts like it holds const pointers.
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
Trk::Track::trackStateOnSurfaces
const Trk::TrackStates * trackStateOnSurfaces() const
return a pointer to a const DataVector of const TrackStateOnSurfaces.
xAOD::TrackParticle_v1::eta
virtual double eta() const override final
The pseudorapidity ( ) of the particle.
Definition: TrackParticle_v1.cxx:77
xAOD::Muon_v1::phi
virtual double phi() const
The azimuthal angle ( ) of the particle.
MuonSegmentAuxContainer.h
EventPrimitivesHelpers.h
MuonCreatorAlg::m_makeClusters
Gaudi::Property< bool > m_makeClusters
Definition: MuonCreatorAlg.h:71
MuonCreatorAlg::execute
virtual StatusCode execute(const EventContext &ctx) const override
Definition: MuonCreatorAlg.cxx:72
xAOD::Muon_v1::eta
virtual double eta() const
The pseudorapidity ( ) of the particle.
MuonCreatorAlg::m_segAssocMapKey
SG::ReadHandleKey< MuonCombined::MuonTagToSegMap > m_segAssocMapKey
Definition: MuonCreatorAlg.h:61
MuonCreatorAlg::m_muonCreatorTool
ToolHandle< MuonCombined::IMuonCreatorTool > m_muonCreatorTool
Definition: MuonCreatorAlg.h:38
test_pyathena.pt
pt
Definition: test_pyathena.py:11
CP::MeVtoGeV
constexpr float MeVtoGeV
Definition: IsolationCloseByCorrectionTool.cxx:33
SlowMuonAuxContainer.h
MuonCreatorAlg::m_doSA
Gaudi::Property< bool > m_doSA
Definition: MuonCreatorAlg.h:70
MuonCreatorAlg::initialize
virtual StatusCode initialize() override
Definition: MuonCreatorAlg.cxx:32
SG::VarHandleKey::key
const std::string & key() const
Return the StoreGate ID for the referenced object.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:141
MdtDriftCircleOnTrack.h
SG::VarHandleKey::empty
bool empty() const
Test if the key is blank.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:150
CaloClusterAuxContainer.h
MuonCreatorAlg::m_tagMaps
SG::ReadHandleKeyArray< MuonCombined::InDetCandidateToTagMap > m_tagMaps
Definition: MuonCreatorAlg.h:58
Monitored::Collection
ValuesCollection< T > Collection(std::string name, const T &collection)
Declare a monitored (double-convertible) collection.
Definition: MonitoredCollection.h:38
MuonSegmentContainer.h
AthReentrantAlgorithm
An algorithm that can be simultaneously executed in multiple threads.
Definition: AthReentrantAlgorithm.h:83
MuonCreatorAlg::m_extrapolatedCollectionName
SG::WriteHandleKey< xAOD::TrackParticleContainer > m_extrapolatedCollectionName
Definition: MuonCreatorAlg.h:45
MuonAuxContainer.h
xAOD::CaloCluster_v1
Description of a calorimeter cluster.
Definition: CaloCluster_v1.h:59
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
TrackParticleAuxContainer.h
MuonCreatorAlg::m_extrapolatedTrkCollectionName
SG::WriteHandleKey< TrackCollection > m_extrapolatedTrkCollectionName
Definition: MuonCreatorAlg.h:47
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
SG::WriteHandle::ptr
pointer_type ptr()
Dereference the pointer.
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
SG::VarHandleKey::initialize
StatusCode initialize(bool used=true)
If this object is used as a property, then this should be called during the initialize phase.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:103
Muon::MdtDriftCircleOnTrack::driftRadius
double driftRadius() const
Returns the value of the drift radius.
Definition: MdtDriftCircleOnTrack.h:277
MuonCreatorAlg::m_clusterContainerName
SG::WriteHandleKey< xAOD::CaloClusterContainer > m_clusterContainerName
Definition: MuonCreatorAlg.h:64
MuonCreatorAlg::m_msOnlyExtrapolatedCollectionName
SG::WriteHandleKey< xAOD::TrackParticleContainer > m_msOnlyExtrapolatedCollectionName
Definition: MuonCreatorAlg.h:49
Trk::MeasurementBase::localCovariance
const Amg::MatrixX & localCovariance() const
Interface method to get the localError.
Definition: MeasurementBase.h:138
SlowMuonContainer.h
merge.output
output
Definition: merge.py:17
Trk::TrackStateOnSurface
represents the track state (measurement, material, fit parameters and quality) at a surface.
Definition: TrackStateOnSurface.h:71
MuonCreatorAlg::m_indetCandidateCollectionName
SG::ReadHandleKey< InDetCandidateCollection > m_indetCandidateCollectionName
Definition: MuonCreatorAlg.h:53
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
MuonCreatorAlg::m_monTool
ToolHandle< GenericMonitoringTool > m_monTool
Definition: MuonCreatorAlg.h:74
Amg::error
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 ...
Definition: EventPrimitivesHelpers.h:40
Muon::MdtDriftCircleOnTrack
This class represents the corrected MDT measurements, where the corrections include the effects of wi...
Definition: MdtDriftCircleOnTrack.h:37
MuonCreatorAlg::m_combinedCollectionName
SG::WriteHandleKey< xAOD::TrackParticleContainer > m_combinedCollectionName
Definition: MuonCreatorAlg.h:43
MuonContainer.h
SG::ReadHandle::ptr
const_pointer_type ptr()
Dereference the pointer.
MuonCreatorAlg::m_muonCandidateKeys
SG::ReadHandleKeyArray< MuonCandidateCollection > m_muonCandidateKeys
Definition: MuonCreatorAlg.h:56
SG::WriteHandle
Definition: StoreGate/StoreGate/WriteHandle.h:76
h
SG::WriteHandle::record
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
ConstDataVector
DataVector adapter that acts like it holds const pointers.
Definition: ConstDataVector.h:76
MuonCombined::IMuonCreatorTool::OutputData
Definition: IMuonCreatorTool.h:37
CaloClusterContainer.h
MuonCreatorAlg::m_buildSlowMuon
Gaudi::Property< bool > m_buildSlowMuon
Definition: MuonCreatorAlg.h:69
MuonSegment.h
Monitored::Scalar
Declare a monitored scalar variable.
Definition: MonitoredScalar.h:34
CaloNoise_fillDB.mu
mu
Definition: CaloNoise_fillDB.py:53
GeV
#define GeV
Definition: CaloTransverseBalanceVecMon.cxx:30
MuonCreatorAlg.h
dq_make_web_display.cl
cl
print [x.__class__ for x in toList(dqregion.getSubRegions()) ]
Definition: dq_make_web_display.py:26
DataVector::size
size_type size() const noexcept
Returns the number of elements in the collection.
MuonCreatorAlg::MuonCreatorAlg
MuonCreatorAlg(const std::string &name, ISvcLocator *pSvcLocator)
Definition: MuonCreatorAlg.cxx:30
TrackParticleContainer.h
SegmentCollection.h
xAOD::TrackParticle_v1::phi
virtual double phi() const override final
The azimuthal angle ( ) of the particle (has range to .)