CMS 3D CMS Logo

List of all members | Public Member Functions | Protected Member Functions | Protected Attributes
l1tpf_calo::Phase1GridBase Class Reference

#include <CaloClusterer.h>

Inheritance diagram for l1tpf_calo::Phase1GridBase:
l1tpf_calo::Grid l1tpf_calo::Phase1Grid l1tpf_calo::Phase2Grid

Public Member Functions

int find_cell (float eta, float phi) const override
 
int ifind_cell (int ieta, int iphi) const
 
 Phase1GridBase (int nEta, int nPhi, int ietaCoarse, int ietaVeryCoarse, const float *towerEtas)
 
- Public Member Functions inherited from l1tpf_calo::Grid
float eta (int icell) const
 
float etaWidth (int icell) const
 
int ieta (int icell) const
 
int iphi (int icell) const
 
int neighbour (int icell, unsigned int idx) const
 
float phi (int icell) const
 
float phiWidth (int icell) const
 
unsigned int size () const
 
virtual ~Grid ()
 

Protected Member Functions

int imove (int ieta, int iphi, int deta, int dphi)
 
bool valid_ieta_iphi (int ieta, int iphi) const
 
- Protected Member Functions inherited from l1tpf_calo::Grid
 Grid (unsigned int size)
 

Protected Attributes

std::vector< int > cell_map_
 
const int ietaCoarse_
 
const int ietaVeryCoarse_
 
const int nEta_
 
const int nPhi_
 
const float * towerEtas_
 
- Protected Attributes inherited from l1tpf_calo::Grid
std::vector< float > eta_
 
std::vector< float > etaWidth_
 
std::vector< int > ieta_
 
std::vector< int > iphi_
 
unsigned int ncells_
 
std::vector< std::array< int, 8 > > neighbours_
 
std::vector< float > phi_
 
std::vector< float > phiWidth_
 

Detailed Description

Definition at line 51 of file CaloClusterer.h.

Constructor & Destructor Documentation

◆ Phase1GridBase()

l1tpf_calo::Phase1GridBase::Phase1GridBase ( int  nEta,
int  nPhi,
int  ietaCoarse,
int  ietaVeryCoarse,
const float *  towerEtas 
)

Definition at line 19 of file CaloClusterer.cc.

21  : Grid(2 * ((ietaCoarse - 1) * nPhi + (ietaVeryCoarse - ietaCoarse) * (nPhi / 2) +
22  (nEta - ietaVeryCoarse + 1) * (nPhi / 4))),
23  nEta_(nEta),
24  nPhi_(nPhi),
25  ietaCoarse_(ietaCoarse),
26  ietaVeryCoarse_(ietaVeryCoarse),
27  towerEtas_(towerEtas),
28  cell_map_(2 * nEta * nPhi, -1) {
29  int icell = 0;
30  for (int ie = -nEta_; ie <= nEta_; ++ie) {
31  int absie = std::abs(ie);
32  for (int iph = 1; iph <= nPhi_; ++iph) {
33  if (!valid_ieta_iphi(ie, iph))
34  continue;
35  ieta_[icell] = ie;
36  iphi_[icell] = iph;
37  float etaLo = (absie < nEta_ ? towerEtas_[absie - 1] : towerEtas_[absie - 2]);
38  float etaHi = (absie < nEta_ ? towerEtas_[absie] : towerEtas_[absie - 1]);
39  eta_[icell] = (ie > 0 ? 0.5 : -0.5) * (etaLo + etaHi);
40  etaWidth_[icell] = (etaHi - etaLo);
41  phiWidth_[icell] = 2 * M_PI / nPhi_;
42  if (absie >= ietaVeryCoarse_)
43  phiWidth_[icell] *= 4;
44  else if (absie >= ietaCoarse_)
45  phiWidth_[icell] *= 2;
46  phi_[icell] = (iph - 1) * 2 * M_PI / nPhi_ + 0.5 * phiWidth_[icell];
47  if (phi_[icell] > M_PI)
48  phi_[icell] -= 2 * M_PI;
49  std::fill(neighbours_[icell].begin(), neighbours_[icell].end(), -1);
50  cell_map_[(ie + nEta_) + 2 * nEta_ * (iph - 1)] = icell;
51  icell++;
52  }
53  }
54  assert(unsigned(icell) == ncells_);
55  // now link the cells
56  for (icell = 0; icell < int(ncells_); ++icell) {
57  int ie = ieta_[icell], iph = iphi_[icell];
58  int ineigh = 0;
59  for (int deta = -1; deta <= +1; ++deta) {
60  for (int dphi = -1; dphi <= +1; ++dphi) {
61  if (deta == 0 && dphi == 0)
62  continue;
63  neighbours_[icell][ineigh++] = imove(ie, iph, deta, dphi);
64  }
65  }
66  }
69  //for (float teta = 0; teta <= 5.0; teta += 0.02) {
70  // for (float tphi = -M_PI; tphi <= M_PI; tphi += 0.02) {
71  // find_cell(+teta, tphi);
72  // find_cell(-teta, tphi);
73  // }
74  //}
75 }

