Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-03-30 23:47:26

0001 #include <iostream>
0002 #include <sstream>
0003 #include <string>
0004 #include <vector>
0005 
0006 #include "FWCore/Framework/interface/Frameworkfwd.h"
0007 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0008 #include "FWCore/Framework/interface/Event.h"
0009 #include "FWCore/Framework/interface/EventSetup.h"
0010 #include "FWCore/Framework/interface/MakerMacros.h"
0011 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0012 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0013 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0014 
0015 #include "Geometry/Records/interface/CaloGeometryRecord.h"
0016 #include "Geometry/HcalTowerAlgo/interface/HcalGeometry.h"
0017 #include "Geometry/CaloGeometry/interface/CaloGeometry.h"
0018 #include "Geometry/CaloTopology/interface/CaloTowerConstituentsMap.h"
0019 #include "DataFormats/CaloTowers/interface/CaloTowerDetId.h"
0020 #include "DataFormats/EcalDetId/interface/EBDetId.h"
0021 #include "DataFormats/EcalDetId/interface/EEDetId.h"
0022 #include "DataFormats/EcalDetId/interface/ESDetId.h"
0023 #include "DataFormats/EcalDetId/interface/EcalSubdetector.h"
0024 #include "DataFormats/HcalDetId/interface/HcalDetId.h"
0025 #include "DataFormats/HcalDetId/interface/HcalSubdetector.h"
0026 
0027 class CaloTowerMapTester : public edm::one::EDAnalyzer<edm::one::WatchRuns> {
0028 public:
0029   explicit CaloTowerMapTester(const edm::ParameterSet&);
0030 
0031   static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0032 
0033 private:
0034   void analyze(edm::Event const&, edm::EventSetup const&) override;
0035   void beginJob() override {}
0036   void beginRun(edm::Run const&, edm::EventSetup const&) override {}
0037   void endRun(edm::Run const&, edm::EventSetup const&) override {}
0038   void doTest(const CaloGeometry* geo, const CaloTowerConstituentsMap* ctmap);
0039 
0040 private:
0041   // ----------member data ---------------------------
0042   const edm::ESGetToken<CaloGeometry, CaloGeometryRecord> tokGeom_;
0043   const edm::ESGetToken<CaloTowerConstituentsMap, CaloGeometryRecord> tokMap_;
0044 };
0045 
0046 CaloTowerMapTester::CaloTowerMapTester(const edm::ParameterSet&)
0047     : tokGeom_{esConsumes<CaloGeometry, CaloGeometryRecord>(edm::ESInputTag{})},
0048       tokMap_{esConsumes<CaloTowerConstituentsMap, CaloGeometryRecord>(edm::ESInputTag{})} {}
0049 
0050 void CaloTowerMapTester::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0051   edm::ParameterSetDescription desc;
0052   desc.setUnknown();
0053   descriptions.add("caloTowerMapTester", desc);
0054 }
0055 
0056 void CaloTowerMapTester::analyze(edm::Event const&, edm::EventSetup const& iSetup) {
0057   const CaloGeometry* geo = &iSetup.getData(tokGeom_);
0058   const CaloTowerConstituentsMap* ctmap = &iSetup.getData(tokMap_);
0059   doTest(geo, ctmap);
0060 }
0061 
0062 void CaloTowerMapTester::doTest(const CaloGeometry* geo, const CaloTowerConstituentsMap* ctmap) {
0063   const HcalGeometry* hgeo = static_cast<const HcalGeometry*>(geo->getSubdetectorGeometry(DetId::Hcal, HcalBarrel));
0064   const std::vector<DetId>& dets = hgeo->getValidDetIds(DetId::Hcal, 0);
0065 
0066   for (const auto& id : dets) {
0067     CaloTowerDetId tower = ctmap->towerOf(id);
0068     std::vector<DetId> ids = ctmap->constituentsOf(tower);
0069     edm::LogVerbatim("CaloTower") << static_cast<HcalDetId>(id) << " belongs to " << tower << " which has "
0070                                   << ids.size() << " constituents\n";
0071     for (unsigned int i = 0; i < ids.size(); ++i) {
0072       std::ostringstream st1;
0073       st1 << "[" << i << "] " << std::hex << ids[i].rawId() << std::dec;
0074       if (ids[i].det() == DetId::Ecal && ids[i].subdetId() == EcalBarrel) {
0075         st1 << " " << static_cast<EBDetId>(ids[i]);
0076       } else if (ids[i].det() == DetId::Ecal && ids[i].subdetId() == EcalEndcap) {
0077         st1 << " " << static_cast<EEDetId>(ids[i]);
0078       } else if (ids[i].det() == DetId::Ecal && ids[i].subdetId() == EcalPreshower) {
0079         st1 << " " << static_cast<ESDetId>(ids[i]);
0080       } else if (ids[i].det() == DetId::Hcal) {
0081         st1 << " " << static_cast<HcalDetId>(ids[i]);
0082       }
0083       edm::LogVerbatim("CaloTower") << st1.str();
0084     }
0085   }
0086 }
0087 
0088 //define this as a plug-in
0089 DEFINE_FWK_MODULE(CaloTowerMapTester);