Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-03-29 22:16:07

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 
0014 #include "Geometry/Records/interface/IdealGeometryRecord.h"
0015 #include "Geometry/HGCalGeometry/interface/HGCalGeometry.h"
0016 #include "DataFormats/ForwardDetId/interface/HGCSiliconDetId.h"
0017 #include "CoralBase/Exception.h"
0018 
0019 class HGCalGeomLocaterTester : public edm::one::EDAnalyzer<> {
0020 public:
0021   explicit HGCalGeomLocaterTester(const edm::ParameterSet&);
0022 
0023   void analyze(edm::Event const& iEvent, edm::EventSetup const&) override;
0024 
0025 private:
0026   void doTestSilicon(const HGCalGeometry* geom, DetId::Detector det);
0027   void doTestScintillator(const HGCalGeometry* geom, DetId::Detector det);
0028 
0029   std::string name_;
0030   edm::ESGetToken<HGCalGeometry, IdealGeometryRecord> geomToken_;
0031 };
0032 
0033 HGCalGeomLocaterTester::HGCalGeomLocaterTester(const edm::ParameterSet& iC)
0034     : name_{iC.getParameter<std::string>("Detector")},
0035       geomToken_{esConsumes<HGCalGeometry, IdealGeometryRecord>(edm::ESInputTag{"", name_})} {}
0036 
0037 void HGCalGeomLocaterTester::analyze(const edm::Event&, const edm::EventSetup& iSetup) {
0038   const HGCalGeometry* geom = &iSetup.getData(geomToken_);
0039   if (geom->topology().waferHexagon8()) {
0040     DetId::Detector det;
0041     if (name_ == "HGCalHESiliconSensitive")
0042       det = DetId::HGCalHSi;
0043     else
0044       det = DetId::HGCalEE;
0045     edm::LogVerbatim("HGCalGeomX") << "Perform test for " << name_ << " Detector " << det << " Mode "
0046                                    << geom->topology().dddConstants().geomMode();
0047     doTestSilicon(geom, det);
0048   } else if (geom->topology().tileTrapezoid()) {
0049     DetId::Detector det(DetId::HGCalHSc);
0050     edm::LogVerbatim("HGCalGeomX") << "Perform test for " << name_ << " Detector " << det << " Mode "
0051                                    << geom->topology().dddConstants().geomMode();
0052     doTestScintillator(geom, det);
0053   }
0054 }
0055 
0056 void HGCalGeomLocaterTester::doTestSilicon(const HGCalGeometry* geom, DetId::Detector det) {
0057   const std::vector<DetId>& ids = geom->getValidDetIds();
0058   edm::LogVerbatim("HGCalGeomX") << "doTest:: " << ids.size() << " valid ids for " << geom->cellElement();
0059   const double tol = 0.001;
0060   const unsigned int step = 10;
0061   int all(0), good(0), bad(0);
0062   for (unsigned int k = 0; k < ids.size(); k += step) {
0063     ++all;
0064     HGCSiliconDetId id(ids[k]);
0065     std::ostringstream st1;
0066     st1 << "ID[" << k << "] " << id;
0067     GlobalPoint global = geom->getPosition(id);
0068     auto waferxy = geom->topology().dddConstants().locateCell(id, false);
0069     double dx = global.x() - waferxy.first;
0070     double dy = global.y() - waferxy.second;
0071     st1 << " position (" << global.x() << ", " << global.y() << ", " << global.z() << ") waferXY (" << waferxy.first
0072         << ", " << waferxy.second << ") Delta (" << dx << ", " << dy << ")";
0073     if ((std::abs(dx) > tol) || (std::abs(dy) > tol)) {
0074       st1 << " ***** ERROR *****";
0075       ++bad;
0076       geom->topology().dddConstants().locateCell(id, true);
0077     } else {
0078       ++good;
0079     }
0080     edm::LogVerbatim("HGCalGeomX") << st1.str();
0081   }
0082   edm::LogVerbatim("HGCalGeomX") << "\n\nStudied " << all << " (" << ids.size() << ") IDs of which " << good
0083                                  << " are good and " << bad << " are bad\n\n\n";
0084 }
0085 
0086 void HGCalGeomLocaterTester::doTestScintillator(const HGCalGeometry* geom, DetId::Detector det) {
0087   const std::vector<DetId>& ids = geom->getValidDetIds();
0088   edm::LogVerbatim("HGCalGeomX") << "doTest:: " << ids.size() << " valid ids for " << geom->cellElement();
0089   const double tol = 0.01;
0090   const unsigned int step = 10;
0091   int all(0), good(0), bad(0);
0092   for (unsigned int k = 0; k < ids.size(); k += step) {
0093     ++all;
0094     HGCScintillatorDetId id(ids[k]);
0095     std::ostringstream st1;
0096     st1 << "ID[" << k << "] " << id;
0097     GlobalPoint global = geom->getPosition(id);
0098     auto tilexy = geom->topology().dddConstants().locateCell(id, false);
0099     double dx = global.x() - tilexy.first;
0100     double dy = global.y() - tilexy.second;
0101     st1 << " position (" << global.x() << ", " << global.y() << ", " << global.z() << ") tileXY (" << tilexy.first
0102         << ", " << tilexy.second << ") Delta (" << dx << ", " << dy << ")";
0103     if ((std::abs(dx) > tol) || (std::abs(dy) > tol)) {
0104       double r1 = sqrt(global.x() * global.x() + global.y() * global.y());
0105       double r2 = sqrt(tilexy.first * tilexy.first + tilexy.second * tilexy.second);
0106       st1 << " R " << r1 << ":" << r2 << " ***** ERROR *****";
0107       ++bad;
0108       geom->topology().dddConstants().locateCell(id, true);
0109     } else {
0110       ++good;
0111     }
0112     edm::LogVerbatim("HGCalGeomX") << st1.str();
0113   }
0114   edm::LogVerbatim("HGCalGeomX") << "\n\nStudied " << all << " (" << ids.size() << ") IDs of which " << good
0115                                  << " are good and " << bad << " are bad\n\n\n";
0116 }
0117 
0118 //define this as a plug-in
0119 DEFINE_FWK_MODULE(HGCalGeomLocaterTester);