File indexing completed on 2023-03-17 13:02:28
0001 #include <memory>
0002
0003 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0004
0005 #include "FWCore/Framework/interface/EventSetup.h"
0006 #include "FWCore/Framework/interface/MakerMacros.h"
0007 #include "FWCore/Utilities/interface/ESGetToken.h"
0008 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0009
0010 #include "Geometry/Records/interface/CaloGeometryRecord.h"
0011 #include "Geometry/CaloGeometry/interface/CaloGeometry.h"
0012 #include "Geometry/CaloTopology/interface/EcalTrigTowerConstituentsMap.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 DumpEcalTrigTowerMapping : public edm::one::EDAnalyzer<> {
0028 public:
0029 explicit DumpEcalTrigTowerMapping(const edm::ParameterSet&);
0030 ~DumpEcalTrigTowerMapping() 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,
0038 const EcalTrigTowerConstituentsMap& etmap,
0039 DetId::Detector det,
0040 int subdetn,
0041 const char* name);
0042 int towerColor(const EcalTrigTowerDetId& theTower);
0043
0044 edm::ESGetToken<EcalTrigTowerConstituentsMap, IdealGeometryRecord> eTTmapToken_;
0045 edm::ESGetToken<CaloGeometry, CaloGeometryRecord> geometryToken_;
0046
0047 int pass_;
0048 };
0049
0050 DumpEcalTrigTowerMapping::DumpEcalTrigTowerMapping(const edm::ParameterSet& )
0051 : eTTmapToken_{esConsumes<EcalTrigTowerConstituentsMap, IdealGeometryRecord>(edm::ESInputTag{})},
0052 geometryToken_{esConsumes<CaloGeometry, CaloGeometryRecord>(edm::ESInputTag{})} {
0053
0054 pass_ = 0;
0055
0056 gROOT->SetStyle("Plain");
0057 gStyle->SetPaperSize(TStyle::kA4);
0058 }
0059
0060 DumpEcalTrigTowerMapping::~DumpEcalTrigTowerMapping() {
0061
0062
0063 }
0064
0065 int DumpEcalTrigTowerMapping::towerColor(const EcalTrigTowerDetId& theTower) {
0066 int iEtaColorIndex = (theTower.ietaAbs() - 1) % 2;
0067 int iPhiColorIndex = 0;
0068 if (theTower.ietaAbs() < 26)
0069 iPhiColorIndex = (theTower.iphi() - 1) % 2;
0070 else
0071 iPhiColorIndex = ((theTower.iphi() - 1) % 4) / 2;
0072
0073 return iEtaColorIndex * 2 + iPhiColorIndex + 1;
0074 }
0075
0076 void DumpEcalTrigTowerMapping::build(const CaloGeometry& cg,
0077 const EcalTrigTowerConstituentsMap& etmap,
0078 DetId::Detector det,
0079 int subdetn,
0080 const char* name) {
0081 if (det == DetId::Ecal && subdetn == EcalEndcap) {
0082 TCanvas* canv = new TCanvas("c", "", 1000, 1000);
0083 canv->SetLeftMargin(0.15);
0084 canv->SetBottomMargin(0.15);
0085
0086 gStyle->SetOptStat(0);
0087 TH2F* h = new TH2F("", "", 10, 0.5, 100.5, 10, 0.5, 100.5);
0088
0089 h->Draw();
0090
0091
0092 gPad->Update();
0093
0094 h->SetXTitle("x index");
0095 h->SetYTitle("y index");
0096
0097 h->GetXaxis()->SetTickLength(-0.03);
0098 h->GetYaxis()->SetTickLength(-0.03);
0099
0100 h->GetXaxis()->SetLabelOffset(0.03);
0101 h->GetYaxis()->SetLabelOffset(0.03);
0102
0103 h->GetXaxis()->SetLabelSize(0.04);
0104 h->GetYaxis()->SetLabelSize(0.04);
0105
0106
0107 h->GetXaxis()->SetTitleSize(0.04);
0108 h->GetYaxis()->SetTitleSize(0.04);
0109
0110 h->GetXaxis()->SetTitleOffset(1.8);
0111 h->GetYaxis()->SetTitleOffset(1.9);
0112
0113 h->GetXaxis()->CenterTitle(true);
0114 h->GetYaxis()->CenterTitle(true);
0115 const std::vector<DetId>& eeDetIds = cg.getValidDetIds(det, subdetn);
0116
0117 edm::LogVerbatim("CaloGeom") << "*** testing endcap trig tower mapping **";
0118 for (const auto& eeDetId : eeDetIds) {
0119 EEDetId myId(eeDetId);
0120 EcalTrigTowerDetId myTower = etmap.towerOf(eeDetId);
0121
0122 assert(myTower == EcalTrigTowerDetId::detIdFromDenseIndex(myTower.denseIndex()));
0123
0124 if (myId.zside() == 1)
0125 continue;
0126
0127 TBox* box = new TBox(myId.ix() - 0.5, myId.iy() - 0.5, myId.ix() + 0.5, myId.iy() + 0.5);
0128 box->SetFillColor(towerColor(myTower));
0129 box->Draw();
0130 }
0131 gPad->SaveAs(name);
0132 delete canv;
0133 delete h;
0134 }
0135
0136 if (det == DetId::Ecal && subdetn == EcalBarrel) {
0137 TCanvas* canv = new TCanvas("c", "", 1000, 1000);
0138 canv->SetLeftMargin(0.15);
0139 canv->SetBottomMargin(0.15);
0140
0141 gStyle->SetOptStat(0);
0142 TH2F* h = new TH2F("", "", 10, -85.5, 85.5, 10, 0.5, 360.5);
0143
0144 h->Draw();
0145
0146
0147 gPad->Update();
0148
0149 h->SetXTitle("eta index");
0150 h->SetYTitle("phi index");
0151
0152 h->GetXaxis()->SetTickLength(-0.03);
0153 h->GetYaxis()->SetTickLength(-0.03);
0154
0155 h->GetXaxis()->SetLabelOffset(0.03);
0156 h->GetYaxis()->SetLabelOffset(0.03);
0157
0158 h->GetXaxis()->SetLabelSize(0.04);
0159 h->GetYaxis()->SetLabelSize(0.04);
0160
0161
0162 h->GetXaxis()->SetTitleSize(0.04);
0163 h->GetYaxis()->SetTitleSize(0.04);
0164
0165 h->GetXaxis()->SetTitleOffset(1.8);
0166 h->GetYaxis()->SetTitleOffset(1.9);
0167
0168 h->GetXaxis()->CenterTitle(true);
0169 h->GetYaxis()->CenterTitle(true);
0170 const std::vector<DetId>& ebDetIds = cg.getValidDetIds(det, subdetn);
0171
0172 edm::LogVerbatim("CaloGeom") << "*** testing barrel trig tower mapping **";
0173 for (const auto& ebDetId : ebDetIds) {
0174 EBDetId myId(ebDetId);
0175 EcalTrigTowerDetId myTower = etmap.towerOf(ebDetId);
0176
0177 assert(myTower == EcalTrigTowerDetId::detIdFromDenseIndex(myTower.denseIndex()));
0178
0179 TBox* box = new TBox(myId.ieta() - 0.5, myId.iphi() - 0.5, myId.ieta() + 0.5, myId.iphi() + 0.5);
0180 box->SetFillColor(towerColor(myTower));
0181 box->Draw();
0182 }
0183 gPad->SaveAs(name);
0184 delete canv;
0185 delete h;
0186 }
0187 }
0188
0189 void DumpEcalTrigTowerMapping::analyze(const edm::Event& , const edm::EventSetup& iSetup) {
0190 edm::LogVerbatim("CaloGeom") << "Here I am ";
0191
0192 const auto& eTTmap = iSetup.getData(eTTmapToken_);
0193 const auto& pG = iSetup.getData(geometryToken_);
0194
0195 if (pass_ == 1) {
0196 build(pG, eTTmap, DetId::Ecal, EcalBarrel, "EBTTmapping.eps");
0197 }
0198 if (pass_ == 2) {
0199 build(pG, eTTmap, DetId::Ecal, EcalEndcap, "EETTmapping.eps");
0200 }
0201
0202 pass_++;
0203 }
0204
0205
0206 DEFINE_FWK_MODULE(DumpEcalTrigTowerMapping);