References funct::abs(), cms::cuda::assert(), begin, cell_map_, end, l1tpf_calo::Grid::eta_, l1tpf_calo::Grid::etaWidth_, ntuplemaker::fill, l1tpf_calo::Grid::ieta_, ietaCoarse_, ietaVeryCoarse_, imove(), createfilelist::int, l1tpf_calo::Grid::iphi_, M_PI, l1tpf_calo::Grid::ncells_, l1tpf_calo::Grid::neighbours_, nEta_, nPhi_, l1tpf_calo::Grid::phi_, l1tpf_calo::Grid::phiWidth_, towerEtas_, and valid_ieta_iphi().

Member Function Documentation

◆ find_cell()

int l1tpf_calo::Phase1GridBase::find_cell ( float  eta,
float  phi 
) const
overridevirtual

Implements l1tpf_calo::Grid.

Definition at line 77 of file CaloClusterer.cc.

77  {
78  int ieta =
80  if (ieta == nEta_)
81  return -1; // outside bounds
82  assert(ieta > 0 && ieta < nEta_);
83  if (ieta > nEta_)
84  ieta = nEta_;
85  if (eta < 0)
86  ieta = -ieta;
87  phi = reco::reduceRange(phi); // [-PI, PI]
88  if (phi < 0) // then bring to [0, 2*PI]
89  phi += 2 * M_PI;
90  int iphi = std::floor(phi * nPhi_ / (2 * M_PI));
91  if (phi >= 2 * M_PI)
92  iphi = nPhi_ - 1; // fix corner case due to roundings etc
93  assert(iphi < nPhi_);
95  iphi -= (iphi % 4);
96  else if (std::abs(ieta) >= ietaCoarse_)
97  iphi -= (iphi % 2);
98  iphi += 1;
100  //if (!valid_ieta_iphi(ieta,iphi)) {
101  // printf("Error in finding cell for eta %+7.4f phi %+7.4f, got ieta = %+3d iphi %2d which is not valid\n",
102  // eta, phi, ieta, iphi);
103  //}
105  int icell = ifind_cell(ieta, iphi);
106  assert(icell != -1);
107 
109  //if (std::abs(eta - eta_[icell]) > 0.501*etaWidth_[icell] || std::abs(deltaPhi(phi, phi_[icell])) > 0.501*phiWidth_[icell]) {
110  // printf("Mismatch in finding cell for eta %+7.4f phi %+7.4f, got ieta = %+3d iphi %2d which has eta %+7.4f +- %.4f phi %+7.4f +- %.4f ; deta = %+7.4f dphi = %+7.4f\n",
111  // eta, phi, ieta, iphi, eta_[icell], etaWidth_[icell], phi_[icell], phiWidth_[icell], eta - eta_[icell], deltaPhi(phi, phi_[icell]));
112  //}
113  //assert(std::abs(eta - eta_[icell]) <= 0.5*etaWidth_[icell]);
114  //assert(std::abs(deltaPhi(phi, phi_[icell])) <= 0.5*phiWidth_[icell]);
115  return icell;
116 }

