Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Phase2-hgx326X Try to address cassette shift abnormality for HGCal geometry #39625

Closed
wants to merge 6 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Geometry/HGCalCommonData/interface/HGCalCassette.h
Original file line number Diff line number Diff line change
@@ -12,13 +12,15 @@ class HGCalCassette {

void setParameter(int cassette, const std::vector<double>& shifts);
std::pair<double, double> getShift(int layer, int zside, int cassette) const;
static int cassetteIndex(int det, int layer, int zside, int cassette);

private:
const std::vector<int> positEE_ = {2, 1, 0, 5, 4, 3};
const std::vector<int> positHE_ = {5, 4, 3, 2, 1, 0, 11, 10, 9, 8, 7, 6};
int cassette_;
bool typeHE_;
std::vector<double> shifts_;
static constexpr int32_t factor_ = 100;
};

#endif
13 changes: 8 additions & 5 deletions Geometry/HGCalCommonData/interface/HGCalDDDConstants.h
Original file line number Diff line number Diff line change
@@ -38,10 +38,11 @@ class HGCalDDDConstants {
~HGCalDDDConstants() = default;

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 lay, bool reco, bool extend = false, bool debug = false) const;
std::array<int, 5> assignCellHex(
float x, float y, int zside, int lay, bool reco, bool extend = false, bool debug = false) const;
std::array<int, 3> assignCellTrap(float x, float y, float z, int lay, bool reco) const;
std::pair<double, double> cellEtaPhiTrap(int type, int irad) const;
bool cellInLayer(int waferU, int waferV, int cellU, int cellV, int lay, bool reco) const;
bool cellInLayer(int waferU, int waferV, int cellU, int cellV, int lay, int zside, bool reco) const;
double cellSizeHex(int type) const;
inline std::pair<double, double> cellSizeTrap(int type, int irad) const {
return std::make_pair(hgpar_->radiusLayer_[type][irad - 1], hgpar_->radiusLayer_[type][irad]);
@@ -90,9 +91,10 @@ class HGCalDDDConstants {
return ((hgpar_->layerType_.empty()) ? HGCalTypes::WaferCenter : hgpar_->layerType_[lay - hgpar_->firstLayer_]);
}
std::pair<float, float> localToGlobal8(
int lay, int waferU, int waferV, double localX, double localY, bool reco, bool debug) const;
int zside, int lay, int waferU, int waferV, double localX, double localY, bool reco, bool debug) const;
std::pair<float, float> locateCell(int cell, int lay, int type, bool reco) const;
std::pair<float, float> locateCell(int lay,
std::pair<float, float> locateCell(int zside,
int lay,
int waferU,
int waferV,
int cellU,
@@ -104,7 +106,7 @@ class HGCalDDDConstants {
std::pair<float, float> locateCell(const HGCSiliconDetId&, bool debug = false) const;
std::pair<float, float> locateCell(const HGCScintillatorDetId&, bool debug = false) const;
std::pair<float, float> locateCellHex(int cell, int wafer, bool reco) const;
std::pair<float, float> locateCellTrap(int lay, int ieta, int iphi, bool reco, bool debug = false) const;
std::pair<float, float> locateCellTrap(int zside, int lay, int ieta, int iphi, bool reco, bool debug = false) const;
inline int levelTop(int ind = 0) const { return hgpar_->levelT_[ind]; }
bool maskCell(const DetId& id, int corners) const;
inline int maxCellUV() const { return (tileTrapezoid() ? hgpar_->nCellsFine_ : 2 * hgpar_->nCellsFine_); }
@@ -147,6 +149,7 @@ class HGCalDDDConstants {
void waferFromPosition(const double x, const double y, int& wafer, int& icell, int& celltyp) const;
void waferFromPosition(const double x,
const double y,
const int zside,
const int layer,
int& waferU,
int& waferV,
7 changes: 6 additions & 1 deletion Geometry/HGCalCommonData/plugins/DDHGCalMixRotatedLayer.cc
Original file line number Diff line number Diff line change
@@ -469,7 +469,7 @@ void DDHGCalMixRotatedLayer::positionMix(const DDLogicalPart& glog,
double phi2 = dphi * (fimax - fimin + 1);
auto cshift = cassette_.getShift(layer + 1, 1, cassette);
#ifdef EDM_ML_DEBUG
edm::LogVerbatim("HGCalGeom") << "DDHGCalMixRotatedLayer: Layer " << copy << " iR "
edm::LogVerbatim("HGCalGeom") << "DDHGCalMixRotatedLayer: Layer " << copy << ":" << (layer + 1) << " zside 1 iR "
<< std::get<1>(HGCalTileIndex::tileUnpack(tileIndex_[ti])) << ":"
<< std::get<2>(HGCalTileIndex::tileUnpack(tileIndex_[ti])) << " R " << r1 << ":"
<< r2 << " Thick " << (2.0 * hthickl) << " phi " << fimin << ":" << fimax << ":"
@@ -546,6 +546,11 @@ void DDHGCalMixRotatedLayer::positionMix(const DDLogicalPart& glog,
auto cshift = cassette_.getShift(layer + 1, 1, cassette);
double xpos = xyoff.first + cshift.first + nc * delx;
double ypos = xyoff.second + cshift.second + nr * dy;
#ifdef EDM_ML_DEBUG
double phi = std::atan2(ypos, xpos);
edm::LogVerbatim("HGCalGeom") << " Cassette " << cassette << " in layer " << (layer + 1) << " zside 1 at "
<< convertRadToDeg(phi) << " Shift " << cshift.first << ":" << cshift.second;
#endif
std::string wafer;
int i(999);
if (part == HGCalTypes::WaferFull) {
Original file line number Diff line number Diff line change
@@ -422,6 +422,11 @@ void DDHGCalSiliconRotatedModule::positionSensitive(const DDLogicalPart& glog, i
auto cshift = cassette_.getShift(layer + 1, 1, cassette);
double xpos = xyoff.first + cshift.first + nc * delx;
double ypos = xyoff.second + cshift.second + nr * dy;
#ifdef EDM_ML_DEBUG
double phi = std::atan2(ypos, xpos);
edm::LogVerbatim("HGCalGeom") << " Cassette " << cassette << " in layer " << (layer + 1) << " zside 1 at "
<< convertRadToDeg(phi) << " Shift " << cshift.first << ":" << cshift.second;
#endif
std::string wafer;
int i(999);
if (part == HGCalTypes::WaferFull) {
22 changes: 17 additions & 5 deletions Geometry/HGCalCommonData/src/HGCalCassette.cc
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "FWCore/MessageLogger/interface/MessageLogger.h"
#include "Geometry/HGCalCommonData/interface/HGCalCassette.h"
#include <algorithm>
#include <sstream>

//#define EDM_ML_DEBUG
@@ -10,11 +11,17 @@ void HGCalCassette::setParameter(int cassette, const std::vector<double>& shifts
shifts_.insert(shifts_.end(), shifts.begin(), shifts.end());
#ifdef EDM_ML_DEBUG
edm::LogVerbatim("HGCalGeom") << "# of cassettes = " << cassette_ << " Type " << typeHE_;
std::ostringstream st1;
st1 << " Shifts:";
for (const auto& s : shifts_)
st1 << ":" << s;
edm::LogVerbatim("HGCalGeom") << st1.str();
for (uint32_t j1 = 0; j1 < shifts.size(); j1 += 12) {
std::ostringstream st1;
if (j1 == 0)
st1 << " Shifts:";
else
st1 << " ";
uint32_t j2 = std::min((j1 + 12), static_cast<uint32_t>(shifts.size()));
for (uint32_t j = j1; j < j2; ++j)
st1 << ":" << shifts[j];
edm::LogVerbatim("HGCalGeom") << st1.str();
}
#endif
}

@@ -29,3 +36,8 @@ std::pair<double, double> HGCalCassette::getShift(int layer, int zside, int cass
#endif
return xy;
}

int HGCalCassette::cassetteIndex(int det, int layer, int side, int cassette) {
int zs = (side > 0) ? factor_ : 0;
return (((zs + det) * factor_ + layer) * factor_ + cassette);
}
100 changes: 60 additions & 40 deletions Geometry/HGCalCommonData/src/HGCalDDDConstants.cc
Original file line number Diff line number Diff line change
@@ -164,45 +164,57 @@ std::pair<int, int> HGCalDDDConstants::assignCell(float x, float y, int lay, int
}

std::array<int, 5> HGCalDDDConstants::assignCellHex(
float x, float y, int lay, bool reco, bool extend, bool debug) const {
float x, float y, int zside, int lay, bool reco, bool extend, bool debug) const {
int waferU(0), waferV(0), waferType(-1), cellU(0), cellV(0);
if (waferHexagon8()) {
double xx = (reco) ? HGCalParameters::k_ScaleToDDD * x : x;
double yy = (reco) ? HGCalParameters::k_ScaleToDDD * y : y;
double wt(1.0);
#ifdef EDM_ML_DEBUG
edm::LogVerbatim("HGCalGeom") << "assignCellHex x " << x << ":" << xx << " y " << y << ":" << yy << " Lay " << lay;
edm::LogVerbatim("HGCalGeom") << "assignCellHex x " << x << ":" << xx << " y " << y << ":" << yy << " zside "
<< zside << " Lay " << lay;
#endif
waferFromPosition(xx, yy, lay, waferU, waferV, cellU, cellV, waferType, wt, extend, debug);
waferFromPosition(xx, yy, zside, lay, waferU, waferV, cellU, cellV, waferType, wt, extend, debug);
}
return std::array<int, 5>{{waferU, waferV, waferType, cellU, cellV}};
}

std::array<int, 3> HGCalDDDConstants::assignCellTrap(float x, float y, float z, int layer, bool reco) const {
int irad(-1), iphi(-1), type(-1);
int irad(-1), iphi(-1), iphi0(-1), type(-1);
const auto& indx = getIndex(layer, reco);
if (indx.first < 0)
return std::array<int, 3>{{irad, iphi, type}};
double xx = (reco) ? ((z > 0) ? x : -x)
: ((z > 0) ? (HGCalParameters::k_ScaleFromDDD * x) : -(HGCalParameters::k_ScaleFromDDD * x));
int zside = ((z > 0) ? 1 : -1);
double xx = (reco) ? (zside * x) : (HGCalParameters::k_ScaleFromDDD * zside * x);
double yy = (reco) ? y : HGCalParameters::k_ScaleFromDDD * y;
int ll = layer - hgpar_->firstLayer_;
xx -= hgpar_->xLayerHex_[ll];
yy -= hgpar_->yLayerHex_[ll];
if (mode_ == HGCalGeometryMode::TrapezoidCassette) {
int cassette = HGCalTileIndex::tileCassette(iphi, hgpar_->phiOffset_, hgpar_->nphiCassette_, hgpar_->cassettes_);
auto cshift = hgcassette_.getShift(layer, 1, cassette);
#ifdef EDM_ML_DEBUG
edm::LogVerbatim("HGCalGeom") << "Cassette " << cassette << " Shift " << cshift.first << ":" << cshift.second;
#endif
xx -= cshift.first;
yy -= cshift.second;
}
double phi = (((yy == 0.0) && (xx == 0.0)) ? 0. : std::atan2(yy, xx));
if (phi < 0)
phi += (2.0 * M_PI);
if (indx.second != 0)
iphi = 1 + static_cast<int>(phi / indx.second);
iphi0 = 1 + static_cast<int>(phi / indx.second);
if (mode_ == HGCalGeometryMode::TrapezoidCassette) {
while (iphi != iphi0) {
iphi = iphi0;
int cassette = HGCalTileIndex::tileCassette(iphi0, hgpar_->phiOffset_, hgpar_->nphiCassette_, hgpar_->cassettes_);
auto cshift = hgcassette_.getShift(layer, zside, cassette);
#ifdef EDM_ML_DEBUG
edm::LogVerbatim("HGCalGeom") << "Layer " << layer << " zside 1 phi " << iphi0 << " Cassette " << cassette
<< " Shift " << cshift.first << ":" << cshift.second;
#endif
xx -= cshift.first;
yy -= cshift.second;
phi = (((yy == 0.0) && (xx == 0.0)) ? 0. : std::atan2(yy, xx));
if (phi < 0)
phi += (2.0 * M_PI);
if (indx.second != 0)
iphi0 = 1 + static_cast<int>(phi / indx.second);
}
} else {
iphi = iphi0;
}
type = hgpar_->scintType(layer);
double r = std::sqrt(xx * xx + yy * yy);
auto ir = std::lower_bound(hgpar_->radiusLayer_[type].begin(), hgpar_->radiusLayer_[type].end(), r);
@@ -226,7 +238,7 @@ std::pair<double, double> HGCalDDDConstants::cellEtaPhiTrap(int type, int irad)
return std::make_pair(dr, df);
}

bool HGCalDDDConstants::cellInLayer(int waferU, int waferV, int cellU, int cellV, int lay, bool reco) const {
bool HGCalDDDConstants::cellInLayer(int waferU, int waferV, int cellU, int cellV, int lay, int zside, bool reco) const {
const auto& indx = getIndex(lay, true);
if (indx.first >= 0) {
if (mode_ == HGCalGeometryMode::Hexagon8Cassette) {
@@ -246,8 +258,9 @@ bool HGCalDDDConstants::cellInLayer(int waferU, int waferV, int cellU, int cellV
int ncell = (thck == HGCalTypes::WaferFineThin) ? hgpar_->nCellsFine_ : hgpar_->nCellsCoarse_;
return HGCalWaferMask::goodCell(cellU, cellV, ncell, part, rotn);
} else if (waferHexagon8() || waferHexagon6()) {
const auto& xy = ((waferHexagon8()) ? locateCell(lay, waferU, waferV, cellU, cellV, reco, true, false, false)
: locateCell(cellU, lay, waferU, reco));
const auto& xy =
((waferHexagon8()) ? locateCell(zside, lay, waferU, waferV, cellU, cellV, reco, true, false, false)
: locateCell(cellU, lay, waferU, reco));
double rpos = sqrt(xy.first * xy.first + xy.second * xy.second);
return ((rpos >= hgpar_->rMinLayHex_[indx.first]) && (rpos <= hgpar_->rMaxLayHex_[indx.first]));
} else {
@@ -624,13 +637,14 @@ unsigned int HGCalDDDConstants::layersInit(bool reco) const {
}

std::pair<float, float> HGCalDDDConstants::localToGlobal8(
int lay, int waferU, int waferV, double localX, double localY, bool reco, bool debug) const {
int zside, int lay, int waferU, int waferV, double localX, double localY, bool reco, bool debug) const {
double x(localX), y(localY);
bool rotx =
((!hgpar_->layerType_.empty()) && (hgpar_->layerType_[lay - hgpar_->firstLayer_] == HGCalTypes::WaferCenterR));
if (debug)
edm::LogVerbatim("HGCalGeom") << "LocalToGlobal8 " << lay << ":" << (lay - hgpar_->firstLayer_) << ":" << rotx
<< " Local (" << x << ":" << y << ") Reco " << reco;
edm::LogVerbatim("HGCalGeom") << "LocalToGlobal8: zside " << zside << " Layer " << lay << ":"
<< (lay - hgpar_->firstLayer_) << ":" << rotx << " Local (" << x << ":" << y
<< ") Reco " << reco;
if (!reco) {
x *= HGCalParameters::k_ScaleToDDD;
y *= HGCalParameters::k_ScaleToDDD;
@@ -641,10 +655,10 @@ 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, 1, (ktr->second).cassette);
auto cshift = hgcassette_.getShift(lay, zside, (ktr->second).cassette);
if (debug)
edm::LogVerbatim("HGCalGeom") << "Cassette " << (ktr->second).cassette << " Shift " << cshift.first << ":"
<< cshift.second;
edm::LogVerbatim("HGCalGeom") << "Layer:zside:Cassette " << lay << ":" << zside << ":" << (ktr->second).cassette
<< " Shift " << cshift.first << ":" << cshift.second;
if (!reco) {
x += (HGCalParameters::k_ScaleToDDD)*cshift.first;
y += (HGCalParameters::k_ScaleToDDD)*cshift.second;
@@ -690,18 +704,19 @@ std::pair<float, float> HGCalDDDConstants::locateCell(int cell, int lay, int typ
}

std::pair<float, float> HGCalDDDConstants::locateCell(
int lay, int waferU, int waferV, int cellU, int cellV, bool reco, bool all, bool norot, bool debug) const {
int zside, int lay, int waferU, int waferV, int cellU, int cellV, bool reco, bool all, bool norot, bool debug)
const {
double x(0), y(0);
int indx = HGCalWaferIndex::waferIndex(lay, waferU, waferV);
auto itr = hgpar_->typesInLayers_.find(indx);
int type = ((itr == hgpar_->typesInLayers_.end()) ? 2 : hgpar_->waferTypeL_[itr->second]);
int layertype = layerType(lay);
bool rotx = (norot) ? false : (layertype == HGCalTypes::WaferCenterR);
if (debug) {
edm::LogVerbatim("HGCalGeom") << "LocateCell " << lay << ":" << (lay - hgpar_->firstLayer_) << ":" << layertype
<< ":" << rotx << ":" << waferU << ":" << waferV << ":" << indx << ":"
<< (itr == hgpar_->typesInLayers_.end()) << ":" << type << " Flags " << reco << ":"
<< all;
edm::LogVerbatim("HGCalGeom") << "LocateCell::Zside " << zside << " Layer " << lay << ":"
<< (lay - hgpar_->firstLayer_) << ":" << layertype << ":" << rotx << ":" << waferU
<< ":" << waferV << ":" << indx << ":" << (itr == hgpar_->typesInLayers_.end()) << ":"
<< type << " Flags " << reco << ":" << all;
}
auto ktr = hgpar_->waferInfoMap_.end();
int place(HGCalCell::cellPlacementOld);
@@ -748,7 +763,7 @@ 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, 1, (ktr->second).cassette);
auto cshift = hgcassette_.getShift(lay, zside, (ktr->second).cassette);
if (debug)
edm::LogVerbatim("HGCalGeom") << "Cassette " << (ktr->second).cassette << " Shift " << cshift.first << ":"
<< cshift.second;
@@ -767,11 +782,11 @@ std::pair<float, float> HGCalDDDConstants::locateCell(
}

std::pair<float, float> HGCalDDDConstants::locateCell(const HGCSiliconDetId& id, bool debug) const {
return locateCell(id.layer(), id.waferU(), id.waferV(), id.cellU(), id.cellV(), true, true, false, debug);
return locateCell(id.zside(), id.layer(), id.waferU(), id.waferV(), id.cellU(), id.cellV(), true, true, false, debug);
}

std::pair<float, float> HGCalDDDConstants::locateCell(const HGCScintillatorDetId& id, bool debug) const {
return locateCellTrap(id.layer(), id.iradius(), id.iphi(), true, debug);
return locateCellTrap(id.zside(), id.layer(), id.iradius(), id.iphi(), true, debug);
}

std::pair<float, float> HGCalDDDConstants::locateCellHex(int cell, int wafer, bool reco) const {
@@ -790,7 +805,8 @@ std::pair<float, float> HGCalDDDConstants::locateCellHex(int cell, int wafer, bo
return std::make_pair(x, y);
}

std::pair<float, float> HGCalDDDConstants::locateCellTrap(int lay, int irad, int iphi, bool reco, bool debug) const {
std::pair<float, float> HGCalDDDConstants::locateCellTrap(
int zside, int lay, int irad, int iphi, bool reco, bool debug) const {
float x(0), y(0);
const auto& indx = getIndex(lay, reco);
if (indx.first >= 0) {
@@ -816,13 +832,13 @@ std::pair<float, float> HGCalDDDConstants::locateCellTrap(int lay, int irad, int
y += hgpar_->yLayerHex_[ll];
if (mode_ == HGCalGeometryMode::TrapezoidCassette) {
int cassette = HGCalTileIndex::tileCassette(iphi, hgpar_->phiOffset_, hgpar_->nphiCassette_, hgpar_->cassettes_);
auto cshift = hgcassette_.getShift(lay, 1, cassette);
auto cshift = hgcassette_.getShift(lay, zside, cassette);
if (debug)
edm::LogVerbatim("HGCalGeom") << "Cassette " << cassette << " Shift " << cshift.first << ":" << cshift.second;
x += cshift.first;
y += cshift.second;
}
if (irad < 0)
if (zside < 0)
x = -x;
}
if (!reco) {
@@ -1286,6 +1302,7 @@ void HGCalDDDConstants::waferFromPosition(const double x, const double y, int& w

void HGCalDDDConstants::waferFromPosition(const double x,
const double y,
const int zside,
const int layer,
int& waferU,
int& waferV,
@@ -1328,11 +1345,14 @@ 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, 1, (ktr->second).cassette);
auto cshift = hgcassette_.getShift(layer, zside, (ktr->second).cassette);
#ifdef EDM_ML_DEBUG
if (debug)
edm::LogVerbatim("HGCalGeom") << "Cassette " << (ktr->second).cassette << " Shift " << cshift.first << ":"
<< cshift.second;
if (debug) {
double phi = std::atan2(yy, xx);
edm::LogVerbatim("HGCalGeom") << " Layer " << layer << " zside 1 "
<< " phi " << convertRadToDeg(phi) << " Cassette " << (ktr->second).cassette
<< " Shift " << cshift.first << ":" << cshift.second;
}
#endif
dx0 = cshift.first;
dy0 = cshift.second;
Loading