Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-12-08 08:16:23

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/HcalTowerAlgo/interface/HcalHardcodeGeometryLoader.h"
0011 #include "Geometry/Records/interface/CaloGeometryRecord.h"
0012 #include <iostream>
0013 
0014 class HcalGeometryAnalyzer : public edm::one::EDAnalyzer<> {
0015 public:
0016   explicit HcalGeometryAnalyzer(const edm::ParameterSet&);
0017   ~HcalGeometryAnalyzer(void) override;
0018 
0019   void beginJob() override {}
0020   void analyze(edm::Event const& iEvent, edm::EventSetup const&) override;
0021   void endJob() override {}
0022 
0023 private:
0024   bool useOld_;
0025   bool geomDB_;
0026   edm::ESGetToken<HcalDDDRecConstants, HcalRecNumberingRecord> tok_ddrec_;
0027   edm::ESGetToken<HcalTopology, HcalRecNumberingRecord> tok_htopo_;
0028   edm::ESGetToken<CaloGeometry, CaloGeometryRecord> tok_geom_;
0029 };
0030 
0031 HcalGeometryAnalyzer::HcalGeometryAnalyzer(const edm::ParameterSet& iConfig) {
0032   useOld_ = iConfig.getParameter<bool>("UseOldLoader");
0033   geomDB_ = iConfig.getParameter<bool>("GeometryFromDB");
0034   tok_ddrec_ = esConsumes<HcalDDDRecConstants, HcalRecNumberingRecord>();
0035   tok_htopo_ = esConsumes<HcalTopology, HcalRecNumberingRecord>();
0036   tok_geom_ = esConsumes<CaloGeometry, CaloGeometryRecord>();
0037 }
0038 
0039 HcalGeometryAnalyzer::~HcalGeometryAnalyzer(void) {}
0040 
0041 void HcalGeometryAnalyzer::analyze(const edm::Event& /*iEvent*/, const edm::EventSetup& iSetup) {
0042   const HcalDDDRecConstants hcons = iSetup.getData(tok_ddrec_);
0043   const HcalTopology topology = iSetup.getData(tok_htopo_);
0044 
0045   CaloSubdetectorGeometry* caloGeom(nullptr);
0046   if (geomDB_) {
0047     const CaloGeometry* geo = &iSetup.getData(tok_geom_);
0048     caloGeom = (CaloSubdetectorGeometry*)(geo->getSubdetectorGeometry(DetId::Hcal, HcalBarrel));
0049   } else if (useOld_) {
0050     HcalHardcodeGeometryLoader m_loader;
0051     caloGeom = m_loader.load(topology);
0052   } else {
0053     HcalFlexiHardcodeGeometryLoader m_loader;
0054     caloGeom = m_loader.load(topology, hcons);
0055   }
0056   const std::vector<DetId>& ids = caloGeom->getValidDetIds();
0057 
0058   std::vector<int> dins;
0059   int counter = 0;
0060   for (std::vector<DetId>::const_iterator i = ids.begin(), iEnd = ids.end(); i != iEnd; ++i, ++counter) {
0061     HcalDetId hid = (*i);
0062     edm::LogVerbatim("HCalGeom") << counter << ": din " << topology.detId2denseId(*i) << ":" << hid;
0063     dins.emplace_back(topology.detId2denseId(*i));
0064 
0065     auto cell = caloGeom->getGeometry(*i);
0066     edm::LogVerbatim("HCalGeom") << *cell;
0067   }
0068 
0069   std::sort(dins.begin(), dins.end());
0070   edm::LogVerbatim("HCalGeom") << "=== Total " << counter << " cells in HCAL."
0071                                << " from HcalTopology ncells " << topology.ncells();
0072 
0073   // HB : 6911: din 16123
0074   edm::LogVerbatim("HCalGeom") << "HB Size " << topology.getHBSize() << "\nHE Size " << topology.getHESize()
0075                                << "\nHO Size " << topology.getHOSize() << "\nHF Size " << topology.getHFSize()
0076                                << "\nTotal "
0077                                << topology.getHBSize() + topology.getHESize() + topology.getHOSize() +
0078                                       topology.getHFSize();
0079 
0080   counter = 0;
0081   for (std::vector<int>::const_iterator i = dins.begin(); i != dins.end(); ++i, ++counter) {
0082     HcalDetId hid = (topology.denseId2detId(*i));
0083     HcalDetId ihid = (topology.denseId2detId(dins[counter]));
0084     edm::LogVerbatim("HCalGeom") << counter << ": din " << (*i) << " :" << hid << " == " << ihid;
0085   }
0086 }
0087 
0088 DEFINE_FWK_MODULE(HcalGeometryAnalyzer);