Skip to content

Commit

Permalink
Merge pull request #30473 from silviodonato/revert-30458-revert-30323…
Browse files Browse the repository at this point in the history
…-Run4-hgx247

Restore "Run4-hgx247 Add some new features for HGCal" (#30323)
  • Loading branch information
cmsbuild committed Jul 1, 2020
2 parents 2161470 + c81f28d commit 0ad2f1c
Show file tree
Hide file tree
Showing 10 changed files with 196 additions and 12 deletions.
1 change: 1 addition & 0 deletions Geometry/CaloTopology/interface/HGCalTopology.h
Expand Up @@ -85,6 +85,7 @@ class HGCalTopology : public CaloSubdetectorTopology {

///Is this a valid cell id
bool valid(const DetId& id) const override;
bool valid(const DetId& id, int cornerMin) const;
bool validHashIndex(uint32_t ix) const { return (ix < kSizeForDenseIndexing); }

unsigned int totalModules() const { return kSizeForDenseIndexing; }
Expand Down
11 changes: 11 additions & 0 deletions Geometry/CaloTopology/src/HGCalTopology.cc
Expand Up @@ -477,6 +477,17 @@ bool HGCalTopology::valid(const DetId& idin) const {
return flag;
}

bool HGCalTopology::valid(const DetId& idin, int cornerMin) const {
if ((mode_ == HGCalGeometryMode::Hexagon8) || (mode_ == HGCalGeometryMode::Hexagon8Full)) {
HGCalTopology::DecodedDetId id = decode(idin);
bool mask = (cornerMin < HGCalTypes::WaferCornerMin) ? false : hdcons_.maskCell(idin, cornerMin);
bool flag = ((idin.det() == det_) && hdcons_.isValidHex8(id.iLay, id.iSec1, id.iSec2, id.iCell1, id.iCell2, true));
return (flag && (!mask));
} else {
return valid(idin);
}
}

DetId HGCalTopology::offsetBy(const DetId startId, int nrStepsX, int nrStepsY) const {
if (startId.det() == DetId::Forward && startId.subdetId() == (int)(subdet_)) {
DetId id = changeXY(startId, nrStepsX, nrStepsY);
Expand Down
6 changes: 5 additions & 1 deletion Geometry/HGCalCommonData/interface/HGCalDDDConstants.h
Expand Up @@ -14,7 +14,9 @@
#include <string>
#include <vector>
#include "DataFormats/DetId/interface/DetId.h"
#include "DataFormats/ForwardDetId/interface/HGCSiliconDetId.h"
#include "Geometry/HGCalCommonData/interface/HGCalGeometryMode.h"
#include "Geometry/HGCalCommonData/interface/HGCalGeomTools.h"
#include "Geometry/HGCalCommonData/interface/HGCalParameters.h"
#include "Geometry/HGCalCommonData/interface/HGCalTypes.h"

Expand Down Expand Up @@ -66,7 +68,7 @@ class HGCalDDDConstants {
int getUVMax(int type) const { return ((type == 0) ? hgpar_->nCellsFine_ : hgpar_->nCellsCoarse_); }
bool isHalfCell(int waferType, int cell) const;
bool isValidHex(int lay, int mod, int cell, bool reco) const;
bool isValidHex8(int lay, int modU, int modV, int cellU, int cellV) const;
bool isValidHex8(int lay, int modU, int modV, int cellU, int cellV, bool fullAndPart = false) const;
bool isValidTrap(int lay, int ieta, int iphi) const;
int lastLayer(bool reco) const;
int layerIndex(int lay, bool reco) const;
Expand All @@ -75,6 +77,7 @@ class HGCalDDDConstants {
std::pair<float, float> locateCell(int cell, int lay, int type, bool reco) const;
std::pair<float, float> locateCell(
int lay, int waferU, int waferV, int cellU, int cellV, bool reco, bool all, bool debug = false) const;
std::pair<float, float> locateCell(const HGCSiliconDetId&, bool debug = false) const;
std::pair<float, float> locateCellHex(int cell, int wafer, bool reco) const;
std::pair<float, float> locateCellTrap(int lay, int ieta, int iphi, bool reco) const;
int levelTop(int ind = 0) const { return hgpar_->levelT_[ind]; }
Expand Down Expand Up @@ -163,6 +166,7 @@ class HGCalDDDConstants {
bool waferInLayerTest(int wafer, int lay, bool full) const;
std::pair<double, double> waferPosition(int waferU, int waferV, bool reco) const;

HGCalGeomTools geomTools_;
const double k_horizontalShift = 1.0;
const float dPhiMin = 0.02;
typedef std::array<std::vector<int32_t>, 2> Simrecovecs;
Expand Down
2 changes: 1 addition & 1 deletion Geometry/HGCalCommonData/interface/HGCalGeomTools.h
Expand Up @@ -33,7 +33,7 @@ class HGCalGeomTools {
std::vector<double> const& slope);
static double radius(
double z, int layer0, int layerf, std::vector<double> const& zFront, std::vector<double> const& rFront);
std::pair<double, double> shiftXY(int waferPosition, double waferSize);
std::pair<double, double> shiftXY(int waferPosition, double waferSize) const;
static double slope(double z, std::vector<double> const& zFront, std::vector<double> const& slope);
static std::pair<double, double> zradius(double z1,
double z2,
Expand Down
2 changes: 2 additions & 0 deletions Geometry/HGCalCommonData/interface/HGCalTypes.h
Expand Up @@ -58,6 +58,8 @@ class HGCalTypes {
WaferOut = 99
};

static constexpr int32_t WaferCornerMin = 3;

enum TileType { TileFine = 0, TileCoarseCast = 1, TileCoarseMould = 2 };

enum TileSiPMType { SiPMUnknown = 0, SiPMSmall = 2, SiPMLarge = 4 };
Expand Down
9 changes: 4 additions & 5 deletions Geometry/HGCalCommonData/python/testHGCalV13XML_cfi.py
Expand Up @@ -11,12 +11,12 @@
'Geometry/CMSCommonData/data/cms/2026/v4/cms.xml',
'Geometry/CMSCommonData/data/eta3/etaMax.xml',
'Geometry/CMSCommonData/data/cmsMother.xml',
'Geometry/CMSCommonData/data/caloBase/2026/v3/caloBase.xml',
'Geometry/CMSCommonData/data/caloBase/2026/v4/caloBase.xml',
'Geometry/CMSCommonData/data/cmsCalo.xml',
'Geometry/CMSCommonData/data/beampipe/2026/v1/beampipe.xml',
'Geometry/CMSCommonData/data/cmsBeam/2026/v1/cmsBeam.xml',
'Geometry/CMSCommonData/data/cavernData/2017/v1/cavernData.xml',
'Geometry/CMSCommonData/data/muonBase/2026/v4/muonBase.xml',
'Geometry/CMSCommonData/data/muonBase/2026/v5/muonBase.xml',
'Geometry/CMSCommonData/data/cmsMuon.xml',
'Geometry/CMSCommonData/data/mgnt.xml',
'Geometry/CMSCommonData/data/muonMB.xml',
Expand All @@ -31,14 +31,13 @@
'Geometry/HcalCommonData/data/hcal/v2/hcalalgo.xml',
'Geometry/HcalCommonData/data/hcalbarrelalgo.xml',
'Geometry/HcalCommonData/data/hcalcablealgo/v2/hcalcablealgo.xml',
'Geometry/HcalCommonData/data/hcalcablealgo/v2/hcalcablealgo.xml',
'Geometry/HcalCommonData/data/hcalouteralgo.xml',
'Geometry/HcalCommonData/data/hcalforwardalgo.xml',
'Geometry/HcalCommonData/data/hcalSimNumbering/NoHE/hcalSimNumbering.xml',
'Geometry/HcalCommonData/data/hcalRecNumbering/NoHE/hcalRecNumbering.xml',
'Geometry/HcalCommonData/data/average/hcalforwardmaterial.xml',
'Geometry/HGCalCommonData/data/hgcalMaterial/v1/hgcalMaterial.xml',
'Geometry/HGCalCommonData/data/hgcal/v12/hgcal.xml',
'Geometry/HGCalCommonData/data/hgcal/v13/hgcal.xml',
'Geometry/HGCalCommonData/data/hgcalEE/v12/hgcalEE.xml',
'Geometry/HGCalCommonData/data/hgcalcell/v9/hgcalcell.xml',
'Geometry/HGCalCommonData/data/hgcalwafer/v9/hgcalwafer.xml',
Expand All @@ -56,7 +55,7 @@
'Geometry/MuonCommonData/data/muonYoke/2021/v3/muonYoke.xml',
'Geometry/MuonCommonData/data/csc/2021/v2/csc.xml',
'Geometry/MuonCommonData/data/mfshield/2017/v2/mfshield.xml',
'Geometry/MuonCommonData/data/mf/2026/v5/mf.xml',
'Geometry/MuonCommonData/data/mf/2026/v6/mf.xml',
'Geometry/MuonCommonData/data/rpcf/2026/v3/rpcf.xml',
'Geometry/MuonCommonData/data/gemf/TDR_BaseLine/gemf.xml',
'Geometry/MuonCommonData/data/gem11/TDR_BaseLine/gem11.xml',
Expand Down
45 changes: 41 additions & 4 deletions Geometry/HGCalCommonData/src/HGCalDDDConstants.cc
Expand Up @@ -491,7 +491,7 @@ bool HGCalDDDConstants::isValidHex(int lay, int mod, int cell, bool reco) const
return result;
}

bool HGCalDDDConstants::isValidHex8(int layer, int modU, int modV, int cellU, int cellV) const {
bool HGCalDDDConstants::isValidHex8(int layer, int modU, int modV, int cellU, int cellV, bool fullAndPart) const {
// Check validity for a layer|wafer|cell of post-TDR version
int indx = HGCalWaferIndex::waferIndex(layer, modU, modV);
auto itr = hgpar_->typesInLayers_.find(indx);
Expand Down Expand Up @@ -519,9 +519,18 @@ bool HGCalDDDConstants::isValidHex8(int layer, int modU, int modV, int cellU, in
if (((cellV - cellU) >= N) || ((cellU - cellV) > N))
return false;

auto ktr = hgpar_->waferTypes_.find(indx);
if (ktr != hgpar_->waferTypes_.end())
return false;
if (fullAndPart) {
auto ktr = hgpar_->waferTypes_.find(indx);
if (ktr != hgpar_->waferTypes_.end()) {
if (hgpar_->waferMaskMode_ > 0) {
if (ktr->second.first == HGCalTypes::WaferOut)
return false;
} else {
if (ktr->second.first < HGCalTypes::WaferCornerMin)
return false;
}
}
}

// edm::LogVerbatim("HGCalGeom") << "Corners " << (ktr->second).first << ":" << waferVirtual(layer,modU,modV);
int type = ((itr == hgpar_->typesInLayers_.end()) ? 2 : hgpar_->waferTypeL_[itr->second]);
Expand Down Expand Up @@ -640,6 +649,34 @@ std::pair<float, float> HGCalDDDConstants::locateCell(
return std::make_pair(x, y);
}

std::pair<float, float> HGCalDDDConstants::locateCell(const HGCSiliconDetId& id, bool debug) const {
int lay(id.layer());
double r = 0.5 * (hgpar_->waferSize_ + hgpar_->sensorSeparation_);
double R = 2.0 * r / sqrt3_;
int ncells = (id.type() == 0) ? hgpar_->nCellsFine_ : hgpar_->nCellsCoarse_;
int n2 = ncells / 2;
auto xyoff = geomTools_.shiftXY(hgpar_->layerCenter_[lay - 1], (2.0 * r));
double xpos = xyoff.first + ((-2 * id.waferU() + id.waferV()) * r);
double ypos = xyoff.second + (1.5 * id.waferV() * R);
#ifdef EDM_ML_DEBUG
if (debug)
edm::LogVerbatim("HGCalGeom") << "LocateCell " << id << " Lay " << lay << " r:R " << r << ":" << R << " N "
<< ncells << ":" << n2 << " Off " << xyoff.first << ":" << xyoff.second << " Pos "
<< xpos << ":" << ypos;
#endif
double R1 = hgpar_->waferSize_ / (3.0 * ncells);
double r1 = 0.5 * R1 * sqrt3_;
xpos += ((1.5 * (id.cellV() - ncells) + 1.0) * R1);
ypos += ((id.cellU() - 0.5 * id.cellV() - n2) * 2 * r1);
#ifdef EDM_ML_DEBUG
if (debug)
edm::LogVerbatim("HGCalGeom") << "LocateCell r1:R1 " << r1 << ":" << R1 << " dx:dy "
<< ((1.5 * (id.cellV() - ncells) + 1.0) * R1) << ":"
<< ((id.cellU() - 0.5 * id.cellV() - n2) * 2 * r1) << " Pos " << xpos << ":" << ypos;
#endif
return std::make_pair(xpos * id.zside(), ypos);
}

std::pair<float, float> HGCalDDDConstants::locateCellHex(int cell, int wafer, bool reco) const {
float x(0), y(0);
if (hgpar_->waferTypeT_[wafer] - 1 == HGCSiliconDetId::HGCalFine) {
Expand Down
2 changes: 1 addition & 1 deletion Geometry/HGCalCommonData/src/HGCalGeomTools.cc
Expand Up @@ -163,7 +163,7 @@ double HGCalGeomTools::radius(
return r;
}

std::pair<double, double> HGCalGeomTools::shiftXY(int waferPosition, double waferSize) {
std::pair<double, double> HGCalGeomTools::shiftXY(int waferPosition, double waferSize) const {
double dx(0), dy(0);
switch (waferPosition) {
case (HGCalTypes::CornerCenterYp): {
Expand Down
81 changes: 81 additions & 0 deletions Geometry/HGCalGeometry/test/HGCalGeomLocatorTester.cc
@@ -0,0 +1,81 @@
#include <iostream>
#include <string>
#include <vector>

#include "FWCore/ParameterSet/interface/ParameterSet.h"
#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 "Geometry/Records/interface/IdealGeometryRecord.h"
#include "Geometry/HGCalCommonData/interface/HGCalGeometryMode.h"
#include "Geometry/HGCalGeometry/interface/HGCalGeometry.h"
#include "DataFormats/ForwardDetId/interface/HGCSiliconDetId.h"
#include "CoralBase/Exception.h"

class HGCalGeomLocaterTester : public edm::one::EDAnalyzer<> {
public:
explicit HGCalGeomLocaterTester(const edm::ParameterSet&);

void analyze(edm::Event const& iEvent, edm::EventSetup const&) override;

private:
void doTest(const HGCalGeometry* geom, DetId::Detector det);

std::string name_;
edm::ESGetToken<HGCalGeometry, IdealGeometryRecord> geomToken_;
};

HGCalGeomLocaterTester::HGCalGeomLocaterTester(const edm::ParameterSet& iC)
: name_{iC.getParameter<std::string>("Detector")},
geomToken_{esConsumes<HGCalGeometry, IdealGeometryRecord>(edm::ESInputTag{"", name_})} {}

void HGCalGeomLocaterTester::analyze(const edm::Event&, const edm::EventSetup& iSetup) {
const auto& geomR = iSetup.getData(geomToken_);
const HGCalGeometry* geom = &geomR;
HGCalGeometryMode::GeometryMode mode = geom->topology().dddConstants().geomMode();
if ((mode == HGCalGeometryMode::Hexagon8) || (mode == HGCalGeometryMode::Hexagon8Full)) {
DetId::Detector det;
if (name_ == "HGCalHESiliconSensitive")
det = DetId::HGCalHSi;
else
det = DetId::HGCalEE;
std::cout << "Perform test for " << name_ << " Detector " << det << " Mode " << mode << std::endl;
doTest(geom, det);
}
}

void HGCalGeomLocaterTester::doTest(const HGCalGeometry* geom, DetId::Detector det) {
const std::vector<DetId>& ids = geom->getValidDetIds();
std::cout << "doTestWafer:: " << ids.size() << " valid ids for " << geom->cellElement() << std::endl;
const double tol = 0.001;
const unsigned int step = 10;
int all(0), good(0), bad(0);
for (unsigned int k = 0; k < ids.size(); k += step) {
++all;
HGCSiliconDetId id(ids[k]);
std::cout << "ID[" << k << "] " << id;
GlobalPoint global = geom->getPosition(id);
auto waferxy = geom->topology().dddConstants().locateCell(id, false);
double dx = global.x() - waferxy.first;
double dy = global.y() - waferxy.second;
std::cout << " position (" << global.x() << ", " << global.y() << ", " << global.z() << ") waferXY ("
<< waferxy.first << ", " << waferxy.second << ") Delta (" << dx << ", " << dy << ")";
if ((std::abs(dx) > tol) || (std::abs(dy) > tol)) {
std::cout << "***** ERROR *****" << std::endl;
++bad;
geom->topology().dddConstants().locateCell(id, true);
} else {
std::cout << std::endl;
++good;
}
}
std::cout << "\n\nStudied " << all << " (" << ids.size() << ") IDs of which " << good << " are good and " << bad
<< " are bad\n\n\n\n";
}

//define this as a plug-in
DEFINE_FWK_MODULE(HGCalGeomLocaterTester);
49 changes: 49 additions & 0 deletions Geometry/HGCalGeometry/test/python/testHGCalGeomLocator_cfg.py
@@ -0,0 +1,49 @@
import FWCore.ParameterSet.Config as cms

process = cms.Process("PROD")
process.load("SimGeneral.HepPDTESSource.pdt_cfi")

process.load("Configuration.Geometry.GeometryExtended2026D41Reco_cff")
#process.load("Geometry.HGCalCommonData.testHGCV12XML_cfi")
#process.load("Geometry.HGCalCommonData.hgcalParametersInitialization_cfi")
#process.load("Geometry.HGCalCommonData.hgcalNumberingInitialization_cfi")
#process.load("Geometry.CaloEventSetup.HGCalV9Topology_cfi")
#process.load("Geometry.HGCalGeometry.HGCalGeometryESProducer_cfi")
process.load('FWCore.MessageService.MessageLogger_cfi')

if hasattr(process,'MessageLogger'):
process.MessageLogger.categories.append('HGCalGeom')

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.prodEE = cms.EDAnalyzer("HGCalGeomLocaterTester",
Detector = cms.string("HGCalEESensitive"),
)

process.prodHEF = process.prodEE.clone(
Detector = "HGCalHESiliconSensitive",
)

process.p1 = cms.Path(process.generator*process.prodEE*process.prodHEF)

0 comments on commit 0ad2f1c

Please sign in to comment.