Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:07:36

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 
0009 #include "Geometry/Records/interface/CaloGeometryRecord.h"
0010 #include "Geometry/CaloGeometry/interface/CaloGeometry.h"
0011 #include "Geometry/CaloTopology/interface/EcalTrigTowerConstituentsMap.h"
0012 
0013 #include "DataFormats/EcalDetId/interface/EBDetId.h"
0014 #include "DataFormats/EcalDetId/interface/EEDetId.h"
0015 #include "DataFormats/EcalDetId/interface/EcalTrigTowerDetId.h"
0016 
0017 #include <TCanvas.h>
0018 #include <TVirtualPad.h>
0019 #include <TStyle.h>
0020 #include <TROOT.h>
0021 #include <TH2F.h>
0022 #include <TBox.h>
0023 
0024 #include <iostream>
0025 
0026 class DumpEcalTrigTowerMapping : public edm::one::EDAnalyzer<> {
0027 public:
0028   explicit DumpEcalTrigTowerMapping(const edm::ParameterSet&);
0029   ~DumpEcalTrigTowerMapping() override;
0030 
0031   void beginJob() override {}
0032   void analyze(edm::Event const& iEvent, edm::EventSetup const&) override;
0033   void endJob() override {}
0034 
0035 private:
0036   void build(const CaloGeometry& cg,
0037              const EcalTrigTowerConstituentsMap& etmap,
0038              DetId::Detector det,
0039              int subdetn,
0040              const char* name);
0041   int towerColor(const EcalTrigTowerDetId& theTower);
0042 
0043   edm::ESGetToken<EcalTrigTowerConstituentsMap, IdealGeometryRecord> eTTmapToken_;
0044   edm::ESGetToken<CaloGeometry, CaloGeometryRecord> geometryToken_;
0045 
0046   int pass_;
0047 };
0048 
0049 DumpEcalTrigTowerMapping::DumpEcalTrigTowerMapping(const edm::ParameterSet& /*iConfig*/)
0050     : eTTmapToken_{esConsumes<EcalTrigTowerConstituentsMap, IdealGeometryRecord>(edm::ESInputTag{})},
0051       geometryToken_{esConsumes<CaloGeometry, CaloGeometryRecord>(edm::ESInputTag{})} {
0052   //now do what ever initialization is needed
0053   pass_ = 0;
0054   // some setup for root
0055   gROOT->SetStyle("Plain");  // white fill colors etc.
0056   gStyle->SetPaperSize(TStyle::kA4);
0057 }
0058 
0059 DumpEcalTrigTowerMapping::~DumpEcalTrigTowerMapping() {
0060   // do anything here that needs to be done at desctruction time
0061   // (e.g. close files, deallocate resources etc.)
0062 }
0063 
0064 int DumpEcalTrigTowerMapping::towerColor(const EcalTrigTowerDetId& theTower) {
0065   int iEtaColorIndex = (theTower.ietaAbs() - 1) % 2;
0066   int iPhiColorIndex = 0;
0067   if (theTower.ietaAbs() < 26)
0068     iPhiColorIndex = (theTower.iphi() - 1) % 2;
0069   else
0070     iPhiColorIndex = ((theTower.iphi() - 1) % 4) / 2;
0071 
0072   return iEtaColorIndex * 2 + iPhiColorIndex + 1;
0073 }
0074 
0075 void DumpEcalTrigTowerMapping::build(const CaloGeometry& cg,
0076                                      const EcalTrigTowerConstituentsMap& etmap,
0077                                      DetId::Detector det,
0078                                      int subdetn,
0079                                      const char* name) {
0080   if (det == DetId::Ecal && subdetn == EcalEndcap) {
0081     TCanvas* canv = new TCanvas("c", "", 1000, 1000);
0082     canv->SetLeftMargin(0.15);
0083     canv->SetBottomMargin(0.15);
0084 
0085     gStyle->SetOptStat(0);
0086     TH2F* h = new TH2F("", "", 10, 0.5, 100.5, 10, 0.5, 100.5);
0087 
0088     h->Draw();
0089     //gPad->SetGridx();
0090     //gPad->SetGridy();
0091     gPad->Update();
0092 
0093     h->SetXTitle("x index");
0094     h->SetYTitle("y index");
0095 
0096     h->GetXaxis()->SetTickLength(-0.03);
0097     h->GetYaxis()->SetTickLength(-0.03);
0098 
0099     h->GetXaxis()->SetLabelOffset(0.03);
0100     h->GetYaxis()->SetLabelOffset(0.03);
0101 
0102     h->GetXaxis()->SetLabelSize(0.04);
0103     h->GetYaxis()->SetLabelSize(0.04);
0104 
0105     // axis titles
0106     h->GetXaxis()->SetTitleSize(0.04);
0107     h->GetYaxis()->SetTitleSize(0.04);
0108 
0109     h->GetXaxis()->SetTitleOffset(1.8);
0110     h->GetYaxis()->SetTitleOffset(1.9);
0111 
0112     h->GetXaxis()->CenterTitle(true);
0113     h->GetYaxis()->CenterTitle(true);
0114     const std::vector<DetId>& eeDetIds = cg.getValidDetIds(det, subdetn);
0115 
0116     std::cout << "*** testing endcap trig tower mapping **" << std::endl;
0117     for (const auto& eeDetId : eeDetIds) {
0118       EEDetId myId(eeDetId);
0119       EcalTrigTowerDetId myTower = etmap.towerOf(eeDetId);
0120 
0121       //      std::cout<<"eedetid="<<EEDetId(eeDetIds[i])<<", myTower="<<myTower<<std::endl;
0122 
0123       assert(myTower == EcalTrigTowerDetId::detIdFromDenseIndex(myTower.denseIndex()));
0124 
0125       if (myId.zside() == 1)
0126         continue;
0127 
0128       TBox* box = new TBox(myId.ix() - 0.5, myId.iy() - 0.5, myId.ix() + 0.5, myId.iy() + 0.5);
0129       box->SetFillColor(towerColor(myTower));
0130       box->Draw();
0131     }
0132     gPad->SaveAs(name);
0133     delete canv;
0134     delete h;
0135   }
0136 
0137   if (det == DetId::Ecal && subdetn == EcalBarrel) {
0138     TCanvas* canv = new TCanvas("c", "", 1000, 1000);
0139     canv->SetLeftMargin(0.15);
0140     canv->SetBottomMargin(0.15);
0141 
0142     gStyle->SetOptStat(0);
0143     TH2F* h = new TH2F("", "", 10, -85.5, 85.5, 10, 0.5, 360.5);
0144 
0145     h->Draw();
0146     //gPad->SetGridx();
0147     //gPad->SetGridy();
0148     gPad->Update();
0149 
0150     h->SetXTitle("eta index");
0151     h->SetYTitle("phi index");
0152 
0153     h->GetXaxis()->SetTickLength(-0.03);
0154     h->GetYaxis()->SetTickLength(-0.03);
0155 
0156     h->GetXaxis()->SetLabelOffset(0.03);
0157     h->GetYaxis()->SetLabelOffset(0.03);
0158 
0159     h->GetXaxis()->SetLabelSize(0.04);
0160     h->GetYaxis()->SetLabelSize(0.04);
0161 
0162     // axis titles
0163     h->GetXaxis()->SetTitleSize(0.04);
0164     h->GetYaxis()->SetTitleSize(0.04);
0165 
0166     h->GetXaxis()->SetTitleOffset(1.8);
0167     h->GetYaxis()->SetTitleOffset(1.9);
0168 
0169     h->GetXaxis()->CenterTitle(true);
0170     h->GetYaxis()->CenterTitle(true);
0171     const std::vector<DetId>& ebDetIds = cg.getValidDetIds(det, subdetn);
0172 
0173     std::cout << "*** testing barrel trig tower mapping **" << std::endl;
0174     for (const auto& ebDetId : ebDetIds) {
0175       EBDetId myId(ebDetId);
0176       EcalTrigTowerDetId myTower = etmap.towerOf(ebDetId);
0177 
0178       assert(myTower == EcalTrigTowerDetId::detIdFromDenseIndex(myTower.denseIndex()));
0179 
0180       TBox* box = new TBox(myId.ieta() - 0.5, myId.iphi() - 0.5, myId.ieta() + 0.5, myId.iphi() + 0.5);
0181       box->SetFillColor(towerColor(myTower));
0182       box->Draw();
0183     }
0184     gPad->SaveAs(name);
0185     delete canv;
0186     delete h;
0187   }
0188 }
0189 
0190 void DumpEcalTrigTowerMapping::analyze(const edm::Event& /*iEvent*/, const edm::EventSetup& iSetup) {
0191   std::cout << "Here I am " << std::endl;
0192 
0193   const auto& eTTmap = iSetup.getData(eTTmapToken_);
0194   const auto& pG = iSetup.getData(geometryToken_);
0195 
0196   if (pass_ == 1) {
0197     build(pG, eTTmap, DetId::Ecal, EcalBarrel, "EBTTmapping.eps");
0198   }
0199   if (pass_ == 2) {
0200     build(pG, eTTmap, DetId::Ecal, EcalEndcap, "EETTmapping.eps");
0201   }
0202 
0203   pass_++;
0204 }
0205 
0206 //define this as a plug-in
0207 DEFINE_FWK_MODULE(DumpEcalTrigTowerMapping);