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 HcalGeometryDump : public edm::one::EDAnalyzer<> {
0014 public:
0015 explicit HcalGeometryDump(const edm::ParameterSet&);
0016 ~HcalGeometryDump(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 HcalGeometryDump::HcalGeometryDump(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 HcalGeometryDump::~HcalGeometryDump(void) {}
0037
0038 void HcalGeometryDump::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 HcalGeometry* caloGeom(nullptr);
0043 if (geomDB_) {
0044 const CaloGeometry* geo = &iSetup.getData(tok_geom_);
0045 caloGeom = (HcalGeometry*)(geo->getSubdetectorGeometry(DetId::Hcal, HcalBarrel));
0046 } else {
0047 HcalFlexiHardcodeGeometryLoader m_loader;
0048 caloGeom = (HcalGeometry*)(m_loader.load(topology, hcons));
0049 }
0050
0051 const std::vector<DetId>& ids = caloGeom->getValidDetIds();
0052
0053 for (int subdet = 1; subdet <= 4; ++subdet) {
0054 std::vector<unsigned int> detIds;
0055 for (auto id : ids) {
0056 DetId hid = id;
0057 if (hid.subdetId() == subdet) {
0058 detIds.emplace_back(hid.rawId());
0059 }
0060 }
0061 edm::LogVerbatim("HCalGeom") << detIds.size() << " valid Ids for subdetector " << subdet;
0062 std::sort(detIds.begin(), detIds.end());
0063 int counter = 0;
0064 for (std::vector<unsigned int>::const_iterator i = detIds.begin(); i != detIds.end(); ++i, ++counter) {
0065 HcalDetId hid = HcalDetId(*i);
0066 auto cell = caloGeom->getGeometry(*i);
0067 edm::LogVerbatim("HCalGeom") << hid << "\tCaloCellGeometry " << cell->getPosition() << "\tHcalGeometry "
0068 << caloGeom->getPosition(hid);
0069 }
0070 }
0071 }
0072
0073 DEFINE_FWK_MODULE(HcalGeometryDump);