ATLAS Offline Software
Loading...
Searching...
No Matches
TRT_HWMappingSvc.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4
11
12// Header Includes
13#include "TRT_HWMappingSvc.h"
15
19
20#include "TFile.h"
21#include "TGraph.h"
22
23#include <sstream>
24#include <fstream>
25
29TRT_HWMappingSvc::TRT_HWMappingSvc( const std::string& name,
30 ISvcLocator* pSvcLocator ) :
31 base_class( name, pSvcLocator ),
32 m_detStore("DetectorStore",name),
33 m_TRT_ID_Helper(nullptr),
34 m_TRTStrawNeighbourSvc("TRT_StrawNeighbourSvc",name)
35{
36 // Get properties from job options
37 declareProperty( "Barrel_HV_COOLFolderName", m_Barrel_HV_COOLFolderName = "/TRT/DCS/HV/BARREL" );
38 declareProperty( "EndcapA_HV_COOLFolderName", m_EndcapA_HV_COOLFolderName = "/TRT/DCS/HV/ENDCAPA" );
39 declareProperty( "EndcapC_HV_COOLFolderName", m_EndcapC_HV_COOLFolderName = "/TRT/DCS/HV/ENDCAPC" );
40 declareProperty( "TRTStrawNeighbourSvc", m_TRTStrawNeighbourSvc );
41 declareProperty( "DetectorStore", m_detStore );
42}
43
48
53 ATH_MSG_INFO("TRT_HWMappingSvc::initialize.");
54
55 StatusCode sc(StatusCode::SUCCESS);
56
57 // Retrieve the DetectorStore
58 sc = m_detStore.retrieve();
59 if ( sc.isFailure() ) {
60 msg(MSG::ERROR) << "Unable to retrieve " << m_detStore << endmsg;
61 return sc;
62 }
63
64 // Get the TRT Identifier Helper.
65 sc = m_detStore->retrieve( m_TRT_ID_Helper, "TRT_ID" );
66 if ( sc.isFailure() ) {
67 ATH_MSG_ERROR( "Unable to retrieve pointer to TRT ID Helper." );
68 return sc;
69 }
70
71 // Get the TRTStrawNeighbourSvc
72 sc = m_TRTStrawNeighbourSvc.retrieve();
73 if ( sc.isFailure() ) {
74 msg(MSG::ERROR) << "Couldn't get " << m_TRTStrawNeighbourSvc << endmsg;
75 return sc;
76 }
77
78 ATH_CHECK( m_HWMapReadKey.initialize() );
79
80 return sc;
81}
82
87
88 std::string chanName = "";
89
90 // Decode the identifier
91 int barrel_ec = m_TRT_ID_Helper->barrel_ec( ident );
92 int phi_module = m_TRT_ID_Helper->phi_module( ident );
93 int layer_or_wheel = m_TRT_ID_Helper->layer_or_wheel( ident );
94 //int straw_layer = m_TRT_ID_Helper->straw_layer( ident );
95 //int straw = m_TRT_ID_Helper->straw( ident );
96
97 // get the data from the Write condition object
99 const TRTCond::HWMap* theMap{*readHandle};
100 if ( theMap == nullptr ) {
101 ATH_MSG_WARNING("Couldn't retrieve DCS HV names. Is TRTHWMapCondAlg added to condSeq?");
102 return chanName;
103 }
104
105
106 if ( abs(barrel_ec) == 1 ) {
107 // Barrel identifier
108 int padNum = get_HV_BarrelPadNum( ident );
109 int hashedPad = hashThisBarrelPad( phi_module, layer_or_wheel, padNum );
110
111 if ( hashedPad >= (int)theMap->get_Barrel_HV_Names()->size() || hashedPad<0) {
112 ATH_MSG_WARNING("channel request for invalid barrel HV pad.");
113 return "";
114 } else chanName = theMap->get_Barrel_HV_Names()->at(hashedPad);
115
116 } else if ( barrel_ec == 2 ) {
117 // EndcapA identifier
118 int fourPlaneNum = get_HV_Endcap4PlaneNum( ident );
119 int cellNum = get_HV_EndcapCellNum( ident );
120 int hashedCell = hashThisEndcapCell( phi_module, layer_or_wheel, fourPlaneNum, cellNum );
121
122 if ( hashedCell >= (int)theMap->get_EndcapA_HV_Names()->size() || hashedCell<0 ) {
123 ATH_MSG_WARNING("channel request for invalid endcap A HV pad.");
124 return "";
125 } else chanName = theMap->get_EndcapA_HV_Names()->at(hashedCell);
126
127 } else if ( barrel_ec == -2 ) {
128 // EndcapC identifier
129 int fourPlaneNum = get_HV_Endcap4PlaneNum( ident );
130 int cellNum = get_HV_EndcapCellNum( ident );
131 int hashedCell = hashThisEndcapCell( phi_module, layer_or_wheel, fourPlaneNum, cellNum );
132
133 if ( hashedCell >= (int)theMap->get_EndcapC_HV_Names()->size() || hashedCell<0) {
134 ATH_MSG_WARNING("channel request for invalid endcap C HV pad.");
135 return "";
136 } else chanName = theMap->get_EndcapC_HV_Names()->at(hashedCell);
137
138 } else {
139 ATH_MSG_ERROR("Unknown Identifier (not barrel or endcap)!");
140 return "";
141 }
142
143 return chanName;
144}
145
150
151 int chanNum = -1;
152
153 // Decode the identifier
154 int barrel_ec = m_TRT_ID_Helper->barrel_ec( ident );
155 int phi_module = m_TRT_ID_Helper->phi_module( ident );
156 int layer_or_wheel = m_TRT_ID_Helper->layer_or_wheel( ident );
157 //int straw_layer = m_TRT_ID_Helper->straw_layer( ident );
158 //int straw = m_TRT_ID_Helper->straw( ident );
159
160 // get the data from the Write condition object
162 const TRTCond::HWMap* theMap{*readHandle};
163 if ( theMap == nullptr ) {
164 ATH_MSG_WARNING("Couldn't retrieve DCS HV numbers. Is TRTHWMapCondAlg added to condSeq?");
165 return chanNum;
166 }
167
168
169 if ( abs(barrel_ec) == 1 ) {
170 // Barrel identifier
171 int padNum = get_HV_BarrelPadNum( ident );
172 int hashedPad = hashThisBarrelPad( phi_module, layer_or_wheel, padNum );
173
174
175 if ( hashedPad >= (int)theMap->get_Barrel_HV_Nums()->size() || hashedPad<0) {
176 ATH_MSG_WARNING("channel request for invalid barrel HV pad.");
177 return -1;
178 } else chanNum = theMap->get_Barrel_HV_Nums()->at(hashedPad);
179
180 } else if ( barrel_ec == 2 ) {
181 // EndcapA identifier
182 int fourPlaneNum = get_HV_Endcap4PlaneNum( ident );
183 int cellNum = get_HV_EndcapCellNum( ident );
184 int hashedPad = hashThisEndcapCell( phi_module, layer_or_wheel, fourPlaneNum, cellNum );
185
186 if ( hashedPad >= (int)theMap->get_EndcapA_HV_Nums()->size() || hashedPad<0) {
187 ATH_MSG_WARNING("channel request for invalid EndcapA HV pad.");
188 return -1;
189 } else chanNum = theMap->get_EndcapA_HV_Nums()->at(hashedPad);
190
191
192 } else if ( barrel_ec == -2 ) {
193 // EndcapC identifier
194 int fourPlaneNum = get_HV_Endcap4PlaneNum( ident );
195 int cellNum = get_HV_EndcapCellNum( ident );
196 int hashedPad = hashThisEndcapCell( phi_module, layer_or_wheel, fourPlaneNum, cellNum );
197
198 if ( hashedPad >= (int)theMap->get_EndcapC_HV_Nums()->size() || hashedPad<0) {
199 ATH_MSG_WARNING("channel request for invalid EndcapC HV pad.");
200 return -1;
201 } else chanNum = theMap->get_EndcapC_HV_Nums()->at(hashedPad);
202
203
204 } else {
205 ATH_MSG_ERROR("Unknown Identifier (not barrel or endcap)!");
206 return -1;
207 }
208
209 return chanNum;
210}
211
216
217 int padNum = -1;
218 m_TRTStrawNeighbourSvc->getPad( ident, padNum );
219 return padNum;
220}
221
225int TRT_HWMappingSvc::hashThisBarrelPad( int sector, int module, int padNum ) {
226
227 int hashedPad = -1;
228
229 /*---------------------------------
230 * Pad counting details:
231 * 32 sectors ( expect sector in range(0,31) )
232 * 3 modules ( expect module in range(0,2) )
233 * 42 pads in type1 module ( expect padNum in range(1,42) )
234 * 65 pads in type2 module ( expect padNum in range(1,65) )
235 * 100 pads in type3 module ( expect padNum in range(1,100) )
236 */
237 padNum -= 1; // shift range down to (0,n-1)
238 int nPadsPerSector = 42+65+100;
239
240 int padOffset = -1;
241 switch( module ) {
242 case 0: padOffset = 0; break;
243 case 1: padOffset = 42; break;
244 case 2: padOffset = 42+65; break;
245 default:
246 msg(MSG::ERROR) << "Couldn't hash this pad: "
247 << sector << "," << module << "," << padNum << endmsg;
248 return -1;
249 }
250
251 hashedPad = 0;
252 hashedPad += sector*nPadsPerSector;
253 hashedPad += padNum + padOffset;
254
255 return hashedPad;
256}
257
262
263 int cellNum = -1;
264
265 // Decode the identifier
266 //int barrel_ec = m_TRT_ID_Helper->barrel_ec( ident );
267 //int phi_module = m_TRT_ID_Helper->phi_module( ident );
268 //int layer_or_wheel = m_TRT_ID_Helper->layer_or_wheel( ident );
269 //int straw_layer = m_TRT_ID_Helper->straw_layer( ident );
270 int straw = m_TRT_ID_Helper->straw( ident );
271
272 /* Simple: Expect straw in range(0,23)
273 * First 8 are Cell 0
274 * Second 8 are Cell 1
275 * Third 8 are Cell 2
276 */
277
278 if ( straw >= 0 && straw < 8 ) cellNum = 0;
279 else if ( straw >= 8 && straw < 16 ) cellNum = 1;
280 else if ( straw >=16 && straw < 24 ) cellNum = 2;
281 else {
282 msg(MSG::WARNING) << "Straw number out of range for Endcap!" << endmsg;
283 cellNum = -1;
284 }
285
286 return cellNum;
287}
288
293
294 int fourPlaneWheelNum = -1;
295
296 // Decode the identifier
297 //int barrel_ec = m_TRT_ID_Helper->barrel_ec( ident );
298 //int phi_module = m_TRT_ID_Helper->phi_module( ident );
299 //int layer_or_wheel = m_TRT_ID_Helper->layer_or_wheel( ident );
300 int straw_layer = m_TRT_ID_Helper->straw_layer( ident );
301 //int straw = m_TRT_ID_Helper->straw( ident );
302
303 /* Simple: Expect straw_layer in range(0,15) or range(0,7)
304 * First 4 are 4-plane wheel 0
305 * Second 4 are 4-plane wheel 1
306 * Third 4 are 4-plane wheel 2
307 * Fourth 4 are 4-plane wheel 3
308 */
309
310 if ( straw_layer >= 0 && straw_layer < 4 ) fourPlaneWheelNum = 0;
311 else if ( straw_layer >= 4 && straw_layer < 8 ) fourPlaneWheelNum = 1;
312 else if ( straw_layer >= 8 && straw_layer < 12 ) fourPlaneWheelNum = 2;
313 else if ( straw_layer >= 12 && straw_layer < 16 ) fourPlaneWheelNum = 3;
314 else {
315 msg(MSG::WARNING) << "Straw layer number out of range for Endcap!" << endmsg;
316 fourPlaneWheelNum = -1;
317 }
318
319 return fourPlaneWheelNum;
320}
321
326
327 int fuseNum = -1;
328
329 // Decode the identifier
330 //int barrel_ec = m_TRT_ID_Helper->barrel_ec( ident );
331 //int phi_module = m_TRT_ID_Helper->phi_module( ident );
332 //int layer_or_wheel = m_TRT_ID_Helper->layer_or_wheel( ident );
333 //int straw_layer = m_TRT_ID_Helper->straw_layer( ident );
334 int straw = m_TRT_ID_Helper->straw( ident );
335
336 /* Simple: Expect straw in range(0,23)
337 * straw# 0,1, 8, 9, 16,17 are Fuse 0
338 * straw# 2,3, 10,11, 18,19 are Fuse 1
339 * straw# 4,5, 12,13, 20,21 are Fuse 2
340 * straw# 6,7, 14,15, 22,23 are Fuse 3
341 */
342
343 straw = straw%8; // (0,8,16 -> 0)
344 if ( straw == 0 or straw == 1 ) fuseNum = 0;
345 if ( straw == 2 or straw == 3 ) fuseNum = 1;
346 if ( straw == 4 or straw == 5 ) fuseNum = 2;
347 if ( straw == 6 or straw == 7 ) fuseNum = 3;
348
349 return fuseNum;
350}
351
355int TRT_HWMappingSvc::hashThisEndcapCell( int sector, int wheel, int layer, int cellNum ) {
356
357 int hashedCell = -1;
358
359 /*---------------------------------
360 * Cell counting details:
361 * 32 sectors ( expect sector in range(0,31) )
362 * 14 wheels ( expect wheel in range(0,13) )
363 * typeA: (0,5) wheelType = 0
364 * typeB: (6,13) wheelType = 1
365 * 4 4-plane layers in typeA ( expect layer in range(0,3) )
366 * 2 4-plane layers in typeB ( expect layer in range(0,1) )
367 * 3 cells per sector in one 4-plane wheel ( expect cell in range(0,2) )
368 */
369
370 // Trick for counting
371 int wheelType = -1;
372 if ( wheel >= 0 && wheel < 6 ) wheelType = 0; // A wheel
373 if ( wheel >= 6 && wheel < 14 ) wheelType = 1; // B wheel
374 if ( wheelType == -1 ) {
375 msg(MSG::ERROR) << "Invalid wheel number." << endmsg;
376 return -1;
377 }
378
379 int nCellsPerSector = (6*4+8*2)*3; // 6 A-wheels + 8 B-wheels
380 int fourPlaneWheelNum;
381 if ( wheelType == 0 ) {
382 fourPlaneWheelNum = layer + 4*wheel; // 0-23
383 } else {
384 fourPlaneWheelNum = layer + 24 + 2*(wheel-6); // 24-39
385 }
386
387 hashedCell = cellNum + 3*fourPlaneWheelNum + sector*nCellsPerSector;
388
389 return hashedCell;
390}
391
392
397
398 return StatusCode::SUCCESS;
399}
400
405
406 // get the data from the Write condition object
408 const TRTCond::HWMap* theMap{*readHandle};
409 if ( theMap == nullptr ) {
410 ATH_MSG_WARNING("Couldn't retrieve DCS HV. Is TRTHWMapCondAlg added to condSeq?");
411 return;
412 }
413
414 ATH_MSG_INFO("Dumping TRT Barrel HV-line/pad map...");
415 for ( int mapItr = 0; mapItr < (int)theMap->get_Barrel_HV_Names()->size(); ++mapItr ) {
416 ATH_MSG_INFO( mapItr << " " << theMap->get_Barrel_HV_Names()->at(mapItr));
417 }
418
419 ATH_MSG_INFO("Dumping TRT EndcapA HV-line/pad map...");
420 for ( int mapItr = 0; mapItr < (int)theMap->get_EndcapA_HV_Names()->size(); ++mapItr ) {
421 ATH_MSG_INFO( mapItr << " " << theMap->get_EndcapA_HV_Names()->at(mapItr));
422 }
423
424 ATH_MSG_INFO("Dumping TRT EndcapA HV-line/pad map...");
425 for ( int mapItr = 0; mapItr < (int)theMap->get_EndcapC_HV_Names()->size(); ++mapItr ) {
426 ATH_MSG_INFO( mapItr << " " << theMap->get_EndcapC_HV_Names()->at(mapItr));
427 }
428
429 ATH_MSG_INFO("Dumping TRT Barrel HV-line/pad channel values...");
430 for ( int mapItr = 0; mapItr < (int)theMap->get_Barrel_HV_Nums()->size(); ++mapItr ) {
431 ATH_MSG_INFO( mapItr << " " << theMap->get_Barrel_HV_Nums()->at(mapItr));
432 }
433
434 ATH_MSG_INFO("Dumping TRT EndcapA HV-line/pad channel values...");
435 for ( int mapItr = 0; mapItr < (int)theMap->get_EndcapA_HV_Nums()->size(); ++mapItr ) {
436 ATH_MSG_INFO( mapItr << " " << theMap->get_EndcapA_HV_Nums()->at(mapItr));
437 }
438
439 ATH_MSG_INFO("Dumping TRT EndcapA HV-line/pad channel values...");
440 for ( int mapItr = 0; mapItr < (int)theMap->get_EndcapC_HV_Nums()->size(); ++mapItr ) {
441 ATH_MSG_INFO( mapItr << " " << theMap->get_EndcapC_HV_Nums()->at(mapItr));
442 }
443
444
445
446 // Create txt file of HV Line name and x,y / phi,z of straws on line
447 const InDetDD::TRT_DetectorManager* detMan = nullptr;
448 StatusCode sc = m_detStore->retrieve(detMan);
449 if ( sc.isFailure() ) {
450 ATH_MSG_ERROR("Couldn't get TRT Detector Manager. Can't ouput text file for monitoring.");
451 return;
452 }
453 std::map< std::string, std::vector<Identifier> > chanNameStrawMap;
455 int nStraws = 0;
456 for ( strawItr = m_TRT_ID_Helper->straw_begin();
457 strawItr != m_TRT_ID_Helper->straw_end(); ++strawItr ) {
458 nStraws++;
459 Identifier strawID = m_TRT_ID_Helper->straw_id(*strawItr);
460 std::string HVchanName = get_HV_CoolChanName(strawID);
461 std::map< std::string, std::vector<Identifier> >::iterator mapItr;
462 mapItr = chanNameStrawMap.find(HVchanName);
463 if ( mapItr == chanNameStrawMap.end() ) {
464 // Channel name not yet recorded. Insert it!
465 std::vector<Identifier> vec;
466 vec.push_back(strawID);
467 chanNameStrawMap.insert( std::make_pair(HVchanName,vec) );
468 } else {
469 // Channel name is there. Add identifier to its vector.
470 (*mapItr).second.push_back(strawID);
471 }
472 }
473 ATH_MSG_INFO( nStraws << " straws from TRT_ID." );
474 std::fstream outFile( "TRT_HVmap.txt", std::ios::out );
475 std::map< std::string, std::vector<Identifier> >::iterator mapItr;
476 for ( mapItr = chanNameStrawMap.begin(); mapItr != chanNameStrawMap.end(); ++mapItr ) {
477 std::vector<Identifier>::const_iterator idItr;
478 ATH_MSG_INFO( "Channel " << (*mapItr).first << " - " );
479 for ( idItr = (*mapItr).second.begin(); idItr != (*mapItr).second.end(); ++idItr ) {
480 int det = m_TRT_ID_Helper->barrel_ec(*idItr);
481 int phi = m_TRT_ID_Helper->phi_module(*idItr);
482 int lay = m_TRT_ID_Helper->layer_or_wheel(*idItr);
483 int sLay = m_TRT_ID_Helper->straw_layer(*idItr);
484 int strawInLay = m_TRT_ID_Helper->straw(*idItr);
485 ATH_MSG_INFO( det << " " << phi << " " << lay << " " << sLay << " " << strawInLay );
486 // Get the detector element for this straw (layer)
487 const InDetDD::TRT_BaseElement* detElem = detMan->getElement(*idItr);
488 // 2D coordinates of straws on line
489 if ( abs(det) == 1 ) outFile << det << " " << (*mapItr).first << " " << detElem->strawCenter(strawInLay)[0] << " " << detElem->strawCenter(strawInLay)[1] << "\n";
490 if ( abs(det) == 2 ) outFile << det << " " << (*mapItr).first << " " << detElem->strawCenter(strawInLay).phi() << " " << detElem->strawCenter(strawInLay)[2] << "\n";
491 }
492 }
493
494 }
Scalar phi() const
phi method
#define endmsg
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_WARNING(x)
std::vector< size_t > vec
Abstract interface to information on straws electronic grouping.
static Double_t sc
This is an Identifier helper class for the TRT subdetector.
Virtual base class of TRT readout elements.
const Amg::Vector3D & strawCenter(int straw) const
Straw Surface: Local -> global transform of the straw via integer.
The Detector Manager for all TRT Detector elements, it acts as the interface to the detector elements...
const TRT_BaseElement * getElement(Identifier id) const
Access Elements Generically---------------------------------------------—.
const std::vector< std::string > * get_EndcapA_HV_Names() const
Definition HWMap.h:34
const std::vector< int > * get_Barrel_HV_Nums() const
Definition HWMap.h:36
const std::vector< std::string > * get_EndcapC_HV_Names() const
Definition HWMap.h:35
const std::vector< std::string > * get_Barrel_HV_Names() const
Definition HWMap.h:33
const std::vector< int > * get_EndcapA_HV_Nums() const
Definition HWMap.h:37
const std::vector< int > * get_EndcapC_HV_Nums() const
Definition HWMap.h:38
std::string get_HV_CoolChanName(const Identifier)
Returns the HV line logical name in COOL channel format (":","/" -> "_")
int get_HV_CoolChanNum(const Identifier)
Returns the COOL channel number for an identifier.
int hashThisEndcapCell(int, int, int, int)
Hashes an Endcap HV cell by sector/wheel/layer/cell#.
int get_HV_EndcapFuseNum(const Identifier)
Returns the fuse number (0-3) for an endcap identifier.
ServiceHandle< ITRT_StrawNeighbourSvc > m_TRTStrawNeighbourSvc
virtual ~TRT_HWMappingSvc()
Destructor //.
int get_HV_BarrelPadNum(const Identifier)
Returns the HV pad for a barrel identifier.
virtual StatusCode initialize()
Initialize //.
const TRT_ID * m_TRT_ID_Helper
Straw Helpers.
std::string m_EndcapA_HV_COOLFolderName
int get_HV_Endcap4PlaneNum(const Identifier)
Returns the 4-plane wheel number for an endcap identifier.
ServiceHandle< StoreGateSvc > m_detStore
SG::ReadCondHandleKey< TRTCond::HWMap > m_HWMapReadKey
TRT_HWMappingSvc(const std::string &, ISvcLocator *)
Constructor //.
virtual StatusCode finalize()
Finalize //.
std::string m_Barrel_HV_COOLFolderName
jobOptions properties
void DumpMaps()
Dump HV-line/pad maps.
int hashThisBarrelPad(int, int, int)
Hashes a Barrel HV pad by sector/module/pad#.
std::string m_EndcapC_HV_COOLFolderName
int get_HV_EndcapCellNum(const Identifier)
Returns the HV cell for an endcap identifier.
MultiRange::const_identifier_factory const_expanded_id_iterator
Definition TRT_ID.h:88
MsgStream & msg
Definition testRead.cxx:32