ATLAS Offline Software
Loading...
Searching...
No Matches
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
16
17#include "RPC_RegSelCondAlg.h"
18
19#include "GaudiKernel/EventIDRange.h"
21#include "CLHEP/Units/SystemOfUnits.h"
27
28RPC_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
36 ATH_CHECK(m_rpcReadKey.initialize());
37 return StatusCode::SUCCESS;
38}
39
40std::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}
#define M_PI
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
emacs: this is -*- c++ -*-
This class saves the "context" of an expanded identifier (ExpandedIdentifier) for compact or hash ver...
Definition IdContext.h:26
This is a "hash" representation of an Identifier.
std::string getString() const
Provide a string form of the identifier - hexadecimal.
virtual const Amg::Vector3D & center() const override
Return the center of the element.
The MuonDetectorManager stores the transient representation of the Muon Spectrometer geometry and pro...
An RpcReadoutElement corresponds to a single RPC module; therefore typicaly a barrel muon station con...
virtual StatusCode initialize() override
SG::ReadCondHandleKey< MuonGM::MuonDetectorManager > m_detMgrKey
MuonDetectorManager from the conditions store.
MuonRegSelCondAlg(const std::string &name, ISvcLocator *pSvcLocator)
SG::ReadCondHandleKey< RpcCablingCondData > m_rpcReadKey
std::unique_ptr< RegSelSiLUT > createTable(const EventContext &ctx, EventIDRange &id_range) const override
RPC_RegSelCondAlg(const std::string &name, ISvcLocator *pSvcLocator)
virtual StatusCode initialize() override
bool range(EventIDRange &r)
const std::string & key() const
const_pointer_type cptr()
Eigen::Matrix< double, 3, 1 > Vector3D