Skip to content
Merged
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
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);
145 changes: 145 additions & 0 deletions Geometry/HGCalCommonData/test/HGCalPartialWaferTester.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
// system include files
#include <memory>
#include <string>
#include <vector>
#include <cmath>

// 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/HGCalDDDConstants.h"
#include "Geometry/HGCalCommonData/interface/HGCalParameters.h"
#include "Geometry/HGCalCommonData/interface/HGCalWaferIndex.h"
#include "Geometry/HGCalCommonData/interface/HGCalWaferMask.h"
#include "Geometry/Records/interface/IdealGeometryRecord.h"

class HGCalPartialWaferTester : public edm::one::EDAnalyzer<> {
public:
explicit HGCalPartialWaferTester(const edm::ParameterSet&);
~HGCalPartialWaferTester() 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 std::string nameSense_;
const std::vector<int> orientations_, partialTypes_;
const int nTrials_;
const edm::ESGetToken<HGCalDDDConstants, IdealGeometryRecord> dddToken_;
};

HGCalPartialWaferTester::HGCalPartialWaferTester(const edm::ParameterSet& iC)
: nameSense_(iC.getParameter<std::string>("nameSense")),
orientations_(iC.getParameter<std::vector<int>>("waferOrientations")),
partialTypes_(iC.getParameter<std::vector<int>>("partialTypes")),
nTrials_(iC.getParameter<int>("numberOfTrials")),
dddToken_(esConsumes<HGCalDDDConstants, IdealGeometryRecord>(edm::ESInputTag{"", nameSense_})) {
edm::LogVerbatim("HGCalGeom") << "Test positions for " << partialTypes_.size() << " partial wafer types "
<< " and " << orientations_.size() << " Orientations for " << nameSense_;
}

void HGCalPartialWaferTester::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
edm::ParameterSetDescription desc;
std::vector<int> orients = {HGCalTypes::WaferOrient0,
HGCalTypes::WaferOrient1,
HGCalTypes::WaferOrient2,
HGCalTypes::WaferOrient3,
HGCalTypes::WaferOrient4,
HGCalTypes::WaferOrient5};
std::vector<int> types = {HGCalTypes::WaferLDTop,
HGCalTypes::WaferLDBottom,
HGCalTypes::WaferLDLeft,
HGCalTypes::WaferLDRight,
HGCalTypes::WaferLDFive,
HGCalTypes::WaferLDThree,
HGCalTypes::WaferHDTop,
HGCalTypes::WaferHDBottom,
HGCalTypes::WaferHDLeft,
HGCalTypes::WaferHDRight,
HGCalTypes::WaferHDFive};
desc.add<std::string>("nameSense", "HGCalHESiliconSensitive");
desc.add<std::vector<int>>("waferOrientations", orients);
desc.add<std::vector<int>>("partialTypes", types);
desc.add<int>("numberOfTrials", 1000);
descriptions.add("hgcalPartialWaferTester", desc);
}

void HGCalPartialWaferTester::analyze(const edm::Event&, const edm::EventSetup& iSetup) {
const HGCalDDDConstants& hgdc = iSetup.getData(dddToken_);
const bool reco(true), all(true), norot(false), debug1(false), debug2(false), extend(true);
for (const auto& partialType : partialTypes_) {
for (const auto& orientation : orientations_) {
int indx(-1), type(-1);
for (auto itr = hgdc.getParameter()->waferInfoMap_.begin(); itr != hgdc.getParameter()->waferInfoMap_.end();
++itr) {
if (((itr->second).part == partialType) && ((itr->second).orient == orientation)) {
indx = itr->first;
type = (itr->second).type;
break;
}
}

if (indx > 0) {
int alltry(0), error(0);
int layer = HGCalWaferIndex::waferLayer(indx);
int waferU = HGCalWaferIndex::waferU(indx);
int waferV = HGCalWaferIndex::waferV(indx);
auto xy = hgdc.waferPosition(layer, waferU, waferV, true, false);
edm::LogVerbatim("HGCalGeom") << "\n\nPartial Type " << partialType << " Orientation " << orientation
<< " Wafer " << waferU << ":" << waferV << " in layer " << layer << " at "
<< xy.first << ":" << xy.second << "\n\n";
int nCells = (type == 0) ? HGCSiliconDetId::HGCalFineN : HGCSiliconDetId::HGCalCoarseN;
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)) {
++alltry;
auto xy = hgdc.locateCell(layer, waferU, waferV, ui, vi, reco, all, norot, debug1);
int lay(layer), cU(0), cV(0), wType(-1), wU(0), wV(0);
double wt(0);
hgdc.waferFromPosition(HGCalParameters::k_ScaleToDDD * xy.first,
HGCalParameters::k_ScaleToDDD * xy.second,
lay,
wU,
wV,
cU,
cV,
wType,
wt,
extend,
debug2);
bool ok =
((wType == type) && (layer == lay) && (waferU == wU) && (waferV == wV) && (ui == cU) && (vi == cV));
std::string comment = (ok) ? "" : " ***** ERROR *****";
edm::LogVerbatim("HGCalGeom")
<< "Layer " << layer << ":" << lay << " waferU " << waferU << ":" << wU << " waferV " << waferV << ":"
<< wV << " Type " << type << ":" << wType << " cellU " << ui << ":" << cU << " cellV " << vi << ":"
<< cV << " position " << xy.first << ":" << xy.second << comment;
if (!ok)
++error;
}
}
edm::LogVerbatim("HGCalGeom") << "\n\nFound " << error << " errors among " << alltry << ":" << nTrials_
<< " trials for partial type " << partialType << " orientation " << orientation
<< " of " << nameSense_;
} else {
edm::LogVerbatim("HGCalGeom") << "\n\nCannot find a wafer of type " << partialType << " and orientation "
<< orientation << " for " << nameSense_;
}
}
}
}

// define this as a plug-in
DEFINE_FWK_MODULE(HGCalPartialWaferTester);
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import FWCore.ParameterSet.Config as cms

process = cms.Process("PROD")
process.load("SimGeneral.HepPDTESSource.pdt_cfi")
process.load('FWCore.MessageService.MessageLogger_cfi')

if hasattr(process,'MessageLogger'):
process.MessageLogger.HGCalGeom=dict()

process.load("IOMC.RandomEngine.IOMC_cff")
process.RandomNumberGeneratorService.generator.initialSeed = 456789

process.source = cms.Source("EmptySource")

process.generator = cms.EDProducer("FlatRandomEGunProducer",
PGunParameters = cms.PSet(
PartID = cms.vint32(14),
MinEta = cms.double(-3.5),
MaxEta = cms.double(3.5),
MinPhi = cms.double(-3.14159265359),
MaxPhi = cms.double(3.14159265359),
MinE = cms.double(9.99),
MaxE = cms.double(10.01)
),
AddAntiParticle = cms.bool(False),
Verbosity = cms.untracked.int32(0),
firstRun = cms.untracked.uint32(1)
)

process.maxEvents = cms.untracked.PSet(
input = cms.untracked.int32(1)
)

process.SimpleMemoryCheck = cms.Service("SimpleMemoryCheck",
ignoreTotal = cms.untracked.int32(1),
moduleMemorySummary = cms.untracked.bool(True)
)

process.load("Geometry.HGCalCommonData.hgcalPartialCellTester_cfi")


process.p1 = cms.Path(process.generator*process.hgcalPartialCellTester)
Loading