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 "FWCore/ParameterSet/interface/ParameterSet.h"
0006 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0007 #include "Geometry/CaloGeometry/interface/CaloGeometry.h"
0008 #include "Geometry/Records/interface/CaloGeometryRecord.h"
0009 #include "Geometry/HcalTowerAlgo/interface/HcalGeometry.h"
0010 #include <iostream>
0011
0012 class HcalGeometryDetIdTester : public edm::one::EDAnalyzer<> {
0013 public:
0014 explicit HcalGeometryDetIdTester(const edm::ParameterSet&);
0015
0016 static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0017
0018 void beginJob() override {}
0019 void analyze(edm::Event const& iEvent, edm::EventSetup const&) override;
0020 void endJob() override {}
0021
0022 private:
0023 static constexpr int ndetMax_ = 4;
0024 int detMin_, detMax_;
0025 edm::ESGetToken<HcalTopology, HcalRecNumberingRecord> tok_htopo_;
0026 edm::ESGetToken<CaloGeometry, CaloGeometryRecord> tok_geom_;
0027 };
0028
0029 HcalGeometryDetIdTester::HcalGeometryDetIdTester(const edm::ParameterSet& iConfig) {
0030 detMin_ = std::min(ndetMax_, std::max(iConfig.getParameter<int>("DetectorMin"), 1));
0031 detMax_ = std::min(ndetMax_, std::max(iConfig.getParameter<int>("DetectorMax"), 1));
0032 if (detMin_ > detMax_)
0033 detMin_ = detMax_;
0034 tok_htopo_ = esConsumes<HcalTopology, HcalRecNumberingRecord>();
0035 tok_geom_ = esConsumes<CaloGeometry, CaloGeometryRecord>();
0036 edm::LogVerbatim("HCalGeom") << "Study DetIds for SubDetId in the range " << detMin_ << ":" << detMax_;
0037 }
0038
0039 void HcalGeometryDetIdTester::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0040 edm::ParameterSetDescription desc;
0041 desc.add<int>("DetectorMin", 1);
0042 desc.add<int>("DetectorMax", 4);
0043 descriptions.add("hcalGeometryDetIdTester", desc);
0044 }
0045
0046 void HcalGeometryDetIdTester::analyze(const edm::Event& , const edm::EventSetup& iSetup) {
0047 const HcalTopology topology = iSetup.getData(tok_htopo_);
0048 const CaloGeometry* geo = &iSetup.getData(tok_geom_);
0049 const HcalGeometry* hcalGeom = static_cast<const HcalGeometry*>(geo->getSubdetectorGeometry(DetId::Hcal, HcalBarrel));
0050
0051 std::string subdets[ndetMax_] = {"HB", "HE", "HO", "HF"};
0052 HcalSubdetector subdetd[ndetMax_] = {HcalBarrel, HcalEndcap, HcalOuter, HcalForward};
0053 int ietaMin[ndetMax_] = {1, 16, 1, 29};
0054 int ietaMax[ndetMax_] = {16, 29, 15, 41};
0055 int depthMin[ndetMax_] = {1, 1, 4, 1};
0056 int depthMax[ndetMax_] = {4, 7, 4, 4};
0057
0058 for (int subd = (detMin_ - 1); subd < detMax_; ++subd) {
0059 edm::LogVerbatim("HCalGeom") << "\n\nStudy Detector = Hcal SubDetector = " << subdets[subd]
0060 << "\n======================================\n";
0061 int nall(0), nbad(0);
0062 const std::vector<DetId>& ids = hcalGeom->getValidDetIds(DetId::Hcal, subdetd[subd]);
0063 for (auto id : ids) {
0064 ++nall;
0065 if (!(topology.valid(id))) {
0066 ++nbad;
0067 edm::LogVerbatim("HCalGeom") << "Check " << HcalDetId(id) << " *****";
0068 }
0069 }
0070 edm::LogVerbatim("HCalGeom") << "\n"
0071 << nbad << " bad out of " << nall
0072 << " detIds\n========================\n\nNow List All IDs\n================";
0073 int k(0);
0074 for (auto id : ids) {
0075 edm::LogVerbatim("HCalGeom") << "[ " << std::setw(4) << k << "] " << HcalDetId(id);
0076 ++k;
0077 }
0078
0079 int n(0);
0080 edm::LogVerbatim("HCalGeom")
0081 << "\nNow List all IDs declared valid by Topology\n===========================================\n";
0082 for (int ieta = ietaMin[subd]; ieta <= ietaMax[subd]; ++ieta) {
0083 for (int depth = depthMin[subd]; depth <= depthMax[subd]; ++depth) {
0084 HcalDetId id(subdetd[subd], ieta, 1, depth);
0085 if (topology.validHcal(id)) {
0086 edm::LogVerbatim("HCalGeom") << "[ " << std::setw(2) << n << "] " << id;
0087 ++n;
0088 }
0089 }
0090 }
0091 edm::LogVerbatim("HCalGeom") << "\nFinds a total of " << n << " IDs";
0092 }
0093 }
0094
0095 DEFINE_FWK_MODULE(HcalGeometryDetIdTester);