From 8af23401423a32eb3f1c3800cf2338c22275baf6 Mon Sep 17 00:00:00 2001 From: Sunanda Date: Sun, 21 Jun 2020 22:30:26 +0200 Subject: [PATCH] Add some new features for HGCal --- .../CaloTopology/interface/HGCalTopology.h | 1 + Geometry/CaloTopology/src/HGCalTopology.cc | 11 +++ .../interface/HGCalDDDConstants.h | 6 +- .../interface/HGCalGeomTools.h | 2 +- .../HGCalCommonData/interface/HGCalTypes.h | 2 + .../python/testHGCalV13XML_cfi.py | 9 +-- .../HGCalCommonData/src/HGCalDDDConstants.cc | 45 ++++++++++- .../HGCalCommonData/src/HGCalGeomTools.cc | 2 +- .../test/HGCalGeomLocatorTester.cc | 81 +++++++++++++++++++ .../test/python/testHGCalGeomLocator_cfg.py | 49 +++++++++++ .../Configuration/python/SimL1Emulator_cff.py | 5 +- 11 files changed, 200 insertions(+), 13 deletions(-) create mode 100644 Geometry/HGCalGeometry/test/HGCalGeomLocatorTester.cc create mode 100644 Geometry/HGCalGeometry/test/python/testHGCalGeomLocator_cfg.py diff --git a/Geometry/CaloTopology/interface/HGCalTopology.h b/Geometry/CaloTopology/interface/HGCalTopology.h index 6cda2a63c7a73..324aa123cdb96 100644 --- a/Geometry/CaloTopology/interface/HGCalTopology.h +++ b/Geometry/CaloTopology/interface/HGCalTopology.h @@ -85,6 +85,7 @@ class HGCalTopology : public CaloSubdetectorTopology { ///Is this a valid cell id bool valid(const DetId& id) const override; + bool valid(const DetId& id, int cornerMin) const; bool validHashIndex(uint32_t ix) const { return (ix < kSizeForDenseIndexing); } unsigned int totalModules() const { return kSizeForDenseIndexing; } diff --git a/Geometry/CaloTopology/src/HGCalTopology.cc b/Geometry/CaloTopology/src/HGCalTopology.cc index 16a92ac8c5c3b..e3dac2ecfcf56 100644 --- a/Geometry/CaloTopology/src/HGCalTopology.cc +++ b/Geometry/CaloTopology/src/HGCalTopology.cc @@ -477,6 +477,17 @@ bool HGCalTopology::valid(const DetId& idin) const { return flag; } +bool HGCalTopology::valid(const DetId& idin, int cornerMin) const { + if ((mode_ == HGCalGeometryMode::Hexagon8) || (mode_ == HGCalGeometryMode::Hexagon8Full)) { + HGCalTopology::DecodedDetId id = decode(idin); + bool mask = (cornerMin < HGCalTypes::WaferCornerMin) ? false : hdcons_.maskCell(idin, cornerMin); + bool flag = ((idin.det() == det_) && hdcons_.isValidHex8(id.iLay, id.iSec1, id.iSec2, id.iCell1, id.iCell2, true)); + return (flag && (!mask)); + } else { + return valid(idin); + } +} + DetId HGCalTopology::offsetBy(const DetId startId, int nrStepsX, int nrStepsY) const { if (startId.det() == DetId::Forward && startId.subdetId() == (int)(subdet_)) { DetId id = changeXY(startId, nrStepsX, nrStepsY); diff --git a/Geometry/HGCalCommonData/interface/HGCalDDDConstants.h b/Geometry/HGCalCommonData/interface/HGCalDDDConstants.h index a0d3ebb7e0529..49ed076fff3ae 100644 --- a/Geometry/HGCalCommonData/interface/HGCalDDDConstants.h +++ b/Geometry/HGCalCommonData/interface/HGCalDDDConstants.h @@ -14,7 +14,9 @@ #include #include #include "DataFormats/DetId/interface/DetId.h" +#include "DataFormats/ForwardDetId/interface/HGCSiliconDetId.h" #include "Geometry/HGCalCommonData/interface/HGCalGeometryMode.h" +#include "Geometry/HGCalCommonData/interface/HGCalGeomTools.h" #include "Geometry/HGCalCommonData/interface/HGCalParameters.h" #include "Geometry/HGCalCommonData/interface/HGCalTypes.h" @@ -66,7 +68,7 @@ class HGCalDDDConstants { int getUVMax(int type) const { return ((type == 0) ? hgpar_->nCellsFine_ : hgpar_->nCellsCoarse_); } bool isHalfCell(int waferType, int cell) const; bool isValidHex(int lay, int mod, int cell, bool reco) const; - bool isValidHex8(int lay, int modU, int modV, int cellU, int cellV) const; + bool isValidHex8(int lay, int modU, int modV, int cellU, int cellV, bool fullAndPart = false) const; bool isValidTrap(int lay, int ieta, int iphi) const; int lastLayer(bool reco) const; int layerIndex(int lay, bool reco) const; @@ -75,6 +77,7 @@ class HGCalDDDConstants { std::pair locateCell(int cell, int lay, int type, bool reco) const; std::pair locateCell( int lay, int waferU, int waferV, int cellU, int cellV, bool reco, bool all, bool debug = false) const; + std::pair locateCell(const HGCSiliconDetId&, bool debug = false) const; std::pair locateCellHex(int cell, int wafer, bool reco) const; std::pair locateCellTrap(int lay, int ieta, int iphi, bool reco) const; int levelTop(int ind = 0) const { return hgpar_->levelT_[ind]; } @@ -163,6 +166,7 @@ class HGCalDDDConstants { bool waferInLayerTest(int wafer, int lay, bool full) const; std::pair waferPosition(int waferU, int waferV, bool reco) const; + HGCalGeomTools geomTools_; const double k_horizontalShift = 1.0; const float dPhiMin = 0.02; typedef std::array, 2> Simrecovecs; diff --git a/Geometry/HGCalCommonData/interface/HGCalGeomTools.h b/Geometry/HGCalCommonData/interface/HGCalGeomTools.h index bfcd7329d31db..c42ffde8538c5 100644 --- a/Geometry/HGCalCommonData/interface/HGCalGeomTools.h +++ b/Geometry/HGCalCommonData/interface/HGCalGeomTools.h @@ -33,7 +33,7 @@ class HGCalGeomTools { std::vector const& slope); static double radius( double z, int layer0, int layerf, std::vector const& zFront, std::vector const& rFront); - std::pair shiftXY(int waferPosition, double waferSize); + std::pair shiftXY(int waferPosition, double waferSize) const; static double slope(double z, std::vector const& zFront, std::vector const& slope); static std::pair zradius(double z1, double z2, diff --git a/Geometry/HGCalCommonData/interface/HGCalTypes.h b/Geometry/HGCalCommonData/interface/HGCalTypes.h index 12bc717405bd8..4f235eb1fff5d 100644 --- a/Geometry/HGCalCommonData/interface/HGCalTypes.h +++ b/Geometry/HGCalCommonData/interface/HGCalTypes.h @@ -58,6 +58,8 @@ class HGCalTypes { WaferOut = 99 }; + static constexpr int32_t WaferCornerMin = 3; + enum TileType { TileFine = 0, TileCoarseCast = 1, TileCoarseMould = 2 }; enum TileSiPMType { SiPMUnknown = 0, SiPMSmall = 2, SiPMLarge = 4 }; diff --git a/Geometry/HGCalCommonData/python/testHGCalV13XML_cfi.py b/Geometry/HGCalCommonData/python/testHGCalV13XML_cfi.py index 72db9f5a3a6aa..43028ca8edd31 100644 --- a/Geometry/HGCalCommonData/python/testHGCalV13XML_cfi.py +++ b/Geometry/HGCalCommonData/python/testHGCalV13XML_cfi.py @@ -11,12 +11,12 @@ 'Geometry/CMSCommonData/data/cms/2026/v4/cms.xml', 'Geometry/CMSCommonData/data/eta3/etaMax.xml', 'Geometry/CMSCommonData/data/cmsMother.xml', - 'Geometry/CMSCommonData/data/caloBase/2026/v3/caloBase.xml', + 'Geometry/CMSCommonData/data/caloBase/2026/v4/caloBase.xml', 'Geometry/CMSCommonData/data/cmsCalo.xml', 'Geometry/CMSCommonData/data/beampipe/2026/v1/beampipe.xml', 'Geometry/CMSCommonData/data/cmsBeam/2026/v1/cmsBeam.xml', 'Geometry/CMSCommonData/data/cavernData/2017/v1/cavernData.xml', - 'Geometry/CMSCommonData/data/muonBase/2026/v4/muonBase.xml', + 'Geometry/CMSCommonData/data/muonBase/2026/v5/muonBase.xml', 'Geometry/CMSCommonData/data/cmsMuon.xml', 'Geometry/CMSCommonData/data/mgnt.xml', 'Geometry/CMSCommonData/data/muonMB.xml', @@ -31,14 +31,13 @@ 'Geometry/HcalCommonData/data/hcal/v2/hcalalgo.xml', 'Geometry/HcalCommonData/data/hcalbarrelalgo.xml', 'Geometry/HcalCommonData/data/hcalcablealgo/v2/hcalcablealgo.xml', - 'Geometry/HcalCommonData/data/hcalcablealgo/v2/hcalcablealgo.xml', 'Geometry/HcalCommonData/data/hcalouteralgo.xml', 'Geometry/HcalCommonData/data/hcalforwardalgo.xml', 'Geometry/HcalCommonData/data/hcalSimNumbering/NoHE/hcalSimNumbering.xml', 'Geometry/HcalCommonData/data/hcalRecNumbering/NoHE/hcalRecNumbering.xml', 'Geometry/HcalCommonData/data/average/hcalforwardmaterial.xml', 'Geometry/HGCalCommonData/data/hgcalMaterial/v1/hgcalMaterial.xml', - 'Geometry/HGCalCommonData/data/hgcal/v12/hgcal.xml', + 'Geometry/HGCalCommonData/data/hgcal/v13/hgcal.xml', 'Geometry/HGCalCommonData/data/hgcalEE/v12/hgcalEE.xml', 'Geometry/HGCalCommonData/data/hgcalcell/v9/hgcalcell.xml', 'Geometry/HGCalCommonData/data/hgcalwafer/v9/hgcalwafer.xml', @@ -56,7 +55,7 @@ 'Geometry/MuonCommonData/data/muonYoke/2021/v3/muonYoke.xml', 'Geometry/MuonCommonData/data/csc/2021/v2/csc.xml', 'Geometry/MuonCommonData/data/mfshield/2017/v2/mfshield.xml', - 'Geometry/MuonCommonData/data/mf/2026/v5/mf.xml', + 'Geometry/MuonCommonData/data/mf/2026/v6/mf.xml', 'Geometry/MuonCommonData/data/rpcf/2026/v3/rpcf.xml', 'Geometry/MuonCommonData/data/gemf/TDR_BaseLine/gemf.xml', 'Geometry/MuonCommonData/data/gem11/TDR_BaseLine/gem11.xml', diff --git a/Geometry/HGCalCommonData/src/HGCalDDDConstants.cc b/Geometry/HGCalCommonData/src/HGCalDDDConstants.cc index 756b65e457df0..5f718c936180f 100644 --- a/Geometry/HGCalCommonData/src/HGCalDDDConstants.cc +++ b/Geometry/HGCalCommonData/src/HGCalDDDConstants.cc @@ -491,7 +491,7 @@ bool HGCalDDDConstants::isValidHex(int lay, int mod, int cell, bool reco) const return result; } -bool HGCalDDDConstants::isValidHex8(int layer, int modU, int modV, int cellU, int cellV) const { +bool HGCalDDDConstants::isValidHex8(int layer, int modU, int modV, int cellU, int cellV, bool fullAndPart) const { // Check validity for a layer|wafer|cell of post-TDR version int indx = HGCalWaferIndex::waferIndex(layer, modU, modV); auto itr = hgpar_->typesInLayers_.find(indx); @@ -519,9 +519,18 @@ bool HGCalDDDConstants::isValidHex8(int layer, int modU, int modV, int cellU, in if (((cellV - cellU) >= N) || ((cellU - cellV) > N)) return false; - auto ktr = hgpar_->waferTypes_.find(indx); - if (ktr != hgpar_->waferTypes_.end()) - return false; + if (fullAndPart) { + auto ktr = hgpar_->waferTypes_.find(indx); + if (ktr != hgpar_->waferTypes_.end()) { + if (hgpar_->waferMaskMode_ > 0) { + if (ktr->second.first == HGCalTypes::WaferOut) + return false; + } else { + if (ktr->second.first < HGCalTypes::WaferCornerMin) + return false; + } + } + } // edm::LogVerbatim("HGCalGeom") << "Corners " << (ktr->second).first << ":" << waferVirtual(layer,modU,modV); int type = ((itr == hgpar_->typesInLayers_.end()) ? 2 : hgpar_->waferTypeL_[itr->second]); @@ -640,6 +649,34 @@ std::pair HGCalDDDConstants::locateCell( return std::make_pair(x, y); } +std::pair HGCalDDDConstants::locateCell(const HGCSiliconDetId& id, bool debug) const { + int lay(id.layer()); + double r = 0.5 * (hgpar_->waferSize_ + hgpar_->sensorSeparation_); + double R = 2.0 * r / sqrt3_; + int ncells = (id.type() == 0) ? hgpar_->nCellsFine_ : hgpar_->nCellsCoarse_; + int n2 = ncells / 2; + auto xyoff = geomTools_.shiftXY(hgpar_->layerCenter_[lay - 1], (2.0 * r)); + double xpos = xyoff.first + ((-2 * id.waferU() + id.waferV()) * r); + double ypos = xyoff.second + (1.5 * id.waferV() * R); +#ifdef EDM_ML_DEBUG + if (debug) + edm::LogVerbatim("HGCalGeom") << "LocateCell " << id << " Lay " << lay << " r:R " << r << ":" << R << " N " + << ncells << ":" << n2 << " Off " << xyoff.first << ":" << xyoff.second << " Pos " + << xpos << ":" << ypos; +#endif + double R1 = hgpar_->waferSize_ / (3.0 * ncells); + double r1 = 0.5 * R1 * sqrt3_; + xpos += ((1.5 * (id.cellV() - ncells) + 1.0) * R1); + ypos += ((id.cellU() - 0.5 * id.cellV() - n2) * 2 * r1); +#ifdef EDM_ML_DEBUG + if (debug) + edm::LogVerbatim("HGCalGeom") << "LocateCell r1:R1 " << r1 << ":" << R1 << " dx:dy " + << ((1.5 * (id.cellV() - ncells) + 1.0) * R1) << ":" + << ((id.cellU() - 0.5 * id.cellV() - n2) * 2 * r1) << " Pos " << xpos << ":" << ypos; +#endif + return std::make_pair(xpos * id.zside(), ypos); +} + std::pair HGCalDDDConstants::locateCellHex(int cell, int wafer, bool reco) const { float x(0), y(0); if (hgpar_->waferTypeT_[wafer] - 1 == HGCSiliconDetId::HGCalFine) { diff --git a/Geometry/HGCalCommonData/src/HGCalGeomTools.cc b/Geometry/HGCalCommonData/src/HGCalGeomTools.cc index 9aa3f5c03fc0a..327f9ed64b4b8 100644 --- a/Geometry/HGCalCommonData/src/HGCalGeomTools.cc +++ b/Geometry/HGCalCommonData/src/HGCalGeomTools.cc @@ -163,7 +163,7 @@ double HGCalGeomTools::radius( return r; } -std::pair HGCalGeomTools::shiftXY(int waferPosition, double waferSize) { +std::pair HGCalGeomTools::shiftXY(int waferPosition, double waferSize) const { double dx(0), dy(0); switch (waferPosition) { case (HGCalTypes::CornerCenterYp): { diff --git a/Geometry/HGCalGeometry/test/HGCalGeomLocatorTester.cc b/Geometry/HGCalGeometry/test/HGCalGeomLocatorTester.cc new file mode 100644 index 0000000000000..0ebc38d9d26ba --- /dev/null +++ b/Geometry/HGCalGeometry/test/HGCalGeomLocatorTester.cc @@ -0,0 +1,81 @@ +#include +#include +#include + +#include "FWCore/ParameterSet/interface/ParameterSet.h" +#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 "Geometry/Records/interface/IdealGeometryRecord.h" +#include "Geometry/HGCalCommonData/interface/HGCalGeometryMode.h" +#include "Geometry/HGCalGeometry/interface/HGCalGeometry.h" +#include "DataFormats/ForwardDetId/interface/HGCSiliconDetId.h" +#include "CoralBase/Exception.h" + +class HGCalGeomLocaterTester : public edm::one::EDAnalyzer<> { +public: + explicit HGCalGeomLocaterTester(const edm::ParameterSet&); + + void analyze(edm::Event const& iEvent, edm::EventSetup const&) override; + +private: + void doTest(const HGCalGeometry* geom, DetId::Detector det); + + std::string name_; + edm::ESGetToken geomToken_; +}; + +HGCalGeomLocaterTester::HGCalGeomLocaterTester(const edm::ParameterSet& iC) + : name_{iC.getParameter("Detector")}, + geomToken_{esConsumes(edm::ESInputTag{"", name_})} {} + +void HGCalGeomLocaterTester::analyze(const edm::Event&, const edm::EventSetup& iSetup) { + const auto& geomR = iSetup.getData(geomToken_); + const HGCalGeometry* geom = &geomR; + HGCalGeometryMode::GeometryMode mode = geom->topology().dddConstants().geomMode(); + if ((mode == HGCalGeometryMode::Hexagon8) || (mode == HGCalGeometryMode::Hexagon8Full)) { + DetId::Detector det; + if (name_ == "HGCalHESiliconSensitive") + det = DetId::HGCalHSi; + else + det = DetId::HGCalEE; + std::cout << "Perform test for " << name_ << " Detector " << det << " Mode " << mode << std::endl; + doTest(geom, det); + } +} + +void HGCalGeomLocaterTester::doTest(const HGCalGeometry* geom, DetId::Detector det) { + const std::vector& ids = geom->getValidDetIds(); + std::cout << "doTestWafer:: " << ids.size() << " valid ids for " << geom->cellElement() << std::endl; + const double tol = 0.001; + const unsigned int step = 10; + int all(0), good(0), bad(0); + for (unsigned int k = 0; k < ids.size(); k += step) { + ++all; + HGCSiliconDetId id(ids[k]); + std::cout << "ID[" << k << "] " << id; + GlobalPoint global = geom->getPosition(id); + auto waferxy = geom->topology().dddConstants().locateCell(id, false); + double dx = global.x() - waferxy.first; + double dy = global.y() - waferxy.second; + std::cout << " position (" << global.x() << ", " << global.y() << ", " << global.z() << ") waferXY (" + << waferxy.first << ", " << waferxy.second << ") Delta (" << dx << ", " << dy << ")"; + if ((std::abs(dx) > tol) || (std::abs(dy) > tol)) { + std::cout << "***** ERROR *****" << std::endl; + ++bad; + geom->topology().dddConstants().locateCell(id, true); + } else { + std::cout << std::endl; + ++good; + } + } + std::cout << "\n\nStudied " << all << " (" << ids.size() << ") IDs of which " << good << " are good and " << bad + << " are bad\n\n\n\n"; +} + +//define this as a plug-in +DEFINE_FWK_MODULE(HGCalGeomLocaterTester); diff --git a/Geometry/HGCalGeometry/test/python/testHGCalGeomLocator_cfg.py b/Geometry/HGCalGeometry/test/python/testHGCalGeomLocator_cfg.py new file mode 100644 index 0000000000000..218d5a972cc90 --- /dev/null +++ b/Geometry/HGCalGeometry/test/python/testHGCalGeomLocator_cfg.py @@ -0,0 +1,49 @@ +import FWCore.ParameterSet.Config as cms + +process = cms.Process("PROD") +process.load("SimGeneral.HepPDTESSource.pdt_cfi") + +process.load("Configuration.Geometry.GeometryExtended2026D41Reco_cff") +#process.load("Geometry.HGCalCommonData.testHGCV12XML_cfi") +#process.load("Geometry.HGCalCommonData.hgcalParametersInitialization_cfi") +#process.load("Geometry.HGCalCommonData.hgcalNumberingInitialization_cfi") +#process.load("Geometry.CaloEventSetup.HGCalV9Topology_cfi") +#process.load("Geometry.HGCalGeometry.HGCalGeometryESProducer_cfi") +process.load('FWCore.MessageService.MessageLogger_cfi') + +if hasattr(process,'MessageLogger'): + process.MessageLogger.categories.append('HGCalGeom') + +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.prodEE = cms.EDAnalyzer("HGCalGeomLocaterTester", + Detector = cms.string("HGCalEESensitive"), + ) + +process.prodHEF = process.prodEE.clone( + Detector = "HGCalHESiliconSensitive", +) + +process.p1 = cms.Path(process.generator*process.prodEE*process.prodHEF) diff --git a/L1Trigger/Configuration/python/SimL1Emulator_cff.py b/L1Trigger/Configuration/python/SimL1Emulator_cff.py index 19b37622c0e6e..069e46d20b8a5 100644 --- a/L1Trigger/Configuration/python/SimL1Emulator_cff.py +++ b/L1Trigger/Configuration/python/SimL1Emulator_cff.py @@ -64,4 +64,7 @@ _phase2_siml1emulator.add(hgcalTriggerPrimitivesTask) from Configuration.Eras.Modifier_phase2_hgcal_cff import phase2_hgcal -phase2_hgcal.toReplaceWith( SimL1EmulatorTask , _phase2_siml1emulator ) +#phase2_hgcal.toReplaceWith( SimL1EmulatorTask , _phase2_siml1emulator ) + +from Configuration.Eras.Modifier_phase2_hgcalV11_cff import phase2_hgcalV11 +(phase2_hgcal & ~phase2_hgcalV11).toReplaceWith( SimL1EmulatorTask, _phase2_siml1emulator )