References funct::abs(), cms::cuda::assert(), HLT_2018_cff::distance, PVValHelper::eta, LEDCalibrationChannels::ieta, LEDCalibrationChannels::iphi, cuda_std::lower_bound(), M_PI, and reco::reduceRange().

◆ ifind_cell()

int l1tpf_calo::Phase1GridBase::ifind_cell ( int  ieta,
int  iphi 
) const
inline

Definition at line 56 of file CaloClusterer.h.

56 { return cell_map_[(ieta + nEta_) + 2 * nEta_ * (iphi - 1)]; }

References cell_map_, l1tpf_calo::Grid::ieta(), l1tpf_calo::Grid::iphi(), and nEta_.

◆ imove()

int l1tpf_calo::Phase1GridBase::imove ( int  ieta,
int  iphi,
int  deta,
int  dphi 
)
protected

Definition at line 118 of file CaloClusterer.cc.

118  {
119  int ie = ieta, iph = iphi;
120  switch (deta) {
121  case -1:
122  ie = (ie == -nEta_ ? 0 : (ie == +1 ? -1 : ie - 1));
123  break;
124  case +1:
125  ie = (ie == +nEta_ ? 0 : (ie == -1 ? +1 : ie + 1));
126  break;
127  case 0:
128  break;
129  default:
130  assert(false);
131  };
132  if (ie == 0)
133  return -1;
134  switch (dphi) {
135  case -1:
136  iph = (iph == 1 ? nPhi_ : iph - 1);
137  break;
138  case +1:
139  iph = (iph == nPhi_ ? 1 : iph + 1);
140  break;
141  case 0:
142  break;
143  default:
144  assert(false);
145  };
146  if (!valid_ieta_iphi(ie, iph))
147  return -1;
148  int icell = ifind_cell(ie, iph);
149  assert(!(ie == ieta && iph == iphi));
150  assert(icell != -1);
151  assert(icell != ifind_cell(ieta, iphi));
152  return icell;
153 }

References cms::cuda::assert(), LEDCalibrationChannels::ieta, and LEDCalibrationChannels::iphi.

Referenced by Phase1GridBase().

◆ valid_ieta_iphi()

bool l1tpf_calo::Phase1GridBase::valid_ieta_iphi ( int  ieta,
int  iphi 
) const
inlineprotected

Definition at line 63 of file CaloClusterer.h.

63  {
64  if (ieta == 0 || iphi == 0)
65  return false;
66  if (std::abs(ieta) >= ietaVeryCoarse_ && (iphi % 4 != 1))
67  return false;
68  if (std::abs(ieta) >= ietaCoarse_ && (iphi % 2 != 1))
69  return false;
70  return true;
71  }

References funct::abs(), l1tpf_calo::Grid::ieta(), ietaCoarse_, ietaVeryCoarse_, and l1tpf_calo::Grid::iphi().

Referenced by Phase1GridBase().

Member Data Documentation

◆ cell_map_

std::vector<int> l1tpf_calo::Phase1GridBase::cell_map_
protected

Definition at line 61 of file CaloClusterer.h.

Referenced by ifind_cell(), and Phase1GridBase().

◆ ietaCoarse_

const int l1tpf_calo::Phase1GridBase::ietaCoarse_
protected

Definition at line 59 of file CaloClusterer.h.

Referenced by Phase1GridBase(), and valid_ieta_iphi().

◆ ietaVeryCoarse_

const int l1tpf_calo::Phase1GridBase::ietaVeryCoarse_
protected

Definition at line 59 of file CaloClusterer.h.

Referenced by Phase1GridBase(), and valid_ieta_iphi().

◆ nEta_

const int l1tpf_calo::Phase1GridBase::nEta_
protected

Definition at line 59 of file CaloClusterer.h.

Referenced by ifind_cell(), and Phase1GridBase().

◆ nPhi_

const int l1tpf_calo::Phase1GridBase::nPhi_
protected

