Skip to content

Commit 24b649f

Browse files
committed
Implement BTL topology navigation
1 parent 2e1c7f6 commit 24b649f

File tree

3 files changed

+106
-15
lines changed

3 files changed

+106
-15
lines changed

Geometry/MTDGeometryBuilder/interface/MTDTopology.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ class MTDTopology {
1414
public:
1515
struct BTLLayout {
1616
// number of logical rods, i.e. rows of sensor modules along eta/z in phi, and of modules per rod
17-
static constexpr size_t nBTLphi_ = BTLDetId::HALF_ROD * BTLDetId::kModulesPerTrkV2;
18-
static constexpr size_t nBTLeta_ =
17+
static constexpr uint32_t nBTLphi_ = BTLDetId::HALF_ROD * BTLDetId::kModulesPerTrkV2;
18+
static constexpr uint32_t nBTLeta_ =
1919
2 * BTLDetId::kRUPerTypeV2 * BTLDetId::kCrystalTypes * BTLDetId::kModulesPerRUV2 / BTLDetId::kModulesPerTrkV2;
20-
static constexpr size_t nBTLmodules_ = nBTLphi_ * nBTLeta_;
20+
static constexpr uint32_t nBTLmodules_ = nBTLphi_ * nBTLeta_;
2121

2222
std::array<uint32_t, nBTLmodules_> btlDetId_;
2323
std::array<uint32_t, nBTLmodules_> btlPhi_;
@@ -47,8 +47,8 @@ class MTDTopology {
4747

4848
// BTL topology navigation methods, find index of closest module along eta or phi
4949

50-
size_t phishiftBTL(const uint32_t detid, const int phiShift);
51-
size_t etashiftBTL(const uint32_t detid, const int etaShift);
50+
uint32_t phishiftBTL(const uint32_t detid, const int phiShift);
51+
uint32_t etashiftBTL(const uint32_t detid, const int etaShift);
5252

5353
// ETL topology navigation is based on a predefined order of dets in sector
5454

Geometry/MTDGeometryBuilder/plugins/MTDTopologyEP.cc

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class MTDTopologyEP : public edm::ESProducer {
2727
ReturnType produce(const MTDTopologyRcd&);
2828

2929
private:
30-
void fillBTLtopology(const MTDGeometry&, MTDTopology::BTLValues&) {};
30+
void fillBTLtopology(const MTDGeometry&, MTDTopology::BTLValues&);
3131
void fillETLtopology(const PMTDParameters&, int& mtdTopologyMode, MTDTopology::ETLValues&);
3232

3333
edm::ESGetToken<MTDGeometry, MTDDigiGeometryRecord> mtdgeoToken_;
@@ -50,13 +50,38 @@ MTDTopologyEP::ReturnType MTDTopologyEP::produce(const MTDTopologyRcd& iRecord)
5050
MTDTopology::BTLValues btlVals;
5151
MTDTopology::ETLValues etlVals;
5252

53+
// build BTL topology content from MTDGeometry
54+
5355
fillBTLtopology(iRecord.get(mtdgeoToken_), btlVals);
5456

57+
// build ETL topology and topology mode information from PMTDParameters
58+
5559
fillETLtopology(iRecord.get(mtdparToken_), mtdTopologyMode, etlVals);
5660

5761
return std::make_unique<MTDTopology>(mtdTopologyMode, btlVals, etlVals);
5862
}
5963

64+
void MTDTopologyEP::fillBTLtopology(const MTDGeometry& mtdgeo, MTDTopology::BTLValues& btlVals) {
65+
MTDTopology::BTLLayout tmpLayout;
66+
uint32_t index(0), iphi(1), ieta(0);
67+
if (mtdgeo.detsBTL().size() != tmpLayout.nBTLmodules_) {
68+
throw cms::Exception("MTDTopologyEP") << "Inconsistent size of BTL structure arrays";
69+
}
70+
for (const auto& det : mtdgeo.detsBTL()) {
71+
ieta++;
72+
73+
tmpLayout.btlDetId_[index] = det->geographicalId().rawId();
74+
tmpLayout.btlPhi_[index] = iphi;
75+
tmpLayout.btlEta_[index] = ieta;
76+
if (ieta == tmpLayout.nBTLeta_) {
77+
iphi++;
78+
ieta = 0;
79+
}
80+
index++;
81+
}
82+
btlVals = tmpLayout;
83+
}
84+
6085
void MTDTopologyEP::fillETLtopology(const PMTDParameters& ptp, int& mtdTopologyMode, MTDTopology::ETLValues& etlVals) {
6186
mtdTopologyMode = ptp.topologyMode_;
6287

Geometry/MTDGeometryBuilder/src/MTDTopology.cc

Lines changed: 75 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,28 +8,94 @@ MTDTopology::MTDTopology(const int& topologyMode, const BTLValues& btl, const ET
88
: mtdTopologyMode_(topologyMode), btlVals_(btl), etlVals_(etl) {}
99

1010
std::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

35101
bool MTDTopology::orderETLSector(const GeomDet*& gd1, const GeomDet*& gd2) {

0 commit comments

Comments
 (0)