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_
17  << " Det " << det_;
18 #endif
19 }
20 
22 #ifdef EDM_ML_DEBUG
23  edm::LogVerbatim("HGCSim") << "Deleting HGCalNumberingScheme";
24 #endif
25 }
26 
27 uint32_t HGCalNumberingScheme::getUnitID(int layer, int module, int cell,
28  int iz, const G4ThreeVector &pos,
29  double& wt) {
30  // module is the copy number of the wafer as placed in the layer
31  uint32_t index(0);
32  wt = 1.0;
35  int cellU(0), cellV(0), waferType(-1), waferU(0), waferV(0);
36  if (cell >= 0) {
37  waferType = module/1000000;
38  waferU = module%100;
39  if ((module/10000)%10 > 0) waferU = -waferU;
40  waferV = (module/100)%100;
41  if ((module/100000)%10 > 0) waferV = -waferV;
42  cellU = cell%100;
43  cellV = (cell/100)%100;
44  } else if (mode_ == HGCalGeometryMode::Hexagon8Full) {
45  double xx = (pos.z() > 0) ? pos.x() : -pos.x();
46  hgcons_.waferFromPosition(xx,pos.y(),layer,waferU,waferV,cellU,
47  cellV,waferType,wt);
48  }
49  if (waferType >= 0) {
50  index = HGCSiliconDetId(det_,iz,waferType,layer,waferU,waferV,
51  cellU,cellV).rawId();
52 #ifdef EDM_ML_DEBUG
53  edm::LogVerbatim("HGCSim") << "OK WaferType " << waferType << " Wafer "
54  << waferU << ":" << waferV << " Cell "
55  << cellU << ":" << cellV;
56  } else {
57  edm::LogVerbatim("HGCSim") << "Bad WaferType " << waferType;
58 #endif
59  }
60  } else if (mode_ == HGCalGeometryMode::Trapezoid) {
61  std::array<int,3> id = hgcons_.assignCellTrap(pos.x(),pos.y(),pos.z(),
62  layer,false);
63  if (id[2] >= 0) {
64  index = HGCScintillatorDetId(id[2], layer, iz*id[0], id[1]).rawId();
65 #ifdef EDM_ML_DEBUG
66  edm::LogVerbatim("HGCSim") << "Radius/Phi " << id[0] << ":" << id[1]
67  << " Type " << id[2] << " Layer|iz "
68  << layer << ":" << iz << " "
69  << HGCScintillatorDetId(index);
70  } else {
71  edm::LogVerbatim("HGCSim") << "Radius/Phi " << id[0] << ":" << id[1]
72  << " Type " << id[2] << " Layer|iz " << layer
73  << ":" << iz;
74 #endif
75  }
76 
77  }
78 #ifdef EDM_ML_DEBUG
79  edm::LogVerbatim("HGCSim") << "HGCalNumberingScheme::i/p " << det_ << ":"
80  << layer << ":" << module << ":" << cell << ":"
81  << iz << ":" << pos.x() << ":" << pos.y() << ":"
82  << pos.z() << " ID " << std::hex << index
83  << std::dec << " wt " << wt;
84  checkPosition(index,pos);
85 #endif
86  return index;
87 }
88 
90  const G4ThreeVector &pos) const {
91 
92  std::pair<float,float> xy;
93  bool ok(false);
94  double z1(0), drMax(10.0), dzMax(1.0);
95  int lay(-1);
96  if (index == 0) {
97  } else if (DetId(index).det() == DetId::HGCalHSi) {
98  HGCSiliconDetId id = HGCSiliconDetId(index);
99  lay= id.layer();
100  xy = hgcons_.locateCell(lay,id.waferU(),id.waferV(),id.cellU(),
101  id.cellV(),false,true);
102  z1 = hgcons_.waferZ(lay,false);
103  ok = true;
104  drMax = 10.0; dzMax = 1.0;
105  } else if (DetId(index).det() == DetId::HGCalHSc) {
107  lay= id.layer();
108  xy = hgcons_.locateCellTrap(lay,id.ietaAbs(),id.iphi(),false);
109  z1 = hgcons_.waferZ(lay,false);
110  ok = true;
111  drMax = 50.0; 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) &&
121  (z2 >= zrange.first) && (z2 <= zrange.second));
122  bool outok= ((r1 >= rrange.first) && (r1 <= rrange.second) &&
123  (z1 >= zrange.first) && (z1 <= zrange.second));
124  std::string ck = (((r1 < rrange.first-10.0) || (r1 > rrange.second+10.0) ||
125  (z1 < zrange.first-5.0) || (z1 > zrange.second+5.0)) ?
126  "***** ERROR *****" : "");
127  if (!(match && inok && outok)) {
128  edm::LogVerbatim("HGCSim") << "HGCalNumberingScheme::Detector " << det_
129  << " Layer " << lay << " R " << r2 << ":"
130  << r1 << ":" << rrange.first << ":"
131  << rrange.second << " Z " << z2 << ":" << z1
132  << ":" << zrange.first << ":" << zrange.second
133  << " Match " << match << ":" << inok << ":"
134  << outok << " " << ck;
135  edm::LogVerbatim("HGCSim") << "Original " << pos.x() << ":" << pos.y()
136  << " return " << xy.first << ":" << xy.second;
137  if (DetId(index).det() == DetId::HGCalHSi) {
138  double wt=0, xx = ((pos.z() > 0) ? pos.x() : -pos.x());
139  int waferU,waferV,cellU,cellV,waferType;
140  hgcons_.waferFromPosition(xx,pos.y(),lay,waferU,waferV,cellU,
141  cellV,waferType,wt,true);
142  xy = hgcons_.locateCell(lay,waferU,waferV,cellU,cellV,false,true,true);
143  edm::LogVerbatim("HGCSim") << "HGCalNumberingScheme "
144  << HGCSiliconDetId(index) << " position "
145  << xy.first << ":" << xy.second;
146  }
147  }
148  }
149 }
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:47
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