CMS 3D CMS Logo

HGCalTowerMap.cc
Go to the documentation of this file.
5 
6 using namespace l1t;
7 
14 
15 
17 {
18 
21 
22  double eta_step = (kEtaMax_ - kEtaMin_)/nEtaBins_;
23  for(int i=0; i<nEtaBins_; i++) etaBins_.emplace_back( kEtaMin_ + eta_step*i );
24  etaBins_.emplace_back( kEtaMax_ );
25 
26  double phi_step = (kPhiMax_ - kPhiMin_)/nPhiBins_;
27  for(int i=0; i<nPhiBins_; i++) phiBins_.emplace_back( kPhiMin_ + phi_step*i );
28  phiBins_.emplace_back( kPhiMax_ );
29 
30 
31  for(int iEta=-nEtaBins_; iEta<=nEtaBins_; iEta++){
32  if(iEta==0) continue;
33  for(int iPhi=0; iPhi<nPhiBins_; iPhi++){
35  tower.setHwEta(iEta);
36  tower.setHwPhi(iPhi);
37  int bin = bin_id(iEta,iPhi);
38  towerMap_[bin] = tower;
39  }
40  }
41 
42 
43 }
44 
45 
46 HGCalTowerMap::HGCalTowerMap( const vector<double>& etaBins, const vector<double>& phiBins )
47 {
48 
49  nEtaBins_ = etaBins.size()-1;
50  nPhiBins_ = phiBins.size()-1;
51  etaBins_ = etaBins;
52  phiBins_ = phiBins;
53 
54  for(int iEta=-nEtaBins_; iEta<=nEtaBins_; iEta++){
55  if(iEta==0) continue;
56  for(int iPhi=0; iPhi<nPhiBins_; iPhi++){
58  tower.setHwEta(iEta);
59  tower.setHwPhi(iPhi);
60  int bin = bin_id(iEta,iPhi);
61  towerMap_[bin] = tower;
62  }
63  }
64 
65 }
66 
67 
69 {
70 
71 }
72 
73 
74 int HGCalTowerMap::iEta(const double eta) const
75 {
76 
77  double absEta = fabs(eta);
78  int signEta = eta>0 ? 1 : -1;
79 
80  if(absEta<kEtaMin_){
81  absEta = kEtaMin_;
82  if(absEta<kEtaMinLoose_) edm::LogWarning("HGCalTowerMap") << "WARNING: trying to access towers below min eta range of tower maps eta="<<eta;
83  return signEta;
84  }
85  else if(absEta>kEtaMax_){
86  absEta = kEtaMax_;
87  if(absEta>kEtaMaxLoose_) edm::LogWarning("HGCalTowerMap") << "WARNING: trying to access towers above max eta range of tower maps eta="<<eta;
88  return signEta*nEtaBins_;
89  }
90 
91  for(int i = 0; i<nEtaBins_; i++){
92  if(absEta>=etaBins_[i] && absEta<etaBins_[i+1]){
93  return signEta*(i+1);
94  }
95  }
96 
97  return 0;
98 
99 }
100 
101 
102 int HGCalTowerMap::iPhi(const double phi) const
103 {
104 
105  double phi_norm = normalizedPhi(phi);
106 
107  for(int i = 0; i<nPhiBins_; i++){
108  if(phi_norm>=phiBins_[i] && phi_norm<phiBins_[i+1]){
109  return i;
110  }
111  }
112 
113  return -1;
114 
115 }
116 
117 
119 
120  if(etaBins_!=map.etaBins() || phiBins_!=map.phiBins()){
121  throw edm::Exception(edm::errors::StdException, "StdException")
122  << "HGCalTowerMap: Trying to add HGCalTowerMaps with different bins"<<endl;
123  }
124 
125  for(int iEta=-nEtaBins_; iEta<=nEtaBins_; iEta++){
126  if(iEta==0) continue;
127  for(int iPhi=0; iPhi<nPhiBins_; iPhi++){
128  towerMap_[bin_id(iEta,iPhi)] += map.tower(iEta,iPhi);
129  }
130  }
131 
132  return *this;
133 
134 }
135 
136 
137 
138 int HGCalTowerMap::bin_id(int iEta, int iPhi) const{
139 
140  if(iEta==0 || iEta>nEtaBins_ || iEta<-nEtaBins_){
141  throw edm::Exception(edm::errors::StdException, "StdException")
142  << "HGCalTowerMap: Trying to access a bin out of eta range"<<endl;
143  }
144 
145  if(iPhi<0 || iPhi>=nPhiBins_){
146  throw edm::Exception(edm::errors::StdException, "StdException")
147  << "HGCalTowerMap: Trying to access a bin out of phi range"<<endl;
148  }
149 
150  return iEta*nPhiBins_ + iPhi;
151 
152 }
153 
int iPhi(const double phi) const
vector< double > phiBins_
Definition: HGCalTowerMap.h:54
static double kEtaMin_
Definition: HGCalTowerMap.h:44
int nEtaBins() const
Definition: HGCalTowerMap.h:29
const vector< double > & etaBins() const
Definition: HGCalTowerMap.h:31
std::unordered_map< int, l1t::HGCalTower > towerMap_
Definition: HGCalTowerMap.h:55
static double kEtaMax_
Definition: HGCalTowerMap.h:45
delete x;
Definition: CaloConfig.h:22
T normalizedPhi(T phi)
Definition: normalizedPhi.h:9
int bin_id(int iEta, int iPhi) const
#define constexpr
int iEta(const double eta) const
static double kPhiMax_
Definition: HGCalTowerMap.h:49
static double kPhiMin_
Definition: HGCalTowerMap.h:48
const l1t::HGCalTower & tower(int iEta, int iPhi) const
Definition: HGCalTowerMap.h:33
int nPhiBins() const
Definition: HGCalTowerMap.h:30
bin
set the eta bin as selection string.
void setHwPhi(int phi)
Definition: L1Candidate.h:43
static double kEtaMinLoose_
Definition: HGCalTowerMap.h:46
vector< double > etaBins_
Definition: HGCalTowerMap.h:53
static double kEtaMaxLoose_
Definition: HGCalTowerMap.h:47
void setHwEta(int eta)
Definition: L1Candidate.h:42
HGCalTowerMap & operator+=(const HGCalTowerMap &map)
const vector< double > & phiBins() const
Definition: HGCalTowerMap.h:32