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 //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){
16  for(size_t towerNr=0;towerNr<towers.size();towerNr++){
17  if(towers[towerNr].hwEta()==iEta && towers[towerNr].hwPhi()==iPhi) return towers[towerNr];
18  }
19  }else return towers[towerIndex];
20  }
21  return nullTower_;
22 }
23 
24 const l1t::CaloCluster& l1t::CaloTools::getCluster(const std::vector<l1t::CaloCluster>& clusters,int iEta,int iPhi)
25 {
26  for(size_t clusterNr=0;clusterNr<clusters.size();clusterNr++){
27  if(clusters[clusterNr].hwEta()==iEta && clusters[clusterNr].hwPhi()==iPhi) return clusters[clusterNr];
28  }
29  return nullCluster_;
30 }
31 
32 
33 
34 //this implimentation has not all the necessary info yet, we need to check the exact HF numbering
35 //(iEta=-28,iPhi=1)=index 0 to (iEta=28,iPhi=72)=index 28*72*2-1
36 //HF then runs after that so -32,1 = 28*72*2
37 size_t l1t::CaloTools::caloTowerHash(int iEta,int iPhi)
38 {
39 
40  if(!isValidIEtaIPhi(iEta,iPhi)) return caloTowerHashMax();
41  else{
42  const int absIEta = abs(iEta);
43  if(absIEta>kHFEnd) return kNrTowers;
44  else if(absIEta<=kHBHEEnd){ //HBHE
45  int iEtaNoZero=iEta;
46  if(iEta>0) iEtaNoZero--;
47  return (iEtaNoZero+kHBHEEnd)*kHBHENrPhi+iPhi-1;
48  }else{ //HF
49  int iEtaIndex = iEta+kHFEnd; //iEta=-32 is 0
50  if(iEta>0) iEtaIndex= iEta-kHBHEEnd+(kHFEnd-kHBHEEnd)-1; //but iEta=29 is 4
51  return iEtaIndex*kHFNrPhi+iPhi/kHFPhiSeg + kNrHBHETowers;
52  }
53  }
54 }
55 
56 
58 {
59  return kNrTowers;
60 }
61 
62 
63 bool l1t::CaloTools::isValidIEtaIPhi(int iEta,int iPhi)
64 {
65  size_t absIEta = abs(iEta);
66  if(iPhi<=0 || iPhi>kHBHENrPhi) return false;
67  if(absIEta==0 || absIEta>kHFEnd) return false;
68  if(absIEta>kHBHEEnd && iPhi%kHFPhiSeg!=1) return false;
69  return true;
70 
71 }
72 
73 int l1t::CaloTools::calHwEtSum(int iEta,int iPhi,const std::vector<l1t::CaloTower>& towers,
74  int localEtaMin,int localEtaMax,int localPhiMin,int localPhiMax,
75  SubDet etMode)
76 {
77 
78  return calHwEtSum(iEta,iPhi,towers,localEtaMin,localEtaMax,localPhiMin,localPhiMax,kHFEnd,etMode);
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  int iEtaAbsMax,SubDet etMode)
84 {
85  int hwEtSum=0;
86  for(int etaNr=localEtaMin;etaNr<=localEtaMax;etaNr++){
87  for(int phiNr=localPhiMin;phiNr<=localPhiMax;phiNr++){
88 
89  int towerIEta = l1t::CaloStage2Nav::offsetIEta(iEta,etaNr);
90  int towerIPhi = l1t::CaloStage2Nav::offsetIPhi(iPhi,phiNr);
91  if(abs(towerIEta)<=iEtaAbsMax){
92  const l1t::CaloTower& tower = getTower(towers,towerIEta,towerIPhi);
93  if(etMode&ECAL) hwEtSum+=tower.hwEtEm();
94  if(etMode&HCAL) hwEtSum+=tower.hwEtHad();
95  }
96  }
97  }
98  return hwEtSum;
99 }
100 
101 
102 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)
103 {
104  size_t nrTowers=0;
105  l1t::CaloStage2Nav nav(iEtaMin,iPhiMin);
106  while(nav.currIEta()<=iEtaMax){
107  while(nav.currIPhi()<=iPhiMax){
108  nav.north();
109  const l1t::CaloTower& tower = l1t::CaloTools::getTower(towers,nav.currIEta(),nav.currIPhi());
110  int towerHwEt =0;
111  if(etMode&ECAL) towerHwEt+=tower.hwEtEm();
112  if(etMode&HCAL) towerHwEt+=tower.hwEtHad();
113  if(etMode&CALO) towerHwEt+=tower.hwPt();
114  if(towerHwEt>=minHwEt && towerHwEt<=maxHwEt) nrTowers++;
115  }
116  nav.east();
117  nav.resetIPhi();
118  }
119  return nrTowers;
120 }
static bool isValidIEtaIPhi(int iEta, int iPhi)
Definition: CaloTools.cc:63
std::pair< int, int > north()
Definition: CaloStage2Nav.h:54
static int offsetIEta(int iEta, int offset)
Definition: CaloStage2Nav.h:43
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:73
int hwEtEm() const
Definition: CaloTower.cc:64
static size_t caloTowerHash(int iEta, int iPhi)
Definition: CaloTools.cc:37
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:102
static const l1t::CaloCluster & getCluster(const std::vector< l1t::CaloCluster > &clusters, int iEta, int iPhi)
Definition: CaloTools.cc:24
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
int hwPt() const
Definition: L1Candidate.cc:69
static size_t caloTowerHashMax()
Definition: CaloTools.cc:57
static const l1t::CaloTower nullTower_
Definition: CaloTools.h:72
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:73
int currIEta() const
Definition: CaloStage2Nav.h:60