Skip to content

Commit aefe844

Browse files
committed
DDD testing
1 parent 86b5751 commit aefe844

File tree

4 files changed

+309
-0
lines changed

4 files changed

+309
-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

Geometry/HGCalCommonData/test/BuildFile.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<use name="CondFormats/GeometryObjects"/>
22
<use name="FWCore/Framework"/>
33
<use name="Geometry/HGCalCommonData"/>
4+
<use name="Geometry/HGCalGeometry"/>
45
<use name="Geometry/Records"/>
56
<use name="DetectorDescription/Core"/>
67
<use name="DataFormats/ForwardDetId"/>
Lines changed: 217 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,217 @@
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+
27+
// user include files
28+
#include "FWCore/Framework/interface/Frameworkfwd.h"
29+
#include "FWCore/Framework/interface/one/EDAnalyzer.h"
30+
#include "FWCore/Framework/interface/Event.h"
31+
#include "FWCore/Framework/interface/EventSetup.h"
32+
#include "FWCore/Framework/interface/MakerMacros.h"
33+
#include "FWCore/MessageLogger/interface/MessageLogger.h"
34+
#include "FWCore/ParameterSet/interface/FileInPath.h"
35+
#include "FWCore/ParameterSet/interface/ParameterSet.h"
36+
#include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
37+
#include "FWCore/Utilities/interface/transform.h"
38+
39+
#include "DataFormats/DetId/interface/DetId.h"
40+
#include "DataFormats/ForwardDetId/interface/HGCSiliconDetId.h"
41+
#include "Geometry/HGCalCommonData/interface/HGCalDDDConstants.h"
42+
#include "Geometry/HGCalCommonData/interface/HGCalGeomUtils.h"
43+
#include "Geometry/Records/interface/IdealGeometryRecord.h"
44+
#include "Geometry/HGCalCommonData/interface/HGCalCell.h"
45+
#include "Geometry/HGCalCommonData/interface/HGCalWaferIndex.h"
46+
#include "Geometry/HGCalGeometry/interface/HGCalGeometry.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 edm::ESGetToken<HGCalGeometry, IdealGeometryRecord> geomToken_;
64+
const std::vector<edm::ESGetToken<HGCalDDDConstants, IdealGeometryRecord>> tok_hgcal_;
65+
const std::vector<edm::ESGetToken<HGCalGeometry, IdealGeometryRecord>> geomToken_;
66+
int size;
67+
std::vector<const HGCalDDDConstants *> hgcCons_;
68+
std::vector<const HGCalGeometry *> hgcGeo_;
69+
std::vector<std::pair<DetId, uint32_t>> detIds_;
70+
std::vector<double> xwafer_, ywafer_, xcell_, ycell_, xcellOff_, ycellOff_;
71+
};
72+
73+
HGCalTestDDDCons::HGCalTestDDDCons(const edm::ParameterSet &iC)
74+
: nameDetectors_(iC.getParameter<std::vector<std::string>>("nameDetectors")),
75+
fileName_(iC.getParameter<std::string>("fileName")),
76+
//geomToken_{esConsumes<HGCalGeometry, IdealGeometryRecord>(edm::ESInputTag{"", "HGCalEESensitive"})},
77+
tok_hgcal_{
78+
edm::vector_transform(nameDetectors_,
79+
[this](const std::string &name) {
80+
return esConsumes<HGCalDDDConstants, IdealGeometryRecord, edm::Transition::BeginRun>(
81+
edm::ESInputTag{"", name});
82+
})},
83+
geomToken_{edm::vector_transform(nameDetectors_, [this](const std::string &name) {
84+
return esConsumes<HGCalGeometry, IdealGeometryRecord, edm::Transition::BeginRun>(edm::ESInputTag{"", name});
85+
})} {
86+
std::ostringstream st1;
87+
for (const auto &name : nameDetectors_)
88+
st1 << " : " << name;
89+
edm::LogVerbatim("HGCGeom") << "Test validity of cells for " << nameDetectors_.size() << " detectors" << st1.str()
90+
<< " with inputs from " << fileName_;
91+
if (!fileName_.empty()) {
92+
edm::FileInPath filetmp("Geometry/HGCalCommonData/data/" + fileName_);
93+
std::string fileName = filetmp.fullPath();
94+
std::ifstream fInput(fileName.c_str());
95+
if (!fInput.good()) {
96+
edm::LogVerbatim("HGCGeom") << "Cannot open file " << fileName;
97+
} else {
98+
char buffer[200];
99+
const std::vector<DetId::Detector> dets = {DetId::HGCalEE, DetId::HGCalHSi, DetId::HGCalHSc};
100+
while (fInput.getline(buffer, 200)) {
101+
std::vector<std::string> items = HGCalGeomUtils::splitString(std::string(buffer));
102+
if (items.size() == 14) {
103+
DetId::Detector det = static_cast<DetId::Detector>(std::atoi(items[0].c_str()));
104+
auto itr = std::find(dets.begin(), dets.end(), det);
105+
if (itr != dets.end()) {
106+
uint32_t pos = static_cast<uint32_t>(itr - dets.begin());
107+
DetId id(0);
108+
if ((det == DetId::HGCalEE) || (det == DetId::HGCalHSi)) {
109+
int type = std::atoi(items[1].c_str());
110+
int zside = std::atoi(items[2].c_str());
111+
int layer = std::atoi(items[3].c_str());
112+
int waferU = std::atoi(items[4].c_str());
113+
int waferV = std::atoi(items[5].c_str());
114+
int cellU = std::atoi(items[6].c_str());
115+
int cellV = std::atoi(items[7].c_str());
116+
id = static_cast<DetId>(HGCSiliconDetId(det, zside, type, layer, waferU, waferV, cellU, cellV));
117+
detIds_.emplace_back(id, pos);
118+
xwafer_.emplace_back(std::atof(items[8].c_str()));
119+
ywafer_.emplace_back(std::atof(items[9].c_str()));
120+
xcellOff_.emplace_back(std::atof(items[10].c_str()));
121+
ycellOff_.emplace_back(std::atof(items[11].c_str()));
122+
xcell_.emplace_back(std::atof(items[12].c_str()));
123+
ycell_.emplace_back(std::atof(items[13].c_str()));
124+
}
125+
}
126+
}
127+
}
128+
fInput.close();
129+
}
130+
}
131+
size = detIds_.size();
132+
edm::LogVerbatim("HGCGeom") << "Reads " << detIds_.size() << " ID's from " << fileName_;
133+
}
134+
135+
void HGCalTestDDDCons::fillDescriptions(edm::ConfigurationDescriptions &descriptions) {
136+
std::vector<std::string> names = {"HGCalEESensitive", "HGCalHESiliconSensitive"};
137+
edm::ParameterSetDescription desc;
138+
desc.add<std::vector<std::string>>("nameDetectors", names);
139+
desc.add<std::string>("fileName", "missD120.txt");
140+
descriptions.add("hgcalTestDDDCons", desc);
141+
}
142+
143+
// ------------ method called to produce the data ------------
144+
void HGCalTestDDDCons::beginRun(edm::Run const &iRun, edm::EventSetup const &iSetup) {
145+
//initiating hgc Geometry
146+
std::vector<std::string> names = {"HGCalEESensitive", "HGCalHESiliconSensitive"};
147+
std::vector<DetId::Detector> dets = {DetId::HGCalEE, DetId::HGCalHSi};
148+
std::map<DetId::Detector, uint32_t> detMap;
149+
for (uint32_t i = 0; i < nameDetectors_.size(); i++) {
150+
edm::LogVerbatim("HGCGeom") << "Tries to initialize HGCalGeometry and HGCalDDDConstants for " << i << ":"
151+
<< nameDetectors_[i];
152+
const edm::ESHandle<HGCalDDDConstants> &hgcCons = iSetup.getHandle(tok_hgcal_[i]);
153+
const HGCalGeometry &hgcGeo = iSetup.getData(geomToken_[i]);
154+
if (hgcCons.isValid()) {
155+
hgcCons_.push_back(hgcCons.product());
156+
} else {
157+
edm::LogWarning("HGCGeom") << "Cannot initiate HGCalDDDConstants for " << nameDetectors_[i] << std::endl;
158+
}
159+
hgcGeo_.push_back(&hgcGeo);
160+
auto ii = std::find(names.begin(), names.end(), nameDetectors_[i]);
161+
if (ii != names.end()) {
162+
uint32_t k = static_cast<uint32_t>(ii - names.begin());
163+
detMap[dets[k]] = i;
164+
}
165+
}
166+
edm::LogVerbatim("HGCGeom") << "Loaded HGCalDDConstants for " << detMap.size() << " detectors";
167+
168+
for (auto itr = detMap.begin(); itr != detMap.end(); ++itr)
169+
edm::LogVerbatim("HGCGeom") << "[" << itr->second << "]: " << nameDetectors_[itr->second] << " for Detector "
170+
<< itr->first;
171+
172+
int cellU(0), cellV(0), waferType(-1), waferU(0), waferV(0);
173+
double wt(1.0);
174+
for (int k = 0; k < size; ++k) {
175+
const HGCalDDDConstants *cons = hgcCons_[detMap[(detIds_[k].first).det()]];
176+
HGCSiliconDetId id(detIds_[k].first);
177+
auto hgpar_ = cons->getParameter();
178+
HGCalCell celli(hgpar_->waferSize_, hgpar_->nCellsFine_, hgpar_->nCellsCoarse_);
179+
auto placement = cons->placementIndex(id);
180+
int ncell_ = id.lowDensity() ? hgpar_->nCellsCoarse_ : hgpar_->nCellsFine_;
181+
auto partialType = cons->partialWaferType(id.layer(), id.waferU(), id.waferV());
182+
auto cellType = HGCalCell::cellType(id.cellU(), id.cellV(), ncell_, placement, partialType);
183+
auto waferxy = cons->waferPositionWithCshift(id.layer(), id.waferU(), id.waferV(), true, true, false);
184+
auto cellxy_cog = cons->locateCell(id, true, false);
185+
auto cellxy_ncog = cons->locateCell(id, false, false);
186+
waferU = id.waferU();
187+
waferV = id.waferV();
188+
double xx = id.zside() * xcell_[k];
189+
cons->waferFromPosition(
190+
xx, ycell_[k], id.zside(), id.layer(), waferU, waferV, cellU, cellV, waferType, wt, false, false);
191+
auto valid = cons->isValidHex8(id.layer(), id.waferU(), id.waferV(), id.cellU(), id.cellV(), true);
192+
float scale = 0.1;
193+
edm::LogVerbatim("HGCGeom") << "Hit[" << k << "] " << id << " Valid " << valid
194+
<< " zside:layer:waferU:waferV:cellU:cellV " << id.layer() << ":" << id.waferU() << ":"
195+
<< id.waferV() << ":" << id.cellU() << ":" << id.cellV()
196+
<< " Observed coordinates wafer:cellCOG:cell " << waferxy.first << "," << waferxy.second
197+
<< ":" << cellxy_ncog.first << "," << cellxy_ncog.second << ":" << cellxy_cog.first
198+
<< "," << cellxy_cog.second << " CellType:CellPosition " << cellType.second << ":"
199+
<< cellType.first;
200+
if (sqrt(pow(waferxy.first + scale * xwafer_[k], 2) + pow(waferxy.second - scale * ywafer_[k], 2)) > 0.01) {
201+
edm::LogVerbatim("HGCGeom") << " Error wafer mismatch actual:observed (" << xwafer_[k] << "," << ywafer_[k]
202+
<< "):(" << waferxy.first << "," << waferxy.second << ") ";
203+
}
204+
if (sqrt(pow(cellxy_ncog.first + scale * xcell_[k], 2) + pow(cellxy_ncog.second - scale * ycell_[k], 2)) > 0.01) {
205+
edm::LogVerbatim("HGCGeom") << " Error cell COG mismatch actual:observed (" << xcell_[k] << "," << ycell_[k]
206+
<< "):(" << cellxy_ncog.first << "," << cellxy_ncog.second << ") ";
207+
}
208+
if (sqrt(pow(cellxy_cog.first + scale * xcellOff_[k], 2) + pow(cellxy_cog.second - scale * ycellOff_[k], 2)) >
209+
0.01) {
210+
edm::LogVerbatim("HGCGeom") << " Error cell center mismatch actual:observed (" << xcellOff_[k] << ","
211+
<< ycellOff_[k] << "):(" << cellxy_cog.first << "," << cellxy_cog.second << ") ";
212+
}
213+
}
214+
}
215+
216+
// define this as a plug-in
217+
DEFINE_FWK_MODULE(HGCalTestDDDCons);
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
###############################################################################
2+
# Way to use this:
3+
# cmsRun testHGCalNumbering_cfg.py type=V19
4+
#
5+
# Options for type V16, V17, V17n, V18, V19
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("HGCalCellArea",ERA)
33+
34+
#geomFile = "Geometry.HGCalCommonData.testHGCal" + options.type + "XML_cfi"
35+
#print("Geometry file: ", geomFile)
36+
37+
38+
process.load(geomFile)
39+
process.load("Geometry.HGCalCommonData.hgcalParametersInitialization_cfi")
40+
process.load("Geometry.HGCalCommonData.hgcalNumberingInitialization_cfi")
41+
process.load("Geometry.EcalCommonData.ecalSimulationParameters_cff")
42+
process.load("Geometry.HcalCommonData.hcalDDDSimConstants_cff")
43+
process.load("SimGeneral.HepPDTESSource.pdt_cfi")
44+
process.load('FWCore.MessageService.MessageLogger_cfi')
45+
46+
if hasattr(process,'MessageLogger'):
47+
process.MessageLogger.HGCalGeom=dict()
48+
process.MessageLogger.HGCGeom=dict()
49+
50+
process.load("IOMC.RandomEngine.IOMC_cff")
51+
process.RandomNumberGeneratorService.generator.initialSeed = 456789
52+
53+
process.source = cms.Source("EmptySource")
54+
55+
process.generator = cms.EDProducer("FlatRandomEGunProducer",
56+
PGunParameters = cms.PSet(
57+
PartID = cms.vint32(14),
58+
MinEta = cms.double(-3.5),
59+
MaxEta = cms.double(3.5),
60+
MinPhi = cms.double(-3.14159265359),
61+
MaxPhi = cms.double(3.14159265359),
62+
MinE = cms.double(9.99),
63+
MaxE = cms.double(10.01)
64+
),
65+
AddAntiParticle = cms.bool(False),
66+
Verbosity = cms.untracked.int32(0),
67+
firstRun = cms.untracked.uint32(1)
68+
)
69+
70+
process.maxEvents = cms.untracked.PSet(
71+
input = cms.untracked.int32(1)
72+
)
73+
74+
process.SimpleMemoryCheck = cms.Service("SimpleMemoryCheck",
75+
ignoreTotal = cms.untracked.int32(1),
76+
moduleMemorySummary = cms.untracked.bool(True)
77+
)
78+
79+
process.load("Geometry.HGCalCommonData.hgcalTestDDDCons_cfi")
80+
81+
82+
process.p1 = cms.Path(process.generator*process.hgcalTestDDDCons)

0 commit comments

Comments
 (0)