ATLAS Offline Software
Loading...
Searching...
No Matches
MuonRpcTimingDecorAlg.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3*/
4
12namespace{
15}
16MuonRpcTimingDecorAlg::MuonRpcTimingDecorAlg(const std::string& name, ISvcLocator* pSvcLocator):
17 AthReentrantAlgorithm(name,pSvcLocator){}
18
20 ATH_CHECK(m_MuonContainer.initialize());
21 m_idKey = m_MuonContainer.key() +".rpcHitIdentifier";
22 m_posXKey = m_MuonContainer.key() +".rpcHitPositionX";
23 m_posYKey = m_MuonContainer.key() +".rpcHitPositionY";
24 m_posZKey = m_MuonContainer.key() +".rpcHitPositionZ";
25 m_timeKey = m_MuonContainer.key() +".rpcHitTime";
26 ATH_CHECK(m_idKey.initialize());
27 ATH_CHECK(m_posXKey.initialize());
28 ATH_CHECK(m_posYKey.initialize());
29 ATH_CHECK(m_posZKey.initialize());
30 ATH_CHECK(m_timeKey.initialize());
31 return StatusCode::SUCCESS;
32 }
33
34 StatusCode MuonRpcTimingDecorAlg::execute(const EventContext& ctx) const {
36 if (!muons.isValid()) {
37 ATH_MSG_FATAL("Failed to load track collection "<<m_MuonContainer.fullKey());
38 return StatusCode::FAILURE;
39 }
40 Decorator dec_pos_x{m_posXKey, ctx};
41 Decorator dec_pos_y{m_posYKey, ctx};
42 Decorator dec_pos_z{m_posZKey, ctx};
43 Decorator dec_time{m_timeKey, ctx};
44 UintDecorator dec_id{m_idKey,ctx};
45
46 for (const xAOD::Muon* mu : *muons) {
47 const xAOD::TrackParticle* tp = mu->primaryTrackParticle();
48 std::vector<RpcInfo> timing_info{};
49 getRpcTiming(tp != mu->trackParticle(xAOD::Muon::InnerDetectorTrackParticle)? tp : nullptr, timing_info);
50 insert<float>(timing_info, mu, dec_pos_x, [](const RpcInfo& info){ return info.pos[Amg::x]; });
51 insert<float>(timing_info, mu, dec_pos_y, [](const RpcInfo& info){ return info.pos[Amg::y]; });
52 insert<float>(timing_info, mu, dec_pos_z, [](const RpcInfo& info){ return info.pos[Amg::z]; });
53 insert<float>(timing_info, mu, dec_time, [](const RpcInfo& info){ return info.time; });
54 insert<unsigned int>(timing_info, mu, dec_id, [](const RpcInfo& info){ return info.id; });
55 }
56 return StatusCode::SUCCESS;
57}
58void MuonRpcTimingDecorAlg::getRpcTiming(const xAOD::TrackParticle* tp, std::vector<RpcInfo>& info) const{
59 if (!tp || !tp->track() || !tp->track()->trackStateOnSurfaces()) return;
60
61 const Trk::TrackStates& states = *(tp->track()->trackStateOnSurfaces());
62 info.reserve(states.size());
63 for (const Trk::TrackStateOnSurface* tsos : states) {
64 // require measurement and track parameters
65 const Trk::MeasurementBase* meas = tsos->measurementOnTrack();
66 const Trk::TrackParameters* pars = tsos->trackParameters();
67 if (!meas || !pars) continue;
68
70 Identifier mid = m_edmHelperSvc->getIdentifier(*meas);
71 if (!m_idHelperSvc->isMuon(mid) || !m_idHelperSvc->isRpc(mid)) continue;
72 auto addHit = [&info](const Trk::MeasurementBase& meas) {
73 const Muon::RpcClusterOnTrack* rot = dynamic_cast<const Muon::RpcClusterOnTrack*>(&meas);
74 if (!rot) return;
75 info.emplace_back(rot->globalPosition(), rot->time(), rot->identify().get_identifier32().get_compact());
76 };
77 const Muon::CompetingMuonClustersOnTrack* crot = dynamic_cast<const Muon::CompetingMuonClustersOnTrack*>(meas);
78 if (crot) {
79 for (unsigned int i = 0; i < crot->numberOfContainedROTs(); ++i) { addHit(crot->rioOnTrack(i)); }
80 } else {
81 addHit(*meas);
82 }
83 }
84}
85template <typename T> void MuonRpcTimingDecorAlg::insert(const std::vector<RpcInfo>& info,
86 const xAOD::Muon* muon,
87 SG::WriteDecorHandle<xAOD::MuonContainer,std::vector<T>>& decor,
88 std::function<T(const RpcInfo&)> func) const {
89 std::vector<T> data;
90 data.reserve(info.size());
91 std::for_each(info.begin(),info.end(),[&](const RpcInfo& rpc){data.emplace_back(func(rpc));});
92 decor(*muon) = std::move(data);
93}
94
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_FATAL(x)
char data[hepevt_bytes_allocation_ATLAS]
Definition HepEvt.cxx:11
Handle class for reading from StoreGate.
An algorithm that can be simultaneously executed in multiple threads.
value_type get_compact() const
Get the compact id.
Identifier32 get_identifier32() const
Get the 32-bit version Identifier, will be invalid if >32 bits needed.
SG::WriteDecorHandleKey< xAOD::MuonContainer > m_timeKey
ServiceHandle< Muon::IMuonIdHelperSvc > m_idHelperSvc
SG::WriteDecorHandleKey< xAOD::MuonContainer > m_idKey
MuonRpcTimingDecorAlg(const std::string &name, ISvcLocator *pSvcLocator)
ServiceHandle< Muon::IMuonEDMHelperSvc > m_edmHelperSvc
SG::ReadHandleKey< xAOD::MuonContainer > m_MuonContainer
virtual StatusCode initialize() override
SG::WriteDecorHandleKey< xAOD::MuonContainer > m_posZKey
void getRpcTiming(const xAOD::TrackParticle *tp, std::vector< RpcInfo > &info) const
SG::WriteDecorHandleKey< xAOD::MuonContainer > m_posXKey
void insert(const std::vector< RpcInfo > &info, const xAOD::Muon *muon, SG::WriteDecorHandle< xAOD::MuonContainer, std::vector< T > > &decor, std::function< T(const RpcInfo &)>func) const
SG::WriteDecorHandleKey< xAOD::MuonContainer > m_posYKey
virtual StatusCode execute(const EventContext &ctx) const override
Class for competing MuonClusters, it extends the Trk::CompetingRIOsOnTrack base class.
unsigned int numberOfContainedROTs() const
Number of RIO_OnTracks to be contained by this CompetingRIOsOnTrack.
const MuonClusterOnTrack & rioOnTrack(unsigned int) const
returns the RIO_OnTrack (also known as ROT) objects depending on the integer
virtual const Amg::Vector3D & globalPosition() const override
Returns global position.
Class to represent calibrated clusters formed from RPC strips.
float time() const
Return the time (ns)
virtual bool isValid() override final
Can the handle be successfully dereferenced?
Handle class for adding a decoration to an object.
This class is the pure abstract base class for all fittable tracking measurements.
Identifier identify() const
return the identifier -extends MeasurementBase
represents the track state (measurement, material, fit parameters and quality) at a surface.
DataVector< const Trk::TrackStateOnSurface > TrackStates
ParametersBase< TrackParametersDim, Charged > TrackParameters
TrackParticle_v1 TrackParticle
Reference the current persistent version:
Muon_v1 Muon
Reference the current persistent version:
MuonContainer_v1 MuonContainer
Definition of the current "Muon container version".