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