Skip to content

Commit

Permalink
Merge pull request #46404 from bsunanda/Run3-hcx377C
Browse files Browse the repository at this point in the history
Run3-377C Add the testing code for the ZDC Topology class
  • Loading branch information
cmsbuild authored Oct 17, 2024
2 parents 50ecb2c + ec01e33 commit db4190c
Show file tree
Hide file tree
Showing 4 changed files with 207 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Geometry/ForwardGeometry/src/ZdcTopology.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ ZdcTopology::ZdcTopology(const HcalDDDRecConstants* hcons)
firstRPDModule_(1),
lastRPDModule_(HcalZDCDetId::kDepRPD) {
mode_ = (HcalTopologyMode::Mode)(hcons_->getTopoMode());
excludeRPD_ = (mode_ < HcalTopologyMode::Mode::Run3);
excludeRPD_ = ((mode_ != HcalTopologyMode::Mode::Run3) && (mode_ != HcalTopologyMode::Mode::Run4));
edm::LogVerbatim("ForwardGeom") << "ZdcTopology : Mode " << mode_ << ":" << HcalTopologyMode::Mode::Run3
<< " ExcludeRPD " << excludeRPD_;
}
Expand Down
2 changes: 2 additions & 0 deletions Geometry/ForwardGeometry/test/BuildFile.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<use name="DataFormats/HcalDetId"/>
<use name="DataFormats/ForwardDetId"/>
<use name="Geometry/HGCalGeometry"/>
<use name="Geometry/ForwardGeometry"/>
<use name="Geometry/Records"/>
<use name="CoralBase"/>
<flags EDM_PLUGIN="1"/>
Expand Down
137 changes: 137 additions & 0 deletions Geometry/ForwardGeometry/test/ZdcTopologyTester.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
#include <iostream>
#include <sstream>
#include <string>
#include <vector>

#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/ESTransientHandle.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/Records/interface/HcalRecNumberingRecord.h"
#include "Geometry/ForwardGeometry/interface/ZdcTopology.h"
#include "DataFormats/HcalDetId/interface/HcalZDCDetId.h"

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

static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);

private:
void analyze(edm::Event const&, edm::EventSetup const&) override;
void beginJob() override {}
void beginRun(edm::Run const&, edm::EventSetup const&) override {}
void endRun(edm::Run const&, edm::EventSetup const&) override {}
void doTest(const ZdcTopology& topology);

// ----------member data ---------------------------
const edm::ESGetToken<ZdcTopology, HcalRecNumberingRecord> tokTopo_;
};

ZdcTopologyTester::ZdcTopologyTester(const edm::ParameterSet&)
: tokTopo_{esConsumes<ZdcTopology, HcalRecNumberingRecord>(edm::ESInputTag{})} {}

void ZdcTopologyTester::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
edm::ParameterSetDescription desc;
desc.setUnknown();
descriptions.add("zdcTopologyTester", desc);
}

void ZdcTopologyTester::analyze(edm::Event const&, edm::EventSetup const& iSetup) { doTest(iSetup.getData(tokTopo_)); }