Definition at line 59 of file CaloClusterer.h.

Referenced by Phase1GridBase().

◆ towerEtas_

const float* l1tpf_calo::Phase1GridBase::towerEtas_
protected

Definition at line 60 of file CaloClusterer.h.

Referenced by Phase1GridBase().

l1tpf_calo::Grid::neighbours_
std::vector< std::array< int, 8 > > neighbours_
Definition: CaloClusterer.h:48
l1tpf_calo::Phase1GridBase::nEta_
const int nEta_
Definition: CaloClusterer.h:59
l1tpf_calo::Phase1GridBase::towerEtas_
const float * towerEtas_
Definition: CaloClusterer.h:60
l1tpf_calo::Phase1GridBase::nPhi_
const int nPhi_
Definition: CaloClusterer.h:59
l1tpf_calo::Phase1GridBase::imove
int imove(int ieta, int iphi, int deta, int dphi)
Definition: CaloClusterer.cc:118
l1tpf_calo::Grid::ncells_
unsigned int ncells_
Definition: CaloClusterer.h:45
cms::cuda::assert
assert(be >=bs)
HLT_2018_cff.distance
distance
Definition: HLT_2018_cff.py:6417
l1tpf_calo::Grid::phi_
std::vector< float > phi_
Definition: CaloClusterer.h:46
end
#define end
Definition: vmac.h:39
l1tpf_calo::Phase1GridBase::ifind_cell
int ifind_cell(int ieta, int iphi) const
Definition: CaloClusterer.h:56
l1tpf_calo::Grid::iphi
int iphi(int icell) const
Definition: CaloClusterer.h:33
l1tpf_calo::Grid::etaWidth_
std::vector< float > etaWidth_
Definition: CaloClusterer.h:46
l1tpf_calo::Phase1GridBase::cell_map_
std::vector< int > cell_map_
Definition: CaloClusterer.h:61
l1tpf_calo::Phase1GridBase::valid_ieta_iphi
bool valid_ieta_iphi(int ieta, int iphi) const
Definition: CaloClusterer.h:63
l1tpf_calo::Grid::phi
float phi(int icell) const
Definition: CaloClusterer.h:29
l1tpf_calo::Grid::ieta_
std::vector< int > ieta_
Definition: CaloClusterer.h:47
cuda_std::lower_bound
__host__ constexpr __device__ RandomIt lower_bound(RandomIt first, RandomIt last, const T &value, Compare comp={})
Definition: cudastdAlgorithm.h:27
ntuplemaker.fill
fill
Definition: ntuplemaker.py:304
l1tpf_calo::Phase1GridBase::ietaVeryCoarse_
const int ietaVeryCoarse_
Definition: CaloClusterer.h:59
createfilelist.int
int
Definition: createfilelist.py:10
l1tpf_calo::Grid::phiWidth_
std::vector< float > phiWidth_
Definition: CaloClusterer.h:46
M_PI
#define M_PI
Definition: BXVectorInputProducer.cc:50
HLT_2018_cff.nEta
nEta
Definition: HLT_2018_cff.py:5271
l1tpf_calo::Phase1GridBase::ietaCoarse_
const int ietaCoarse_
Definition: CaloClusterer.h:59
l1tpf_calo::Grid::Grid
Grid(unsigned int size)
Definition: CaloClusterer.h:36
l1tpf_calo::Grid::eta_
std::vector< float > eta_
Definition: CaloClusterer.h:46
l1tpf_calo::Grid::ieta
int ieta(int icell) const
Definition: CaloClusterer.h:32
l1tpf_calo::Grid::iphi_
std::vector< int > iphi_
Definition: CaloClusterer.h:47
HLT_2018_cff.nPhi
nPhi
Definition: HLT_2018_cff.py:5272
funct::abs
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
l1tpf_calo::Grid::eta
float eta(int icell) const
Definition: CaloClusterer.h:28
begin
#define begin
Definition: vmac.h:32
reco::reduceRange
constexpr T reduceRange(T x)
Definition: deltaPhi.h:18