Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 ///////////////////////////////////////////////////////////////////////////////
0002 // File: HFNoseNumberingScheme.cc
0003 // Description: Numbering scheme for HFNose detector
0004 ///////////////////////////////////////////////////////////////////////////////
0005 #include "SimG4CMS/Calo/interface/HFNoseNumberingScheme.h"
0006 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0007 #include "Geometry/HGCalCommonData/interface/HGCalTypes.h"
0008 #include <iostream>
0009 
0010 //#define EDM_ML_DEBUG
0011 
0012 HFNoseNumberingScheme::HFNoseNumberingScheme(const HGCalDDDConstants& hgc) : hgcons_(hgc), mode_(hgc.geomMode()) {
0013 #ifdef EDM_ML_DEBUG
0014   edm::LogVerbatim("HGCSim") << "Creating HFNoseNumberingScheme";
0015 #endif
0016 }
0017 
0018 uint32_t HFNoseNumberingScheme::getUnitID(
0019     int layer, int module, int cell, int iz, const G4ThreeVector& pos, double& wt) {
0020   // module is the copy number of the wafer as placed in the layer
0021   uint32_t index(0);
0022   wt = 1.0;
0023   int cellU(0), cellV(0), waferType(-1), waferU(0), waferV(0);
0024   if (cell >= 0) {
0025     waferType = HGCalTypes::getUnpackedType(module);
0026     waferU = HGCalTypes::getUnpackedU(module);
0027     waferV = HGCalTypes::getUnpackedV(module);
0028     cellU = HGCalTypes::getUnpackedCellU(cell);
0029     cellV = HGCalTypes::getUnpackedCellV(cell);
0030   } else if (mode_ == HGCalGeometryMode::Hexagon8Full) {
0031     double xx = (pos.z() > 0) ? pos.x() : -pos.x();
0032     hgcons_.waferFromPosition(xx, pos.y(), layer, waferU, waferV, cellU, cellV, waferType, wt);
0033   }
0034   if (waferType >= 0) {
0035     index = HFNoseDetId(iz, waferType, layer, waferU, waferV, cellU, cellV).rawId();
0036 #ifdef EDM_ML_DEBUG
0037     edm::LogVerbatim("HFNSim") << "OK WaferType " << waferType << " Wafer " << waferU << ":" << waferV << " Cell "
0038                                << cellU << ":" << cellV;
0039   } else {
0040     edm::LogVerbatim("HFNSim") << "Bad WaferType " << waferType;
0041 #endif
0042   }
0043 #ifdef EDM_ML_DEBUG
0044   edm::LogVerbatim("HFNSim") << "HFNoseNumberingScheme::i/p " << layer << ":" << module << ":" << cell << ":" << iz
0045                              << ":" << pos.x() << ":" << pos.y() << ":" << pos.z() << " ID " << std::hex << index
0046                              << std::dec << " wt " << wt;
0047   checkPosition(index, pos);
0048 #endif
0049   return index;
0050 }
0051 
0052 void HFNoseNumberingScheme::checkPosition(uint32_t index, const G4ThreeVector& pos) const {
0053   std::pair<float, float> xy;
0054   bool ok(false);
0055   double z1(0), tolR(10.0), tolZ(1.0);
0056   int lay(-1);
0057   if (index == 0) {
0058   } else if ((DetId(index).det() == DetId::Forward) && (DetId(index).subdetId() == static_cast<int>(HFNose))) {
0059     HFNoseDetId id = HFNoseDetId(index);
0060     lay = id.layer();
0061     xy = hgcons_.locateCell(lay, id.waferU(), id.waferV(), id.cellU(), id.cellV(), false, true);
0062     z1 = hgcons_.waferZ(lay, false);
0063     ok = true;
0064   }
0065   if (ok) {
0066     double r1 = std::sqrt(xy.first * xy.first + xy.second * xy.second);
0067     double r2 = pos.perp();
0068     double z2 = std::abs(pos.z());
0069     std::pair<double, double> zrange = hgcons_.rangeZ(false);
0070     std::pair<double, double> rrange = hgcons_.rangeR(z2, false);
0071     bool match = (std::abs(r1 - r2) < tolR) && (std::abs(z1 - z2) < tolZ);
0072     bool inok = ((r2 >= rrange.first) && (r2 <= rrange.second) && (z2 >= zrange.first) && (z2 <= zrange.second));
0073     bool outok = ((r1 >= rrange.first) && (r1 <= rrange.second) && (z1 >= zrange.first) && (z1 <= zrange.second));
0074     std::string ck = (((r1 < rrange.first - tolR) || (r1 > rrange.second + tolR) || (z1 < zrange.first - tolZ) ||
0075                        (z1 > zrange.second + tolZ))
0076                           ? "***** ERROR *****"
0077                           : "");
0078     if (!(match && inok && outok)) {
0079       edm::LogVerbatim("HGCSim") << "HFNoseNumberingScheme::Detector " << DetId(index).det() << " Layer " << lay
0080                                  << " R " << r2 << ":" << r1 << ":" << rrange.first << ":" << rrange.second << " Z "
0081                                  << z2 << ":" << z1 << ":" << zrange.first << ":" << zrange.second << " Match " << match
0082                                  << ":" << inok << ":" << outok << " " << ck;
0083       edm::LogVerbatim("HGCSim") << "Original " << pos.x() << ":" << pos.y() << " return " << xy.first << ":"
0084                                  << xy.second;
0085       if ((DetId(index).det() == DetId::Forward) && (DetId(index).subdetId() == static_cast<int>(HFNose))) {
0086         double wt = 0, xx = ((pos.z() > 0) ? pos.x() : -pos.x());
0087         int waferU, waferV, cellU, cellV, waferType;
0088         hgcons_.waferFromPosition(xx, pos.y(), lay, waferU, waferV, cellU, cellV, waferType, wt, true);
0089         xy = hgcons_.locateCell(lay, waferU, waferV, cellU, cellV, false, true, true);
0090         edm::LogVerbatim("HGCSim") << "HFNoseNumberingScheme " << HFNoseDetId(index) << " position " << xy.first << ":"
0091                                    << xy.second;
0092       }
0093     }
0094   }
0095 }