Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 14:29:08

0001 ///////////////////////////////////////////////////////////////////////////////
0002 // File: HGCNumberingScheme.cc
0003 // Description: Numbering scheme for High Granularity Calorimeter
0004 ///////////////////////////////////////////////////////////////////////////////
0005 #include "SimG4CMS/Calo/interface/HGCNumberingScheme.h"
0006 #include "SimDataFormats/CaloTest/interface/HGCalTestNumbering.h"
0007 #include "Geometry/HGCalCommonData/interface/HGCalGeometryMode.h"
0008 #include "DataFormats/Math/interface/FastMath.h"
0009 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0010 
0011 #include "DataFormats/ForwardDetId/interface/HGCalDetId.h"
0012 
0013 #include "CLHEP/Units/GlobalSystemOfUnits.h"
0014 #include <iostream>
0015 
0016 //#define EDM_ML_DEBUG
0017 
0018 HGCNumberingScheme::HGCNumberingScheme(const HGCalDDDConstants& hgc, std::string& name) : hgcons_(hgc) {
0019   edm::LogVerbatim("HGCSim") << "Creating HGCNumberingScheme for " << name;
0020 }
0021 
0022 HGCNumberingScheme::~HGCNumberingScheme() { edm::LogVerbatim("HGCSim") << "Deleting HGCNumberingScheme"; }
0023 
0024 uint32_t HGCNumberingScheme::getUnitID(
0025     ForwardSubdetector subdet, int layer, int module, int cell, int iz, const G4ThreeVector& pos) {
0026   // module is the copy number of the wafer as placed in the layer
0027   int icell(0), celltyp(0), wafer(0);
0028   uint32_t index(0);
0029   if (hgcons_.geomMode() == HGCalGeometryMode::HexagonFull) {
0030     if (cell >= 0) {
0031       wafer = hgcons_.waferFromCopy(module);
0032       celltyp = cell / 1000;
0033       icell = cell % 1000;
0034     } else {
0035       hgcons_.waferFromPosition(pos.x(), pos.y(), wafer, icell, celltyp);
0036     }
0037     if (wafer >= 0) {
0038       if (celltyp != 1)
0039         celltyp = 0;
0040       index = HGCalTestNumbering::packHexagonIndex((int)subdet, iz, layer, wafer, celltyp, icell);
0041     }
0042   } else if (hgcons_.geomMode() == HGCalGeometryMode::Hexagon) {
0043     wafer = hgcons_.waferFromCopy(module);
0044     celltyp = cell / 1000;
0045     icell = cell % 1000;
0046     if (celltyp != 1)
0047       celltyp = 0;
0048 
0049     index = HGCalTestNumbering::packHexagonIndex((int)subdet, iz, layer, wafer, celltyp, icell);
0050     //check if it fits
0051     if (!hgcons_.isValidHex(layer, wafer, icell, false)) {
0052       index = 0;
0053       edm::LogError("HGCSim") << "[HGCNumberingScheme] ID out of bounds :"
0054                               << " Subdet= " << subdet << " Zside= " << iz << " Layer= " << layer << " Wafer= " << wafer
0055                               << ":" << module << " CellType= " << celltyp << " Cell= " << icell;
0056     }
0057   }
0058 #ifdef EDM_ML_DEBUG
0059   int subd, zside, lay, sector, subsector, cellx;
0060   HGCalTestNumbering::unpackHexagonIndex(index, subd, zside, lay, sector, subsector, cellx);
0061   edm::LogVerbatim("HGCSim") << "HGCNumberingScheme::i/p " << subdet << ":" << layer << ":" << module << ":" << iz
0062                              << ":" << wafer << ":" << celltyp << ":" << icell << ":" << std::hex << index << std::dec
0063                              << " Output " << subd << ":" << lay << ":" << zside << ":" << sector << ":" << subsector
0064                              << ":" << cellx;
0065 #endif
0066   return index;
0067 }
0068 
0069 int HGCNumberingScheme::assignCell(float x, float y, int layer) {
0070   std::pair<int, int> phicell = hgcons_.assignCell(x, y, layer, 0, false);
0071   return phicell.second;
0072 }
0073 
0074 std::pair<float, float> HGCNumberingScheme::getLocalCoords(int cell, int layer) {
0075   return hgcons_.locateCell(cell, layer, 0, false);
0076 }