Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-07-16 22:52:39

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     int zside = (pos.z() > 0) ? 1 : -1;
0032     double xx = zside * pos.x();
0033     hgcons_.waferFromPosition(xx, pos.y(), zside, layer, waferU, waferV, cellU, cellV, waferType, wt, false, false);
0034   }
0035   if (waferType >= 0) {
0036     index = HFNoseDetId(iz, waferType, layer, waferU, waferV, cellU, cellV).rawId();
0037 #ifdef EDM_ML_DEBUG
0038     edm::LogVerbatim("HFNSim") << "OK WaferType " << waferType << " Wafer " << waferU << ":" << waferV << " Cell "
0039                                << cellU << ":" << cellV;
0040   } else {
0041     edm::LogVerbatim("HFNSim") << "Bad WaferType " << waferType;
0042 #endif
0043   }
0044 #ifdef EDM_ML_DEBUG
0045   edm::LogVerbatim("HFNSim") << "HFNoseNumberingScheme::i/p " << layer << ":" << module << ":" << cell << ":" << iz
0046                              << ":" << pos.x() << ":" << pos.y() << ":" << pos.z() << " ID " << std::hex << index
0047                              << std::dec << " wt " << wt;
0048   checkPosition(index, pos);
0049 #endif
0050   return index;
0051 }
0052 
0053 void HFNoseNumberingScheme::checkPosition(uint32_t index, const G4ThreeVector& pos) const {
0054   std::pair<float, float> xy;
0055   bool ok(false);
0056   double z1(0), tolR(10.0), tolZ(1.0);
0057   int lay(-1);
0058   if (index == 0) {
0059   } else if ((DetId(index).det() == DetId::Forward) && (DetId(index).subdetId() == static_cast<int>(HFNose))) {
0060     HFNoseDetId id = HFNoseDetId(index);
0061     lay = id.layer();
0062     xy = hgcons_.locateCell(
0063         id.zside(), lay, id.waferU(), id.waferV(), id.cellU(), id.cellV(), false, true, false, false, false);
0064     z1 = hgcons_.waferZ(lay, false);
0065     ok = true;
0066   }
0067   if (ok) {
0068     double r1 = std::sqrt(xy.first * xy.first + xy.second * xy.second);
0069     double r2 = pos.perp();
0070     double z2 = std::abs(pos.z());
0071     std::pair<double, double> zrange = hgcons_.rangeZ(false);
0072     std::pair<double, double> rrange = hgcons_.rangeR(z2, false);
0073     bool match = (std::abs(r1 - r2) < tolR) && (std::abs(z1 - z2) < tolZ);
0074     bool inok = ((r2 >= rrange.first) && (r2 <= rrange.second) && (z2 >= zrange.first) && (z2 <= zrange.second));
0075     bool outok = ((r1 >= rrange.first) && (r1 <= rrange.second) && (z1 >= zrange.first) && (z1 <= zrange.second));
0076     std::string ck = (((r1 < rrange.first - tolR) || (r1 > rrange.second + tolR) || (z1 < zrange.first - tolZ) ||
0077                        (z1 > zrange.second + tolZ))
0078                           ? "***** ERROR *****"
0079                           : "");
0080     if (!(match && inok && outok)) {
0081       edm::LogVerbatim("HGCSim") << "HFNoseNumberingScheme::Detector " << DetId(index).det() << " Layer " << lay
0082                                  << " R " << r2 << ":" << r1 << ":" << rrange.first << ":" << rrange.second << " Z "
0083                                  << z2 << ":" << z1 << ":" << zrange.first << ":" << zrange.second << " Match " << match
0084                                  << ":" << inok << ":" << outok << " " << ck;
0085       edm::LogVerbatim("HGCSim") << "Original " << pos.x() << ":" << pos.y() << " return " << xy.first << ":"
0086                                  << xy.second;
0087       if ((DetId(index).det() == DetId::Forward) && (DetId(index).subdetId() == static_cast<int>(HFNose))) {
0088         int zside = (pos.z() > 0) ? 1 : -1;
0089         double wt = 0, xx = (zside * pos.x());
0090         int waferU, waferV, cellU, cellV, waferType;
0091         hgcons_.waferFromPosition(xx, pos.y(), zside, lay, waferU, waferV, cellU, cellV, waferType, wt, false, true);
0092         xy = hgcons_.locateCell(zside, lay, waferU, waferV, cellU, cellV, false, true, false, false, true);
0093         edm::LogVerbatim("HGCSim") << "HFNoseNumberingScheme " << HFNoseDetId(index) << " position " << xy.first << ":"
0094                                    << xy.second;
0095       }
0096     }
0097   }
0098 }