ATLAS Offline Software
Loading...
Searching...
No Matches
TGCCableSLBToHPB.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4
6
12
13namespace MuonTGC_Cabling {
14
15TGCCableSLBToHPB::TGCCableSLBToHPB(const std::string& filename)
16 : TGCCable(TGCCable::SLBToHPB), m_database{{{nullptr}}} {
17 m_database[TGCId::Endcap][TGCId::WT] =
18 std::make_unique<TGCDatabasePPToSL>(filename, "SB EWT");
19 m_database[TGCId::Endcap][TGCId::WD] =
20 std::make_unique<TGCDatabasePPToSL>(filename, "SB EWD");
21 m_database[TGCId::Endcap][TGCId::ST] =
22 std::make_unique<TGCDatabasePPToSL>(filename, "SB EST");
23 m_database[TGCId::Endcap][TGCId::SD] =
24 std::make_unique<TGCDatabasePPToSL>(filename, "SB ESD");
25 m_database[TGCId::Forward][TGCId::WT] =
26 std::make_unique<TGCDatabasePPToSL>(filename, "SB FWT");
27 m_database[TGCId::Forward][TGCId::WD] =
28 std::make_unique<TGCDatabasePPToSL>(filename, "SB FWD");
29 m_database[TGCId::Forward][TGCId::ST] =
30 std::make_unique<TGCDatabasePPToSL>(filename, "SB FST");
31 m_database[TGCId::Forward][TGCId::SD] =
32 std::make_unique<TGCDatabasePPToSL>(filename, "SB FSD");
33}
34
35TGCCableSLBToHPB::~TGCCableSLBToHPB() = default;
36
37std::unique_ptr<TGCChannelId> TGCCableSLBToHPB::getChannel(
38 const TGCChannelId& channelId, bool orChannel) const {
39
40 if (channelId.getChannelIdType() == TGCChannelId::ChannelIdType::SLBOut) {
41 return getChannelOut(channelId, orChannel);
42 }
43 if (channelId.getChannelIdType() == TGCChannelId::ChannelIdType::HPBIn) {
44 return getChannelIn(channelId, orChannel);
45 }
46
47 return nullptr;
48}
49
51
52 if (moduleId.getModuleIdType() == TGCModuleId::SLB) {
53 return getModuleOut(moduleId);
54 }
55 if (moduleId.getModuleIdType() == TGCModuleId::HPB) {
56 return getModuleIn(moduleId);
57 }
58
59 return TGCModuleMap{};
60}
61
62std::unique_ptr<TGCChannelId> TGCCableSLBToHPB::getChannelIn(
63 const TGCChannelId& hpbin, bool orChannel) const {
64 if (orChannel || hpbin.isValid() == false) {
65 return nullptr;
66 }
67
68 // HPB module
69 std::unique_ptr<TGCModuleId> hpb{hpbin.getModule()};
70 if (!hpb) {
71 return nullptr;
72 }
73
74 // HPB -> SLB module connection
75 TGCModuleMap mapId = getModule(*hpb);
76
77 if (!mapId.size()) {
78 return nullptr;
79 }
80
81 int numOfBlock = TGCChannelSLBOut::getNumberOfBlock(TGCId::WD); // SD
82 if (numOfBlock == 0) {
83 return nullptr;
84 }
85
87 int slbInBlock = TGCChannelHPBIn::getSlbInBlock();
88
89 // SLB module
90
91 int blockInHPB = hpbin.getBlock();
92 int nSlb = hpbin.getChannel() / (numOfBlock * 2); // half block
93 int port = blockInHPB * slbInBlock + nSlb;
94 auto slb = mapId.popModule(port);
95
96 if (!slb) {
97 return nullptr;
98 }
99
100 // HPB ->SLB channel connection
101 int nInSlb = hpbin.getChannel() / (numOfBlock * 2); // half block
102 int blockInSlb = nInSlb / 2;
103 int nInBlock = nInSlb % 2;
104 int channel = (chInBlock / 2) * nInBlock;
105
106 return std::make_unique<TGCChannelSLBOut>(
107 slb->getSideType(), slb->getModuleType(), slb->getRegionType(),
108 slb->getSector(), slb->getId(), blockInSlb, channel);
109}
110
111std::unique_ptr<TGCChannelId> TGCCableSLBToHPB::getChannelInforHPB(
112 const TGCChannelId& hpbin, TGCId::ModuleType moduleType,
113 bool orChannel) const {
114 if (orChannel || hpbin.isValid() == false) {
115 return nullptr;
116 }
117 // HPB module
118 std::unique_ptr<TGCModuleId> hpb{
119 hpbin.getModule()}; // This function is defined in TGCChannelHPBIn
120 // set current SideType,SignalType...
121 // ChannelID(HPBIn) is set in HPBIn constructor
122 if (!hpb) {
123 return nullptr;
124 }
125
126 // HPB -> SLB module connection
127 TGCModuleMap mapId = getModuleInforHPB(*hpb, moduleType);
128 if (!mapId.size()) {
129 return nullptr;
130 }
131
132 // need to check
133 int numOfBlock = TGCChannelSLBOut::getNumberOfBlock(moduleType);
134 if (numOfBlock == 0) {
135 return nullptr;
136 }
137
138 int chInBlock = TGCChannelSLBOut::getChannelInBlock(moduleType);
139 int slbInBlock = 0;
140
141 // SLB module
142 std::unique_ptr<TGCModuleId> slb{};
143 int blockInHPB = 0;
144 int nSlb = 0; // half block
145 int port = 0; // input position for HPT
146
147 // HPB ->SLB channel connection
148 int blockInSlb = 0;
149 int posInHpb = 0;
150 int channel = 0;
151 switch (moduleType) {
152 case TGCId::WD:
153 case TGCId::SD:
154 slbInBlock = 3;
155 blockInHPB = hpbin.getBlock();
156 nSlb = hpbin.getChannel() / (numOfBlock * 2);
157 port = blockInHPB * slbInBlock + nSlb;
158 slb = mapId.popModule(port);
159 blockInSlb = (hpbin.getChannel() - nSlb * (numOfBlock * 2)) / 2;
160 posInHpb = (hpbin.getChannel() - (numOfBlock * 2) * nSlb) % 2;
161 channel = (chInBlock / 2) * posInHpb;
162 break;
163
164 case TGCId::WT:
165 slbInBlock = 2;
166 blockInHPB = hpbin.getBlock();
167 nSlb = hpbin.getChannel() / (numOfBlock * 2);
168 port = blockInHPB * slbInBlock + nSlb;
169 slb = mapId.popModule(-port);
170
171 blockInSlb = (hpbin.getChannel() - nSlb * (numOfBlock * 2)) / 2;
172 posInHpb = (hpbin.getChannel() - (numOfBlock * 2) * nSlb) % 2;
173 channel = (chInBlock / 2) * posInHpb;
174 break;
175
176 case TGCId::ST:
177 blockInHPB = hpbin.getBlock();
178 if (blockInHPB == 0 && hpbin.getChannel() < numOfBlock) {
179 port = 1;
180 } else {
181 port = 2;
182 }
183 slb = mapId.popModule(-port);
184
185 blockInSlb = (hpbin.getChannel()) % numOfBlock;
186 if (blockInHPB == 1 && hpbin.getChannel() >= numOfBlock) {
187 blockInSlb = blockInSlb + numOfBlock / 2;
188 }
189 channel = 0;
190 break;
191
192 default:
193 break;
194 }
195
196 if (!slb) {
197 return nullptr;
198 }
199
200 const int offset = 6; // offset to get center of block
201 channel += offset;
202
203 int SLBID = slb->getId();
204 if ((chInBlock * blockInSlb + channel) > chInBlock * numOfBlock) {
205 SLBID++;
206 channel = channel % chInBlock;
207 blockInSlb = 0;
208 } else if (channel > chInBlock) {
209 channel = channel % chInBlock;
210 blockInSlb++;
211 }
212
213 return std::make_unique<TGCChannelSLBOut>(
214 slb->getSideType(), moduleType, slb->getRegionType(), slb->getSector(),
215 SLBID, blockInSlb, channel);
216}
217
218std::unique_ptr<TGCChannelId> TGCCableSLBToHPB::getChannelOut(
219 const TGCChannelId& slbout, bool orChannel) const {
220 if (orChannel || slbout.isValid() == false ||
221 slbout.getMultipletType() == TGCId::Triplet) {
222 return nullptr;
223 }
224
225 // SLB module
226 std::unique_ptr<TGCModuleId> slb{slbout.getModule()};
227 if (!slb) {
228 return nullptr;
229 }
230
231 // SLB -> HPB module connection
232 TGCModuleMap mapId = getModule(*slb);
233
234 if (mapId.empty()) {
235 return nullptr;
236 }
237
238 // HPB module
239 int port = mapId.begin()->first;
240 std::unique_ptr<TGCModuleId> hpb = mapId.popModule(port);
241 if (!hpb) {
242 return nullptr;
243 }
244
245 int chInBlock = TGCChannelSLBOut::getChannelInBlock(slbout.getModuleType());
246 if (chInBlock <= 1) {
247 return nullptr;
248 }
249 int slbInBlock = TGCChannelHPBIn::getSlbInBlock();
250
251 // SLB ->HPB channel connection
252 int block = port / slbInBlock;
253 int hitId = (port % slbInBlock) * 2 + slbout.getBlock();
254 int pos = slbout.getChannel() / (chInBlock / 2);
255 int channel = hitId * 2 + pos;
256
257 return std::make_unique<TGCChannelHPBIn>(
258 hpb->getSideType(), hpb->getSignalType(), hpb->getRegionType(),
259 hpb->getSector(), hpb->getId(), block, channel);
260}
261
263 if (hpbin.isValid() == false) {
264 return TGCModuleMap{};
265 }
266 const int hpbId = hpbin.getId();
267
270 if (hpbin.getSignalType() == TGCId::Wire) {
271 doublet = TGCId::WD;
272 triplet = TGCId::WT;
273 }
274 if (hpbin.getSignalType() == TGCId::Strip) {
275 doublet = TGCId::SD;
276 triplet = TGCId::ST;
277 }
278
279 if (doublet == TGCId::NoModuleType || triplet == TGCId::NoModuleType) {
280 return TGCModuleMap{};
281 }
282
283 TGCDatabase* doubletP = m_database[hpbin.getRegionType()][doublet].get();
284 TGCDatabase* tripletP = m_database[hpbin.getRegionType()][triplet].get();
285
286 TGCModuleMap mapId{};
287 const int doubletMaxEntry = doubletP->getMaxEntry();
288 for (int i = 0; i < doubletMaxEntry; i++) {
289 if (doubletP->getEntry(i, 1) == hpbId) {
290 int id = doubletP->getEntry(i, 0);
291 int block = doubletP->getEntry(i, 2);
292 auto slb = std::make_unique<TGCModuleSLB>(
293 hpbin.getSideType(), doublet, hpbin.getRegionType(),
294 hpbin.getSector(), id);
295
296 mapId.insert(block, std::move(slb));
297 }
298 }
299 const int tripletMaxEntry = tripletP->getMaxEntry();
300 for (int i = 0; i < tripletMaxEntry; i++) {
301 if (tripletP->getEntry(i, 1) == hpbId) {
302 int id = tripletP->getEntry(i, 0);
303 int block = -tripletP->getEntry(i, 2);
304 auto slb = std::make_unique<TGCModuleSLB>(
305 hpbin.getSideType(), triplet, hpbin.getRegionType(),
306 hpbin.getSector(), id);
307
308 mapId.insert(block, std::move(slb));
309 }
310 }
311
312 return mapId;
313}
314
316 const TGCModuleId& hpbin, TGCId::ModuleType moduleType) const {
317 if (hpbin.isValid() == false) {
318 return TGCModuleMap{};
319 }
320
321 const int hpbId = hpbin.getId();
322
323 TGCDatabase* databaseP =
324 m_database[hpbin.getRegionType()][moduleType].get();
325
326 TGCModuleMap mapId{};
327 const int MaxEntry = databaseP->getMaxEntry();
328 for (int i = 0; i < MaxEntry; i++) {
329 if (databaseP->getEntry(i, 1) == hpbId) {
330 int id = databaseP->getEntry(i, 0);
331 int block = -100;
332 switch (moduleType) {
333 case TGCId::WD:
334 case TGCId::SD:
335 block = databaseP->getEntry(i, 2);
336 break;
337
338 case TGCId::WT:
339 case TGCId::ST:
340 block = -1 * databaseP->getEntry(i, 2); // check - sign
341 break;
342
343 default:
344 break;
345 }
346 auto slb = std::make_unique<TGCModuleSLB>(
347 hpbin.getSideType(), moduleType, hpbin.getRegionType(),
348 hpbin.getSector(), id);
349
350 mapId.insert(block, std::move(slb));
351 }
352 }
353
354 return mapId;
355}
356
358 if (slb.isValid() == false) {
359 return TGCModuleMap{};
360 }
361
362 const int slbId = slb.getId();
363
364 TGCDatabase* databaseP =
365 m_database[slb.getRegionType()][slb.getModuleType()].get();
366
367 TGCModuleMap mapId{};
368 const int MaxEntry = databaseP->getMaxEntry();
369 for (int i = 0; i < MaxEntry; i++) {
370 if (databaseP->getEntry(i, 0) == slbId) {
371 int id = databaseP->getEntry(i, 1);
372 int block = databaseP->getEntry(i, 2);
373 if (slb.getMultipletType() == TGCId::Triplet) {
374 block *= -1;
375 }
376
377 auto hpb = std::make_unique<TGCModuleHPB>(
378 slb.getSideType(), slb.getSignalType(), slb.getRegionType(),
379 slb.getSector(), id);
380
381 mapId.insert(block, std::move(hpb));
382 break;
383 }
384 }
385
386 return mapId;
387}
388
389} // namespace MuonTGC_Cabling
bool getModule(std::istream &s, RegSelModule &m)
std::unique_ptr< TGCChannelId > getChannel(const TGCChannelId &channelId, bool orChannel=false) const
TGCModuleMap getModuleIn(const TGCModuleId &hpb) const
std::unique_ptr< TGCChannelId > getChannelOut(const TGCChannelId &slbout, bool orChannel=false) const
std::unique_ptr< TGCChannelId > getChannelIn(const TGCChannelId &hpbin, bool orChannel=false) const
std::unique_ptr< TGCChannelId > getChannelInforHPB(const TGCChannelId &hpbin, TGCId::ModuleType moduleType, bool orChannel=false) const
std::array< std::array< std::unique_ptr< TGCDatabase >, TGCId::MaxModuleType >, TGCId::MaxRegionType > m_database
TGCModuleMap getModule(const TGCModuleId &moduleId) const
TGCModuleMap getModuleInforHPB(const TGCModuleId &hpb, TGCId::ModuleType moduleType) const
TGCModuleMap getModuleOut(const TGCModuleId &slb) const
TGCCable(CableType type=NoCableType)
Definition TGCCable.h:31
virtual std::unique_ptr< TGCModuleId > getModule() const
virtual bool isValid() const
static int getNumberOfBlock(TGCId::ModuleType moduleType)
static int getChannelInBlock(TGCId::ModuleType moduleType)
virtual int getMaxEntry() const
virtual int getEntry(int entry, int column) const
ModuleType getModuleType() const
Definition TGCId.h:137
RegionType getRegionType() const
Definition TGCId.h:146
virtual int getSector() const
Definition TGCId.h:156
MultipletType getMultipletType() const
Definition TGCId.h:143
SideType getSideType() const
Definition TGCId.h:134
SignalType getSignalType() const
Definition TGCId.h:140
int getId() const
Definition TGCId.h:162
ModuleIdType getModuleIdType() const
Definition TGCModuleId.h:32
virtual bool isValid() const
Definition TGCModuleId.h:36
Store_t::const_iterator begin() const
Returns the begin iterator of the underlying map.
void insert(int connector, std::unique_ptr< TGCModuleId > moduleId)
std::unique_ptr< TGCModuleId > popModule(const int connector)
Return a certain module and remove it from the map.