20 #include "Identifier/Identifier.h"
31 #include "GaudiKernel/ISvcLocator.h"
32 #include "GaudiKernel/GaudiException.h"
45 ISvcLocator* pSvcLocator )
46 : base_class(
name,pSvcLocator),
47 m_detStore(
"DetectorStore",
name),
60 ATH_MSG_DEBUG(
"TRT_StrawNeighbourSvc initialize method called");
62 if (StatusCode::SUCCESS!=
m_detStore.retrieve()) {
64 return StatusCode::FAILURE;
70 return StatusCode::FAILURE;
74 int chipConversionSocketToChip_m1[]={0,1,2,3,4,21,7,6,5,20,19,8,9,16,17,18,10,15,14,13,12,11};
76 int chipConversionChipToSocket_m1[] = {0,1,2,3,4,8,7,6,11,12,16,21,20,19,18,17,13,14,15,10,9,5};
79 int chipConversionSocketToChip_m2[] = {0,5,4,3,2,1,33,6,7,8,9,32,31,12,11,10,27,28,29,30,13,14,26,25,24,23,22,15,16,17,18,19,20,21};
81 int chipConversionChipToSocket_m2[] = {0,5,4,3,2,1,7,8,9,10,15,14,13,20,21,27,28,29,30,31,32,33,26,25,24,23,22,16,17,18,19,12,11,6};
84 int chipConversionSocketToChip_m3[] = {0,1,2,3,4,5,6,50,11,10,9,8,7,49,12,13,14,15,48,47,46,18,17,16,42,43,44,45,19,20,41,40,39,38,37,22,21,31,32,33,34,35,36,23,30,29,28,27,26,25,24};
86 int chipConversionChipToSocket_m3[] = {0,1,2,3,4,5,6,12,11,10,9,8,14,15,16,17,23,22,21,28,29,36,35,43,50,49,48,47,46,45,44,37,38,39,40,41,42,34,33,32,31,30,24,25,26,27,20,19,18,13,7};
91 int chipIndexToChipHardware_A0[] = {2, 1, 3, 0, 6, 5, 7, 4, 10, 9, 11, 8};
92 int chipIndexToChipHardware_A8[] = {8, 11, 9, 10, 4, 7, 5, 6, 0, 3, 1, 2};
93 int chipIndexToChipHardware_C0[] = {1, 2, 0, 3, 5, 6, 4, 7, 9, 10, 8, 11};
94 int chipIndexToChipHardware_C8[] = {11, 8, 10, 9, 7, 4, 6, 5, 3, 0, 2, 1};
96 int *chip_list[] = {chipIndexToChipHardware_A0, chipIndexToChipHardware_A8, chipIndexToChipHardware_C0, chipIndexToChipHardware_C8};
97 for (
int i=0;
i<4;
i++)
for (
int j=0; j<12; j++) map_list[
i][j] = chip_list[
i][j];
104 SmartIF<IRDBAccessSvc> iAccessSvc{service(
"RDBAccessSvc")};
107 throw GaudiException(
"Could not initalize RDBAccessSvc",
"TRT_GeoModel",StatusCode::FAILURE);
110 SmartIF<IGeoModelSvc> geoModel{service(
"GeoModelSvc")};
113 throw GaudiException(
"Could not locate GeoModelSvc",
"TRT_GeoModel",StatusCode::FAILURE);
116 const std::string& detectorKey = versionKey.
tag();
117 const std::string& detectorNode = versionKey.
node();
118 IRDBRecordset_ptr RDB_TRTElec = iAccessSvc->getRecordsetPtr(
"TRTBarElecToStrawRel",detectorKey,detectorNode);
120 if (RDB_TRTElec->size()==0) {
121 RDB_TRTElec = iAccessSvc->getRecordsetPtr(
"TRTBarElecToStrawRel",
"TRTBarElecToStrawRel-02");
122 msg(
MSG::INFO) <<
"The folder: InnerDetector->TRT->TRTBarrel->TRTBarrelElectronics not found in DetDesc tag. Using hardcoded tag: TRTBarElecToStrawRel-02" <<
endmsg;
128 const int numberOfm1layers=19;
129 const int numberOfm2layers=24;
130 const int numberOfm3layers=30;
132 int layer_m1_array[numberOfm1layers]= {15,16,16,16,16,17,17,17,17,17,18,18,18,18,18,19,19,19,18};
133 int layer_m2_array[numberOfm2layers]= {19,20,20,20,20,20,21,21,21,21,21,22,22,22,22,22,23,23,23,23,23,24,24,23};
134 int layer_m3_array[numberOfm3layers]= {23,24,24,24,24,25,25,25,25,25,26,26,26,26,26,27,27,27,27,27,28,28,28,28,28,29,29,29,29,28};
139 for (
i=0;
i<numberOfm1layers ;
i++){
141 acc +=layer_m1_array[
i];
146 for (
i=0;
i<numberOfm2layers;
i++){
148 acc +=layer_m2_array[
i];
153 for (
i=0;
i<numberOfm3layers;
i++){
155 acc +=layer_m3_array[
i];
166 int stnm=0, pad=0, previous_pad=1,
layer = 0, pad_rel_mod=0;
169 std::vector<std::vector<int> >
dummy1;
170 std::vector<int> dummy12;
171 std::vector<std::vector<int> >
dummy2;
173 std::vector<std::vector<int> >
dummy3;
174 std::vector<int> dummy32;
176 std::vector<std::vector<int> > dumdumdum1;
177 std::vector<std::vector<int> > dumdumdum2;
178 std::vector<std::vector<int> > dumdumdum3;
179 std::vector<int> dumdum ;
180 for (
unsigned int d =0;
d<=100;
d++ ) {
181 dumdumdum1.push_back(dumdum);
182 dumdumdum2.push_back(dumdum);
183 dumdumdum3.push_back(dumdum);
196 if (!(
layer==0))
break;
197 stnm = RDBVars__TRTElec->
getInt(
"STRAWNUM");
198 pad = RDBVars__TRTElec->
getInt(
"HVPADRELSTRAW");
199 pad_rel_mod = RDBVars__TRTElec->
getInt(
"HVPADRELMOD");
200 m_m1.push_back(pad_rel_mod);
201 if (pad==previous_pad) dummy12.push_back(stnm);
202 else if (pad != previous_pad) {
204 dummy1.push_back(dummy12);
206 dummy12.push_back(stnm);
208 chip=(RDBVars__TRTElec->
getDouble(
"CHIPRELSTRAW"));
210 (dumdumdum1[(
int)chip]).push_back(
straw+1);
223 if (!(
layer==1))
break;
224 stnm = RDBVars__TRTElec->
getInt(
"STRAWNUM");
225 pad = RDBVars__TRTElec->
getInt(
"HVPADRELSTRAW");
226 pad_rel_mod = RDBVars__TRTElec->
getInt(
"HVPADRELMOD");
227 m_m2.push_back(pad_rel_mod);
228 if (pad==previous_pad)
dummy22.push_back(stnm);
229 else if (pad != previous_pad) {
235 chip=(RDBVars__TRTElec->
getDouble(
"CHIPRELSTRAW"));
237 (dumdumdum2[(
int)chip]).push_back(
straw+1-329);
249 if (
straw>1641)
break;
252 if (!(
layer==2))
break;
253 stnm = RDBVars__TRTElec->
getInt(
"STRAWNUM");
254 pad = RDBVars__TRTElec->
getInt(
"HVPADRELSTRAW");
255 pad_rel_mod = RDBVars__TRTElec->
getInt(
"HVPADRELMOD");
256 m_m3.push_back(pad_rel_mod);
257 if (pad==previous_pad) dummy32.push_back(stnm);
258 else if (pad != previous_pad) {
260 dummy3.push_back(dummy32);
262 dummy32.push_back(stnm);
264 chip=(RDBVars__TRTElec->
getDouble(
"CHIPRELSTRAW"));
266 (dumdumdum3[(
int)chip]).push_back(
straw+1-329-520);
276 if (!((
m_m1.size()==330)&&(
m_m2.size()==521)&&(
m_m3.size()==794) ))
ATH_MSG_WARNING(
"Initialization of TRT_StrawNeighbourTool incomplete. Depending on usage, this can give rise to runtime problems");
280 int numberOfStraws[75] = {0,
304 int TripletOrientation[2][32] = {
317 for(
int j=0; j<2; j++)
318 for(
int jj=0; jj<32; jj++)
322 return StatusCode::SUCCESS;
336 return StatusCode::SUCCESS;
355 else if (moduleType==1) {
364 else if (moduleType==2) {
389 msg(MSG::ERROR) <<
"Sorry, getRunningNumbering only works for barrel" <<
endmsg;
401 strawnumber -=
straw;
403 else if (moduleType==1) {
405 strawnumber -=
straw;
407 else if (moduleType==2) {
409 strawnumber -=
straw;
419 msg(MSG::ERROR) <<
"Sorry, this only works for barrel"<<
endmsg;
449 else {
msg(MSG::ERROR) <<
"Something is very wrong: According to identifier, straw belongs to a barrel module which is not of type 1,2 or 3 (corresponding to offline numbering: layer_or_wheel = 0,1 or 2) " <<
endmsg;}
465 if (strawlayer%8 >= 4) chip++;
467 int nominal_reversed = 1 - ( (
phi -
phi%8)/8 ) %2 ;
477 else {
msg(MSG::ERROR) <<
"Something is very wrong: endcap chip mapping " <<
bec <<
endmsg; chip = 12; }
481 int board = layer_or_wheel;
482 if (board<6) { board *= 2;
if (strawlayer>7) board++; }
564 if (layer_or_wheel == 0) {
567 else if (layer_or_wheel == 1) {
570 else if (layer_or_wheel == 2){
573 else {
msg(MSG::ERROR) <<
"Something is very wrong: According to identifier, straw belongs to a barrel module which is not of type 1,2 or 3 (corresponding to offline numbering: layer_or_wheel = 0,1 or 2) " <<
endmsg;}
579 msg(MSG::WARNING) <<
" Sorry getPin only implemented for barrel so far. Returning pin=0 " <<
endmsg;
595 pad= temp_straw_layer*3+temp_straw+1;
604 strawnumber=strawnumber%1642;
609 pad =
m_m1[strawnumber];
612 else if (moduleType==1) {
613 pad =
m_m2[strawnumber];
616 else if (moduleType==2) {
617 pad =
m_m3[strawnumber];
620 msg(MSG::ERROR) <<
"Something went wrong: Pad not found, returning 0" <<
endmsg;
643 for (
int temp_it = temp_straw * 8 ; temp_it < temp_straw * 8 +8 ; temp_it++){
644 for (
int temp_it2 = temp_straw_layer * 4 ; temp_it2 < temp_straw_layer * 4 +4 ; temp_it2++){
651 neighbourIDs.push_back(outputID);
661 neighbourIDs.push_back(outputID);
663 msg(MSG::ERROR) <<
" Error in getStrawsFromPad. Returning "<<
endmsg;
690 for(
unsigned int i = 0 ;
i < 4 ;
i ++ ) {
691 for(
unsigned int j = 0 ; j < 4 ; j ++ ) {
707 ( straw_layer + j - local_straw_layer),
708 (
straw +
i - local_straw));
709 neighbourIDs.push_back(outputID);
719 int chip = 0, chiptest=-10;
726 neighbourIDs.push_back(outputID);
728 msg(MSG::ERROR) <<
" Error in getStrawsFromChip. Returning "<<
endmsg;
734 msg(MSG::ERROR) <<
"Attempt to use getStrawsFromChip based on a non-TRT identifier. barrel_ec(inputID) = " <<
m_trtid->
barrel_ec(inputID) <<
endmsg; }
759 ( straw_layer - local_straw_layer),
760 (
straw - local_straw ) );
772 else {
msg(MSG::ERROR) <<
"Attempt to use getFirstStrawFromChip based on a non-TRT identifier. barrel_ec(inputID) = "<<
m_trtid->
barrel_ec(inputID) <<
endmsg; }
785 int hardwarechip = 0;
787 if ( (chip<1) || (chip > 50) || (abs(
layer)>2) )
msg(MSG::ERROR) <<
"Attempt to use chipToBoard(int chip, int layer) with input outside bounds: 1<=chip<=50 and 0<=|layer|<=2 . Input was: chip = "<<chip<<
" layer = "<<
layer <<
endmsg;
789 if (abs(
layer)==0) hardwarechip = chip -1;
790 else if (abs(
layer)==1) hardwarechip = chip + 20;
791 else if (abs(
layer)==2) hardwarechip = chip + 20 + 33;
806 int list[] = {10, 11, 15, 9, 9, 11, 12, 13, 14};
808 for (
int i=0;
i<9;
i++) {
810 if (hardwarechip <
count)
return i;
815 msg(MSG::ERROR) <<
"Something went wrong in chipToBoardBarrel - please contact the author "<<
endmsg;
833 return (16*wheel + strawlayer) / 4;
835 return (16*6+8*(wheel-6) + strawlayer) /4;
861 int addToStrawNumber=0;
862 int addToStrawNumberNext=0;
890 else if (abs(
bec)==2) {
894 else if (
side==-2) phi1=31-phi_stack,
side=0;
907 if (strawlayerNumber>7) strawlayerNumber =
int(
strawNumber/24) + 8;
924 int strawNumberNew=0;
926 if(LayerNumber<6 && strawlayerNumber>7)
928 strawNumberNew=strawNumberNew+(384*LayerNumber);
929 strawNumberNew=strawNumberNew+192+(strawlayerNumber%8)+(
strawNumber*8);
931 else if(LayerNumber<6 && strawlayerNumber<8)
933 strawNumberNew=strawNumberNew+(384*LayerNumber);
934 strawNumberNew=strawNumberNew + (strawlayerNumber%8) + (
strawNumber*8);
937 else if(LayerNumber>5 && strawlayerNumber>7)
939 strawNumberNew = strawNumberNew + 2304 + 192*(LayerNumber-6);
940 strawNumberNew = strawNumberNew + 192 + (strawlayerNumber%8) + (8*
strawNumber);
942 else if(LayerNumber>5 && strawlayerNumber<8)
944 strawNumberNew = strawNumberNew + 2304 + 192*(LayerNumber-6);
945 strawNumberNew = strawNumberNew + (strawlayerNumber%8) + (8*
strawNumber);
953 msg(MSG::ERROR) <<
"corrupted input identifier to TRT_StrawNeighbourSvc::strawNumber(). barrel_ec=" <<
bec<<
endmsg;
974 else if(LayerNumber==1)
978 else if(LayerNumber==2)
986 msg(MSG::ERROR) <<
"Sorry, TRT_StrawNeighbourSvc::strawLayerNumber only works for barrel" <<
endmsg;