CMS 3D CMS Logo

List of all members | Public Member Functions | Private Member Functions | Private Attributes
HGCalNumberingScheme Class Reference

#include <HGCalNumberingScheme.h>

Public Member Functions

uint32_t getUnitID (int layer, int module, int cell, int iz, const G4ThreeVector &pos, double &wt)
 assigns the det id to a hit More...
 
 HGCalNumberingScheme (const HGCalDDDConstants &hgc, const DetId::Detector &det, const std::string &name, const std::string &fileName)
 
 HGCalNumberingScheme ()=delete
 
 ~HGCalNumberingScheme ()
 

Private Member Functions

void checkPosition (uint32_t index, const G4ThreeVector &pos, bool matchOnly, bool debug) const
 

Private Attributes

const DetId::Detector det_
 
std::vector< int > dumpDets_
 
int firstLayer_
 
const HGCalDDDConstantshgcons_
 
std::vector< int > indices_
 
const HGCalGeometryMode::GeometryMode mode_
 
const std::string name_
 

Detailed Description

Definition at line 19 of file HGCalNumberingScheme.h.

Constructor & Destructor Documentation

◆ HGCalNumberingScheme() [1/2]

HGCalNumberingScheme::HGCalNumberingScheme ( const HGCalDDDConstants hgc,
const DetId::Detector det,
const std::string &  name,
const std::string &  fileName 
)

Definition at line 20 of file HGCalNumberingScheme.cc.

References edmScanValgrind::buffer, det_, dumpDets_, MillePedeFileConverter_cfg::fileName, firstLayer_, edm::FileInPath::fullPath(), HGCalDDDConstants::getLayerOffset(), HGCalGeometryMode::Hexagon8, HGCalGeometryMode::Hexagon8Cassette, HGCalGeometryMode::Hexagon8File, HGCalGeometryMode::Hexagon8Full, HGCalGeometryMode::Hexagon8Module, hgcons_, indices_, LEDCalibrationChannels::iphi, mps_monitormerge::items, phase1PixelTopology::layer, mode_, name_, relativeConstraints::ring, CaloSimUtils::splitString(), AlCaHLTBitMon_QueryRunRegistry::string, HGCalTileIndex::tileIndex(), HGCalDDDConstants::tileTrapezoid(), HGCalGeometryMode::Trapezoid, HGCalGeometryMode::TrapezoidCassette, HGCalGeometryMode::TrapezoidFile, HGCalGeometryMode::TrapezoidModule, HGCalDDDConstants::waferHexagon8File(), HGCalWaferIndex::waferIndex(), HGCalWaferIndex::waferU(), and HGCalWaferIndex::waferV().

24  : hgcons_(hgc), mode_(hgc.geomMode()), det_(det), name_(name) {
25 #ifdef EDM_ML_DEBUG
26  edm::LogVerbatim("HGCSim") << "Creating HGCalNumberingScheme for " << name_ << " Det " << det_ << " Mode " << mode_
32 #endif
34  if (!fileName.empty()) {
35  edm::FileInPath filetmp1("SimG4CMS/Calo/data/" + fileName);
36  std::string filetmp2 = filetmp1.fullPath();
37  std::ifstream fInput(filetmp2.c_str());
38  if (!fInput.good()) {
39  edm::LogVerbatim("HGCalSim") << "Cannot open file " << filetmp2;
40  } else {
41  char buffer[80];
42  while (fInput.getline(buffer, 80)) {
43  std::vector<std::string> items = CaloSimUtils::splitString(std::string(buffer));
44  if (items.size() > 2) {
45  if (hgcons_.waferHexagon8File()) {
46  int layer = std::atoi(items[0].c_str());
47  int waferU = std::atoi(items[1].c_str());
48  int waferV = std::atoi(items[2].c_str());
49  indices_.emplace_back(HGCalWaferIndex::waferIndex(layer, waferU, waferV, false));
50  } else if (hgcons_.tileTrapezoid()) {
51  int layer = std::atoi(items[0].c_str());
52  int ring = std::atoi(items[1].c_str());
53  int iphi = std::atoi(items[2].c_str());
55  }
56  } else if (items.size() == 1) {
57  int dumpdet = std::atoi(items[0].c_str());
58  dumpDets_.emplace_back(dumpdet);
59  }
60  }
61 #ifdef EDM_ML_DEBUG
62  edm::LogVerbatim("HGCalSim") << "Reads in " << indices_.size() << ":" << dumpDets_.size()
63  << " component information from " << filetmp2 << " Layer Offset " << firstLayer_;
64 #endif
65  fInput.close();
66  }
67  }
68 }
Log< level::Info, true > LogVerbatim
const DetId::Detector det_
const HGCalGeometryMode::GeometryMode mode_
int32_t waferU(const int32_t index)
const HGCalDDDConstants & hgcons_
int getLayerOffset() const
std::vector< int > indices_
constexpr std::array< uint8_t, layerIndexSize > layer
int32_t tileIndex(int32_t layer, int32_t ring, int32_t phi)
std::vector< std::string > splitString(const std::string &)
Definition: CaloSimUtils.cc:3
std::vector< int > dumpDets_
bool tileTrapezoid() const
int32_t waferIndex(int32_t layer, int32_t waferU, int32_t waferV, bool old=false)
bool waferHexagon8File() const
int32_t waferV(const int32_t index)
const std::string name_

