Skip to content

Commit

Permalink
Bug fix to geometry and provision to mask parts of virtual wafer
Browse files Browse the repository at this point in the history
  • Loading branch information
Sunanda committed Oct 26, 2018
1 parent 5d5f154 commit ab10b1d
Show file tree
Hide file tree
Showing 11 changed files with 348 additions and 37 deletions.
1 change: 1 addition & 0 deletions Geometry/HGCalCommonData/interface/HGCalDDDConstants.h
Expand Up @@ -85,6 +85,7 @@ class HGCalDDDConstants {
std::pair<float,float> locateCellTrap(int lay, int ieta, int iphi,
bool reco) const;
int levelTop(int ind=0) const {return hgpar_->levelT_[ind];}
bool maskCell(const DetId& id, int corners) const;
int maxCellUV() const {
return ((mode_==HGCalGeometryMode::Trapezoid) ? hgpar_->nCellsFine_ :
2*hgpar_->nCellsFine_);}
Expand Down
4 changes: 3 additions & 1 deletion Geometry/HGCalCommonData/interface/HGCalParameters.h
Expand Up @@ -17,6 +17,7 @@ class HGCalParameters {

typedef std::vector<std::unordered_map<int32_t,int32_t> > layer_map;
typedef std::unordered_map<int32_t, int32_t> wafer_map;
typedef std::unordered_map<int32_t,std::pair<int32_t,int32_t> > waferT_map;

static constexpr double k_ScaleFromDDD = 0.1;
static constexpr double k_ScaleToDDD = 10.0;
Expand Down Expand Up @@ -152,7 +153,8 @@ class HGCalParameters {
int firstMixedLayer_;
wafer_map wafersInLayers_;
wafer_map typesInLayers_;

waferT_map waferTypes_;

COND_SERIALIZABLE;

private:
Expand Down
5 changes: 4 additions & 1 deletion Geometry/HGCalCommonData/interface/HGCalWaferIndex.h
Expand Up @@ -10,10 +10,13 @@ class HGCalWaferIndex {

HGCalWaferIndex() {}
~HGCalWaferIndex() {}
static int32_t waferIndex(int32_t layer, int32_t waferU, int32_t waferV);
static int32_t waferIndex(int32_t layer, int32_t waferU, int32_t waferV,
bool old=false);
static int32_t waferLayer(const int32_t index);
static int32_t waferU(const int32_t index);
static int32_t waferV(const int32_t index);
static int32_t waferCopy(const int32_t index);
static bool waferFormat(const int32_t index);

};

Expand Down
110 changes: 102 additions & 8 deletions Geometry/HGCalCommonData/src/HGCalDDDConstants.cc
Expand Up @@ -691,6 +691,100 @@ std::pair<float,float> HGCalDDDConstants::locateCellTrap(int lay, int irad,
return std::make_pair(x,y);
}

bool HGCalDDDConstants::maskCell(const DetId& detId, int corners) const {
bool mask(false);
if (corners > 2 && corners < 6) {
if ((mode_ == HGCalGeometryMode::Hexagon8) ||
(mode_ == HGCalGeometryMode::Hexagon8Full)) {
HGCSiliconDetId id(detId);
int wl = HGCalWaferIndex::waferIndex(id.layer(),id.waferU(),id.waferV());
auto itr = hgpar_->waferTypes_.find(wl);
#ifdef EDM_ML_DEBUG
edm::LogVerbatim("HGCalGeom") << "MaskCell: Layer " << id.layer()
<< " Wafer " << id.waferU() << ":"
<< id.waferV() << " Index " << wl << ":"
<< (itr != hgpar_->waferTypes_.end());
#endif
if (itr != hgpar_->waferTypes_.end()) {
int N = getUVMax(id.type());
int ncor = (itr->second).first;
int fcor = (itr->second).second;
if (ncor >= corners) {
int u = id.cellU();
int v = id.cellV();
if (ncor == 4) {
switch (fcor) {
case(0): { mask = (v >= N); break; }
case(1): { mask = (u >= N); break; }
case(2): { mask = (u <= v); break; }
case(3): { mask = (v < N); break; }
case(4): { mask = (u < N); break; }
default: { mask = (u > v); break; }
}
} else {
switch (fcor) {
case(0): {
if (ncor == 3) {
mask = !((u > 2*v) && (v < N));
} else {
mask = ((u >= N) && (v >= N) && ((u+v) > (3*N-2)));
}
break;
}
case(1): {
if (ncor == 3) {
mask = !((u+v) < N);
} else {
mask = ((u >= N) && (u > v) && ((2*u-v) > 2*N));
}
break;
}
case(2): {
if (ncor == 3) {
mask = !((u < N) && (v > u) && (v > (2*u-1)));
} else {
mask = ((u > 2*v) && (v < N));
}
break;
}
case(3): {
if (ncor == 3) {
mask = !((v >= u) && ((2*v-u) > (2*N-2)));
} else {
mask = ((u+v) < N);
}
break;
}
case(4) : {
if (ncor == 3) {
mask = !((u >= N) && (v >= N) && ((u+v) > (3*N-2)));
} else {
mask = ((u < N) && (v > u) && (v > (2*u-1)));
}
break;
}
default: {
if (ncor == 3) {
mask = !((u >= N) && (u > v) && ((2*u-v) > 2*N));
} else {
mask = ((v >= u) && ((2*v-u) > (2*N-2)));
}
break;
}
}
}
#ifdef EDM_ML_DEBUG
edm::LogVerbatim("HGCalGeom") << "Corners: " << ncor << ":" << fcor
<< " N " << N << " u " << u << " v "
<< v << " Mask " << mask;
#endif
}
}
}
}
return mask;
}

int HGCalDDDConstants::maxCells(bool reco) const {

int cells(0);
Expand Down Expand Up @@ -883,8 +977,8 @@ std::pair<double,double> HGCalDDDConstants::rangeR(double z, bool reco) const {
rmax *= HGCalParameters::k_ScaleToDDD;
}
#ifdef EDM_ML_DEBUG
edm::LogVerbatim("HGCalGeom") << "DDHGCalEEAlgo:rangeR: " << z << ":" << zz
<< " R " << rmin << ":" << rmax;
edm::LogVerbatim("HGCalGeom") << "HGCalDDDConstants:rangeR: " << z << ":"
<< zz << " R " << rmin << ":" << rmax;
#endif
return std::pair<double,double>(rmin,rmax);
}
Expand All @@ -894,7 +988,7 @@ std::pair<double,double> HGCalDDDConstants::rangeZ(bool reco) const {
double zmax = (hgpar_->zLayerHex_[hgpar_->zLayerHex_.size()-1] +
hgpar_->waferThick_);
#ifdef EDM_ML_DEBUG
edm::LogVerbatim("HGCalGeom") << "DDHGCalEEAlgo:rangeZ: " << zmin << ":"
edm::LogVerbatim("HGCalGeom") << "HGCalDDDConstants:rangeZ: " << zmin << ":"
<< zmax << ":" << hgpar_->waferThick_;
#endif
if (!reco) {
Expand Down Expand Up @@ -1320,12 +1414,12 @@ bool HGCalDDDConstants::waferInLayerTest(int wafer, int lay, bool full) const {
const double waferX = hgpar_->waferPosX_[wafer];
const double waferY = hgpar_->waferPosY_[wafer];
double xc[HGCalParameters::k_CornerSize], yc[HGCalParameters::k_CornerSize];
xc[0] = waferX+rmax_; yc[0] = waferY-0.5*hexside_;
xc[1] = waferX+rmax_; yc[1] = waferY+0.5*hexside_;
xc[2] = waferX; yc[2] = waferY+hexside_;
xc[3] = waferX-rmax_; yc[3] = waferY+0.5*hexside_;
xc[0] = waferX; yc[0] = waferY+hexside_;
xc[1] = waferX-rmax_; yc[1] = waferY+0.5*hexside_;
xc[2] = waferX-rmax_; yc[2] = waferY-0.5*hexside_;
xc[3] = waferX; yc[3] = waferY-hexside_;
xc[4] = waferX+rmax_; yc[4] = waferY-0.5*hexside_;
xc[5] = waferX; yc[5] = waferY-hexside_;
xc[5] = waferX+rmax_; yc[5] = waferY+0.5*hexside_;
bool cornerOne(false), cornerAll(true);
for (unsigned int k=0; k<HGCalParameters::k_CornerSize; ++k) {
double rpos = std::sqrt(xc[k]*xc[k]+yc[k]*yc[k]);
Expand Down
111 changes: 95 additions & 16 deletions Geometry/HGCalCommonData/src/HGCalGeomParameters.cc
Expand Up @@ -837,9 +837,11 @@ void HGCalGeomParameters::loadWaferHexagon(HGCalParameters& php) {
double rr = 2.0*dx*tan(30.0*CLHEP::deg);
int ncol = (int)(2.0*rout/waferW) + 1;
int nrow = (int)(rout/(waferW*tan(30.0*CLHEP::deg))) + 1;
int ns2 = (2*ncol+1)*(2*nrow+1)*php.layer_.size();
int incm(0), inrm(0), kount(0), ntot(0);
double xc[HGCalParameters::k_CornerSize], yc[HGCalParameters::k_CornerSize];
HGCalParameters::layer_map copiesInLayers(php.layer_.size()+1);
HGCalParameters::waferT_map waferTypes(ns2+1);
#ifdef EDM_ML_DEBUG
edm::LogVerbatim("HGCalGeom") << "Row " << nrow << " Column " << ncol;
#endif
Expand All @@ -850,12 +852,12 @@ void HGCalGeomParameters::loadWaferHexagon(HGCalParameters& php) {
if (inr%2 == inc%2) {
double xpos = nc*dx;
double ypos = nr*dy;
xc[0] = xpos+dx; yc[0] = ypos-0.5*rr;
xc[1] = xpos+dx; yc[1] = ypos+0.5*rr;
xc[2] = xpos; yc[2] = ypos+rr;
xc[3] = xpos-dx; yc[3] = ypos+0.5*rr;
xc[0] = xpos; yc[0] = ypos+rr;
xc[1] = xpos-dx; yc[1] = ypos+0.5*rr;
xc[2] = xpos-dx; yc[2] = ypos-0.5*rr;
xc[3] = xpos; yc[3] = ypos-rr;
xc[4] = xpos+dx; yc[4] = ypos-0.5*rr;
xc[5] = xpos; yc[5] = ypos-rr;
xc[5] = xpos+dx; yc[5] = ypos+0.5*rr;
bool cornerOne(false);
for (unsigned int k=0; k<HGCalParameters::k_CornerSize; ++k) {
double rpos = std::sqrt(xc[k]*xc[k]+yc[k]*yc[k]);
Expand Down Expand Up @@ -891,23 +893,48 @@ void HGCalGeomParameters::loadWaferHexagon(HGCalParameters& php) {
php.waferPosY_.emplace_back(ypos);
for (unsigned int il=0; il<php.layer_.size(); ++il) {
bool corner(false), cornerAll(true);
int nCorner(0), firstCorner(-1), firstMiss(-1);
for (unsigned int k=0; k<HGCalParameters::k_CornerSize; ++k) {
double rpos = std::sqrt(xc[k]*xc[k]+yc[k]*yc[k]);
if (rpos >= php.rMinLayHex_[il] &&
rpos <= php.rMaxLayHex_[il]) corner = true;
else cornerAll = false;
rpos <= php.rMaxLayHex_[il]) {
corner = true;
++nCorner;
if (firstCorner < 0) firstCorner = k;
} else {
cornerAll = false;
if (firstMiss < 0) firstMiss = k;
}
}
if (corner) {
auto cpy = copiesInLayers[php.layer_[il]].find(copy);
if (cpy == copiesInLayers[php.layer_[il]].end())
copiesInLayers[php.layer_[il]][copy] = cornerAll ? php.waferCopy_.size() : -1;
}
if ((!cornerAll) && (nCorner > 0)) {
if (nCorner == 3) {
if ((firstCorner == 0) && (firstMiss < 3))
firstCorner = firstMiss+3;
} else if (nCorner == 4) {
if ((firstCorner == 0) && (firstMiss < 4))
firstCorner = firstMiss+2;
} else if (nCorner == 5) {
if ((firstCorner == 0) && (firstMiss < 5))
firstCorner = firstMiss+1;
} else if (nCorner == 2) {
if ((firstCorner == 0) && (firstMiss < 2))
firstCorner = firstMiss+4;
}
int wl = HGCalWaferIndex::waferIndex(php.layer_[il],copy,0,true);
waferTypes[wl] = std::make_pair(nCorner,firstCorner);
}
}
}
}
}
}
php.copiesInLayers_ = copiesInLayers;
php.waferTypes_ = waferTypes;
php.nSectors_ = (int)(php.waferCopy_.size());
php.waferUVMax_ = 0;
#ifdef EDM_ML_DEBUG
Expand Down Expand Up @@ -967,6 +994,7 @@ void HGCalGeomParameters::loadWaferHexagon8(HGCalParameters& php) {
#endif
HGCalParameters::wafer_map wafersInLayers(ns1+1);
HGCalParameters::wafer_map typesInLayers(ns2+1);
HGCalParameters::waferT_map waferTypes(ns2+1);
int ipos(0), lpos(0), uvmax(0);
std::vector<int> uvmx(php.zLayerHex_.size(),0);
double xc[HGCalParameters::k_CornerSize], yc[HGCalParameters::k_CornerSize];
Expand All @@ -982,12 +1010,12 @@ void HGCalGeomParameters::loadWaferHexagon8(HGCalParameters& php) {
php.waferPosY_.emplace_back(ypos);
wafersInLayers[indx] = ipos;
++ipos;
xc[0] = xpos+r; yc[0] = ypos+0.5*R;
xc[1] = xpos; yc[1] = ypos+R;
xc[2] = xpos-r; yc[2] = ypos+0.5*R;
xc[3] = xpos-r; yc[3] = ypos-0.5*R;
xc[4] = xpos; yc[4] = ypos-R;
xc[5] = xpos+r; yc[5] = ypos-0.5*R;
xc[0] = xpos; yc[0] = ypos+R;
xc[1] = xpos-r; yc[1] = ypos+0.5*R;
xc[2] = xpos-r; yc[2] = ypos-0.5*R;
xc[3] = xpos; yc[3] = ypos-R;
xc[4] = xpos+r; yc[4] = ypos-0.5*R;
xc[5] = xpos+r; yc[5] = ypos+0.5*R;
bool cornerOne(false), cornerAll(true);
for (unsigned int k=0; k<HGCalParameters::k_CornerSize; ++k) {
double rpos = sqrt(xc[k]*xc[k]+yc[k]*yc[k]);
Expand All @@ -1007,23 +1035,74 @@ void HGCalGeomParameters::loadWaferHexagon8(HGCalParameters& php) {
++lpos;
#ifdef EDM_ML_DEBUG
indtypes.emplace_back(kndx);
int corners[6];
#endif
bool cornerOne(false), cornerAll(true);
int nCorner(0), firstCorner(-1), firstMiss(-1);
for (unsigned int k=0; k<HGCalParameters::k_CornerSize; ++k) {
double rpos = sqrt(xc[k]*xc[k]+yc[k]*yc[k]);
if (rpos <= php.rMaxLayHex_[i]) cornerOne = true;
else cornerAll = false;
if ((rpos <= php.rMaxLayHex_[i]) && (rpos >= php.rMinLayHex_[i])) {
cornerOne = true;
#ifdef EDM_ML_DEBUG
corners[nCorner] = k;
#endif
if (firstCorner < 0) firstCorner = k;
++nCorner;
} else {
cornerAll = false;
if (firstMiss < 0) firstMiss = k;
}
}
#ifdef EDM_ML_DEBUG
if (((nCorner==0) && std::abs(u) < 5 && std::abs(v) < 5) ||
(std::abs(u) < 2 && std::abs(v) < 2)) {
edm::LogVerbatim("HGCalGeom") << "Layer " << lay << " R "
<< php.rMinLayHex_[i] << ":"
<< php.rMaxLayHex_[i] << " u "
<< u << " v " << v << " with "
<< nCorner << " corners";
for (int k=0; k<6; ++k) {
double rpos = std::sqrt(xc[k]*xc[k]+yc[k]*yc[k]);
edm::LogVerbatim("HGCalGeom") << "[" << k << "] x " << xc[k]
<< " y " << yc[k] << " R " << rpos;
}
}
#endif
if ((cornerAll) || (cornerOne && php.defineFull_)) {
uvmx[i] = std::max(uvmx[i],std::max(std::abs(u),std::abs(v)));
}
if ((!cornerAll) && (nCorner > 0)) {
if (nCorner == 3) {
if ((firstCorner == 0) && (firstMiss < 3))
firstCorner = firstMiss+3;
} else if (nCorner == 4) {
if ((firstCorner == 0) && (firstMiss < 4))
firstCorner = firstMiss+2;
} else if (nCorner == 5) {
if ((firstCorner == 0) && (firstMiss < 5))
firstCorner = firstMiss+1;
} else if (nCorner == 2) {
if ((firstCorner == 0) && (firstMiss < 2))
firstCorner = firstMiss+4;
}
#ifdef EDM_ML_DEBUG
edm::LogVerbatim("HGCalGeom") << "Layer " << lay << " u|v " << u
<< ":" << v << " with " << nCorner
<< " corners First " << firstCorner;
for (int k=0; k<nCorner; ++k)
edm::LogVerbatim("HGCalGeom") << " [" << k << " ] " << corners[k];
#endif
int wl = HGCalWaferIndex::waferIndex(lay,u,v);
waferTypes[wl] = std::make_pair(nCorner,firstCorner);
}
}
}
}
php.waferUVMax_ = uvmax;
php.waferUVMaxLayer_= uvmx;
php.wafersInLayers_ = wafersInLayers;
php.typesInLayers_ = typesInLayers;
php.waferTypes_ = waferTypes;
php.nSectors_ = (int)(php.waferCopy_.size());
HGCalParameters::hgtrap mytr;
mytr.lay = 1; mytr.bl = php.waferR_;
Expand Down Expand Up @@ -1287,5 +1366,5 @@ HGCalGeomParameters::cellPosition(const std::vector<HGCalGeomParameters::cellPar
dy = (yy - itrf->xyz.y());
if (std::abs(dy) < tolerance) dy = 0;
}
return std::pair<double,double>(dx,dy);
return std::make_pair(dx,dy);
}

0 comments on commit ab10b1d

Please sign in to comment.