Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:14:28

0001 #include "CommonTools/UtilAlgos/interface/TFileService.h"
0002 #include "DataFormats/EcalDetId/interface/ESDetId.h"
0003 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0004 #include "FWCore/Framework/interface/EventSetup.h"
0005 #include "FWCore/Framework/interface/MakerMacros.h"
0006 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0007 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0008 #include "FWCore/ServiceRegistry/interface/Service.h"
0009 #include "Geometry/Records/interface/CaloGeometryRecord.h"
0010 #include "Geometry/CaloGeometry/interface/CaloGeometry.h"
0011 #include "Geometry/CaloGeometry/interface/CaloCellGeometry.h"
0012 #include "Geometry/CaloGeometry/interface/CaloSubdetectorGeometry.h"
0013 #include "Geometry/CaloGeometry/interface/EZArrayFL.h"
0014 
0015 #include "TH2.h"
0016 
0017 #include <iomanip>
0018 #include <iostream>
0019 #include <sstream>  // for ostringstream
0020 
0021 typedef EZArrayFL<GlobalPoint> CornersVec;
0022 
0023 class EcalPreshowerCellParameterDump : public edm::one::EDAnalyzer<edm::one::SharedResources> {
0024 public:
0025   explicit EcalPreshowerCellParameterDump(const edm::ParameterSet&);
0026   ~EcalPreshowerCellParameterDump() override {}
0027 
0028   static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0029 
0030   void beginJob() override {}
0031   void analyze(edm::Event const& iEvent, edm::EventSetup const&) override;
0032   void endJob() override {}
0033 
0034 private:
0035   const bool debug_;
0036   const edm::ESGetToken<CaloGeometry, CaloGeometryRecord> tok_geom_;
0037   std::vector<TH2D*> hist_;
0038 };
0039 
0040 EcalPreshowerCellParameterDump::EcalPreshowerCellParameterDump(const edm::ParameterSet& ps)
0041     : debug_(ps.getUntrackedParameter<bool>("debug", false)),
0042       tok_geom_(esConsumes<CaloGeometry, CaloGeometryRecord>()) {
0043   usesResource(TFileService::kSharedResource);
0044 
0045   if (debug_) {
0046     edm::Service<TFileService> fs;
0047     for (short iz = 0; iz < 2; ++iz) {
0048       short zside = 2 * iz - 1;
0049       for (short lay = 1; lay <= 2; ++lay) {
0050         std::ostringstream name, title;
0051         name << "hist" << iz << lay;
0052         title << "y vs. x (zside = " << zside << ",layer = " << lay << ")";
0053         hist_.emplace_back(
0054             fs->make<TH2D>(name.str().c_str(), title.str().c_str(), 5000, -125.0, 125.0, 5000, -125.0, 125.0));
0055       }
0056     }
0057   }
0058 }
0059 
0060 void EcalPreshowerCellParameterDump::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0061   edm::ParameterSetDescription desc;
0062   desc.addUntracked<bool>("debug", false);
0063   descriptions.add("ecalPreshowerCellParameterDump", desc);
0064 }
0065 
0066 void EcalPreshowerCellParameterDump::analyze(const edm::Event& /*iEvent*/, const edm::EventSetup& iSetup) {
0067   const CaloGeometry* geo = &iSetup.getData(tok_geom_);
0068   const CaloSubdetectorGeometry* ecalGeom =
0069       static_cast<const CaloSubdetectorGeometry*>(geo->getSubdetectorGeometry(DetId::Ecal, EcalPreshower));
0070 
0071   edm::LogVerbatim("EcalGeom") << "\n\nStudy Detector = Ecal SubDetector = ES"
0072                                << "\n======================================\n";
0073   const std::vector<DetId>& ids = ecalGeom->getValidDetIds(DetId::Ecal, EcalPreshower);
0074   int nall(0);
0075   for (auto id : ids) {
0076     ++nall;
0077     auto geom = ecalGeom->getGeometry(id);
0078     ESDetId esid(id);
0079 
0080     if (debug_) {
0081       edm::LogVerbatim("EcalGeom") << nall << " " << esid.rawId() << " " << std::setprecision(6) << geom->getPosition();
0082       unsigned int hid = ((esid.zside() + 1) + esid.plane() - 1);
0083       if (hid < hist_.size())
0084         hist_[hid]->Fill(geom->getPosition().x(), geom->getPosition().y());
0085     } else {
0086       std::ostringstream st1;
0087       st1 << "Cell[" << nall << "] " << esid << " geom->getPosition " << std::setprecision(4) << geom->getPosition()
0088           << " BackPoint " << geom->getBackPoint() << " [rho,eta:etaSpan,phi:phiSpan] (" << geom->rhoPos() << ", "
0089           << geom->etaPos() << ":" << geom->etaSpan() << ", " << geom->phiPos() << ":" << geom->phiSpan() << ")";
0090 
0091       const CaloCellGeometry::CornersVec& corners(geom->getCorners());
0092 
0093       for (unsigned int ci(0); ci != corners.size(); ci++) {
0094         st1 << " Corner: " << ci << "  Location" << corners[ci] << " ; ";
0095       }
0096 
0097       edm::LogVerbatim("EcalGeom") << st1.str();
0098     }
0099   }
0100   edm::LogVerbatim("EcalGeom") << "\n\nDumps a total of : " << nall << " cells of the detector\n";
0101 }
0102 
0103 DEFINE_FWK_MODULE(EcalPreshowerCellParameterDump);