CMS 3D CMS Logo

HGCalNumberingScheme.cc
Go to the documentation of this file.
1 // File: HGCalNumberingScheme.cc
3 // Description: Numbering scheme for High Granularity Calorimeter
7 #include <iostream>
8 
9 //#define EDM_ML_DEBUG
10 
12  const DetId::Detector& det,
13  const std::string& name)
14  : hgcons_(hgc), mode_(hgc.geomMode()), det_(det), name_(name) {
15 #ifdef EDM_ML_DEBUG
16  edm::LogVerbatim("HGCSim") << "Creating HGCalNumberingScheme for " << name_ << " Det " << det_;
17 #endif
18 }
19 
21 #ifdef EDM_ML_DEBUG
22  edm::LogVerbatim("HGCSim") << "Deleting HGCalNumberingScheme";
23 #endif
24 }
25 
26 uint32_t HGCalNumberingScheme::getUnitID(int layer, int module, int cell, int iz, const G4ThreeVector& pos, double& wt) {
27  // module is the copy number of the wafer as placed in the layer
28  uint32_t index(0);
29  wt = 1.0;
30 #ifdef EDM_ML_DEBUG
31  edm::LogVerbatim("HGCSim")
32  << "HGCalNumberingScheme:: input Layer " << layer << " Module " << module
33  << " Cell " << cell << " iz " << iz << " Position " << pos << " Mode "
34  << mode_ << ":" << HGCalGeometryMode::Hexagon8Full << ":"
36 #endif
38  int cellU(0), cellV(0), waferType(-1), waferU(0), waferV(0);
39  if (cell >= 0) {
40  waferType = module / 1000000;
41  waferU = module % 100;
42  if ((module / 10000) % 10 > 0)
43  waferU = -waferU;
44  waferV = (module / 100) % 100;
45  if ((module / 100000) % 10 > 0)
46  waferV = -waferV;
47  cellU = cell % 100;
48  cellV = (cell / 100) % 100;
49  } else if (mode_ == HGCalGeometryMode::Hexagon8Full) {
50  double xx = (pos.z() > 0) ? pos.x() : -pos.x();
51  hgcons_.waferFromPosition(xx, pos.y(), layer, waferU, waferV, cellU, cellV, waferType, wt);
52  }
53  if (waferType >= 0) {
54  index = HGCSiliconDetId(det_, iz, waferType, layer, waferU, waferV, cellU, cellV).rawId();
55 #ifdef EDM_ML_DEBUG
56  edm::LogVerbatim("HGCSim")
57  << "OK WaferType " << waferType << " Wafer " << waferU << ":" << waferV
58  << " Cell " << cellU << ":" << cellV;
59  } else {
60  edm::LogVerbatim("HGCSim") << "Bad WaferType " << waferType;
61 #endif
62  }
63  } else if (mode_ == HGCalGeometryMode::Trapezoid) {
64  std::array<int, 3> id = hgcons_.assignCellTrap(pos.x(), pos.y(), pos.z(), layer, false);
65  if (id[2] >= 0) {
66  index = HGCScintillatorDetId(id[2], layer, iz * id[0], id[1]).rawId();
67 #ifdef EDM_ML_DEBUG
68  edm::LogVerbatim("HGCSim")
69  << "Radius/Phi " << id[0] << ":" << id[1] << " Type " << id[2]
70  << " Layer|iz " << layer << ":" << iz << " "
71  << HGCScintillatorDetId(index);
72  } else {
73  edm::LogVerbatim("HGCSim")
74  << "Radius/Phi " << id[0] << ":" << id[1] << " Type " << id[2]
75  << " Layer|iz " << layer << ":" << iz << " ERROR";
76 #endif
77  }
78  }
79 #ifdef EDM_ML_DEBUG
80  edm::LogVerbatim("HGCSim")
81  << "HGCalNumberingScheme::i/p " << det_ << ":" << layer << ":" << module
82  << ":" << cell << ":" << iz << ":" << pos.x() << ":" << pos.y() << ":"
83  << pos.z() << " ID " << std::hex << index << std::dec << " wt " << wt;
84  checkPosition(index, pos);
85  }
86 #endif
87  return index;
88 }
89 
90 void HGCalNumberingScheme::checkPosition(uint32_t index, const G4ThreeVector& pos) const {
91  std::pair<float, float> xy;
92  bool ok(false);
93  double z1(0), drMax(10.0), dzMax(1.0);
94  int lay(-1);
95  if (index == 0) {
96  } else if (DetId(index).det() == DetId::HGCalHSi) {
97  HGCSiliconDetId id = HGCSiliconDetId(index);
98  lay = id.layer();
99  xy = hgcons_.locateCell(lay, id.waferU(), id.waferV(), id.cellU(), id.cellV(), false, true);
100  z1 = hgcons_.waferZ(lay, false);
101  ok = true;
102  drMax = 10.0;
103  dzMax = 1.0;
104  } else if (DetId(index).det() == DetId::HGCalHSc) {
106  lay = id.layer();
107  xy = hgcons_.locateCellTrap(lay, id.ietaAbs(), id.iphi(), false);
108  z1 = hgcons_.waferZ(lay, false);
109  ok = true;
110  drMax = 50.0;
111  dzMax = 5.0;
112  }
113  if (ok) {
114  double r1 = std::sqrt(xy.first * xy.first + xy.second * xy.second);
115  double r2 = pos.perp();
116  double z2 = std::abs(pos.z());
117  std::pair<double, double> zrange = hgcons_.rangeZ(false);
118  std::pair<double, double> rrange = hgcons_.rangeR(z2, false);
119  bool match = (std::abs(r1 - r2) < drMax) && (std::abs(z1 - z2) < dzMax);
120  bool inok = ((r2 >= rrange.first) && (r2 <= rrange.second) && (z2 >= zrange.first) && (z2 <= zrange.second));
121  bool outok = ((r1 >= rrange.first) && (r1 <= rrange.second) && (z1 >= zrange.first) && (z1 <= zrange.second));
122  std::string ck = (((r1 < rrange.first - 10.0) || (r1 > rrange.second +10.0) ||
123  (z1 < zrange.first - 5.0) || (z1 > zrange.second + 5.0)) ?
124  "***** ERROR *****" : "");
125  if (!(match && inok && outok)) {
126  edm::LogVerbatim("HGCSim")
127  << "HGCalNumberingScheme::Detector " << det_ << " Layer " << lay << " R "
128  << r2 << ":" << r1 << ":" << rrange.first << ":" << rrange.second << " Z "
129  << z2 << ":" << z1 << ":" << zrange.first << ":" << zrange.second
130  << " Match " << match << ":" << inok << ":" << outok << " " << ck;
131  edm::LogVerbatim("HGCSim")
132  << "Original " << pos.x() << ":" << pos.y() << " return " << xy.first
133  << ":" << xy.second;
134  if (DetId(index).det() == DetId::HGCalHSi) {
135  double wt = 0, xx = ((pos.z() > 0) ? pos.x() : -pos.x());
136  int waferU, waferV, cellU, cellV, waferType;
137  hgcons_.waferFromPosition(xx, pos.y(), lay, waferU, waferV, cellU, cellV, waferType, wt, true);
138  xy = hgcons_.locateCell(lay, waferU, waferV, cellU, cellV, false, true, true);
139  edm::LogVerbatim("HGCSim")
140  << "HGCalNumberingScheme " << HGCSiliconDetId(index) << " position "
141  << xy.first << ":" << xy.second;
142  }
143  }
144  }
145 }
HGCalNumberingScheme()=delete
void waferFromPosition(const double x, const double y, int &wafer, int &icell, int &celltyp) const
const HGCalGeometryMode::GeometryMode mode_
const HGCalDDDConstants & hgcons_
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:50
std::pair< float, float > locateCell(int cell, int lay, int type, bool reco) const
std::pair< double, double > rangeR(double z, bool reco) const
std::pair< double, double > rangeZ(bool reco) const
T sqrt(T t)
Definition: SSEVec.h:18
std::pair< float, float > locateCellTrap(int lay, int ieta, int iphi, bool reco) const
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
double waferZ(int layer, bool reco) const
Definition: DetId.h:18
uint32_t getUnitID(int layer, int module, int cell, int iz, const G4ThreeVector &pos, double &wt)
assigns the det id to a hit
Detector
Definition: DetId.h:26
void checkPosition(uint32_t index, const G4ThreeVector &pos) const
std::array< int, 3 > assignCellTrap(float x, float y, float z, int lay, bool reco) const
std::pair< typename Association::data_type::first_type, double > match(Reference key, Association association, bool bestMatchByMaxValue)
Generic matching function.
Definition: Utils.h:10
Definition: vlib.h:208