@@ -8,28 +8,94 @@ MTDTopology::MTDTopology(const int& topologyMode, const BTLValues& btl, const ET
88 : mtdTopologyMode_(topologyMode), btlVals_(btl), etlVals_(etl) {}
99
1010std::pair<uint32_t , uint32_t > MTDTopology::btlIndex (const uint32_t detId) {
11- uint32_t iphi (0 ), ieta (0 );
12- return std::make_pair (iphi, ieta);
11+ size_t index (0 );
12+ bool found (false );
13+ for (const auto & theid : btlVals_.btlDetId_ ) {
14+ if (theid == detId) {
15+ found = true ;
16+ break ;
17+ }
18+ index++;
19+ }
20+ if (found) {
21+ return std::make_pair (btlVals_.btlPhi_ [index], btlVals_.btlEta_ [index]);
22+ } else {
23+ edm::LogWarning (" MTDTopology" ) << " Searching BTL topology for BTLDetId " << detId
24+ << " not in BTL geometry structure" ;
25+ return std::make_pair (std::numeric_limits<uint32_t >::max (), std::numeric_limits<uint32_t >::max ());
26+ }
1327}
1428
15- uint32_t MTDTopology::btlidFromIndex (const uint32_t iphi, const uint32_t ieta) { return 0 ; }
29+ uint32_t MTDTopology::btlidFromIndex (const uint32_t iphi, const uint32_t ieta) {
30+ uint32_t res (0 );
31+ for (uint32_t index = 0 ; index < btlVals_.nBTLmodules_ ; index++) {
32+ if (iphi == btlVals_.btlPhi_ [index] && ieta == btlVals_.btlEta_ [index]) {
33+ res = btlVals_.btlDetId_ [index];
34+ break ;
35+ }
36+ index++;
37+ }
38+ return res;
39+ }
1640
17- size_t MTDTopology::phishiftBTL (const uint32_t detid, const int phiShift) {
41+ uint32_t MTDTopology::phishiftBTL (const uint32_t detid, const int phiShift) {
1842 if (phiShift == 0 ) {
1943 edm::LogWarning (" MTDTopology" ) << " asking of a null phiShift in BTL" ;
2044 return failIndex_;
2145 }
22-
23- return failIndex_;
46+ // search for the next detector, check only sign from input
47+ int sh = phiShift > 0 ? 1 : -1 ;
48+ size_t index (0 );
49+ bool found (false );
50+ for (const auto & theid : btlVals_.btlDetId_ ) {
51+ if (theid == detid) {
52+ found = true ;
53+ break ;
54+ }
55+ index++;
56+ }
57+ if (found) {
58+ int newIndex = index + sh * btlVals_.nBTLeta_ ;
59+ if (newIndex > static_cast <int >(btlVals_.nBTLmodules_ )) {
60+ newIndex = newIndex - btlVals_.nBTLmodules_ ;
61+ } else if (newIndex < 1 ) {
62+ newIndex = newIndex + btlVals_.nBTLmodules_ ;
63+ }
64+ return newIndex;
65+ } else {
66+ edm::LogWarning (" MTDTopology" ) << " Searching for non existent BTLDetId " << detid;
67+ return failIndex_;
68+ }
2469}
2570
26- size_t MTDTopology::etashiftBTL (const uint32_t detid, const int etaShift) {
71+ uint32_t MTDTopology::etashiftBTL (const uint32_t detid, const int etaShift) {
2772 if (etaShift == 0 ) {
2873 edm::LogWarning (" MTDTopology" ) << " asking of a null etaShift in BTL" ;
2974 return failIndex_;
3075 }
31-
32- return failIndex_;
76+ // search for the next detector, check only sign from input
77+ int sh = etaShift > 0 ? 1 : -1 ;
78+ size_t index (0 );
79+ bool found (false );
80+ for (const auto & theid : btlVals_.btlDetId_ ) {
81+ if (theid == detid) {
82+ found = true ;
83+ break ;
84+ }
85+ index++;
86+ }
87+ if (found) {
88+ int newIndex = index + sh;
89+ if (newIndex < 1 || newIndex > static_cast <int >(btlVals_.nBTLmodules_ )) {
90+ return failIndex_;
91+ } else if (btlVals_.btlEta_ [newIndex] != btlVals_.btlEta_ [index]) {
92+ return failIndex_;
93+ }
94+ return newIndex;
95+ } else {
96+ edm::LogWarning (" MTDTopology" ) << " Searching for non existent BTLDetId " << detid;
97+ return failIndex_;
98+ }
3399}
34100
35101bool MTDTopology::orderETLSector (const GeomDet*& gd1, const GeomDet*& gd2) {
0 commit comments