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