From 6ce276c73e6fa8209d3d6b0466892d709effdafd Mon Sep 17 00:00:00 2001 From: Sunanda Date: Mon, 14 Oct 2024 11:34:32 +0200 Subject: [PATCH 1/2] Update the topology class and tetester in view of all modifiedrun conditions --- .../CaloTopology/interface/HcalTopology.h | 9 +- Geometry/CaloTopology/src/HcalTopology.cc | 114 ++++++++++++------ .../CaloTopology/test/HcalTopologyTester.cc | 5 +- 3 files changed, 84 insertions(+), 44 deletions(-) diff --git a/Geometry/CaloTopology/interface/HcalTopology.h b/Geometry/CaloTopology/interface/HcalTopology.h index a8e691328a7a5..2e0106757a8e6 100644 --- a/Geometry/CaloTopology/interface/HcalTopology.h +++ b/Geometry/CaloTopology/interface/HcalTopology.h @@ -44,6 +44,7 @@ class HcalTopology : public CaloSubdetectorTopology { DetId denseId2detId(unsigned int /*denseid*/) const override; /// return a count of valid cells (for dense indexing use) unsigned int ncells() const override; + unsigned int ncells(int subdet) const; /// return a version which identifies the given topology int topoVersion() const override; @@ -167,8 +168,10 @@ class HcalTopology : public CaloSubdetectorTopology { HcalDetId idBack(const HcalDetId& id) const { return hcons_->idBack(id); } private: - bool phase1() const { return ((mode_ == HcalTopologyMode::LHC) || (mode_ == HcalTopologyMode::Run3)); } - bool phase2() const { return ((mode_ == HcalTopologyMode::SLHC) || (mode_ == HcalTopologyMode::Run4)); } + bool phase1() const { return ((mode_ == HcalTopologyMode::LHC) || (mode_ == HcalTopologyMode::H2HE)); } + bool phase1A() const { return ((mode_ == HcalTopologyMode::LHC) || (mode_ == HcalTopologyMode::Run2A) || (mode_ == HcalTopologyMode::H2) || (mode_ == HcalTopologyMode::H2HE)); } + bool phase1B() const { return ((mode_ == HcalTopologyMode::Run2B) || (mode_ == HcalTopologyMode::Run2C) || (mode_ == HcalTopologyMode::Run3) || (mode_ == HcalTopologyMode::SLHC)); } + bool phase2() const { return ((mode_ == HcalTopologyMode::Run4)); } /** Get the neighbors of the given cell with higher absolute ieta */ int incAIEta(const HcalDetId& id, HcalDetId neighbors[2]) const; /** Get the neighbors of the given cell with lower absolute ieta */ @@ -176,7 +179,7 @@ class HcalTopology : public CaloSubdetectorTopology { /** Is this a valid cell id, ignoring the exclusion list */ bool validDetIdPreLS1(const HcalDetId& id) const; - bool validRaw(const HcalDetId& id) const; + bool validRaw(const HcalDetId& id, const bool debug=false) const; unsigned int detId2denseIdPreLS1(const DetId& id) const; bool isExcluded(const HcalDetId& id) const; diff --git a/Geometry/CaloTopology/src/HcalTopology.cc b/Geometry/CaloTopology/src/HcalTopology.cc index d3534ca11687f..74d94df112ec1 100644 --- a/Geometry/CaloTopology/src/HcalTopology.cc +++ b/Geometry/CaloTopology/src/HcalTopology.cc @@ -64,7 +64,7 @@ HcalTopology::HcalTopology(const HcalDDDRecConstants* hcons, const bool mergePos } else { nEtaHE_ = (lastHERing_ - firstHERing_ + 1); } - if (mode_ == HcalTopologyMode::LHC) { + if (phase1()) { topoVersion_ = 0; //DL HBSize_ = kHBSizePreLS1; // qie-per-fiber * fiber/rm * rm/rbx * rbx/barrel * barrel/hcal HESize_ = kHESizePreLS1; // qie-per-fiber * fiber/rm * rm/rbx * rbx/endcap * endcap/hcal @@ -155,6 +155,11 @@ HcalTopology::HcalTopology(const HcalDDDRecConstants* hcons, const bool mergePos << " " << maxDepthHB_ << ":" << maxDepthHE_ << " " << nEtaHB_ << ":" << nEtaHE_ << " " << etaHE2HF_ << ":" << etaHF2HE_ << " " << maxPhiHE_; #endif + + // Now redfine some of the sizes +#ifdef EDM_ML_DEBUG + edm::LogVerbatim("HCalGeom") << "Redefined sizes could be for HB:" << ncells(HcalBarrel) << " HE:" << ncells(HcalEndcap) << " HF: " << ncells(HcalForward); +#endif } bool HcalTopology::valid(const DetId& id) const { @@ -164,7 +169,7 @@ bool HcalTopology::valid(const DetId& id) const { bool HcalTopology::validHcal(const HcalDetId& id) const { // check the raw rules - return validRaw(id) && !isExcluded(id); + return validRaw(id, false) && !isExcluded(id); } bool HcalTopology::validDetId(HcalSubdetector subdet, int ieta, int iphi, int depth) const { @@ -435,7 +440,7 @@ int HcalTopology::exclude(HcalSubdetector subdet, int ieta1, int ieta2, int iphi for (int iphi = iphi_l; iphi <= iphi_h; iphi++) for (int depth = depth_l; depth <= depth_h; depth++) { HcalDetId id(subdet, ieta, iphi, depth); - if (validRaw(id)) { // use 'validRaw' to include check validity in "uncut" detector + if (validRaw(id, false)) { // use 'validRaw' to include check validity in "uncut" detector exclude(id); n++; } @@ -488,7 +493,12 @@ bool HcalTopology::validDetIdPreLS1(const HcalDetId& id) const { } /** Is this a valid cell id? */ -bool HcalTopology::validRaw(const HcalDetId& id) const { +bool HcalTopology::validRaw(const HcalDetId& id, +#ifdef EDM_ML_DEBUG + const bool debug) const { +#else + const bool) const { +#endif bool ok = true; int ieta = id.ieta(); int aieta = id.ietaAbs(); @@ -502,16 +512,23 @@ bool HcalTopology::validRaw(const HcalDetId& id) const { if (ok) { if (subdet == HcalBarrel) { - if (phase2() || (mode_ == HcalTopologyMode::H2HE)) { - if ((aieta > lastHBRing()) || (depth > hcons_->getMaxDepth(0, aieta, iphi, zside)) || - (depth < hcons_->getMinDepth(0, aieta, iphi, zside))) + if (phase1()) { + if (aieta > lastHBRing() || depth > 2 || (aieta <= 14 && depth > 1)) ok = false; } else { - if (aieta > lastHBRing() || depth > 2 || (aieta <= 14 && depth > 1)) + if ((aieta > lastHBRing()) || (depth > hcons_->getMaxDepth(0, aieta, iphi, zside)) || + (depth < hcons_->getMinDepth(0, aieta, iphi, zside))) ok = false; } } else if (subdet == HcalEndcap) { - if (phase2() || (mode_ == HcalTopologyMode::H2HE)) { + if (phase1A()) { + if (depth > hcons_->getMaxDepth(1, aieta, iphi, zside) || aieta < firstHERing() || aieta > lastHERing() || + (aieta == firstHERing() && depth != hcons_->getDepthEta16(2, iphi, zside)) || + (aieta == 17 && depth != 1 && mode_ != HcalTopologyMode::H2) || // special case at H2 + (((aieta >= 17 && aieta < firstHETripleDepthRing()) || aieta == lastHERing()) && depth > 2) || + (aieta >= firstHEDoublePhiRing() && (iphi % 2) == 0)) + ok = false; + } else { if ((depth > hcons_->getMaxDepth(1, aieta, iphi, zside)) || (depth < hcons_->getMinDepth(1, aieta, iphi, zside)) || (aieta < firstHERing()) || (aieta > lastHERing())) { ok = false; @@ -533,13 +550,6 @@ bool HcalTopology::validRaw(const HcalDetId& id) const { } } } - } else { - if (depth > hcons_->getMaxDepth(1, aieta, iphi, zside) || aieta < firstHERing() || aieta > lastHERing() || - (aieta == firstHERing() && depth != hcons_->getDepthEta16(2, iphi, zside)) || - (aieta == 17 && depth != 1 && mode_ != HcalTopologyMode::H2) || // special case at H2 - (((aieta >= 17 && aieta < firstHETripleDepthRing()) || aieta == lastHERing()) && depth > 2) || - (aieta >= firstHEDoublePhiRing() && (iphi % 2) == 0)) - ok = false; } } else if (subdet == HcalOuter) { if (aieta > lastHORing() || iphi > IPHI_MAX || depth != 4) @@ -556,6 +566,10 @@ bool HcalTopology::validRaw(const HcalDetId& id) const { ok = false; } } +#ifdef EDM_ML_DEBUG + if (debug) + edm::LogVerbatim("HCalGeom") << "HcalValdRaw ID: " << subdet << ":" << aieta << ":" << depth << ":" << iphi << ":" << zside << " Mode " << mode_ << ":" << phase1() << ":" << phase1A() << ":" << phase1B() << ":" << phase2() << " Limits HB " << lastHBRing() << " HE " << firstHERing() << ":" << lastHERing() << ":" << firstHEDoublePhiRing() << ":" << firstHEQuadPhiRing() << " Depth " << hcons_->getMaxDepth(0, aieta, iphi, zside) << ":" << hcons_->getMinDepth(0, aieta, iphi, zside) << ":" << hcons_->getDepthEta16(2, iphi, zside) << " OK " << ok; +#endif return ok; } @@ -752,14 +766,7 @@ int HcalTopology::decAIEta(const HcalDetId& id, HcalDetId neighbors[2]) const { void HcalTopology::depthBinInformation( HcalSubdetector subdet, int etaRing, int iphi, int zside, int& nDepthBins, int& startingBin) const { if (subdet == HcalBarrel) { - if (phase2() || (mode_ == HcalTopologyMode::H2HE)) { - startingBin = hcons_->getMinDepth(0, etaRing, iphi, zside); - if (etaRing == lastHBRing()) { - nDepthBins = hcons_->getDepthEta16(1, iphi, zside) - startingBin + 1; - } else { - nDepthBins = hcons_->getMaxDepth(0, etaRing, iphi, zside) - startingBin + 1; - } - } else { + if (phase1() || (mode_ == HcalTopologyMode::H2)) { if (etaRing <= 14) { nDepthBins = 1; startingBin = 1; @@ -767,16 +774,16 @@ void HcalTopology::depthBinInformation( nDepthBins = 2; startingBin = 1; } - } - } else if (subdet == HcalEndcap) { - if (phase2() || (mode_ == HcalTopologyMode::H2HE)) { - if (etaRing == firstHERing()) { - startingBin = hcons_->getDepthEta16(2, iphi, zside); + } else { + startingBin = hcons_->getMinDepth(0, etaRing, iphi, zside); + if (etaRing == lastHBRing()) { + nDepthBins = hcons_->getDepthEta16(1, iphi, zside) - startingBin + 1; } else { - startingBin = hcons_->getMinDepth(1, etaRing, iphi, zside); + nDepthBins = hcons_->getMaxDepth(0, etaRing, iphi, zside) - startingBin + 1; } - nDepthBins = hcons_->getMaxDepth(1, etaRing, iphi, zside) - startingBin + 1; - } else { + } + } else if (subdet == HcalEndcap) { + if (phase1A()) { if (etaRing == firstHERing()) { nDepthBins = 1; startingBin = 3; @@ -790,6 +797,13 @@ void HcalTopology::depthBinInformation( nDepthBins = (etaRing >= firstHETripleDepthRing()) ? 3 : 2; startingBin = 1; } + } else { + if (etaRing == firstHERing()) { + startingBin = hcons_->getDepthEta16(2, iphi, zside); + } else { + startingBin = hcons_->getMinDepth(1, etaRing, iphi, zside); + } + nDepthBins = hcons_->getMaxDepth(1, etaRing, iphi, zside) - startingBin + 1; } } else if (subdet == HcalForward) { nDepthBins = maxDepthHF_; @@ -822,15 +836,20 @@ bool HcalTopology::incrementDepth(HcalDetId& detId) const { depth = 4; } else if (subdet == HcalBarrel && etaRing == lastHBRing()) { // overlap - subdet = HcalEndcap; - if (phase2() || (mode_ == HcalTopologyMode::H2HE)) - depth = hcons_->getDepthEta16(2, iphi, zside); - } else if ((subdet == HcalEndcap) && (etaRing == lastHERing() - 1) && !phase2()) { + if (phase2()) { // No more chance + detId = HcalDetId(); + return false; + } else { + subdet = HcalEndcap; + if (phase1B()) + depth = hcons_->getDepthEta16(2, iphi, zside); + } + } else if ((subdet == HcalEndcap) && (etaRing == lastHERing() - 1) && !phase1B()) { // guard ring HF29 is behind HE 28 subdet = HcalForward; (ieta > 0) ? ++ieta : --ieta; depth = 1; - } else if ((subdet == HcalEndcap) && (etaRing == lastHERing()) && !phase2()) { + } else if ((subdet == HcalEndcap) && (etaRing == lastHERing()) && !phase1B()) { // split cells go to bigger granularity. Ring 29 -> 28 (ieta > 0) ? --ieta : ++ieta; } else { @@ -864,7 +883,7 @@ bool HcalTopology::decrementDepth(HcalDetId& detId) const { } } } else if ((subdet == HcalEndcap) && (etaRing == lastHERing()) && (depth == hcons_->getDepthEta29(iphi, zside, 0)) && - !phase2()) { + !phase1B()) { (ieta > 0) ? --ieta : ++ieta; } else if (depth <= 0) { if (subdet == HcalForward && etaRing == firstHFRing()) { @@ -1057,17 +1076,18 @@ double HcalTopology::etaMax(HcalSubdetector subdet) const { } return eta; } + std::pair HcalTopology::etaRange(HcalSubdetector subdet, int keta) const { int ieta = (keta > 0) ? keta : -keta; if (subdet == HcalForward) { if (ieta >= firstHFRing_) { - unsigned int ii = (unsigned int)(ieta - firstHFRing_); + unsigned int ii = static_cast(ieta - firstHFRing_); if (ii + 1 < etaTableHF.size()) return std::pair(etaTableHF[ii], etaTableHF[ii + 1]); } } else { int ietal = (phase1() && ieta == lastHERing_ - 1) ? (ieta + 1) : ieta; - if ((ietal < (int)(etaTable.size())) && (ieta > 0)) + if ((ietal < static_cast(etaTable.size())) && (ieta > 0)) return std::pair(etaTable[ieta - 1], etaTable[ietal]); } return std::pair(0, 0); @@ -1625,4 +1645,18 @@ DetId HcalTopology::denseId2detId(unsigned int denseid) const { unsigned int HcalTopology::ncells() const { return HBSize_ + HESize_ + HOSize_ + HFSize_; } +unsigned int HcalTopology::ncells(int subdet) const { + unsigned int ncell(0); + for (int eta = -maxEta_; eta <= maxEta_; eta++) { + for (unsigned int phi = 1; phi <= maxPhi_; phi++) { + for (int depth = 1; depth <= 7; depth++) { + HcalDetId cell((HcalSubdetector)subdet, eta, phi, depth); + if (validRaw(cell, true)) + ++ncell; + } + } + } + return ncell; +} + int HcalTopology::topoVersion() const { return topoVersion_; } diff --git a/Geometry/CaloTopology/test/HcalTopologyTester.cc b/Geometry/CaloTopology/test/HcalTopologyTester.cc index faba57b67f72f..5a2cd82550004 100644 --- a/Geometry/CaloTopology/test/HcalTopologyTester.cc +++ b/Geometry/CaloTopology/test/HcalTopologyTester.cc @@ -52,7 +52,10 @@ void HcalTopologyTester::doTest(const HcalTopology& topology) { << " HE: " << topology.getHESize() << " HF: " << topology.getHFSize() << " HO: " << topology.getHOSize() << " HT: " << topology.getHTSize() << " Calib: " << topology.getCALIBSize() << " Overall: " << topology.ncells(); - + std::vector dets = {"HB", "HE", "HO", "HF"}; + for (int det = 1; det <= 4; ++det) + edm::LogVerbatim("HCalGeom") << "Valid cells for " << dets[det-1] << " = " << topology.ncells(det); + // First test on movements along eta/phi directions edm::LogVerbatim("HCalGeom") << "\nTest on movements along eta/phi directions" << "\n=========================================="; From 1283dba7f9e8203c39f227f868e1eb89a18cc84f Mon Sep 17 00:00:00 2001 From: Sunanda Date: Mon, 14 Oct 2024 11:41:54 +0200 Subject: [PATCH 2/2] Code check --- .../CaloTopology/interface/HcalTopology.h | 12 +++++-- Geometry/CaloTopology/src/HcalTopology.cc | 31 ++++++++++++------- .../CaloTopology/test/HcalTopologyTester.cc | 4 +-- 3 files changed, 30 insertions(+), 17 deletions(-) diff --git a/Geometry/CaloTopology/interface/HcalTopology.h b/Geometry/CaloTopology/interface/HcalTopology.h index 2e0106757a8e6..c181300bf35f8 100644 --- a/Geometry/CaloTopology/interface/HcalTopology.h +++ b/Geometry/CaloTopology/interface/HcalTopology.h @@ -169,8 +169,14 @@ class HcalTopology : public CaloSubdetectorTopology { private: bool phase1() const { return ((mode_ == HcalTopologyMode::LHC) || (mode_ == HcalTopologyMode::H2HE)); } - bool phase1A() const { return ((mode_ == HcalTopologyMode::LHC) || (mode_ == HcalTopologyMode::Run2A) || (mode_ == HcalTopologyMode::H2) || (mode_ == HcalTopologyMode::H2HE)); } - bool phase1B() const { return ((mode_ == HcalTopologyMode::Run2B) || (mode_ == HcalTopologyMode::Run2C) || (mode_ == HcalTopologyMode::Run3) || (mode_ == HcalTopologyMode::SLHC)); } + bool phase1A() const { + return ((mode_ == HcalTopologyMode::LHC) || (mode_ == HcalTopologyMode::Run2A) || (mode_ == HcalTopologyMode::H2) || + (mode_ == HcalTopologyMode::H2HE)); + } + bool phase1B() const { + return ((mode_ == HcalTopologyMode::Run2B) || (mode_ == HcalTopologyMode::Run2C) || + (mode_ == HcalTopologyMode::Run3) || (mode_ == HcalTopologyMode::SLHC)); + } bool phase2() const { return ((mode_ == HcalTopologyMode::Run4)); } /** Get the neighbors of the given cell with higher absolute ieta */ int incAIEta(const HcalDetId& id, HcalDetId neighbors[2]) const; @@ -179,7 +185,7 @@ class HcalTopology : public CaloSubdetectorTopology { /** Is this a valid cell id, ignoring the exclusion list */ bool validDetIdPreLS1(const HcalDetId& id) const; - bool validRaw(const HcalDetId& id, const bool debug=false) const; + bool validRaw(const HcalDetId& id, const bool debug = false) const; unsigned int detId2denseIdPreLS1(const DetId& id) const; bool isExcluded(const HcalDetId& id) const; diff --git a/Geometry/CaloTopology/src/HcalTopology.cc b/Geometry/CaloTopology/src/HcalTopology.cc index 74d94df112ec1..05dca5267a42e 100644 --- a/Geometry/CaloTopology/src/HcalTopology.cc +++ b/Geometry/CaloTopology/src/HcalTopology.cc @@ -158,7 +158,8 @@ HcalTopology::HcalTopology(const HcalDDDRecConstants* hcons, const bool mergePos // Now redfine some of the sizes #ifdef EDM_ML_DEBUG - edm::LogVerbatim("HCalGeom") << "Redefined sizes could be for HB:" << ncells(HcalBarrel) << " HE:" << ncells(HcalEndcap) << " HF: " << ncells(HcalForward); + edm::LogVerbatim("HCalGeom") << "Redefined sizes could be for HB:" << ncells(HcalBarrel) + << " HE:" << ncells(HcalEndcap) << " HF: " << ncells(HcalForward); #endif } @@ -495,7 +496,7 @@ bool HcalTopology::validDetIdPreLS1(const HcalDetId& id) const { /** Is this a valid cell id? */ bool HcalTopology::validRaw(const HcalDetId& id, #ifdef EDM_ML_DEBUG - const bool debug) const { + const bool debug) const { #else const bool) const { #endif @@ -568,7 +569,13 @@ bool HcalTopology::validRaw(const HcalDetId& id, } #ifdef EDM_ML_DEBUG if (debug) - edm::LogVerbatim("HCalGeom") << "HcalValdRaw ID: " << subdet << ":" << aieta << ":" << depth << ":" << iphi << ":" << zside << " Mode " << mode_ << ":" << phase1() << ":" << phase1A() << ":" << phase1B() << ":" << phase2() << " Limits HB " << lastHBRing() << " HE " << firstHERing() << ":" << lastHERing() << ":" << firstHEDoublePhiRing() << ":" << firstHEQuadPhiRing() << " Depth " << hcons_->getMaxDepth(0, aieta, iphi, zside) << ":" << hcons_->getMinDepth(0, aieta, iphi, zside) << ":" << hcons_->getDepthEta16(2, iphi, zside) << " OK " << ok; + edm::LogVerbatim("HCalGeom") << "HcalValdRaw ID: " << subdet << ":" << aieta << ":" << depth << ":" << iphi << ":" + << zside << " Mode " << mode_ << ":" << phase1() << ":" << phase1A() << ":" + << phase1B() << ":" << phase2() << " Limits HB " << lastHBRing() << " HE " + << firstHERing() << ":" << lastHERing() << ":" << firstHEDoublePhiRing() << ":" + << firstHEQuadPhiRing() << " Depth " << hcons_->getMaxDepth(0, aieta, iphi, zside) + << ":" << hcons_->getMinDepth(0, aieta, iphi, zside) << ":" + << hcons_->getDepthEta16(2, iphi, zside) << " OK " << ok; #endif return ok; } @@ -836,13 +843,13 @@ bool HcalTopology::incrementDepth(HcalDetId& detId) const { depth = 4; } else if (subdet == HcalBarrel && etaRing == lastHBRing()) { // overlap - if (phase2()) { // No more chance - detId = HcalDetId(); - return false; + if (phase2()) { // No more chance + detId = HcalDetId(); + return false; } else { - subdet = HcalEndcap; - if (phase1B()) - depth = hcons_->getDepthEta16(2, iphi, zside); + subdet = HcalEndcap; + if (phase1B()) + depth = hcons_->getDepthEta16(2, iphi, zside); } } else if ((subdet == HcalEndcap) && (etaRing == lastHERing() - 1) && !phase1B()) { // guard ring HF29 is behind HE 28 @@ -1650,9 +1657,9 @@ unsigned int HcalTopology::ncells(int subdet) const { for (int eta = -maxEta_; eta <= maxEta_; eta++) { for (unsigned int phi = 1; phi <= maxPhi_; phi++) { for (int depth = 1; depth <= 7; depth++) { - HcalDetId cell((HcalSubdetector)subdet, eta, phi, depth); - if (validRaw(cell, true)) - ++ncell; + HcalDetId cell((HcalSubdetector)subdet, eta, phi, depth); + if (validRaw(cell, true)) + ++ncell; } } } diff --git a/Geometry/CaloTopology/test/HcalTopologyTester.cc b/Geometry/CaloTopology/test/HcalTopologyTester.cc index 5a2cd82550004..fd859689337ab 100644 --- a/Geometry/CaloTopology/test/HcalTopologyTester.cc +++ b/Geometry/CaloTopology/test/HcalTopologyTester.cc @@ -54,8 +54,8 @@ void HcalTopologyTester::doTest(const HcalTopology& topology) { << " Calib: " << topology.getCALIBSize() << " Overall: " << topology.ncells(); std::vector dets = {"HB", "HE", "HO", "HF"}; for (int det = 1; det <= 4; ++det) - edm::LogVerbatim("HCalGeom") << "Valid cells for " << dets[det-1] << " = " << topology.ncells(det); - + edm::LogVerbatim("HCalGeom") << "Valid cells for " << dets[det - 1] << " = " << topology.ncells(det); + // First test on movements along eta/phi directions edm::LogVerbatim("HCalGeom") << "\nTest on movements along eta/phi directions" << "\n==========================================";