void ZdcTopologyTester::doTest(const ZdcTopology& topology) {
// Total number of valid cells
for (int idet = 0; idet < 4; idet++) {
int ndet(0);
std::string det = "EM";
HcalZDCDetId::Section section = HcalZDCDetId::EM;
if (idet == 1) {
det = "HAD";
section = HcalZDCDetId::HAD;
} else if (idet == 2) {
det = "LUM";
section = HcalZDCDetId::LUM;
} else if (idet == 3) {
det = "RPD";
section = HcalZDCDetId::RPD;
}
for (int depth = 1; depth <= HcalZDCDetId::kDepTot; ++depth) {
for (int zside = 0; zside <= 1; ++zside) {
bool forward = (zside == 0) ? true : false;
const HcalZDCDetId id(section, forward, depth);
if (topology.valid(id))
++ndet;
}
}
edm::LogVerbatim("HCalGeom") << "Number of valid cells in " << det << ": " << ndet;
}

// First test on movements along eta/phi directions
edm::LogVerbatim("HCalGeom") << "\nTest on movements along transverse/longiudnal directions"
<< "\n========================================================";
for (int idet = 0; idet < 4; idet++) {
HcalZDCDetId::Section section = HcalZDCDetId::EM;
if (idet == 1)
section = HcalZDCDetId::HAD;
else if (idet == 2)
section = HcalZDCDetId::LUM;
else if (idet == 3)
section = HcalZDCDetId::RPD;
for (int depth = 1; depth <= HcalZDCDetId::kDepTot; ++depth) {
for (int zside = 0; zside <= 1; ++zside) {
bool forward = (zside == 0) ? true : false;
const HcalZDCDetId id(section, forward, depth);
if (topology.valid(id)) {
std::vector<DetId> idT = topology.transverse(id);
std::vector<DetId> idL = topology.longitudinal(id);
edm::LogVerbatim("HCalGeom") << "Neighbours for : Tower " << id;
std::ostringstream st1;
st1 << " " << idT.size() << " sets transverse:";
for (auto& i : idT)
st1 << " " << (HcalZDCDetId)(i());
edm::LogVerbatim("HCalGeom") << st1.str();
std::ostringstream st2;
st2 << " " << idL.size() << " sets along Longitunal:";
for (auto& i : idL)
st2 << " " << (HcalZDCDetId)(i());
edm::LogVerbatim("HCalGeom") << st2.str();
}
}
}
}

// Check on Dense Index
edm::LogVerbatim("HCalGeom") << "\nCheck on Dense Index"
<< "\n=====================";
for (int idet = 0; idet < 4; idet++) {
HcalZDCDetId::Section section = HcalZDCDetId::EM;
if (idet == 1)
section = HcalZDCDetId::HAD;
else if (idet == 2)
section = HcalZDCDetId::LUM;
else if (idet == 3)
section = HcalZDCDetId::RPD;
for (int depth = 1; depth <= HcalZDCDetId::kDepTot; ++depth) {
for (int zside = 0; zside <= 1; ++zside) {
bool forward = (zside == 0) ? true : false;
HcalZDCDetId cell(section, forward, depth);
if (topology.valid(cell)) {
unsigned int dense = topology.detId2DenseIndex(DetId(cell));
DetId id = topology.denseId2detId(dense);
std::string cherr = (cell.rawId() != id.rawId()) ? " **** ERROR *****" : "";
edm::LogVerbatim("HCalGeom") << cell << " Dense " << std::hex << dense << std::dec << " o/p "
<< HcalZDCDetId(id) << cherr;
}
}
}
}
}

//define this as a plug-in
DEFINE_FWK_MODULE(ZdcTopologyTester);
67 changes: 67 additions & 0 deletions Geometry/ForwardGeometry/test/testZdcTopology_cfg.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
###############################################################################
# Way to use this:
# cmsRun testZdcTopology_cfg.py type=2024
#
# Options for type 2021, 2023, 2024
#
###############################################################################
import FWCore.ParameterSet.Config as cms
import os, sys, imp, re
import FWCore.ParameterSet.VarParsing as VarParsing

####################################################################
### SETUP OPTIONS
options = VarParsing.VarParsing('standard')
options.register('type',
"2024",
VarParsing.VarParsing.multiplicity.singleton,
VarParsing.VarParsing.varType.string,
"type of operations:2021, 2023, 2024")

### get and parse the command line arguments
options.parseArguments()

geomFile = "Configuration.Geometry.GeometryExtended" + options.type + "Reco_cff"

print(options)
print("Geometry file: ", geomFile)

####################################################################
# Use the options

from Configuration.Eras.Era_Run3_DDD_cff import Run3_DDD
process = cms.Process('TestZdcTopology',Run3_DDD)

process.load("SimGeneral.HepPDTESSource.pdt_cfi")
process.load(geomFile)
process.load("Geometry.ForwardGeometry.zdcTopologyTester_cfi")
process.load('FWCore.MessageService.MessageLogger_cfi')

if hasattr(process,'MessageLogger'):
process.MessageLogger.HCalGeom=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.p1 = cms.Path(process.generator*process.zdcTopologyTester)

0 comments on commit db4190c

Please sign in to comment.