Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-10-20 10:42:10

0001 #include <cmath>
0002 #include <iostream>
0003 #include <string>
0004 #include <vector>
0005 
0006 #include "CommonTools/UtilAlgos/interface/TFileService.h"
0007 
0008 #include "FWCore/Framework/interface/Frameworkfwd.h"
0009 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0010 #include "FWCore/Framework/interface/Event.h"
0011 #include "FWCore/Framework/interface/EventSetup.h"
0012 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0013 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0014 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0015 
0016 #include "Geometry/Records/interface/IdealGeometryRecord.h"
0017 #include "Geometry/HGCalGeometry/interface/HGCalGeometry.h"
0018 #include "DataFormats/ForwardDetId/interface/HGCSiliconDetId.h"
0019 
0020 class HGCalGeometryRotCheck : public edm::one::EDAnalyzer<edm::one::WatchRuns> {
0021 public:
0022   explicit HGCalGeometryRotCheck(const edm::ParameterSet&);
0023   ~HGCalGeometryRotCheck() override = default;
0024   static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0025 
0026   void beginRun(edm::Run const&, edm::EventSetup const&) override;
0027   void analyze(edm::Event const& iEvent, edm::EventSetup const&) override {}
0028   void endRun(edm::Run const&, edm::EventSetup const&) override {}
0029 
0030 private:
0031   const std::string nameDetector_;
0032   const edm::ESGetToken<HGCalGeometry, IdealGeometryRecord> geomToken_;
0033   const std::vector<int> layers_;
0034 };
0035 
0036 HGCalGeometryRotCheck::HGCalGeometryRotCheck(const edm::ParameterSet& iC)
0037     : nameDetector_(iC.getParameter<std::string>("detectorName")),
0038       geomToken_(esConsumes<HGCalGeometry, IdealGeometryRecord, edm::Transition::BeginRun>(
0039           edm::ESInputTag{"", nameDetector_})),
0040       layers_(iC.getParameter<std::vector<int>>("layers")) {}
0041 
0042 void HGCalGeometryRotCheck::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0043   edm::ParameterSetDescription desc;
0044   std::vector<int> layer = {27, 28, 29, 30, 31, 32, 33};
0045   desc.add<std::string>("detectorName", "HGCalHESiliconSensitive");
0046   desc.add<std::vector<int>>("layers", layer);
0047   descriptions.add("hgcalGeometryRotCheck", desc);
0048 }
0049 
0050 void HGCalGeometryRotCheck::beginRun(const edm::Run&, const edm::EventSetup& iSetup) {
0051   const auto& geomR = iSetup.getData(geomToken_);
0052   const HGCalGeometry* geom = &geomR;
0053   int layerF = *(layers_.begin());
0054   int layerL = *(--layers_.end());
0055   int layerOff = geom->topology().dddConstants().getLayerOffset();
0056   edm::LogVerbatim("HGCalGeom") << nameDetector_ << " with layers in the range " << layerF << ":" << layerL
0057                                 << " Offset " << layerOff;
0058 
0059   auto rrF = geom->topology().dddConstants().rangeRLayer(layerF - layerOff, true);
0060   auto rrE = geom->topology().dddConstants().rangeRLayer(layerL - layerOff, true);
0061   edm::LogVerbatim("HGCalGeom") << " RFront " << rrF.first << ":" << rrF.second << " RBack " << rrE.first << ":"
0062                                 << rrE.second;
0063   double r = rrE.first + 5.0;
0064   const int nPhi = 10;
0065   while (r <= rrF.second) {
0066     for (int k = 0; k < nPhi; ++k) {
0067       double phi = 2.0 * k * M_PI / nPhi;
0068       for (auto lay : layers_) {
0069         double zz = geom->topology().dddConstants().waferZ(lay - layerOff, true);
0070         GlobalPoint global1(r * cos(phi), r * sin(phi), zz);
0071         DetId id = geom->getClosestCellHex(global1, true);
0072         HGCSiliconDetId detId = HGCSiliconDetId(id);
0073         GlobalPoint global2 = geom->getPosition(id);
0074         double dx = global1.x() - global2.x();
0075         double dy = global1.y() - global2.y();
0076         double dR = std::sqrt(dx * dx + dy * dy);
0077         edm::LogVerbatim("HGCalGeom") << "Layer: " << lay << " ID " << detId << " I/P " << global1 << " O/P " << global2
0078                                       << " dR " << dR;
0079       }
0080     }
0081     r += 100.0;
0082   }
0083 }
0084 
0085 //define this as a plug-in
0086 #include "FWCore/Framework/interface/MakerMacros.h"
0087 DEFINE_FWK_MODULE(HGCalGeometryRotCheck);