CMS 3D CMS Logo

EgammaHadTower.cc
Go to the documentation of this file.
11 
14 
15 #include <algorithm>
16 #include <iostream>
17 
18 //#define EDM_ML_DEBUG
19 
22  es.get<CaloGeometryRecord>().get(ctmaph);
23  towerMap_ = &(*ctmaph);
24  nMaxClusters_ = 4;
25 
27  es.get<HcalChannelQualityRcd>().get("withTopo", hQuality);
28  hcalQuality_ = hQuality.product();
29 
30  edm::ESHandle<HcalTopology> hcalTopology;
31  es.get<HcalRecNumberingRecord>().get(hcalTopology);
32  hcalTopology_ = hcalTopology.product();
33 }
34 
36  DetId detid = cluster.seed();
37  if (detid.det() != DetId::Ecal) {
38  // Basic clusters of hybrid super-cluster do not have the seed set; take the first DetId instead
39  // Should be checked . The single Tower Mode should be favoured until fixed
40  detid = cluster.hitsAndFractions()[0].first;
41  if (detid.det() != DetId::Ecal) {
43  return tower;
44  }
45  }
47  return id;
48 }
49 
50 std::vector<CaloTowerDetId> EgammaHadTower::towersOf(const reco::SuperCluster& sc) const {
51  std::vector<CaloTowerDetId> towers;
52  std::vector<reco::CaloClusterPtr> orderedClusters;
53 
54  // in this mode, check only the tower behind the seed
55  if (mode_ == SingleTower) {
56  towers.push_back(towerOf(*sc.seed()));
57  }
58 
59  // in this mode check the towers behind each basic cluster
60  if (mode_ == TowersBehindCluster) {
61  // Loop on the basic clusters
62  for (auto it = sc.clustersBegin(); it != sc.clustersEnd(); ++it) {
63  orderedClusters.push_back(*it);
64  }
65  std::sort(orderedClusters.begin(), orderedClusters.end(), [](auto& c1, auto& c2) { return (*c1 > *c2); });
66  unsigned nclusters = orderedClusters.size();
67  for (unsigned iclus = 0; iclus < nclusters && iclus < nMaxClusters_; ++iclus) {
68  // Get the tower
69  CaloTowerDetId id = towerOf(*(orderedClusters[iclus]));
70 #ifdef EDM_ML_DEBUG
71  std::cout << "CaloTowerId " << id << std::endl;
72 #endif
73  if (std::find(towers.begin(), towers.end(), id) == towers.end()) {
74  towers.push_back(id);
75  }
76  }
77  }
78  // if(towers.size() > 4) {
79  // std::cout << " NTOWERS " << towers.size() << " ";
80  // for(unsigned i=0; i<towers.size() ; ++i) {
81  // std::cout << towers[i] << " ";
82  // }
83  // std::cout << std::endl;
84  // for ( unsigned iclus=0 ; iclus < orderedClusters.size(); ++iclus) {
85  // // Get the tower
86  // CaloTowerDetId id = towerOf(*(orderedClusters[iclus]));
87  // std::cout << " Pos " << orderedClusters[iclus]->position() << " " << orderedClusters[iclus]->energy() << " " << id ;
88  // }
89  // std::cout << std::endl;
90  // }
91  return towers;
92 }
93 
94 double EgammaHadTower::getDepth1HcalESum(const std::vector<CaloTowerDetId>& towers,
95  CaloTowerCollection const& towerCollection) const {
96  double esum = 0.;
97  for (auto const& tower : towerCollection) {
98  if (std::find(towers.begin(), towers.end(), tower.id()) != towers.end()) {
99  esum += tower.ietaAbs() < 18 || tower.ietaAbs() > 29 ? tower.hadEnergy() : tower.hadEnergyHeInnerLayer();
100  }
101  }
102  return esum;
103 }
104 
105 double EgammaHadTower::getDepth2HcalESum(const std::vector<CaloTowerDetId>& towers,
106  CaloTowerCollection const& towerCollection) const {
107  double esum = 0.;
108  for (auto const& tower : towerCollection) {
109  if (std::find(towers.begin(), towers.end(), tower.id()) != towers.end()) {
110  esum += tower.hadEnergyHeOuterLayer();
111  }
112  }
113  return esum;
114 }
115 
116 bool EgammaHadTower::hasActiveHcal(const std::vector<CaloTowerDetId>& towers) const {
117  bool active = false;
118  int statusMask = ((1 << HcalChannelStatus::HcalCellOff) | (1 << HcalChannelStatus::HcalCellMask) |
120 #ifdef EDM_ML_DEBUG
121  std::cout << "DEBUG: hasActiveHcal called with " << towers.size() << " detids. First tower detid ieta "
122  << towers.front().ieta() << " iphi " << towers.front().iphi() << std::endl;
123 #endif
124  for (auto towerid : towers) {
125  unsigned int ngood = 0, nbad = 0;
126  for (DetId id : towerMap_->constituentsOf(towerid)) {
127  if (id.det() != DetId::Hcal) {
128  continue;
129  }
130  HcalDetId hid(id);
131  if (hid.subdet() != HcalBarrel && hid.subdet() != HcalEndcap)
132  continue;
133 #ifdef EDM_ML_DEBUG
134  std::cout << "EgammaHadTower DetId " << std::hex << id.rawId() << " hid.rawId " << hid.rawId() << std::dec
135  << " sub " << hid.subdet() << " ieta " << hid.ieta() << " iphi " << hid.iphi() << " depth "
136  << hid.depth() << std::endl;
137 #endif
138  // Sunanda's fix for 2017 Plan1
139  // and removed protection
140  int status =
141  hcalQuality_->getValues((DetId)(hcalTopology_->idFront(HcalDetId(id))), /*throwOnFail=*/true)->getValue();
142 
143 #ifdef EDM_ML_DEBUG
144  std::cout << "channels status = " << std::hex << status << std::dec << " int value = " << status << std::endl;
145 #endif
146 
147  if (status & statusMask) {
148 #ifdef EDM_ML_DEBUG
149  std::cout << " BAD!" << std::endl;
150 #endif
151  nbad++;
152  } else {
153  ngood++;
154  }
155  }
156 #ifdef EDM_ML_DEBUG
157  std::cout << " overall ngood " << ngood << " nbad " << nbad << "\n";
158 #endif
159  if (nbad == 0 || (ngood > 0 && nbad < ngood)) {
160  active = true;
161  }
162  }
163  return active;
164 }
edm::ESHandle::product
T const * product() const
Definition: ESHandle.h:86
EgammaHadTower::SingleTower
Definition: EgammaHadTower.h:19
HcalTopology::idFront
HcalDetId idFront(const HcalDetId &id) const
Definition: HcalTopology.h:170
EgammaHadTower::HoeMode
HoeMode
Definition: EgammaHadTower.h:19
ESHandle.h
EgammaHadTower::nMaxClusters_
unsigned int nMaxClusters_
Definition: EgammaHadTower.h:31
CaloTowerConstituentsMap::constituentsOf
std::vector< DetId > constituentsOf(const CaloTowerDetId &id) const
Get the constituent detids for this tower id ( not yet implemented )
Definition: CaloTowerConstituentsMap.cc:69
HcalDetId::iphi
constexpr int iphi() const
get the cell iphi
Definition: HcalDetId.h:157
reco::SuperCluster
Definition: SuperCluster.h:18
HcalChannelQualityRcd
Definition: HcalChannelQualityRcd.h:8
mps_update.status
status
Definition: mps_update.py:69
CaloGeometryRecord
Definition: CaloGeometryRecord.h:30
DetId::det
constexpr Detector det() const
get the detector field from this detid
Definition: DetId.h:46
gather_cfg.cout
cout
Definition: gather_cfg.py:144
DetId::Hcal
Definition: DetId.h:28
ALCARECOPromptCalibProdSiPixelAli0T_cff.mode
mode
Definition: ALCARECOPromptCalibProdSiPixelAli0T_cff.py:96
hgcalTowerProducer_cfi.tower
tower
Definition: hgcalTowerProducer_cfi.py:3
EgammaHadTower::EgammaHadTower
EgammaHadTower(const edm::EventSetup &es, HoeMode mode=SingleTower)
Definition: EgammaHadTower.cc:20
edm::SortedCollection< CaloTower >
HcalRecNumberingRecord.h
HcalDetId::depth
constexpr int depth() const
get the tower depth
Definition: HcalDetId.h:164
HcalBarrel
Definition: HcalAssistant.h:33
spr::find
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
EgammaHadTower::mode_
HoeMode mode_
Definition: EgammaHadTower.h:30
HcalChannelStatus::HcalCellMask
Definition: HcalChannelStatus.h:18
HcalCondObjectContainer::getValues
const Item * getValues(DetId fId, bool throwOnFail=true) const
Definition: HcalCondObjectContainer.h:159
EgammaHadTower.h
DetId
Definition: DetId.h:17
EgammaHadTower::hasActiveHcal
bool hasActiveHcal(const std::vector< CaloTowerDetId > &towers) const
Definition: EgammaHadTower.cc:116
HcalChannelStatus::HcalCellOff
Definition: HcalChannelStatus.h:17
EgammaHadTower::getDepth2HcalESum
double getDepth2HcalESum(const std::vector< CaloTowerDetId > &towers, CaloTowerCollection const &) const
Definition: EgammaHadTower.cc:105
edm::EventSetup::get
T get() const
Definition: EventSetup.h:73
EgammaHadTower::hcalQuality_
const HcalChannelQuality * hcalQuality_
Definition: EgammaHadTower.h:32
reco::CaloCluster
Definition: CaloCluster.h:31
edm::ESHandle< CaloTowerConstituentsMap >
HcalRecNumberingRecord
Definition: HcalRecNumberingRecord.h:23
CaloGeometryRecord.h
EcalSubdetector.h
HcalChannelStatus::getValue
uint32_t getValue() const
Definition: HcalChannelStatus.h:60
HcalDetId::ieta
constexpr int ieta() const
get the cell ieta
Definition: HcalDetId.h:155
reco::SuperCluster::seed
const CaloClusterPtr & seed() const
seed BasicCluster
Definition: SuperCluster.h:77
reco::CaloCluster::hitsAndFractions
const std::vector< std::pair< DetId, float > > & hitsAndFractions() const
Definition: CaloCluster.h:210
HcalDetId.h
CaloTopologyRecord.h
HcalDetId::subdet
constexpr HcalSubdetector subdet() const
get the subdetector
Definition: HcalDetId.h:138
HcalDetId
Definition: HcalDetId.h:12
alignmentValidation.c1
c1
do drawing
Definition: alignmentValidation.py:1025
reco::SuperCluster::clustersBegin
CaloCluster_iterator clustersBegin() const
fist iterator over BasicCluster constituents
Definition: SuperCluster.h:86
edm::EventSetup
Definition: EventSetup.h:57
CaloTowerConstituentsMap::towerOf
CaloTowerDetId towerOf(const DetId &id) const
Get the tower id for this det id (or null if not known)
Definition: CaloTowerConstituentsMap.cc:26
DetId::Ecal
Definition: DetId.h:27
HcalCondObjectContainer.h
get
#define get
HcalChannelStatus.h
reco::CaloCluster::seed
DetId seed() const
return DetId of seed
Definition: CaloCluster.h:219
HcalChannelQualityRcd.h
HcalChannelQuality.h
EgammaHadTower::towersOf
std::vector< CaloTowerDetId > towersOf(const reco::SuperCluster &sc) const
Definition: EgammaHadTower.cc:50
HLT_2018_cff.towers
towers
Definition: HLT_2018_cff.py:35030
DetId::rawId
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
HcalChannelStatus::HcalCellDead
Definition: HcalChannelStatus.h:20
HLT_2018_cff.towerCollection
towerCollection
Definition: HLT_2018_cff.py:17558
HcalEndcap
Definition: HcalAssistant.h:34
EgammaHadTower::towerMap_
const CaloTowerConstituentsMap * towerMap_
Definition: EgammaHadTower.h:29
triggerObjects_cff.id
id
Definition: triggerObjects_cff.py:31
EgammaHadTower::getDepth1HcalESum
double getDepth1HcalESum(const std::vector< CaloTowerDetId > &towers, CaloTowerCollection const &) const
Definition: EgammaHadTower.cc:94
EgammaHadTower::TowersBehindCluster
Definition: EgammaHadTower.h:19
reco::SuperCluster::clustersEnd
CaloCluster_iterator clustersEnd() const
last iterator over BasicCluster constituents
Definition: SuperCluster.h:89
EgammaHadTower::hcalTopology_
const HcalTopology * hcalTopology_
Definition: EgammaHadTower.h:33
TauDecayModes.dec
dec
Definition: TauDecayModes.py:143
EgammaHadTower::towerOf
CaloTowerDetId towerOf(const reco::CaloCluster &cluster) const
Definition: EgammaHadTower.cc:35
CaloTowerDetId
Definition: CaloTowerDetId.h:12