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/HcalCommonData/interface/HcalDDDRecConstants.h"
0006 #include "Geometry/Records/interface/CaloGeometryRecord.h"
0007 #include "Geometry/CaloGeometry/interface/CaloGeometry.h"
0008 #include "Geometry/CaloGeometry/interface/CaloCellGeometry.h"
0009 #include "Geometry/HcalTowerAlgo/interface/HcalGeometry.h"
0010 #include "Geometry/HcalTowerAlgo/interface/HcalFlexiHardcodeGeometryLoader.h"
0011 #include "DataFormats/HcalDetId/interface/HcalDetId.h"
0012 #include <iostream>
0013 #include <string>
0014 
0015 class HcalGeometryPlan1Tester : public edm::one::EDAnalyzer<> {
0016 public:
0017   explicit HcalGeometryPlan1Tester(const edm::ParameterSet&);
0018   ~HcalGeometryPlan1Tester(void) override {}
0019 
0020   void beginJob() override {}
0021   void analyze(edm::Event const&, edm::EventSetup const&) override;
0022   void endJob() override {}
0023 
0024 private:
0025   bool geomES_;
0026   edm::ESGetToken<HcalDDDRecConstants, HcalRecNumberingRecord> tok_ddrec_;
0027   edm::ESGetToken<HcalTopology, HcalRecNumberingRecord> tok_htopo_;
0028   edm::ESGetToken<CaloGeometry, CaloGeometryRecord> tok_geom_;
0029 };
0030 
0031 HcalGeometryPlan1Tester::HcalGeometryPlan1Tester(const edm::ParameterSet& iConfig) {
0032   geomES_ = iConfig.getParameter<bool>("GeometryFromES");
0033   tok_ddrec_ = esConsumes<HcalDDDRecConstants, HcalRecNumberingRecord>();
0034   tok_htopo_ = esConsumes<HcalTopology, HcalRecNumberingRecord>();
0035   tok_geom_ = esConsumes<CaloGeometry, CaloGeometryRecord>();
0036 }
0037 
0038 void HcalGeometryPlan1Tester::analyze(const edm::Event& /*iEvent*/, const edm::EventSetup& iSetup) {
0039   const HcalDDDRecConstants hcons = iSetup.getData(tok_ddrec_);
0040   const HcalTopology topology = iSetup.getData(tok_htopo_);
0041   //  HcalGeometry* geom(nullptr);
0042   const CaloSubdetectorGeometry* geom(nullptr);
0043   if (geomES_) {
0044     const CaloGeometry* geo = &iSetup.getData(tok_geom_);
0045     geom = (geo->getSubdetectorGeometry(DetId::Hcal, HcalBarrel));
0046   } else {
0047     HcalFlexiHardcodeGeometryLoader m_loader;
0048     geom = (m_loader.load(topology, hcons));
0049   }
0050   //  geom  = (HcalGeometry*)(geom0);
0051 
0052   std::vector<HcalDetId> idsp;
0053   bool ok = hcons.specialRBXHBHE(true, idsp);
0054   edm::LogVerbatim("HCalGeom") << "Special RBX Flag " << ok << " with " << idsp.size() << " ID's" << std::endl;
0055   int nall(0), ngood(0);
0056   for (std::vector<HcalDetId>::const_iterator itr = idsp.begin(); itr != idsp.end(); ++itr) {
0057     if (topology.valid(*itr)) {
0058       ++nall;
0059       HcalDetId idnew = hcons.mergedDepthDetId(*itr);
0060       GlobalPoint pt1 = (dynamic_cast<const HcalGeometry*>(geom))->getGeometryBase(*itr)->getPosition();
0061       auto ptr = geom->getGeometry(idnew);
0062       GlobalPoint pt2 = ptr->getPosition();
0063       GlobalPoint pt0 = (dynamic_cast<const HcalGeometry*>(geom))->getPosition(idnew);
0064       double deta = std::abs(pt1.eta() - pt2.eta());
0065       double dphi = std::abs(pt1.phi() - pt2.phi());
0066       if (dphi > M_PI)
0067         dphi -= (2 * M_PI);
0068       ok = (deta < 0.00001) && (dphi < 0.00001);
0069       deta = std::abs(pt0.eta() - pt2.eta());
0070       dphi = std::abs(pt0.phi() - pt2.phi());
0071       if (dphi > M_PI)
0072         dphi -= (2 * M_PI);
0073       if ((deta > 0.00001) || (dphi > 0.00001))
0074         ok = false;
0075       if (ok)
0076         ++ngood;
0077       std::string cok = (ok) ? "" : " ***** ERROR *****";
0078       edm::LogVerbatim("HCalGeom") << "Unmerged ID " << (*itr) << " (" << pt1.eta() << ", " << pt1.phi() << ", "
0079                                    << pt1.z() << ") Merged ID " << idnew << " (" << pt2.eta() << ", " << pt2.phi()
0080                                    << ", " << pt2.z() << ") or (" << pt0.eta() << ", " << pt0.phi() << ", " << pt0.z()
0081                                    << ")" << cok;
0082       ;
0083     }
0084   }
0085   edm::LogVerbatim("HCalGeom") << ngood << " out of " << nall << " ID's are tested OK";
0086 }
0087 
0088 DEFINE_FWK_MODULE(HcalGeometryPlan1Tester);