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 }
35 
37  DetId detid = cluster.seed();
38  if(detid.det() != DetId::Ecal) {
39  // Basic clusters of hybrid super-cluster do not have the seed set; take the first DetId instead
40  // Should be checked . The single Tower Mode should be favoured until fixed
41  detid = cluster.hitsAndFractions()[0].first;
42  if(detid.det() != DetId::Ecal) {
43  CaloTowerDetId tower;
44  return tower;
45  }
46  }
48  return id;
49 }
50 
51 std::vector<CaloTowerDetId> EgammaHadTower::towersOf(const reco::SuperCluster& sc) const {
52  std::vector<CaloTowerDetId> towers;
53  std::vector<reco::CaloClusterPtr> orderedClusters;
54 
55  // in this mode, check only the tower behind the seed
56  if ( mode_ == SingleTower ) {
57  towers.push_back(towerOf(*sc.seed()));
58  }
59 
60  // in this mode check the towers behind each basic cluster
61  if ( mode_ == TowersBehindCluster ) {
62  // Loop on the basic clusters
65 
66  for ( ; it !=itend; ++it) {
67  orderedClusters.push_back(*it);
68  }
69  std::sort(orderedClusters.begin(),orderedClusters.end(),ClusterGreaterThan);
70  unsigned nclusters=orderedClusters.size();
71  for ( unsigned iclus =0 ; iclus <nclusters && iclus < NMaxClusters_; ++iclus) {
72  // Get the tower
73  CaloTowerDetId id = towerOf(*(orderedClusters[iclus]));
74 #ifdef EDM_ML_DEBUG
75  std:: cout << "CaloTowerId " << id << std::endl;
76 #endif
77  std::vector<CaloTowerDetId>::const_iterator itcheck=find(towers.begin(),towers.end(),id);
78  if( itcheck == towers.end() ) {
79  towers.push_back(id);
80  }
81  }
82  }
83 // if(towers.size() > 4) {
84 // std::cout << " NTOWERS " << towers.size() << " ";
85 // for(unsigned i=0; i<towers.size() ; ++i) {
86 // std::cout << towers[i] << " ";
87 // }
88 // std::cout << std::endl;
89 // for ( unsigned iclus=0 ; iclus < orderedClusters.size(); ++iclus) {
90 // // Get the tower
91 // CaloTowerDetId id = towerOf(*(orderedClusters[iclus]));
92 // std::cout << " Pos " << orderedClusters[iclus]->position() << " " << orderedClusters[iclus]->energy() << " " << id ;
93 // }
94 // std::cout << std::endl;
95 // }
96  return towers;
97 }
98 
99 double EgammaHadTower::getDepth1HcalESum(const std::vector<CaloTowerDetId> & towers) const {
100  double esum=0.;
103  for( ; trItr != trItrEnd ; ++trItr){
104  std::vector<CaloTowerDetId>::const_iterator itcheck = find(towers.begin(), towers.end(), trItr->id());
105  if( itcheck != towers.end() ) {
106  esum += trItr->ietaAbs()<18 || trItr->ietaAbs()>29 ? trItr->hadEnergy() : trItr->hadEnergyHeInnerLayer() ;
107  }
108  }
109  return esum;
110 }
111 
112 double EgammaHadTower::getDepth2HcalESum(const std::vector<CaloTowerDetId> & towers) const {
113  double esum=0.;
116  for( ; trItr != trItrEnd ; ++trItr){
117  std::vector<CaloTowerDetId>::const_iterator itcheck = find(towers.begin(), towers.end(), trItr->id());
118  if( itcheck != towers.end() ) {
119  esum += trItr->hadEnergyHeOuterLayer();
120  }
121  }
122  return esum;
123 }
124 
125 bool EgammaHadTower::hasActiveHcal( const std::vector<CaloTowerDetId> & towers ) const {
126 
127  bool active = false;
129 #ifdef EDM_ML_DEBUG
130  std::cout << "DEBUG: hasActiveHcal called with " << towers.size()
131  << " detids. First tower detid ieta " << towers.front().ieta()
132  << " iphi " << towers.front().iphi() << std::endl;
133 #endif
134  for (auto towerid : towers) {
135  unsigned int ngood = 0, nbad = 0;
136  for (DetId id : towerMap_->constituentsOf(towerid)) {
137  if (id.det() != DetId::Hcal) {
138  continue;
139  }
140  HcalDetId hid(id);
141  if (hid.subdet() != HcalBarrel && hid.subdet() != HcalEndcap) continue;
142 #ifdef EDM_ML_DEBUG
143  std::cout << "EgammaHadTower DetId " << std::hex << id.rawId()
144  << " hid.rawId " << hid.rawId() << std::dec
145  << " sub " << hid.subdet() << " ieta " << hid.ieta()
146  << " iphi " << hid.iphi()
147  << " depth " << hid.depth() << std::endl;
148 #endif
149  // Sunanda's fix for 2017 Plan1
150  // and removed protection
151  int status = hcalQuality_->getValues((DetId)(hcalTopology_->idFront(HcalDetId(id))),/*throwOnFail=*/true)->getValue();
152 
153 #ifdef EDM_ML_DEBUG
154  std::cout << "channels status = " << std::hex << status << std::dec
155  << " int value = " << status << std::endl;
156 #endif
157 
158  if (status & statusMask) {
159 #ifdef EDM_ML_DEBUG
160  std::cout << " BAD!" << std::endl;
161 #endif
162  nbad++;
163  } else {
164  ngood++;
165  }
166  }
167 #ifdef EDM_ML_DEBUG
168  std::cout << " overall ngood " << ngood << " nbad " << nbad << "\n";
169 #endif
170  if (nbad == 0 || (ngood > 0 && nbad < ngood)) {
171  active = true;
172  }
173  }
174  return active;
175 }
176 
178  return getDepth1HcalESum(towersOf(sc)) ;
179 }
180 
182  return getDepth2HcalESum(towersOf(sc)) ;
183 }
184 
186  towerCollection_ = towerCollection;
187 }
188 
190  return hasActiveHcal(towersOf(sc)) ;
191 }
192 
194  return (*c1 > *c2);
195 }
const CaloTowerCollection * towerCollection_
const HcalTopology * hcalTopology_
HcalSubdetector subdet() const
get the subdetector
Definition: HcalDetId.h:146
const HcalChannelQuality * hcalQuality_
CaloTowerDetId towerOf(const reco::CaloCluster &cluster) const
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:50
std::vector< CaloTower >::const_iterator const_iterator
const std::vector< std::pair< DetId, float > > & hitsAndFractions() const
Definition: CaloCluster.h:197
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:20
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:166
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:159
bool ClusterGreaterThan(const reco::CaloClusterPtr &c1, const reco::CaloClusterPtr &c2)
const_iterator end() const
int iphi() const
get the cell iphi
Definition: HcalDetId.h:161
const CaloTowerConstituentsMap * towerMap_
Definition: DetId.h:18
DetId seed() const
return DetId of seed
Definition: CaloCluster.h:207
std::vector< CaloTowerDetId > towersOf(const reco::SuperCluster &sc) const
double getDepth2HcalESum(const reco::SuperCluster &sc) const
T get() const
Definition: EventSetup.h:71
CaloCluster_iterator clustersBegin() const
fist iterator over BasicCluster constituents
Definition: SuperCluster.h:75
unsigned int NMaxClusters_
HcalDetId idFront(const HcalDetId &id) const
Definition: HcalTopology.h:177
const CaloClusterPtr & seed() const
seed BasicCluster
Definition: SuperCluster.h:66
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:78
constexpr Detector det() const
get the detector field from this detid
Definition: DetId.h:39