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
64 
65  for (; it != itend; ++it) {
66  orderedClusters.push_back(*it);
67  }
68  std::sort(orderedClusters.begin(), orderedClusters.end(), ClusterGreaterThan);
69  unsigned nclusters = orderedClusters.size();
70  for (unsigned iclus = 0; iclus < nclusters && iclus < NMaxClusters_; ++iclus) {
71  // Get the tower
72  CaloTowerDetId id = towerOf(*(orderedClusters[iclus]));
73 #ifdef EDM_ML_DEBUG
74  std::cout << "CaloTowerId " << id << std::endl;
75 #endif
76  std::vector<CaloTowerDetId>::const_iterator itcheck = find(towers.begin(), towers.end(), id);
77  if (itcheck == towers.end()) {
78  towers.push_back(id);
79  }
80  }
81  }
82  // if(towers.size() > 4) {
83  // std::cout << " NTOWERS " << towers.size() << " ";
84  // for(unsigned i=0; i<towers.size() ; ++i) {
85  // std::cout << towers[i] << " ";
86  // }
87  // std::cout << std::endl;
88  // for ( unsigned iclus=0 ; iclus < orderedClusters.size(); ++iclus) {
89  // // Get the tower
90  // CaloTowerDetId id = towerOf(*(orderedClusters[iclus]));
91  // std::cout << " Pos " << orderedClusters[iclus]->position() << " " << orderedClusters[iclus]->energy() << " " << id ;
92  // }
93  // std::cout << std::endl;
94  // }
95  return towers;
96 }
97 
98 double EgammaHadTower::getDepth1HcalESum(const std::vector<CaloTowerDetId>& towers) const {
99  double esum = 0.;
102  for (; trItr != trItrEnd; ++trItr) {
103  std::vector<CaloTowerDetId>::const_iterator itcheck = find(towers.begin(), towers.end(), trItr->id());
104  if (itcheck != towers.end()) {
105  esum += trItr->ietaAbs() < 18 || trItr->ietaAbs() > 29 ? trItr->hadEnergy() : trItr->hadEnergyHeInnerLayer();
106  }
107  }
108  return esum;
109 }
110 
111 double EgammaHadTower::getDepth2HcalESum(const std::vector<CaloTowerDetId>& towers) const {
112  double esum = 0.;
115  for (; trItr != trItrEnd; ++trItr) {
116  std::vector<CaloTowerDetId>::const_iterator itcheck = find(towers.begin(), towers.end(), trItr->id());
117  if (itcheck != towers.end()) {
118  esum += trItr->hadEnergyHeOuterLayer();
119  }
120  }
121  return esum;
122 }
123 
124 bool EgammaHadTower::hasActiveHcal(const std::vector<CaloTowerDetId>& towers) const {
125  bool active = false;
126  int statusMask = ((1 << HcalChannelStatus::HcalCellOff) | (1 << HcalChannelStatus::HcalCellMask) |
128 #ifdef EDM_ML_DEBUG
129  std::cout << "DEBUG: hasActiveHcal called with " << towers.size() << " detids. First tower detid ieta "
130  << towers.front().ieta() << " iphi " << towers.front().iphi() << std::endl;
131 #endif
132  for (auto towerid : towers) {
133  unsigned int ngood = 0, nbad = 0;
134  for (DetId id : towerMap_->constituentsOf(towerid)) {
135  if (id.det() != DetId::Hcal) {
136  continue;
137  }
138  HcalDetId hid(id);
139  if (hid.subdet() != HcalBarrel && hid.subdet() != HcalEndcap)
140  continue;
141 #ifdef EDM_ML_DEBUG
142  std::cout << "EgammaHadTower DetId " << std::hex << id.rawId() << " hid.rawId " << hid.rawId() << std::dec
143  << " sub " << hid.subdet() << " ieta " << hid.ieta() << " iphi " << hid.iphi() << " depth "
144  << hid.depth() << std::endl;
145 #endif
146  // Sunanda's fix for 2017 Plan1
147  // and removed protection
148  int status =
149  hcalQuality_->getValues((DetId)(hcalTopology_->idFront(HcalDetId(id))), /*throwOnFail=*/true)->getValue();
150 
151 #ifdef EDM_ML_DEBUG
152  std::cout << "channels status = " << std::hex << status << std::dec << " int value = " << status << std::endl;
153 #endif
154 
155  if (status & statusMask) {
156 #ifdef EDM_ML_DEBUG
157  std::cout << " BAD!" << std::endl;
158 #endif
159  nbad++;
160  } else {
161  ngood++;
162  }
163  }
164 #ifdef EDM_ML_DEBUG
165  std::cout << " overall ngood " << ngood << " nbad " << nbad << "\n";
166 #endif
167  if (nbad == 0 || (ngood > 0 && nbad < ngood)) {
168  active = true;
169  }
170  }
171  return active;
172 }
173 
175 
177 
180 }
181 
183 
184 bool ClusterGreaterThan(const reco::CaloClusterPtr& c1, const reco::CaloClusterPtr& c2) { return (*c1 > *c2); }
const CaloTowerCollection * towerCollection_
const HcalTopology * hcalTopology_
HcalSubdetector subdet() const
get the subdetector
Definition: HcalDetId.h:138
const HcalChannelQuality * hcalQuality_
CaloTowerDetId towerOf(const reco::CaloCluster &cluster) const
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
std::vector< CaloTower >::const_iterator const_iterator
const Item * getValues(DetId fId, bool throwOnFail=true) const
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
bool hasActiveHcal(const reco::SuperCluster &sc) const
std::vector< DetId > constituentsOf(const CaloTowerDetId &id) const
Get the constituent detids for this tower id ( not yet implemented )
void setTowerCollection(const CaloTowerCollection *towercollection)
int depth() const
get the tower depth
Definition: HcalDetId.h:164
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)
double getDepth1HcalESum(const reco::SuperCluster &sc) const
int ieta() const
get the cell ieta
Definition: HcalDetId.h:155
bool ClusterGreaterThan(const reco::CaloClusterPtr &c1, const reco::CaloClusterPtr &c2)
const_iterator end() const
int iphi() const
get the cell iphi
Definition: HcalDetId.h:157
const CaloTowerConstituentsMap * towerMap_
Definition: DetId.h:17
DetId seed() const
return DetId of seed
Definition: CaloCluster.h:218
std::vector< CaloTowerDetId > towersOf(const reco::SuperCluster &sc) const
double getDepth2HcalESum(const reco::SuperCluster &sc) const
T get() const
Definition: EventSetup.h:73
CaloCluster_iterator clustersBegin() const
fist iterator over BasicCluster constituents
Definition: SuperCluster.h:86
unsigned int NMaxClusters_
HcalDetId idFront(const HcalDetId &id) const
Definition: HcalTopology.h:170
const CaloClusterPtr & seed() const
seed BasicCluster
Definition: SuperCluster.h:77
uint32_t getValue() const
T const * product() const
Definition: ESHandle.h:86
EgammaHadTower(const edm::EventSetup &es, HoeMode mode=SingleTower)
const_iterator begin() const
CaloCluster_iterator clustersEnd() const
last iterator over BasicCluster constituents
Definition: SuperCluster.h:89
constexpr Detector det() const
get the detector field from this detid
Definition: DetId.h:46