Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-03-29 07:44:26

0001 #include <iostream>
0002 #include <string>
0003 #include <vector>
0004 
0005 #include "FWCore/Framework/interface/Frameworkfwd.h"
0006 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0007 #include "FWCore/Framework/interface/Event.h"
0008 #include "FWCore/Framework/interface/EventSetup.h"
0009 #include "FWCore/Framework/interface/MakerMacros.h"
0010 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0011 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0012 
0013 #include "Geometry/Records/interface/IdealGeometryRecord.h"
0014 #include "Geometry/HGCalCommonData/interface/HGCalGeometryMode.h"
0015 #include "Geometry/HGCalGeometry/interface/HGCalGeometry.h"
0016 #include "DataFormats/ForwardDetId/interface/ForwardSubdetector.h"
0017 #include "DataFormats/ForwardDetId/interface/HGCalDetId.h"
0018 #include "DataFormats/ForwardDetId/interface/HGCScintillatorDetId.h"
0019 #include "DataFormats/ForwardDetId/interface/HGCSiliconDetId.h"
0020 #include "CoralBase/Exception.h"
0021 
0022 class HGCalSizeTester : public edm::one::EDAnalyzer<> {
0023 public:
0024   explicit HGCalSizeTester(const edm::ParameterSet&);
0025   ~HGCalSizeTester() override = default;
0026 
0027   void analyze(edm::Event const& iEvent, edm::EventSetup const&) override;
0028 
0029 private:
0030   void doTestWafer(const HGCalGeometry* geom, DetId::Detector det);
0031   void doTestScint(const HGCalGeometry* geom, DetId::Detector det);
0032 
0033   const std::string name;
0034   const edm::ESGetToken<HGCalGeometry, IdealGeometryRecord> geomToken_;
0035 };
0036 
0037 HGCalSizeTester::HGCalSizeTester(const edm::ParameterSet& iC)
0038     : name{iC.getParameter<std::string>("detector")},
0039       geomToken_{esConsumes<HGCalGeometry, IdealGeometryRecord>(edm::ESInputTag{"", name})} {}
0040 
0041 void HGCalSizeTester::analyze(const edm::Event&, const edm::EventSetup& iSetup) {
0042   const auto& geomR = iSetup.getData(geomToken_);
0043   const HGCalGeometry* geom = &geomR;
0044   if (!geom->topology().waferHexagon6()) {
0045     DetId::Detector det;
0046     if (name == "HGCalHESiliconSensitive")
0047       det = DetId::HGCalHSi;
0048     else if (name == "HGCalHEScintillatorSensitive")
0049       det = DetId::HGCalHSc;
0050     else
0051       det = DetId::HGCalEE;
0052     edm::LogVerbatim("HGCalGeomX") << "Perform test for " << name << " Detector " << det;
0053     if (name == "HGCalHEScintillatorSensitive") {
0054       doTestScint(geom, det);
0055     } else {
0056       doTestWafer(geom, det);
0057     }
0058   }
0059 }
0060 
0061 void HGCalSizeTester::doTestWafer(const HGCalGeometry* geom, DetId::Detector det) {
0062   const std::vector<DetId>& ids = geom->getValidDetIds();
0063   edm::LogVerbatim("HGCalGeomX") << "doTestWafer:: " << ids.size() << " valid ids for " << geom->cellElement();
0064   int layers[] = {1, 5, 10};
0065   int zsides[] = {1, -1};
0066   int cells[] = {1, 4, 7};
0067   int wafers[] = {7, 5, 3, -3, -5, -7};
0068   for (int zside : zsides) {
0069     for (int layer : layers) {
0070       for (int waferU : wafers) {
0071         for (int waferV : wafers) {
0072           int type = geom->topology().dddConstants().getTypeHex(layer, waferU, waferV);
0073           edm::LogVerbatim("HGCalGeomX") << "zside " << zside << " layer " << layer << " wafer " << waferU << ":"
0074                                          << waferV << " type " << type;
0075           for (int cellU : cells) {
0076             for (int cellV : cells) {
0077               edm::LogVerbatim("HGCalGeomX") << "det " << det << " cell " << cellU << ":" << cellV;
0078               DetId id1 = (DetId)(HGCSiliconDetId(det, zside, type, layer, waferU, waferV, cellU, cellV));
0079               edm::LogVerbatim("HGCalGeomX") << HGCSiliconDetId(id1);
0080               if (geom->topology().valid(id1)) {
0081                 auto icell1 = geom->getGeometry(id1);
0082                 GlobalPoint global1 = geom->getPosition(id1);
0083                 DetId idc1 = geom->getClosestCell(global1);
0084                 std::string cherr = (id1.rawId() != idc1.rawId()) ? "***** ERROR *****" : "";
0085                 edm::LogVerbatim("HGCalGeomX")
0086                     << "DetId (" << det << ":" << zside << ":" << type << ":" << layer << ":" << waferU << ":" << waferV
0087                     << ":" << cellU << ":" << cellV << ") Geom " << icell1 << " position (" << global1.x() << ", "
0088                     << global1.y() << ", " << global1.z() << ") ids " << std::hex << id1.rawId() << ":" << idc1.rawId()
0089                     << std::dec << ":" << HGCSiliconDetId(id1) << ":" << HGCSiliconDetId(idc1)
0090                     << " parameter[3] = " << icell1->param()[2] << ":" << icell1->param()[2] << cherr;
0091                 std::vector<GlobalPoint> corners = geom->getNewCorners(idc1);
0092                 std::ostringstream st1;
0093                 st1 << corners.size() << " corners";
0094                 for (auto const& cor : corners)
0095                   st1 << " [" << cor.x() << "," << cor.y() << "," << cor.z() << "]";
0096                 edm::LogVerbatim("HGCalGeomX") << st1.str();
0097                 std::vector<DetId> ids = geom->topology().neighbors(id1);
0098                 int k(0);
0099                 for (auto const& id : ids) {
0100                   GlobalPoint global0 = geom->getPosition(id);
0101                   edm::LogVerbatim("HGCalGeomX") << "Neighbor[" << k << "] " << HGCSiliconDetId(id) << " position ("
0102                                                  << global0.x() << ", " << global0.y() << ", " << global0.z() << ")";
0103                   ++k;
0104                 }
0105               }
0106             }
0107           }
0108         }
0109       }
0110     }
0111   }
0112 }
0113 
0114 void HGCalSizeTester::doTestScint(const HGCalGeometry* geom, DetId::Detector det) {
0115   const std::vector<DetId>& ids = geom->getValidDetIds();
0116   edm::LogVerbatim("HGCalGeomX") << "doTestScint: " << ids.size() << " valid ids for " << geom->cellElement();
0117   int layers[] = {9, 15, 22};
0118   int zsides[] = {1, -1};
0119   int iphis[] = {1, 51, 101, 151, 201};
0120   int ietas[] = {11, 20, 29};
0121   for (int zside : zsides) {
0122     for (int layer : layers) {
0123       int type = geom->topology().dddConstants().getTypeTrap(layer);
0124       for (int ieta : ietas) {
0125         for (int iphi : iphis) {
0126           DetId id1 = (DetId)(HGCScintillatorDetId(type, layer, zside * ieta, iphi));
0127           if (geom->topology().valid(id1)) {
0128             auto icell1 = geom->getGeometry(id1);
0129             GlobalPoint global1 = geom->getPosition(id1);
0130             DetId idc1 = geom->getClosestCell(global1);
0131             std::string cherr = (id1.rawId() != idc1.rawId()) ? "***** ERROR *****" : "";
0132             edm::LogVerbatim("HGCalGeomX")
0133                 << "DetId (" << det << ":" << zside << ":" << type << ":" << layer << ":" << ieta << ":" << iphi
0134                 << ") Geom " << icell1 << " position (" << global1.x() << ", " << global1.y() << ", " << global1.z()
0135                 << ") ids " << std::hex << id1.rawId() << ":" << idc1.rawId() << std::dec << ":"
0136                 << HGCScintillatorDetId(id1) << ":" << HGCScintillatorDetId(idc1)
0137                 << " parameter[11] = " << icell1->param()[10] << ":" << icell1->param()[10] << cherr;
0138             std::vector<GlobalPoint> corners = geom->getNewCorners(idc1);
0139             std::ostringstream st1;
0140             st1 << corners.size() << " corners";
0141             for (auto const& cor : corners)
0142               st1 << " [" << cor.x() << "," << cor.y() << "," << cor.z() << "]";
0143             edm::LogVerbatim("HGCalGeomX") << st1.str();
0144             std::vector<DetId> ids = geom->topology().neighbors(id1);
0145             int k(0);
0146             for (auto const& id : ids) {
0147               GlobalPoint global0 = geom->getPosition(id);
0148               edm::LogVerbatim("HGCalGeomX") << "Neighbor[" << k << "] " << HGCScintillatorDetId(id) << " position ("
0149                                              << global0.x() << ", " << global0.y() << ", " << global0.z() << ")";
0150               ++k;
0151             }
0152           }
0153         }
0154       }
0155     }
0156   }
0157 }
0158 
0159 //define this as a plug-in
0160 DEFINE_FWK_MODULE(HGCalSizeTester);