Skip to content

Commit

Permalink
Merge pull request #37546 from perrotta/simplifyConstantsHgcalCellUv
Browse files Browse the repository at this point in the history
Simplify usage of constants in HGCalCellUV
  • Loading branch information
cmsbuild committed Apr 13, 2022
2 parents f6c204b + d803ce4 commit 7642901
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 12 deletions.
8 changes: 3 additions & 5 deletions Geometry/HGCalCommonData/interface/HGCalCellUV.h
@@ -1,7 +1,6 @@
#ifndef Geometry_HGCalCommonData_HGCalCellUV_h
#define Geometry_HGCalCommonData_HGCalCellUV_h

#include <cmath>
#include <cstdint>
#include <iterator>
#include <map>
Expand Down Expand Up @@ -35,10 +34,9 @@ class HGCalCellUV {
bool extend,
bool debug);

const double sqrt3_ = std::sqrt(3.0);
const double sqrt3By2_ = (0.5 * sqrt3_);
const double sin60_ = sqrt3By2_;
const double cos60_ = 0.5;
static constexpr double sqrt3_ = 1.732050807568877; // std::sqrt(3.0) in double precision
static constexpr double sin60_ = 0.5 * sqrt3_;
static constexpr double cos60_ = 0.5;

int32_t ncell_[2];
double cellX_[2], cellY_[2], cellXTotal_[2], cellYTotal_[2], waferSize;
Expand Down
14 changes: 7 additions & 7 deletions Geometry/HGCalCommonData/src/HGCalCellUV.cc
@@ -1,7 +1,7 @@
#include "Geometry/HGCalCommonData/interface/HGCalCellUV.h"
#include "FWCore/MessageLogger/interface/MessageLogger.h"
#include <iostream>
#include <vector>
#include <array>
#include <algorithm>
#include <cassert>

Expand Down Expand Up @@ -47,8 +47,8 @@ std::pair<int32_t, int32_t> HGCalCellUV::cellUVFromXY1(
//--- Reverse transform to placement=0, if placement index ≠ 6
double xloc1 = (placement >= 6) ? xloc : -xloc;
int rot = placement % 6;
static const std::vector<double> fcos = {1.0, 0.5, -0.5, -1.0, -0.5, 0.5};
static const std::vector<double> fsin = {0.0, sqrt3By2_, sqrt3By2_, 0.0, -sqrt3By2_, -sqrt3By2_};
static constexpr std::array<double, 6> fcos = {{1.0, cos60_, -cos60_, -1.0, -cos60_, cos60_}};
static constexpr std::array<double, 6> fsin = {{0.0, sin60_, sin60_, 0.0, -sin60_, -sin60_}};
double x = xloc1 * fcos[rot] - yloc * fsin[rot];
double y = xloc1 * fsin[rot] + yloc * fcos[rot];

Expand Down Expand Up @@ -88,8 +88,8 @@ std::pair<int32_t, int32_t> HGCalCellUV::cellUVFromXY2(
//--- Reverse transform to placement=0, if placement index ≠ 7
double xloc1 = (placement >= 6) ? xloc : -1 * xloc;
int rot = placement % 6;
static const std::vector<double> fcos = {0.5, 1.0, 0.5, -0.5, -1.0, -0.5};
static const std::vector<double> fsin = {-sqrt3By2_, 0.0, sqrt3By2_, sqrt3By2_, 0.0, -sqrt3By2_};
static constexpr std::array<double, 6> fcos = {{cos60_, 1.0, cos60_, -cos60_, -1.0, -cos60_}};
static constexpr std::array<double, 6> fsin = {{-sin60_, 0.0, sin60_, sin60_, 0.0, -sin60_}};
double x = xloc1 * fcos[rot] - yloc * fsin[rot];
double y = xloc1 * fsin[rot] + yloc * fcos[rot];

Expand Down Expand Up @@ -155,8 +155,8 @@ std::pair<int32_t, int32_t> HGCalCellUV::cellUVFromXY3(
//--- Reverse transform to placement=0, if placement index ≠ 6
double xloc1 = (placement >= 6) ? xloc : -xloc;
int rot = placement % 6;
static const std::vector<double> fcos = {1.0, 0.5, -0.5, -1.0, -0.5, 0.5};
static const std::vector<double> fsin = {0.0, sqrt3By2_, sqrt3By2_, 0.0, -sqrt3By2_, -sqrt3By2_};
static constexpr std::array<double, 6> fcos = {{1.0, cos60_, -cos60_, -1.0, -cos60_, cos60_}};
static constexpr std::array<double, 6> fsin = {{0.0, sin60_, sin60_, 0.0, -sin60_, -sin60_}};
double xprime = xloc1 * fcos[rot] - yloc * fsin[rot];
double yprime = xloc1 * fsin[rot] + yloc * fcos[rot];
double x = xprime + cellX_[type];
Expand Down

0 comments on commit 7642901

Please sign in to comment.