Skip to content

Commit

Permalink
Merge pull request #24367 from bsunanda/Run2-hcx181
Browse files Browse the repository at this point in the history
Run2-hcx181 Correct accessing constituents of CaloTower
  • Loading branch information
cmsbuild committed Aug 28, 2018
2 parents ec7f3db + 61424d7 commit 425a3c0
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 18 deletions.
5 changes: 5 additions & 0 deletions Geometry/CaloTopology/src/CaloTowerConstituentsMap.cc
Expand Up @@ -69,7 +69,12 @@ void CaloTowerConstituentsMap::sort() {
}

std::vector<DetId> CaloTowerConstituentsMap::constituentsOf(const CaloTowerDetId& id) const {
#ifdef EDM_ML_DEBUG
std::cout << "Get constituent of " << std::hex << id.rawId() << std::dec
<< " ID " << id << " ieta " << id.ieta() << std::endl;
#endif
std::vector<DetId> items;
if (id.ieta() == 0) return items;

// build reverse map if needed
if(!m_reverseItems.load(std::memory_order_acquire)) {
Expand Down
2 changes: 2 additions & 0 deletions RecoEgamma/EgammaIsolationAlgos/interface/EgammaHadTower.h
Expand Up @@ -10,6 +10,7 @@
#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;

Expand Down Expand Up @@ -37,6 +38,7 @@ class EgammaHadTower {
const CaloTowerCollection * towerCollection_;
unsigned int NMaxClusters_;
const HcalChannelQuality * hcalQuality_;
const HcalTopology * hcalTopology_;
};

bool ClusterGreaterThan(const reco::CaloClusterPtr& c1, const reco::CaloClusterPtr& c2) ;
Expand Down
51 changes: 40 additions & 11 deletions RecoEgamma/EgammaIsolationAlgos/src/EgammaHadTower.cc
Expand Up @@ -9,10 +9,14 @@
#include "CondFormats/DataRecord/interface/HcalChannelQualityRcd.h"
#include "DataFormats/HcalDetId/interface/HcalDetId.h"

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

#include <algorithm>
#include <iostream>

//#define EDM_ML_DEBUG

EgammaHadTower::EgammaHadTower(const edm::EventSetup &es,HoeMode mode):mode_(mode) {
edm::ESHandle<CaloTowerConstituentsMap> ctmaph;
es.get<CaloGeometryRecord>().get(ctmaph);
Expand All @@ -22,6 +26,11 @@ EgammaHadTower::EgammaHadTower(const edm::EventSetup &es,HoeMode mode):mode_(mod
edm::ESHandle<HcalChannelQuality> hQuality;
es.get<HcalChannelQualityRcd>().get("withTopo",hQuality);
hcalQuality_ = hQuality.product();

edm::ESHandle<HcalTopology> hcalTopology;
es.get<HcalRecNumberingRecord>().get( hcalTopology );
hcalTopology_ = hcalTopology.product();

}

CaloTowerDetId EgammaHadTower::towerOf(const reco::CaloCluster& cluster) const {
Expand Down Expand Up @@ -62,6 +71,9 @@ std::vector<CaloTowerDetId> EgammaHadTower::towersOf(const reco::SuperCluster&
for ( unsigned iclus =0 ; iclus <nclusters && iclus < NMaxClusters_; ++iclus) {
// Get the tower
CaloTowerDetId id = towerOf(*(orderedClusters[iclus]));
#ifdef EDM_ML_DEBUG
std:: cout << "CaloTowerId " << id << std::endl;
#endif
std::vector<CaloTowerDetId>::const_iterator itcheck=find(towers.begin(),towers.end(),id);
if( itcheck == towers.end() ) {
towers.push_back(id);
Expand Down Expand Up @@ -111,33 +123,50 @@ double EgammaHadTower::getDepth2HcalESum(const std::vector<CaloTowerDetId> & tow
}

bool EgammaHadTower::hasActiveHcal( const std::vector<CaloTowerDetId> & towers ) const {
bool debug = false; // change this to true to get debug output

bool active = false;
int statusMask = ((1<<HcalChannelStatus::HcalCellOff) | (1<<HcalChannelStatus::HcalCellMask) | (1<<HcalChannelStatus::HcalCellDead));
if (debug) std::cout << "DEBUG: hasActiveHcal called with " << towers.size() << " detids. First tower detid ieta " << towers.front().ieta() << " iphi " << towers.front().iphi() << std::endl;
#ifdef EDM_ML_DEBUG
std::cout << "DEBUG: hasActiveHcal called with " << towers.size()
<< " detids. First tower detid ieta " << towers.front().ieta()
<< " iphi " << towers.front().iphi() << std::endl;
#endif
for (auto towerid : towers) {
unsigned int ngood = 0, nbad = 0;
for (DetId id : towerMap_->constituentsOf(towerid)) {
if (id.det() != DetId::Hcal) {
continue;
}
HcalDetId hid(id);
if (debug) std::cout << " hcal constituent on subdet " << hid.subdet() << ", ieta " << hid.ieta() << " iphi " << hid.iphi() << ", depth " << hid.depth() << std::endl;
if (hid.subdet() != HcalBarrel && hid.subdet() != HcalEndcap) continue;
const auto * values = hcalQuality_->getValues(id,/*throwOnFail=*/false);
if (!values) {
if (debug) std::cout << " MISSING IN CONDITIONS" << std::endl;
continue;
}
int status = values->getValue();
#ifdef EDM_ML_DEBUG
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
// Sunanda's fix for 2017 Plan1
// and removed protection
int status = hcalQuality_->getValues((DetId)(hcalTopology_->idFront(HcalDetId(id))),/*throwOnFail=*/true)->getValue();

#ifdef EDM_ML_DEBUG
std::cout << "channels status = " << std::hex << status << std::dec
<< " int value = " << status << std::endl;
#endif

if (status & statusMask) {
if (debug) std::cout << " BAD!" << std::endl;
#ifdef EDM_ML_DEBUG
std::cout << " BAD!" << std::endl;
#endif
nbad++;
} else {
ngood++;
}
}
if (debug) std::cout << " overall ngood " << ngood << " nbad " << nbad << std::endl;
#ifdef EDM_ML_DEBUG
std::cout << " overall ngood " << ngood << " nbad " << nbad << "\n";
#endif
if (nbad == 0 || (ngood > 0 && nbad < ngood)) {
active = true;
}
Expand Down
21 changes: 14 additions & 7 deletions RecoLocalCalo/CaloTowersCreator/src/CaloTowersCreator.cc
Expand Up @@ -8,6 +8,7 @@
#include "RecoLocalCalo/EcalRecAlgos/interface/EcalSeverityLevelAlgoRcd.h"
#include "CommonTools/Utils/interface/StringToEnumValue.h"

//#define EDM_ML_DEBUG

CaloTowersCreator::CaloTowersCreator(const edm::ParameterSet& conf) :
algo_(conf.getParameter<double>("EBThreshold"),
Expand Down Expand Up @@ -126,13 +127,13 @@ CaloTowersCreator::CaloTowersCreator(const edm::ParameterSet& conf) :
if (eScales_.instanceLabel.empty()) produces<CaloTowerCollection>();
else produces<CaloTowerCollection>(eScales_.instanceLabel);

/*
#ifdef EDM_ML_DEBUG
std::cout << "VI Producer "
<< (useRejectedHitsOnly_ ? "use rejectOnly " : " ")
<< (allowMissingInputs_ ? "allowMissing " : " " )
<< nLabels << ' ' << severitynames.size()
<< std::endl;
*/
#endif
}

void CaloTowersCreator::produce(edm::Event& e, const edm::EventSetup& c) {
Expand Down Expand Up @@ -200,7 +201,7 @@ void CaloTowersCreator::produce(edm::Event& e, const edm::EventSetup& c) {
algo_.setUseRejectedRecoveredHcalHits(useRejectedRecoveredHcalHits_);
algo_.setUseRejectedRecoveredEcalHits(useRejectedRecoveredEcalHits_);

/*
#ifdef EDM_ML_DEBUG
std::cout << "VI Produce: "
<< (useRejectedHitsOnly_ ? "use rejectOnly " : " ")
<< (allowMissingInputs_ ? "allowMissing " : " " )
Expand All @@ -209,7 +210,7 @@ void CaloTowersCreator::produce(edm::Event& e, const edm::EventSetup& c) {
<< ' ' << theEcalSeveritiesToBeExcluded_.size()
<< ' ' << theEcalSeveritiesToBeUsedInBadTowers_.size()
<< std::endl;
*/
#endif

algo_.begin(); // clear the internal buffer

Expand Down Expand Up @@ -284,12 +285,18 @@ void CaloTowersCreator::produce(edm::Event& e, const edm::EventSetup& c) {
// Step C: Process
algo_.finish(*prod);

/*
#ifdef EDM_ML_DEBUG
int totc=0; float totE=0;
reco::LeafCandidate::LorentzVector totP4;
for (auto const & tw : (*prod) ) { totc += tw.constituents().size(); totE+=tw.energy(); totP4+=tw.p4();}
for (auto const & tw : (*prod) ) {
totc += tw.constituents().size();
totE+=tw.energy();
totP4+=tw.p4();
std::cout << "CaloTowerCreator: " << tw.id() << " with E " << tw.energy()
<< " and " << tw.constituents().size() << " constituents\n";
}
std::cout << "VI " << (*prod).size() << " " << totc << " " << totE << " " << totP4 << std::endl;
*/
#endif

// Step D: Put into the event
if (eScales_.instanceLabel.empty()) e.put(std::move(prod));
Expand Down

0 comments on commit 425a3c0

Please sign in to comment.