Skip to content

Commit

Permalink
Code check
Browse files Browse the repository at this point in the history
  • Loading branch information
Sunanda committed Mar 24, 2022
1 parent e37c6ca commit 0acf376
Show file tree
Hide file tree
Showing 8 changed files with 69 additions and 36 deletions.
11 changes: 9 additions & 2 deletions Geometry/HGCalCommonData/interface/HGCalDDDConstants.h
Expand Up @@ -84,8 +84,15 @@ class HGCalDDDConstants {
std::pair<float, float> localToGlobal8(
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, int waferU, int waferV, int cellU, int cellV, bool reco, bool all, bool norot = false, bool debug = false) const;
std::pair<float, float> locateCell(int lay,
int waferU,
int waferV,
int cellU,
int cellV,
bool reco,
bool all,
bool norot = false,
bool debug = false) const;
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;
Expand Down
5 changes: 3 additions & 2 deletions Geometry/HGCalCommonData/src/HGCalDDDConstants.cc
Expand Up @@ -672,8 +672,9 @@ std::pair<float, float> HGCalDDDConstants::locateCell(
int indx = HGCalWaferIndex::waferIndex(lay, waferU, waferV);
auto itr = hgpar_->typesInLayers_.find(indx);
int type = ((itr == hgpar_->typesInLayers_.end()) ? 2 : hgpar_->waferTypeL_[itr->second]);
bool rotx = (norot) ? false :
((!hgpar_->layerType_.empty()) && (hgpar_->layerType_[lay - hgpar_->firstLayer_] == HGCalTypes::WaferCenterR));
bool rotx = (norot) ? false
: ((!hgpar_->layerType_.empty()) &&
(hgpar_->layerType_[lay - hgpar_->firstLayer_] == HGCalTypes::WaferCenterR));
if (debug) {
edm::LogVerbatim("HGCalGeom") << "LocateCell " << lay << ":" << (lay - hgpar_->firstLayer_) << ":" << rotx << ":"
<< waferU << ":" << waferV << ":" << indx << ":"
Expand Down
2 changes: 1 addition & 1 deletion Geometry/HGCalGeometry/interface/HGCalGeometry.h
Expand Up @@ -80,7 +80,7 @@ class HGCalGeometry final : public CaloSubdetectorGeometry {
/// Returns the corner points of this cell's volume.
CornersVec getCorners(const DetId& id) const;
CornersVec get8Corners(const DetId& id) const;
CornersVec getNewCorners(const DetId& id, bool debug=false) const;
CornersVec getNewCorners(const DetId& id, bool debug = false) const;

// Get neighbor in z along a direction
DetId neighborZ(const DetId& idin, const GlobalVector& p) const;
Expand Down
15 changes: 11 additions & 4 deletions Geometry/HGCalGeometry/src/FastTimeGeometry.cc
Expand Up @@ -64,8 +64,13 @@ void FastTimeGeometry::newCell(
}

#ifdef EDM_ML_DEBUG
edm::LogVerbatim("FastTimeGeom") << "FastTimeGeometry::newCell-> [" << cellIndex << "] front:" << f1.x() << '/' << f1.y() << '/' << f1.z() << " back:" << f2.x() << '/' << f2.y() << '/' << f2.z() << " eta|phi " << m_cellVec[cellIndex].etaPos() << ":" << m_cellVec[cellIndex].phiPos() << " id:" << FastTimeDetId(detId) << " with valid DetId from " << nOld << " to " << m_validIds.size();
edm::LogVerbatim("FastTimeGeom") << "Cell[" << cellIndex << "] " << std::hex << geomId.rawId() << ":" << m_validGeomIds[cellIndex].rawId() << std::dec;
edm::LogVerbatim("FastTimeGeom") << "FastTimeGeometry::newCell-> [" << cellIndex << "] front:" << f1.x() << '/'
<< f1.y() << '/' << f1.z() << " back:" << f2.x() << '/' << f2.y() << '/' << f2.z()
<< " eta|phi " << m_cellVec[cellIndex].etaPos() << ":"
<< m_cellVec[cellIndex].phiPos() << " id:" << FastTimeDetId(detId)
<< " with valid DetId from " << nOld << " to " << m_validIds.size();
edm::LogVerbatim("FastTimeGeom") << "Cell[" << cellIndex << "] " << std::hex << geomId.rawId() << ":"
<< m_validGeomIds[cellIndex].rawId() << std::dec;
#endif
}

Expand Down Expand Up @@ -117,7 +122,8 @@ DetId FastTimeGeometry::getClosestCell(const GlobalPoint& r) const {
}
FastTimeDetId id = FastTimeDetId(m_Type, etaZPhi.first, etaZPhi.second, zside);
#ifdef EDM_ML_DEBUG
edm::LogVerbatim("FastTimeGeom") << "getClosestCell: for (" << r.x() << ", " << r.y() << ", " << r.z() << ") Id " << id.type() << ":" << id.zside() << ":" << id.ieta() << ":" << id.iphi();
edm::LogVerbatim("FastTimeGeom") << "getClosestCell: for (" << r.x() << ", " << r.y() << ", " << r.z() << ") Id "
<< id.type() << ":" << id.zside() << ":" << id.ieta() << ":" << id.iphi();
#endif

return (topology().valid(id) ? DetId(id) : DetId());
Expand All @@ -143,7 +149,8 @@ unsigned int FastTimeGeometry::indexFor(const DetId& id) const {
DetId geoId = (DetId)(FastTimeDetId(id).geometryCell());
cellIndex = topology().detId2denseGeomId(geoId);
#ifdef EDM_ML_DEBUG
edm::LogVerbatim("FastTimeGeom") << "indexFor " << std::hex << id.rawId() << ":" << geoId.rawId() << std::dec << " index " << cellIndex;
edm::LogVerbatim("FastTimeGeom") << "indexFor " << std::hex << id.rawId() << ":" << geoId.rawId() << std::dec
<< " index " << cellIndex;
#endif
}
return cellIndex;
Expand Down
8 changes: 6 additions & 2 deletions Geometry/HGCalGeometry/src/FastTimeGeometryLoader.cc
Expand Up @@ -22,7 +22,10 @@ FastTimeGeometry* FastTimeGeometryLoader::build(const FastTimeTopology& topology
unsigned int numberOfCells = topology.totalGeomModules(); // both sides
int detType = topology.detectorType();
#ifdef EDM_ML_DEBUG
edm::LogVerbatim("FastTimeGeom") << "Number of Cells " << numberOfCells << " for type " << detType << " of sub-detector " << topology.subDetector() << " Shape parameters " << FastTimeGeometry::k_NumberOfShapes << ":" << FastTimeGeometry::k_NumberOfParametersPerShape;
edm::LogVerbatim("FastTimeGeom") << "Number of Cells " << numberOfCells << " for type " << detType
<< " of sub-detector " << topology.subDetector() << " Shape parameters "
<< FastTimeGeometry::k_NumberOfShapes << ":"
<< FastTimeGeometry::k_NumberOfParametersPerShape;
#endif
geom->allocateCorners(numberOfCells);
geom->allocatePar(FastTimeGeometry::k_NumberOfShapes, FastTimeGeometry::k_NumberOfParametersPerShape);
Expand All @@ -46,7 +49,8 @@ FastTimeGeometry* FastTimeGeometryLoader::build(const FastTimeTopology& topology
const HepGeom::Transform3D ht3d(hr, h3v);
DetId detId = (DetId)(FastTimeDetId(detType, 0, 0, zside));
#ifdef EDM_ML_DEBUG
edm::LogVerbatim("FastTimeGeom") << "FastTimeGeometryLoader:: transf " << ht3d.getTranslation() << " and " << ht3d.getRotation();
edm::LogVerbatim("FastTimeGeom") << "FastTimeGeometryLoader:: transf " << ht3d.getTranslation() << " and "
<< ht3d.getRotation();
#endif
params[0] = topology.dddConstants().getZHalf(detType);
params[1] = params[2] = 0;
Expand Down
46 changes: 29 additions & 17 deletions Geometry/HGCalGeometry/src/HGCalGeometry.cc
Expand Up @@ -197,9 +197,7 @@ bool HGCalGeometry::present(const DetId& detId) const {
return (nullptr != getGeometryRawPtr(index));
}

GlobalPoint HGCalGeometry::getPosition(const DetId& detid) const {
return getPosition(detid, false);
}
GlobalPoint HGCalGeometry::getPosition(const DetId& detid) const { return getPosition(detid, false); }

GlobalPoint HGCalGeometry::getPosition(const DetId& detid, bool debug) const {
unsigned int cellIndex = indexFor(detid);
Expand All @@ -213,21 +211,29 @@ GlobalPoint HGCalGeometry::getPosition(const DetId& detid, bool debug) const {
const HepGeom::Point3D<float> lcoord(xy.first, xy.second, 0);
glob = m_cellVec[cellIndex].getPosition(lcoord);
if (debug)
edm::LogVerbatim("HGCalGeom") << "getPosition:: index " << cellIndex << " Local " << lcoord.x() << ":" << lcoord.y() << " ID " << id.iCell1 << ":" << id.iSec1 << " Global " << glob;
edm::LogVerbatim("HGCalGeom") << "getPosition:: index " << cellIndex << " Local " << lcoord.x() << ":"
<< lcoord.y() << " ID " << id.iCell1 << ":" << id.iSec1 << " Global " << glob;
} else if (m_topology.tileTrapezoid()) {
const HepGeom::Point3D<float> lcoord(0, 0, 0);
glob = m_cellVec2[cellIndex].getPosition(lcoord);
if (debug)
edm::LogVerbatim("HGCalGeom") << "getPositionTrap:: index " << cellIndex << " Local " << lcoord.x() << ":" << lcoord.y() << " ID " << id.iLay << ":" << id.iSec1 << ":" << id.iCell1 << " Global " << glob;
edm::LogVerbatim("HGCalGeom") << "getPositionTrap:: index " << cellIndex << " Local " << lcoord.x() << ":"
<< lcoord.y() << " ID " << id.iLay << ":" << id.iSec1 << ":" << id.iCell1
<< " Global " << glob;
} else {
if (debug)
edm::LogVerbatim("HGCalGeom") << "getPosition for " << HGCSiliconDetId(detid) << " Layer " << id.iLay << " Wafer " << id.iSec1 << ":" << id.iSec2 << " Cell " << id.iCell1 << ":" << id.iCell2;
xy = m_topology.dddConstants().locateCell(id.iLay, id.iSec1, id.iSec2, id.iCell1, id.iCell2, true, true, false, debug);
edm::LogVerbatim("HGCalGeom") << "getPosition for " << HGCSiliconDetId(detid) << " Layer " << id.iLay
<< " Wafer " << id.iSec1 << ":" << id.iSec2 << " Cell " << id.iCell1 << ":"
<< id.iCell2;
xy = m_topology.dddConstants().locateCell(
id.iLay, id.iSec1, id.iSec2, id.iCell1, id.iCell2, true, true, false, debug);
double xx = id.zSide * xy.first;
double zz = id.zSide * m_topology.dddConstants().waferZ(id.iLay, true);
glob = GlobalPoint(xx, xy.second, zz);
if (debug)
edm::LogVerbatim("HGCalGeom") << "getPositionWafer:: index " << cellIndex << " Local " << xy.first << ":" << xy.second << " ID " << id.iLay << ":" << id.iSec1 << ":" << id.iSec2 << ":" << id.iCell1 << ":" << id.iCell2 << " Global " << glob;
edm::LogVerbatim("HGCalGeom") << "getPositionWafer:: index " << cellIndex << " Local " << xy.first << ":"
<< xy.second << " ID " << id.iLay << ":" << id.iSec1 << ":" << id.iSec2 << ":"
<< id.iCell1 << ":" << id.iCell2 << " Global " << glob;
}
}
return glob;
Expand Down Expand Up @@ -303,7 +309,8 @@ HGCalGeometry::CornersVec HGCalGeometry::getCorners(const DetId& detid) const {
co[i] = m_cellVec[cellIndex].getPosition(lcoord);
}
} else {
xy = m_topology.dddConstants().locateCell(id.iLay, id.iSec1, id.iSec2, id.iCell1, id.iCell2, true, false, true, debugLocate);
xy = m_topology.dddConstants().locateCell(
id.iLay, id.iSec1, id.iSec2, id.iCell1, id.iCell2, true, false, true, debugLocate);
float zz = m_topology.dddConstants().waferZ(id.iLay, true);
float dx = k_fac2 * m_cellVec[cellIndex].param()[FlatHexagon::k_r];
float dy = k_fac1 * m_cellVec[cellIndex].param()[FlatHexagon::k_R];
Expand Down Expand Up @@ -359,7 +366,8 @@ HGCalGeometry::CornersVec HGCalGeometry::get8Corners(const DetId& detid) const {
co[i] = m_cellVec[cellIndex].getPosition(lcoord);
}
} else {
xy = m_topology.dddConstants().locateCell(id.iLay, id.iSec1, id.iSec2, id.iCell1, id.iCell2, true, false, true, debugLocate);
xy = m_topology.dddConstants().locateCell(
id.iLay, id.iSec1, id.iSec2, id.iCell1, id.iCell2, true, false, true, debugLocate);
dx = k_fac2 * m_cellVec[cellIndex].param()[FlatHexagon::k_r];
float dy = k_fac1 * m_cellVec[cellIndex].param()[FlatHexagon::k_R];
float dz = -id.zSide * m_cellVec[cellIndex].param()[FlatHexagon::k_dZ];
Expand All @@ -381,7 +389,8 @@ HGCalGeometry::CornersVec HGCalGeometry::getNewCorners(const DetId& detid, bool
unsigned int cellIndex = indexFor(detid);
HGCalTopology::DecodedDetId id = m_topology.decode(detid);
if (debug)
edm::LogVerbatim("HGCalGeom") << "NewCorners for Layer " << id.iLay << " Wafer " << id.iSec1 << ":" << id.iSec2 << " Cell " << id.iCell1 << ":" << id.iCell2;
edm::LogVerbatim("HGCalGeom") << "NewCorners for Layer " << id.iLay << " Wafer " << id.iSec1 << ":" << id.iSec2
<< " Cell " << id.iCell1 << ":" << id.iCell2;
if (cellIndex < m_cellVec2.size() && m_det == DetId::HGCalHSc) {
GlobalPoint v = getPosition(detid);
int type = std::min(id.iType, 1);
Expand All @@ -407,7 +416,8 @@ HGCalGeometry::CornersVec HGCalGeometry::getNewCorners(const DetId& detid, bool
static const int signy[] = {1, 1, 0, -1, -1, 0};
#ifdef EDM_ML_DEBUG
if (debug)
edm::LogVerbatim("HGCalGeom") << "kfac " << k_fac1 << ":" << k_fac2 << " dx:dy:dz " << dx << ":" << dy << ":" << dz;
edm::LogVerbatim("HGCalGeom") << "kfac " << k_fac1 << ":" << k_fac2 << " dx:dy:dz " << dx << ":" << dy << ":"
<< dz;
#endif
if (m_topology.waferHexagon6()) {
xy = m_topology.dddConstants().locateCellHex(id.iCell1, id.iSec1, true);
Expand All @@ -416,14 +426,16 @@ HGCalGeometry::CornersVec HGCalGeometry::getNewCorners(const DetId& detid, bool
co[i] = m_cellVec[cellIndex].getPosition(lcoord);
}
} else {
xy = m_topology.dddConstants().locateCell(id.iLay, id.iSec1, id.iSec2, id.iCell1, id.iCell2, true, false, true, debug);
xy = m_topology.dddConstants().locateCell(
id.iLay, id.iSec1, id.iSec2, id.iCell1, id.iCell2, true, false, true, debug);
float zz = m_topology.dddConstants().waferZ(id.iLay, true);
for (unsigned int i = 0; i < ncorner; ++i) {
double xloc = xy.first + signx[i] * dx;
double yloc = xy.second + signy[i] * dy;
double xloc = xy.first + signx[i] * dx;
double yloc = xy.second + signy[i] * dy;
#ifdef EDM_ML_DEBUG
if (debug)
edm::LogVerbatim("HGCalGeom") << "Corner " << i << " x " << xy.first << ":" << xloc << " y " << xy.second << ":" << yloc << " z " << zz << ":" << id.zSide * (zz + dz);
if (debug)
edm::LogVerbatim("HGCalGeom") << "Corner " << i << " x " << xy.first << ":" << xloc << " y " << xy.second
<< ":" << yloc << " z " << zz << ":" << id.zSide * (zz + dz);
#endif
auto xyglob = m_topology.dddConstants().localToGlobal8(id.iLay, id.iSec1, id.iSec2, xloc, yloc, true, debug);
double xx = id.zSide * xyglob.first;
Expand Down
12 changes: 7 additions & 5 deletions Geometry/HGCalGeometry/test/FastTimeGeometryTester.cc
Expand Up @@ -31,9 +31,9 @@ class FastTimeGeometryTester : public edm::one::EDAnalyzer<> {
int type_;
};

FastTimeGeometryTester::FastTimeGeometryTester(const edm::ParameterSet& iC) :
name_(iC.getParameter<std::string>("Detector")),
geomToken_(esConsumes<FastTimeGeometry, IdealGeometryRecord>(edm::ESInputTag{"", name_})) {
FastTimeGeometryTester::FastTimeGeometryTester(const edm::ParameterSet& iC)
: name_(iC.getParameter<std::string>("Detector")),
geomToken_(esConsumes<FastTimeGeometry, IdealGeometryRecord>(edm::ESInputTag{"", name_})) {
type_ = (name_ == "FastTimeBarrel") ? 1 : 2;
}

Expand All @@ -60,8 +60,10 @@ void FastTimeGeometryTester::doTest(const FastTimeGeometry* geom, ForwardSubdete
auto icell1 = geom->getGeometry(id1);
GlobalPoint global1 = geom->getPosition(id1);
DetId idc1 = geom->getClosestCell(global1);
std::string cherr = (id1.rawId() != idc1.rawId()) ? " ***** ERROR *****" : "";
edm::LogVerbatim("FastTimeGeom") << "Input " << FastTimeDetId(id1) << " geometry " << icell1 << " position (" << global1.x() << ", " << global1.y() << ", " << global1.z() << " Output " << FastTimeDetId(idc1) << cherr;
std::string cherr = (id1.rawId() != idc1.rawId()) ? " ***** ERROR *****" : "";
edm::LogVerbatim("FastTimeGeom") << "Input " << FastTimeDetId(id1) << " geometry " << icell1 << " position ("
<< global1.x() << ", " << global1.y() << ", " << global1.z() << " Output "
<< FastTimeDetId(idc1) << cherr;
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions Geometry/HGCalGeometry/test/HGCalGeometryNewCornersTest.cc
Expand Up @@ -71,10 +71,10 @@ void HGCalGeometryNewCornersTest::beginRun(const edm::Run&, const edm::EventSetu
int layerOff = geom->topology().dddConstants().getLayerOffset();
edm::LogVerbatim("HGCalGeom") << nameDetector_ << " with layers in the range " << layerF << ":" << layerL
<< " Offset " << layerOff << " and for " << waferU_.size() << " wafers and cells";

for (unsigned int k = 0; k < waferU_.size(); ++k) {
for (auto lay : layers_) {
HGCSiliconDetId detId(det, 1, types_[k], lay - layerOff, waferU_[k], waferV_[k], 0 , 0);
HGCSiliconDetId detId(det, 1, types_[k], lay - layerOff, waferU_[k], waferV_[k], 0, 0);
GlobalPoint global = geom->getPosition(DetId(detId), debug_);
double phi2 = global.phi();
auto xy = geom->topology().dddConstants().waferPosition(lay - layerOff, waferU_[k], waferV_[k], debug_);
Expand All @@ -85,7 +85,7 @@ void HGCalGeometryNewCornersTest::beginRun(const edm::Run&, const edm::EventSetu
std::vector<GlobalPoint> corners = geom->getNewCorners(DetId(detId), debug_);
std::ostringstream st1;
for (auto const& it : corners)
st1 << it << ", ";
st1 << it << ", ";
edm::LogVerbatim("HGCalGeom") << "Corners: " << st1.str();
}
}
Expand Down

0 comments on commit 0acf376

Please sign in to comment.