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 <iostream>
0012 
0013 class HcalGeometryDetIdAnalyzer : public edm::one::EDAnalyzer<> {
0014 public:
0015   explicit HcalGeometryDetIdAnalyzer(const edm::ParameterSet&);
0016   ~HcalGeometryDetIdAnalyzer(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 useOld_;
0024   edm::ESGetToken<HcalDDDRecConstants, HcalRecNumberingRecord> tok_ddrec_;
0025   edm::ESGetToken<HcalTopology, HcalRecNumberingRecord> tok_htopo_;
0026 };
0027 
0028 HcalGeometryDetIdAnalyzer::HcalGeometryDetIdAnalyzer(const edm::ParameterSet& iConfig) {
0029   useOld_ = iConfig.getParameter<bool>("UseOldLoader");
0030   tok_ddrec_ = esConsumes<HcalDDDRecConstants, HcalRecNumberingRecord>();
0031   tok_htopo_ = esConsumes<HcalTopology, HcalRecNumberingRecord>();
0032 }
0033 
0034 HcalGeometryDetIdAnalyzer::~HcalGeometryDetIdAnalyzer(void) {}
0035 
0036 void HcalGeometryDetIdAnalyzer::analyze(const edm::Event& /*iEvent*/, const edm::EventSetup& iSetup) {
0037   const HcalDDDRecConstants hcons = iSetup.getData(tok_ddrec_);
0038   const HcalTopology topology = iSetup.getData(tok_htopo_);
0039 
0040   CaloSubdetectorGeometry* caloGeom(nullptr);
0041   if (useOld_) {
0042     HcalHardcodeGeometryLoader m_loader;
0043     caloGeom = m_loader.load(topology);
0044   } else {
0045     HcalFlexiHardcodeGeometryLoader m_loader;
0046     caloGeom = m_loader.load(topology, hcons);
0047   }
0048   const std::vector<DetId>& ids = caloGeom->getValidDetIds();
0049 
0050   int counter = 0;
0051   for (std::vector<DetId>::const_iterator i = ids.begin(), iEnd = ids.end(); i != iEnd; ++i, ++counter) {
0052     HcalDetId hid = (*i);
0053     unsigned int did = topology.detId2denseId(*i);
0054     HcalDetId rhid = topology.denseId2detId(did);
0055 
0056     edm::LogVerbatim("HCalGeom") << counter << ": din " << std::hex << did << std::dec << ": " << hid << " == " << rhid;
0057     assert(hid == rhid);
0058   }
0059   edm::LogVerbatim("HCalGeom") << "No error found among " << counter << " HCAL valid ID's";
0060 }
0061 
0062 DEFINE_FWK_MODULE(HcalGeometryDetIdAnalyzer);