File indexing completed on 2024-04-06 12:14:52
0001 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0002 #include "FWCore/Framework/interface/EventSetup.h"
0003 #include "FWCore/Framework/interface/MakerMacros.h"
0004 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0005 #include "Geometry/CaloGeometry/interface/CaloGeometry.h"
0006 #include "Geometry/CaloGeometry/interface/CaloCellGeometry.h"
0007 #include "Geometry/HcalCommonData/interface/HcalDDDRecConstants.h"
0008 #include "Geometry/HcalTowerAlgo/interface/HcalGeometry.h"
0009 #include "Geometry/HcalTowerAlgo/interface/HcalFlexiHardcodeGeometryLoader.h"
0010 #include "Geometry/Records/interface/CaloGeometryRecord.h"
0011 #include <iostream>
0012
0013 class HcalDetIdTester : public edm::one::EDAnalyzer<> {
0014 public:
0015 explicit HcalDetIdTester(const edm::ParameterSet&);
0016 ~HcalDetIdTester(void) override;
0017
0018 void beginJob() override {}
0019 void analyze(edm::Event const& iEvent, edm::EventSetup const&) override;
0020 void endJob() override {}
0021
0022 private:
0023 bool geomDB_;
0024 edm::ESGetToken<HcalDDDRecConstants, HcalRecNumberingRecord> tok_ddrec_;
0025 edm::ESGetToken<HcalTopology, HcalRecNumberingRecord> tok_htopo_;
0026 edm::ESGetToken<CaloGeometry, CaloGeometryRecord> tok_geom_;
0027 };
0028
0029 HcalDetIdTester::HcalDetIdTester(const edm::ParameterSet& iConfig) {
0030 geomDB_ = iConfig.getParameter<bool>("GeometryFromDB");
0031 tok_ddrec_ = esConsumes<HcalDDDRecConstants, HcalRecNumberingRecord>();
0032 tok_htopo_ = esConsumes<HcalTopology, HcalRecNumberingRecord>();
0033 tok_geom_ = esConsumes<CaloGeometry, CaloGeometryRecord>();
0034 }
0035
0036 HcalDetIdTester::~HcalDetIdTester(void) {}
0037
0038 void HcalDetIdTester::analyze(const edm::Event& , const edm::EventSetup& iSetup) {
0039 const HcalDDDRecConstants hcons = iSetup.getData(tok_ddrec_);
0040 const HcalTopology topology = iSetup.getData(tok_htopo_);
0041
0042 CaloSubdetectorGeometry* caloGeom(nullptr);
0043 if (geomDB_) {
0044 const CaloGeometry* geo = &iSetup.getData(tok_geom_);
0045 caloGeom = (CaloSubdetectorGeometry*)(geo->getSubdetectorGeometry(DetId::Hcal, HcalBarrel));
0046 } else {
0047 HcalFlexiHardcodeGeometryLoader m_loader;
0048 caloGeom = m_loader.load(topology, hcons);
0049 }
0050
0051 int maxDepth = (topology.maxDepthHB() > topology.maxDepthHE()) ? topology.maxDepthHB() : topology.maxDepthHE();
0052
0053 int nfail0(0);
0054 for (int det = 1; det <= HcalForward; det++) {
0055 for (int eta = -HcalDetId::kHcalEtaMask2; eta <= (int)(HcalDetId::kHcalEtaMask2); eta++) {
0056 for (int depth = 1; depth <= maxDepth; depth++) {
0057 for (unsigned int phi = 0; phi <= HcalDetId::kHcalPhiMask2; phi++) {
0058 HcalDetId detId((HcalSubdetector)det, eta, phi, depth);
0059 if (topology.valid(detId)) {
0060 auto cell = caloGeom->getGeometry((DetId)(detId));
0061 if (cell) {
0062 edm::LogVerbatim("HCalGeom") << detId << " " << cell->getPosition();
0063 } else {
0064 edm::LogVerbatim("HCalGeom") << detId << " position not found";
0065 ++nfail0;
0066 }
0067 }
0068 }
0069 }
0070 }
0071 }
0072
0073 int nfail1(0);
0074 const std::vector<DetId>& ids = caloGeom->getValidDetIds();
0075 for (auto id : ids) {
0076 if (!topology.valid(id)) {
0077 edm::LogVerbatim("HCalGeom") << HcalDetId(id) << " declared as invalid == ERROR";
0078 ++nfail1;
0079 }
0080 }
0081
0082 edm::LogVerbatim("HCalGeom") << "\nNumber of failures:\nTopology certifies but geometry fails " << nfail0
0083 << "\nGeometry certifies but Topology fails " << nfail1 << std::endl;
0084 }
0085
0086 DEFINE_FWK_MODULE(HcalDetIdTester);