File indexing completed on 2024-10-14 22:39:36
0001 #include <memory>
0002 #include <fstream>
0003 #include <iostream>
0004
0005 #include "FWCore/ServiceRegistry/interface/Service.h"
0006 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0007 #include "FWCore/Framework/interface/MakerMacros.h"
0008 #include "FWCore/Framework/interface/Frameworkfwd.h"
0009 #include "FWCore/ParameterSet/interface/FileInPath.h"
0010 #include "DataFormats/DetId/interface/DetId.h"
0011 #include "DataFormats/EcalDetId/interface/ESDetId.h"
0012 #include "DataFormats/EcalDigi/interface/ESDataFrame.h"
0013 #include "DataFormats/EcalDigi/interface/EcalDigiCollections.h"
0014 #include "DQMServices/Core/interface/DQMStore.h"
0015 #include "DQM/EcalPreshowerMonitorModule/interface/ESOccupancyTask.h"
0016
0017 #include "TStyle.h"
0018 #include "TH2F.h"
0019
0020 using namespace cms;
0021 using namespace edm;
0022 using namespace std;
0023
0024 ESOccupancyTask::ESOccupancyTask(const edm::ParameterSet& ps) {
0025 rechittoken_ = consumes<ESRecHitCollection>(ps.getParameter<InputTag>("RecHitLabel"));
0026 prefixME_ = ps.getUntrackedParameter<string>("prefixME", "EcalPreshower");
0027
0028 eCount_ = 0;
0029
0030
0031 for (int i = 0; i < 2; ++i)
0032 for (int j = 0; j < 2; ++j) {
0033 hRecOCC_[i][j] = nullptr;
0034 hRecNHit_[i][j] = nullptr;
0035 hEng_[i][j] = nullptr;
0036 hEvEng_[i][j] = nullptr;
0037 hEnDensity_[i][i] = nullptr;
0038 hGoodRecNHit_[i][j] = nullptr;
0039
0040 hSelEng_[i][j] = nullptr;
0041 hSelOCC_[i][j] = nullptr;
0042 hSelOCCByLS_[i][j] = nullptr;
0043 hSelEnDensity_[i][j] = nullptr;
0044 }
0045
0046 for (int i = 0; i < 2; ++i)
0047 hE1E2_[i] = nullptr;
0048 }
0049
0050 std::shared_ptr<ESOccLSCache> ESOccupancyTask::globalBeginLuminosityBlock(const edm::LuminosityBlock& lumi,
0051 const edm::EventSetup& c) const {
0052 auto lumiCache = std::make_shared<ESOccLSCache>();
0053 lumiCache->ievtLS_ = 0;
0054
0055 for (int iz = 0; iz < 2; ++iz) {
0056 for (int ip = 0; ip < 2; ++ip) {
0057 hSelOCCByLS_[iz][ip]->Reset();
0058 }
0059 }
0060 return lumiCache;
0061 }
0062
0063 void ESOccupancyTask::globalEndLuminosityBlock(const edm::LuminosityBlock& lumi, const edm::EventSetup& c) {}
0064
0065 void ESOccupancyTask::bookHistograms(DQMStore::IBooker& iBooker, Run const&, EventSetup const&) {
0066 iBooker.setCurrentFolder(prefixME_ + "/ESOccupancyTask");
0067
0068
0069
0070 char histo[200];
0071 for (int i = 0; i < 2; ++i)
0072 for (int j = 0; j < 2; ++j) {
0073 int iz = (i == 0) ? 1 : -1;
0074 sprintf(histo, "ES RecHit 2D Occupancy Z %d P %d", iz, j + 1);
0075 hRecOCC_[i][j] = iBooker.book2D(histo, histo, 40, 0.5, 40.5, 40, 0.5, 40.5);
0076 hRecOCC_[i][j]->setAxisTitle("Si X", 1);
0077 hRecOCC_[i][j]->setAxisTitle("Si Y", 2);
0078
0079
0080 sprintf(histo, "ES Energy Density Z %d P %d", iz, j + 1);
0081 hEnDensity_[i][j] = iBooker.book2D(histo, histo, 40, 0.5, 40.5, 40, 0.5, 40.5);
0082 hEnDensity_[i][j]->setAxisTitle("Si X", 1);
0083 hEnDensity_[i][j]->setAxisTitle("Si Y", 2);
0084
0085 sprintf(histo, "ES Num of RecHits Z %d P %d", iz, j + 1);
0086 hRecNHit_[i][j] = iBooker.book1DD(histo, histo, 60, 0, 1920);
0087 hRecNHit_[i][j]->setAxisTitle("# of RecHits", 1);
0088 hRecNHit_[i][j]->setAxisTitle("Num of Events", 2);
0089
0090 sprintf(histo, "ES Num of Good RecHits Z %d P %d", iz, j + 1);
0091 hGoodRecNHit_[i][j] = iBooker.book1DD(histo, histo, 60, 0, 1920);
0092 hGoodRecNHit_[i][j]->setAxisTitle("# of good RecHits", 1);
0093 hGoodRecNHit_[i][j]->setAxisTitle("Num of Events", 2);
0094
0095 sprintf(histo, "ES RecHit Energy Z %d P %d", iz, j + 1);
0096 hEng_[i][j] = iBooker.book1DD(histo, histo, 50, 0, 0.001);
0097 hEng_[i][j]->setAxisTitle("RecHit Energy", 1);
0098 hEng_[i][j]->setAxisTitle("Num of ReHits", 2);
0099
0100 sprintf(histo, "ES Event Energy Z %d P %d", iz, j + 1);
0101 hEvEng_[i][j] = iBooker.book1DD(histo, histo, 50, 0, 0.1);
0102 hEvEng_[i][j]->setAxisTitle("Event Energy", 1);
0103 hEvEng_[i][j]->setAxisTitle("Num of Events", 2);
0104
0105
0106 sprintf(histo, "ES RecHit Energy with selected hits Z %d P %d", iz, j + 1);
0107 hSelEng_[i][j] = iBooker.book1DD(histo, histo, 50, 0, 0.001);
0108 hSelEng_[i][j]->setAxisTitle("RecHit Energy", 1);
0109 hSelEng_[i][j]->setAxisTitle("Num of ReHits", 2);
0110
0111 sprintf(histo, "ES Occupancy with selected hits Z %d P %d", iz, j + 1);
0112 hSelOCC_[i][j] = iBooker.book2D(histo, histo, 40, 0.5, 40.5, 40, 0.5, 40.5);
0113 hSelOCC_[i][j]->setAxisTitle("Si X", 1);
0114 hSelOCC_[i][j]->setAxisTitle("Si Y", 2);
0115
0116 sprintf(histo, "ES Energy Density with selected hits Z %d P %d", iz, j + 1);
0117 hSelEnDensity_[i][j] = iBooker.book2D(histo, histo, 40, 0.5, 40.5, 40, 0.5, 40.5);
0118 hSelEnDensity_[i][j]->setAxisTitle("Si X", 1);
0119 hSelEnDensity_[i][j]->setAxisTitle("Si Y", 2);
0120 }
0121
0122 hE1E2_[0] = iBooker.book2D("ES+ EP1 vs EP2", "ES+ EP1 vs EP2", 50, 0, 0.1, 50, 0, 0.1);
0123 hE1E2_[1] = iBooker.book2D("ES- EP1 vs EP2", "ES- EP1 vs EP2", 50, 0, 0.1, 50, 0, 0.1);
0124
0125
0126 iBooker.setCurrentFolder(prefixME_ + "/ByLumiSection");
0127 for (int i = 0; i < 2; ++i) {
0128 for (int j = 0; j < 2; ++j) {
0129 int iz = (i == 0) ? 1 : -1;
0130 sprintf(histo, "ES Occupancy with selected hits Z %d P %d", iz, j + 1);
0131 hSelOCCByLS_[i][j] = iBooker.book2D(histo, histo, 40, 0.5, 40.5, 40, 0.5, 40.5);
0132 hSelOCCByLS_[i][j]->setAxisTitle("Si X", 1);
0133 hSelOCCByLS_[i][j]->setAxisTitle("Si Y", 2);
0134 }
0135 }
0136 }
0137
0138 void ESOccupancyTask::analyze(const edm::Event& e, const edm::EventSetup& iSetup) {
0139 runNum_ = e.id().run();
0140 eCount_++;
0141
0142
0143 int zside, plane, ix, iy;
0144 int sum_RecHits[2][2], sum_GoodRecHits[2][2];
0145 float sum_Energy[2][2];
0146
0147 for (int i = 0; i < 2; ++i)
0148 for (int j = 0; j < 2; ++j) {
0149 sum_RecHits[i][j] = 0;
0150 sum_GoodRecHits[i][j] = 0;
0151 sum_Energy[i][j] = 0;
0152 }
0153
0154 Handle<ESRecHitCollection> ESRecHit;
0155 if (e.getByToken(rechittoken_, ESRecHit)) {
0156 for (ESRecHitCollection::const_iterator hitItr = ESRecHit->begin(); hitItr != ESRecHit->end(); ++hitItr) {
0157 ESDetId id = ESDetId(hitItr->id());
0158
0159 zside = id.zside();
0160 plane = id.plane();
0161 ix = id.six();
0162 iy = id.siy();
0163
0164 int i = (zside == 1) ? 0 : 1;
0165 int j = plane - 1;
0166
0167 sum_RecHits[i][j]++;
0168 sum_Energy[i][j] += hitItr->energy();
0169 hRecOCC_[i][j]->Fill(ix, iy);
0170 if (hitItr->energy() != 0) {
0171 hEng_[i][j]->Fill(hitItr->energy());
0172 hEnDensity_[i][j]->Fill(ix, iy, hitItr->energy());
0173
0174 if (hitItr->recoFlag() == 14 || hitItr->recoFlag() == 1 ||
0175 (hitItr->recoFlag() <= 10 && hitItr->recoFlag() >= 5))
0176 continue;
0177 sum_GoodRecHits[i][j]++;
0178 hSelEng_[i][j]->Fill(hitItr->energy());
0179 hSelEnDensity_[i][j]->Fill(ix, iy, hitItr->energy());
0180 hSelOCC_[i][j]->Fill(ix, iy);
0181 hSelOCCByLS_[i][j]->Fill(ix, iy);
0182 }
0183 }
0184 } else {
0185 LogWarning("ESOccupancyTask") << "RecHitCollection not available";
0186 }
0187
0188
0189 for (int i = 0; i < 2; ++i)
0190 for (int j = 0; j < 2; ++j) {
0191 hRecNHit_[i][j]->Fill(sum_RecHits[i][j]);
0192 hGoodRecNHit_[i][j]->Fill(sum_GoodRecHits[i][j]);
0193 hEvEng_[i][j]->Fill(sum_Energy[i][j]);
0194
0195
0196 hRecOCC_[i][j]->setBinContent(40, 40, eCount_);
0197 hEnDensity_[i][j]->setBinContent(40, 40, eCount_);
0198
0199 hSelOCC_[i][j]->setBinContent(40, 40, eCount_);
0200 hSelOCCByLS_[i][j]->setBinContent(40, 40, eCount_);
0201 hSelEnDensity_[i][j]->setBinContent(40, 40, eCount_);
0202 }
0203
0204 hE1E2_[0]->Fill(sum_Energy[0][0], sum_Energy[0][1]);
0205 hE1E2_[1]->Fill(sum_Energy[1][0], sum_Energy[1][1]);
0206 }
0207
0208
0209 DEFINE_FWK_MODULE(ESOccupancyTask);