-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add the testing code for partial wafer positioning for V17 HGCal Geom…
…etry as done in #38345 (now closed)
- Loading branch information
Sunanda
committed
Jun 13, 2022
1 parent
9e90536
commit 2aabc03
Showing
6 changed files
with
356 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
146 changes: 146 additions & 0 deletions
146
Geometry/HGCalCommonData/test/HGCalPartialCellTester.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
119 changes: 119 additions & 0 deletions
119
Geometry/HGCalCommonData/test/HGCalPartialWaferTester.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
// 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 int orientation_, partialType_, nTrials_; | ||
const edm::ESGetToken<HGCalDDDConstants, IdealGeometryRecord> dddToken_; | ||
}; | ||
|
||
HGCalPartialWaferTester::HGCalPartialWaferTester(const edm::ParameterSet& iC) | ||
: nameSense_(iC.getParameter<std::string>("NameSense")), | ||
orientation_(iC.getParameter<int>("waferOrientation")), | ||
partialType_(iC.getParameter<int>("partialType")), | ||
nTrials_(iC.getParameter<int>("numberOfTrials")), | ||
dddToken_(esConsumes<HGCalDDDConstants, IdealGeometryRecord>(edm::ESInputTag{"", nameSense_})) { | ||
edm::LogVerbatim("HGCalGeom") << "Test positions for partial wafer type " << partialType_ << " Orientation " | ||
<< orientation_ << " for " << nameSense_; | ||
} | ||
|
||
void HGCalPartialWaferTester::fillDescriptions(edm::ConfigurationDescriptions& descriptions) { | ||
edm::ParameterSetDescription desc; | ||
desc.add<std::string>("NameSense", "HGCalHESiliconSensitive"); | ||
desc.add<int>("waferOrientation", 0); | ||
desc.add<int>("partialType", 11); | ||
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_); | ||
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 all(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") << "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_)) { | ||
++all; | ||
auto xy = hgdc.locateCell(layer, waferU, waferV, ui, vi, true, true, false, false); | ||
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, | ||
false, | ||
true); | ||
std::string comment = | ||
((wType == type) && (layer == lay) && (waferU == wU) && (waferV == wV) && (ui == cU) && (vi == cV)) | ||
? "" | ||
: " ***** 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 (comment != "") | ||
++error; | ||
} | ||
} | ||
edm::LogVerbatim("HGCalGeom") << "\n\nFound " << error << " errors among " << all << ":" << nTrials_ << " trials"; | ||
} 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); |
42 changes: 42 additions & 0 deletions
42
Geometry/HGCalCommonData/test/python/testHGCalPartialCellTester_cfg.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
38 changes: 38 additions & 0 deletions
38
Geometry/HGCalCommonData/test/python/testHGCalPartialWaferTester_cfg.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import FWCore.ParameterSet.Config as cms | ||
|
||
process = cms.Process("PROD") | ||
process.load("SimGeneral.HepPDTESSource.pdt_cfi") | ||
process.load("Configuration.Geometry.GeometryExtended2026D92_cff") | ||
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.load("Geometry.HGCalCommonData.hgcalPartialWaferTester_cfi") | ||
|
||
|
||
process.p1 = cms.Path(process.generator*process.hgcalPartialWaferTester) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters