Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 28 additions & 14 deletions Geometry/HGCalCommonData/src/HGCalCellUV.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ HGCalCellUV::HGCalCellUV(double waferSize, double separation, int32_t nFine, int
cellX_[k] = waferSize / (3 * ncell_[k]);
cellY_[k] = 0.5 * sqrt3_ * cellX_[k];
cellXTotal_[k] = (waferSize + separation) / (3 * ncell_[k]);
cellY_[k] = 0.5 * sqrt3_ * cellXTotal_[k];
cellYTotal_[k] = 0.5 * sqrt3_ * cellXTotal_[k];
}

// Fill up the placement vectors
Expand Down Expand Up @@ -45,8 +45,11 @@ HGCalCellUV::HGCalCellUV(double waferSize, double separation, int32_t nFine, int

std::pair<int32_t, int32_t> HGCalCellUV::cellUVFromXY1(
double xloc, double yloc, int32_t placement, int32_t type, bool extend, bool debug) const {
if (type != 0)
type = 1;
//--- Reverse transform to placement=0, if placement index ≠ 6
double xloc1 = (placement >= HGCalCell::cellPlacementExtra) ? xloc : -xloc;
double cellY = (extend) ? cellYTotal_[type] : cellY_[type];
int rot = placement % HGCalCell::cellPlacementExtra;
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_}};
Expand All @@ -59,9 +62,9 @@ std::pair<int32_t, int32_t> HGCalCellUV::cellUVFromXY1(
double w = y;

//--- Rounding in u, v, w coordinates
int iu = std::floor(u / cellY_[type]) + 3 * (ncell_[type]) - 1;
int iv = std::floor(v / cellY_[type]) + 3 * (ncell_[type]);
int iw = std::floor(w / cellY_[type]) + 1;
int iu = std::floor(u / cellY) + 3 * (ncell_[type]) - 1;
int iv = std::floor(v / cellY) + 3 * (ncell_[type]);
int iw = std::floor(w / cellY) + 1;

int isv = (iu + iw) / 3;
int isu = (iv + iw) / 3;
Expand All @@ -87,6 +90,9 @@ std::pair<int32_t, int32_t> HGCalCellUV::cellUVFromXY2(
double xloc, double yloc, int32_t placement, int32_t type, bool extend, bool debug) const {
//--- Using multiple inequalities to find (u, v)
//--- Reverse transform to placement=0, if placement index ≠ 7
if (type != 0)
type = 1;
double cellY = (extend) ? cellYTotal_[type] : cellY_[type];
double xloc1 = (placement >= HGCalCell::cellPlacementExtra) ? xloc : -1 * xloc;
int rot = placement % HGCalCell::cellPlacementExtra;
static constexpr std::array<double, 6> fcos = {{cos60_, 1.0, cos60_, -cos60_, -1.0, -cos60_}};
Expand All @@ -95,8 +101,8 @@ std::pair<int32_t, int32_t> HGCalCellUV::cellUVFromXY2(
double y = xloc1 * fsin[rot] + yloc * fcos[rot];

int32_t u(-100), v(-100);
int ncell = (type != 0) ? ncell_[1] : ncell_[0];
double r = (type != 0) ? cellY_[1] : cellY_[0];
int ncell = ncell_[type];
double r = cellY;
double l1 = (y / r) + ncell - 1.0;
int l2 = std::floor((0.5 * y + 0.5 * x / sqrt3_) / r + ncell - 4.0 / 3.0);
int l3 = std::floor((x / sqrt3_) / r + ncell - 4.0 / 3.0);
Expand Down Expand Up @@ -154,17 +160,21 @@ std::pair<int32_t, int32_t> HGCalCellUV::cellUVFromXY3(
double xloc, double yloc, int32_t placement, int32_t type, bool extend, bool debug) const {
//--- Using Cube coordinates to find the (u, v)
//--- Reverse transform to placement=0, if placement index ≠ 6
if (type != 0)
type = 1;
double cellX = (extend) ? cellXTotal_[type] : cellX_[type];
double cellY = (extend) ? cellYTotal_[type] : cellY_[type];
double xloc1 = (placement >= HGCalCell::cellPlacementExtra) ? xloc : -xloc;
int rot = placement % HGCalCell::cellPlacementExtra;
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];
double x = xprime + cellX;
double y = yprime;

x = x / cellX_[type];
y = y / cellY_[type];
x = x / cellX;
y = y / cellY;

double cu = 2 * x / 3;
double cv = -x / 3 + y / 2;
Expand All @@ -187,7 +197,7 @@ std::pair<int32_t, int32_t> HGCalCellUV::cellUVFromXY3(
//--- Taking care of extending cells
int u(ncell_[type] + iv), v(ncell_[type] - 1 - iw);
double xcell = (1.5 * (v - u) + 0.5) * cellX_[type];
double ycell = (v + u - 2 * ncell_[type] + 1) * cellY_[type];
double ycell = (v + u - 2 * ncell_[type] + 1) * cellY;
if (v == -1) {
if ((yprime - sqrt3_ * xprime) < (ycell - sqrt3_ * xcell)) {
v += 1;
Expand Down Expand Up @@ -270,6 +280,10 @@ std::pair<int, int> HGCalCellUV::cellUVFromXY4(double xloc,

std::pair<int32_t, int32_t> HGCalCellUV::cellUVFromXY1(
double xloc, double yloc, int32_t placement, int32_t type, int32_t partial, bool extend, bool debug) const {
if (type != 0)
type = 1;
double cellX = (extend) ? cellXTotal_[type] : cellX_[type];
double cellY = (extend) ? cellYTotal_[type] : cellY_[type];
std::pair<int, int> uv = HGCalCellUV::cellUVFromXY1(xloc, yloc, placement, type, extend, debug);
int u = uv.first;
int v = uv.second;
Expand All @@ -281,8 +295,8 @@ std::pair<int32_t, int32_t> HGCalCellUV::cellUVFromXY1(
static constexpr std::array<double, 6> fsin = {{0.0, sin60_, sin60_, 0.0, -sin60_, -sin60_}};
double xprime = -1 * (xloc1 * fcos[rot] - yloc * fsin[rot]);
double yprime = xloc1 * fsin[rot] + yloc * fcos[rot];
double xcell = -1 * (1.5 * (v - u) + 0.5) * cellX_[type];
double ycell = (v + u - 2 * ncell_[type] + 1) * cellY_[type];
double xcell = -1 * (1.5 * (v - u) + 0.5) * cellX;
double ycell = (v + u - 2 * ncell_[type] + 1) * cellY;
if ((yprime - sqrt3_ * xprime) > (ycell - sqrt3_ * xcell)) {
u += -1;
} else {
Expand All @@ -299,8 +313,8 @@ std::pair<int32_t, int32_t> HGCalCellUV::cellUVFromXY1(
static constexpr std::array<double, 6> fsin = {{0.0, sin60_, sin60_, 0.0, -sin60_, -sin60_}};
double xprime = -1 * (xloc1 * fcos[rot] - yloc * fsin[rot]);
double yprime = xloc1 * fsin[rot] + yloc * fcos[rot];
double xcell = -1 * (1.5 * (v - u) + 0.5) * cellX_[type];
double ycell = (v + u - 2 * ncell_[type] + 1) * cellY_[type];
double xcell = -1 * (1.5 * (v - u) + 0.5) * cellX;
double ycell = (v + u - 2 * ncell_[type] + 1) * cellY;
if ((yprime - sqrt3_ * xprime) > (ycell - sqrt3_ * xcell)) {
u += 1;
v += 1;
Expand Down
32 changes: 26 additions & 6 deletions Geometry/HGCalCommonData/src/HGCalDDDConstants.cc
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,17 @@ bool HGCalDDDConstants::cellInLayer(int waferU, int waferV, int cellU, int cellV
auto ktr = hgpar_->waferInfoMap_.find(indx);
int part = (ktr != hgpar_->waferInfoMap_.end()) ? (ktr->second).part : HGCalTypes::WaferFull;
return HGCalWaferMask::goodCell(cellU, cellV, part);
} else if (mode_ == HGCalGeometryMode::Hexagon8Module) {
int indx = HGCalWaferIndex::waferIndex(lay, waferU, waferV);
auto ktr = hgpar_->waferInfoMap_.find(indx);
int thck(HGCalTypes::WaferFineThin), part(HGCalTypes::WaferFull), rotn(HGCalTypes::WaferOrient0);
if (ktr != hgpar_->waferInfoMap_.end()) {
thck = (ktr->second).type;
part = (ktr->second).part;
rotn = (ktr->second).orient;
}
int ncell = (thck == HGCalTypes::WaferFineThin) ? hgpar_->nCellsFine_ : hgpar_->nCellsCoarse_;
return HGCalWaferMask::goodCell(cellU, cellV, ncell, part, rotn);
} else if (waferHexagon8() || waferHexagon6()) {
const auto& xy = ((waferHexagon8()) ? locateCell(lay, waferU, waferV, cellU, cellV, reco, true, false, false)
: locateCell(cellU, lay, waferU, reco));
Expand Down Expand Up @@ -699,7 +710,7 @@ std::pair<float, float> HGCalDDDConstants::locateCell(
if (mode_ == HGCalGeometryMode::Hexagon8Cassette) {
ktr = hgpar_->waferInfoMap_.find(indx);
if (ktr != hgpar_->waferInfoMap_.end())
place = HGCalCell::cellPlacementIndex(1, HGCalTypes::layerType(layertype), (ktr->second).orient);
place = HGCalCell::cellPlacementIndex(1, HGCalTypes::layerFrontBack(layertype), (ktr->second).orient);
}
auto xy = hgcell_->cellUV2XY2(cellU, cellV, place, type);
x = xy.first;
Expand Down Expand Up @@ -842,11 +853,16 @@ bool HGCalDDDConstants::maskCell(const DetId& detId, int corners) const {
}
int wl = HGCalWaferIndex::waferIndex(layer, waferU, waferV);
auto itr = hgpar_->waferTypes_.find(wl);
auto ktr = hgpar_->waferInfoMap_.find(wl);
#ifdef EDM_ML_DEBUG
edm::LogVerbatim("HGCalGeom") << "MaskCell: Layer " << layer << " Wafer " << waferU << ":" << waferV << " Index "
<< wl << ":" << (itr != hgpar_->waferTypes_.end());
<< wl << ":" << (itr != hgpar_->waferTypes_.end()) << ":"
<< (ktr != hgpar_->waferInfoMap_.end());
#endif
if (itr != hgpar_->waferTypes_.end()) {
if (mode_ == HGCalGeometryMode::Hexagon8Cassette) {
int part = (ktr != hgpar_->waferInfoMap_.end()) ? (ktr->second).part : HGCalTypes::WaferFull;
mask = !(HGCalWaferMask::goodCell(u, v, part));
} else if (itr != hgpar_->waferTypes_.end()) {
if ((itr->second).second <= HGCalTypes::k_OffsetRotation)
mask = HGCalWaferMask::maskCell(u, v, N, (itr->second).first, (itr->second).second, corners);
else
Expand Down Expand Up @@ -1305,8 +1321,12 @@ void HGCalDDDConstants::waferFromPosition(const double x,
int indx = HGCalWaferIndex::waferIndex(layer, waferU, waferV);
auto ktr = hgpar_->waferInfoMap_.find(indx);
if (ktr != hgpar_->waferInfoMap_.end()) {
place = HGCalCell::cellPlacementIndex(1, HGCalTypes::layerType(layertype), (ktr->second).orient);
place = HGCalCell::cellPlacementIndex(1, HGCalTypes::layerFrontBack(layertype), (ktr->second).orient);
part = (ktr->second).part;
if (debug)
edm::LogVerbatim("HGCalGeom") << "waferfFromPosition: frontback " << layertype << ":"
<< HGCalTypes::layerFrontBack(layertype) << " Orient " << (ktr->second).orient
<< " place " << place << " part " << part;
}
}
cellHex(xx, yy, celltype, place, part, cellU, cellV, extend, debug);
Expand Down Expand Up @@ -1592,8 +1612,8 @@ void HGCalDDDConstants::cellHex(
double xloc, double yloc, int cellType, int place, int part, int& cellU, int& cellV, bool extend, bool debug) const {
if (mode_ == HGCalGeometryMode::Hexagon8Cassette) {
auto uv = (part == HGCalTypes::WaferFull)
? hgcellUV_->cellUVFromXY3(xloc, yloc, place, cellType, extend, debug)
: hgcellUV_->cellUVFromXY1(xloc, yloc, place, cellType, part, extend, debug);
? hgcellUV_->cellUVFromXY3(xloc, yloc, place, cellType, true, debug)
: hgcellUV_->cellUVFromXY1(xloc, yloc, place, cellType, part, true, debug);
cellU = uv.first;
cellV = uv.second;
} else if (waferHexagon8File()) {
Expand Down
17 changes: 8 additions & 9 deletions Geometry/HGCalCommonData/test/HGCalCellUVTester.cc
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// -*- C++ -*-
//
// Package: HGCalCellPositionTester
// Class: HGCalCellPositionTester
// Package: HGCalCellUVTester
// Class: HGCalCellUVTester
//
/**\class HGCalCellPositionTester HGCalCellPositionTester.cc
test/HGCalCellPositionTester.cc
/**\class HGCalCellUVTester HGCalCellUVTester.cc
test/HGCalCellUVTester.cc

Description: <one line class summary>

Expand All @@ -25,7 +25,6 @@
#include <vector>
#include <stdlib.h>
#include <cmath>
//#include <chrono>

// user include files
#include "FWCore/Framework/interface/Frameworkfwd.h"
Expand Down Expand Up @@ -94,10 +93,10 @@ void HGCalCellUVTester::analyze(const edm::Event&, const edm::EventSetup&) {
double c2 = yi - (xi / sqrt(3));
if ((xi < r2) && (xi > -1 * r2) && (c1 < R2) && (c1 > -1 * R2) && (c2 < R2) &&
(c2 > -1 * R2)) { //Only allowing (x, y) inside a wafer
std::pair<int32_t, int32_t> uv1 = wafer.cellUVFromXY1(xi, yi, placeIndex_, waferType_, 0, 0);
std::pair<int32_t, int32_t> uv2 = wafer.cellUVFromXY2(xi, yi, placeIndex_, waferType_, 0, 0);
std::pair<int32_t, int32_t> uv3 = wafer.cellUVFromXY3(xi, yi, placeIndex_, waferType_, 1, 0);
//std::pair<int32_t, int32_t> uv2 = wafer.HGCalCellUVFromXY2(xi, yi, placeIndex_, waferType_, 1, 0);
std::pair<int32_t, int32_t> uv1 = wafer.cellUVFromXY1(xi, yi, placeIndex_, waferType_, true, false);
std::pair<int32_t, int32_t> uv2 = wafer.cellUVFromXY2(xi, yi, placeIndex_, waferType_, true, false);
std::pair<int32_t, int32_t> uv3 = wafer.cellUVFromXY3(xi, yi, placeIndex_, waferType_, true, false);
//std::pair<int32_t, int32_t> uv2 = wafer.HGCalCellUVFromXY2(xi, yi, placeIndex_, waferType_, true, false);
std::string comment = ((uv1.first != uv3.first) || (uv2.first != uv3.first) || (uv1.second != uv3.second) ||
(uv2.second != uv3.second))
? " ***** ERROR *****"
Expand Down
146 changes: 146 additions & 0 deletions Geometry/HGCalCommonData/test/HGCalPartialCellTester.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
// -*- C++ -*-
//
// Package: HGCalCellPartialCellTester
// Class: HGCalCellPartialCellTester
//
/**\class HGCalCellPartialCellTester HGCalCellPartialCellTester.cc
test/HGCalCellPartialCellTester.cc

Description: <one line class summary>

Implementation:
<Notes on implementation>
*/
//
// Original Author: Sunanda Banerjee, Pruthvi Suryadevara
// Created: Mon 2022/06/10
//
//

// system include files
#include <fstream>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <stdlib.h>
#include <cmath>
//#include <chrono>

// user include files
#include "FWCore/Framework/interface/Frameworkfwd.h"
#include "FWCore/Framework/interface/one/EDAnalyzer.h"

#include "FWCore/Framework/interface/Event.h"
#include "FWCore/Framework/interface/EventSetup.h"
#include "FWCore/Framework/interface/MakerMacros.h"

#include "FWCore/MessageLogger/interface/MessageLogger.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
#include "Geometry/HGCalCommonData/interface/HGCalCellUV.h"
#include "Geometry/HGCalCommonData/interface/HGCalCell.h"
#include "Geometry/HGCalCommonData/interface/HGCalWaferMask.h"

class HGCalPartialCellTester : public edm::one::EDAnalyzer<> {
public:
explicit HGCalPartialCellTester(const edm::ParameterSet&);
~HGCalPartialCellTester() override = default;
static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);

void beginJob() override {}
void analyze(edm::Event const& iEvent, edm::EventSetup const&) override;
void endJob() override {}

private:
const double waferSize_;
const int waferType_;
const int placeIndex_;
const int partialType_;
const int nTrials_;
const int modeUV_;
};

HGCalPartialCellTester::HGCalPartialCellTester(const edm::ParameterSet& iC)
: waferSize_(iC.getParameter<double>("waferSize")),
waferType_(iC.getParameter<int>("waferType")),
placeIndex_(iC.getParameter<int>("cellPlacementIndex")),
partialType_(iC.getParameter<int>("partialType")),
nTrials_(iC.getParameter<int>("numbberOfTrials")),
modeUV_(iC.getParameter<int>("modeUV")) {
edm::LogVerbatim("HGCalGeom") << "Test positions for wafer of size " << waferSize_ << " Type " << waferType_
<< " Placement Index " << placeIndex_ << " mode " << modeUV_ << " with " << nTrials_
<< " trials";
}

void HGCalPartialCellTester::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
edm::ParameterSetDescription desc;
desc.add<double>("waferSize", 166.4408);
desc.add<int>("waferType", 1);
desc.add<int>("cellPlacementIndex", 2);
desc.add<int>("partialType", 11);
desc.add<int>("numbberOfTrials", 1000);
desc.add<int>("modeUV", 0);
descriptions.add("hgcalPartialCellTester", desc);
}

// ------------ method called to produce the data ------------
void HGCalPartialCellTester::analyze(const edm::Event&, const edm::EventSetup&) {
const int nFine(12), nCoarse(8);
double r2 = 0.5 * waferSize_;
double R2 = 2 * r2 / sqrt(3);
int nCells = (waferType_ == 0) ? nFine : nCoarse;
HGCalCellUV wafer(waferSize_, 0.0, nFine, nCoarse);
HGCalCell wafer2(waferSize_, nFine, nCoarse);
edm::LogVerbatim("HGCalGeom") << "\nHGCalPartialCellTester:: nCells " << nCells << " and placement index "
<< placeIndex_ << "\n\n";
auto start_t = std::chrono::high_resolution_clock::now();

if (modeUV_ <= 0) {
for (int i = 0; i < nTrials_; i++) {
double xi = (2 * r2 * static_cast<double>(rand()) / RAND_MAX) - r2;
double yi = (2 * R2 * static_cast<double>(rand()) / RAND_MAX) - R2;
double c1 = yi + xi / sqrt(3);
double c2 = yi - (xi / sqrt(3));
if ((xi < r2) && (xi > -1 * r2) && (c1 < R2) && (c1 > -1 * R2) && (c2 < R2) && (c2 > -1 * R2) &&
(xi > 0)) { //Only allowing (x, y) inside a partial wafer 11, placement index 2
std::pair<int32_t, int32_t> uv1 = wafer.cellUVFromXY1(xi, yi, placeIndex_, waferType_, true, false);
std::pair<int32_t, int32_t> uv5 =
wafer.cellUVFromXY1(xi, yi, placeIndex_, waferType_, partialType_, true, false);
std::string cellType = (HGCalWaferMask::goodCell(uv5.first, uv5.second, 11)) ? "Goodcell" : "Badcell";
std::string comment = ((uv1.first != uv5.first) || (uv1.second != uv5.second)) ? " ***** ERROR *****" : "";
edm::LogVerbatim("HGCalGeom") << cellType << " x = " << xi << " y = " << yi << " type = " << waferType_
<< " placement index " << placeIndex_ << " u " << uv1.first << ":" << uv5.first
<< ":" << uv5.first << " v " << uv1.second << ":" << uv5.second << ":"
<< uv5.second << ":" << comment;
}
}
} else {
for (int i = 0; i < nTrials_; i++) {
int ui = std::floor(2 * nCells * rand() / RAND_MAX);
int vi = std::floor(2 * nCells * rand() / RAND_MAX);
if ((ui < 2 * nCells) && (vi < 2 * nCells) && ((vi - ui) < nCells) && ((ui - vi) <= nCells) &&
HGCalWaferMask::goodCell(ui, vi, partialType_)) {
//Only allowing (U, V) inside a wafer
std::pair<double, double> xy1 = wafer2.cellUV2XY2(ui, vi, placeIndex_, waferType_);
std::pair<int32_t, int32_t> uv1 =
wafer.cellUVFromXY1(xy1.first, xy1.second, placeIndex_, waferType_, true, false);
std::pair<int32_t, int32_t> uv5 =
wafer.cellUVFromXY1(xy1.first, xy1.second, placeIndex_, waferType_, partialType_, true, false);
std::string comment = ((uv1.first != ui) || (uv1.second != vi) || (uv5.first != ui) || (uv5.second != vi))
? " ***** ERROR *****"
: "";
edm::LogVerbatim("HGCalGeom") << "u = " << ui << " v = " << vi << " type = " << waferType_
<< " placement index " << placeIndex_ << " x " << xy1.first << " ,y "
<< xy1.second << " u " << uv5.first << " v " << uv5.second << comment;
}
}
}
auto end_t = std::chrono::high_resolution_clock::now();
auto diff_t = end_t - start_t;
edm::LogVerbatim("HGCalGeom") << "Execution time for " << nTrials_
<< " events = " << std::chrono::duration<double, std::milli>(diff_t).count() << " ms";
}

// define this as a plug-in
DEFINE_FWK_MODULE(HGCalPartialCellTester);
Loading