CMS 3D CMS Logo

ESOccupancyTask.cc
Go to the documentation of this file.
1 #include <memory>
2 #include <fstream>
3 #include <iostream>
4 
16 
17 #include "TStyle.h"
18 #include "TH2F.h"
19 
20 using namespace cms;
21 using namespace edm;
22 using namespace std;
23 
25  rechittoken_ = consumes<ESRecHitCollection>(ps.getParameter<InputTag>("RecHitLabel"));
26  prefixME_ = ps.getUntrackedParameter<string>("prefixME", "EcalPreshower");
27 
28  eCount_ = 0;
29 
30  //Histogram init
31  for (int i = 0; i < 2; ++i)
32  for (int j = 0; j < 2; ++j) {
33  hRecOCC_[i][j] = nullptr;
34  hRecNHit_[i][j] = nullptr;
35  hEng_[i][j] = nullptr;
36  hEvEng_[i][j] = nullptr;
37  hEnDensity_[i][i] = nullptr;
38  hGoodRecNHit_[i][j] = nullptr;
39 
40  hSelEng_[i][j] = nullptr;
41  hSelOCC_[i][j] = nullptr;
42  hSelOCCByLS_[i][j] = nullptr;
43  hSelEnDensity_[i][j] = nullptr;
44  }
45 
46  for (int i = 0; i < 2; ++i)
47  hE1E2_[i] = nullptr;
48 }
49 
51  const edm::EventSetup& c) const {
52  auto lumiCache = std::make_shared<ESOccLSCache>();
53  lumiCache->ievtLS_ = 0;
54 
55  for (int iz = 0; iz < 2; ++iz) {
56  for (int ip = 0; ip < 2; ++ip) {
57  hSelOCCByLS_[iz][ip]->Reset();
58  }
59  }
60  return lumiCache;
61 }
62 
64 
66  iBooker.setCurrentFolder(prefixME_ + "/ESOccupancyTask");
67 
68  //Booking Histograms
69  //Notice: Change ESRenderPlugin under DQM/RenderPlugins/src if you change this histogram name.
70  char histo[200];
71  for (int i = 0; i < 2; ++i)
72  for (int j = 0; j < 2; ++j) {
73  int iz = (i == 0) ? 1 : -1;
74  sprintf(histo, "ES RecHit 2D Occupancy Z %d P %d", iz, j + 1);
75  hRecOCC_[i][j] = iBooker.book2D(histo, histo, 40, 0.5, 40.5, 40, 0.5, 40.5);
76  hRecOCC_[i][j]->setAxisTitle("Si X", 1);
77  hRecOCC_[i][j]->setAxisTitle("Si Y", 2);
78 
79  //Bin 40,40 is used to save eumber of event for scaling.
80  sprintf(histo, "ES Energy Density Z %d P %d", iz, j + 1);
81  hEnDensity_[i][j] = iBooker.book2D(histo, histo, 40, 0.5, 40.5, 40, 0.5, 40.5);
82  hEnDensity_[i][j]->setAxisTitle("Si X", 1);
83  hEnDensity_[i][j]->setAxisTitle("Si Y", 2);
84 
85  sprintf(histo, "ES Num of RecHits Z %d P %d", iz, j + 1);
86  hRecNHit_[i][j] = iBooker.book1DD(histo, histo, 60, 0, 1920);
87  hRecNHit_[i][j]->setAxisTitle("# of RecHits", 1);
88  hRecNHit_[i][j]->setAxisTitle("Num of Events", 2);
89 
90  sprintf(histo, "ES Num of Good RecHits Z %d P %d", iz, j + 1);
91  hGoodRecNHit_[i][j] = iBooker.book1DD(histo, histo, 60, 0, 1920);
92  hGoodRecNHit_[i][j]->setAxisTitle("# of good RecHits", 1);
93  hGoodRecNHit_[i][j]->setAxisTitle("Num of Events", 2);
94 
95  sprintf(histo, "ES RecHit Energy Z %d P %d", iz, j + 1);
96  hEng_[i][j] = iBooker.book1DD(histo, histo, 50, 0, 0.001);
97  hEng_[i][j]->setAxisTitle("RecHit Energy", 1);
98  hEng_[i][j]->setAxisTitle("Num of ReHits", 2);
99 
100  sprintf(histo, "ES Event Energy Z %d P %d", iz, j + 1);
101  hEvEng_[i][j] = iBooker.book1DD(histo, histo, 50, 0, 0.1);
102  hEvEng_[i][j]->setAxisTitle("Event Energy", 1);
103  hEvEng_[i][j]->setAxisTitle("Num of Events", 2);
104 
105  // histograms with selected hits
106  sprintf(histo, "ES RecHit Energy with selected hits Z %d P %d", iz, j + 1);
107  hSelEng_[i][j] = iBooker.book1DD(histo, histo, 50, 0, 0.001);
108  hSelEng_[i][j]->setAxisTitle("RecHit Energy", 1);
109  hSelEng_[i][j]->setAxisTitle("Num of ReHits", 2);
110 
111  sprintf(histo, "ES Occupancy with selected hits Z %d P %d", iz, j + 1);
112  hSelOCC_[i][j] = iBooker.book2D(histo, histo, 40, 0.5, 40.5, 40, 0.5, 40.5);
113  hSelOCC_[i][j]->setAxisTitle("Si X", 1);
114  hSelOCC_[i][j]->setAxisTitle("Si Y", 2);
115 
116  sprintf(histo, "ES Energy Density with selected hits Z %d P %d", iz, j + 1);
117  hSelEnDensity_[i][j] = iBooker.book2D(histo, histo, 40, 0.5, 40.5, 40, 0.5, 40.5);
118  hSelEnDensity_[i][j]->setAxisTitle("Si X", 1);
119  hSelEnDensity_[i][j]->setAxisTitle("Si Y", 2);
120  }
121 
122  hE1E2_[0] = iBooker.book2D("ES+ EP1 vs EP2", "ES+ EP1 vs EP2", 50, 0, 0.1, 50, 0, 0.1);
123  hE1E2_[1] = iBooker.book2D("ES- EP1 vs EP2", "ES- EP1 vs EP2", 50, 0, 0.1, 50, 0, 0.1);
124 
125  // LS-based histos
126  iBooker.setCurrentFolder(prefixME_ + "/ByLumiSection");
127  for (int i = 0; i < 2; ++i) {
128  for (int j = 0; j < 2; ++j) {
129  int iz = (i == 0) ? 1 : -1;
130  sprintf(histo, "ES Occupancy with selected hits Z %d P %d", iz, j + 1);
131  hSelOCCByLS_[i][j] = iBooker.book2D(histo, histo, 40, 0.5, 40.5, 40, 0.5, 40.5);
132  hSelOCCByLS_[i][j]->setAxisTitle("Si X", 1);
133  hSelOCCByLS_[i][j]->setAxisTitle("Si Y", 2);
134  }
135  }
136 }
137 
139  runNum_ = e.id().run();
140  eCount_++;
141 
142  // RecHits
143  int zside, plane, ix, iy;
144  int sum_RecHits[2][2], sum_GoodRecHits[2][2];
145  float sum_Energy[2][2];
146 
147  for (int i = 0; i < 2; ++i)
148  for (int j = 0; j < 2; ++j) {
149  sum_RecHits[i][j] = 0;
150  sum_GoodRecHits[i][j] = 0;
151  sum_Energy[i][j] = 0;
152  }
153 
155  if (e.getByToken(rechittoken_, ESRecHit)) {
156  for (ESRecHitCollection::const_iterator hitItr = ESRecHit->begin(); hitItr != ESRecHit->end(); ++hitItr) {
157  ESDetId id = ESDetId(hitItr->id());
158 
159  zside = id.zside();
160  plane = id.plane();
161  ix = id.six();
162  iy = id.siy();
163 
164  int i = (zside == 1) ? 0 : 1;
165  int j = plane - 1;
166 
167  sum_RecHits[i][j]++;
168  sum_Energy[i][j] += hitItr->energy();
169  hRecOCC_[i][j]->Fill(ix, iy);
170  if (hitItr->energy() != 0) {
171  hEng_[i][j]->Fill(hitItr->energy());
172  hEnDensity_[i][j]->Fill(ix, iy, hitItr->energy());
173 
174  if (hitItr->recoFlag() == 14 || hitItr->recoFlag() == 1 ||
175  (hitItr->recoFlag() <= 10 && hitItr->recoFlag() >= 5))
176  continue;
177  sum_GoodRecHits[i][j]++;
178  hSelEng_[i][j]->Fill(hitItr->energy());
179  hSelEnDensity_[i][j]->Fill(ix, iy, hitItr->energy());
180  hSelOCC_[i][j]->Fill(ix, iy);
181  hSelOCCByLS_[i][j]->Fill(ix, iy);
182  }
183  }
184  } else {
185  LogWarning("ESOccupancyTask") << "RecHitCollection not available";
186  }
187 
188  //Fill histograms after a event
189  for (int i = 0; i < 2; ++i)
190  for (int j = 0; j < 2; ++j) {
191  hRecNHit_[i][j]->Fill(sum_RecHits[i][j]);
192  hGoodRecNHit_[i][j]->Fill(sum_GoodRecHits[i][j]);
193  hEvEng_[i][j]->Fill(sum_Energy[i][j]);
194 
195  //Save eCount_ for Scaling
196  hRecOCC_[i][j]->setBinContent(40, 40, eCount_);
197  hEnDensity_[i][j]->setBinContent(40, 40, eCount_);
198 
199  hSelOCC_[i][j]->setBinContent(40, 40, eCount_);
200  hSelOCCByLS_[i][j]->setBinContent(40, 40, eCount_);
201  hSelEnDensity_[i][j]->setBinContent(40, 40, eCount_);
202  }
203 
204  hE1E2_[0]->Fill(sum_Energy[0][0], sum_Energy[0][1]);
205  hE1E2_[1]->Fill(sum_Energy[1][0], sum_Energy[1][1]);
206 }
207 
208 //define this as a plug-in
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
virtual void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:36
std::vector< EcalRecHit >::const_iterator const_iterator
void globalEndLuminosityBlock(const edm::LuminosityBlock &lumi, const edm::EventSetup &c) override
End Lumi.
int zside(DetId const &)
T getUntrackedParameter(std::string const &, T const &) const
MonitorElement * book1DD(TString const &name, TString const &title, int nchX, double lowX, double highX, FUNC onbooking=NOOP())
Definition: DQMStore.h:155
void analyze(const edm::Event &, const edm::EventSetup &) override
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
const_iterator begin() const
ESOccupancyTask(const edm::ParameterSet &ps)
Namespace of DDCMS conversion namespace.
const_iterator end() const
ALPAKA_FN_ACC ALPAKA_FN_INLINE uint32_t ix(uint32_t id)
void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &) override
MonitorElement * book2D(TString const &name, TString const &title, int nchX, double lowX, double highX, int nchY, double lowY, double highY, FUNC onbooking=NOOP())
Definition: DQMStore.h:221
std::shared_ptr< ESOccLSCache > globalBeginLuminosityBlock(const edm::LuminosityBlock &lumi, const edm::EventSetup &c) const override
Begin Lumi.
HLT enums.
ALPAKA_FN_ACC ALPAKA_FN_INLINE uint32_t iy(uint32_t id)
Log< level::Warning, false > LogWarning
Definition: Run.h:45
virtual void setAxisTitle(const std::string &title, int axis=1)
set x-, y- or z-axis title (axis=1, 2, 3 respectively)