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 <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 #include "FWCore/ServiceRegistry/interface/Service.h"
0016 #include "FWCore/Utilities/interface/transform.h"
0017 
0018 #include "Geometry/Records/interface/IdealGeometryRecord.h"
0019 #include "Geometry/HGCalCommonData/interface/HGCalGeometryMode.h"
0020 #include "Geometry/HGCalGeometry/interface/HGCalGeometry.h"
0021 #include "DataFormats/ForwardDetId/interface/ForwardSubdetector.h"
0022 #include "DataFormats/ForwardDetId/interface/HFNoseDetId.h"
0023 #include "DataFormats/ForwardDetId/interface/HGCalDetId.h"
0024 #include "DataFormats/ForwardDetId/interface/HGCScintillatorDetId.h"
0025 #include "DataFormats/ForwardDetId/interface/HGCSiliconDetId.h"
0026 
0027 #include "TH1D.h"
0028 #include "TH2D.h"
0029 
0030 class HGCalGeometryCheck : public edm::one::EDAnalyzer<edm::one::WatchRuns, edm::one::SharedResources> {
0031 public:
0032   explicit HGCalGeometryCheck(const edm::ParameterSet&);
0033   ~HGCalGeometryCheck() override;
0034   static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0035 
0036   void beginRun(edm::Run const&, edm::EventSetup const&) override;
0037   void analyze(edm::Event const& iEvent, edm::EventSetup const&) override {}
0038   void endRun(edm::Run const&, edm::EventSetup const&) override {}
0039 
0040 private:
0041   void doTest(const HGCalGeometry* geom, ForwardSubdetector subdet);
0042   void doTestWafer(const HGCalGeometry* geom, DetId::Detector det);
0043   void doTestScint(const HGCalGeometry* geom, DetId::Detector det);
0044 
0045   const std::vector<std::string> nameDetectors_;
0046   const std::vector<edm::ESGetToken<HGCalGeometry, IdealGeometryRecord>> geomTokens_;
0047   const double rmin_, rmax_, zmin_, zmax_;
0048   const int nbinR_, nbinZ_;
0049   const bool ifNose_, verbose_;
0050   std::vector<unsigned int> modHF_;
0051   std::vector<TH2D*> h_RZ_;
0052   std::vector<TH1D*> h_Mod_;
0053 };
0054 
0055 HGCalGeometryCheck::HGCalGeometryCheck(const edm::ParameterSet& iC)
0056     : nameDetectors_(iC.getParameter<std::vector<std::string>>("detectorNames")),
0057       geomTokens_{edm::vector_transform(
0058           nameDetectors_,
0059           [this](const std::string& name) {
0060             return esConsumes<HGCalGeometry, IdealGeometryRecord, edm::Transition::BeginRun>(edm::ESInputTag{"", name});
0061           })},
0062       rmin_(iC.getUntrackedParameter<double>("rMin", 0.0)),
0063       rmax_(iC.getUntrackedParameter<double>("rMax", 300.0)),
0064       zmin_(iC.getUntrackedParameter<double>("zMin", 300.0)),
0065       zmax_(iC.getUntrackedParameter<double>("zMax", 600.0)),
0066       nbinR_(iC.getUntrackedParameter<int>("nBinR", 300)),
0067       nbinZ_(iC.getUntrackedParameter<int>("nBinZ", 600)),
0068       ifNose_(iC.getUntrackedParameter<bool>("ifNose", false)),
0069       verbose_(iC.getUntrackedParameter<bool>("verbosity", false)) {
0070   usesResource(TFileService::kSharedResource);
0071 }
0072 
0073 HGCalGeometryCheck::~HGCalGeometryCheck() {}
0074 
0075 void HGCalGeometryCheck::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0076   edm::ParameterSetDescription desc;
0077   std::vector<std::string> names = {"HGCalEESensitive", "HGCalHESiliconSensitive", "HGCalHEScintillatorSensitive"};
0078   desc.add<std::vector<std::string>>("detectorNames", names);
0079   desc.addUntracked<double>("rMin", 0.0);
0080   desc.addUntracked<double>("rMax", 300.0);
0081   desc.addUntracked<double>("zMin", 300.0);
0082   desc.addUntracked<double>("zMax", 600.0);
0083   desc.addUntracked<int>("nBinR", 300);
0084   desc.addUntracked<int>("nBinZ", 600);
0085   desc.addUntracked<bool>("ifNose", false);
0086   desc.addUntracked<bool>("verbosity", false);
0087   descriptions.add("hgcalGeometryCheck", desc);
0088 }
0089 
0090 void HGCalGeometryCheck::beginRun(const edm::Run&, const edm::EventSetup& iSetup) {
0091   edm::Service<TFileService> fs;
0092   char name[100], title[200];
0093   sprintf(name, "RZ_All");
0094   sprintf(title, "R vs Z for All Detectors");
0095   h_RZ_.emplace_back(fs->make<TH2D>(name, title, nbinZ_, zmin_, zmax_, nbinR_, rmin_, rmax_));
0096 
0097   for (unsigned int ih = 0; ih < nameDetectors_.size(); ++ih) {
0098     const auto& geomR = iSetup.getData(geomTokens_[ih]);
0099     const HGCalGeometry* geom = &geomR;
0100     int layerF = geom->topology().dddConstants().firstLayer();
0101     int layerL = geom->topology().dddConstants().lastLayer(true);
0102     edm::LogVerbatim("HGCalGeom") << nameDetectors_[ih] << " with layers in the range " << layerF << ":" << layerL;
0103     sprintf(name, "RZ_%s", nameDetectors_[ih].c_str());
0104     sprintf(title, "R vs Z for %s", nameDetectors_[ih].c_str());
0105     h_RZ_.emplace_back(fs->make<TH2D>(name, title, nbinZ_, zmin_, zmax_, nbinR_, rmin_, rmax_));
0106     unsigned int k(0);
0107     for (int lay = layerF; lay <= layerL; ++lay, ++k) {
0108       sprintf(name, "Mod_%s_L%d", nameDetectors_[ih].c_str(), lay);
0109       sprintf(title, "Modules in layer %d in %s", lay, nameDetectors_[ih].c_str());
0110       h_Mod_.emplace_back(fs->make<TH1D>(name, title, 200, -50, 50));
0111 
0112       auto zz = geom->topology().dddConstants().waferZ(lay, true);
0113       auto rr = geom->topology().dddConstants().rangeR(zz, true);
0114       auto rr0 = geom->topology().dddConstants().rangeRLayer(lay, true);
0115       edm::LogVerbatim("HGCalGeom") << "Layer " << lay << " R " << rr.first << ":" << rr.second << " (" << rr0.first
0116                                     << ":" << rr0.second << ") Z " << zz;
0117       double r = rr.first;
0118       while (r <= rr.second) {
0119         h_RZ_[0]->Fill(zz, r);
0120         h_RZ_[ih + 1]->Fill(zz, r);
0121         for (int k = 0; k < 100; ++k) {
0122           double phi = 2 * k * M_PI / 100.0;
0123           GlobalPoint global1(r * cos(phi), r * sin(phi), zz);
0124           DetId id = geom->getClosestCell(global1);
0125 
0126           if (ifNose_) {
0127             HFNoseDetId detId = HFNoseDetId(id);
0128             h_Mod_.back()->Fill(detId.waferU());
0129             h_Mod_.back()->Fill(detId.waferV());
0130             if (verbose_)
0131               edm::LogVerbatim("HGCalGeom") << "R: " << r << " ID " << detId;
0132           } else if (geom->topology().waferHexagon6()) {
0133             HGCalDetId detId = HGCalDetId(id);
0134             h_Mod_.back()->Fill(detId.wafer());
0135             if (verbose_)
0136               edm::LogVerbatim("HGCalGeom") << "R: " << r << " ID " << detId;
0137           } else if (geom->topology().tileTrapezoid()) {
0138             HGCScintillatorDetId detId = HGCScintillatorDetId(id);
0139             h_Mod_.back()->Fill(detId.ieta());
0140             if (verbose_)
0141               edm::LogVerbatim("HGCalGeom") << "R: " << r << " ID " << detId;
0142           } else {
0143             HGCSiliconDetId detId = HGCSiliconDetId(id);
0144             h_Mod_.back()->Fill(detId.waferU());
0145             h_Mod_.back()->Fill(detId.waferV());
0146             if (verbose_)
0147               edm::LogVerbatim("HGCalGeom") << "R: " << r << " ID " << detId;
0148           }
0149         }
0150         r += 1.0;
0151       }
0152     }
0153   }
0154 }
0155 
0156 //define this as a plug-in
0157 #include "FWCore/Framework/interface/MakerMacros.h"
0158 DEFINE_FWK_MODULE(HGCalGeometryCheck);