Skip to content

Commit

Permalink
Merge pull request #41355 from bsunanda/Phase2-hgx337A
Browse files Browse the repository at this point in the history
Phase2-hgx337A Further attempts to diagnose cassette shift studies for HGCal geometry (relevant for the V18 version)
  • Loading branch information
cmsbuild authored Apr 19, 2023
2 parents e70d83a + ef72c17 commit 5b979f2
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 31 deletions.
4 changes: 2 additions & 2 deletions Geometry/HGCalCommonData/interface/HGCalDDDConstants.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ class HGCalDDDConstants {
std::pair<int, int> assignCell(float x, float y, int lay, int subSec, bool reco) const;
std::array<int, 5> assignCellHex(float x, float y, int zside, int lay, bool reco, bool extend, bool debug) const;
std::array<int, 3> 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_));
}
Expand Down
43 changes: 24 additions & 19 deletions Geometry/HGCalCommonData/src/HGCalDDDConstants.cc
Original file line number Diff line number Diff line change
Expand Up @@ -192,11 +192,12 @@ std::array<int, 3> 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));
Expand Down Expand Up @@ -251,24 +252,24 @@ std::array<int, 3> HGCalDDDConstants::assignCellTrap(float x, float y, float z,
return std::array<int, 3>{{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;
}
}
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;
}
Expand Down Expand Up @@ -752,15 +753,16 @@ std::pair<float, float> 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;
}
}
Expand Down Expand Up @@ -860,15 +862,16 @@ std::pair<float, float> 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;
}
}
Expand Down Expand Up @@ -929,11 +932,12 @@ std::pair<float, float> 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)
Expand Down Expand Up @@ -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;
}
}
Expand Down
4 changes: 2 additions & 2 deletions Geometry/HGCalCommonData/test/HGCalWaferIDTester.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
Expand Down
6 changes: 4 additions & 2 deletions SimG4CMS/Calo/plugins/HGCalTestPartialWaferHits.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 << ":"
Expand Down Expand Up @@ -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());
Expand Down
3 changes: 2 additions & 1 deletion SimG4CMS/Calo/src/HGCScintSD.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
22 changes: 17 additions & 5 deletions SimG4CMS/Calo/src/HGCalSD.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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,
Expand Down Expand Up @@ -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);
Expand All @@ -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;
}
Expand Down

0 comments on commit 5b979f2

Please sign in to comment.