Skip to content

Commit

Permalink
EgammaHadTower to namespace
Browse files Browse the repository at this point in the history
  • Loading branch information
guitargeek committed Oct 7, 2020
1 parent b1e154d commit 0d9d2e2
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 97 deletions.
12 changes: 4 additions & 8 deletions RecoEgamma/EgammaElectronAlgos/interface/ElectronHcalHelper.h
Original file line number Diff line number Diff line change
@@ -1,24 +1,20 @@

#ifndef ElectronHcalHelper_h
#define ElectronHcalHelper_h

class EgammaHcalIsolation;
class EgammaTowerIsolation;

#include "DataFormats/CaloTowers/interface/CaloTowerCollection.h"
#include "Geometry/CaloGeometry/interface/CaloGeometry.h"
#include "FWCore/Framework/interface/Event.h"
#include "FWCore/Framework/interface/EventSetup.h"
#include "FWCore/Framework/interface/ESHandle.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "DataFormats/EgammaReco/interface/SuperClusterFwd.h"
#include "DataFormats/Common/interface/Handle.h"
#include "DataFormats/HcalRecHit/interface/HcalRecHitCollections.h"
#include "FWCore/Framework/interface/ConsumesCollector.h"

class EgammaHcalIsolation;
class EgammaTowerIsolation;
class EgammaHadTower;
class HcalTopology;
class HcalChannelQuality;
class CaloTowerConstituentsMap;

