Skip to content

Commit

Permalink
Merge pull request #24134 from bsunanda/Phase2-hgx132
Browse files Browse the repository at this point in the history
Phase2-hgx132 Bug fix for HGCal post TDR geometry
  • Loading branch information
cmsbuild committed Aug 3, 2018
2 parents 1402592 + 751a8e5 commit 2220201
Show file tree
Hide file tree
Showing 10 changed files with 269 additions and 22 deletions.
2 changes: 1 addition & 1 deletion Geometry/HGCalCommonData/data/hgcalCons/v9/hgcalCons.xml
Expand Up @@ -97,7 +97,7 @@
<PartSelector path="//HGCalHEScintillatorSensitive.*"/>
<Parameter name="Volume" value="HGCalHEScintillatorSensitive" eval="false"/>
<Parameter name="GeometryMode" value="HGCalGeometryMode::Trapezoid" eval="false"/>
<Parameter name="etaMinBH" value="1.3"/>
<Parameter name="etaMinBH" value="1.25"/>
<Parameter name="LevelZSide" value="3"/>
<Parameter name="LevelTop" value="7"/>
<Parameter name="LevelTop" value="7"/>
Expand Down
2 changes: 1 addition & 1 deletion Geometry/HGCalCommonData/data/hgcalCons/v9p/hgcalCons.xml
Expand Up @@ -97,7 +97,7 @@
<PartSelector path="//HGCalHEScintillatorSensitive.*"/>
<Parameter name="Volume" value="HGCalHEScintillatorSensitive" eval="false"/>
<Parameter name="GeometryMode" value="HGCalGeometryMode::Trapezoid" eval="false"/>
<Parameter name="etaMinBH" value="1.3"/>
<Parameter name="etaMinBH" value="1.25"/>
<Parameter name="LevelZSide" value="3"/>
<Parameter name="LevelTop" value="7"/>
<Parameter name="LevelTop" value="7"/>
Expand Down
10 changes: 7 additions & 3 deletions Geometry/HGCalCommonData/interface/HGCalDDDConstants.h
Expand Up @@ -66,7 +66,8 @@ class HGCalDDDConstants {
std::pair<float,float> locateCell(int cell, int lay, int type,
bool reco) const;
std::pair<float,float> locateCell(int lay, int waferU, int waferV, int cellU,
int cellV, bool reco, bool all) const;
int cellV, bool reco, bool all,
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) const;
Expand All @@ -88,6 +89,8 @@ class HGCalDDDConstants {
int numberCellsHexagon(int wafer) const;
int numberCellsHexagon(int lay, int waferU, int waferV,
bool flag) const;
std::pair<double,double> rangeR(double z, bool reco) const;
std::pair<double,double> rangeZ(bool reco) const;
std::pair<int,int> rowColumnWafer(const int wafer) const;
int scintType(const float dPhi) const
{ return ((dPhi < dPhiMin) ? 0 : 1); }
Expand All @@ -101,7 +104,8 @@ class HGCalDDDConstants {
void waferFromPosition(const double x, const double y,
const int layer, int& waferU,
int& waferV, int& cellU, int& cellV,
int& celltype, double& wt) const;
int& celltype, double& wt,
bool debug=false) const;
bool waferInLayer(int wafer, int lay, bool reco) const;
bool waferFullInLayer(int wafer, int lay, bool reco) const;
int waferCount(const int type) const {return ((type == 0) ? waferMax_[2] : waferMax_[3]);}
Expand All @@ -127,7 +131,7 @@ class HGCalDDDConstants {
const std::vector<double>& posX,
const std::vector<double>& posY) const;
void cellHex(double xloc, double yloc, int cellType, int& cellU,
int& cellV) const;
int& cellV, bool debug=false) const;
std::pair<int,float> getIndex(int lay, bool reco) const;
bool isValidCell(int layindex, int wafer, int cell) const;
bool waferInLayerTest(int wafer, int lay, bool full) const;
Expand Down
144 changes: 133 additions & 11 deletions Geometry/HGCalCommonData/src/HGCalDDDConstants.cc
Expand Up @@ -203,7 +203,7 @@ bool HGCalDDDConstants::cellInLayer(int waferU, int waferV, int cellU,
(mode_ == HGCalGeometryMode::HexagonFull)) {
const auto & xy = ((mode_ == HGCalGeometryMode::Hexagon8) ||
(mode_ == HGCalGeometryMode::Hexagon8Full)) ?
locateCell(lay, waferU, waferV, cellU, cellV, reco, true) :
locateCell(lay, waferU, waferV, cellU, cellV, reco, true, false) :
locateCell(cellU, lay, waferU, reco);
double rpos = sqrt(xy.first*xy.first + xy.second*xy.second);
return ((rpos >= hgpar_->rMinLayHex_[indx.first]) &&
Expand Down Expand Up @@ -539,26 +539,49 @@ std::pair<float,float> HGCalDDDConstants::locateCell(int cell, int lay,
std::pair<float,float> HGCalDDDConstants::locateCell(int lay, int waferU,
int waferV, int cellU,
int cellV, bool reco,
bool all) const {
bool all, bool
#ifdef EDM_ML_DEBUG
debug
#endif
) const {

float 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]);
#ifdef EDM_ML_DEBUG
if (debug)
edm::LogVerbatim("HGCalGeom") << "LocateCell " << lay << ":" << waferU
<< ":" << waferV << ":" << indx << ":"
<< (itr == hgpar_->typesInLayers_.end())
<< ":" << type;
#endif
int kndx = cellV*100 + cellU;
if (type == 0) {
auto ktr = hgpar_->cellFineIndex_.find(kndx);
if (ktr != hgpar_->cellFineIndex_.end()) {
x = hgpar_->cellFineX_[ktr->second];
y = hgpar_->cellFineY_[ktr->second];
}
#ifdef EDM_ML_DEBUG
if (debug)
edm::LogVerbatim("HGCalGeom") << "Fine " << cellU << ":" << cellV << ":"
<< kndx << ":" << x << ":" << y << ":"
<< (ktr != hgpar_->cellFineIndex_.end());
#endif
} else {
auto ktr = hgpar_->cellCoarseIndex_.find(kndx);
if (ktr != hgpar_->cellCoarseIndex_.end()) {
x = hgpar_->cellCoarseX_[ktr->second];
y = hgpar_->cellCoarseY_[ktr->second];
}
#ifdef EDM_ML_DEBUG
if (debug)
edm::LogVerbatim("HGCalGeom") << "Coarse " << cellU << ":" << cellV <<":"
<< kndx << ":" << x << ":" << y << ":"
<< (ktr != hgpar_->cellCoarseIndex_.end());
#endif
}
if (!reco) {
x *= HGCalParameters::k_ScaleToDDD;
Expand All @@ -568,6 +591,11 @@ std::pair<float,float> HGCalDDDConstants::locateCell(int lay, int waferU,
const auto & xy = waferPosition(waferU, waferV, reco);
x += xy.first;
y += xy.second;
#ifdef EDM_ML_DEBUG
if (debug)
edm::LogVerbatim("HGCalGeom") << "With wafer " << x << ":" << y << ":"
<< xy.first << ":" << xy.second;
#endif
}
return std::make_pair(x,y);
}
Expand Down Expand Up @@ -600,6 +628,8 @@ std::pair<float,float> HGCalDDDConstants::locateCellTrap(int lay, int ieta,
double phi = (iphi-0.5)*indx.second;
double z = hgpar_->zLayerHex_[indx.first];
double r = z*std::tan(2.0*std::atan(std::exp(-eta)));
std::pair<double,double> range = rangeR(z,true);
r = std::max(range.first, std::min(r,range.second));
x = r*std::cos(phi);
y = r*std::sin(phi);
}
Expand Down Expand Up @@ -767,6 +797,49 @@ int HGCalDDDConstants::numberCellsHexagon(int lay, int waferU, int waferV,
else return N;
}

std::pair<double,double> HGCalDDDConstants::rangeR(double z, bool reco) const {
double zz = (reco ? std::abs(z) :
HGCalParameters::k_ScaleFromDDD*std::abs(z));
double rmin = zz*hgpar_->slopeMin_;
double rmax(0);
#ifdef EDM_ML_DEBUG
unsigned int ik(0);
#endif
for (unsigned int k=0; k<hgpar_->slopeTop_.size(); ++k) {
if (zz < hgpar_->zFront_[k]) break;
rmax = (hgpar_->rMaxFront_[k] + (zz-hgpar_->zFront_[k]) *
hgpar_->slopeTop_[k]);
#ifdef EDM_ML_DEBUG
ik = k;
#endif
}
#ifdef EDM_ML_DEBUG
edm::LogVerbatim("HGCalGeom") << "DDHGCalEEAlgo:rangeR: " << z << ":" << zz
<< " Zone " << ik << " R " << rmin << ":"
<< rmax;
#endif
if (!reco) {
rmin *= HGCalParameters::k_ScaleToDDD;
rmax *= HGCalParameters::k_ScaleToDDD;
}
return std::pair<double,double>(rmin,rmax);
}

std::pair<double,double> HGCalDDDConstants::rangeZ(bool reco) const {
double zmin = (hgpar_->zLayerHex_[0] - hgpar_->waferThick_);
double zmax = (hgpar_->zLayerHex_[hgpar_->zLayerHex_.size()-1] +
hgpar_->waferThick_);
#ifdef EDM_ML_DEBUG
edm::LogVerbatim("HGCalGeom") << "DDHGCalEEAlgo:rangeZ: " << zmin << ":"
<< zmax << ":" << hgpar_->waferThick_;
#endif
if (!reco) {
zmin *= HGCalParameters::k_ScaleToDDD;
zmax *= HGCalParameters::k_ScaleToDDD;
}
return std::pair<double,double>(zmin,zmax);
}

std::pair<int,int> HGCalDDDConstants::rowColumnWafer(int wafer) const {
int row(0), col(0);
if (wafer < (int)(hgpar_->waferCopy_.size())) {
Expand Down Expand Up @@ -882,7 +955,11 @@ void HGCalDDDConstants::waferFromPosition(const double x, const double y,
void HGCalDDDConstants::waferFromPosition(const double x, const double y,
const int layer, int& waferU,
int& waferV, int& cellU, int& cellV,
int& celltype, double& wt) const {
int& celltype, double& wt, bool
#ifdef EDM_ML_DEBUG
debug
#endif
) const {

double xx(HGCalParameters::k_ScaleFromDDD*x);
double yy(HGCalParameters::k_ScaleFromDDD*y);
Expand All @@ -897,14 +974,31 @@ void HGCalDDDConstants::waferFromPosition(const double x, const double y,
auto itr = hgpar_->typesInLayers_.find(HGCalWaferIndex::waferIndex(layer,waferU,waferV));
celltype = ((itr == hgpar_->typesInLayers_.end()) ? 2 :
hgpar_->waferTypeL_[itr->second]);
#ifdef EDM_ML_DEBUG
if (debug)
edm::LogVerbatim("HGCalGeom") << "WaferFromPosition:: Input " << xx
<< ":" << yy << " compared with "
<< hgpar_->waferPosX_[k] << ":"
<< hgpar_->waferPosY_[k]
<< " difference " << dx << ":" << dy
<< ":" << dx*tan30deg_ << ":"
<< (hexside_-dy) << " comparator "
<< rmax_ << ":" << hexside_ <<" wafer "
<< waferU << ":" << waferV << ":"
<< celltype;
#endif
xx -= hgpar_->waferPosX_[k];
yy -= hgpar_->waferPosY_[k];
break;
}
}
}
if (std::abs(waferU) <= hgpar_->waferUVMax_) {
cellHex(xx, yy, celltype, cellU, cellV);
cellHex(xx, yy, celltype, cellU, cellV
#ifdef EDM_ML_DEBUG
, debug
#endif
);
wt = ((celltype < 2) ?
(hgpar_->cellThickness_[celltype]/hgpar_->waferThick_) : 1.0);
} else {
Expand Down Expand Up @@ -1053,26 +1147,54 @@ int HGCalDDDConstants::cellHex(double xx, double yy,
}

void HGCalDDDConstants::cellHex(double xloc, double yloc, int cellType,
int& cellU, int& cellV) const {
int& cellU, int& cellV, bool
#ifdef EDM_ML_DEBUG
debug
#endif
) const {
int N = (cellType == 0) ? hgpar_->nCellsFine_ : hgpar_->nCellsCoarse_;
double Rc = 2*rmax_/(3*N);
double rc = 0.5*Rc*sqrt3_;
double v0 = ((xloc/Rc -1.0)/1.5);
int cv0 = (v0 > 0) ? (N + (int)(v0+0.5)) : (N - (int)(-v0+0.5));
double u0 = (0.5*yloc/rc+0.5*cv0);
int cu0 = (u0 > 0) ? (N/2 + (int)(u0+0.5)) : (N/2 - (int)(-u0+0.5));
cu0 = std::max(0,std::min(cu0,2*N-1));
cv0 = std::max(0,std::min(cv0,2*N-1));
if (cv0-cu0 >= N) cv0 = cu0+N-1;
#ifdef EDM_ML_DEBUG
if (debug)
edm::LogVerbatim("HGCalGeom") << "cellHex: input " << xloc << ":"
<< yloc << ":" << cellType << " parameter "
<< rc << ":" << Rc << " u0 " << u0 << ":"
<< cu0 << " v0 " << v0 << ":" << cv0;
#endif
bool found(false);
static const int shift[3] = {0,1,-1};
for (int i1=0; i1<3; ++i1) {
cellU = cu0 + shift[i1];
for (int i2=0; i2<3; ++i2) {
cellV = cv0 + shift[i2];
double xc = (1.5*(cellV-N)+1.0)*Rc;
double yc = (2*cellU-cellV-N)*rc;
if (((std::abs(xloc-xc) <= rc) && (std::abs(yloc-yc) <= 0.5*Rc)) ||
((std::abs(yloc-yc) <= Rc) &&
(std::abs(xloc-xc) <= sqrt3_*std::abs(yloc-yc-Rc)))) {
found = true; break;
if (((cellV-cellU) < N) && ((cellU-cellV) <= N) && (cellU >= 0) &&
(cellV >= 0) && (cellU < 2*N) && (cellV < 2*N)) {
double xc = (1.5*(cellV-N)+1.0)*Rc;
double yc = (2*cellU-cellV-N)*rc;
if ((std::abs(yloc-yc) <= rc) && (std::abs(xloc-xc) <= Rc) &&
((std::abs(xloc-xc) <= 0.5*Rc) ||
(std::abs(yloc-yc) <= sqrt3_*(Rc-std::abs(xloc-xc))))) {
#ifdef EDM_ML_DEBUG
if (debug)
edm::LogVerbatim("HGCalGeom") << "cellHex: local " << xc << ":"
<< yc << " difference "
<< std::abs(xloc-xc) << ":"
<< std::abs(yloc-yc) << ":"
<< sqrt3_*(Rc-std::abs(yloc-yc))
<< " comparator " << rc << ":" << Rc
<< " (u,v) = (" << cellU << ","
<< cellV << ")";
#endif
found = true; break;
}
}
}
if (found) break;
Expand Down
2 changes: 1 addition & 1 deletion Geometry/HGCalCommonData/src/HGCalParametersFromDD.cc
Expand Up @@ -198,7 +198,7 @@ bool HGCalParametersFromDD::build(const DDCompactView* cpv,
php.firstLayer_ = (int)(getDDDValue("FirstLayer", sv));
php.waferThick_ = HGCalParameters::k_ScaleFromDDD*getDDDValue("WaferThickness", sv);
php.waferSize_ = php.waferR_ = 0;
php.waferThick_ = php.sensorSeparation_= php.mouseBite_ = 0;
php.sensorSeparation_= php.mouseBite_ = 0;
#ifdef EDM_ML_DEBUG
edm::LogVerbatim("HGCalGeom") << "Top levels " << php.levelT_[0] << ":"
<< php.levelT_[1] << " EtaMinBH "
Expand Down
3 changes: 3 additions & 0 deletions SimCalorimetry/HGCalSimProducers/interface/HGCDigitizer.h
Expand Up @@ -110,6 +110,9 @@ private :
std::unique_ptr<hgc::HGCSimHitDataAccumulator> simHitAccumulator_;
void resetSimHitDataAccumulator();

//debug position
void checkPosition(const HGCalDigiCollection* digis) const;

//digitizers
std::unique_ptr<HGCEEDigitizer> theHGCEEDigitizer_;
std::unique_ptr<HGCHEbackDigitizer> theHGCHEbackDigitizer_;
Expand Down

0 comments on commit 2220201

Please sign in to comment.