From b73f9f89e528016f419187bd7ac99ace4b0a376c Mon Sep 17 00:00:00 2001 From: Kenichi Hatakeyama Date: Wed, 26 Feb 2020 12:06:32 -0600 Subject: [PATCH] Cleanup of PRRecHit producer update for HCAL --- .../interface/PFHCALDenseIdNavigator.h | 6 +- .../interface/PFRecHitHCALCachedNavigator.h | 185 ------------------ .../PFClusterProducer/plugins/Navigators.cc | 19 +- .../plugins/PFRecHitProducer.cc | 4 +- .../plugins/PFRecHitProducer.h | 4 +- .../python/particleFlowRecHitHBHE_cfi.py | 2 +- .../python/particleFlowRecHitHF_cfi.py | 6 +- .../python/particleFlowRecHitHO_cfi.py | 2 +- 8 files changed, 28 insertions(+), 200 deletions(-) delete mode 100644 RecoParticleFlow/PFClusterProducer/interface/PFRecHitHCALCachedNavigator.h diff --git a/RecoParticleFlow/PFClusterProducer/interface/PFHCALDenseIdNavigator.h b/RecoParticleFlow/PFClusterProducer/interface/PFHCALDenseIdNavigator.h index 968f264121831..c786d20659a37 100644 --- a/RecoParticleFlow/PFClusterProducer/interface/PFHCALDenseIdNavigator.h +++ b/RecoParticleFlow/PFClusterProducer/interface/PFHCALDenseIdNavigator.h @@ -35,17 +35,17 @@ class PFHCALDenseIdNavigator : public PFRecHitNavigatorBase { } void init(const edm::EventSetup& iSetup) override { - /* if (!neighboursHcal_.empty()) return; // neighboursHcal_ is already defined. No need to redefine it. */ bool check = theRecNumberWatcher_.check(iSetup); std::cout << "check: " << check << " " << neighboursHcal_.size() << std::endl; - if (!check) return; + if (!check) + return; //std::cout << "checking" << std::endl; - + edm::ESHandle hcalTopology; iSetup.get().get(hcalTopology); topology_.release(); diff --git a/RecoParticleFlow/PFClusterProducer/interface/PFRecHitHCALCachedNavigator.h b/RecoParticleFlow/PFClusterProducer/interface/PFRecHitHCALCachedNavigator.h deleted file mode 100644 index 2006274c10b92..0000000000000 --- a/RecoParticleFlow/PFClusterProducer/interface/PFRecHitHCALCachedNavigator.h +++ /dev/null @@ -1,185 +0,0 @@ -#ifndef RecoParticleFlow_PFClusterProducer_PFRecHitHCALCachedNavigator_h -#define RecoParticleFlow_PFClusterProducer_PFRecHitHCALCachedNavigator_h - -#include "RecoParticleFlow/PFClusterProducer/interface/PFRecHitNavigatorBase.h" -#include "Geometry/CaloGeometry/interface/CaloSubdetectorGeometry.h" -#include "Geometry/CaloGeometry/interface/CaloGeometry.h" - -#include "RecoCaloTools/Navigation/interface/CaloNavigator.h" -#include "DataFormats/EcalDetId/interface/EBDetId.h" -#include "DataFormats/EcalDetId/interface/EEDetId.h" -#include "DataFormats/EcalDetId/interface/ESDetId.h" -#include "DataFormats/HcalDetId/interface/HcalDetId.h" - -#include "Geometry/CaloTopology/interface/EcalEndcapTopology.h" -#include "Geometry/CaloTopology/interface/EcalBarrelTopology.h" -#include "Geometry/CaloTopology/interface/EcalPreshowerTopology.h" -#include "Geometry/CaloTopology/interface/HcalTopology.h" - -#include "Geometry/CaloTopology/interface/CaloTowerTopology.h" -#include "DataFormats/CaloTowers/interface/CaloTowerDetId.h" - -template -class PFRecHitHCALCachedNavigator : public PFRecHitNavigatorBase { -public: - ~PFRecHitHCALCachedNavigator() override { - if (!ownsTopo) { - topology_.release(); - } - } - - PFRecHitHCALCachedNavigator(const edm::ParameterSet& iConfig) { - vdetectorEnum_ = iConfig.getParameter>("detectorEnums"); - } - - void init(const edm::EventSetup& iSetup) override { - if (!neighboursHcal_.empty()) - return; // neighboursHcal_ is already defined. No need to redefine it. - - edm::ESHandle hcalTopology; - iSetup.get().get(hcalTopology); - topology_.release(); - topology_.reset(hcalTopology.product()); - - // Fill a vector of valid denseid's - edm::ESHandle hGeom; - iSetup.get().get(hGeom); - const CaloGeometry& caloGeom = *hGeom; - - std::vector vecHcal; - std::vector vDenseIdHcal; - vecHcal.clear(); - vDenseIdHcal.clear(); - neighboursHcal_.clear(); - for (unsigned i = 0; i < vdetectorEnum_.size(); ++i) { - std::vector vecDetIds(caloGeom.getValidDetIds(DetId::Hcal, vdetectorEnum_[i])); - vecHcal.insert(vecHcal.end(), vecDetIds.begin(), vecDetIds.end()); - } - for (unsigned i = 0; i < vecHcal.size(); ++i) { - vDenseIdHcal.push_back(topology_.get()->detId2denseId(vecHcal[i])); - } - std::sort(vDenseIdHcal.begin(), vDenseIdHcal.end()); - - // Fill a vector of cell neighbours - denseIdHcalMax_ = *max_element(vDenseIdHcal.begin(), vDenseIdHcal.end()); - denseIdHcalMin_ = *min_element(vDenseIdHcal.begin(), vDenseIdHcal.end()); - neighboursHcal_.resize(denseIdHcalMax_ - denseIdHcalMin_ + 1); - - for (unsigned i = 0; i < vDenseIdHcal.size(); ++i) { - DetId N(0); - DetId E(0); - DetId S(0); - DetId W(0); - DetId NW(0); - DetId NE(0); - DetId SW(0); - DetId SE(0); - std::vector neighbours(9, DetId(0)); - - // the centre - unsigned denseid_c = vDenseIdHcal[i]; - DetId detid_c = topology_.get()->denseId2detId(denseid_c); - CaloNavigator navigator(detid_c, topology_.get()); - - // Using enum in Geometry/CaloTopology/interface/CaloDirection.h - // Order: CENTER(NONE),SOUTH,SOUTHEAST,SOUTHWEST,EAST,WEST,NORTHEAST,NORTHWEST,NORTH - neighbours[NONE] = detid_c; - - navigator.home(); - N = navigator.north(); - neighbours[NORTH] = N; - if (N != DetId(0)) { - NE = navigator.east(); - } else { - navigator.home(); - E = navigator.east(); - NE = navigator.north(); - } - neighbours[NORTHEAST] = NE; - - navigator.home(); - S = navigator.south(); - neighbours[SOUTH] = S; - if (S != DetId(0)) { - SW = navigator.west(); - } else { - navigator.home(); - W = navigator.west(); - SW = navigator.south(); - } - neighbours[SOUTHWEST] = SW; - - navigator.home(); - E = navigator.east(); - neighbours[EAST] = E; - if (E != DetId(0)) { - SE = navigator.south(); - } else { - navigator.home(); - S = navigator.south(); - SE = navigator.east(); - } - neighbours[SOUTHEAST] = SE; - - navigator.home(); - W = navigator.west(); - neighbours[WEST] = W; - if (W != DetId(0)) { - NW = navigator.north(); - } else { - navigator.home(); - N = navigator.north(); - NW = navigator.west(); - } - neighbours[NORTHWEST] = NW; - - unsigned index = denseid_c - denseIdHcalMin_; - neighboursHcal_[index] = neighbours; - } - } - - void associateNeighbours(reco::PFRecHit& hit, - std::unique_ptr& hits, - edm::RefProd& refProd) override { - DetId detid(hit.detId()); - unsigned denseid = topology_.get()->detId2denseId(detid); - - std::vector neighbours(9, DetId(0)); - - if (denseid < denseIdHcalMin_ || denseid > denseIdHcalMax_) { - edm::LogWarning("PFRecHitHCALCachedNavigator") << " DenseId for this cell is out of the range." << std::endl; - } else if (!validNeighbours(denseid)) { - edm::LogWarning("PFRecHitHCALCachedNavigator") - << " DenseId for this cell does not have the neighbour information." << std::endl; - } else { - unsigned index = denseid - denseIdHcalMin_; - neighbours = neighboursHcal_[index]; - } - - associateNeighbour(neighbours[NORTH], hit, hits, refProd, 0, 1, 0); // N - associateNeighbour(neighbours[NORTHEAST], hit, hits, refProd, 1, 1, 0); // NE - associateNeighbour(neighbours[SOUTH], hit, hits, refProd, 0, -1, 0); // S - associateNeighbour(neighbours[SOUTHWEST], hit, hits, refProd, -1, -1, 0); // SW - associateNeighbour(neighbours[EAST], hit, hits, refProd, 1, 0, 0); // E - associateNeighbour(neighbours[SOUTHEAST], hit, hits, refProd, 1, -1, 0); // SE - associateNeighbour(neighbours[WEST], hit, hits, refProd, -1, 0, 0); // W - associateNeighbour(neighbours[NORTHWEST], hit, hits, refProd, -1, 1, 0); // NW - } - - bool validNeighbours(const unsigned int denseid) const { - bool ok = true; - unsigned index = denseid - denseIdHcalMin_; - if (neighboursHcal_[index].size() != 9) - ok = false; // the neighbour vector size should be 3x3 - return ok; - } - -protected: - std::unique_ptr topology_; - std::vector vdetectorEnum_; - std::vector> neighboursHcal_; - unsigned int denseIdHcalMax_; - unsigned int denseIdHcalMin_; -}; - -#endif diff --git a/RecoParticleFlow/PFClusterProducer/plugins/Navigators.cc b/RecoParticleFlow/PFClusterProducer/plugins/Navigators.cc index dd483f55a0bf1..1dbf5c78b820b 100644 --- a/RecoParticleFlow/PFClusterProducer/plugins/Navigators.cc +++ b/RecoParticleFlow/PFClusterProducer/plugins/Navigators.cc @@ -6,7 +6,7 @@ #include "RecoParticleFlow/PFClusterProducer/interface/PFRecHitDualNavigator.h" #include "RecoParticleFlow/PFClusterProducer/interface/PFRecHitCaloNavigator.h" #include "RecoParticleFlow/PFClusterProducer/interface/PFRecHitCaloNavigatorWithTime.h" -#include "RecoParticleFlow/PFClusterProducer/interface/PFRecHitHCALCachedNavigator.h" +#include "RecoParticleFlow/PFClusterProducer/interface/PFHCALDenseIdNavigator.h" #include "RecoParticleFlow/PFClusterProducer/interface/PFECALHashNavigator.h" #include "RecoParticleFlow/PFClusterProducer/interface/HGCRecHitNavigator.h" @@ -61,9 +61,21 @@ class PFRecHitPreshowerNavigator final : public PFRecHitCaloNavigator(); } }; -class PFRecHitHCALNavigator final : public PFRecHitHCALCachedNavigator { +class PFRecHitHCALDenseIdNavigator final : public PFHCALDenseIdNavigator { public: - PFRecHitHCALNavigator(const edm::ParameterSet& iConfig) : PFRecHitHCALCachedNavigator(iConfig) {} + PFRecHitHCALDenseIdNavigator(const edm::ParameterSet& iConfig) : PFHCALDenseIdNavigator(iConfig) {} +}; + +class PFRecHitHCALNavigator : public PFRecHitCaloNavigator { +public: + PFRecHitHCALNavigator(const edm::ParameterSet& iConfig) {} + + void init(const edm::EventSetup& iSetup) override { + edm::ESHandle hcalTopology; + iSetup.get().get(hcalTopology); + topology_.release(); + topology_.reset(hcalTopology.product()); + } }; class PFRecHitHCALNavigatorWithTime : public PFRecHitCaloNavigatorWithTime { @@ -145,6 +157,7 @@ DEFINE_EDM_PLUGIN(PFRecHitNavigationFactory, PFRecHitECALNavigator, "PFRecHitECA DEFINE_EDM_PLUGIN(PFRecHitNavigationFactory, PFRecHitECALNavigatorWithTime, "PFRecHitECALNavigatorWithTime"); DEFINE_EDM_PLUGIN(PFRecHitNavigationFactory, PFRecHitCaloTowerNavigator, "PFRecHitCaloTowerNavigator"); DEFINE_EDM_PLUGIN(PFRecHitNavigationFactory, PFRecHitPreshowerNavigator, "PFRecHitPreshowerNavigator"); +DEFINE_EDM_PLUGIN(PFRecHitNavigationFactory, PFRecHitHCALDenseIdNavigator, "PFRecHitHCALDenseIdNavigator"); DEFINE_EDM_PLUGIN(PFRecHitNavigationFactory, PFRecHitHCALNavigator, "PFRecHitHCALNavigator"); DEFINE_EDM_PLUGIN(PFRecHitNavigationFactory, PFRecHitHCALNavigatorWithTime, "PFRecHitHCALNavigatorWithTime"); DEFINE_EDM_PLUGIN(PFRecHitNavigationFactory, PFRecHitHGCEENavigator, "PFRecHitHGCEENavigator"); diff --git a/RecoParticleFlow/PFClusterProducer/plugins/PFRecHitProducer.cc b/RecoParticleFlow/PFClusterProducer/plugins/PFRecHitProducer.cc index 738fcf51f648c..8ba3648b26b34 100644 --- a/RecoParticleFlow/PFClusterProducer/plugins/PFRecHitProducer.cc +++ b/RecoParticleFlow/PFClusterProducer/plugins/PFRecHitProducer.cc @@ -30,14 +30,14 @@ PFRecHitProducer::~PFRecHitProducer() = default; // member functions // -void PFRecHitProducer::beginRun(const edm::Run&, const edm::EventSetup& iSetup) { +void PFRecHitProducer::beginLuminosityBlock(edm::LuminosityBlock const& iLumi, const edm::EventSetup& iSetup) { for (const auto& creator : creators_) { creator->init(iSetup); } navigator_->init(iSetup); } -void PFRecHitProducer::endRun(const edm::Run&, const edm::EventSetup&) {} +void PFRecHitProducer::endLuminosityBlock(edm::LuminosityBlock const& iLumi, const edm::EventSetup&) {} // ------------ method called to produce the data ------------ void PFRecHitProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) { diff --git a/RecoParticleFlow/PFClusterProducer/plugins/PFRecHitProducer.h b/RecoParticleFlow/PFClusterProducer/plugins/PFRecHitProducer.h index d3335852a653f..87b2a7a0ac3d2 100644 --- a/RecoParticleFlow/PFClusterProducer/plugins/PFRecHitProducer.h +++ b/RecoParticleFlow/PFClusterProducer/plugins/PFRecHitProducer.h @@ -27,8 +27,8 @@ class PFRecHitProducer final : public edm::stream::EDProducer<> { private: void produce(edm::Event&, const edm::EventSetup&) override; - void beginRun(const edm::Run&, const edm::EventSetup&) override; - void endRun(const edm::Run&, const edm::EventSetup&) override; + void beginLuminosityBlock(edm::LuminosityBlock const&, const edm::EventSetup&) override; + void endLuminosityBlock(edm::LuminosityBlock const&, const edm::EventSetup&) override; std::vector > creators_; std::unique_ptr navigator_; bool init_; diff --git a/RecoParticleFlow/PFClusterProducer/python/particleFlowRecHitHBHE_cfi.py b/RecoParticleFlow/PFClusterProducer/python/particleFlowRecHitHBHE_cfi.py index 9348d2be84bef..258cdc642ef8e 100644 --- a/RecoParticleFlow/PFClusterProducer/python/particleFlowRecHitHBHE_cfi.py +++ b/RecoParticleFlow/PFClusterProducer/python/particleFlowRecHitHBHE_cfi.py @@ -9,7 +9,7 @@ particleFlowRecHitHBHE = cms.EDProducer("PFRecHitProducer", navigator = cms.PSet( - name = cms.string("PFRecHitHCALNavigator"), + name = cms.string("PFRecHitHCALDenseIdNavigator"), detectorEnums = cms.vint32(1,2) ), producers = cms.VPSet( diff --git a/RecoParticleFlow/PFClusterProducer/python/particleFlowRecHitHF_cfi.py b/RecoParticleFlow/PFClusterProducer/python/particleFlowRecHitHF_cfi.py index d9e5b1bb86b5f..41d4d3400f17d 100644 --- a/RecoParticleFlow/PFClusterProducer/python/particleFlowRecHitHF_cfi.py +++ b/RecoParticleFlow/PFClusterProducer/python/particleFlowRecHitHF_cfi.py @@ -5,7 +5,7 @@ particleFlowRecHitHF = cms.EDProducer("PFRecHitProducer", navigator = cms.PSet( - name = cms.string("PFRecHitHCALNavigator"), + name = cms.string("PFRecHitHCALDenseIdNavigator"), detectorEnums = cms.vint32(4) ), producers = cms.VPSet( @@ -36,9 +36,9 @@ detectorEnum = cms.int32(4)) ) ) - + ) - ) + ) ) ) diff --git a/RecoParticleFlow/PFClusterProducer/python/particleFlowRecHitHO_cfi.py b/RecoParticleFlow/PFClusterProducer/python/particleFlowRecHitHO_cfi.py index ab8b60e7573d9..2795cd2c30d9b 100644 --- a/RecoParticleFlow/PFClusterProducer/python/particleFlowRecHitHO_cfi.py +++ b/RecoParticleFlow/PFClusterProducer/python/particleFlowRecHitHO_cfi.py @@ -1,7 +1,7 @@ import FWCore.ParameterSet.Config as cms particleFlowRecHitHO = cms.EDProducer("PFRecHitProducer", navigator = cms.PSet( - name = cms.string("PFRecHitHCALNavigator"), + name = cms.string("PFRecHitHCALDenseIdNavigator"), detectorEnums = cms.vint32(3) ), producers = cms.VPSet(