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