◆ HGCalNumberingScheme() [2/2]

HGCalNumberingScheme::HGCalNumberingScheme ( )
delete

◆ ~HGCalNumberingScheme()

HGCalNumberingScheme::~HGCalNumberingScheme ( )

Definition at line 70 of file HGCalNumberingScheme.cc.

70  {
71 #ifdef EDM_ML_DEBUG
72  edm::LogVerbatim("HGCSim") << "Deleting HGCalNumberingScheme";
73 #endif
74 }
Log< level::Info, true > LogVerbatim

Member Function Documentation

◆ checkPosition()

void HGCalNumberingScheme::checkPosition ( uint32_t  index,
const G4ThreeVector &  pos,
bool  matchOnly,
bool  debug 
) const
private

Definition at line 175 of file HGCalNumberingScheme.cc.

References funct::abs(), debug, det_, HGC3DClusterGenMatchSelector_cfi::dR, PVValHelper::dx, PVValHelper::dy, DetId::HGCalEE, DetId::HGCalHSc, DetId::HGCalHSi, hgcons_, LEDCalibrationChannels::iphi, HGCalDDDConstants::locateCell(), HGCalDDDConstants::locateCellTrap(), match(), convertSQLiteXML::ok, diffTwoXMLs::r1, diffTwoXMLs::r2, HGCalDDDConstants::rangeR(), HGCalDDDConstants::rangeZ(), mathSSE::sqrt(), AlCaHLTBitMon_QueryRunRegistry::string, HGCalDDDConstants::waferFromPosition(), HGCalWaferIndex::waferU(), HGCalWaferIndex::waferV(), HGCalDDDConstants::waferZ(), geometryCSVtoXML::xx, geometryCSVtoXML::xy, testProducerWithPsetDescEmpty_cfi::z2, and TkClusParameters_cff::zrange.

Referenced by getUnitID().

