ATLAS Offline Software
RPC_RegSelCondAlg.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4 
17 #include "RPC_RegSelCondAlg.h"
18 
19 #include "GaudiKernel/EventIDRange.h"
21 #include "CLHEP/Units/SystemOfUnits.h"
27 
28 RPC_RegSelCondAlg::RPC_RegSelCondAlg(const std::string& name, ISvcLocator* pSvcLocator):
29  MuonRegSelCondAlg( name, pSvcLocator )
30 {
31  ATH_MSG_DEBUG( "RPC_RegSelCondAlg::RPC_RegSelCondAlg() " << name );
32 }
33 
37  return StatusCode::SUCCESS;
38 }
39 
40 std::unique_ptr<RegSelSiLUT> RPC_RegSelCondAlg::createTable( const EventContext& ctx, EventIDRange& id_range ) const {
41 
43 
44  if( !cablingCondData.range( id_range ) ) {
45  ATH_MSG_ERROR("Failed to retrieve validity range for " << cablingCondData.key());
46  return {nullptr};
47  }
48 
49 
50  const RpcCablingCondData* cabling{*cablingCondData};
51 
53 
54  if( !managerHandle.range( id_range ) ) {
55  ATH_MSG_ERROR("Failed to retrieve validity range for " << m_detMgrKey.key());
56  return {nullptr};
57  }
58  const MuonGM::MuonDetectorManager* manager = managerHandle.cptr();
59 
60  const RpcIdHelper* helper = manager->rpcIdHelper();
61 
62  std::vector<Identifier>::const_iterator idfirst = helper->module_begin();
63  std::vector<Identifier>::const_iterator idlast = helper->module_end();
64 
65  IdContext ModuleContext = helper->module_context();
66 
67  ATH_MSG_DEBUG("createTable()");
68 
69  std::unique_ptr<RegSelSiLUT> lut = std::make_unique<RegSelSiLUT>(RegSelSiLUT::RPC);
70 
71 
72  //loop over modules (PrepRawData collections)
73  for ( std::vector<Identifier>::const_iterator itr=idfirst ; itr!=idlast ; ++itr ) {
74 
75  Identifier prdId = *itr;
76  IdentifierHash prdHashId;
77  int gethash_code = helper->get_hash(prdId, prdHashId, &ModuleContext);
78  if (gethash_code != 0 ) {
79  ATH_MSG_DEBUG("Failed retrieving IdentifierHash for PRD Identifier = " << prdId.getString() << ". Skipping to the next PRD.");
80  continue;
81  }
82 
83  std::vector<uint32_t> robIds;
84  if ( (cabling->giveROB_fromPRD(prdHashId, robIds)).isFailure() ) {
85  ATH_MSG_ERROR( "RegSelCondAlg_RPC could not get ROBid" );
86  return {nullptr};
87  }
88 
89 
90  if (robIds.empty()) {
91  ATH_MSG_DEBUG("There is no ROB associated with the PRD HashId = " << (unsigned int)prdHashId << ". Skipping to the next PRD.");
92  continue;
93  }
94  if (robIds.size()!=1 && robIds.size()!=2 && robIds.size()!=4) {
95  ATH_MSG_WARNING("Unhandled number of ROBs per one PRD. Expected 1, 2 or 4, got " << robIds.size() << ". Omitting the PRD HashId = " << (unsigned int)prdHashId);
96  continue;
97  }
98 
99  ExpandedIdentifier exp_id;
100  if ( helper->get_expanded_id( prdId, exp_id, &ModuleContext) ) {
101  ATH_MSG_DEBUG("Failed retrieving ExpandedIdentifier for PRD Identifier = " << prdId.getString() << ". Skipping to the next PRD.");
102  continue;
103  }
104 
105  int detid = ( exp_id[2]<0 ? -1 : 1 );
106  int layerid = exp_id[1];
107  if ( layerid==0 ) layerid = 11; // this line should never be executed
108 
109  int ndbz = helper->doubletZMax(prdId);
110 
111  double zmin = 99999999;
112  double zmax = -99999999;
113  double rmin = 99999999;
114  double rmax = -99999999;
115  double phimin = 999999;
116  double phimax = -999999;
117  Amg::Vector3D Pzmin;
118  Amg::Vector3D Pzmax;
119 
120  for (int dbz=1; dbz<=ndbz; dbz++) {
121 
122  const MuonGM::RpcReadoutElement* rpcold = nullptr;
123  int ndbp = helper->doubletPhiMax(prdId);
124 
125  for (int dbp=1; dbp<=ndbp; dbp++) {
126  Identifier chid = helper->channelID(prdId, dbz, dbp, 1, 0, 1);
127 
128  const MuonGM::RpcReadoutElement* rpc = manager->getRpcReadoutElement(chid);
129 
130  if ( rpc != rpcold ) {
131 
132  // here a new module
133  rpcold = rpc;
134 
135  Amg::Vector3D rpcPos = rpc->center();
136  double zminMod = rpcPos.z()-0.5*rpc->getZsize();
137  double zmaxMod = rpcPos.z()+0.5*rpc->getZsize();
138 
139  double rcen = std::sqrt(rpcPos.mag()*rpcPos.mag()-rpcPos.z()*rpcPos.z());
140 
141  double rminMod = rcen-0.5*rpc->getRsize();
142  double rmaxMod = rcen+0.5*rpc->getRsize();
143 
144  double dphi = std::atan2(rpc->getSsize()/2,rpcPos.perp());
145  double pminMod = rpcPos.phi() - dphi;
146  double pmaxMod = rpcPos.phi() + dphi;
147 
148  if (zminMod < zmin) {
149  zmin = zminMod;
150  Pzmin = rpcPos;
151  Pzmin[2] = zmin;
152  }
153  if (zmaxMod > zmax) {
154  zmax = zmaxMod;
155  Pzmax = rpcPos;
156  Pzmax[2] = zmax;
157  }
158  if (rminMod < rmin) {
159  rmin = rminMod;
160  }
161  if (rmaxMod > rmax) {
162  rmax = rmaxMod;
163  }
164  if (pminMod < phimin) phimin = pminMod;
165  if (pmaxMod > phimax) phimax = pmaxMod;
166 
167  }
168  }
169  }
170 
171  double phiMinFirst = phimin;
172  double phiMaxFirst = 0.5*(phimin+phimax);
173  double phiMinSecond = phiMaxFirst;
174  double phiMaxSecond = phimax;
175 
176  if (phiMinFirst < 0) phiMinFirst += 2*M_PI;
177  if (phiMaxFirst < 0) phiMaxFirst += 2*M_PI;
178  if (phiMinSecond < 0) phiMinSecond += 2*M_PI;
179  if (phiMaxSecond < 0) phiMaxSecond += 2*M_PI;
180 
181 
182  if (robIds.size()==1) {
183  IdentifierHash lowerHashId( (1<<16) | (unsigned int)prdHashId );
184 
185  RegSelModule m1( zmin, zmax, rmin, rmax, phiMinFirst, phiMaxSecond, layerid, detid, robIds[0], lowerHashId );
186  lut->addModule( m1 );
187  }
188  //the code below exploits the fact that ROB Ids are sorted!!! They go in order: SIDE A, ROBs 0..15, then SIDE C ROBs 0..15
189  //it is also assumed that if there are 4 ROBs, then zmin<0 and zmax>0
190  else if (robIds.size()==2) {
191  uint32_t lowerRobId=0;
192  uint32_t higherRobId=0;
193  if ( ((robIds[0] & 0xff) == 0) && ((robIds[1] & 0xff) == 15) ) { //the two ROBs around phi=0
194  lowerRobId = robIds[1];
195  higherRobId = robIds[0];
196  }
197  else {
198  lowerRobId = robIds[0];
199  higherRobId = robIds[1];
200  }
201  IdentifierHash lowerHashId( (1<<16) | (unsigned int)prdHashId );
202  IdentifierHash higherHashId( (2<<16) | (unsigned int)prdHashId );
203 
204  RegSelModule m1( zmin, zmax, rmin, rmax, phiMinFirst, phiMaxFirst, layerid, detid, lowerRobId, lowerHashId );
205  RegSelModule m2( zmin, zmax, rmin, rmax, phiMinSecond, phiMaxSecond, layerid, detid, higherRobId, higherHashId );
206  lut->addModule( m1 );
207  lut->addModule( m2 );
208  }
209  else if (robIds.size()==4) { //this is the case only for two BOG chambers at z=0 read by ROBs 10-11 and 12-13, each on both sides A and C
210  uint32_t sideA_lowerRobId = robIds[0];
211  uint32_t sideA_higherRobId = robIds[1];
212  uint32_t sideC_lowerRobId = robIds[2];
213  uint32_t sideC_higherRobId = robIds[3];
214  IdentifierHash sideA_lowerHashId( (1<<16) | (unsigned int)prdHashId );
215  IdentifierHash sideA_higherHashId( (2<<16) | (unsigned int)prdHashId );
216  IdentifierHash sideC_lowerHashId( (3<<16) | (unsigned int)prdHashId );
217  IdentifierHash sideC_higherHashId( (4<<16) | (unsigned int)prdHashId );
218 
219  RegSelModule m1( 0, zmax, rmin, rmax, phiMinFirst, phiMaxFirst, layerid, detid, sideA_lowerRobId, sideA_lowerHashId );
220  RegSelModule m2( 0, zmax, rmin, rmax, phiMinSecond, phiMaxSecond, layerid, detid, sideA_higherRobId, sideA_higherHashId );
221  RegSelModule m3( zmin, 0, rmin, rmax, phiMinFirst, phiMaxFirst, layerid, detid, sideC_lowerRobId, sideC_lowerHashId );
222  RegSelModule m4( zmin, 0, rmin, rmax, phiMinSecond, phiMaxSecond, layerid, detid, sideC_higherRobId, sideC_higherHashId );
223  lut->addModule( m1 );
224  lut->addModule( m2 );
225  lut->addModule( m3 );
226  lut->addModule( m4 );
227  }
228  } //end of loop over modules (PrepRawData collections)
229 
230  lut->initialise();
231 
232  return lut;
233 
234 }
MuonRegSelCondAlg
Definition: MuonRegSelCondAlg.h:32
RegSelModule
Definition: RegSelModule.h:38
RPC_RegSelCondAlg::RPC_RegSelCondAlg
RPC_RegSelCondAlg(const std::string &name, ISvcLocator *pSvcLocator)
Definition: RPC_RegSelCondAlg.cxx:28
python.SystemOfUnits.m2
int m2
Definition: SystemOfUnits.py:92
SG::ReadCondHandle
Definition: ReadCondHandle.h:44
MuonGM::MuonClusterReadoutElement::center
virtual const Amg::Vector3D & center() const override
Return the center of the element.
Definition: MuonClusterReadoutElement.h:125
xAOD::uint32_t
setEventNumber uint32_t
Definition: EventInfo_v1.cxx:127
PixelAthClusterMonAlgCfg.zmin
zmin
Definition: PixelAthClusterMonAlgCfg.py:169
ReadCellNoiseFromCool.cabling
cabling
Definition: ReadCellNoiseFromCool.py:154
MuonGM::MuonReadoutElement::getZsize
double getZsize() const
Definition: MuonDetDescr/MuonReadoutGeometry/MuonReadoutGeometry/MuonReadoutElement.h:198
M_PI
#define M_PI
Definition: ActiveFraction.h:11
ExpandedIdentifier
Definition: DetectorDescription/Identifier/Identifier/ExpandedIdentifier.h:102
MuonGM::RpcReadoutElement
An RpcReadoutElement corresponds to a single RPC module; therefore typicaly a barrel muon station con...
Definition: MuonDetDescr/MuonReadoutGeometry/MuonReadoutGeometry/RpcReadoutElement.h:55
SG::ReadCondHandle::range
bool range(EventIDRange &r)
Definition: ReadCondHandle.h:224
SG::VarHandleKey::key
const std::string & key() const
Return the StoreGate ID for the referenced object.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:141
MuonRegSelCondAlg::m_detMgrKey
SG::ReadCondHandleKey< MuonGM::MuonDetectorManager > m_detMgrKey
MuonDetectorManager from the conditions store.
Definition: MuonRegSelCondAlg.h:46
RpcIdHelper
Definition: RpcIdHelper.h:51
ITkPixEncoding::lut
constexpr auto lut(Generator &&f)
Definition: ITkPixQCoreEncodingLUT.h:19
RpcCablingCondData
Definition: RpcCablingCondData.h:21
runBeamSpotCalibration.helper
helper
Definition: runBeamSpotCalibration.py:112
MuonGM::MuonReadoutElement::getSsize
double getSsize() const
Definition: MuonDetDescr/MuonReadoutGeometry/MuonReadoutGeometry/MuonReadoutElement.h:196
python.changerun.m1
m1
Definition: changerun.py:32
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
MuonMDT_CablingMap.h
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
WriteCondHandle.h
PixelAthClusterMonAlgCfg.zmax
zmax
Definition: PixelAthClusterMonAlgCfg.py:169
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
RPC_RegSelCondAlg::m_rpcReadKey
SG::ReadCondHandleKey< RpcCablingCondData > m_rpcReadKey
Definition: RPC_RegSelCondAlg.h:38
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
IdentifierHash.h
MuonRegSelCondAlg::initialize
virtual StatusCode initialize() override
Definition: MuonRegSelCondAlg.cxx:35
SG::CondHandleKey::initialize
StatusCode initialize(bool used=true)
Amg::Vector3D
Eigen::Matrix< double, 3, 1 > Vector3D
Definition: GeoPrimitives.h:47
MuonDetectorManager.h
Identifier::getString
std::string getString() const
Provide a string form of the identifier - hexadecimal.
Definition: Identifier.cxx:25
MuonGM::MuonReadoutElement::getRsize
double getRsize() const
Definition: MuonDetDescr/MuonReadoutGeometry/MuonReadoutGeometry/MuonReadoutElement.h:197
MuonGM::MuonDetectorManager
The MuonDetectorManager stores the transient representation of the Muon Spectrometer geometry and pro...
Definition: MuonDetDescr/MuonReadoutGeometry/MuonReadoutGeometry/MuonDetectorManager.h:50
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
RPC_RegSelCondAlg::createTable
std::unique_ptr< RegSelSiLUT > createTable(const EventContext &ctx, EventIDRange &id_range) const override
Definition: RPC_RegSelCondAlg.cxx:40
python.Logging.manager
manager
Definition: PhysicsAnalysis/D3PDTools/AnaAlgorithm/python/Logging.py:92
SG::ReadCondHandle::key
const std::string & key() const
Definition: ReadCondHandle.h:59
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
MuonStation.h
IdContext
This class saves the "context" of an expanded identifier (ExpandedIdentifier) for compact or hash ver...
Definition: IdContext.h:26
RegSelSiLUT::RPC
@ RPC
Definition: RegSelSiLUT.h:45
python.SystemOfUnits.m3
int m3
Definition: SystemOfUnits.py:93
RPC_RegSelCondAlg.h
emacs: this is -*- c++ -*-
SG::ReadCondHandle::cptr
const_pointer_type cptr()
Definition: ReadCondHandle.h:67
RPC_RegSelCondAlg::initialize
virtual StatusCode initialize() override
Definition: RPC_RegSelCondAlg.cxx:34
RpcReadoutElement.h
Identifier
Definition: IdentifierFieldParser.cxx:14