ATLAS Offline Software
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):
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 
38  ATH_CHECK(m_clusterPreparator.retrieve());
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 
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 
70  if (m_use_RoIBasedDataAccess) {
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 
161  TrigL2MuonSA::RpcHitData lutDigit;
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 
209  if (m_use_RoIBasedDataAccess) {
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 
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 
233  if( m_emulateNoRpcHit )
234  return StatusCode::SUCCESS;
235 
236  std::vector<const Muon::RpcPrepDataCollection*> rpcCols;
237  std::vector<IdentifierHash> rpcHashList;
238  std::vector<IdentifierHash> rpcHashList_cache;
239 
240  if (m_use_RoIBasedDataAccess) {
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 
TrigL2MuonSA::RpcHitData::y
double y
Definition: RpcData.h:37
TrigL2MuonSA::RpcHitData::measuresPhi
bool measuresPhi
Definition: RpcData.h:50
Muon::MuonPrepDataContainer
Template for Muon PRD containers (which are basically collections of MuonPrepDataCollections).
Definition: MuonPrepDataContainer.h:42
dumpTgcDigiDeadChambers.gasGap
list gasGap
Definition: dumpTgcDigiDeadChambers.py:33
TrigL2MuonSA::RpcDataPreparator::setRoIBasedDataAccess
void setRoIBasedDataAccess(bool use_RoIBasedDataAccess)
Definition: RpcDataPreparator.cxx:47
TrigL2MuonSA::RpcHitData::distToEtaReadout
double distToEtaReadout
Definition: RpcData.h:40
TrigL2MuonSA::RpcHitData::doubletR
int doubletR
Definition: RpcData.h:43
phi
Scalar phi() const
phi method
Definition: AmgMatrixBasePlugin.h:67
TrigL2MuonSA::RpcHits
std::vector< RpcHitData > RpcHits
Definition: RpcData.h:57
TrigL2MuonSA::RpcDataPreparator::RpcDataPreparator
RpcDataPreparator(const std::string &type, const std::string &name, const IInterface *parent)
Definition: RpcDataPreparator.cxx:16
dumpTgcDigiDeadChambers.stationName
dictionary stationName
Definition: dumpTgcDigiDeadChambers.py:30
eta
Scalar eta() const
pseudorapidity method
Definition: AmgMatrixBasePlugin.h:83
TrigL2MuonSA::RpcHitData::stationName
std::string stationName
Definition: RpcData.h:51
TrigL2MuonSA::RpcHitData::phi
double phi
Definition: RpcData.h:48
CxxUtils::wrapToPi
T wrapToPi(T phi)
Wrap angle in radians to [-pi, pi].
Definition: phihelper.h:24
createCablingJSON.doubletR
int doubletR
Definition: createCablingJSON.py:15
TrigRoiDescriptor::roiWord
virtual unsigned int roiWord() const override final
Definition: TrigRoiDescriptor.h:135
MuonGM::RpcReadoutElement
An RpcReadoutElement corresponds to a single RPC module; therefore typicaly a barrel muon station con...
Definition: MuonDetDescr/MuonReadoutGeometry/MuonReadoutGeometry/RpcReadoutElement.h:55
UploadAMITag.l
list l
Definition: UploadAMITag.larcaf.py:157
TrigRoiDescriptor
nope - should be used for standalone also, perhaps need to protect the class def bits #ifndef XAOD_AN...
Definition: TrigRoiDescriptor.h:56
drawFromPickle.cos
cos
Definition: drawFromPickle.py:36
python.CaloAddPedShiftConfig.type
type
Definition: CaloAddPedShiftConfig.py:42
TrigL2MuonSA::RpcHitData::doubletZ
int doubletZ
Definition: RpcData.h:45
RpcData.h
TrigL2MuonSA::RpcHitData::l
double l
Definition: RpcData.h:49
TrigL2MuonSA::RpcHitData::doubletPhi
int doubletPhi
Definition: RpcData.h:44
SG::makeHandle
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())
Definition: ReadCondHandle.h:274
RecMuonRoIUtils.h
TrigL2MuonSA::RpcHitData::time
double time
Definition: RpcData.h:39
TrigL2MuonSA::RpcDataPreparator::initialize
virtual StatusCode initialize() override
Definition: RpcDataPreparator.cxx:25
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
MuonGM::RpcReadoutElement::distanceToPhiReadout
double distanceToPhiReadout(const Amg::Vector3D &P) const
Definition: MuonDetDescr/MuonReadoutGeometry/src/RpcReadoutElement.cxx:223
Muon::RpcPrepData
Class to represent RPC measurements.
Definition: RpcPrepData.h:35
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
TrigL2MuonSA::RpcHitData::z
double z
Definition: RpcData.h:38
TRT::Hit::layer
@ layer
Definition: HitInfo.h:79
RpcDataPreparator.h
test_pyathena.parent
parent
Definition: test_pyathena.py:15
TrigL2MuonSA::RpcLayerClusters
Definition: ClusterPatFinder.h:58
TrigL2MuonSA::RpcHitData::gasGap
int gasGap
Definition: RpcData.h:42
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
drawFromPickle.tan
tan
Definition: drawFromPickle.py:36
Muon::MuonPrepDataCollection
Template to hold collections of MuonPrepRawData objects.
Definition: MuonPrepDataCollection.h:46
TrigL2MuonSA::RpcHitData
Definition: RpcData.h:14
TrigL2MuonSA::RpcHitData::layer
int layer
Definition: RpcData.h:46
TrigL2MuonSA::RpcHitData::distToPhiReadout
double distToPhiReadout
Definition: RpcData.h:41
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:240
TrigL2MuonSA::RpcLayerHits
Definition: RpcPatFinder.h:20
phihelper.h
Helper for azimuthal angle calculations.
Amg::Vector3D
Eigen::Matrix< double, 3, 1 > Vector3D
Definition: GeoPrimitives.h:47
MuonDetectorManager.h
IdentifiableContainerMT::indexFindPtr
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,...
Definition: IdentifiableContainerMT.h:289
RoiDescriptor::phi
virtual double phi() const override final
Methods to retrieve data members.
Definition: RoiDescriptor.h:100
TrigL2MuonSA::RpcDataPreparator::prepareData
StatusCode prepareData(const EventContext &ctx, const TrigRoiDescriptor *p_roids, TrigL2MuonSA::RpcHits &rpcHits, TrigL2MuonSA::RpcLayerHits &rpcLayerHits, const ToolHandle< RpcPatFinder > *rpcPatFinder, const bool dynamicDeltaRpc) const
Definition: RpcDataPreparator.cxx:55
python.CaloCondTools.log
log
Definition: CaloCondTools.py:20
TrigL2MuonSA::RpcHitData::x
double x
Definition: RpcData.h:33
RoiDescriptor::eta
virtual double eta() const override final
Definition: RoiDescriptor.h:101
createCablingJSON.doubletPhi
int doubletPhi
Definition: createCablingJSON.py:16
MuonGM::RpcReadoutElement::distanceToEtaReadout
double distanceToEtaReadout(const Amg::Vector3D &P) const
Definition: MuonDetDescr/MuonReadoutGeometry/src/RpcReadoutElement.cxx:278
AthAlgTool
Definition: AthAlgTool.h:26
IdentifierHash
This is a "hash" representation of an Identifier. This encodes a 32 bit index which can be used to lo...
Definition: IdentifierHash.h:25
TrigL2MuonSA::RpcHitData::eta
double eta
Definition: RpcData.h:47
RpcReadoutElement.h
Identifier
Definition: IdentifierFieldParser.cxx:14