175  {
176  std::pair<float, float> xy;
177  bool ok(false);
178  double z1(0), tolR(14.0), tolZ(1.0);
179  int lay(-1);
180  if (index == 0) {
181  } else if (DetId(index).det() == DetId::HGCalHSi) {
183  lay = id.layer();
184  xy = hgcons_.locateCell(lay, id.waferU(), id.waferV(), id.cellU(), id.cellV(), false, true);
185  z1 = hgcons_.waferZ(lay, false);
186  ok = true;
187  tolR = 14.0;
188  tolZ = 1.0;
189  } else if (DetId(index).det() == DetId::HGCalHSc) {
191  lay = id.layer();
192  xy = hgcons_.locateCellTrap(lay, id.ietaAbs(), id.iphi(), false);
193  z1 = hgcons_.waferZ(lay, false);
194  ok = true;
195  tolR = 50.0;
196  tolZ = 5.0;
197  }
198  if (ok) {
199  double r1 = std::sqrt(xy.first * xy.first + xy.second * xy.second);
200  double r2 = pos.perp();
201  double z2 = std::abs(pos.z());
202  std::pair<double, double> zrange = hgcons_.rangeZ(false);
203  std::pair<double, double> rrange = hgcons_.rangeR(z2, false);
204  bool match = (std::abs(r1 - r2) < tolR) && (std::abs(z1 - z2) < tolZ);
205  bool inok = ((r2 >= rrange.first) && (r2 <= rrange.second) && (z2 >= zrange.first) && (z2 <= zrange.second));
206  bool outok = ((r1 >= rrange.first) && (r1 <= rrange.second) && (z1 >= zrange.first) && (z1 <= zrange.second));
207  std::string ck = (((r1 < rrange.first - tolR) || (r1 > rrange.second + tolR) || (z1 < zrange.first - tolZ) ||
208  (z1 > zrange.second + tolZ))
209  ? "***** ERROR *****"
210  : "");
211  if (matchOnly && match)
212  ck = "";
213  if (!(match && inok && outok) || debug) {
214  edm::LogVerbatim("HGCSim") << "HGCalNumberingScheme::Detector " << det_ << " Layer " << lay << " R " << r2 << ":"
215  << r1 << ":" << rrange.first << ":" << rrange.second << " Z " << z2 << ":" << z1 << ":"
216  << zrange.first << ":" << zrange.second << " Match " << match << ":" << inok << ":"
217  << outok << " " << ck;
218  edm::LogVerbatim("HGCSim") << "Original " << pos.x() << ":" << pos.y() << " return " << xy.first << ":"
219  << xy.second;
220  if ((DetId(index).det() == DetId::HGCalEE) || (DetId(index).det() == DetId::HGCalHSi)) {
221  double wt = 0, xx = ((pos.z() > 0) ? pos.x() : -pos.x());
222  int waferU, waferV, cellU, cellV, waferType;
223  hgcons_.waferFromPosition(xx, pos.y(), lay, waferU, waferV, cellU, cellV, waferType, wt, false, false);
224  xy = hgcons_.locateCell(lay, waferU, waferV, cellU, cellV, false, true, true);
225  double dx = (xx - xy.first);
226  double dy = (pos.y() - xy.second);
227  double dR = std::sqrt(dx * dx + dy * dy);
228  ck = (dR > tolR) ? " ***** ERROR *****" : "";
229  edm::LogVerbatim("HGCSim") << "HGCalNumberingScheme " << HGCSiliconDetId(index) << " original position " << xx
230  << ":" << pos.y() << " derived " << xy.first << ":" << xy.second << " Difference "
231  << dR << ck;
232  }
233  }
234  }
235 }
std::pair< float, float > locateCellTrap(int lay, int ieta, int iphi, bool reco, bool debug=false) const
double waferZ(int layer, bool reco) const
Log< level::Info, true > LogVerbatim
void waferFromPosition(const double x, const double y, int &wafer, int &icell, int &celltyp) const
std::pair< double, double > rangeZ(bool reco) const
const DetId::Detector det_
int32_t waferU(const int32_t index)
const HGCalDDDConstants & hgcons_
T sqrt(T t)
Definition: SSEVec.h:19
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
std::pair< double, double > rangeR(double z, bool reco) const
Definition: DetId.h:17
#define debug
Definition: HDRShower.cc:19
std::pair< float, float > locateCell(int cell, int lay, int type, bool reco) const
int32_t waferV(const int32_t index)
std::pair< typename Association::data_type::first_type, double > match(Reference key, Association association, bool bestMatchByMaxValue)
Generic matching function.
Definition: Utils.h:10

◆ getUnitID()

uint32_t HGCalNumberingScheme::getUnitID ( int  layer,
int  module,
int  cell,
int  iz,
const G4ThreeVector &  pos,
double &  wt 
)

assigns the det id to a hit

Definition at line 76 of file HGCalNumberingScheme.cc.

References HGCalDDDConstants::assignCellTrap(), checkPosition(), debug, TauDecayModes::dec, det_, dumpDets_, spr::find(), firstLayer_, HGCalTypes::getUnpackedCellU(), HGCalTypes::getUnpackedCellV(), HGCalTypes::getUnpackedType(), HGCalTypes::getUnpackedU(), HGCalTypes::getUnpackedV(), HGCalGeometryMode::Hexagon8, HGCalGeometryMode::Hexagon8Cassette, HGCalGeometryMode::Hexagon8Module, HGCSiliconDetId::HGCalCoarseThick, hgcons_, indices_, phase1PixelTopology::layer, mode_, callgraph::module, name_, HGCalParameters::waferInfo::part, DetId::rawId(), relativeConstraints::ring, edm::second(), HGCScintillatorDetId::setSiPM(), HGCScintillatorDetId::setType(), HGCalDDDConstants::tileExist(), HGCalTileIndex::tileIndex(), HGCalDDDConstants::tileRings(), HGCalDDDConstants::tileSiPM(), HGCalDDDConstants::tileTrapezoid(), HGCalDDDConstants::tileType(), HGCalDDDConstants::waferFromPosition(), HGCalTypes::WaferFull, HGCalDDDConstants::waferHexagon8(), HGCalDDDConstants::waferHexagon8File(), HGCalWaferIndex::waferIndex(), HGCalDDDConstants::waferInfo(), HGCalDDDConstants::waferType(), HGCalWaferIndex::waferU(), HGCalWaferIndex::waferV(), and geometryCSVtoXML::xx.

