diff --git a/Geometry/HGCalCommonData/interface/HGCalCell.h b/Geometry/HGCalCommonData/interface/HGCalCell.h new file mode 100644 index 0000000000000..6888d05979655 --- /dev/null +++ b/Geometry/HGCalCommonData/interface/HGCalCell.h @@ -0,0 +1,51 @@ +#ifndef Geometry_HGCalCommonData_HGCalCell_h +#define Geometry_HGCalCommonData_HGCalCell_h + +#include +#include + +class HGCalCell { +public: + HGCalCell(double waferSize, int32_t nFine, int32_t nCoarse); + + static constexpr int32_t waferOrient0 = 0; + static constexpr int32_t waferOrient1 = 1; + static constexpr int32_t waferOrient2 = 2; + static constexpr int32_t waferOrient3 = 3; + static constexpr int32_t waferOrient4 = 4; + static constexpr int32_t waferOrient5 = 5; + + static constexpr int32_t cellPlacementIndex0 = 0; + static constexpr int32_t cellPlacementIndex1 = 1; + static constexpr int32_t cellPlacementIndex2 = 2; + static constexpr int32_t cellPlacementIndex3 = 3; + static constexpr int32_t cellPlacementIndex4 = 4; + static constexpr int32_t cellPlacementIndex5 = 5; + static constexpr int32_t cellPlacementIndex6 = 6; + static constexpr int32_t cellPlacementIndex7 = 7; + static constexpr int32_t cellPlacementIndex8 = 8; + static constexpr int32_t cellPlacementIndex9 = 9; + static constexpr int32_t cellPlacementIndex10 = 10; + static constexpr int32_t cellPlacementIndex11 = 11; + + static constexpr int32_t cellPlacementExtra = 6; + static constexpr int32_t cellPlacementOld = 7; + static constexpr int32_t cellPlacementTotal = 12; + + static constexpr int32_t fullCell = 0; + static constexpr int32_t cornerCell = 1; + static constexpr int32_t truncatedCell = 2; + static constexpr int32_t extendedCell = 3; + + std::pair HGCalCellUV2XY1(int32_t u, int32_t v, int32_t placementIndex, int32_t type); + std::pair HGCalCellUV2XY2(int32_t u, int32_t v, int32_t placementIndex, int32_t type); + std::pair HGCalCellUV2Cell(int32_t u, int32_t v, int32_t placementIndex, int32_t type); + static int32_t HGCalCellPlacementIndex(int32_t iz, int32_t fwdBack, int32_t orient); + +private: + const double sqrt3By2_ = (0.5 * std::sqrt(3.0)); + int32_t ncell_[2]; + double cellX_[2], cellY_[2]; +}; + +#endif diff --git a/Geometry/HGCalCommonData/interface/HGCalGeometryMode.h b/Geometry/HGCalCommonData/interface/HGCalGeometryMode.h index 07fae409aa0de..01469070fe4c6 100644 --- a/Geometry/HGCalCommonData/interface/HGCalGeometryMode.h +++ b/Geometry/HGCalCommonData/interface/HGCalGeometryMode.h @@ -33,6 +33,7 @@ namespace HGCalGeometryMode { TrapezoidFile = 7, Hexagon8Module = 8, TrapezoidModule = 9, + Hexagon8ModuleOrient = 10, }; enum WaferMode { Polyhedra = 0, ExtrudedPolygon = 1 }; } // namespace HGCalGeometryMode diff --git a/Geometry/HGCalCommonData/src/HGCalCell.cc b/Geometry/HGCalCommonData/src/HGCalCell.cc new file mode 100644 index 0000000000000..60e82acbf0684 --- /dev/null +++ b/Geometry/HGCalCommonData/src/HGCalCell.cc @@ -0,0 +1,233 @@ +#include "Geometry/HGCalCommonData/interface/HGCalCell.h" +#include + +HGCalCell::HGCalCell(double waferSize, int32_t nFine, int32_t nCoarse) { + ncell_[0] = nFine; + ncell_[1] = nCoarse; + for (int k = 0; k < 2; ++k) { + cellX_[k] = waferSize / (3 * ncell_[k]); + cellY_[k] = sqrt3By2_ * cellX_[k]; + } +} + +std::pair HGCalCell::HGCalCellUV2XY1(int32_t u, int32_t v, int32_t placementIndex, int32_t type) { + if (type != 0) + type = 1; + double x(0), y(0); + switch (placementIndex) { + case (HGCalCell::cellPlacementIndex6): + x = (1.5 * (v - u) + 0.5) * cellX_[type]; + y = (v + u - 2 * ncell_[type] + 1) * cellY_[type]; + break; + case (HGCalCell::cellPlacementIndex7): + x = (1.5 * (v - ncell_[type]) + 1.0) * cellX_[type]; + y = (2 * u - v - ncell_[type]) * cellY_[type]; + break; + case (HGCalCell::cellPlacementIndex8): + x = (1.5 * (u - ncell_[type]) + 0.5) * cellX_[type]; + y = -(2 * v - u - ncell_[type] + 1) * cellY_[type]; + break; + case (HGCalCell::cellPlacementIndex9): + x = -(1.5 * (v - u) + 0.5) * cellX_[type]; + y = -(v + u - 2 * ncell_[type] + 1) * cellY_[type]; + break; + case (HGCalCell::cellPlacementIndex10): + x = -(1.5 * (v - ncell_[type]) + 1) * cellX_[type]; + y = -(2 * u - v - ncell_[type]) * cellY_[type]; + break; + case (HGCalCell::cellPlacementIndex11): + x = -(1.5 * (u - ncell_[type]) + 0.5) * cellX_[type]; + y = (2 * v - u - ncell_[type] + 1) * cellY_[type]; + break; + case (HGCalCell::cellPlacementIndex0): + x = (1.5 * (u - v) - 0.5) * cellX_[type]; + y = (v + u - 2 * ncell_[type] + 1) * cellY_[type]; + break; + case (HGCalCell::cellPlacementIndex1): + x = -(1.5 * (v - ncell_[type]) + 1.0) * cellX_[type]; + y = (2 * u - v - ncell_[type]) * cellY_[type]; + break; + case (HGCalCell::cellPlacementIndex2): + x = -(1.5 * (u - ncell_[type]) + 0.5) * cellX_[type]; + y = -(2 * v - u - ncell_[type] + 1) * cellY_[type]; + break; + case (HGCalCell::cellPlacementIndex3): + x = -(1.5 * (u - v) - 0.5) * cellX_[type]; + y = -(v + u - 2 * ncell_[type] + 1) * cellY_[type]; + break; + case (HGCalCell::cellPlacementIndex4): + x = (1.5 * (v - ncell_[type]) + 1) * cellX_[type]; + y = -(2 * u - v - ncell_[type]) * cellY_[type]; + break; + default: + x = (1.5 * (u - ncell_[type]) + 0.5) * cellX_[type]; + y = (2 * v - u - ncell_[type] + 1) * cellY_[type]; + break; + } + return std::make_pair(x, y); +} + +std::pair HGCalCell::HGCalCellUV2XY2(int32_t u, int32_t v, int32_t placementIndex, int32_t type) { + if (type != 0) + type = 1; + double x(0), y(0); + if (placementIndex < HGCalCell::cellPlacementExtra) { + double x0 = (1.5 * (u - v) - 0.5) * cellX_[type]; + double y0 = (u + v - 2 * ncell_[type] + 1) * cellY_[type]; + const std::vector fcos = {1.0, 0.5, -0.5, -1.0, -0.5, 0.5}; + const std::vector fsin = {0.0, sqrt3By2_, sqrt3By2_, 0.0, -sqrt3By2_, -sqrt3By2_}; + x = x0 * fcos[placementIndex] - y0 * fsin[placementIndex]; + y = x0 * fsin[placementIndex] + y0 * fcos[placementIndex]; + } else { + double x0 = (1.5 * (v - ncell_[type]) + 1.0) * cellX_[type]; + double y0 = (2 * u - v - ncell_[type]) * cellY_[type]; + const std::vector fcos = {0.5, 1.0, 0.5, -0.5, -1.0, -0.5}; + const std::vector fsin = {sqrt3By2_, 0.0, -sqrt3By2_, -sqrt3By2_, 0.0, sqrt3By2_}; + x = x0 * fcos[placementIndex - HGCalCell::cellPlacementExtra] - + y0 * fsin[placementIndex - HGCalCell::cellPlacementExtra]; + y = x0 * fsin[placementIndex - HGCalCell::cellPlacementExtra] + + y0 * fcos[placementIndex - HGCalCell::cellPlacementExtra]; + } + return std::make_pair(x, y); +} + +std::pair HGCalCell::HGCalCellUV2Cell(int32_t u, int32_t v, int32_t placementIndex, int32_t type) { + if (type != 0) + type = 1; + int cell(0), cellx(0), cellt(HGCalCell::fullCell); + if (placementIndex >= HGCalCell::cellPlacementExtra) { + const std::vector itype0 = {0, 7, 8, 9, 10, 11, 6, 3, 4, 5, 4, 5, 3}; + const std::vector itype1 = {0, 0, 1, 2, 3, 4, 5, 0, 1, 2, 0, 1, 2}; + const std::vector itype2 = {0, 11, 6, 7, 8, 9, 10, 5, 3, 4, 3, 4, 5}; + const std::vector itype3 = {0, 4, 5, 0, 1, 2, 3, 2, 0, 1, 2, 0, 1}; + const std::vector itype4 = {0, 9, 10, 11, 6, 7, 8, 4, 5, 3, 5, 3, 4}; + const std::vector itype5 = {0, 2, 3, 4, 5, 0, 1, 1, 2, 0, 1, 2, 0}; + if (u == 0 && v == 0) { + cellx = 1; + cellt = HGCalCell::cornerCell; + } else if (u == 0 && (v - u) == (ncell_[type] - 1)) { + cellx = 2; + cellt = HGCalCell::cornerCell; + } else if ((v - u) == (ncell_[type] - 1) && v == (2 * ncell_[type] - 1)) { + cellx = 3; + cellt = HGCalCell::cornerCell; + } else if (u == (2 * ncell_[type] - 1) && v == (2 * ncell_[type] - 1)) { + cellx = 4; + cellt = HGCalCell::cornerCell; + } else if (u == (2 * ncell_[type] - 1) && (u - v) == ncell_[type]) { + cellx = 5; + cellt = HGCalCell::cornerCell; + } else if ((u - v) == ncell_[type] && v == 0) { + cellx = 6; + cellt = HGCalCell::cornerCell; + } else if (u == 0) { + cellx = 7; + cellt = HGCalCell::truncatedCell; + } else if ((v - u) == (ncell_[type] - 1)) { + cellx = 10; + cellt = HGCalCell::extendedCell; + } else if (v == (2 * ncell_[type] - 1)) { + cellx = 8; + cellt = HGCalCell::truncatedCell; + } else if (u == (2 * ncell_[type] - 1)) { + cellx = 11; + cellt = HGCalCell::extendedCell; + } else if ((u - v) == ncell_[type]) { + cellx = 9; + cellt = HGCalCell::truncatedCell; + } else if (v == 0) { + cellx = 12; + cellt = HGCalCell::extendedCell; + } + switch (placementIndex) { + case (HGCalCell::cellPlacementIndex6): + cell = itype0[cellx]; + break; + case (HGCalCell::cellPlacementIndex7): + cell = itype1[cellx]; + break; + case (HGCalCell::cellPlacementIndex8): + cell = itype2[cellx]; + break; + case (HGCalCell::cellPlacementIndex9): + cell = itype3[cellx]; + break; + case (HGCalCell::cellPlacementIndex10): + cell = itype4[cellx]; + break; + default: + cell = itype5[cellx]; + break; + } + } else { + const std::vector itype0 = {0, 1, 2, 3, 4, 5, 0, 1, 2, 0, 0, 1, 2}; + const std::vector itype1 = {0, 8, 9, 10, 11, 6, 7, 4, 5, 3, 4, 5, 3}; + const std::vector itype2 = {0, 3, 4, 5, 0, 1, 2, 2, 0, 1, 1, 2, 0}; + const std::vector itype3 = {0, 10, 11, 6, 7, 8, 9, 5, 3, 4, 5, 3, 4}; + const std::vector itype4 = {0, 5, 0, 1, 2, 3, 4, 0, 1, 2, 2, 0, 1}; + const std::vector itype5 = {0, 6, 7, 8, 9, 10, 11, 3, 4, 5, 3, 4, 5}; + if (u == 0 && v == 0) { + cellx = 1; + cellt = HGCalCell::cornerCell; + } else if (v == 0 && (u - v) == (ncell_[type])) { + cellx = 2; + cellt = HGCalCell::cornerCell; + } else if ((u - v) == (ncell_[type]) && u == (2 * ncell_[type] - 1)) { + cellx = 3; + cellt = HGCalCell::cornerCell; + } else if (u == (2 * ncell_[type] - 1) && v == (2 * ncell_[type] - 1)) { + cellx = 4; + cellt = HGCalCell::cornerCell; + } else if (v == (2 * ncell_[type] - 1) && (v - u) == (ncell_[type] - 1)) { + cellx = 5; + cellt = HGCalCell::cornerCell; + } else if ((v - u) == (ncell_[type] - 1) && u == 0) { + cellx = 6; + cellt = HGCalCell::cornerCell; + } else if (v == 0) { + cellx = 10; + cellt = HGCalCell::extendedCell; + } else if ((u - v) == ncell_[type]) { + cellx = 7; + cellt = HGCalCell::truncatedCell; + } else if (u == (2 * ncell_[type] - 1)) { + cellx = 11; + cellt = HGCalCell::extendedCell; + } else if (v == (2 * ncell_[type] - 1)) { + cellx = 8; + cellt = HGCalCell::truncatedCell; + } else if ((v - u) == (ncell_[type] - 1)) { + cellx = 12; + cellt = HGCalCell::extendedCell; + } else if (u == 0) { + cellx = 9; + cellt = HGCalCell::truncatedCell; + } + switch (placementIndex) { + case (HGCalCell::cellPlacementIndex0): + cell = itype0[cellx]; + break; + case (HGCalCell::cellPlacementIndex1): + cell = itype1[cellx]; + break; + case (HGCalCell::cellPlacementIndex2): + cell = itype2[cellx]; + break; + case (HGCalCell::cellPlacementIndex3): + cell = itype3[cellx]; + break; + case (HGCalCell::cellPlacementIndex4): + cell = itype4[cellx]; + break; + default: + cell = itype5[cellx]; + break; + } + } + return std::make_pair(cell, cellt); +} + +int HGCalCell::HGCalCellPlacementIndex(int32_t iz, int32_t fwdBack, int32_t orient) { + int32_t indx = ((iz * fwdBack) > 0) ? orient : (orient + HGCalCell::cellPlacementExtra); + return indx; +} diff --git a/Geometry/HGCalCommonData/src/HGCalGeometryMode.cc b/Geometry/HGCalCommonData/src/HGCalGeometryMode.cc index 84af1dce96222..f9ef5a04642e3 100644 --- a/Geometry/HGCalCommonData/src/HGCalGeometryMode.cc +++ b/Geometry/HGCalCommonData/src/HGCalGeometryMode.cc @@ -12,6 +12,7 @@ HGCalStringToEnumParser::HGCalStringToEnumParse enumMap["HGCalGeometryMode::TrapezoidFile"] = HGCalGeometryMode::TrapezoidFile; enumMap["HGCalGeometryMode::Hexagon8Module"] = HGCalGeometryMode::Hexagon8Module; enumMap["HGCalGeometryMode::TrapezoidModule"] = HGCalGeometryMode::TrapezoidModule; + enumMap["HGCalGeometryMode::Hexagon8ModuleOrient"] = HGCalGeometryMode::Hexagon8ModuleOrient; } template <> diff --git a/Geometry/HGCalCommonData/test/HGCalCellPositionTester.cc b/Geometry/HGCalCommonData/test/HGCalCellPositionTester.cc new file mode 100644 index 0000000000000..2569bb5a57823 --- /dev/null +++ b/Geometry/HGCalCommonData/test/HGCalCellPositionTester.cc @@ -0,0 +1,107 @@ +// -*- C++ -*- +// +// Package: HGCalCellPositionTester +// Class: HGCalCellPositionTester +// +/**\class HGCalCellPositionTester HGCalCellPositionTester.cc + test/HGCalCellPositionTester.cc + + Description: + + Implementation: + +*/ +// +// Original Author: Sunanda Banerjee +// Created: Mon 2022/01/15 +// +// + +// system include files +#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/HGCalCell.h" + +class HGCalCellPositionTester : public edm::one::EDAnalyzer<> { +public: + explicit HGCalCellPositionTester(const edm::ParameterSet&); + ~HGCalCellPositionTester() override {} + 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_; +}; + +HGCalCellPositionTester::HGCalCellPositionTester(const edm::ParameterSet& iC) + : waferSize_(iC.getParameter("waferSize")), + waferType_(iC.getParameter("waferType")), + placeIndex_(iC.getParameter("cellPlacementIndex")) { + edm::LogVerbatim("HGCalGeom") << "Test positions for wafer of size " << waferSize_ << " Type " << waferType_ + << " Placement Index " << placeIndex_; +} + +void HGCalCellPositionTester::fillDescriptions(edm::ConfigurationDescriptions& descriptions) { + edm::ParameterSetDescription desc; + desc.add("waferSize", 166.4408); + desc.add("waferType", 0); + desc.add("cellPlacementIndex", 7); + descriptions.add("hgcalCellPositionTester", desc); +} + +// ------------ method called to produce the data ------------ +void HGCalCellPositionTester::analyze(const edm::Event&, const edm::EventSetup&) { + const int nFine(12), nCoarse(8); + const double tol(0.00001); + HGCalCell wafer(waferSize_, nFine, nCoarse); + int nCells = (waferType_ == 0) ? nFine : nCoarse; + int indexMin = (placeIndex_ >= 0) ? placeIndex_ : 0; + int indexMax = (placeIndex_ >= 0) ? placeIndex_ : 11; + edm::LogVerbatim("HGCalGeom") << "\nHGCalCellPositionTester:: nCells " << nCells << " and placement index between " + << indexMin << " and " << indexMax << "\n\n"; + for (int placeIndex = indexMin; placeIndex <= indexMax; ++placeIndex) { + for (int iu = 0; iu < 2 * nCells; ++iu) { + for (int iv = 0; iv < 2 * nCells; ++iv) { + int u(iu), v(iv); + if (placeIndex < HGCalCell::cellPlacementExtra) { + u = iv; + v = iu; + } + if (((v - u) < nCells) && ((u - v) <= nCells)) { + std::pair xy1 = wafer.HGCalCellUV2XY1(u, v, placeIndex, waferType_); + std::pair xy2 = wafer.HGCalCellUV2XY2(u, v, placeIndex, waferType_); + double dx = xy1.first - xy2.first; + double dy = xy1.second - xy2.second; + std::string comment = ((std::abs(dx) > tol) || (std::abs(dy) > tol)) ? " ***** ERROR *****" : ""; + edm::LogVerbatim("HGCalGeom") << "u = " << u << " v = " << v << " type = " << waferType_ + << " placement index " << placeIndex << " x " << xy1.first << ":" << xy2.first + << ":" << dx << " y " << xy1.second << ":" << xy2.second << ":" << dy + << comment; + } + } + } + } +} + +// define this as a plug-in +DEFINE_FWK_MODULE(HGCalCellPositionTester); diff --git a/Geometry/HGCalCommonData/test/python/testHGCalCellPositionTester_cfg.py b/Geometry/HGCalCommonData/test/python/testHGCalCellPositionTester_cfg.py new file mode 100644 index 0000000000000..e23a08825fd22 --- /dev/null +++ b/Geometry/HGCalCommonData/test/python/testHGCalCellPositionTester_cfg.py @@ -0,0 +1,37 @@ +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.load("Geometry.HGCalCommonData.hgcalCellPositionTester_cfi") + + +process.p1 = cms.Path(process.generator*process.hgcalCellPositionTester)