ATLAS Offline Software
RpcDataPreparator.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2021 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  TrigL2MuonSA::RpcHits& rpcHits,
57  TrigL2MuonSA::RpcLayerHits& rpcLayerHits,
58  const ToolHandle<RpcPatFinder>* rpcPatFinder,
59  const bool dynamicDeltaRpc) const
60 {
61  // RPC data extraction referring TrigMuonEFStandaloneTrackTool and MuonHoughPatternFinderTool
62  rpcHits.clear();
63 
64  if( m_emulateNoRpcHit ) return StatusCode::SUCCESS;
65 
66  std::vector<const Muon::RpcPrepDataCollection*> rpcCols;
67  std::vector<IdentifierHash> rpcHashList;
68 
69  if (m_use_RoIBasedDataAccess) {
70 
71  ATH_MSG_DEBUG("Use RoI based data access");
72 
73  if (p_roids) m_regionSelector->lookup( Gaudi::Hive::currentContext() )->HashIDList(*p_roids, rpcHashList);
74  else {
75  TrigRoiDescriptor fullscan_roi( true );
76  m_regionSelector->lookup( Gaudi::Hive::currentContext() )->HashIDList(fullscan_roi, rpcHashList);
77  }
78  ATH_MSG_DEBUG("rpcHashList.size()=" << rpcHashList.size());
79 
80  } else {
81 
82  ATH_MSG_DEBUG("Use full data access");
83 
84  TrigRoiDescriptor fullscan_roi( true );
85  m_regionSelector->lookup( Gaudi::Hive::currentContext() )->HashIDList(fullscan_roi, rpcHashList);
86  ATH_MSG_DEBUG("rpcHashList.size()=" << rpcHashList.size());
87  }
88 
89  if (!rpcHashList.empty()) {
90 
91  // Get RPC container
92  auto rpcPrepContainerHandle = SG::makeHandle(m_rpcPrepContainerKey);
93  const Muon::RpcPrepDataContainer* rpcPrds = rpcPrepContainerHandle.cptr();
94 
95  if (!rpcPrepContainerHandle.isValid()) {
96  ATH_MSG_ERROR("Cannot retrieve RPC PRD Container key: " << m_rpcPrepContainerKey.key());
97  return StatusCode::FAILURE;
98  } else {
99  ATH_MSG_DEBUG("RPC PRD Container retrieved with key: " << m_rpcPrepContainerKey.key());
100  }
101 
102  // Get RPC collections
103  for(const IdentifierHash& id : rpcHashList) {
104  auto RPCcoll = rpcPrds->indexFindPtr(id);
105 
106  if( RPCcoll == nullptr ) {
107  continue;
108  }
109 
110  if( RPCcoll->size() == 0) {
111  ATH_MSG_DEBUG("Empty RPC list");
112  continue;
113  }
114 
115  rpcCols.push_back(RPCcoll);
116  }
117  }
118 
119  for( const Muon::RpcPrepDataCollection* rpc : rpcCols ){
120 
121  rpcHits.reserve( rpcHits.size() + rpc->size() );
122  for( const Muon::RpcPrepData* prd : *rpc ) {
123 
124  const Identifier id = prd->identify();
125 
126  const int doubletR = m_idHelperSvc->rpcIdHelper().doubletR(id);
127  const int doubletPhi = m_idHelperSvc->rpcIdHelper().doubletPhi(id);
128  const int doubletZ = m_idHelperSvc->rpcIdHelper().doubletZ(id);
129  const int gasGap = m_idHelperSvc->rpcIdHelper().gasGap(id);
130  const bool measuresPhi = m_idHelperSvc->rpcIdHelper().measuresPhi(id);
131  const int stationEta = m_idHelperSvc->rpcIdHelper().stationEta(id);
132  std::string stationName = m_idHelperSvc->rpcIdHelper().stationNameString(m_idHelperSvc->rpcIdHelper().stationName(id));
133 
134  int layer = 0;
135  // BO
136  if (stationName.substr(0,2)=="BO") layer = 4;
137  // doubletR
138  layer += 2*(doubletR-1);
139  // BML7 special chamber with 1 RPC doublet (doubletR=1 but RPC2) :
140  if (stationName.substr(0,3)=="BML"&&stationEta==7) layer+=2;
141  // gasGap
142  layer += gasGap - 1;
143 
144  const Amg::Vector3D globalpos = prd->globalPosition();
145  const double hitx=globalpos.x();
146  const double hity=globalpos.y();
147  const double hitz=globalpos.z();
148 
149  const double hittime = prd->time();
150  const MuonGM::RpcReadoutElement* detEl = prd->detectorElement();
151  const double distToPhiReadout = detEl->distanceToPhiReadout(globalpos);
152  const double distToEtaReadout = detEl->distanceToEtaReadout(globalpos);
153 
154  ATH_MSG_DEBUG("Selected Rpc Collection: station name:" << stationName
155  << " global positions x/y/z=" << hitx << "/" << hity << "/" << hitz
156  << " doubletR: " << doubletR << " doubletZ: " << doubletZ << " doubletPhi " << doubletPhi
157  << " gasGap " << gasGap << " layer " << layer << " time " << hittime
158  << " distToEtaReadout " << distToEtaReadout << " distToPhiReadout " << distToPhiReadout);
159 
160  TrigL2MuonSA::RpcHitData lutDigit;
161 
162  lutDigit.x = hitx;
163  lutDigit.y = hity;
164  lutDigit.z = hitz;
165  lutDigit.time = hittime;
166  lutDigit.distToEtaReadout = distToEtaReadout;
167  lutDigit.distToPhiReadout = distToPhiReadout;
168  lutDigit.gasGap = gasGap;
169  lutDigit.doubletR = doubletR;
170  lutDigit.doubletPhi = doubletPhi;
171  lutDigit.doubletZ = doubletZ;
172  lutDigit.measuresPhi = measuresPhi;
173  lutDigit.stationName = stationName;
174  lutDigit.layer = layer;
175 
176  const float r2 = hitx*hitx+hity*hity;
177  float phi = std::atan2(hity,hitx);
178  const float l = std::sqrt(hitz*hitz+r2);
179  const float tan = std::sqrt( (l-hitz)/(l+hitz) );
180  const float eta = -std::log(tan);
181  const float deta = std::abs(p_roids->eta() - eta);
182  const float dphi = std::abs(CxxUtils::wrapToPi(p_roids->phi() - phi));
183 
184  lutDigit.eta = eta;
185  lutDigit.phi = phi;
186  lutDigit.l = l;
187  rpcHits.push_back(lutDigit);
188 
189  float deta_thr = 0.1;
190  float dphi_thr = 0.1;
191  float dynamic_add = 0.02;
192 
193  //Determine deta, dphi threshold in case of dynamicDeltaRpcMode
194  if( dynamicDeltaRpc ){
195  ATH_MSG_DEBUG("Collected RPC hits by MultiMuonTriggerMode");
196  double RoiPhiMin(0);
197  double RoiPhiMax(0);
198  double RoiEtaMin(0);
199  double RoiEtaMax(0);
200  ATH_CHECK( m_recRPCRoiTool->RoIsize(p_roids->roiWord(), RoiEtaMin, RoiEtaMax, RoiPhiMin, RoiPhiMax) );
201  ATH_MSG_DEBUG( "RoI Phi min = " << RoiPhiMin << " RoI Phi max = " << RoiPhiMax << " RoI Eta min = " << RoiEtaMin << " RoI Eta max = " << RoiEtaMax );
202  deta_thr = std::abs( RoiEtaMax - RoiEtaMin )/2. + dynamic_add;
203  dphi_thr = std::abs( std::acos( std::cos( RoiPhiMax - RoiPhiMin ) ) )/2. + dynamic_add;
204  ATH_MSG_DEBUG( "deta threshold = " << deta_thr);
205  ATH_MSG_DEBUG( "dphi threshold = " << dphi_thr);
206  }
207 
208  if (m_use_RoIBasedDataAccess) {
209  if ( deta<deta_thr && dphi<dphi_thr)
210  (*rpcPatFinder)->addHit(stationName, stationEta, measuresPhi, gasGap, doubletR, hitx, hity, hitz, rpcLayerHits);
211  } else {
212  if ( deta<0.15 && dphi<0.1)
213  (*rpcPatFinder)->addHit(stationName, stationEta, measuresPhi, gasGap, doubletR, hitx, hity, hitz, rpcLayerHits);
214  }
215  }
216  }
217 
218  return StatusCode::SUCCESS;
219 }
220 
221 // --------------------------------------------------------------------------------
222 // --------------------------------------------------------------------------------
223 
225  TrigL2MuonSA::RpcLayerClusters& rpcLayerClusters,
226  const ToolHandle<ClusterPatFinder>* clusterPatFinder,
227  const bool dynamicDeltaRpc) const
228 {
229  // RPC data extraction referring TrigMuonEFStandaloneTrackTool and MuonHoughPatternFinderTool
230 
231  if( m_emulateNoRpcHit )
232  return StatusCode::SUCCESS;
233 
234  std::vector<const Muon::RpcPrepDataCollection*> rpcCols;
235  std::vector<IdentifierHash> rpcHashList;
236  std::vector<IdentifierHash> rpcHashList_cache;
237 
238  if (m_use_RoIBasedDataAccess) {
239 
240  ATH_MSG_DEBUG("Use RoI based data access");
241 
242  if (p_roids) m_regionSelector->lookup( Gaudi::Hive::currentContext() )->HashIDList(*p_roids, rpcHashList);
243  else {
244  TrigRoiDescriptor fullscan_roi( true );
245  m_regionSelector->lookup( Gaudi::Hive::currentContext() )->HashIDList(fullscan_roi, rpcHashList);
246  }
247  ATH_MSG_DEBUG("rpcHashList.size()=" << rpcHashList.size());
248 
249  } else {
250 
251  ATH_MSG_DEBUG("Use full data access");
252 
253  TrigRoiDescriptor fullscan_roi( true );
254  m_regionSelector->lookup( Gaudi::Hive::currentContext() )->HashIDList(fullscan_roi, rpcHashList);
255  ATH_MSG_DEBUG("rpcHashList.size()=" << rpcHashList.size());
256 
257  }
258 
259  if (!rpcHashList.empty()) {
260 
261  // Get RPC container
262  const Muon::RpcPrepDataContainer* rpcPrds;
263  auto rpcPrepContainerHandle = SG::makeHandle(m_rpcPrepContainerKey);
264  rpcPrds = rpcPrepContainerHandle.cptr();
265  if (!rpcPrepContainerHandle.isValid()) {
266  ATH_MSG_ERROR("Cannot retrieve RPC PRD Container key: " << m_rpcPrepContainerKey.key());
267  return StatusCode::FAILURE;
268  } else {
269  ATH_MSG_DEBUG("RPC PRD Container retrieved with key: " << m_rpcPrepContainerKey.key());
270  }
271 
272  // Get RPC collections
273  for(const IdentifierHash& id : rpcHashList) {
274 
275  auto RPCcoll = rpcPrds->indexFindPtr(id);
276 
277  if( RPCcoll == nullptr ) {
278  continue;
279  }
280 
281  if( RPCcoll->size() == 0) {
282  ATH_MSG_DEBUG("Empty RPC list");
283  continue;
284  }
285 
286  rpcHashList_cache.push_back(id);
287  rpcCols.push_back(RPCcoll);
288  }
289  }
290  ATH_MSG_DEBUG("Do rpc clustering");
291  ATH_CHECK( m_clusterPreparator->clusteringRPCs(dynamicDeltaRpc, rpcCols, p_roids, clusterPatFinder, rpcLayerClusters) );
292 
293  return StatusCode::SUCCESS;
294 }
295 
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
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
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
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
TrigL2MuonSA::RpcDataPreparator::prepareData
StatusCode prepareData(const TrigRoiDescriptor *p_roids, TrigL2MuonSA::RpcHits &rpcHits, TrigL2MuonSA::RpcLayerHits &rpcLayerHits, const ToolHandle< RpcPatFinder > *rpcPatFinder, const bool dynamicDeltaRpc) const
Definition: RpcDataPreparator.cxx:55
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