ATLAS Offline Software
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 
6 #include "StoreGate/ReadHandle.h"
12 namespace{
15 }
16 MuonRpcTimingDecorAlg::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 }
58 void 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 }
85 template <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 
grepfile.info
info
Definition: grepfile.py:38
make_hlt_rep.pars
pars
Definition: make_hlt_rep.py:90
xAOD::muon
@ muon
Definition: TrackingPrimitives.h:195
data
char data[hepevt_bytes_allocation_ATLAS]
Definition: HepEvt.cxx:11
EnergyLoss.h
ScatteringAngles.h
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
Muon::MuonClusterOnTrack::globalPosition
virtual const Amg::Vector3D & globalPosition() const override
Returns global position.
Definition: MuonClusterOnTrack.cxx:93
MuonRpcTimingDecorAlg::execute
virtual StatusCode execute(const EventContext &ctx) const override
Definition: MuonRpcTimingDecorAlg.cxx:34
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
Amg::y
@ y
Definition: GeoPrimitives.h:35
CompetingMuonClustersOnTrack.h
Identifier::get_identifier32
Identifier32 get_identifier32() const
Get the 32-bit version Identifier, will be invalid if >32 bits needed.
MuonRpcTimingDecorAlg::RpcInfo
Definition: MuonRpcTimingDecorAlg.h:41
ParticleTest.tp
tp
Definition: ParticleTest.py:25
MuonRpcTimingDecorAlg.h
MuonRpcTimingDecorAlg::m_posZKey
SG::WriteDecorHandleKey< xAOD::MuonContainer > m_posZKey
Definition: MuonRpcTimingDecorAlg.h:38
Muon::RpcClusterOnTrack
Class to represent calibrated clusters formed from RPC strips.
Definition: RpcClusterOnTrack.h:35
MuonRpcTimingDecorAlg::m_edmHelperSvc
ServiceHandle< Muon::IMuonEDMHelperSvc > m_edmHelperSvc
Definition: MuonRpcTimingDecorAlg.h:30
Muon::CompetingMuonClustersOnTrack
Definition: CompetingMuonClustersOnTrack.h:54
Identifier32::get_compact
value_type get_compact() const
Get the compact id.
Definition: Identifier32.h:44
xAOD::Muon_v1
Class describing a Muon.
Definition: Muon_v1.h:38
AthReentrantAlgorithm
An algorithm that can be simultaneously executed in multiple threads.
Definition: AthReentrantAlgorithm.h:83
MuonRpcTimingDecorAlg::MuonRpcTimingDecorAlg
MuonRpcTimingDecorAlg(const std::string &name, ISvcLocator *pSvcLocator)
Definition: MuonRpcTimingDecorAlg.cxx:16
MaterialEffectsOnTrack.h
Amg::z
@ z
Definition: GeoPrimitives.h:36
RpcClusterOnTrack.h
lumiFormat.i
int i
Definition: lumiFormat.py:85
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
Amg::x
@ x
Definition: GeoPrimitives.h:34
urldecode::states
states
Definition: urldecode.h:39
SG::WriteDecorHandle
Handle class for adding a decoration to an object.
Definition: StoreGate/StoreGate/WriteDecorHandle.h:100
MuonRpcTimingDecorAlg::getRpcTiming
void getRpcTiming(const xAOD::TrackParticle *tp, std::vector< RpcInfo > &info) const
Definition: MuonRpcTimingDecorAlg.cxx:58
MuonRpcTimingDecorAlg::initialize
virtual StatusCode initialize() override
Definition: MuonRpcTimingDecorAlg.cxx:19
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
Trk::ParametersBase
Definition: ParametersBase.h:55
DataVector< const Trk::TrackStateOnSurface >
MuonRpcTimingDecorAlg::insert
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
Definition: MuonRpcTimingDecorAlg.cxx:85
Trk::MeasurementBase
Definition: MeasurementBase.h:58
Muon::CompetingMuonClustersOnTrack::numberOfContainedROTs
unsigned int numberOfContainedROTs() const
Number of RIO_OnTracks to be contained by this CompetingRIOsOnTrack.
Definition: CompetingMuonClustersOnTrack.h:178
Trk::TrackStateOnSurface
represents the track state (measurement, material, fit parameters and quality) at a surface.
Definition: TrackStateOnSurface.h:71
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
Muon::RpcClusterOnTrack::time
float time() const
Return the time (ns)
Definition: RpcClusterOnTrack.h:159
MuonRpcTimingDecorAlg::m_MuonContainer
SG::ReadHandleKey< xAOD::MuonContainer > m_MuonContainer
Definition: MuonRpcTimingDecorAlg.h:33
Muon::CompetingMuonClustersOnTrack::rioOnTrack
const MuonClusterOnTrack & rioOnTrack(unsigned int) const
returns the RIO_OnTrack (also known as ROT) objects depending on the integer
Definition: CompetingMuonClustersOnTrack.h:190
Trk::RIO_OnTrack::identify
Identifier identify() const
return the identifier -extends MeasurementBase
Definition: RIO_OnTrack.h:152
MuonRpcTimingDecorAlg::m_timeKey
SG::WriteDecorHandleKey< xAOD::MuonContainer > m_timeKey
Definition: MuonRpcTimingDecorAlg.h:39
xAOD::TrackParticle_v1
Class describing a TrackParticle.
Definition: TrackParticle_v1.h:43
MuonRpcTimingDecorAlg::m_idKey
SG::WriteDecorHandleKey< xAOD::MuonContainer > m_idKey
Definition: MuonRpcTimingDecorAlg.h:35
ReadHandle.h
Handle class for reading from StoreGate.
MuonRpcTimingDecorAlg::m_posYKey
SG::WriteDecorHandleKey< xAOD::MuonContainer > m_posYKey
Definition: MuonRpcTimingDecorAlg.h:37
CaloNoise_fillDB.mu
mu
Definition: CaloNoise_fillDB.py:53
MuonRpcTimingDecorAlg::m_idHelperSvc
ServiceHandle< Muon::IMuonIdHelperSvc > m_idHelperSvc
Definition: MuonRpcTimingDecorAlg.h:29
MuonRpcTimingDecorAlg::m_posXKey
SG::WriteDecorHandleKey< xAOD::MuonContainer > m_posXKey
Definition: MuonRpcTimingDecorAlg.h:36
TSU::T
unsigned long long T
Definition: L1TopoDataTypes.h:35
Identifier
Definition: IdentifierFieldParser.cxx:14