Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #include <cmath>
0002 #include <iostream>
0003 #include <sstream>
0004 #include <string>
0005 #include <vector>
0006 
0007 #include "FWCore/Framework/interface/Frameworkfwd.h"
0008 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0009 #include "FWCore/Framework/interface/Event.h"
0010 #include "FWCore/Framework/interface/EventSetup.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/Math/interface/angle_units.h"
0018 #include "DataFormats/ForwardDetId/interface/HGCSiliconDetId.h"
0019 
0020 using namespace angle_units::operators;
0021 
0022 class HGCalGeometryNewCornersTest : public edm::one::EDAnalyzer<edm::one::WatchRuns> {
0023 public:
0024   explicit HGCalGeometryNewCornersTest(const edm::ParameterSet&);
0025   ~HGCalGeometryNewCornersTest() override = default;
0026   static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0027 
0028   void beginRun(edm::Run const&, edm::EventSetup const&) override;
0029   void analyze(edm::Event const& iEvent, edm::EventSetup const&) override {}
0030   void endRun(edm::Run const&, edm::EventSetup const&) override {}
0031 
0032 private:
0033   const std::string nameDetector_;
0034   const edm::ESGetToken<HGCalGeometry, IdealGeometryRecord> geomToken_;
0035   const std::vector<int> layers_;
0036   const std::vector<int> waferU_, waferV_, types_;
0037   const bool debug_;
0038 };
0039 
0040 HGCalGeometryNewCornersTest::HGCalGeometryNewCornersTest(const edm::ParameterSet& iC)
0041     : nameDetector_(iC.getParameter<std::string>("detectorName")),
0042       geomToken_(esConsumes<HGCalGeometry, IdealGeometryRecord, edm::Transition::BeginRun>(
0043           edm::ESInputTag{"", nameDetector_})),
0044       layers_(iC.getParameter<std::vector<int>>("layers")),
0045       waferU_(iC.getParameter<std::vector<int>>("waferUs")),
0046       waferV_(iC.getParameter<std::vector<int>>("waferVs")),
0047       types_(iC.getParameter<std::vector<int>>("types")),
0048       debug_(iC.getParameter<bool>("debugFlag")) {}
0049 
0050 void HGCalGeometryNewCornersTest::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0051   edm::ParameterSetDescription desc;
0052   std::vector<int> layer = {27, 28, 29, 30, 31, 32};
0053   std::vector<int> waferU = {-2, -3, 1, -8, 2, 8};
0054   std::vector<int> waferV = {0, -2, 3, 0, 9, 0};
0055   std::vector<int> type = {0, 0, 0, 2, 2, 2};
0056   desc.add<std::string>("detectorName", "HGCalHESiliconSensitive");
0057   desc.add<std::vector<int>>("layers", layer);
0058   desc.add<std::vector<int>>("waferUs", waferU);
0059   desc.add<std::vector<int>>("waferVs", waferV);
0060   desc.add<std::vector<int>>("types", type);
0061   desc.add<bool>("debugFlag", false);
0062   descriptions.add("hgcalGeometryNewCornersTest", desc);
0063 }
0064 
0065 void HGCalGeometryNewCornersTest::beginRun(const edm::Run&, const edm::EventSetup& iSetup) {
0066   const auto& geomR = iSetup.getData(geomToken_);
0067   const HGCalGeometry* geom = &geomR;
0068   DetId::Detector det = (nameDetector_ == "HGCalEESensitive") ? DetId::HGCalEE : DetId::HGCalHSi;
0069   int layerF = *(layers_.begin());
0070   int layerL = *(--layers_.end());
0071   int layerOff = geom->topology().dddConstants().getLayerOffset();
0072   edm::LogVerbatim("HGCalGeom") << nameDetector_ << " with layers in the range " << layerF << ":" << layerL
0073                                 << " Offset " << layerOff << " and for " << waferU_.size() << " wafers and cells";
0074 
0075   for (unsigned int k = 0; k < waferU_.size(); ++k) {
0076     for (auto lay : layers_) {
0077       HGCSiliconDetId detId(det, 1, types_[k], lay - layerOff, waferU_[k], waferV_[k], 0, 0);
0078       GlobalPoint global = geom->getPosition(DetId(detId), debug_);
0079       double phi2 = global.phi();
0080       auto xy = geom->topology().dddConstants().waferPosition(lay - layerOff, waferU_[k], waferV_[k], true, debug_);
0081       double phi1 = std::atan2(xy.second, xy.first);
0082       edm::LogVerbatim("HGCalGeom") << "Layer: " << lay << " U " << waferU_[k] << " V " << waferV_[k] << " Position ("
0083                                     << xy.first << ", " << xy.second << ") phi " << convertRadToDeg(phi1);
0084       edm::LogVerbatim("HGCalGeom") << detId << " Position " << global << " phi " << convertRadToDeg(phi2);
0085       std::vector<GlobalPoint> corners = geom->getNewCorners(DetId(detId), debug_);
0086       std::ostringstream st1;
0087       for (auto const& it : corners)
0088         st1 << it << ", ";
0089       edm::LogVerbatim("HGCalGeom") << "Corners: " << st1.str();
0090     }
0091   }
0092 }
0093 
0094 //define this as a plug-in
0095 #include "FWCore/Framework/interface/MakerMacros.h"
0096 DEFINE_FWK_MODULE(HGCalGeometryNewCornersTest);