ATLAS Offline Software
Loading...
Searching...
No Matches
RpcDataPreparator.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4
5#include "RpcDataPreparator.h"
6#include "RpcData.h"
7#include "RecMuonRoIUtils.h"
8
11#include "CxxUtils/phihelper.h"
12
13// --------------------------------------------------------------------------------
14// --------------------------------------------------------------------------------
15
17 const std::string& name,
18 const IInterface* parent):
19 AthAlgTool(type,name,parent) {
20}
21
22// --------------------------------------------------------------------------------
23// --------------------------------------------------------------------------------
24
26{
27
28 // Locate RegionSelector
29 ATH_CHECK( m_regionSelector.retrieve() );
30
31 ATH_CHECK( m_recRPCRoiTool.retrieve() );
32
33 ATH_CHECK(m_idHelperSvc.retrieve());
34 ATH_MSG_DEBUG("Retrieved " << m_idHelperSvc);
35
36 ATH_CHECK(m_rpcPrepContainerKey.initialize());
37
39 ATH_MSG_DEBUG("Retrieved service " << m_clusterPreparator);
40
41 return StatusCode::SUCCESS;
42}
43
44// --------------------------------------------------------------------------------
45// --------------------------------------------------------------------------------
46
48{
49 m_use_RoIBasedDataAccess = use_RoIBasedDataAccess;
50}
51
52// --------------------------------------------------------------------------------
53// --------------------------------------------------------------------------------
54
55StatusCode TrigL2MuonSA::RpcDataPreparator::prepareData(const EventContext& ctx,
56 const TrigRoiDescriptor* p_roids,
57 TrigL2MuonSA::RpcHits& rpcHits,
58 TrigL2MuonSA::RpcLayerHits& rpcLayerHits,
59 const ToolHandle<RpcPatFinder>* rpcPatFinder,
60 const bool dynamicDeltaRpc) const
61{
62 // RPC data extraction referring TrigMuonEFStandaloneTrackTool and MuonHoughPatternFinderTool
63 rpcHits.clear();
64
65 if( m_emulateNoRpcHit ) return StatusCode::SUCCESS;
66
67 std::vector<const Muon::RpcPrepDataCollection*> rpcCols;
68 std::vector<IdentifierHash> rpcHashList;
69
71
72 ATH_MSG_DEBUG("Use RoI based data access");
73
74 if (p_roids) m_regionSelector->lookup(ctx)->HashIDList(*p_roids, rpcHashList);
75 else {
76 TrigRoiDescriptor fullscan_roi( true );
77 m_regionSelector->lookup(ctx)->HashIDList(fullscan_roi, rpcHashList);
78 }
79 ATH_MSG_DEBUG("rpcHashList.size()=" << rpcHashList.size());
80
81 } else {
82
83 ATH_MSG_DEBUG("Use full data access");
84
85 TrigRoiDescriptor fullscan_roi( true );
86 m_regionSelector->lookup(ctx)->HashIDList(fullscan_roi, rpcHashList);
87 ATH_MSG_DEBUG("rpcHashList.size()=" << rpcHashList.size());
88 }
89
90 if (!rpcHashList.empty()) {
91
92 // Get RPC container
93 auto rpcPrepContainerHandle = SG::makeHandle(m_rpcPrepContainerKey, ctx);
94 const Muon::RpcPrepDataContainer* rpcPrds = rpcPrepContainerHandle.cptr();
95
96 if (!rpcPrepContainerHandle.isValid()) {
97 ATH_MSG_ERROR("Cannot retrieve RPC PRD Container key: " << m_rpcPrepContainerKey.key());
98 return StatusCode::FAILURE;
99 } else {
100 ATH_MSG_DEBUG("RPC PRD Container retrieved with key: " << m_rpcPrepContainerKey.key());
101 }
102
103 // Get RPC collections
104 for(const IdentifierHash& id : rpcHashList) {
105 auto RPCcoll = rpcPrds->indexFindPtr(id);
106
107 if( RPCcoll == nullptr ) {
108 continue;
109 }
110
111 if( RPCcoll->size() == 0) {
112 ATH_MSG_DEBUG("Empty RPC list");
113 continue;
114 }
115
116 rpcCols.push_back(RPCcoll);
117 }
118 }
119
120 for( const Muon::RpcPrepDataCollection* rpc : rpcCols ){
121
122 rpcHits.reserve( rpcHits.size() + rpc->size() );
123 for( const Muon::RpcPrepData* prd : *rpc ) {
124
125 const Identifier id = prd->identify();
126
127 const int doubletR = m_idHelperSvc->rpcIdHelper().doubletR(id);
128 const int doubletPhi = m_idHelperSvc->rpcIdHelper().doubletPhi(id);
129 const int doubletZ = m_idHelperSvc->rpcIdHelper().doubletZ(id);
130 const int gasGap = m_idHelperSvc->rpcIdHelper().gasGap(id);
131 const bool measuresPhi = m_idHelperSvc->rpcIdHelper().measuresPhi(id);
132 const int stationEta = m_idHelperSvc->rpcIdHelper().stationEta(id);
133 std::string stationName = m_idHelperSvc->rpcIdHelper().stationNameString(m_idHelperSvc->rpcIdHelper().stationName(id));
134
135 int layer = 0;
136 // BO
137 if (stationName.substr(0,2)=="BO") layer = 4;
138 // doubletR
139 layer += 2*(doubletR-1);
140 // BML7 special chamber with 1 RPC doublet (doubletR=1 but RPC2) :
141 if (stationName.substr(0,3)=="BML"&&stationEta==7) layer+=2;
142 // gasGap
143 layer += gasGap - 1;
144
145 const Amg::Vector3D globalpos = prd->globalPosition();
146 const double hitx=globalpos.x();
147 const double hity=globalpos.y();
148 const double hitz=globalpos.z();
149
150 const double hittime = prd->time();
151 const MuonGM::RpcReadoutElement* detEl = prd->detectorElement();
152 const double distToPhiReadout = detEl->distanceToPhiReadout(globalpos);
153 const double distToEtaReadout = detEl->distanceToEtaReadout(globalpos);
154
155 ATH_MSG_DEBUG("Selected Rpc Collection: station name:" << stationName
156 << " global positions x/y/z=" << hitx << "/" << hity << "/" << hitz
157 << " doubletR: " << doubletR << " doubletZ: " << doubletZ << " doubletPhi " << doubletPhi
158 << " gasGap " << gasGap << " layer " << layer << " time " << hittime
159 << " distToEtaReadout " << distToEtaReadout << " distToPhiReadout " << distToPhiReadout);
160
162
163 lutDigit.x = hitx;
164 lutDigit.y = hity;
165 lutDigit.z = hitz;
166 lutDigit.time = hittime;
167 lutDigit.distToEtaReadout = distToEtaReadout;
168 lutDigit.distToPhiReadout = distToPhiReadout;
169 lutDigit.gasGap = gasGap;
170 lutDigit.doubletR = doubletR;
171 lutDigit.doubletPhi = doubletPhi;
172 lutDigit.doubletZ = doubletZ;
173 lutDigit.measuresPhi = measuresPhi;
174 lutDigit.stationName = stationName;
175 lutDigit.layer = layer;
176
177 const float r2 = hitx*hitx+hity*hity;
178 float phi = std::atan2(hity,hitx);
179 const float l = std::sqrt(hitz*hitz+r2);
180 const float tan = std::sqrt( (l-hitz)/(l+hitz) );
181 const float eta = -std::log(tan);
182 const float deta = std::abs(p_roids->eta() - eta);
183 const float dphi = std::abs(CxxUtils::wrapToPi(p_roids->phi() - phi));
184
185 lutDigit.eta = eta;
186 lutDigit.phi = phi;
187 lutDigit.l = l;
188 rpcHits.push_back(lutDigit);
189
190 float deta_thr = 0.1;
191 float dphi_thr = 0.1;
192 float dynamic_add = 0.02;
193
194 //Determine deta, dphi threshold in case of dynamicDeltaRpcMode
195 if( dynamicDeltaRpc ){
196 ATH_MSG_DEBUG("Collected RPC hits by MultiMuonTriggerMode");
197 double RoiPhiMin(0);
198 double RoiPhiMax(0);
199 double RoiEtaMin(0);
200 double RoiEtaMax(0);
201 ATH_CHECK( m_recRPCRoiTool->RoIsize(p_roids->roiWord(), RoiEtaMin, RoiEtaMax, RoiPhiMin, RoiPhiMax) );
202 ATH_MSG_DEBUG( "RoI Phi min = " << RoiPhiMin << " RoI Phi max = " << RoiPhiMax << " RoI Eta min = " << RoiEtaMin << " RoI Eta max = " << RoiEtaMax );
203 deta_thr = std::abs( RoiEtaMax - RoiEtaMin )/2. + dynamic_add;
204 dphi_thr = std::abs( std::acos( std::cos( RoiPhiMax - RoiPhiMin ) ) )/2. + dynamic_add;
205 ATH_MSG_DEBUG( "deta threshold = " << deta_thr);
206 ATH_MSG_DEBUG( "dphi threshold = " << dphi_thr);
207 }
208
210 if ( deta<deta_thr && dphi<dphi_thr)
211 (*rpcPatFinder)->addHit(stationName, stationEta, measuresPhi, gasGap, doubletR, hitx, hity, hitz, rpcLayerHits);
212 } else {
213 if ( deta<0.15 && dphi<0.1)
214 (*rpcPatFinder)->addHit(stationName, stationEta, measuresPhi, gasGap, doubletR, hitx, hity, hitz, rpcLayerHits);
215 }
216 }
217 }
218
219 return StatusCode::SUCCESS;
220}
221
222// --------------------------------------------------------------------------------
223// --------------------------------------------------------------------------------
224
225StatusCode TrigL2MuonSA::RpcDataPreparator::prepareData(const EventContext& ctx,
226 const TrigRoiDescriptor* p_roids,
227 TrigL2MuonSA::RpcLayerClusters& rpcLayerClusters,
228 const ToolHandle<ClusterPatFinder>* clusterPatFinder,
229 const bool dynamicDeltaRpc) const
230{
231 // RPC data extraction referring TrigMuonEFStandaloneTrackTool and MuonHoughPatternFinderTool
232
234 return StatusCode::SUCCESS;
235
236 std::vector<const Muon::RpcPrepDataCollection*> rpcCols;
237 std::vector<IdentifierHash> rpcHashList;
238 std::vector<IdentifierHash> rpcHashList_cache;
239
241
242 ATH_MSG_DEBUG("Use RoI based data access");
243
244 if (p_roids) m_regionSelector->lookup(ctx)->HashIDList(*p_roids, rpcHashList);
245 else {
246 TrigRoiDescriptor fullscan_roi( true );
247 m_regionSelector->lookup(ctx)->HashIDList(fullscan_roi, rpcHashList);
248 }
249 ATH_MSG_DEBUG("rpcHashList.size()=" << rpcHashList.size());
250
251 } else {
252
253 ATH_MSG_DEBUG("Use full data access");
254
255 TrigRoiDescriptor fullscan_roi( true );
256 m_regionSelector->lookup(ctx)->HashIDList(fullscan_roi, rpcHashList);
257 ATH_MSG_DEBUG("rpcHashList.size()=" << rpcHashList.size());
258
259 }
260
261 if (!rpcHashList.empty()) {
262
263 // Get RPC container
264 const Muon::RpcPrepDataContainer* rpcPrds;
265 auto rpcPrepContainerHandle = SG::makeHandle(m_rpcPrepContainerKey, ctx);
266 rpcPrds = rpcPrepContainerHandle.cptr();
267 if (!rpcPrepContainerHandle.isValid()) {
268 ATH_MSG_ERROR("Cannot retrieve RPC PRD Container key: " << m_rpcPrepContainerKey.key());
269 return StatusCode::FAILURE;
270 } else {
271 ATH_MSG_DEBUG("RPC PRD Container retrieved with key: " << m_rpcPrepContainerKey.key());
272 }
273
274 // Get RPC collections
275 for(const IdentifierHash& id : rpcHashList) {
276
277 auto RPCcoll = rpcPrds->indexFindPtr(id);
278
279 if( RPCcoll == nullptr ) {
280 continue;
281 }
282
283 if( RPCcoll->size() == 0) {
284 ATH_MSG_DEBUG("Empty RPC list");
285 continue;
286 }
287
288 rpcHashList_cache.push_back(id);
289 rpcCols.push_back(RPCcoll);
290 }
291 }
292 ATH_MSG_DEBUG("Do rpc clustering");
293 ATH_CHECK( m_clusterPreparator->clusteringRPCs(dynamicDeltaRpc, rpcCols, p_roids, clusterPatFinder, rpcLayerClusters) );
294
295 return StatusCode::SUCCESS;
296}
297
Scalar eta() const
pseudorapidity method
Scalar phi() const
phi method
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_DEBUG(x)
AthAlgTool(const std::string &type, const std::string &name, const IInterface *parent)
Constructor with parameters:
virtual const T * indexFindPtr(IdentifierHash hashId) const override final
return pointer on the found entry or null if out of range using hashed index - fast version,...
This is a "hash" representation of an Identifier.
An RpcReadoutElement corresponds to a single RPC module; therefore typicaly a barrel muon station con...
Class to represent RPC measurements.
Definition RpcPrepData.h:35
virtual double phi() const override final
Methods to retrieve data members.
virtual double eta() const override final
ToolHandle< RpcClusterPreparator > m_clusterPreparator
StatusCode prepareData(const EventContext &ctx, const TrigRoiDescriptor *p_roids, TrigL2MuonSA::RpcHits &rpcHits, TrigL2MuonSA::RpcLayerHits &rpcLayerHits, const ToolHandle< RpcPatFinder > *rpcPatFinder, const bool dynamicDeltaRpc) const
ToolHandle< LVL1::ITrigT1MuonRecRoiTool > m_recRPCRoiTool
void setRoIBasedDataAccess(bool use_RoIBasedDataAccess)
RpcDataPreparator(const std::string &type, const std::string &name, const IInterface *parent)
ServiceHandle< Muon::IMuonIdHelperSvc > m_idHelperSvc
Gaudi::Property< bool > m_emulateNoRpcHit
ToolHandle< IRegSelTool > m_regionSelector
virtual StatusCode initialize() override
SG::ReadHandleKey< Muon::RpcPrepDataContainer > m_rpcPrepContainerKey
std::string stationName
Definition RpcData.h:51
nope - should be used for standalone also, perhaps need to protect the class def bits ifndef XAOD_ANA...
virtual unsigned int roiWord() const override final
Eigen::Matrix< double, 3, 1 > Vector3D
T wrapToPi(T phi)
Wrap angle in radians to [-pi, pi].
Definition phihelper.h:24
MuonPrepDataContainerT< RpcPrepData > RpcPrepDataContainer
MuonPrepDataCollection< RpcPrepData > RpcPrepDataCollection
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())
std::vector< RpcHitData > RpcHits
Definition RpcData.h:57
Helper for azimuthal angle calculations.