class ElectronHcalHelper {
public:
Expand Down Expand Up @@ -71,8 +67,8 @@ class ElectronHcalHelper {
// event data (towers strategy)
EgammaTowerIsolation *towerIso1_;
EgammaTowerIsolation *towerIso2_;
EgammaHadTower *hadTower_;
CaloTowerCollection const *towersFromCollection_ = nullptr;
CaloTowerConstituentsMap const *towerMap_ = nullptr;
HcalChannelQuality const *hcalQuality_ = nullptr;
HcalTopology const *hcalTopology_ = nullptr;
};
Expand Down
16 changes: 7 additions & 9 deletions RecoEgamma/EgammaElectronAlgos/src/ElectronHcalHelper.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

#include "RecoEgamma/EgammaElectronAlgos/interface/ElectronHcalHelper.h"
#include "RecoEgamma/EgammaIsolationAlgos/interface/EgammaHcalIsolation.h"
#include "RecoEgamma/EgammaIsolationAlgos/interface/EgammaTowerIsolation.h"
Expand All @@ -11,17 +10,17 @@
using namespace reco;

ElectronHcalHelper::ElectronHcalHelper(const Configuration& cfg)
: cfg_(cfg), caloGeomCacheId_(0), hcalIso_(nullptr), towerIso1_(nullptr), towerIso2_(nullptr), hadTower_(nullptr) {}
: cfg_(cfg), caloGeomCacheId_(0), hcalIso_(nullptr), towerIso1_(nullptr), towerIso2_(nullptr) {}

void ElectronHcalHelper::checkSetup(const edm::EventSetup& es) {
if (cfg_.hOverEConeSize == 0) {
return;
}

if (cfg_.useTowers) {
delete hadTower_;
edm::ESHandle<CaloTowerConstituentsMap> ctmaph;
es.get<CaloGeometryRecord>().get(ctmaph);
towerMap_ = ctmaph.product();

edm::ESHandle<HcalChannelQuality> hQuality;
es.get<HcalChannelQualityRcd>().get("withTopo", hQuality);
Expand All @@ -30,7 +29,6 @@ void ElectronHcalHelper::checkSetup(const edm::EventSetup& es) {
es.get<HcalRecNumberingRecord>().get(hcalTopology);
hcalTopology_ = hcalTopology.product();

hadTower_ = new EgammaHadTower(*ctmaph);
} else {
unsigned long long newCaloGeomCacheId_ = es.get<CaloGeometryRecord>().cacheIdentifier();
if (caloGeomCacheId_ != newCaloGeomCacheId_) {
Expand Down Expand Up @@ -69,15 +67,15 @@ void ElectronHcalHelper::readEvent(const edm::Event& evt) {
}

std::vector<CaloTowerDetId> ElectronHcalHelper::hcalTowersBehindClusters(const reco::SuperCluster& sc) const {
return hadTower_->towersOf(sc);
return egammaHadTower::towersOf(sc, *towerMap_);
}

double ElectronHcalHelper::hcalESumDepth1BehindClusters(const std::vector<CaloTowerDetId>& towers) const {
return hadTower_->getDepth1HcalESum(towers, *towersFromCollection_);
return egammaHadTower::getDepth1HcalESum(towers, *towersFromCollection_);
}

double ElectronHcalHelper::hcalESumDepth2BehindClusters(const std::vector<CaloTowerDetId>& towers) const {
return hadTower_->getDepth2HcalESum(towers, *towersFromCollection_);
return egammaHadTower::getDepth2HcalESum(towers, *towersFromCollection_);
}

double ElectronHcalHelper::hcalESum(const SuperCluster& sc, const std::vector<CaloTowerDetId>* excludeTowers) const {
Expand Down Expand Up @@ -117,7 +115,8 @@ double ElectronHcalHelper::hcalESumDepth2(const SuperCluster& sc,

bool ElectronHcalHelper::hasActiveHcal(const reco::SuperCluster& sc) const {
if (cfg_.checkHcalStatus && cfg_.hOverEConeSize != 0 && cfg_.useTowers) {
return hadTower_->hasActiveHcal(hadTower_->towersOf(sc), *hcalQuality_, *hcalTopology_);
return egammaHadTower::hasActiveHcal(
egammaHadTower::towersOf(sc, *towerMap_), *towerMap_, *hcalQuality_, *hcalTopology_);
} else {
return true;
}
Expand All @@ -130,7 +129,6 @@ ElectronHcalHelper::~ElectronHcalHelper() {
if (cfg_.useTowers) {
delete towerIso1_;
delete towerIso2_;
delete hadTower_;
} else {
delete hcalIso_;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,6 @@ void EgammaHLTBcHcalIsolationProducersRegional::produce(edm::StreamID,
edm::ESHandle<CaloTowerConstituentsMap> ctmaph;
iSetup.get<CaloGeometryRecord>().get(ctmaph);

EgammaHadTower hadTower(*ctmaph);

const EgammaTowerIsolation towerIso1(outerCone_, 0., etMin_, 1, &caloTowers);
const EgammaTowerIsolation towerIso2(outerCone_, 0., etMin_, 2, &caloTowers);

Expand All @@ -137,8 +135,8 @@ void EgammaHLTBcHcalIsolationProducersRegional::produce(edm::StreamID,

float isol = 0;

auto towersBehindCluster =
useSingleTower_ ? hadTower.towersOf(*(recoEcalCandRef->superCluster())) : std::vector<CaloTowerDetId>{};
auto towersBehindCluster = useSingleTower_ ? egammaHadTower::towersOf(*(recoEcalCandRef->superCluster()), *ctmaph)
: std::vector<CaloTowerDetId>{};

if (doEtSum_) { //calculate hcal isolation excluding the towers behind the cluster which will be used for H for H/E
const EgammaTowerIsolation isolAlgo(outerCone_, innerCone_, etMin_, depth_, &caloTowers);
Expand All @@ -151,8 +149,8 @@ void EgammaHLTBcHcalIsolationProducersRegional::produce(edm::StreamID,

} else { //calcuate H for H/E
if (useSingleTower_)
isol = hadTower.getDepth1HcalESum(towersBehindCluster, caloTowers) +
hadTower.getDepth2HcalESum(towersBehindCluster, caloTowers);
isol = egammaHadTower::getDepth1HcalESum(towersBehindCluster, caloTowers) +
egammaHadTower::getDepth2HcalESum(towersBehindCluster, caloTowers);
else {
auto const &sc = recoEcalCandRef->superCluster().get();
isol = towerIso1.getTowerESum(sc) + towerIso2.getTowerESum(sc);
Expand Down
34 changes: 17 additions & 17 deletions RecoEgamma/EgammaIsolationAlgos/interface/EgammaHadTower.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,29 @@
// Florian Beaudette 22 Jun 2011

#include "DataFormats/CaloTowers/interface/CaloTowerCollection.h"
#include "DataFormats/EgammaReco/interface/SuperCluster.h"
#include "DataFormats/EgammaReco/interface/SuperClusterFwd.h"
#include "DataFormats/CaloRecHit/interface/CaloCluster.h"
#include "Geometry/CaloTopology/interface/CaloTowerConstituentsMap.h"
#include "Geometry/CaloTopology/interface/HcalTopology.h"

class HcalChannelQuality;

class EgammaHadTower {
public:
enum HoeMode { SingleTower = 0, TowersBehindCluster = 1 };

EgammaHadTower(CaloTowerConstituentsMap const& towerMap) : towerMap_{towerMap} {}
double getDepth1HcalESum(const std::vector<CaloTowerDetId>& towers, CaloTowerCollection const&) const;
double getDepth2HcalESum(const std::vector<CaloTowerDetId>& towers, CaloTowerCollection const&) const;
std::vector<CaloTowerDetId> towersOf(const reco::SuperCluster& sc, HoeMode mode = SingleTower) const;
CaloTowerDetId towerOf(const reco::CaloCluster& cluster) const;
bool hasActiveHcal(const std::vector<CaloTowerDetId>& towers,
const HcalChannelQuality& hcalQuality,
HcalTopology const& hcalTopology) const;

private:
const CaloTowerConstituentsMap& towerMap_;
};
namespace egammaHadTower {
enum class HoeMode { SingleTower = 0, TowersBehindCluster = 1 };

double getDepth1HcalESum(std::vector<CaloTowerDetId> const& towers, CaloTowerCollection const&);
double getDepth2HcalESum(std::vector<CaloTowerDetId> const& towers, CaloTowerCollection const&);

std::vector<CaloTowerDetId> towersOf(reco::SuperCluster const& sc,
CaloTowerConstituentsMap const& towerMap,
HoeMode mode = HoeMode::SingleTower);

CaloTowerDetId towerOf(reco::CaloCluster const& cluster, CaloTowerConstituentsMap const& towerMap);

bool hasActiveHcal(std::vector<CaloTowerDetId> const& towers,
CaloTowerConstituentsMap const& towerMap,
HcalChannelQuality const& hcalQuality,
HcalTopology const& hcalTopology);
}; // namespace egammaHadTower

#endif
46 changes: 20 additions & 26 deletions RecoEgamma/EgammaIsolationAlgos/src/EgammaHadTower.cc
Original file line number Diff line number Diff line change
@@ -1,22 +1,13 @@
#include "RecoEgamma/EgammaIsolationAlgos/interface/EgammaHadTower.h"
#include "Geometry/CaloEventSetup/interface/CaloTopologyRecord.h"
#include "DataFormats/EcalDetId/interface/EcalSubdetector.h"
#include "Geometry/Records/interface/CaloGeometryRecord.h"
#include "CondFormats/HcalObjects/interface/HcalChannelStatus.h"
#include "CondFormats/HcalObjects/interface/HcalChannelQuality.h"
#include "CondFormats/HcalObjects/interface/HcalCondObjectContainer.h"
#include "CondFormats/DataRecord/interface/HcalChannelQualityRcd.h"
#include "DataFormats/HcalDetId/interface/HcalDetId.h"
#include "DataFormats/EgammaReco/interface/SuperCluster.h"

#include "Geometry/Records/interface/CaloGeometryRecord.h"
#include "Geometry/Records/interface/HcalRecNumberingRecord.h"

#include <algorithm>
#include <iostream>
#include <algorithm>

//#define EDM_ML_DEBUG

CaloTowerDetId EgammaHadTower::towerOf(const reco::CaloCluster& cluster) const {
CaloTowerDetId egammaHadTower::towerOf(const reco::CaloCluster& cluster, CaloTowerConstituentsMap const& towerMap) {
DetId detid = cluster.seed();
if (detid.det() != DetId::Ecal) {
// Basic clusters of hybrid super-cluster do not have the seed set; take the first DetId instead
Expand All @@ -27,23 +18,25 @@ CaloTowerDetId EgammaHadTower::towerOf(const reco::CaloCluster& cluster) const {
return tower;
}
}
CaloTowerDetId id(towerMap_.towerOf(detid));
CaloTowerDetId id(towerMap.towerOf(detid));
return id;
}

std::vector<CaloTowerDetId> EgammaHadTower::towersOf(const reco::SuperCluster& sc, HoeMode mode) const {
std::vector<CaloTowerDetId> egammaHadTower::towersOf(const reco::SuperCluster& sc,
CaloTowerConstituentsMap const& towerMap,
HoeMode mode) {
constexpr unsigned int nMaxClusters = 4;

std::vector<CaloTowerDetId> towers;
std::vector<reco::CaloClusterPtr> orderedClusters;

// in this mode, check only the tower behind the seed
if (mode == SingleTower) {
towers.push_back(towerOf(*sc.seed()));
if (mode == HoeMode::SingleTower) {
towers.push_back(towerOf(*sc.seed(), towerMap));
}

// in this mode check the towers behind each basic cluster
if (mode == TowersBehindCluster) {
if (mode == HoeMode::TowersBehindCluster) {
// Loop on the basic clusters
for (auto it = sc.clustersBegin(); it != sc.clustersEnd(); ++it) {
orderedClusters.push_back(*it);
Expand All @@ -52,7 +45,7 @@ std::vector<CaloTowerDetId> EgammaHadTower::towersOf(const reco::SuperCluster& s
unsigned nclusters = orderedClusters.size();
for (unsigned iclus = 0; iclus < nclusters && iclus < nMaxClusters; ++iclus) {
// Get the tower
CaloTowerDetId id = towerOf(*(orderedClusters[iclus]));
CaloTowerDetId id = towerOf(*(orderedClusters[iclus]), towerMap);
#ifdef EDM_ML_DEBUG
std::cout << "CaloTowerId " << id << std::endl;
#endif
Expand All @@ -77,8 +70,8 @@ std::vector<CaloTowerDetId> EgammaHadTower::towersOf(const reco::SuperCluster& s
return towers;
}

double EgammaHadTower::getDepth1HcalESum(const std::vector<CaloTowerDetId>& towers,
CaloTowerCollection const& towerCollection) const {
double egammaHadTower::getDepth1HcalESum(const std::vector<CaloTowerDetId>& towers,
CaloTowerCollection const& towerCollection) {
double esum = 0.;
for (auto const& tower : towerCollection) {
if (std::find(towers.begin(), towers.end(), tower.id()) != towers.end()) {
Expand All @@ -88,8 +81,8 @@ double EgammaHadTower::getDepth1HcalESum(const std::vector<CaloTowerDetId>& towe
return esum;
}

double EgammaHadTower::getDepth2HcalESum(const std::vector<CaloTowerDetId>& towers,
CaloTowerCollection const& towerCollection) const {
double egammaHadTower::getDepth2HcalESum(const std::vector<CaloTowerDetId>& towers,
CaloTowerCollection const& towerCollection) {
double esum = 0.;
for (auto const& tower : towerCollection) {
if (std::find(towers.begin(), towers.end(), tower.id()) != towers.end()) {
Expand All @@ -99,9 +92,10 @@ double EgammaHadTower::getDepth2HcalESum(const std::vector<CaloTowerDetId>& towe
return esum;
}

bool EgammaHadTower::hasActiveHcal(const std::vector<CaloTowerDetId>& towers,
bool egammaHadTower::hasActiveHcal(const std::vector<CaloTowerDetId>& towers,
CaloTowerConstituentsMap const& towerMap,
const HcalChannelQuality& hcalQuality,
HcalTopology const& hcalTopology) const {
HcalTopology const& hcalTopology) {
bool active = false;
int statusMask = ((1 << HcalChannelStatus::HcalCellOff) | (1 << HcalChannelStatus::HcalCellMask) |
(1 << HcalChannelStatus::HcalCellDead));
Expand All @@ -111,15 +105,15 @@ bool EgammaHadTower::hasActiveHcal(const std::vector<CaloTowerDetId>& towers,
#endif
for (auto towerid : towers) {
unsigned int ngood = 0, nbad = 0;
for (DetId id : towerMap_.constituentsOf(towerid)) {
for (DetId id : towerMap.constituentsOf(towerid)) {
if (id.det() != DetId::Hcal) {
continue;
}
HcalDetId hid(id);
if (hid.subdet() != HcalBarrel && hid.subdet() != HcalEndcap)
continue;
#ifdef EDM_ML_DEBUG
std::cout << "EgammaHadTower DetId " << std::hex << id.rawId() << " hid.rawId " << hid.rawId() << std::dec
std::cout << "egammaHadTower DetId " << std::hex << id.rawId() << " hid.rawId " << hid.rawId() << std::dec
<< " sub " << hid.subdet() << " ieta " << hid.ieta() << " iphi " << hid.iphi() << " depth "
<< hid.depth() << std::endl;
#endif
Expand Down
19 changes: 4 additions & 15 deletions RecoEgamma/EgammaPhotonProducers/src/GEDPhotonProducer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
#include <vector>
#include <memory>

// Framework
#include "FWCore/MessageLogger/interface/MessageLogger.h"
#include "FWCore/Utilities/interface/Exception.h"
#include "FWCore/Utilities/interface/isFinite.h"
Expand All @@ -15,21 +14,12 @@
#include "Geometry/CaloEventSetup/interface/CaloTopologyRecord.h"

#include "DataFormats/VertexReco/interface/Vertex.h"
#include "DataFormats/VertexReco/interface/VertexFwd.h"
#include "DataFormats/EgammaReco/interface/ClusterShape.h"
#include "DataFormats/EgammaCandidates/interface/PhotonCore.h"
#include "DataFormats/EgammaCandidates/interface/Photon.h"
#include "DataFormats/EgammaCandidates/interface/PhotonFwd.h"
#include "DataFormats/EgammaCandidates/interface/Conversion.h"
#include "DataFormats/Common/interface/ValueMap.h"
#include "DataFormats/ParticleFlowCandidate/interface/PFCandidate.h"
#include "DataFormats/ParticleFlowCandidate/interface/PFCandidateEGammaExtra.h"
#include "DataFormats/ParticleFlowCandidate/interface/PFCandidateEGammaExtraFwd.h"

#include "DataFormats/ForwardDetId/interface/ForwardSubdetector.h"

#include "DataFormats/EgammaReco/interface/ElectronSeed.h"
#include "RecoCaloTools/Selectors/interface/CaloConeSelector.h"

#include "RecoLocalCalo/EcalRecAlgos/interface/EcalSeverityLevelAlgoRcd.h"
#include "RecoLocalCalo/EcalRecAlgos/interface/EcalSeverityLevelAlgo.h"
Expand Down Expand Up @@ -527,14 +517,13 @@ void GEDPhotonProducer::fillPhotonCollection(edm::Event& evt,

edm::ESHandle<HcalTopology> hcalTopology;
es.get<HcalRecNumberingRecord>().get(hcalTopology);
EgammaHadTower towerIsoBehindClus(*ctmaph);

TowersBehindClus = towerIsoBehindClus.towersOf(*scRef);
hcalDepth1OverEcalBc = towerIsoBehindClus.getDepth1HcalESum(TowersBehindClus, *hcalTowers) / scRef->energy();
hcalDepth2OverEcalBc = towerIsoBehindClus.getDepth2HcalESum(TowersBehindClus, *hcalTowers) / scRef->energy();
TowersBehindClus = egammaHadTower::towersOf(*scRef, *ctmaph);
hcalDepth1OverEcalBc = egammaHadTower::getDepth1HcalESum(TowersBehindClus, *hcalTowers) / scRef->energy();
hcalDepth2OverEcalBc = egammaHadTower::getDepth2HcalESum(TowersBehindClus, *hcalTowers) / scRef->energy();

if (checkHcalStatus_ && hcalDepth1OverEcalBc == 0 && hcalDepth2OverEcalBc == 0) {
invalidHcal = !towerIsoBehindClus.hasActiveHcal(TowersBehindClus, *hcalQuality, *hcalTopology);
invalidHcal = !egammaHadTower::hasActiveHcal(TowersBehindClus, *ctmaph, *hcalQuality, *hcalTopology);
}
}

Expand Down
9 changes: 3 additions & 6 deletions RecoEgamma/EgammaPhotonProducers/src/PhotonProducer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,9 @@
#include "Geometry/CaloEventSetup/interface/CaloTopologyRecord.h"

#include "DataFormats/VertexReco/interface/Vertex.h"
#include "DataFormats/VertexReco/interface/VertexFwd.h"
#include "DataFormats/EgammaReco/interface/ClusterShape.h"
#include "DataFormats/EgammaCandidates/interface/PhotonCore.h"
#include "DataFormats/EgammaCandidates/interface/Photon.h"
#include "DataFormats/EgammaCandidates/interface/PhotonFwd.h"
#include "DataFormats/EgammaCandidates/interface/Conversion.h"

#include "DataFormats/EgammaReco/interface/ElectronSeed.h"
Expand Down Expand Up @@ -277,10 +275,9 @@ void PhotonProducer::fillPhotonCollection(edm::Event& evt,
edm::ESHandle<CaloTowerConstituentsMap> ctmaph;
es.get<CaloGeometryRecord>().get(ctmaph);

const EgammaHadTower egammaHadTower(*ctmaph);
auto towersBehindCluster = egammaHadTower.towersOf(*scRef);
float hcalDepth1OverEcalBc = egammaHadTower.getDepth1HcalESum(towersBehindCluster, hcalTowers) / scRef->energy();
float hcalDepth2OverEcalBc = egammaHadTower.getDepth2HcalESum(towersBehindCluster, hcalTowers) / scRef->energy();
auto towersBehindCluster = egammaHadTower::towersOf(*scRef, *ctmaph);
float hcalDepth1OverEcalBc = egammaHadTower::getDepth1HcalESum(towersBehindCluster, hcalTowers) / scRef->energy();
float hcalDepth2OverEcalBc = egammaHadTower::getDepth2HcalESum(towersBehindCluster, hcalTowers) / scRef->energy();

// recalculate position of seed BasicCluster taking shower depth for unconverted photon
math::XYZPoint unconvPos =
Expand Down
Loading

0 comments on commit 0d9d2e2

Please sign in to comment.