76  {
77  // module is the copy number of the wafer as placed in the layer
78  uint32_t index(0);
79  wt = 1.0;
80 #ifdef EDM_ML_DEBUG
81  edm::LogVerbatim("HGCSim") << "HGCalNumberingScheme:: input Layer " << layer << " Module " << module << " Cell "
82  << cell << " iz " << iz << " Position " << pos;
83 #endif
84  if (hgcons_.waferHexagon8()) {
85  int cellU(0), cellV(0), waferType(-1), waferU(0), waferV(0);
86  if (cell >= 0) {
90  cellU = HGCalTypes::getUnpackedCellU(cell);
91  cellV = HGCalTypes::getUnpackedCellV(cell);
92  } else if (mode_ != HGCalGeometryMode::Hexagon8) {
93  double xx = (pos.z() > 0) ? pos.x() : -pos.x();
96  bool debug(false);
97  if (!indices_.empty()) {
98  int indx = HGCalWaferIndex::waferIndex(firstLayer_ + layer, wU, wV, false);
99  if (std::find(indices_.begin(), indices_.end(), indx) != indices_.end())
100  debug = true;
101  }
102  if (!dumpDets_.empty()) {
103  if ((std::find(dumpDets_.begin(), dumpDets_.end(), det_) != dumpDets_.end()) &&
105  debug = true;
106  }
107  hgcons_.waferFromPosition(xx, pos.y(), layer, waferU, waferV, cellU, cellV, waferType, wt, false, debug);
108  }
109  if (waferType >= 0) {
110  if (hgcons_.waferHexagon8File()) {
111  int type = hgcons_.waferType(layer, waferU, waferV, true);
112  if (type != waferType) {
113 #ifdef EDM_ML_DEBUG
114  edm::LogVerbatim("HGCSim") << "HGCalNumberingScheme:: " << name_ << " Layer|u|v|Index|module|cell " << layer
115  << ":" << waferU << ":" << waferV << ":"
116  << HGCalWaferIndex::waferIndex(layer, waferU, waferV, false) << ":" << module
117  << ":" << cell << " has a type mismatch " << waferType << ":" << type;
118 #endif
120  waferType = type;
121  }
122  }
123  index = HGCSiliconDetId(det_, iz, waferType, layer, waferU, waferV, cellU, cellV).rawId();
124 #ifdef EDM_ML_DEBUG
125  edm::LogVerbatim("HGCSim") << "OK WaferType " << waferType << " Wafer " << waferU << ":" << waferV << " Cell "
126  << cellU << ":" << cellV << " input " << cell << " wt " << wt << " Mode " << mode_;
127  } else {
128  edm::LogVerbatim("HGCSim") << "Bad WaferType " << waferType << " for Layer:u:v " << layer << ":" << waferU << ":"
129  << waferV;
130 #endif
131  }
132  } else if (hgcons_.tileTrapezoid()) {
133  std::array<int, 3> id = hgcons_.assignCellTrap(pos.x(), pos.y(), pos.z(), layer, false);
134  if (id[2] >= 0) {
135  int ring(id[0]);
136  if (!(hgcons_.tileExist(iz, layer, ring, id[1])) && ((ring + 1) <= (hgcons_.tileRings(layer)).second))
137  ++ring;
138  std::pair<int, int> typm = hgcons_.tileType(layer, ring, 0);
139  HGCScintillatorDetId detId(id[2], layer, iz * ring, id[1], false, 0);
140  if (typm.first >= 0) {
141  detId.setType(typm.first);
142  detId.setSiPM(typm.second);
143  }
144  index = detId.rawId();
145  bool debug(false);
146  if (!indices_.empty()) {
147  int indx = HGCalTileIndex::tileIndex(layer, id[0], id[1]);
148  if (std::find(indices_.begin(), indices_.end(), indx) != indices_.end())
149  debug = true;
150  }
151  if (debug)
152  edm::LogVerbatim("HGCSim") << "Radius/Phi " << ring << "(" << id[0] << "):" << id[1] << " Type " << id[2] << ":"
153  << typm.first << " SiPM " << typm.second << ":" << hgcons_.tileSiPM(typm.second)
154  << " Layer " << layer << " z " << iz << " " << detId << " wt " << wt << " position "
155  << pos << " R " << pos.perp();
156 #ifdef EDM_ML_DEBUG
157  } else {
158  edm::LogVerbatim("HGCSim") << "Radius/Phi " << id[0] << ":" << id[1] << " Type " << id[2] << " Layer|iz " << layer
159  << ":" << iz << " ERROR";
160 #endif
161  }
162  }
163 #ifdef EDM_ML_DEBUG
166  if (debug)
167  edm::LogVerbatim("HGCSim") << "HGCalNumberingScheme::i/p " << det_ << ":" << layer << ":" << module << ":" << cell
168  << ":" << iz << ":" << pos.x() << ":" << pos.y() << ":" << pos.z() << " ID " << std::hex
169  << index << std::dec << " wt " << wt;
170  checkPosition(index, pos, matchOnly, debug);
171 #endif
172  return index;
173 }
Log< level::Info, true > LogVerbatim
void waferFromPosition(const double x, const double y, int &wafer, int &icell, int &celltyp) const
const DetId::Detector det_
std::pair< int, int > tileRings(int layer) const
static int32_t getUnpackedCellU(int id)
Definition: HGCalTypes.cc:32
static int32_t getUnpackedU(int id)
Definition: HGCalTypes.cc:16
const HGCalGeometryMode::GeometryMode mode_
int32_t waferU(const int32_t index)
HGCalParameters::waferInfo waferInfo(int lay, int waferU, int waferV) const
const HGCalDDDConstants & hgcons_
static int32_t getUnpackedV(int id)
Definition: HGCalTypes.cc:22
bool waferHexagon8() const
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
std::vector< int > indices_
constexpr std::array< uint8_t, layerIndexSize > layer
U second(std::pair< T, U > const &p)
int32_t tileIndex(int32_t layer, int32_t ring, int32_t phi)
static constexpr int32_t WaferFull
Definition: HGCalTypes.h:35
int waferType(DetId const &id, bool fromFile=false) const
std::vector< int > dumpDets_
static int32_t getUnpackedType(int id)
Definition: HGCalTypes.cc:14
int tileSiPM(int sipm) const
bool tileTrapezoid() const
std::pair< int, int > tileType(int layer, int ring, int phi) const
int32_t waferIndex(int32_t layer, int32_t waferU, int32_t waferV, bool old=false)
std::array< int, 3 > assignCellTrap(float x, float y, float z, int lay, bool reco) const
#define debug
Definition: HDRShower.cc:19
bool tileExist(int zside, int layer, int ring, int phi) const
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
bool waferHexagon8File() const
void checkPosition(uint32_t index, const G4ThreeVector &pos, bool matchOnly, bool debug) const
static int32_t getUnpackedCellV(int id)
Definition: HGCalTypes.cc:34
int32_t waferV(const int32_t index)
const std::string name_

Member Data Documentation

◆ det_

const DetId::Detector HGCalNumberingScheme::det_
private

Definition at line 38 of file HGCalNumberingScheme.h.

Referenced by checkPosition(), getUnitID(), and HGCalNumberingScheme().

◆ dumpDets_

std::vector<int> HGCalNumberingScheme::dumpDets_
private

Definition at line 41 of file HGCalNumberingScheme.h.

Referenced by getUnitID(), and HGCalNumberingScheme().

◆ firstLayer_

int HGCalNumberingScheme::firstLayer_
private

Definition at line 40 of file HGCalNumberingScheme.h.

Referenced by getUnitID(), and HGCalNumberingScheme().

◆ hgcons_

const HGCalDDDConstants& HGCalNumberingScheme::hgcons_
private

Definition at line 36 of file HGCalNumberingScheme.h.

Referenced by checkPosition(), getUnitID(), and HGCalNumberingScheme().

◆ indices_

std::vector<int> HGCalNumberingScheme::indices_
private

Definition at line 42 of file HGCalNumberingScheme.h.

Referenced by getUnitID(), and HGCalNumberingScheme().

◆ mode_

const HGCalGeometryMode::GeometryMode HGCalNumberingScheme::mode_
private

Definition at line 37 of file HGCalNumberingScheme.h.

Referenced by getUnitID(), and HGCalNumberingScheme().

◆ name_

const std::string HGCalNumberingScheme::name_
private

Definition at line 39 of file HGCalNumberingScheme.h.

Referenced by getUnitID(), and HGCalNumberingScheme().