diff --git a/Geometry/HGCalCommonData/src/HGCalCellUV.cc b/Geometry/HGCalCommonData/src/HGCalCellUV.cc index 40177dce9b887..1c400a09bb0ff 100644 --- a/Geometry/HGCalCommonData/src/HGCalCellUV.cc +++ b/Geometry/HGCalCommonData/src/HGCalCellUV.cc @@ -15,7 +15,7 @@ HGCalCellUV::HGCalCellUV(double waferSize, double separation, int32_t nFine, int cellX_[k] = waferSize / (3 * ncell_[k]); cellY_[k] = 0.5 * sqrt3_ * cellX_[k]; cellXTotal_[k] = (waferSize + separation) / (3 * ncell_[k]); - cellY_[k] = 0.5 * sqrt3_ * cellXTotal_[k]; + cellYTotal_[k] = 0.5 * sqrt3_ * cellXTotal_[k]; } // Fill up the placement vectors @@ -45,8 +45,11 @@ HGCalCellUV::HGCalCellUV(double waferSize, double separation, int32_t nFine, int std::pair HGCalCellUV::cellUVFromXY1( double xloc, double yloc, int32_t placement, int32_t type, bool extend, bool debug) const { + if (type != 0) + type = 1; //--- Reverse transform to placement=0, if placement index ≠ 6 double xloc1 = (placement >= HGCalCell::cellPlacementExtra) ? xloc : -xloc; + double cellY = (extend) ? cellYTotal_[type] : cellY_[type]; int rot = placement % HGCalCell::cellPlacementExtra; static constexpr std::array fcos = {{1.0, cos60_, -cos60_, -1.0, -cos60_, cos60_}}; static constexpr std::array fsin = {{0.0, sin60_, sin60_, 0.0, -sin60_, -sin60_}}; @@ -59,9 +62,9 @@ std::pair HGCalCellUV::cellUVFromXY1( double w = y; //--- Rounding in u, v, w coordinates - int iu = std::floor(u / cellY_[type]) + 3 * (ncell_[type]) - 1; - int iv = std::floor(v / cellY_[type]) + 3 * (ncell_[type]); - int iw = std::floor(w / cellY_[type]) + 1; + int iu = std::floor(u / cellY) + 3 * (ncell_[type]) - 1; + int iv = std::floor(v / cellY) + 3 * (ncell_[type]); + int iw = std::floor(w / cellY) + 1; int isv = (iu + iw) / 3; int isu = (iv + iw) / 3; @@ -87,6 +90,9 @@ std::pair HGCalCellUV::cellUVFromXY2( double xloc, double yloc, int32_t placement, int32_t type, bool extend, bool debug) const { //--- Using multiple inequalities to find (u, v) //--- Reverse transform to placement=0, if placement index ≠ 7 + if (type != 0) + type = 1; + double cellY = (extend) ? cellYTotal_[type] : cellY_[type]; double xloc1 = (placement >= HGCalCell::cellPlacementExtra) ? xloc : -1 * xloc; int rot = placement % HGCalCell::cellPlacementExtra; static constexpr std::array fcos = {{cos60_, 1.0, cos60_, -cos60_, -1.0, -cos60_}}; @@ -95,8 +101,8 @@ std::pair HGCalCellUV::cellUVFromXY2( double y = xloc1 * fsin[rot] + yloc * fcos[rot]; int32_t u(-100), v(-100); - int ncell = (type != 0) ? ncell_[1] : ncell_[0]; - double r = (type != 0) ? cellY_[1] : cellY_[0]; + int ncell = ncell_[type]; + double r = cellY; double l1 = (y / r) + ncell - 1.0; int l2 = std::floor((0.5 * y + 0.5 * x / sqrt3_) / r + ncell - 4.0 / 3.0); int l3 = std::floor((x / sqrt3_) / r + ncell - 4.0 / 3.0); @@ -154,17 +160,21 @@ std::pair HGCalCellUV::cellUVFromXY3( double xloc, double yloc, int32_t placement, int32_t type, bool extend, bool debug) const { //--- Using Cube coordinates to find the (u, v) //--- Reverse transform to placement=0, if placement index ≠ 6 + if (type != 0) + type = 1; + double cellX = (extend) ? cellXTotal_[type] : cellX_[type]; + double cellY = (extend) ? cellYTotal_[type] : cellY_[type]; double xloc1 = (placement >= HGCalCell::cellPlacementExtra) ? xloc : -xloc; int rot = placement % HGCalCell::cellPlacementExtra; static constexpr std::array fcos = {{1.0, cos60_, -cos60_, -1.0, -cos60_, cos60_}}; static constexpr std::array fsin = {{0.0, sin60_, sin60_, 0.0, -sin60_, -sin60_}}; double xprime = xloc1 * fcos[rot] - yloc * fsin[rot]; double yprime = xloc1 * fsin[rot] + yloc * fcos[rot]; - double x = xprime + cellX_[type]; + double x = xprime + cellX; double y = yprime; - x = x / cellX_[type]; - y = y / cellY_[type]; + x = x / cellX; + y = y / cellY; double cu = 2 * x / 3; double cv = -x / 3 + y / 2; @@ -187,7 +197,7 @@ std::pair HGCalCellUV::cellUVFromXY3( //--- Taking care of extending cells int u(ncell_[type] + iv), v(ncell_[type] - 1 - iw); double xcell = (1.5 * (v - u) + 0.5) * cellX_[type]; - double ycell = (v + u - 2 * ncell_[type] + 1) * cellY_[type]; + double ycell = (v + u - 2 * ncell_[type] + 1) * cellY; if (v == -1) { if ((yprime - sqrt3_ * xprime) < (ycell - sqrt3_ * xcell)) { v += 1; @@ -270,6 +280,10 @@ std::pair HGCalCellUV::cellUVFromXY4(double xloc, std::pair HGCalCellUV::cellUVFromXY1( double xloc, double yloc, int32_t placement, int32_t type, int32_t partial, bool extend, bool debug) const { + if (type != 0) + type = 1; + double cellX = (extend) ? cellXTotal_[type] : cellX_[type]; + double cellY = (extend) ? cellYTotal_[type] : cellY_[type]; std::pair uv = HGCalCellUV::cellUVFromXY1(xloc, yloc, placement, type, extend, debug); int u = uv.first; int v = uv.second; @@ -281,8 +295,8 @@ std::pair HGCalCellUV::cellUVFromXY1( static constexpr std::array fsin = {{0.0, sin60_, sin60_, 0.0, -sin60_, -sin60_}}; double xprime = -1 * (xloc1 * fcos[rot] - yloc * fsin[rot]); double yprime = xloc1 * fsin[rot] + yloc * fcos[rot]; - double xcell = -1 * (1.5 * (v - u) + 0.5) * cellX_[type]; - double ycell = (v + u - 2 * ncell_[type] + 1) * cellY_[type]; + double xcell = -1 * (1.5 * (v - u) + 0.5) * cellX; + double ycell = (v + u - 2 * ncell_[type] + 1) * cellY; if ((yprime - sqrt3_ * xprime) > (ycell - sqrt3_ * xcell)) { u += -1; } else { @@ -299,8 +313,8 @@ std::pair HGCalCellUV::cellUVFromXY1( static constexpr std::array fsin = {{0.0, sin60_, sin60_, 0.0, -sin60_, -sin60_}}; double xprime = -1 * (xloc1 * fcos[rot] - yloc * fsin[rot]); double yprime = xloc1 * fsin[rot] + yloc * fcos[rot]; - double xcell = -1 * (1.5 * (v - u) + 0.5) * cellX_[type]; - double ycell = (v + u - 2 * ncell_[type] + 1) * cellY_[type]; + double xcell = -1 * (1.5 * (v - u) + 0.5) * cellX; + double ycell = (v + u - 2 * ncell_[type] + 1) * cellY; if ((yprime - sqrt3_ * xprime) > (ycell - sqrt3_ * xcell)) { u += 1; v += 1; diff --git a/Geometry/HGCalCommonData/src/HGCalDDDConstants.cc b/Geometry/HGCalCommonData/src/HGCalDDDConstants.cc index 800be12cfc8bc..ea013aec2eaad 100644 --- a/Geometry/HGCalCommonData/src/HGCalDDDConstants.cc +++ b/Geometry/HGCalCommonData/src/HGCalDDDConstants.cc @@ -239,6 +239,17 @@ bool HGCalDDDConstants::cellInLayer(int waferU, int waferV, int cellU, int cellV auto ktr = hgpar_->waferInfoMap_.find(indx); int part = (ktr != hgpar_->waferInfoMap_.end()) ? (ktr->second).part : HGCalTypes::WaferFull; return HGCalWaferMask::goodCell(cellU, cellV, part); + } else if (mode_ == HGCalGeometryMode::Hexagon8Module) { + int indx = HGCalWaferIndex::waferIndex(lay, waferU, waferV); + auto ktr = hgpar_->waferInfoMap_.find(indx); + int thck(HGCalTypes::WaferFineThin), part(HGCalTypes::WaferFull), rotn(HGCalTypes::WaferOrient0); + if (ktr != hgpar_->waferInfoMap_.end()) { + thck = (ktr->second).type; + part = (ktr->second).part; + rotn = (ktr->second).orient; + } + 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)); @@ -699,7 +710,7 @@ std::pair HGCalDDDConstants::locateCell( if (mode_ == HGCalGeometryMode::Hexagon8Cassette) { ktr = hgpar_->waferInfoMap_.find(indx); if (ktr != hgpar_->waferInfoMap_.end()) - place = HGCalCell::cellPlacementIndex(1, HGCalTypes::layerType(layertype), (ktr->second).orient); + place = HGCalCell::cellPlacementIndex(1, HGCalTypes::layerFrontBack(layertype), (ktr->second).orient); } auto xy = hgcell_->cellUV2XY2(cellU, cellV, place, type); x = xy.first; @@ -842,11 +853,16 @@ bool HGCalDDDConstants::maskCell(const DetId& detId, int corners) const { } int wl = HGCalWaferIndex::waferIndex(layer, waferU, waferV); auto itr = hgpar_->waferTypes_.find(wl); + auto ktr = hgpar_->waferInfoMap_.find(wl); #ifdef EDM_ML_DEBUG edm::LogVerbatim("HGCalGeom") << "MaskCell: Layer " << layer << " Wafer " << waferU << ":" << waferV << " Index " - << wl << ":" << (itr != hgpar_->waferTypes_.end()); + << wl << ":" << (itr != hgpar_->waferTypes_.end()) << ":" + << (ktr != hgpar_->waferInfoMap_.end()); #endif - if (itr != hgpar_->waferTypes_.end()) { + if (mode_ == HGCalGeometryMode::Hexagon8Cassette) { + int part = (ktr != hgpar_->waferInfoMap_.end()) ? (ktr->second).part : HGCalTypes::WaferFull; + mask = !(HGCalWaferMask::goodCell(u, v, part)); + } else if (itr != hgpar_->waferTypes_.end()) { if ((itr->second).second <= HGCalTypes::k_OffsetRotation) mask = HGCalWaferMask::maskCell(u, v, N, (itr->second).first, (itr->second).second, corners); else @@ -1305,8 +1321,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()) { - place = HGCalCell::cellPlacementIndex(1, HGCalTypes::layerType(layertype), (ktr->second).orient); + place = HGCalCell::cellPlacementIndex(1, HGCalTypes::layerFrontBack(layertype), (ktr->second).orient); part = (ktr->second).part; + if (debug) + edm::LogVerbatim("HGCalGeom") << "waferfFromPosition: frontback " << layertype << ":" + << HGCalTypes::layerFrontBack(layertype) << " Orient " << (ktr->second).orient + << " place " << place << " part " << part; } } cellHex(xx, yy, celltype, place, part, cellU, cellV, extend, debug); @@ -1592,8 +1612,8 @@ void HGCalDDDConstants::cellHex( double xloc, double yloc, int cellType, int place, int part, int& cellU, int& cellV, bool extend, bool debug) const { if (mode_ == HGCalGeometryMode::Hexagon8Cassette) { auto uv = (part == HGCalTypes::WaferFull) - ? hgcellUV_->cellUVFromXY3(xloc, yloc, place, cellType, extend, debug) - : hgcellUV_->cellUVFromXY1(xloc, yloc, place, cellType, part, extend, debug); + ? hgcellUV_->cellUVFromXY3(xloc, yloc, place, cellType, true, debug) + : hgcellUV_->cellUVFromXY1(xloc, yloc, place, cellType, part, true, debug); cellU = uv.first; cellV = uv.second; } else if (waferHexagon8File()) { diff --git a/Geometry/HGCalCommonData/test/HGCalCellUVTester.cc b/Geometry/HGCalCommonData/test/HGCalCellUVTester.cc index f216dbbb2e462..3c6e134ed5484 100644 --- a/Geometry/HGCalCommonData/test/HGCalCellUVTester.cc +++ b/Geometry/HGCalCommonData/test/HGCalCellUVTester.cc @@ -1,10 +1,10 @@ // -*- C++ -*- // -// Package: HGCalCellPositionTester -// Class: HGCalCellPositionTester +// Package: HGCalCellUVTester +// Class: HGCalCellUVTester // -/**\class HGCalCellPositionTester HGCalCellPositionTester.cc - test/HGCalCellPositionTester.cc +/**\class HGCalCellUVTester HGCalCellUVTester.cc + test/HGCalCellUVTester.cc Description: @@ -25,7 +25,6 @@ #include #include #include -//#include // user include files #include "FWCore/Framework/interface/Frameworkfwd.h" @@ -94,10 +93,10 @@ void HGCalCellUVTester::analyze(const edm::Event&, const edm::EventSetup&) { double c2 = yi - (xi / sqrt(3)); if ((xi < r2) && (xi > -1 * r2) && (c1 < R2) && (c1 > -1 * R2) && (c2 < R2) && (c2 > -1 * R2)) { //Only allowing (x, y) inside a wafer - std::pair uv1 = wafer.cellUVFromXY1(xi, yi, placeIndex_, waferType_, 0, 0); - std::pair uv2 = wafer.cellUVFromXY2(xi, yi, placeIndex_, waferType_, 0, 0); - std::pair uv3 = wafer.cellUVFromXY3(xi, yi, placeIndex_, waferType_, 1, 0); - //std::pair uv2 = wafer.HGCalCellUVFromXY2(xi, yi, placeIndex_, waferType_, 1, 0); + std::pair uv1 = wafer.cellUVFromXY1(xi, yi, placeIndex_, waferType_, true, false); + std::pair uv2 = wafer.cellUVFromXY2(xi, yi, placeIndex_, waferType_, true, false); + std::pair uv3 = wafer.cellUVFromXY3(xi, yi, placeIndex_, waferType_, true, false); + //std::pair uv2 = wafer.HGCalCellUVFromXY2(xi, yi, placeIndex_, waferType_, true, false); std::string comment = ((uv1.first != uv3.first) || (uv2.first != uv3.first) || (uv1.second != uv3.second) || (uv2.second != uv3.second)) ? " ***** ERROR *****" diff --git a/Geometry/HGCalCommonData/test/HGCalPartialCellTester.cc b/Geometry/HGCalCommonData/test/HGCalPartialCellTester.cc new file mode 100644 index 0000000000000..829d877b5e782 --- /dev/null +++ b/Geometry/HGCalCommonData/test/HGCalPartialCellTester.cc @@ -0,0 +1,146 @@ +// -*- C++ -*- +// +// Package: HGCalCellPartialCellTester +// Class: HGCalCellPartialCellTester +// +/**\class HGCalCellPartialCellTester HGCalCellPartialCellTester.cc + test/HGCalCellPartialCellTester.cc + + Description: + + Implementation: + +*/ +// +// Original Author: Sunanda Banerjee, Pruthvi Suryadevara +// Created: Mon 2022/06/10 +// +// + +// system include files +#include +#include +#include +#include +#include +#include +#include +//#include + +// user include files +#include "FWCore/Framework/interface/Frameworkfwd.h" +#include "FWCore/Framework/interface/one/EDAnalyzer.h" + +#include "FWCore/Framework/interface/Event.h" +#include "FWCore/Framework/interface/EventSetup.h" +#include "FWCore/Framework/interface/MakerMacros.h" + +#include "FWCore/MessageLogger/interface/MessageLogger.h" +#include "FWCore/ParameterSet/interface/ParameterSet.h" +#include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h" +#include "Geometry/HGCalCommonData/interface/HGCalCellUV.h" +#include "Geometry/HGCalCommonData/interface/HGCalCell.h" +#include "Geometry/HGCalCommonData/interface/HGCalWaferMask.h" + +class HGCalPartialCellTester : public edm::one::EDAnalyzer<> { +public: + explicit HGCalPartialCellTester(const edm::ParameterSet&); + ~HGCalPartialCellTester() override = default; + static void fillDescriptions(edm::ConfigurationDescriptions& descriptions); + + void beginJob() override {} + void analyze(edm::Event const& iEvent, edm::EventSetup const&) override; + void endJob() override {} + +private: + const double waferSize_; + const int waferType_; + const int placeIndex_; + const int partialType_; + const int nTrials_; + const int modeUV_; +}; + +HGCalPartialCellTester::HGCalPartialCellTester(const edm::ParameterSet& iC) + : waferSize_(iC.getParameter("waferSize")), + waferType_(iC.getParameter("waferType")), + placeIndex_(iC.getParameter("cellPlacementIndex")), + partialType_(iC.getParameter("partialType")), + nTrials_(iC.getParameter("numbberOfTrials")), + modeUV_(iC.getParameter("modeUV")) { + edm::LogVerbatim("HGCalGeom") << "Test positions for wafer of size " << waferSize_ << " Type " << waferType_ + << " Placement Index " << placeIndex_ << " mode " << modeUV_ << " with " << nTrials_ + << " trials"; +} + +void HGCalPartialCellTester::fillDescriptions(edm::ConfigurationDescriptions& descriptions) { + edm::ParameterSetDescription desc; + desc.add("waferSize", 166.4408); + desc.add("waferType", 1); + desc.add("cellPlacementIndex", 2); + desc.add("partialType", 11); + desc.add("numbberOfTrials", 1000); + desc.add("modeUV", 0); + descriptions.add("hgcalPartialCellTester", desc); +} + +// ------------ method called to produce the data ------------ +void HGCalPartialCellTester::analyze(const edm::Event&, const edm::EventSetup&) { + const int nFine(12), nCoarse(8); + double r2 = 0.5 * waferSize_; + double R2 = 2 * r2 / sqrt(3); + int nCells = (waferType_ == 0) ? nFine : nCoarse; + HGCalCellUV wafer(waferSize_, 0.0, nFine, nCoarse); + HGCalCell wafer2(waferSize_, nFine, nCoarse); + edm::LogVerbatim("HGCalGeom") << "\nHGCalPartialCellTester:: nCells " << nCells << " and placement index " + << placeIndex_ << "\n\n"; + auto start_t = std::chrono::high_resolution_clock::now(); + + if (modeUV_ <= 0) { + for (int i = 0; i < nTrials_; i++) { + double xi = (2 * r2 * static_cast(rand()) / RAND_MAX) - r2; + double yi = (2 * R2 * static_cast(rand()) / RAND_MAX) - R2; + double c1 = yi + xi / sqrt(3); + double c2 = yi - (xi / sqrt(3)); + if ((xi < r2) && (xi > -1 * r2) && (c1 < R2) && (c1 > -1 * R2) && (c2 < R2) && (c2 > -1 * R2) && + (xi > 0)) { //Only allowing (x, y) inside a partial wafer 11, placement index 2 + std::pair uv1 = wafer.cellUVFromXY1(xi, yi, placeIndex_, waferType_, true, false); + std::pair uv5 = + wafer.cellUVFromXY1(xi, yi, placeIndex_, waferType_, partialType_, true, false); + std::string cellType = (HGCalWaferMask::goodCell(uv5.first, uv5.second, 11)) ? "Goodcell" : "Badcell"; + std::string comment = ((uv1.first != uv5.first) || (uv1.second != uv5.second)) ? " ***** ERROR *****" : ""; + edm::LogVerbatim("HGCalGeom") << cellType << " x = " << xi << " y = " << yi << " type = " << waferType_ + << " placement index " << placeIndex_ << " u " << uv1.first << ":" << uv5.first + << ":" << uv5.first << " v " << uv1.second << ":" << uv5.second << ":" + << uv5.second << ":" << comment; + } + } + } else { + for (int i = 0; i < nTrials_; i++) { + int ui = std::floor(2 * nCells * rand() / RAND_MAX); + int vi = std::floor(2 * nCells * rand() / RAND_MAX); + if ((ui < 2 * nCells) && (vi < 2 * nCells) && ((vi - ui) < nCells) && ((ui - vi) <= nCells) && + HGCalWaferMask::goodCell(ui, vi, partialType_)) { + //Only allowing (U, V) inside a wafer + std::pair xy1 = wafer2.cellUV2XY2(ui, vi, placeIndex_, waferType_); + std::pair uv1 = + wafer.cellUVFromXY1(xy1.first, xy1.second, placeIndex_, waferType_, true, false); + std::pair uv5 = + wafer.cellUVFromXY1(xy1.first, xy1.second, placeIndex_, waferType_, partialType_, true, false); + std::string comment = ((uv1.first != ui) || (uv1.second != vi) || (uv5.first != ui) || (uv5.second != vi)) + ? " ***** ERROR *****" + : ""; + edm::LogVerbatim("HGCalGeom") << "u = " << ui << " v = " << vi << " type = " << waferType_ + << " placement index " << placeIndex_ << " x " << xy1.first << " ,y " + << xy1.second << " u " << uv5.first << " v " << uv5.second << comment; + } + } + } + auto end_t = std::chrono::high_resolution_clock::now(); + auto diff_t = end_t - start_t; + edm::LogVerbatim("HGCalGeom") << "Execution time for " << nTrials_ + << " events = " << std::chrono::duration(diff_t).count() << " ms"; +} + +// define this as a plug-in +DEFINE_FWK_MODULE(HGCalPartialCellTester); diff --git a/Geometry/HGCalCommonData/test/HGCalPartialWaferTester.cc b/Geometry/HGCalCommonData/test/HGCalPartialWaferTester.cc new file mode 100644 index 0000000000000..f2cf74dab6235 --- /dev/null +++ b/Geometry/HGCalCommonData/test/HGCalPartialWaferTester.cc @@ -0,0 +1,119 @@ +// system include files +#include +#include +#include +#include + +// user include files +#include "FWCore/Framework/interface/Frameworkfwd.h" +#include "FWCore/Framework/interface/one/EDAnalyzer.h" + +#include "FWCore/Framework/interface/Event.h" +#include "FWCore/Framework/interface/EventSetup.h" +#include "FWCore/Framework/interface/MakerMacros.h" + +#include "FWCore/MessageLogger/interface/MessageLogger.h" +#include "FWCore/ParameterSet/interface/ParameterSet.h" +#include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h" +#include "Geometry/HGCalCommonData/interface/HGCalDDDConstants.h" +#include "Geometry/HGCalCommonData/interface/HGCalParameters.h" +#include "Geometry/HGCalCommonData/interface/HGCalWaferIndex.h" +#include "Geometry/HGCalCommonData/interface/HGCalWaferMask.h" +#include "Geometry/Records/interface/IdealGeometryRecord.h" + +class HGCalPartialWaferTester : public edm::one::EDAnalyzer<> { +public: + explicit HGCalPartialWaferTester(const edm::ParameterSet&); + ~HGCalPartialWaferTester() override = default; + static void fillDescriptions(edm::ConfigurationDescriptions& descriptions); + + void beginJob() override {} + void analyze(edm::Event const& iEvent, edm::EventSetup const&) override; + void endJob() override {} + +private: + const std::string nameSense_; + const int orientation_, partialType_, nTrials_; + const edm::ESGetToken dddToken_; +}; + +HGCalPartialWaferTester::HGCalPartialWaferTester(const edm::ParameterSet& iC) + : nameSense_(iC.getParameter("NameSense")), + orientation_(iC.getParameter("waferOrientation")), + partialType_(iC.getParameter("partialType")), + nTrials_(iC.getParameter("numberOfTrials")), + dddToken_(esConsumes(edm::ESInputTag{"", nameSense_})) { + edm::LogVerbatim("HGCalGeom") << "Test positions for partial wafer type " << partialType_ << " Orientation " + << orientation_ << " for " << nameSense_; +} + +void HGCalPartialWaferTester::fillDescriptions(edm::ConfigurationDescriptions& descriptions) { + edm::ParameterSetDescription desc; + desc.add("NameSense", "HGCalHESiliconSensitive"); + desc.add("waferOrientation", 0); + desc.add("partialType", 11); + desc.add("numberOfTrials", 1000); + descriptions.add("hgcalPartialWaferTester", desc); +} + +void HGCalPartialWaferTester::analyze(const edm::Event&, const edm::EventSetup& iSetup) { + const HGCalDDDConstants& hgdc = iSetup.getData(dddToken_); + int indx(-1), type(-1); + for (auto itr = hgdc.getParameter()->waferInfoMap_.begin(); itr != hgdc.getParameter()->waferInfoMap_.end(); ++itr) { + if (((itr->second).part == partialType_) && ((itr->second).orient == orientation_)) { + indx = itr->first; + type = (itr->second).type; + break; + } + } + + if (indx > 0) { + int all(0), error(0); + int layer = HGCalWaferIndex::waferLayer(indx); + int waferU = HGCalWaferIndex::waferU(indx); + int waferV = HGCalWaferIndex::waferV(indx); + auto xy = hgdc.waferPosition(layer, waferU, waferV, true, false); + edm::LogVerbatim("HGCalGeom") << "Wafer " << waferU << ":" << waferV << " in layer " << layer << " at " << xy.first + << ":" << xy.second << "\n\n"; + int nCells = (type == 0) ? HGCSiliconDetId::HGCalFineN : HGCSiliconDetId::HGCalCoarseN; + for (int i = 0; i < nTrials_; i++) { + int ui = std::floor(2 * nCells * rand() / RAND_MAX); + int vi = std::floor(2 * nCells * rand() / RAND_MAX); + if ((ui < 2 * nCells) && (vi < 2 * nCells) && ((vi - ui) < nCells) && ((ui - vi) <= nCells) && + HGCalWaferMask::goodCell(ui, vi, partialType_)) { + ++all; + auto xy = hgdc.locateCell(layer, waferU, waferV, ui, vi, true, true, false, false); + int lay(layer), cU(0), cV(0), wType(-1), wU(0), wV(0); + double wt(0); + hgdc.waferFromPosition(HGCalParameters::k_ScaleToDDD * xy.first, + HGCalParameters::k_ScaleToDDD * xy.second, + lay, + wU, + wV, + cU, + cV, + wType, + wt, + false, + true); + std::string comment = + ((wType == type) && (layer == lay) && (waferU == wU) && (waferV == wV) && (ui == cU) && (vi == cV)) + ? "" + : " ***** ERROR *****"; + edm::LogVerbatim("HGCalGeom") << "Layer " << layer << ":" << lay << " waferU " << waferU << ":" << wU + << " waferV " << waferV << ":" << wV << " Type " << type << ":" << wType + << " cellU " << ui << ":" << cU << " cellV " << vi << ":" << cV << " position " + << xy.first << ":" << xy.second << comment; + if (comment != "") + ++error; + } + } + edm::LogVerbatim("HGCalGeom") << "\n\nFound " << error << " errors among " << all << ":" << nTrials_ << " trials"; + } else { + edm::LogVerbatim("HGCalGeom") << "\n\nCannot find a wafer of type " << partialType_ << " and orientation " + << orientation_ << " for " << nameSense_; + } +} + +// define this as a plug-in +DEFINE_FWK_MODULE(HGCalPartialWaferTester); diff --git a/Geometry/HGCalCommonData/test/python/testHGCalPartialCellTester_cfg.py b/Geometry/HGCalCommonData/test/python/testHGCalPartialCellTester_cfg.py new file mode 100644 index 0000000000000..e12bab92519f2 --- /dev/null +++ b/Geometry/HGCalCommonData/test/python/testHGCalPartialCellTester_cfg.py @@ -0,0 +1,42 @@ +import FWCore.ParameterSet.Config as cms + +process = cms.Process("PROD") +process.load("SimGeneral.HepPDTESSource.pdt_cfi") +process.load('FWCore.MessageService.MessageLogger_cfi') + +if hasattr(process,'MessageLogger'): + process.MessageLogger.HGCalGeom=dict() + +process.load("IOMC.RandomEngine.IOMC_cff") +process.RandomNumberGeneratorService.generator.initialSeed = 456789 + +process.source = cms.Source("EmptySource") + +process.generator = cms.EDProducer("FlatRandomEGunProducer", + PGunParameters = cms.PSet( + PartID = cms.vint32(14), + MinEta = cms.double(-3.5), + MaxEta = cms.double(3.5), + MinPhi = cms.double(-3.14159265359), + MaxPhi = cms.double(3.14159265359), + MinE = cms.double(9.99), + MaxE = cms.double(10.01) + ), + AddAntiParticle = cms.bool(False), + Verbosity = cms.untracked.int32(0), + firstRun = cms.untracked.uint32(1) + ) + +process.maxEvents = cms.untracked.PSet( + input = cms.untracked.int32(1) +) + +process.SimpleMemoryCheck = cms.Service("SimpleMemoryCheck", + ignoreTotal = cms.untracked.int32(1), + moduleMemorySummary = cms.untracked.bool(True) +) + +process.load("Geometry.HGCalCommonData.hgcalPartialCellTester_cfi") + + +process.p1 = cms.Path(process.generator*process.hgcalPartialCellTester) diff --git a/Geometry/HGCalCommonData/test/python/testHGCalPartialWaferTester_cfg.py b/Geometry/HGCalCommonData/test/python/testHGCalPartialWaferTester_cfg.py new file mode 100644 index 0000000000000..58d6270a0bb8b --- /dev/null +++ b/Geometry/HGCalCommonData/test/python/testHGCalPartialWaferTester_cfg.py @@ -0,0 +1,38 @@ +import FWCore.ParameterSet.Config as cms + +process = cms.Process("PROD") +process.load("SimGeneral.HepPDTESSource.pdt_cfi") +process.load("Configuration.Geometry.GeometryExtended2026D92_cff") +process.load('FWCore.MessageService.MessageLogger_cfi') + +if hasattr(process,'MessageLogger'): + process.MessageLogger.HGCalGeom=dict() + +process.load("IOMC.RandomEngine.IOMC_cff") +process.RandomNumberGeneratorService.generator.initialSeed = 456789 + +process.source = cms.Source("EmptySource") + +process.generator = cms.EDProducer("FlatRandomEGunProducer", + PGunParameters = cms.PSet( + PartID = cms.vint32(14), + MinEta = cms.double(-3.5), + MaxEta = cms.double(3.5), + MinPhi = cms.double(-3.14159265359), + MaxPhi = cms.double(3.14159265359), + MinE = cms.double(9.99), + MaxE = cms.double(10.01) + ), + AddAntiParticle = cms.bool(False), + Verbosity = cms.untracked.int32(0), + firstRun = cms.untracked.uint32(1) + ) + +process.maxEvents = cms.untracked.PSet( + input = cms.untracked.int32(1) +) + +process.load("Geometry.HGCalCommonData.hgcalPartialWaferTester_cfi") + + +process.p1 = cms.Path(process.generator*process.hgcalPartialWaferTester) diff --git a/Geometry/HGCalCommonData/test/python/testHGCalValidHex_cfg.py b/Geometry/HGCalCommonData/test/python/testHGCalValidHex_cfg.py index 89b4ce9b90232..7a904d2483703 100644 --- a/Geometry/HGCalCommonData/test/python/testHGCalValidHex_cfg.py +++ b/Geometry/HGCalCommonData/test/python/testHGCalValidHex_cfg.py @@ -5,7 +5,9 @@ #process.load("Geometry.CMSCommonData.cmsExtendedGeometry2026D49XML_cfi") #process.load("Geometry.CMSCommonData.cmsExtendedGeometry2026D68XML_cfi") #process.load("Geometry.CMSCommonData.cmsExtendedGeometry2026D70XML_cfi") -process.load("Geometry.HGCalCommonData.testHGCalV14XML_cfi") +#process.load("Geometry.CMSCommonData.cmsExtendedGeometry2026D88XML_cfi") +process.load("Geometry.CMSCommonData.cmsExtendedGeometry2026D92XML_cfi") +#process.load("Geometry.HGCalCommonData.testHGCalV14XML_cfi") process.load("Geometry.HGCalCommonData.hgcalParametersInitialization_cfi") process.load("Geometry.HGCalCommonData.hgcalNumberingInitialization_cfi") process.load("Geometry.EcalCommonData.ecalSimulationParameters_cff")