Skip to content

Commit 7ea9eb4

Browse files
authored
Merge pull request #48532 from Pruthvi-ch/DDD_test
DDD testing
2 parents 2d93b3c + a13555d commit 7ea9eb4

File tree

3 files changed

+294
-0
lines changed

3 files changed

+294
-0
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
8 2 -1 1 5 0 4 8 842.30 2.37 880.67 -27.84 880.67 -27.84
2+
8 2 -1 1 5 0 11 11 842.30 2.37 807.42 -21.80 807.42 -21.80
3+
8 2 -1 1 5 0 15 11 842.30 2.37 765.40 2.37 765.56 2.37
4+
8 2 -1 1 5 0 15 14 842.30 2.37 765.52 -33.76 765.56 -33.88
5+
8 2 -1 1 5 0 15 15 842.30 2.37 767.75 -44.48 765.56 -45.97
6+
8 1 -1 6 5 0 6 10 842.30 2.37 859.74 44.66 859.74 44.66
7+
8 1 -1 6 5 0 11 10 842.30 2.37 807.42 14.45 807.42 14.45
8+
8 1 -1 6 5 0 11 15 842.30 2.37 808.22 73.48 807.42 74.87
9+
8 1 -1 6 5 0 6 13 842.30 2.37 859.82 81.05 859.74 80.92
Lines changed: 207 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,207 @@
1+
// -*- C++ -*-
2+
//
3+
// Package: HGCalTestDDDCons.cc
4+
// Class: HGCalTestDDDCons
5+
//
6+
/**\class HGCalTestDDDCons HGCalTestDDDCons.cc
7+
test/HGCalTestDDDCons.cc
8+
9+
Description: <one line class summary>
10+
11+
Implementation:
12+
<Notes on implementation>
13+
*/
14+
//
15+
// Original Author: Pruthvi Suryadevara
16+
// Created: Mon 2025/7/11
17+
//
18+
//
19+
20+
// system include files
21+
#include <fstream>
22+
#include <iostream>
23+
#include <sstream>
24+
#include <string>
25+
#include <vector>
26+
#include <cmath>
27+
28+
// user include files
29+
#include "FWCore/Framework/interface/Frameworkfwd.h"
30+
#include "FWCore/Framework/interface/one/EDAnalyzer.h"
31+
#include "FWCore/Framework/interface/Event.h"
32+
#include "FWCore/Framework/interface/EventSetup.h"
33+
#include "FWCore/Framework/interface/MakerMacros.h"
34+
#include "FWCore/MessageLogger/interface/MessageLogger.h"
35+
#include "FWCore/ParameterSet/interface/FileInPath.h"
36+
#include "FWCore/ParameterSet/interface/ParameterSet.h"
37+
#include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
38+
#include "FWCore/Utilities/interface/transform.h"
39+
40+
#include "DataFormats/DetId/interface/DetId.h"
41+
#include "DataFormats/ForwardDetId/interface/HGCSiliconDetId.h"
42+
#include "Geometry/HGCalCommonData/interface/HGCalDDDConstants.h"
43+
#include "Geometry/HGCalCommonData/interface/HGCalGeomUtils.h"
44+
#include "Geometry/Records/interface/IdealGeometryRecord.h"
45+
#include "Geometry/HGCalCommonData/interface/HGCalCell.h"
46+
#include "Geometry/HGCalCommonData/interface/HGCalWaferIndex.h"
47+
48+
class HGCalTestDDDCons : public edm::one::EDAnalyzer<edm::one::WatchRuns> {
49+
public:
50+
explicit HGCalTestDDDCons(const edm::ParameterSet &);
51+
~HGCalTestDDDCons() override = default;
52+
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions);
53+
54+
void beginJob() override {}
55+
void beginRun(edm::Run const &, edm::EventSetup const &) override;
56+
void analyze(edm::Event const &iEvent, edm::EventSetup const &) override {}
57+
void endRun(edm::Run const &, edm::EventSetup const &) override {}
58+
void endJob() override {}
59+
60+
private:
61+
const std::vector<std::string> nameDetectors_;
62+
const std::string fileName_;
63+
const std::vector<edm::ESGetToken<HGCalDDDConstants, IdealGeometryRecord>> tok_hgcal_;
64+
int size;
65+
std::vector<const HGCalDDDConstants *> hgcCons_;
66+
std::vector<std::pair<DetId, uint32_t>> detIds_;
67+
std::vector<double> xwafer_, ywafer_, xcell_, ycell_, xcellOff_, ycellOff_;
68+
};
69+
70+
HGCalTestDDDCons::HGCalTestDDDCons(const edm::ParameterSet &iC)
71+
: nameDetectors_(iC.getParameter<std::vector<std::string>>("nameDetectors")),
72+
fileName_(iC.getParameter<std::string>("fileName")),
73+
tok_hgcal_{edm::vector_transform(nameDetectors_, [this](const std::string &name) {
74+
return esConsumes<HGCalDDDConstants, IdealGeometryRecord, edm::Transition::BeginRun>(edm::ESInputTag{"", name});
75+
})} {
76+
std::ostringstream st1;
77+
for (const auto &name : nameDetectors_)
78+
st1 << " : " << name;
79+
edm::LogVerbatim("HGCGeom") << "Test validity of cells for " << nameDetectors_.size() << " detectors" << st1.str()
80+
<< " with inputs from " << fileName_;
81+
if (!fileName_.empty()) {
82+
edm::FileInPath filetmp("Geometry/HGCalCommonData/data/" + fileName_);
83+
std::string fileName = filetmp.fullPath();
84+
std::ifstream fInput(fileName.c_str());
85+
if (!fInput.good()) {
86+
edm::LogVerbatim("HGCGeom") << "Cannot open file " << fileName;
87+
} else {
88+
char buffer[200];
89+
const std::vector<DetId::Detector> dets = {DetId::HGCalEE, DetId::HGCalHSi, DetId::HGCalHSc};
90+
while (fInput.getline(buffer, 200)) {
91+
std::vector<std::string> items = HGCalGeomUtils::splitString(std::string(buffer));
92+
if (items.size() == 14) {
93+
DetId::Detector det = static_cast<DetId::Detector>(std::atoi(items[0].c_str()));
94+
auto itr = std::find(dets.begin(), dets.end(), det);
95+
if (itr != dets.end()) {
96+
uint32_t pos = static_cast<uint32_t>(itr - dets.begin());
97+
DetId id(0);
98+
if ((det == DetId::HGCalEE) || (det == DetId::HGCalHSi)) {
99+
int type = std::atoi(items[1].c_str());
100+
int zside = std::atoi(items[2].c_str());
101+
int layer = std::atoi(items[3].c_str());
102+
int waferU = std::atoi(items[4].c_str());
103+
int waferV = std::atoi(items[5].c_str());
104+
int cellU = std::atoi(items[6].c_str());
105+
int cellV = std::atoi(items[7].c_str());
106+
id = static_cast<DetId>(HGCSiliconDetId(det, zside, type, layer, waferU, waferV, cellU, cellV));
107+
detIds_.emplace_back(id, pos);
108+
xwafer_.emplace_back(std::atof(items[8].c_str()));
109+
ywafer_.emplace_back(std::atof(items[9].c_str()));
110+
xcellOff_.emplace_back(std::atof(items[10].c_str()));
111+
ycellOff_.emplace_back(std::atof(items[11].c_str()));
112+
xcell_.emplace_back(std::atof(items[12].c_str()));
113+
ycell_.emplace_back(std::atof(items[13].c_str()));
114+
}
115+
}
116+
}
117+
}
118+
fInput.close();
119+
}
120+
}
121+
size = detIds_.size();
122+
edm::LogVerbatim("HGCGeom") << "Reads " << detIds_.size() << " ID's from " << fileName_;
123+
}
124+
125+
void HGCalTestDDDCons::fillDescriptions(edm::ConfigurationDescriptions &descriptions) {
126+
std::vector<std::string> names = {"HGCalEESensitive", "HGCalHESiliconSensitive"};
127+
edm::ParameterSetDescription desc;
128+
desc.add<std::vector<std::string>>("nameDetectors", names);
129+
desc.add<std::string>("fileName", "missD120.txt");
130+
descriptions.add("hgcalTestDDDCons", desc);
131+
}
132+
133+
// ------------ method called to produce the data ------------
134+
void HGCalTestDDDCons::beginRun(edm::Run const &iRun, edm::EventSetup const &iSetup) {
135+
//initiating hgc Geometry
136+
std::vector<std::string> names = {"HGCalEESensitive", "HGCalHESiliconSensitive"};
137+
std::vector<DetId::Detector> dets = {DetId::HGCalEE, DetId::HGCalHSi};
138+
std::map<DetId::Detector, uint32_t> detMap;
139+
for (uint32_t i = 0; i < nameDetectors_.size(); i++) {
140+
edm::LogVerbatim("HGCGeom") << "Tries to initialize HGCalGeometry and HGCalDDDConstants for " << i << ":"
141+
<< nameDetectors_[i];
142+
const edm::ESHandle<HGCalDDDConstants> &hgcCons = iSetup.getHandle(tok_hgcal_[i]);
143+
if (hgcCons.isValid()) {
144+
hgcCons_.push_back(hgcCons.product());
145+
} else {
146+
edm::LogWarning("HGCGeom") << "Cannot initiate HGCalDDDConstants for " << nameDetectors_[i] << std::endl;
147+
}
148+
auto ii = std::find(names.begin(), names.end(), nameDetectors_[i]);
149+
if (ii != names.end()) {
150+
uint32_t k = static_cast<uint32_t>(ii - names.begin());
151+
detMap[dets[k]] = i;
152+
}
153+
}
154+
edm::LogVerbatim("HGCGeom") << "Loaded HGCalDDConstants for " << detMap.size() << " detectors";
155+
156+
for (auto itr = detMap.begin(); itr != detMap.end(); ++itr)
157+
edm::LogVerbatim("HGCGeom") << "[" << itr->second << "]: " << nameDetectors_[itr->second] << " for Detector "
158+
<< itr->first;
159+
160+
int cellU(0), cellV(0), waferType(-1), waferU(0), waferV(0);
161+
double wt(1.0);
162+
for (int k = 0; k < size; ++k) {
163+
const HGCalDDDConstants *cons = hgcCons_[detMap[(detIds_[k].first).det()]];
164+
HGCSiliconDetId id(detIds_[k].first);
165+
auto hgpar_ = cons->getParameter();
166+
HGCalCell celli(hgpar_->waferSize_, hgpar_->nCellsFine_, hgpar_->nCellsCoarse_);
167+
auto placement = cons->placementIndex(id);
168+
int ncell_ = id.lowDensity() ? hgpar_->nCellsCoarse_ : hgpar_->nCellsFine_;
169+
auto partialType = cons->partialWaferType(id.layer(), id.waferU(), id.waferV());
170+
auto cellType = HGCalCell::cellType(id.cellU(), id.cellV(), ncell_, placement, partialType);
171+
auto waferxy = cons->waferPositionWithCshift(id.layer(), id.waferU(), id.waferV(), true, true, false);
172+
auto cellxy_cog = cons->locateCell(id, true, false);
173+
auto cellxy_ncog = cons->locateCell(id, false, false);
174+
waferU = id.waferU();
175+
waferV = id.waferV();
176+
double xx = id.zside() * xcell_[k];
177+
cons->waferFromPosition(
178+
xx, ycell_[k], id.zside(), id.layer(), waferU, waferV, cellU, cellV, waferType, wt, false, false);
179+
auto valid = cons->isValidHex8(id.layer(), id.waferU(), id.waferV(), id.cellU(), id.cellV(), true);
180+
float scale = 0.1;
181+
edm::LogVerbatim("HGCGeom") << "Hit[" << k << "] " << id << " Valid " << valid
182+
<< " zside:layer:waferU:waferV:cellU:cellV " << id.layer() << ":" << id.waferU() << ":"
183+
<< id.waferV() << ":" << id.cellU() << ":" << id.cellV()
184+
<< " Observed coordinates wafer:cellCOG:cell " << waferxy.first << "," << waferxy.second
185+
<< ":" << cellxy_ncog.first << "," << cellxy_ncog.second << ":" << cellxy_cog.first
186+
<< "," << cellxy_cog.second << " CellType:CellPosition " << cellType.second << ":"
187+
<< cellType.first;
188+
if (std::sqrt(std::pow(waferxy.first + scale * xwafer_[k], 2) + std::pow(waferxy.second - scale * ywafer_[k], 2)) >
189+
0.01) {
190+
edm::LogVerbatim("HGCGeom") << " Error wafer mismatch actual:observed (" << xwafer_[k] << "," << ywafer_[k]
191+
<< "):(" << waferxy.first << "," << waferxy.second << ") ";
192+
}
193+
if (std::sqrt(std::pow(cellxy_ncog.first + scale * xcell_[k], 2) +
194+
std::pow(cellxy_ncog.second - scale * ycell_[k], 2)) > 0.01) {
195+
edm::LogVerbatim("HGCGeom") << " Error cell COG mismatch actual:observed (" << xcell_[k] << "," << ycell_[k]
196+
<< "):(" << cellxy_ncog.first << "," << cellxy_ncog.second << ") ";
197+
}
198+
if (std::sqrt(std::pow(cellxy_cog.first + scale * xcellOff_[k], 2) +
199+
std::pow(cellxy_cog.second - scale * ycellOff_[k], 2)) > 0.01) {
200+
edm::LogVerbatim("HGCGeom") << " Error cell center mismatch actual:observed (" << xcellOff_[k] << ","
201+
<< ycellOff_[k] << "):(" << cellxy_cog.first << "," << cellxy_cog.second << ") ";
202+
}
203+
}
204+
}
205+
206+
// define this as a plug-in
207+
DEFINE_FWK_MODULE(HGCalTestDDDCons);
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
###############################################################################
2+
# Way to use this:
3+
# cmsRun testHGCalDDDCons_cfi.py geometry=D120
4+
#
5+
# Options for Geometry D120
6+
#
7+
###############################################################################
8+
import FWCore.ParameterSet.Config as cms
9+
import os, sys, importlib, re
10+
import FWCore.ParameterSet.VarParsing as VarParsing
11+
12+
####################################################################
13+
### SETUP OPTIONS
14+
options = VarParsing.VarParsing('standard')
15+
options.register('geometry',
16+
"D120",
17+
VarParsing.VarParsing.multiplicity.singleton,
18+
VarParsing.VarParsing.varType.string,
19+
"type of operations: D120, D122, etc")
20+
21+
### get and parse the command line arguments
22+
options.parseArguments()
23+
print(options)
24+
25+
geomName = "Run4" + options.geometry
26+
geomFile = "Configuration.Geometry.GeometryExtended" + geomName + "Reco_cff"
27+
import Configuration.Geometry.defaultPhase2ConditionsEra_cff as _settings
28+
GLOBAL_TAG, ERA = _settings.get_era_and_conditions(geomName)
29+
30+
31+
from Configuration.Eras.Era_Phase2C17I13M9_cff import Phase2C17I13M9
32+
process = cms.Process("TestHGCalDDDCons",ERA)
33+
34+
process.load(geomFile)
35+
process.load("Geometry.HGCalCommonData.hgcalParametersInitialization_cfi")
36+
process.load("Geometry.HGCalCommonData.hgcalNumberingInitialization_cfi")
37+
process.load("Geometry.EcalCommonData.ecalSimulationParameters_cff")
38+
process.load("Geometry.HcalCommonData.hcalDDDSimConstants_cff")
39+
process.load("SimGeneral.HepPDTESSource.pdt_cfi")
40+
process.load('FWCore.MessageService.MessageLogger_cfi')
41+
42+
if hasattr(process,'MessageLogger'):
43+
process.MessageLogger.HGCalGeom=dict()
44+
process.MessageLogger.HGCGeom=dict()
45+
46+
process.load("IOMC.RandomEngine.IOMC_cff")
47+
process.RandomNumberGeneratorService.generator.initialSeed = 456789
48+
49+
process.source = cms.Source("EmptySource")
50+
51+
process.generator = cms.EDProducer("FlatRandomEGunProducer",
52+
PGunParameters = cms.PSet(
53+
PartID = cms.vint32(14),
54+
MinEta = cms.double(-3.5),
55+
MaxEta = cms.double(3.5),
56+
MinPhi = cms.double(-3.14159265359),
57+
MaxPhi = cms.double(3.14159265359),
58+
MinE = cms.double(9.99),
59+
MaxE = cms.double(10.01)
60+
),
61+
AddAntiParticle = cms.bool(False),
62+
Verbosity = cms.untracked.int32(0),
63+
firstRun = cms.untracked.uint32(1)
64+
)
65+
66+
process.maxEvents = cms.untracked.PSet(
67+
input = cms.untracked.int32(1)
68+
)
69+
70+
process.SimpleMemoryCheck = cms.Service("SimpleMemoryCheck",
71+
ignoreTotal = cms.untracked.int32(1),
72+
moduleMemorySummary = cms.untracked.bool(True)
73+
)
74+
75+
process.load("Geometry.HGCalCommonData.hgcalTestDDDCons_cfi")
76+
77+
78+
process.p1 = cms.Path(process.generator*process.hgcalTestDDDCons)

0 commit comments

Comments
 (0)