Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-05-26 00:02:36

0001 #include <memory>
0002 
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/Utilities/interface/ESGetToken.h"
0007 
0008 #include "Geometry/Records/interface/CaloGeometryRecord.h"
0009 #include "Geometry/Records/interface/CaloTopologyRecord.h"
0010 #include "Geometry/CaloGeometry/interface/CaloGeometry.h"
0011 #include "Geometry/CaloTopology/interface/CaloTopology.h"
0012 #include "Geometry/CaloTopology/interface/CaloSubdetectorTopology.h"
0013 
0014 #include "DataFormats/EcalDetId/interface/EBDetId.h"
0015 #include "DataFormats/EcalDetId/interface/EEDetId.h"
0016 #include "DataFormats/EcalDetId/interface/EcalTrigTowerDetId.h"
0017 
0018 #include <TCanvas.h>
0019 #include <TVirtualPad.h>
0020 #include <TStyle.h>
0021 #include <TROOT.h>
0022 #include <TH2F.h>
0023 #include <TBox.h>
0024 
0025 #include <iostream>
0026 
0027 class TestEcalGetWindow : public edm::one::EDAnalyzer<> {
0028 public:
0029   explicit TestEcalGetWindow(const edm::ParameterSet&);
0030   ~TestEcalGetWindow() override;
0031 
0032   void beginJob() override {}
0033   void analyze(edm::Event const& iEvent, edm::EventSetup const&) override;
0034   void endJob() override {}
0035 
0036 private:
0037   void build(const CaloGeometry& cg, const CaloTopology& etmap, DetId::Detector det, int subdetn, const char* name);
0038   int towerColor(const EcalTrigTowerDetId& theTower);
0039 
0040   edm::ESGetToken<CaloTopology, CaloTopologyRecord> topologyToken_;
0041   edm::ESGetToken<CaloGeometry, CaloGeometryRecord> geometryToken_;
0042 
0043   int pass_;
0044 };
0045 
0046 TestEcalGetWindow::TestEcalGetWindow(const edm::ParameterSet& /*iConfig*/)
0047     : topologyToken_{esConsumes<CaloTopology, CaloTopologyRecord>(edm::ESInputTag{})},
0048       geometryToken_{esConsumes<CaloGeometry, CaloGeometryRecord>(edm::ESInputTag{})} {
0049   //now do what ever initialization is needed
0050   pass_ = 0;
0051   // some setup for root
0052   gROOT->SetStyle("Plain");  // white fill colors etc.
0053   gStyle->SetPaperSize(TStyle::kA4);
0054 }
0055 
0056 TestEcalGetWindow::~TestEcalGetWindow() {}
0057 
0058 void TestEcalGetWindow::build(
0059     const CaloGeometry& /*cg*/, const CaloTopology& ct, DetId::Detector det, int subdetn, const char* name) {
0060   if (det == DetId::Ecal && subdetn == EcalEndcap) {
0061     TCanvas* canv = new TCanvas("c", "", 1000, 1000);
0062     canv->SetLeftMargin(0.15);
0063     canv->SetBottomMargin(0.15);
0064 
0065     gStyle->SetOptStat(0);
0066     TH2F* h = new TH2F("", "", 10, 0.5, 100.5, 10, 0.5, 100.5);
0067 
0068     h->Draw();
0069     //gPad->SetGridx();
0070     //gPad->SetGridy();
0071     gPad->Update();
0072 
0073     h->SetXTitle("x index");
0074     h->SetYTitle("y index");
0075 
0076     h->GetXaxis()->SetTickLength(-0.03);
0077     h->GetYaxis()->SetTickLength(-0.03);
0078 
0079     h->GetXaxis()->SetLabelOffset(0.03);
0080     h->GetYaxis()->SetLabelOffset(0.03);
0081 
0082     h->GetXaxis()->SetLabelSize(0.04);
0083     h->GetYaxis()->SetLabelSize(0.04);
0084 
0085     // axis titles
0086     h->GetXaxis()->SetTitleSize(0.04);
0087     h->GetYaxis()->SetTitleSize(0.04);
0088 
0089     h->GetXaxis()->SetTitleOffset(1.8);
0090     h->GetYaxis()->SetTitleOffset(1.9);
0091 
0092     h->GetXaxis()->CenterTitle(true);
0093     h->GetYaxis()->CenterTitle(true);
0094     const CaloSubdetectorTopology* topology = ct.getSubdetectorTopology(det, subdetn);
0095 
0096     std::vector<DetId> eeDetIds;
0097     eeDetIds.emplace_back(EEDetId(1, 50, 1, EEDetId::XYMODE));
0098     eeDetIds.emplace_back(EEDetId(25, 50, 1, EEDetId::XYMODE));
0099     eeDetIds.emplace_back(EEDetId(50, 1, 1, EEDetId::XYMODE));
0100     eeDetIds.emplace_back(EEDetId(50, 25, 1, EEDetId::XYMODE));
0101     eeDetIds.emplace_back(EEDetId(3, 60, 1, EEDetId::XYMODE));
0102     for (const auto& eeDetId : eeDetIds) {
0103       EEDetId myId(eeDetId);
0104       if (myId.zside() == -1)
0105         continue;
0106       std::vector<DetId> myNeighbours = topology->getWindow(myId, 13, 13);
0107       for (const auto& myNeighbour : myNeighbours) {
0108         EEDetId myEEId(myNeighbour);
0109         TBox* box = new TBox(myEEId.ix() - 0.5, myEEId.iy() - 0.5, myEEId.ix() + 0.5, myEEId.iy() + 0.5);
0110         box->SetFillColor(1);
0111         box->Draw();
0112       }
0113     }
0114     gPad->SaveAs(name);
0115     delete canv;
0116     delete h;
0117   }
0118 
0119   if (det == DetId::Ecal && subdetn == EcalBarrel) {
0120     TCanvas* canv = new TCanvas("c", "", 1000, 1000);
0121     canv->SetLeftMargin(0.15);
0122     canv->SetBottomMargin(0.15);
0123 
0124     gStyle->SetOptStat(0);
0125     TH2F* h = new TH2F("", "", 10, -85.5, 85.5, 10, 0.5, 360.5);
0126 
0127     h->Draw();
0128     //gPad->SetGridx();
0129     //gPad->SetGridy();
0130     gPad->Update();
0131 
0132     h->SetXTitle("eta index");
0133     h->SetYTitle("phi index");
0134 
0135     h->GetXaxis()->SetTickLength(-0.03);
0136     h->GetYaxis()->SetTickLength(-0.03);
0137 
0138     h->GetXaxis()->SetLabelOffset(0.03);
0139     h->GetYaxis()->SetLabelOffset(0.03);
0140 
0141     h->GetXaxis()->SetLabelSize(0.04);
0142     h->GetYaxis()->SetLabelSize(0.04);
0143 
0144     // axis titles
0145     h->GetXaxis()->SetTitleSize(0.04);
0146     h->GetYaxis()->SetTitleSize(0.04);
0147 
0148     h->GetXaxis()->SetTitleOffset(1.8);
0149     h->GetYaxis()->SetTitleOffset(1.9);
0150 
0151     h->GetXaxis()->CenterTitle(true);
0152     h->GetYaxis()->CenterTitle(true);
0153     const CaloSubdetectorTopology* topology = ct.getSubdetectorTopology(det, subdetn);
0154     std::vector<DetId> ebDetIds;
0155     ebDetIds.emplace_back(EBDetId(1, 1));
0156     ebDetIds.emplace_back(EBDetId(30, 30));
0157     ebDetIds.emplace_back(EBDetId(-1, 120));
0158     ebDetIds.emplace_back(EBDetId(85, 1));
0159     for (const auto& ebDetId : ebDetIds) {
0160       EBDetId myId(ebDetId);
0161       std::vector<DetId> myNeighbours = topology->getWindow(myId, 13, 13);
0162       for (const auto& myNeighbour : myNeighbours) {
0163         EBDetId myEBId(myNeighbour);
0164         TBox* box = new TBox(myEBId.ieta() - 0.5, myEBId.iphi() - 0.5, myEBId.ieta() + 0.5, myEBId.iphi() + 0.5);
0165         box->SetFillColor(1);
0166         box->Draw();
0167       }
0168     }
0169     gPad->SaveAs(name);
0170     delete canv;
0171     delete h;
0172   }
0173 }
0174 // ------------ method called to produce the data  ------------
0175 void TestEcalGetWindow::analyze(const edm::Event& /*iEvent*/, const edm::EventSetup& iSetup) {
0176   std::cout << "Here I am " << std::endl;
0177 
0178   const auto& theCaloTopology = iSetup.getData(topologyToken_);
0179   const auto& pG = iSetup.getData(geometryToken_);
0180 
0181   if (pass_ == 1) {
0182     build(pG, theCaloTopology, DetId::Ecal, EcalBarrel, "EBGetWindowTest.eps");
0183   }
0184   if (pass_ == 2) {
0185     build(pG, theCaloTopology, DetId::Ecal, EcalEndcap, "EEGetWindowTest.eps");
0186   }
0187 
0188   pass_++;
0189 }
0190 
0191 //define this as a plug-in
0192 
0193 DEFINE_FWK_MODULE(TestEcalGetWindow);