Skip to content

Commit 5da506a

Browse files
authored
Merge pull request #48466 from fabiocos/fc-ismtd20250702
MTD DetId: add static methods to MTDDetId to test whether it is BTL or ETL
2 parents 5d91099 + 8bafe85 commit 5da506a

File tree

3 files changed

+53
-0
lines changed

3 files changed

+53
-0
lines changed

DataFormats/ForwardDetId/interface/MTDDetId.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,18 @@ class MTDDetId : public DetId {
2626
/** Enumerated type for MTD sub-deteector systems. */
2727
enum MTDType { typeUNKNOWN = 0, BTL = 1, ETL = 2 };
2828

29+
static const uint32_t kMTDOffset = 25;
2930
static const uint32_t kMTDsubdOffset = 23;
3031
static const uint32_t kMTDsubdMask = 0x3;
3132
static const uint32_t kZsideOffset = 22;
3233
static const uint32_t kZsideMask = 0x1;
3334
static const uint32_t kRodRingOffset = 16;
3435
static const uint32_t kRodRingMask = 0x3F;
3536

37+
static constexpr uint32_t kMTDMask = 0x31; // DetId::Detector::Forward && MTDDetId::SubDetector::FastTime
38+
static constexpr uint32_t kBTLMask = 0xc5; // isMTD && MTDDetId::MTDType::BTL
39+
static constexpr uint32_t kETLMask = 0xc6; // isMTD && MTDDetId::MTDType::ETL
40+
3641
// ---------- Constructors, enumerated types ----------
3742

3843
/** Construct a null id */
@@ -55,6 +60,16 @@ class MTDDetId : public DetId {
5560
/** Returns enumerated type specifying MTD sub-detector, i.e. BTL or ETL. */
5661
inline int mtdSubDetector() const { return (id_ >> kMTDsubdOffset) & kMTDsubdMask; }
5762

63+
static inline bool const testForMTD(const DetId& id) {
64+
return (id.rawId() >> MTDDetId::kMTDOffset) == MTDDetId::kMTDMask;
65+
}
66+
static inline bool const testForBTL(const DetId& id) {
67+
return (id.rawId() >> MTDDetId::kMTDsubdOffset) == MTDDetId::kBTLMask;
68+
}
69+
static inline bool const testForETL(const DetId& id) {
70+
return (id.rawId() >> MTDDetId::kMTDsubdOffset) == MTDDetId::kETLMask;
71+
}
72+
5873
/** Returns MTD side, i.e. Z-=0 or Z+=1. */
5974
inline int mtdSide() const { return (id_ >> kZsideOffset) & kZsideMask; }
6075
/** Return MTD side, i.e. Z-=-1 or Z+=1. */

DataFormats/ForwardDetId/test/BuildFile.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,6 @@
44

55
<bin file="testHFNoseDetId.cc">
66
</bin>
7+
8+
<bin file="testMTD.cc">
9+
</bin>
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#include "DataFormats/ForwardDetId/interface/MTDDetId.h"
2+
#include "DataFormats/ForwardDetId/interface/BTLDetId.h"
3+
#include "DataFormats/ForwardDetId/interface/ETLDetId.h"
4+
#include "DataFormats/DetId/interface/DetId.h"
5+
6+
#include <iostream>
7+
#include <iomanip>
8+
#include <bitset>
9+
10+
int main() {
11+
DetId id;
12+
BTLDetId btlid;
13+
ETLDetId etlid;
14+
15+
auto printBits = [&](const uint32_t& id) {
16+
std::stringstream ss;
17+
ss << std::bitset<4>((id >> 28) & 0xF).to_string() << " " << std::bitset<4>((id >> 24) & 0xF).to_string() << " "
18+
<< std::bitset<4>((id >> 20) & 0xF).to_string() << " " << std::bitset<4>((id >> 16) & 0xF).to_string() << " "
19+
<< std::bitset<4>((id >> 12) & 0xF).to_string() << " " << std::bitset<4>((id >> 8) & 0xF).to_string() << " "
20+
<< std::bitset<4>((id >> 4) & 0xF).to_string() << " " << std::bitset<4>(id & 0xF).to_string();
21+
return ss.str();
22+
};
23+
24+
std::cout << "DetId " << std::setw(20) << id.rawId() << std::setw(40) << printBits(id.rawId()) << " mask "
25+
<< std::setw(40) << printBits(MTDDetId::kMTDMask) << " isMTD " << MTDDetId::testForMTD(id) << " isBTL "
26+
<< MTDDetId::testForBTL(id) << " isETL " << MTDDetId::testForETL(id) << std::endl;
27+
std::cout << "BTLDetId " << std::setw(20) << btlid.rawId() << std::setw(40) << printBits(btlid.rawId()) << " mask "
28+
<< std::setw(40) << printBits(MTDDetId::kBTLMask) << " isMTD " << MTDDetId::testForMTD(btlid) << " isBTL "
29+
<< MTDDetId::testForBTL(btlid) << " isETL " << MTDDetId::testForETL(btlid) << std::endl;
30+
std::cout << "ETLDetId " << std::setw(20) << etlid.rawId() << std::setw(40) << printBits(etlid.rawId()) << " mask "
31+
<< std::setw(40) << printBits(MTDDetId::kETLMask) << " isMTD " << MTDDetId::testForMTD(etlid) << " isBTL "
32+
<< MTDDetId::testForBTL(etlid) << " isETL " << MTDDetId::testForETL(etlid) << std::endl;
33+
34+
return 0;
35+
}

0 commit comments

Comments
 (0)