Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:15:12

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/IdealGeometryRecord.h"
0016 #include "Geometry/HGCalGeometry/interface/HGCalGeometry.h"
0017 #include "DataFormats/ForwardDetId/interface/ForwardSubdetector.h"
0018 #include "DataFormats/ForwardDetId/interface/HGCalDetId.h"
0019 #include "DataFormats/ForwardDetId/interface/HGCScintillatorDetId.h"
0020 #include "DataFormats/ForwardDetId/interface/HGCSiliconDetId.h"
0021 
0022 class HGCalValidTest : public edm::one::EDAnalyzer<> {
0023 public:
0024   explicit HGCalValidTest(const edm::ParameterSet&);
0025   ~HGCalValidTest() override = default;
0026 
0027   static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0028   void analyze(edm::Event const& iEvent, edm::EventSetup const&) override;
0029 
0030 private:
0031   const std::string name;
0032   const edm::ESGetToken<HGCalGeometry, IdealGeometryRecord> geomToken_;
0033 };
0034 
0035 HGCalValidTest::HGCalValidTest(const edm::ParameterSet& iC)
0036     : name{iC.getParameter<std::string>("detector")},
0037       geomToken_{esConsumes<HGCalGeometry, IdealGeometryRecord>(edm::ESInputTag{"", name})} {}
0038 
0039 void HGCalValidTest::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0040   edm::ParameterSetDescription desc;
0041   desc.add<std::string>("detector", "HGCalHEScintillatorSensitive");
0042   descriptions.add("hgcalValidTestHEB", desc);
0043 }
0044 
0045 void HGCalValidTest::analyze(const edm::Event&, const edm::EventSetup& iSetup) {
0046   const auto& geom = &iSetup.getData(geomToken_);
0047   DetId::Detector det;
0048   if (geom->topology().waferHexagon6()) {
0049     ForwardSubdetector subdet;
0050     if (name == "HGCalHESiliconSensitive")
0051       subdet = HGCHEF;
0052     else if (name == "HGCalHEScintillatorSensitive")
0053       subdet = HGCHEB;
0054     else
0055       subdet = HGCEE;
0056     edm::LogVerbatim("HGCalGeom") << "Cannot perform test for " << name << " Detector:Subdetector " << DetId::Forward
0057                                   << ":" << subdet << " Mode " << geom->topology().dddConstants().geomMode();
0058     return;
0059   } else {
0060     if (name == "HGCalHESiliconSensitive")
0061       det = DetId::HGCalHSi;
0062     else if (name == "HGCalHEScintillatorSensitive")
0063       det = DetId::HGCalHSc;
0064     else
0065       det = DetId::HGCalEE;
0066     edm::LogVerbatim("HGCalGeom") << "Perform test for " << name << " Detector " << det << " Mode "
0067                                   << geom->topology().dddConstants().geomMode();
0068   }
0069 
0070   int firstLayer = geom->topology().dddConstants().firstLayer();
0071   int lastLayer = geom->topology().dddConstants().lastLayer(true);
0072   const std::vector<DetId>& ids = geom->getValidDetIds();
0073   edm::LogVerbatim("HGCalGeom") << "doTest: " << ids.size() << " valid ids for " << geom->cellElement();
0074 
0075   std::vector<int> zsides = {-1, 1};
0076   for (int zside : zsides) {
0077     for (int layer = firstLayer; layer <= lastLayer; ++layer) {
0078       std::vector<std::pair<int, int> > done;
0079       for (auto const& id : ids) {
0080         if (det == DetId::HGCalHSc) {
0081           HGCScintillatorDetId hid(id);
0082           if ((hid.zside() != zside) || (hid.layer() != layer))
0083             continue;
0084           std::pair<int, int> ring = std::make_pair(hid.ring(), 0);
0085           if (std::find(done.begin(), done.end(), ring) != done.end())
0086             continue;
0087           done.emplace_back(ring);
0088           edm::LogVerbatim("HGCalGeom") << "Corners for " << hid;
0089         } else {
0090           HGCSiliconDetId hid(id);
0091           if ((hid.zside() != zside) || (hid.layer() != layer))
0092             continue;
0093           if (std::find(done.begin(), done.end(), hid.waferUV()) != done.end())
0094             continue;
0095           done.emplace_back(hid.waferUV());
0096           edm::LogVerbatim("HGCalGeom") << "Corners for " << hid;
0097         }
0098 
0099         const auto cor = geom->getNewCorners(id);
0100         std::ostringstream st1;
0101         for (unsigned int k = 0; k < cor.size(); ++k)
0102           st1 << " [" << k << "] " << std::setprecision(4) << cor[k];
0103         edm::LogVerbatim("HGCalGeom") << st1.str();
0104       }
0105     }
0106   }
0107 }
0108 
0109 //define this as a plug-in
0110 DEFINE_FWK_MODULE(HGCalValidTest);