test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
CaloTools.cc
Go to the documentation of this file.
2 
3 
5 
8 
9 const float l1t::CaloTools::kGTEtaLSB = 0.0435;
10 const float l1t::CaloTools::kGTPhiLSB = 0.0435;
11 const float l1t::CaloTools::kGTEtLSB = 0.5;
12 
13 const int l1t::CaloTools::cos_coeff[72] = {1023, 1019, 1007, 988, 961, 927, 886, 838, 784, 723, 658, 587, 512, 432, 350, 265, 178, 89, 0, -89, -178, -265, -350, -432, -512, -587, -658, -723, -784, -838, -886, -927, -961, -988, -1007, -1019, -1023, -1019, -1007, -988, -961, -927, -886, -838, -784, -723, -658, -587, -512, -432, -350, -265, -178, -89, 0, 89, 178, 265, 350, 432, 512, 587, 658, 723, 784, 838, 886, 927, 961, 988, 1007, 1019};
14 
15 const int l1t::CaloTools::sin_coeff[72] = {0, 89, 178, 265, 350, 432, 512, 587, 658, 723, 784, 838, 886, 927, 961, 988, 1007, 1019, 1023, 1019, 1007, 988, 961, 927, 886, 838, 784, 723, 658, 587, 512, 432, 350, 265, 178, 89, 0, -89, -178, -265, -350, -432, -512, -587, -658, -723, -784, -838, -886, -927, -961, -988, -1007, -1019, -1023, -1019, -1007, -988, -961, -927, -886, -838, -784, -723, -658, -587, -512, -432, -350, -265, -178, -89};
16 
17 
18 
19 bool l1t::CaloTools::insertTower(std::vector<l1t::CaloTower>& towers, const l1t::CaloTower& tower) {
20  size_t towerIndex = CaloTools::caloTowerHash(tower.hwEta(), tower.hwPhi());
21  if (towers.size() > towerIndex) {
22  towers.at(towerIndex) = tower;
23  return true;
24  }
25  else return false;
26 }
27 
28 //currently implemented as a brute force search but this will hopefully change in the future
29 //with standarising the layout of std::vector<l1t::CaloTower>
30 const l1t::CaloTower& l1t::CaloTools::getTower(const std::vector<l1t::CaloTower>& towers,int iEta,int iPhi)
31 {
32  size_t towerIndex = CaloTools::caloTowerHash(iEta, iPhi);
33  if(towerIndex<towers.size()){
34  if(towers[towerIndex].hwEta()!=iEta || towers[towerIndex].hwPhi()!=iPhi){ //it failed, this is bad, but we will not log the error due to policy and silently attempt to do a brute force search instead
35  // std::cout <<"error, tower "<<towers[towerIndex].hwEta()<<" "<<towers[towerIndex].hwPhi()<<" does not match "<<iEta<<" "<<iPhi<<" index "<<towerIndex<<" nr towrs "<<towers.size()<<std::endl;
36  for(size_t towerNr=0;towerNr<towers.size();towerNr++){
37  if(towers[towerNr].hwEta()==iEta && towers[towerNr].hwPhi()==iPhi) return towers[towerNr];
38  }
39  }else return towers[towerIndex];
40 
41  }
42  else{// in case the vector of towers do not contain all the towers (towerIndex can be > towers.size())
43  for(size_t towerNr=0;towerNr<towers.size();towerNr++){
44  if(towers[towerNr].hwEta()==iEta && towers[towerNr].hwPhi()==iPhi) return towers[towerNr];
45  }
46  }
47 
48  return nullTower_;
49 }
50 
51 const l1t::CaloCluster& l1t::CaloTools::getCluster(const std::vector<l1t::CaloCluster>& clusters,int iEta,int iPhi)
52 {
53  for(size_t clusterNr=0;clusterNr<clusters.size();clusterNr++){
54  if(clusters[clusterNr].hwEta()==iEta && clusters[clusterNr].hwPhi()==iPhi) return clusters[clusterNr];
55  }
56  return nullCluster_;
57 }
58 
59 
60 
61 //this implimentation has not all the necessary info yet, we need to check the exact HF numbering
62 //(iEta=-28,iPhi=1)=index 0 to (iEta=28,iPhi=72)=index 28*72*2-1
63 //HF then runs after that so -32,1 = 28*72*2
64 size_t l1t::CaloTools::caloTowerHash(int iEta,int iPhi)
65 {
66 
67  if(!isValidIEtaIPhi(iEta,iPhi)) return caloTowerHashMax();
68  else{
69  const int absIEta = abs(iEta);
70  if(absIEta>kHFEnd) return kNrTowers;
71  else if(absIEta<=kHBHEEnd){ //HBHE
72  int iEtaNoZero=iEta;
73  if(iEta>0) iEtaNoZero--;
74  return (iEtaNoZero+kHBHEEnd)*kHBHENrPhi+iPhi-1;
75  }else{ //HF
76  int iEtaIndex = iEta+kHFEnd; //iEta=-32 is 0
77  if(iEta>0) iEtaIndex= iEta-kHBHEEnd+(kHFEnd-kHBHEEnd)-1; //but iEta=29 is 4
78  return iEtaIndex*kHFNrPhi+iPhi/kHFPhiSeg + kNrHBHETowers;
79  }
80  }
81 }
82 
83 
85 {
86  return kNrTowers;
87 }
88 
89 
90 bool l1t::CaloTools::isValidIEtaIPhi(int iEta,int iPhi)
91 {
92  size_t absIEta = abs(iEta);
93  if(iPhi<=0 || iPhi>kNPhi) return false;
94  if(absIEta==0 || absIEta>kHFEnd) return false;
95  //if(absIEta>kHBHEEnd && iPhi%kHFPhiSeg!=1) return false;
96  return true;
97 
98 }
99 
100 int l1t::CaloTools::calHwEtSum(int iEta,int iPhi,const std::vector<l1t::CaloTower>& towers,
101  int localEtaMin,int localEtaMax,int localPhiMin,int localPhiMax,
102  SubDet etMode)
103 {
104 
105  return calHwEtSum(iEta,iPhi,towers,localEtaMin,localEtaMax,localPhiMin,localPhiMax,kHFEnd,etMode);
106 }
107 
108 int l1t::CaloTools::calHwEtSum(int iEta,int iPhi,const std::vector<l1t::CaloTower>& towers,
109  int localEtaMin,int localEtaMax,int localPhiMin,int localPhiMax,
110  int iEtaAbsMax,SubDet etMode)
111 {
112  int hwEtSum=0;
113  for(int etaNr=localEtaMin;etaNr<=localEtaMax;etaNr++){
114  for(int phiNr=localPhiMin;phiNr<=localPhiMax;phiNr++){
115 
116  int towerIEta = l1t::CaloStage2Nav::offsetIEta(iEta,etaNr);
117  int towerIPhi = l1t::CaloStage2Nav::offsetIPhi(iPhi,phiNr);
118  if(abs(towerIEta)<=iEtaAbsMax){
119  const l1t::CaloTower& tower = getTower(towers,towerIEta,towerIPhi);
120  if(etMode==ECAL) hwEtSum+=tower.hwEtEm();
121  else if(etMode==HCAL) hwEtSum+=tower.hwEtHad();
122  else if(etMode==CALO) hwEtSum+=tower.hwPt();
123  }
124  }
125  }
126  return hwEtSum;
127 }
128 
129 
130 size_t l1t::CaloTools::calNrTowers(int iEtaMin,int iEtaMax,int iPhiMin,int iPhiMax,const std::vector<l1t::CaloTower>& towers,int minHwEt,int maxHwEt,SubDet etMode)
131 {
132  size_t nrTowers=0;
133  l1t::CaloStage2Nav nav(iEtaMin,iPhiMin);
134  while(nav.currIEta()<=iEtaMax){
135  bool finishPhi = false;
136  while(!finishPhi){
137  const l1t::CaloTower& tower = l1t::CaloTools::getTower(towers,nav.currIEta(),nav.currIPhi());
138  int towerHwEt =0;
139  if(etMode==ECAL) towerHwEt+=tower.hwEtEm();
140  else if(etMode==HCAL) towerHwEt+=tower.hwEtHad();
141  else if(etMode==CALO) towerHwEt+=tower.hwPt();
142  if(towerHwEt>=minHwEt && towerHwEt<=maxHwEt) nrTowers++;
143  finishPhi = (nav.currIPhi() == iPhiMax);
144  nav.north();
145  }
146  nav.east();
147  nav.resetIPhi();
148  }
149  return nrTowers;
150 }
151 
152 std::pair<float,float> l1t::CaloTools::towerEtaBounds(int ieta)
153 {
154  if(ieta==0) ieta = 1;
155  if(ieta>kHFEnd) ieta = kHFEnd;
156  if(ieta<(-1*kHFEnd)) ieta = -1*kHFEnd;
157  //const float towerEtas[33] = {0,0.087,0.174,0.261,0.348,0.435,0.522,0.609,0.696,0.783,0.870,0.957,1.044,1.131,1.218,1.305,1.392,1.479,1.566,1.653,1.740,1.830,1.930,2.043,2.172,2.322,2.5,2.650,3.000,3.5,4.0,4.5,5.0};
158  const float towerEtas[42] = {0,0.087,0.174,0.261,0.348,0.435,0.522,0.609,0.696,0.783,0.870,0.957,1.044,1.131,1.218,1.305,1.392,1.479,1.566,1.653,1.740,1.830,1.930,2.043,2.172,2.322,2.5,2.650,2.853,3.139,3.314,3.489,3.664,3.839,4.013,4.191,4.363,4.538,4.716,4.889,5.191,5.191};
159  return std::make_pair( towerEtas[abs(ieta)-1],towerEtas[abs(ieta)] );
160 }
161 
163 {
164  std::pair<float,float> bounds = towerEtaBounds(ieta);
165  float eta = (bounds.second+bounds.first)/2.;
166  float sign = ieta>0 ? 1. : -1.;
167  return sign*eta;
168 }
169 
170 float l1t::CaloTools::towerPhi(int ieta, int iphi)
171 {
172  float phi = (float(iphi)-0.5)*towerPhiSize(ieta);
173  if (phi > M_PI) phi = phi - (2*M_PI);
174  return phi;
175 }
176 
178 {
179  std::pair<float,float> bounds = towerEtaBounds(ieta);
180  float size = (bounds.second-bounds.first);
181  return size;
182 }
183 
185 {
186  return 2.*M_PI/kNPhi;
187 }
188 
189 
190 // convert from calo ieta to internal MP ieta
191 int l1t::CaloTools::mpEta(int ieta) {
192 
193  if (ieta>kHFBegin) return ieta-1;
194  else if (ieta<-1*kHFBegin) return ieta+1;
195  else return ieta;
196 
197 }
198 
199 
200 // convert from internal MP ieta to calo ieta
201 int l1t::CaloTools::caloEta(int mpEta) {
202 
203  if (mpEta>=kHFBegin) return mpEta+1;
204  else if (mpEta<=-1*kHFBegin) return mpEta-1;
205  else return mpEta;
206 
207 }
208 
209 
210 // convert calorimeter ieta to RCT region index
212 {
213 
214  // outside HF
215  if (abs(ieta) > kHFEnd)
216  return (ieta<0 ? 0 : 21);
217 
218  // inside HBHE
219  if (abs(ieta) <= kHFBegin)
220  {
221  if (ieta<0)
222  return 11 - ceil( double (abs(ieta) /4.) );
223  else
224  return ceil( double (abs(ieta) /4.) ) + 10;
225  }
226 
227  // in HF
228  if (ieta<0)
229  return 4 - ceil( double (abs(ieta)-29) /4. );
230  else
231  return ceil( double (abs(ieta)-29) /4. ) + 17;
232 
233 }
234 
235 
236 int l1t::CaloTools::gtEta(int ieta) {
237 
238  double eta = towerEta(ieta);
239  return round ( eta / kGTEtaLSB );
240 
241 }
242 
243 int l1t::CaloTools::gtPhi(int ieta, int iphi) {
244 
245  double phi = towerPhi(ieta, iphi);
246  if (phi<0) phi = phi + 2*M_PI;
247  return round ( phi / kGTPhiLSB );
248 
249 }
250 
251 
252 
253 
254 
255 // this conversion is based on GT input definitions in CMS DN-2014/029
257 
258  return math::PtEtaPhiMLorentzVector( cand->hwPt() * kGTEtLSB + 1.E-6,
259  cand->hwEta() * kGTEtaLSB,
260  cand->hwPhi() * kGTPhiLSB,
261  0. ) ;
262 
263 }
264 
265 
267 
268  return l1t::EGamma( p4Demux(&eg),
269  eg.hwPt(),
270  eg.hwEta(),
271  eg.hwPhi(),
272  eg.hwQual(),
273  eg.hwIso() );
274 
275 }
276 
277 
279 
280  return l1t::Tau( p4Demux(&tau),
281  tau.hwPt(),
282  tau.hwEta(),
283  tau.hwPhi(),
284  tau.hwQual(),
285  tau.hwIso() );
286 
287 }
288 
289 
291 
292  return l1t::Jet( p4Demux(&jet),
293  jet.hwPt(),
294  jet.hwEta(),
295  jet.hwPhi(),
296  jet.hwQual() );
297 
298 }
299 
300 
302 
303  return l1t::EtSum( p4Demux(&etsum),
304  etsum.getType(),
305  etsum.hwPt(),
306  etsum.hwEta(),
307  etsum.hwPhi(),
308  etsum.hwQual() );
309 
310 }
311 
312 
313 
314 //
316 
317  return math::PtEtaPhiMLorentzVector( cand->hwPt() * 0.5 + 1.E-6,
318  towerEta(cand->hwEta()),
319  towerPhi(cand->hwEta(), cand->hwPhi()),
320  0. ) ;
321 
322 }
323 
325 
326  return l1t::EGamma( p4MP(&eg),
327  eg.hwPt(),
328  eg.hwEta(),
329  eg.hwPhi(),
330  eg.hwQual(),
331  eg.hwIso() );
332 }
333 
334 
336 
337  return l1t::Tau( p4MP(&tau),
338  tau.hwPt(),
339  tau.hwEta(),
340  tau.hwPhi(),
341  tau.hwQual(),
342  tau.hwIso() );
343 }
344 
345 
347 
348  return l1t::Jet( p4MP(&jet),
349  jet.hwPt(),
350  jet.hwEta(),
351  jet.hwPhi(),
352  jet.hwQual() );
353 
354 }
355 
357 
358  return l1t::EtSum( p4MP(&etsum),
359  etsum.getType(),
360  etsum.hwPt(),
361  etsum.hwEta(),
362  etsum.hwPhi(),
363  etsum.hwQual() );
364 
365 }
static float towerEta(int ieta)
Definition: CaloTools.cc:162
static l1t::Tau tauP4MP(l1t::Tau &)
Definition: CaloTools.cc:335
static l1t::EtSum etSumP4MP(l1t::EtSum &)
Definition: CaloTools.cc:356
static bool isValidIEtaIPhi(int iEta, int iPhi)
Definition: CaloTools.cc:90
static const float kGTPhiLSB
Definition: CaloTools.h:116
static float towerPhi(int ieta, int iphi)
Definition: CaloTools.cc:170
std::pair< int, int > north()
Definition: CaloStage2Nav.h:54
static int mpEta(int ieta)
Definition: CaloTools.cc:191
static l1t::EGamma egP4MP(l1t::EGamma &)
Definition: CaloTools.cc:324
static int regionEta(int ieta)
Definition: CaloTools.cc:211
Definition: Tau.h:16
static int offsetIEta(int iEta, int offset)
Definition: CaloStage2Nav.h:43
double sign(double x)
static float towerEtaSize(int ieta)
Definition: CaloTools.cc:177
static int calHwEtSum(int iEta, int iPhi, const std::vector< l1t::CaloTower > &towers, int localEtaMin, int localEtaMax, int localPhiMin, int localPhiMax, SubDet etMode=CALO)
Definition: CaloTools.cc:100
static const float kGTEtaLSB
Definition: CaloTools.h:115
static math::PtEtaPhiMLorentzVector p4MP(l1t::L1Candidate *)
Definition: CaloTools.cc:315
int hwPhi() const
Definition: L1Candidate.cc:79
int hwEtEm() const
Definition: CaloTower.cc:64
static int gtPhi(int ieta, int iphi)
Definition: CaloTools.cc:243
static size_t caloTowerHash(int iEta, int iPhi)
Definition: CaloTools.cc:64
int currIPhi() const
Definition: CaloStage2Nav.h:61
PtEtaPhiMLorentzVectorD PtEtaPhiMLorentzVector
Lorentz vector with cartesian internal representation.
Definition: LorentzVector.h:25
int hwIso() const
Definition: L1Candidate.cc:84
Definition: Jet.h:16
static int offsetIPhi(int iPhi, int offset)
Definition: CaloStage2Nav.h:32
static size_t calNrTowers(int iEtaMin, int iEtaMax, int iPhiMin, int iPhiMax, const std::vector< l1t::CaloTower > &towers, int minHwEt, int maxHwEt, SubDet etMode=CALO)
Definition: CaloTools.cc:130
static l1t::EGamma egP4Demux(l1t::EGamma &)
Definition: CaloTools.cc:266
static int gtEta(int ieta)
Definition: CaloTools.cc:236
static const l1t::CaloCluster & getCluster(const std::vector< l1t::CaloCluster > &clusters, int iEta, int iPhi)
Definition: CaloTools.cc:51
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
static l1t::Jet jetP4MP(l1t::Jet &)
Definition: CaloTools.cc:346
static l1t::Jet jetP4Demux(l1t::Jet &)
Definition: CaloTools.cc:290
int hwEta() const
Definition: L1Candidate.cc:74
int hwQual() const
Definition: L1Candidate.cc:89
#define M_PI
static const int32_t cos_coeff[72]
Definition: CaloTools.h:105
static float towerPhiSize(int ieta)
Definition: CaloTools.cc:184
static l1t::Tau tauP4Demux(l1t::Tau &)
Definition: CaloTools.cc:278
int hwPt() const
Definition: L1Candidate.cc:69
static std::pair< float, float > towerEtaBounds(int ieta)
Definition: CaloTools.cc:152
static size_t caloTowerHashMax()
Definition: CaloTools.cc:84
static const l1t::CaloTower nullTower_
Definition: CaloTools.h:112
Geom::Phi< T > phi() const
static bool insertTower(std::vector< l1t::CaloTower > &towers, const l1t::CaloTower &tower)
Definition: CaloTools.cc:19
std::pair< int, int > east()
Definition: CaloStage2Nav.h:56
static int caloEta(int ietaMP)
Definition: CaloTools.cc:201
static const l1t::CaloTower & getTower(const std::vector< l1t::CaloTower > &towers, int iEta, int iPhi)
Definition: CaloTools.cc:30
static const float kGTEtLSB
Definition: CaloTools.h:117
static math::PtEtaPhiMLorentzVector p4Demux(l1t::L1Candidate *)
Definition: CaloTools.cc:256
int hwEtHad() const
Definition: CaloTower.cc:69
static const l1t::CaloCluster nullCluster_
Definition: CaloTools.h:113
EtSumType getType() const
Definition: EtSum.cc:37
tuple size
Write out results.
static l1t::EtSum etSumP4Demux(l1t::EtSum &)
Definition: CaloTools.cc:301
static const int32_t sin_coeff[72]
Definition: CaloTools.h:106
int currIEta() const
Definition: CaloStage2Nav.h:60