Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-04-04 00:15:39

0001 #include <iostream>
0002 #include <string>
0003 #include <vector>
0004 
0005 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0006 #include "FWCore/Framework/interface/Frameworkfwd.h"
0007 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0008 
0009 #include "FWCore/Framework/interface/Event.h"
0010 #include "FWCore/Framework/interface/EventSetup.h"
0011 #include "FWCore/Framework/interface/MakerMacros.h"
0012 
0013 #include "Geometry/Records/interface/IdealGeometryRecord.h"
0014 #include "Geometry/HGCalGeometry/interface/FastTimeGeometry.h"
0015 #include "DataFormats/ForwardDetId/interface/FastTimeDetId.h"
0016 #include "DataFormats/ForwardDetId/interface/ForwardSubdetector.h"
0017 #include "CoralBase/Exception.h"
0018 
0019 class FastTimeGeometryTester : public edm::one::EDAnalyzer<> {
0020 public:
0021   explicit FastTimeGeometryTester(const edm::ParameterSet&);
0022   ~FastTimeGeometryTester() override = default;
0023 
0024   void analyze(edm::Event const& iEvent, edm::EventSetup const&) override;
0025 
0026 private:
0027   void doTest(const FastTimeGeometry* geom, ForwardSubdetector subdet);
0028 
0029   const std::string name_;
0030   const edm::ESGetToken<FastTimeGeometry, IdealGeometryRecord> geomToken_;
0031   int type_;
0032 };
0033 
0034 FastTimeGeometryTester::FastTimeGeometryTester(const edm::ParameterSet& iC)
0035     : name_(iC.getParameter<std::string>("Detector")),
0036       geomToken_(esConsumes<FastTimeGeometry, IdealGeometryRecord>(edm::ESInputTag{"", name_})) {
0037   type_ = (name_ == "FastTimeBarrel") ? 1 : 2;
0038 }
0039 
0040 void FastTimeGeometryTester::analyze(const edm::Event&, const edm::EventSetup& iSetup) {
0041   ForwardSubdetector subdet = FastTime;
0042 
0043   const auto& geomR = iSetup.getData(geomToken_);
0044   const FastTimeGeometry* geom = &geomR;
0045 
0046   doTest(geom, subdet);
0047 }
0048 
0049 void FastTimeGeometryTester::doTest(const FastTimeGeometry* geom, ForwardSubdetector subdet) {
0050   const std::vector<DetId>& ids = geom->getValidDetIds();
0051   edm::LogVerbatim("FastTimeGeom") << ids.size() << " valid ids for " << geom->cellElement() << std::endl;
0052 
0053   int iEtaZ[] = {1, 7, 13};
0054   int iPhis[] = {1, 5, 10};
0055   int zsides[] = {1, -1};
0056   for (int zside : zsides) {
0057     for (int etaZ : iEtaZ) {
0058       for (int phi : iPhis) {
0059         DetId id1 = (DetId)(FastTimeDetId(type_, etaZ, phi, zside));
0060         auto icell1 = geom->getGeometry(id1);
0061         GlobalPoint global1 = geom->getPosition(id1);
0062         DetId idc1 = geom->getClosestCell(global1);
0063         std::string cherr = (id1.rawId() != idc1.rawId()) ? "  ***** ERROR *****" : "";
0064         edm::LogVerbatim("FastTimeGeom") << "Input " << FastTimeDetId(id1) << " geometry " << icell1 << " position ("
0065                                          << global1.x() << ", " << global1.y() << ", " << global1.z() << " Output "
0066                                          << FastTimeDetId(idc1) << cherr;
0067       }
0068     }
0069   }
0070 }
0071 
0072 //define this as a plug-in
0073 DEFINE_FWK_MODULE(FastTimeGeometryTester);