LDMX Software
EcalID.cxx
1#include "DetDescr/EcalID.h"
2
3#include "DetDescr/DetectorIDInterpreter.h"
4
5std::ostream& operator<<(std::ostream& s, const ldmx::EcalID& id) {
6 std::pair uv = id.getCellUV();
7 s << "Ecal(" << id.layer() << ',' << id.module() << ',' << id.cell() << '['
8 << uv.first << ',' << uv.second << "])";
9 return s;
10}
11
12namespace ldmx {
13
14void EcalID::createInterpreters() {
16 fields.push_back(new IDField("subdetector", 0, SUBDETECTORID_SHIFT, 31));
17 fields.push_back(
18 new IDField("layer", 1, LAYER_SHIFT,
19 LAYER_SHIFT + IDField::countOnes(LAYER_MASK) - 1));
20 fields.push_back(
21 new IDField("module", 2, MODULE_SHIFT,
22 MODULE_SHIFT + IDField::countOnes(MODULE_MASK) - 1));
23 fields.push_back(new IDField("cell", 3, CELL_SHIFT,
24 CELL_SHIFT + IDField::countOnes(CELL_MASK) - 1));
25
27 SD_ECAL,
28 EcalAbstractID::CELL_TYPE_MASK << EcalAbstractID::CELL_TYPE_SHIFT,
29 EcalAbstractID::PrecisionGlobal << EcalAbstractID::CELL_TYPE_SHIFT,
30 fields);
32 SD_ECAL,
33 EcalAbstractID::CELL_TYPE_MASK << EcalAbstractID::CELL_TYPE_SHIFT,
34 EcalAbstractID::PrecisionLocal << EcalAbstractID::CELL_TYPE_SHIFT,
35 fields);
36}
37
38static const unsigned int base_row_w = 13;
39static const unsigned int v_middle = 11;
40static const unsigned int max_v = 23;
41
42EcalID::EcalID(unsigned int layer, unsigned int module, unsigned int u,
43 unsigned int v)
44 : EcalAbstractID(EcalAbstractID::PrecisionGlobal, 0) {
45 id_ |= (layer & LAYER_MASK) << LAYER_SHIFT;
46 id_ |= (module & MODULE_MASK) << MODULE_SHIFT;
47
48 unsigned int cell = 0;
49 if (v > max_v) {
50 EXCEPTION_RAISE("InvalidIdException",
51 "Attempted to create EcalID with invalid (u,v)=(" +
52 std::to_string(u) + "," + std::to_string(v) + ")");
53 }
54
55 if (v <= v_middle) { // simple case...
56 if (u > (base_row_w - 1 + v)) {
57 EXCEPTION_RAISE("InvalidIdException",
58 "Attempted to create EcalID with invalid (u,v)=(" +
59 std::to_string(u) + "," + std::to_string(v) + ")");
60 }
61 cell = u + v * base_row_w + (v - 1) * v / 2;
62 } else {
63 unsigned int umin = v - v_middle;
64 static unsigned int umax = 23; // constant
65 unsigned int vrel = v - v_middle - 1;
66 if (u < umin || u > umax) {
67 EXCEPTION_RAISE("InvalidIdException",
68 "Attempted to create EcalID with invalid (u,v)=(" +
69 std::to_string(u) + "," + std::to_string(v) + ")");
70 }
71 cell = 222 + (u - umin) + vrel * base_row_w + 55 -
72 (v_middle - vrel - 1) * (v_middle - vrel) / 2;
73 }
74 id_ |= (cell & CELL_MASK) << CELL_SHIFT;
75}
76
77static const int row_starts[25] = {0, 13, 27, 42, 58, 75, 93, 112, 132,
78 153, 175, 198, 222, 245, 267, 288, 308, 327,
79 345, 362, 378, 393, 407, 420, -1};
80
81std::pair<unsigned int, unsigned int> EcalID::getCellUV() const {
82 int cell = getCellID();
83 unsigned int v;
84 for (v = 0; v < max_v && cell >= row_starts[v + 1]; v++)
85 ; // find the right v value
86 unsigned int u = cell - row_starts[v];
87 if (v > v_middle) u += (v - v_middle);
88 return std::pair<unsigned int, unsigned int>(u, v);
89}
90} // namespace ldmx
Class that defines an ECal detector ID with a cell number.
static void registerInterpreter(SubdetectorIDType idtype, const IDField::IDFieldList &fieldList)
Register a new field interpreter for a given subdetector id.
RawValue id_
The raw, packed value of the ID.
Definition DetectorID.h:84
Parent of precision and trigger EcalIDs.
Extension of DetectorID providing access to ECal layers and cell numbers in a hex grid.
Definition EcalID.h:20
int cell() const
Get the value of the cell field from the ID.
Definition EcalID.h:111
int getCellID() const
Get the value of the cell field from the ID.
Definition EcalID.h:117
std::pair< unsigned int, unsigned int > getCellUV() const
Get the cell u,v index assuming a CMS-standard 432-cell sensor.
Definition EcalID.cxx:81
EcalID()
Empty ECAL id (but not null!)
Definition EcalID.h:32
int layer() const
Get the value of the layer field from the ID.
Definition EcalID.h:99
static unsigned countOnes(unsigned mask)
Utility for counting number of 1 in a mask.
Definition IDField.cxx:33
std::vector< IDField * > IDFieldList
List of fields.
Definition IDField.h:25