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  hSelEnDensity_[i][j] = nullptr;
43  }
44 
45  for (int i = 0; i < 2; ++i)
46  hE1E2_[i] = nullptr;
47 }
48 
50  iBooker.setCurrentFolder(prefixME_ + "/ESOccupancyTask");
51 
52  //Booking Histograms
53  //Notice: Change ESRenderPlugin under DQM/RenderPlugins/src if you change this histogram name.
54  char histo[200];
55  for (int i = 0; i < 2; ++i)
56  for (int j = 0; j < 2; ++j) {
57  int iz = (i == 0) ? 1 : -1;
58  sprintf(histo, "ES RecHit 2D Occupancy Z %d P %d", iz, j + 1);
59  hRecOCC_[i][j] = iBooker.book2D(histo, histo, 40, 0.5, 40.5, 40, 0.5, 40.5);
60  hRecOCC_[i][j]->setAxisTitle("Si X", 1);
61  hRecOCC_[i][j]->setAxisTitle("Si Y", 2);
62 
63  //Bin 40,40 is used to save eumber of event for scaling.
64  sprintf(histo, "ES Energy Density Z %d P %d", iz, j + 1);
65  hEnDensity_[i][j] = iBooker.book2D(histo, histo, 40, 0.5, 40.5, 40, 0.5, 40.5);
66  hEnDensity_[i][j]->setAxisTitle("Si X", 1);
67  hEnDensity_[i][j]->setAxisTitle("Si Y", 2);
68 
69  sprintf(histo, "ES Num of RecHits Z %d P %d", iz, j + 1);
70  hRecNHit_[i][j] = iBooker.book1DD(histo, histo, 60, 0, 1920);
71  hRecNHit_[i][j]->setAxisTitle("# of RecHits", 1);
72  hRecNHit_[i][j]->setAxisTitle("Num of Events", 2);
73 
74  sprintf(histo, "ES Num of Good RecHits Z %d P %d", iz, j + 1);
75  hGoodRecNHit_[i][j] = iBooker.book1DD(histo, histo, 60, 0, 1920);
76  hGoodRecNHit_[i][j]->setAxisTitle("# of good RecHits", 1);
77  hGoodRecNHit_[i][j]->setAxisTitle("Num of Events", 2);
78 
79  sprintf(histo, "ES RecHit Energy Z %d P %d", iz, j + 1);
80  hEng_[i][j] = iBooker.book1DD(histo, histo, 50, 0, 0.001);
81  hEng_[i][j]->setAxisTitle("RecHit Energy", 1);
82  hEng_[i][j]->setAxisTitle("Num of ReHits", 2);
83 
84  sprintf(histo, "ES Event Energy Z %d P %d", iz, j + 1);
85  hEvEng_[i][j] = iBooker.book1DD(histo, histo, 50, 0, 0.1);
86  hEvEng_[i][j]->setAxisTitle("Event Energy", 1);
87  hEvEng_[i][j]->setAxisTitle("Num of Events", 2);
88 
89  // histograms with selected hits
90  sprintf(histo, "ES RecHit Energy with selected hits Z %d P %d", iz, j + 1);
91  hSelEng_[i][j] = iBooker.book1DD(histo, histo, 50, 0, 0.001);
92  hSelEng_[i][j]->setAxisTitle("RecHit Energy", 1);
93  hSelEng_[i][j]->setAxisTitle("Num of ReHits", 2);
94 
95  sprintf(histo, "ES Occupancy with selected hits Z %d P %d", iz, j + 1);
96  hSelOCC_[i][j] = iBooker.book2D(histo, histo, 40, 0.5, 40.5, 40, 0.5, 40.5);
97  hSelOCC_[i][j]->setAxisTitle("Si X", 1);
98  hSelOCC_[i][j]->setAxisTitle("Si Y", 2);
99 
100  sprintf(histo, "ES Energy Density with selected hits Z %d P %d", iz, j + 1);
101  hSelEnDensity_[i][j] = iBooker.book2D(histo, histo, 40, 0.5, 40.5, 40, 0.5, 40.5);
102  hSelEnDensity_[i][j]->setAxisTitle("Si X", 1);
103  hSelEnDensity_[i][j]->setAxisTitle("Si Y", 2);
104  }
105 
106  hE1E2_[0] = iBooker.book2D("ES+ EP1 vs EP2", "ES+ EP1 vs EP2", 50, 0, 0.1, 50, 0, 0.1);
107  hE1E2_[1] = iBooker.book2D("ES- EP1 vs EP2", "ES- EP1 vs EP2", 50, 0, 0.1, 50, 0, 0.1);
108 }
109 
111  runNum_ = e.id().run();
112  eCount_++;
113 
114  // RecHits
115  int zside, plane, ix, iy;
116  int sum_RecHits[2][2], sum_GoodRecHits[2][2];
117  float sum_Energy[2][2];
118 
119  for (int i = 0; i < 2; ++i)
120  for (int j = 0; j < 2; ++j) {
121  sum_RecHits[i][j] = 0;
122  sum_GoodRecHits[i][j] = 0;
123  sum_Energy[i][j] = 0;
124  }
125 
127  if (e.getByToken(rechittoken_, ESRecHit)) {
128  for (ESRecHitCollection::const_iterator hitItr = ESRecHit->begin(); hitItr != ESRecHit->end(); ++hitItr) {
129  ESDetId id = ESDetId(hitItr->id());
130 
131  zside = id.zside();
132  plane = id.plane();
133  ix = id.six();
134  iy = id.siy();
135 
136  int i = (zside == 1) ? 0 : 1;
137  int j = plane - 1;
138 
139  sum_RecHits[i][j]++;
140  sum_Energy[i][j] += hitItr->energy();
141  hRecOCC_[i][j]->Fill(ix, iy);
142  if (hitItr->energy() != 0) {
143  hEng_[i][j]->Fill(hitItr->energy());
144  hEnDensity_[i][j]->Fill(ix, iy, hitItr->energy());
145 
146  if (hitItr->recoFlag() == 14 || hitItr->recoFlag() == 1 ||
147  (hitItr->recoFlag() <= 10 && hitItr->recoFlag() >= 5))
148  continue;
149  sum_GoodRecHits[i][j]++;
150  hSelEng_[i][j]->Fill(hitItr->energy());
151  hSelEnDensity_[i][j]->Fill(ix, iy, hitItr->energy());
152  hSelOCC_[i][j]->Fill(ix, iy);
153  }
154  }
155  } else {
156  LogWarning("ESOccupancyTask") << "RecHitCollection not available";
157  }
158 
159  //Fill histograms after a event
160  for (int i = 0; i < 2; ++i)
161  for (int j = 0; j < 2; ++j) {
162  hRecNHit_[i][j]->Fill(sum_RecHits[i][j]);
163  hGoodRecNHit_[i][j]->Fill(sum_GoodRecHits[i][j]);
164  hEvEng_[i][j]->Fill(sum_Energy[i][j]);
165 
166  //Save eCount_ for Scaling
167  hRecOCC_[i][j]->setBinContent(40, 40, eCount_);
168  hEnDensity_[i][j]->setBinContent(40, 40, eCount_);
169 
170  hSelOCC_[i][j]->setBinContent(40, 40, eCount_);
171  hSelEnDensity_[i][j]->setBinContent(40, 40, eCount_);
172  }
173 
174  hE1E2_[0]->Fill(sum_Energy[0][0], sum_Energy[0][1]);
175  hE1E2_[1]->Fill(sum_Energy[1][0], sum_Energy[1][1]);
176 }
177 
178 //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
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
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:212
HLT enums.
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)