Skip to content

Commit e76ebb0

Browse files
committed
account for bad ecal hits not in db
1 parent bea4fba commit e76ebb0

File tree

3 files changed

+106
-41
lines changed

3 files changed

+106
-41
lines changed

RecoLocalCalo/CaloTowersCreator/interface/CaloTowersCreationAlgo.h

+6-1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
// need if we want to store the handles
2525
#include "FWCore/Framework/interface/ESHandle.h"
26+
#include <tuple>
2627

2728

2829
#include <map>
@@ -46,6 +47,9 @@ class DetId;
4647

4748
class CaloTowersCreationAlgo {
4849
public:
50+
51+
int nalgo=-1;
52+
4953
CaloTowersCreationAlgo();
5054

5155
CaloTowersCreationAlgo(double EBthreshold, double EEthreshold,
@@ -141,7 +145,8 @@ class CaloTowersCreationAlgo {
141145
// Called in assignHit to check if the energy should be added to
142146
// calotower, and how to flag the channel
143147
unsigned int hcalChanStatusForCaloTower(const CaloRecHit* hit);
144-
unsigned int ecalChanStatusForCaloTower(const CaloRecHit* hit);
148+
149+
std::tuple<unsigned int,bool> ecalChanStatusForCaloTower(const CaloRecHit* hit);
145150

146151
// Channel flagging is based on acceptable severity levels specified in the
147152
// configuration file. These methods are used to pass the values read in

RecoLocalCalo/CaloTowersCreator/src/CaloTowersCreationAlgo.cc

+82-37
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,9 @@ CaloTowersCreationAlgo::CaloTowersCreationAlgo(double EBthreshold, double EEthre
235235
theMomEEDepth(momEEDepth)
236236

237237
{
238+
// static int N = 0;
239+
// std::cout << "VI Algo " << ++N << std::endl;
240+
// nalgo=N;
238241
}
239242

240243

@@ -292,6 +295,9 @@ void CaloTowersCreationAlgo::finish(CaloTowerCollection& result) {
292295
// now copy this map into the final collection
293296
result.reserve(theTowerMapSize);
294297
// auto k=0U;
298+
// if (!theEbHandle.isValid()) std::cout << "VI ebHandle not valid" << std::endl;
299+
// if (!theEeHandle.isValid()) std::cout << "VI eeHandle not valid" << std::endl;
300+
295301
for(auto const & mt : theTowerMap ) {
296302
// Convert only if there is at least one constituent in the metatower.
297303
// The check of constituents size in the coverted tower is still needed!
@@ -412,9 +418,12 @@ void CaloTowersCreationAlgo::rescaleTowers(const CaloTowerCollection& ctc, CaloT
412418
void CaloTowersCreationAlgo::assignHit(const CaloRecHit * recHit) {
413419
DetId detId = recHit->detid();
414420

415-
unsigned int chStatusForCT = (detId.det()==DetId::Hcal)?
416-
hcalChanStatusForCaloTower(recHit) :
417-
ecalChanStatusForCaloTower(recHit);
421+
unsigned int chStatusForCT;
422+
bool ecalIsBad=false;
423+
if (detId.det()==DetId::Hcal)
424+
chStatusForCT = hcalChanStatusForCaloTower(recHit);
425+
else
426+
std::tie(chStatusForCT,ecalIsBad) = ecalChanStatusForCaloTower(recHit);
418427

419428
// this is for skipping channls: mostly needed for the creation of
420429
// bad towers from hits i the bad channel collections.
@@ -523,12 +532,30 @@ void CaloTowersCreationAlgo::assignHit(const CaloRecHit * recHit) {
523532
else passEmThreshold = (energy >= threshold);
524533
}
525534

535+
CaloTowerDetId towerDetId = theTowerConstituentsMap->towerOf(detId);
536+
if (towerDetId.null()) return;
537+
MetaTower & tower = find(towerDetId);
538+
539+
540+
// count bad cells and avoid double counting with those from DB (Recovered are counted bad)
541+
542+
// somehow misses some
543+
// if ( (chStatusForCT == CaloTowersCreationAlgo::BadChan) & (!ecalIsBad) ) ++tower.numBadEcalCells;
544+
545+
// a bit slower...
546+
if ( chStatusForCT == CaloTowersCreationAlgo::BadChan ) {
547+
auto thisEcalSevLvl = theEcalSevLvlAlgo->severityLevel(detId);
548+
// check if the Ecal severity is ok to keep
549+
auto sevit = std::find(theEcalSeveritiesToBeExcluded.begin(),
550+
theEcalSeveritiesToBeExcluded.end(),
551+
thisEcalSevLvl);
552+
if (sevit==theEcalSeveritiesToBeExcluded.end()) ++tower.numBadEcalCells; // notinDB
553+
}
554+
526555

527556
// if (chStatusForCT != CaloTowersCreationAlgo::BadChan && energy >= threshold) {
528557
if (chStatusForCT != CaloTowersCreationAlgo::BadChan && passEmThreshold) {
529-
CaloTowerDetId towerDetId = theTowerConstituentsMap->towerOf(detId);
530-
if (towerDetId.null()) return;
531-
MetaTower & tower = find(towerDetId);
558+
532559
tower.E_em += e;
533560
tower.E += e;
534561

@@ -970,8 +997,8 @@ void CaloTowersCreationAlgo::convert(const CaloTowerDetId& id, const MetaTower&
970997

971998
// for ECAL the number of all bad channels is obtained here -----------------------
972999

973-
/* old hyper slow algorithm
974-
1000+
/*
1001+
// old hyper slow algorithm
9751002
// get all possible constituents of the tower
9761003
std::vector<DetId> allConstituents = theTowerConstituentsMap->constituentsOf(id);
9771004
@@ -1000,11 +1027,25 @@ void CaloTowersCreationAlgo::convert(const CaloTowerDetId& id, const MetaTower&
10001027
}
10011028
10021029
// compare with fast version
1003-
auto numBadEcalChanNew = ecalBadChs[id.denseIndex()];
1004-
if (numBadEcalChanNew!=numBadEcalChan) std::cout << "wrong " << id << " " << numBadEcalChanNew << " " << numBadEcalChan << " " << mt.numBadEcalCells << std::endl;
1005-
*/
1030+
1031+
// hcal:
1032+
int inEcals[2] = {0,0};
1033+
for (std::vector<std::pair<DetId,float> >::iterator i=metaContains.begin(); i!=metaContains.end(); ++i) {
1034+
DetId detId = i->first;
1035+
if(detId.det() == DetId::Ecal){
1036+
if( detId.subdetId()==EcalBarrel ) inEcals[0] =1;
1037+
else if( detId.subdetId()==EcalEndcap ) inEcals[1] =1;
1038+
}
1039+
}
10061040
1007-
numBadEcalChan = ecalBadChs[id.denseIndex()];
1041+
auto numBadEcalChanNew = ecalBadChs[id.denseIndex()]+mt.numBadEcalCells; // - mt.numRecEcalCells
1042+
if (int(numBadEcalChanNew)!=int(numBadEcalChan)) {
1043+
std::cout << "VI wrong " << ((inEcals[1]==1) ? "EE" : "" ) << id << " " << numBadEcalChanNew << " " << numBadEcalChan
1044+
<< " " << mt.numBadEcalCells << " " << mt.numRecEcalCells << std::endl;
1045+
}
1046+
*/
1047+
1048+
numBadEcalChan = ecalBadChs[id.denseIndex()]+mt.numBadEcalCells; // - mt.numRecEcalCells
10081049

10091050
//--------------------------------------------------------------------------------------
10101051

@@ -1043,7 +1084,8 @@ void CaloTowersCreationAlgo::convert(const CaloTowerDetId& id, const MetaTower&
10431084
caloTower.setConstituents(std::move(contains));
10441085
caloTower.setHottestCellE(maxCellE);
10451086

1046-
// std::cout << "CaloTowerVI " << caloTower.id() << ' ' << caloTower.pt() << ' ' << caloTower.et() << ' ' << caloTower.mass() << ' '<< caloTower.constituentsSize() <<' '<< caloTower.towerStatusWord() << std::endl;
1087+
// std::cout << "CaloTowerVI " << nalgo << ' ' << caloTower.id() << ((inEcals[1]==1) ? "EE " : " " ) << caloTower.pt() << ' ' << caloTower.et() << ' ' << caloTower.mass() << ' '
1088+
// << caloTower.constituentsSize() <<' '<< caloTower.towerStatusWord() << std::endl;
10471089

10481090
}
10491091

@@ -1447,6 +1489,8 @@ void CaloTowersCreationAlgo::makeHcalDropChMap() {
14471489

14481490
void CaloTowersCreationAlgo::makeEcalBadChs() {
14491491

1492+
// std::cout << "VI making EcalBadChs ";
1493+
14501494
// for ECAL the number of all bad channels is obtained here -----------------------
14511495

14521496
for (auto ind=0U; ind<CaloTowerDetId::kSizeForDenseIndexing; ++ind) {
@@ -1464,15 +1508,8 @@ void CaloTowersCreationAlgo::makeEcalBadChs() {
14641508
ac_it!=allConstituents.end(); ++ac_it) {
14651509

14661510
if (ac_it->det()!=DetId::Ecal) continue;
1467-
1468-
int thisEcalSevLvl = -999;
1469-
1470-
if (ac_it->subdetId() == EcalBarrel) {
1471-
thisEcalSevLvl = theEcalSevLvlAlgo->severityLevel( *ac_it);
1472-
}
1473-
else if (ac_it->subdetId() == EcalEndcap) {
1474-
thisEcalSevLvl = theEcalSevLvlAlgo->severityLevel( *ac_it);
1475-
}
1511+
1512+
auto thisEcalSevLvl = theEcalSevLvlAlgo->severityLevel( *ac_it);
14761513

14771514
// check if the Ecal severity is ok to keep
14781515
std::vector<int>::const_iterator sevit = std::find(theEcalSeveritiesToBeExcluded.begin(),
@@ -1482,7 +1519,18 @@ void CaloTowersCreationAlgo::makeEcalBadChs() {
14821519
++numBadEcalChan;
14831520
}
14841521
}
1485-
}
1522+
1523+
// if (0!=numBadEcalChan) std::cout << id << ":" << numBadEcalChan << ", ";
1524+
}
1525+
1526+
/*
1527+
int tot=0;
1528+
for (auto ind=0U; ind<CaloTowerDetId::kSizeForDenseIndexing; ++ind) {
1529+
if (ecalBadChs[ind]!=0) ++tot;
1530+
}
1531+
std::cout << " | " << tot << std::endl;
1532+
*/
1533+
14861534
}
14871535

14881536

@@ -1550,7 +1598,7 @@ unsigned int CaloTowersCreationAlgo::hcalChanStatusForCaloTower(const CaloRecHit
15501598

15511599

15521600

1553-
unsigned int CaloTowersCreationAlgo::ecalChanStatusForCaloTower(const CaloRecHit* hit) {
1601+
std::tuple<unsigned int,bool> CaloTowersCreationAlgo::ecalChanStatusForCaloTower(const CaloRecHit* hit) {
15541602

15551603
// const DetId id = hit->detid();
15561604

@@ -1580,6 +1628,7 @@ unsigned int CaloTowersCreationAlgo::ecalChanStatusForCaloTower(const CaloRecHit
15801628
// exclude problematic channels as defined by ECAL.
15811629
// For definitions of ECAL severity levels see RecoLocalCalo/EcalRecAlgos/interface/EcalSeverityLevelAlgo.h
15821630

1631+
bool isBad = (severityLevel == EcalSeverityLevel::kBad);
15831632

15841633
bool isRecovered = (severityLevel == EcalSeverityLevel::kRecovered);
15851634

@@ -1603,42 +1652,38 @@ unsigned int CaloTowersCreationAlgo::ecalChanStatusForCaloTower(const CaloRecHit
16031652
if (accepted ||
16041653
std::find(theEcalSeveritiesToBeUsedInBadTowers.begin(), theEcalSeveritiesToBeUsedInBadTowers.end(), severityLevel)
16051654
== theEcalSeveritiesToBeUsedInBadTowers.end())
1606-
return CaloTowersCreationAlgo::IgnoredChan;
1655+
return std::make_tuple(CaloTowersCreationAlgo::IgnoredChan,isBad);
16071656
// this hit was either already accepted, or is not eligible for inclusion
16081657
}
16091658
else {
16101659

16111660
if (theRecoveredEcalHitsAreUsed || !useRejectedRecoveredEcalHits) {
16121661
// skip recovered hits either because they were already used or because there was an explicit instruction
1613-
return CaloTowersCreationAlgo::IgnoredChan;
1662+
return std::make_tuple(CaloTowersCreationAlgo::IgnoredChan,isBad);;
16141663
}
16151664
else if (useRejectedRecoveredEcalHits) {
1616-
return CaloTowersCreationAlgo::RecoveredChan;
1665+
return std::make_tuple(CaloTowersCreationAlgo::RecoveredChan,isBad);
16171666
}
16181667

16191668
} // recovered channels
16201669

16211670
// clasify channels as problematic
1622-
return CaloTowersCreationAlgo::ProblematicChan;
1671+
return std::make_tuple(CaloTowersCreationAlgo::ProblematicChan,isBad);
16231672

16241673
} // treatment of rejected hits
16251674

16261675

16271676

16281677
// for normal reconstruction
1629-
if (severityLevel == EcalSeverityLevel::kGood) return CaloTowersCreationAlgo::GoodChan;
1678+
if (severityLevel == EcalSeverityLevel::kGood) return std::make_tuple(CaloTowersCreationAlgo::GoodChan,false);
16301679

16311680
if (isRecovered) {
1632-
return (theRecoveredEcalHitsAreUsed) ?
1633-
CaloTowersCreationAlgo::RecoveredChan : CaloTowersCreationAlgo::BadChan;
1681+
return std::make_tuple( (theRecoveredEcalHitsAreUsed) ?
1682+
CaloTowersCreationAlgo::RecoveredChan : CaloTowersCreationAlgo::BadChan, true);
16341683
}
16351684
else {
1636-
if (!accepted) {
1637-
return CaloTowersCreationAlgo::BadChan;
1638-
}
1639-
else {
1640-
return CaloTowersCreationAlgo::ProblematicChan;
1641-
}
1685+
return std::make_tuple(accepted ? CaloTowersCreationAlgo::ProblematicChan : CaloTowersCreationAlgo::BadChan,isBad);
1686+
16421687
}
16431688

16441689

RecoLocalCalo/CaloTowersCreator/src/CaloTowersCreator.cc

+18-3
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,14 @@ CaloTowersCreator::CaloTowersCreator(const edm::ParameterSet& conf) :
139139

140140
if (EScales.instanceLabel=="") produces<CaloTowerCollection>();
141141
else produces<CaloTowerCollection>(EScales.instanceLabel);
142+
143+
/*
144+
std::cout << "VI Producer "
145+
<< (useRejectedHitsOnly_ ? "use rejectOnly " : " ")
146+
<< (allowMissingInputs_ ? "allowMissing " : " " )
147+
<< nLabels << ' ' << severitynames.size()
148+
<< std::endl;
149+
*/
142150
}
143151

144152
void CaloTowersCreator::produce(edm::Event& e, const edm::EventSetup& c) {
@@ -205,9 +213,16 @@ void CaloTowersCreator::produce(edm::Event& e, const edm::EventSetup& c) {
205213
algo_.setUseRejectedRecoveredHcalHits(useRejectedRecoveredHcalHits_);
206214
algo_.setUseRejectedRecoveredEcalHits(useRejectedRecoveredEcalHits_);
207215

208-
209-
210-
216+
/*
217+
std::cout << "VI Produce: "
218+
<< (useRejectedHitsOnly_ ? "use rejectOnly " : " ")
219+
<< (allowMissingInputs_ ? "allowMissing " : " " )
220+
<< (theRecoveredEcalHitsAreUsed_ ? "use RecoveredEcal ": " " )
221+
<< toks_ecal_.size()
222+
<< ' ' << theEcalSeveritiesToBeExcluded_.size()
223+
<< ' ' << theEcalSeveritiesToBeUsedInBadTowers_.size()
224+
<< std::endl;
225+
*/
211226

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

0 commit comments

Comments
 (0)