3#include "DetDescr/DetectorIDInterpreter.h"
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 <<
"])";
14void EcalID::createInterpreters() {
16 fields.push_back(
new IDField(
"subdetector", 0, SUBDETECTORID_SHIFT, 31));
18 new IDField(
"layer", 1, LAYER_SHIFT,
21 new IDField(
"module", 2, MODULE_SHIFT,
23 fields.push_back(
new IDField(
"cell", 3, CELL_SHIFT,
28 EcalAbstractID::CELL_TYPE_MASK << EcalAbstractID::CELL_TYPE_SHIFT,
29 EcalAbstractID::PrecisionGlobal << EcalAbstractID::CELL_TYPE_SHIFT,
33 EcalAbstractID::CELL_TYPE_MASK << EcalAbstractID::CELL_TYPE_SHIFT,
34 EcalAbstractID::PrecisionLocal << EcalAbstractID::CELL_TYPE_SHIFT,
38static const unsigned int base_row_w = 13;
39static const unsigned int v_middle = 11;
40static const unsigned int max_v = 23;
45 id_ |= (
layer & LAYER_MASK) << LAYER_SHIFT;
46 id_ |= (
module & MODULE_MASK) << MODULE_SHIFT;
48 unsigned int cell = 0;
50 EXCEPTION_RAISE(
"InvalidIdException",
51 "Attempted to create EcalID with invalid (u,v)=(" +
52 std::to_string(u) +
"," + std::to_string(v) +
")");
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) +
")");
61 cell = u + v * base_row_w + (v - 1) * v / 2;
63 unsigned int umin = v - v_middle;
64 static unsigned int umax = 23;
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) +
")");
71 cell = 222 + (u - umin) + vrel * base_row_w + 55 -
72 (v_middle - vrel - 1) * (v_middle - vrel) / 2;
74 id_ |= (
cell & CELL_MASK) << CELL_SHIFT;
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};
84 for (v = 0; v < max_v && cell >= row_starts[v + 1]; v++)
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);
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.
Parent of precision and trigger EcalIDs.
Extension of DetectorID providing access to ECal layers and cell numbers in a hex grid.
int cell() const
Get the value of the cell field from the ID.
int getCellID() const
Get the value of the cell field from the ID.
std::pair< unsigned int, unsigned int > getCellUV() const
Get the cell u,v index assuming a CMS-standard 432-cell sensor.
EcalID()
Empty ECAL id (but not null!)
int layer() const
Get the value of the layer field from the ID.
static unsigned countOnes(unsigned mask)
Utility for counting number of 1 in a mask.
std::vector< IDField * > IDFieldList
List of fields.