CMS 3D CMS Logo

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