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 //currently implemented as a brute force search but this will hopefully change in the future
10 //with standarising the layout of std::vector<l1t::CaloTower>
11 const l1t::CaloTower& l1t::CaloTools::getTower(const std::vector<l1t::CaloTower>& towers,int iEta,int iPhi)
12 {
13  size_t towerIndex = CaloTools::caloTowerHash(iEta, iPhi);
14  if(towerIndex<towers.size()){
15  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
16  // std::cout <<"error, tower "<<towers[towerIndex].hwEta()<<" "<<towers[towerIndex].hwPhi()<<" does not match "<<iEta<<" "<<iPhi<<" index "<<towerIndex<<" nr towrs "<<towers.size()<<std::endl;
17  for(size_t towerNr=0;towerNr<towers.size();towerNr++){
18  if(towers[towerNr].hwEta()==iEta && towers[towerNr].hwPhi()==iPhi) return towers[towerNr];
19  }
20  }else return towers[towerIndex];
21 
22  }
23  else{// in case the vector of towers do not contain all the towers (towerIndex can be > towers.size())
24  for(size_t towerNr=0;towerNr<towers.size();towerNr++){
25  if(towers[towerNr].hwEta()==iEta && towers[towerNr].hwPhi()==iPhi) return towers[towerNr];
26  }
27  }
28 
29  return nullTower_;
30 }
31 
32 const l1t::CaloCluster& l1t::CaloTools::getCluster(const std::vector<l1t::CaloCluster>& clusters,int iEta,int iPhi)
33 {
34  for(size_t clusterNr=0;clusterNr<clusters.size();clusterNr++){
35  if(clusters[clusterNr].hwEta()==iEta && clusters[clusterNr].hwPhi()==iPhi) return clusters[clusterNr];
36  }
37  return nullCluster_;
38 }
39 
40 
41 
42 //this implimentation has not all the necessary info yet, we need to check the exact HF numbering
43 //(iEta=-28,iPhi=1)=index 0 to (iEta=28,iPhi=72)=index 28*72*2-1
44 //HF then runs after that so -32,1 = 28*72*2
45 size_t l1t::CaloTools::caloTowerHash(int iEta,int iPhi)
46 {
47 
48  if(!isValidIEtaIPhi(iEta,iPhi)) return caloTowerHashMax();
49  else{
50  const int absIEta = abs(iEta);
51  if(absIEta>kHFEnd) return kNrTowers;
52  else if(absIEta<=kHBHEEnd){ //HBHE
53  int iEtaNoZero=iEta;
54  if(iEta>0) iEtaNoZero--;
55  return (iEtaNoZero+kHBHEEnd)*kHBHENrPhi+iPhi-1;
56  }else{ //HF
57  int iEtaIndex = iEta+kHFEnd; //iEta=-32 is 0
58  if(iEta>0) iEtaIndex= iEta-kHBHEEnd+(kHFEnd-kHBHEEnd)-1; //but iEta=29 is 4
59  return iEtaIndex*kHFNrPhi+iPhi/kHFPhiSeg + kNrHBHETowers;
60  }
61  }
62 }
63 
64 
66 {
67  return kNrTowers;
68 }
69 
70 
71 bool l1t::CaloTools::isValidIEtaIPhi(int iEta,int iPhi)
72 {
73  size_t absIEta = abs(iEta);
74  if(iPhi<=0 || iPhi>kHBHENrPhi) return false;
75  if(absIEta==0 || absIEta>kHFEnd) return false;
76  if(absIEta>kHBHEEnd && iPhi%kHFPhiSeg!=1) return false;
77  return true;
78 
79 }
80 
81 int l1t::CaloTools::calHwEtSum(int iEta,int iPhi,const std::vector<l1t::CaloTower>& towers,
82  int localEtaMin,int localEtaMax,int localPhiMin,int localPhiMax,
83  SubDet etMode)
84 {
85 
86  return calHwEtSum(iEta,iPhi,towers,localEtaMin,localEtaMax,localPhiMin,localPhiMax,kHFEnd,etMode);
87 }
88 
89 int l1t::CaloTools::calHwEtSum(int iEta,int iPhi,const std::vector<l1t::CaloTower>& towers,
90  int localEtaMin,int localEtaMax,int localPhiMin,int localPhiMax,
91  int iEtaAbsMax,SubDet etMode)
92 {
93  int hwEtSum=0;
94  for(int etaNr=localEtaMin;etaNr<=localEtaMax;etaNr++){
95  for(int phiNr=localPhiMin;phiNr<=localPhiMax;phiNr++){
96 
97  int towerIEta = l1t::CaloStage2Nav::offsetIEta(iEta,etaNr);
98  int towerIPhi = l1t::CaloStage2Nav::offsetIPhi(iPhi,phiNr);
99  if(abs(towerIEta)<=iEtaAbsMax){
100  const l1t::CaloTower& tower = getTower(towers,towerIEta,towerIPhi);
101  if(etMode&ECAL) hwEtSum+=tower.hwEtEm();
102  if(etMode&HCAL) hwEtSum+=tower.hwEtHad();
103  }
104  }
105  }
106  return hwEtSum;
107 }
108 
109 
110 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)
111 {
112  size_t nrTowers=0;
113  l1t::CaloStage2Nav nav(iEtaMin,iPhiMin);
114  while(nav.currIEta()<=iEtaMax){
115  bool finishPhi = false;
116  while(!finishPhi){
117  const l1t::CaloTower& tower = l1t::CaloTools::getTower(towers,nav.currIEta(),nav.currIPhi());
118  int towerHwEt =0;
119  if(etMode&ECAL) towerHwEt+=tower.hwEtEm();
120  if(etMode&HCAL) towerHwEt+=tower.hwEtHad();
121  if(etMode&CALO) towerHwEt+=tower.hwPt();
122  if(towerHwEt>=minHwEt && towerHwEt<=maxHwEt) nrTowers++;
123  finishPhi = (nav.currIPhi() == iPhiMax);
124  nav.north();
125  }
126  nav.east();
127  nav.resetIPhi();
128  }
129  return nrTowers;
130 }
131 
132 std::pair<float,float> l1t::CaloTools::towerEtaBounds(int ieta)
133 {
134  if(ieta==0) ieta = 1;
135  if(ieta>32) ieta = 32;
136  if(ieta<-32) ieta = -32;
137  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};
138  return std::make_pair( towerEtas[abs(ieta)-1],towerEtas[abs(ieta)] );
139 }
140 
142 {
143  std::pair<float,float> bounds = towerEtaBounds(ieta);
144  float eta = (bounds.second+bounds.first)/2.;
145  float sign = ieta>0 ? 1. : -1.;
146  return sign*eta;
147 }
148 
149 float l1t::CaloTools::towerPhi(int ieta, int iphi)
150 {
151  return (float(iphi)-0.5)*towerPhiSize(ieta);
152 }
153 
155 {
156  std::pair<float,float> bounds = towerEtaBounds(ieta);
157  float size = (bounds.second-bounds.first);
158  return size;
159 }
160 
162 {
163  if(abs(ieta)<=28) return 2.*M_PI/72.;
164  else return 2.*M_PI/18.;
165 }
166 
167 
static float towerEta(int ieta)
Definition: CaloTools.cc:141
static bool isValidIEtaIPhi(int iEta, int iPhi)
Definition: CaloTools.cc:71
static float towerPhi(int ieta, int iphi)
Definition: CaloTools.cc:149
std::pair< int, int > north()
Definition: CaloStage2Nav.h:54
static int offsetIEta(int iEta, int offset)
Definition: CaloStage2Nav.h:43
double sign(double x)
static float towerEtaSize(int ieta)
Definition: CaloTools.cc:154
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:81
int hwEtEm() const
Definition: CaloTower.cc:64
T eta() const
static size_t caloTowerHash(int iEta, int iPhi)
Definition: CaloTools.cc:45
int currIPhi() const
Definition: CaloStage2Nav.h:61
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:110
static const l1t::CaloCluster & getCluster(const std::vector< l1t::CaloCluster > &clusters, int iEta, int iPhi)
Definition: CaloTools.cc:32
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
#define M_PI
static float towerPhiSize(int ieta)
Definition: CaloTools.cc:161
int hwPt() const
Definition: L1Candidate.cc:69
static std::pair< float, float > towerEtaBounds(int ieta)
Definition: CaloTools.cc:132
static size_t caloTowerHashMax()
Definition: CaloTools.cc:65
static const l1t::CaloTower nullTower_
Definition: CaloTools.h:80
std::pair< int, int > east()
Definition: CaloStage2Nav.h:56
static const l1t::CaloTower & getTower(const std::vector< l1t::CaloTower > &towers, int iEta, int iPhi)
Definition: CaloTools.cc:11
int hwEtHad() const
Definition: CaloTower.cc:69
static const l1t::CaloCluster nullCluster_
Definition: CaloTools.h:81
tuple size
Write out results.
int currIEta() const
Definition: CaloStage2Nav.h:60