diff --git a/Geometry/HGCalCommonData/interface/HGCalDDDConstants.h b/Geometry/HGCalCommonData/interface/HGCalDDDConstants.h index dc0810fde9830..962ee9d376127 100644 --- a/Geometry/HGCalCommonData/interface/HGCalDDDConstants.h +++ b/Geometry/HGCalCommonData/interface/HGCalDDDConstants.h @@ -40,8 +40,8 @@ class HGCalDDDConstants { std::pair assignCell(float x, float y, int lay, int subSec, bool reco) const; std::array assignCellHex(float x, float y, int zside, int lay, bool reco, bool extend, bool debug) const; std::array assignCellTrap(float x, float y, float z, int lay, bool reco) const; - bool cassetteShiftScintillator(int layer, int iphi) const; - bool cassetteShiftSilicon(int layer, int waferU, int waferV) const; + bool cassetteShiftScintillator(int zside, int layer, int iphi) const; + bool cassetteShiftSilicon(int zside, int layer, int waferU, int waferV) const; int cassetteTile(int iphi) const { return (HGCalTileIndex::tileCassette(iphi, hgpar_->phiOffset_, hgpar_->nphiCassette_, hgpar_->cassettes_)); } diff --git a/Geometry/HGCalCommonData/src/HGCalDDDConstants.cc b/Geometry/HGCalCommonData/src/HGCalDDDConstants.cc index 7aad27318a9da..86fe3677bc5cd 100644 --- a/Geometry/HGCalCommonData/src/HGCalDDDConstants.cc +++ b/Geometry/HGCalCommonData/src/HGCalDDDConstants.cc @@ -192,11 +192,12 @@ std::array HGCalDDDConstants::assignCellTrap(float x, float y, float z, if (mode_ == HGCalGeometryMode::TrapezoidCassette) { int cassette = HGCalTileIndex::tileCassette(iphi, hgpar_->phiOffset_, hgpar_->nphiCassette_, hgpar_->cassettes_); auto cshift = hgcassette_.getShift(layer, zside, cassette); + int invert = ((layerType(layer) == HGCalTypes::WaferCenter) && (zside > 0)) ? 1 : -1; #ifdef EDM_ML_DEBUG - edm::LogVerbatim("HGCalGeomT") << "Cassette " << cassette << " Shift " << -(zside * cshift.first) << ":" + edm::LogVerbatim("HGCalGeomT") << "Cassette " << cassette << " Shift " << (invert * -cshift.first) << ":" << cshift.second; #endif - xx += (zside * cshift.first); + xx -= (invert * cshift.first); yy -= cshift.second; } double phi = (((yy == 0.0) && (xx == 0.0)) ? 0. : std::atan2(yy, xx)); @@ -251,13 +252,13 @@ std::array HGCalDDDConstants::assignCellTrap(float x, float y, float z, return std::array{{irad, iphi, type}}; } -bool HGCalDDDConstants::cassetteShiftSilicon(int layer, int waferU, int waferV) const { +bool HGCalDDDConstants::cassetteShiftSilicon(int zside, int layer, int waferU, int waferV) const { bool shift(false); if (mode_ == HGCalGeometryMode::Hexagon8Cassette) { int indx = HGCalWaferIndex::waferIndex(layer, waferU, waferV); auto ktr = hgpar_->waferInfoMap_.find(indx); if (ktr != hgpar_->waferInfoMap_.end()) { - auto cshift = hgcassette_.getShift(layer, 1, (ktr->second).cassette); + auto cshift = hgcassette_.getShift(layer, zside, (ktr->second).cassette); if ((cshift.first != 0) || (cshift.second != 0)) shift = true; } @@ -265,10 +266,10 @@ bool HGCalDDDConstants::cassetteShiftSilicon(int layer, int waferU, int waferV) return shift; } -bool HGCalDDDConstants::cassetteShiftScintillator(int layer, int iphi) const { +bool HGCalDDDConstants::cassetteShiftScintillator(int zside, int layer, int iphi) const { bool shift(false); if (mode_ == HGCalGeometryMode::TrapezoidCassette) { - auto cshift = hgcassette_.getShift(layer, 1, cassetteTile(iphi)); + auto cshift = hgcassette_.getShift(layer, zside, cassetteTile(iphi)); if ((cshift.first != 0) || (cshift.second != 0)) shift = true; } @@ -752,15 +753,16 @@ std::pair HGCalDDDConstants::localToGlobal8( int indx = HGCalWaferIndex::waferIndex(lay, waferU, waferV); auto ktr = hgpar_->waferInfoMap_.find(indx); if ((mode_ == HGCalGeometryMode::Hexagon8Cassette) && (ktr != hgpar_->waferInfoMap_.end())) { - auto cshift = hgcassette_.getShift(lay, -zside, (ktr->second).cassette); + int invert = ((layerType(lay) == HGCalTypes::WaferCenter) && (zside > 0)) ? 1 : -1; + auto cshift = hgcassette_.getShift(lay, zside, (ktr->second).cassette); if (debug) - edm::LogVerbatim("HGCalGeom") << "Cassette " << (ktr->second).cassette << " Shift " << -(zside * cshift.first) + edm::LogVerbatim("HGCalGeom") << "Cassette " << (ktr->second).cassette << " Shift " << (invert * cshift.first) << ":" << cshift.second; if (!reco) { - x -= ((HGCalParameters::k_ScaleToDDD)*zside * cshift.first); + x += ((HGCalParameters::k_ScaleToDDD)*invert * cshift.first); y += ((HGCalParameters::k_ScaleToDDD)*cshift.second); } else { - x -= (zside * cshift.first); + x += (invert * cshift.first); y += cshift.second; } } @@ -860,15 +862,16 @@ std::pair HGCalDDDConstants::locateCell( x += xy.first; y += xy.second; if ((mode_ == HGCalGeometryMode::Hexagon8Cassette) && (ktr != hgpar_->waferInfoMap_.end())) { - auto cshift = hgcassette_.getShift(lay, -zside, (ktr->second).cassette); + int invert = ((layerType(lay) == HGCalTypes::WaferCenter) && (zside > 0)) ? 1 : -1; + auto cshift = hgcassette_.getShift(lay, zside, (ktr->second).cassette); if (debug) - edm::LogVerbatim("HGCalGeom") << "Cassette " << (ktr->second).cassette << " Shift " << -(zside * cshift.first) + edm::LogVerbatim("HGCalGeom") << "Cassette " << (ktr->second).cassette << " Shift " << (invert * cshift.first) << ":" << cshift.second; if (!reco) { - x -= ((HGCalParameters::k_ScaleToDDD)*zside * cshift.first); + x += ((HGCalParameters::k_ScaleToDDD)*invert * cshift.first); y += ((HGCalParameters::k_ScaleToDDD)*cshift.second); } else { - x -= (zside * cshift.first); + x += (invert * cshift.first); y += cshift.second; } } @@ -929,11 +932,12 @@ std::pair HGCalDDDConstants::locateCellTrap( y += hgpar_->yLayerHex_[ll]; if (mode_ == HGCalGeometryMode::TrapezoidCassette) { int cassette = HGCalTileIndex::tileCassette(iphi, hgpar_->phiOffset_, hgpar_->nphiCassette_, hgpar_->cassettes_); + int invert = ((layerType(lay) == HGCalTypes::WaferCenter) && (zside > 0)) ? 1 : -1; auto cshift = hgcassette_.getShift(lay, zside, cassette); if (debug) - edm::LogVerbatim("HGCalGeom") << "Cassette " << cassette << " Shift " << -(zside * cshift.first) << ":" + edm::LogVerbatim("HGCalGeom") << "Cassette " << cassette << " Shift " << (invert * cshift.first) << ":" << cshift.second; - x -= (zside * cshift.first); + x += (invert * cshift.first); y += cshift.second; } if (irad < 0) @@ -1461,11 +1465,12 @@ void HGCalDDDConstants::waferFromPosition(const double x, int indx = HGCalWaferIndex::waferIndex(layer, waferU, waferV); auto ktr = hgpar_->waferInfoMap_.find(indx); if (ktr != hgpar_->waferInfoMap_.end()) { - auto cshift = hgcassette_.getShift(layer, -zside, (ktr->second).cassette); + int invert = ((layerType(layer) == HGCalTypes::WaferCenter) && (zside > 0)) ? 1 : -1; + auto cshift = hgcassette_.getShift(layer, zside, (ktr->second).cassette); if (debug) - edm::LogVerbatim("HGCalGeom") << "Cassette " << (ktr->second).cassette << " Shift " << -(zside * cshift.first) + edm::LogVerbatim("HGCalGeom") << "Cassette " << (ktr->second).cassette << " Shift " << (invert * cshift.first) << ":" << cshift.second; - dx0 = -(zside * cshift.first); + dx0 = (invert * cshift.first); dy0 = cshift.second; } } diff --git a/Geometry/HGCalCommonData/test/HGCalWaferIDTester.cc b/Geometry/HGCalCommonData/test/HGCalWaferIDTester.cc index 8221f32a801d2..67f5535502068 100644 --- a/Geometry/HGCalCommonData/test/HGCalWaferIDTester.cc +++ b/Geometry/HGCalCommonData/test/HGCalWaferIDTester.cc @@ -147,7 +147,7 @@ void HGCalWaferIDTester::analyze(const edm::Event& iEvent, const edm::EventSetup int indx = HGCalWaferIndex::waferIndex(layer, detIds_[k].waferU(), detIds_[k].waferV()); st1 << " Part:Orient:Cassette:Shift " << std::get<1>(hgdc.waferFileInfo(indx)) << ":" << std::get<2>(hgdc.waferFileInfo(indx)) << ":" << std::get<3>(hgdc.waferFileInfo(indx)) << ":" - << hgdc.cassetteShiftSilicon(layer, detIds_[k].waferU(), detIds_[k].waferV()); + << hgdc.cassetteShiftSilicon(zside, layer, detIds_[k].waferU(), detIds_[k].waferV()); double xx = (zside < 0) ? -posXY_[k].first : posXY_[k].first; double yy = posXY_[k].second; hgdc.waferFromPosition(xx, yy, zside, layer, waferU, waferV, cellU, cellV, waferType, wt, false, debug); @@ -159,7 +159,7 @@ void HGCalWaferIDTester::analyze(const edm::Event& iEvent, const edm::EventSetup indx = HGCalWaferIndex::waferIndex(layer, id.waferU(), id.waferV()); st1 << " Part:Orient:Cassette:Shift " << std::get<1>(hgdc.waferFileInfo(indx)) << ":" << std::get<2>(hgdc.waferFileInfo(indx)) << ":" << std::get<3>(hgdc.waferFileInfo(indx)) << ":" - << hgdc.cassetteShiftSilicon(layer, id.waferU(), id.waferV()); + << hgdc.cassetteShiftSilicon(zside, layer, id.waferU(), id.waferV()); auto xy = hgdc.locateCell(id, true); double xx0 = (id.zside() > 0) ? xy.first : -xy.first; double yy0 = xy.second; diff --git a/SimG4CMS/Calo/plugins/HGCalTestPartialWaferHits.cc b/SimG4CMS/Calo/plugins/HGCalTestPartialWaferHits.cc index d57b99ea973ff..f64297ff37b74 100644 --- a/SimG4CMS/Calo/plugins/HGCalTestPartialWaferHits.cc +++ b/SimG4CMS/Calo/plugins/HGCalTestPartialWaferHits.cc @@ -126,7 +126,8 @@ void HGCalTestPartialWaferHits::analyze(const edm::Event& e, const edm::EventSet if (((id.det() == DetId::HGCalEE) && (nameSense_ == "HGCalEESensitive")) || ((id.det() == DetId::HGCalHSi) && (nameSense_ == "HGCalHESiliconSensitive"))) { std::string_view pid = - ((hgc.cassetteShiftSilicon(hid.layer(), hid.waferU(), hid.waferV())) ? "HGCSim" : "HGCalSim"); + ((hgc.cassetteShiftSilicon(hid.zside(), hid.layer(), hid.waferU(), hid.waferV())) ? "HGCSim" + : "HGCalSim"); const auto& info = hgc.waferInfo(hid.layer(), hid.waferU(), hid.waferV()); if (!valid) st1 << " Wafer Type:Part:Orient:Cassette " << info.type << ":" << info.part << ":" << info.orient << ":" @@ -168,7 +169,8 @@ void HGCalTestPartialWaferHits::analyze(const edm::Event& e, const edm::EventSet HGCScintillatorDetId hid(id); st1 << hid; if ((id.det() == DetId::HGCalHSc) && (nameSense_ == "HGCalHEScintillatorSensitive")) { - std::string_view pid = ((hgc.cassetteShiftScintillator(hid.layer(), hid.iphi())) ? "HGCSim" : "HGCalSim"); + std::string_view pid = + ((hgc.cassetteShiftScintillator(hid.zside(), hid.layer(), hid.iphi())) ? "HGCSim" : "HGCalSim"); GlobalPoint pos = geom->getPosition(id); bool valid1 = geom->topology().valid(id); bool valid2 = hgc.isValidTrap(hid.zside(), hid.layer(), hid.ring(), hid.iphi()); diff --git a/SimG4CMS/Calo/src/HGCScintSD.cc b/SimG4CMS/Calo/src/HGCScintSD.cc index 5774faef30df6..87d00a465704f 100644 --- a/SimG4CMS/Calo/src/HGCScintSD.cc +++ b/SimG4CMS/Calo/src/HGCScintSD.cc @@ -218,7 +218,8 @@ uint32_t HGCScintSD::setDetUnitId(const G4Step* aStep) { } if ((id != 0) && checkID_) { HGCScintillatorDetId hid1(id); - std::string_view pid = ((hgcons_->cassetteShiftScintillator(hid1.layer(), hid1.iphi())) ? "HGCSim" : "HGCalSim"); + std::string_view pid = + ((hgcons_->cassetteShiftScintillator(hid1.zside(), hid1.layer(), hid1.iphi())) ? "HGCSim" : "HGCalSim"); bool debug = (verbose_ > 0) ? true : false; auto xy = hgcons_->locateCell(HGCScintillatorDetId(id), debug); double dx = xy.first - (hitPoint.x() / CLHEP::cm); diff --git a/SimG4CMS/Calo/src/HGCalSD.cc b/SimG4CMS/Calo/src/HGCalSD.cc index 75bcc398c0770..cba4babf9dd92 100644 --- a/SimG4CMS/Calo/src/HGCalSD.cc +++ b/SimG4CMS/Calo/src/HGCalSD.cc @@ -3,6 +3,7 @@ // Description: Sensitive Detector class for High Granularity Calorimeter /////////////////////////////////////////////////////////////////////////////// +#include "DataFormats/Math/interface/angle_units.h" #include "DataFormats/Math/interface/FastMath.h" #include "DataFormats/ForwardDetId/interface/HGCSiliconDetId.h" #include "SimG4CMS/Calo/interface/HGCalSD.h" @@ -25,6 +26,8 @@ //#define EDM_ML_DEBUG +using namespace angle_units::operators; + HGCalSD::HGCalSD(const std::string& name, const HGCalDDDConstants* hgc, const SensitiveDetectorCatalog& clg, @@ -200,7 +203,7 @@ uint32_t HGCalSD::setDetUnitId(const G4Step* aStep) { #endif if ((id != 0) && checkID_) { HGCSiliconDetId hid1(id); - bool cshift = (hgcons_->cassetteShiftSilicon(hid1.layer(), hid1.waferU(), hid1.waferV())); + bool cshift = (hgcons_->cassetteShiftSilicon(hid1.zside(), hid1.layer(), hid1.waferU(), hid1.waferV())); std::string_view pid = (cshift ? "HGCSim" : "HGCalSim"); bool debug = (verbose_ > 0) ? true : false; auto xy = hgcons_->locateCell(hid1, debug); @@ -213,10 +216,19 @@ uint32_t HGCalSD::setDetUnitId(const G4Step* aStep) { if ((diff > tol) || (!valid1)) pid = "HGCalError"; auto partn = hgcons_->waferTypeRotation(hid1.layer(), hid1.waferU(), hid1.waferV(), false, false); - edm::LogVerbatim(pid) << "CheckID " << HGCSiliconDetId(id) << " input position: (" << hitPoint.x() / CLHEP::cm - << ", " << hitPoint.y() / CLHEP::cm << "); position from ID (" << xx << ", " << xy.second - << ") distance " << diff << " Valid " << valid1 << " Wafer type|rotation " << partn.first - << ":" << partn.second << " CassetteShift " << cshift; + int indx = HGCalWaferIndex::waferIndex(layer, hid1.waferU(), hid1.waferV()); + double phi = std::atan2(hitPoint.y(), hitPoint.x()); + edm::LogVerbatim(pid) << "CheckID " << HGCSiliconDetId(id) << " Layer:Module:Cell:ModuleLev " << layer << ":" + << module << ":" << cell << ":" << moduleLev << " SimWt:history " << useSimWt_ << ":" + << touch->GetHistoryDepth() << ":" << levelT1_ << ":" << levelT2_ << " input position: (" + << hitPoint.x() / CLHEP::cm << ", " << hitPoint.y() / CLHEP::cm << ":" << convertRadToDeg(phi) + << "); position from ID (" << xx << ", " << xy.second << ") distance " << dx << ":" << dy + << ":" << diff << " Valid " << valid1 << " Wafer type|rotation " << partn.first << ":" + << partn.second << " Part:Orient:Cassette " << std::get<1>(hgcons_->waferFileInfo(indx)) + << ":" << std::get<2>(hgcons_->waferFileInfo(indx)) << ":" + << std::get<3>(hgcons_->waferFileInfo(indx)) << " CassetteShift " << cshift; + xy = hgcons_->locateCell(hid1, true); + printDetectorLevels(touch); } return id; }