CMS 3D CMS Logo

ESOccupancyTask.cc
Go to the documentation of this file.
1 #include <memory>
2 #include <fstream>
3 #include <iostream>
4 
17 
18 #include "TStyle.h"
19 #include "TH2F.h"
20 
21 using namespace cms;
22 using namespace edm;
23 using namespace std;
24 
26 
27  rechittoken_ = consumes<ESRecHitCollection>(ps.getParameter<InputTag>("RecHitLabel"));
28  prefixME_ = ps.getUntrackedParameter<string>("prefixME", "EcalPreshower");
29 
30  eCount_ = 0;
31 
32  //Histogram init
33  for (int i = 0; i < 2; ++i)
34  for (int j = 0; j < 2; ++j) {
35  hRecOCC_[i][j] = nullptr;
36  hRecNHit_[i][j] = nullptr;
37  hEng_[i][j] = nullptr;
38  hEvEng_[i][j] = nullptr;
39  hEnDensity_[i][i] = nullptr;
40  hGoodRecNHit_[i][j] = nullptr;
41 
42  hSelEng_[i][j] = nullptr;
43  hSelOCC_[i][j] = nullptr;
44  hSelEnDensity_[i][j] = nullptr;
45  }
46 
47  for (int i = 0; i<2; ++i)
48  hE1E2_[i]=nullptr;
49 }
50 
51 void
53 {
54  iBooker.setCurrentFolder(prefixME_ + "/ESOccupancyTask");
55 
56  //Booking Histograms
57  //Notice: Change ESRenderPlugin under DQM/RenderPlugins/src if you change this histogram name.
58  char histo[200];
59  for (int i=0 ; i<2; ++i)
60  for (int j=0 ; j<2; ++j) {
61  int iz = (i==0)? 1:-1;
62  sprintf(histo, "ES RecHit 2D Occupancy Z %d P %d", iz, j+1);
63  hRecOCC_[i][j] = iBooker.book2D(histo, histo, 40, 0.5, 40.5, 40, 0.5, 40.5);
64  hRecOCC_[i][j]->setAxisTitle("Si X", 1);
65  hRecOCC_[i][j]->setAxisTitle("Si Y", 2);
66 
67  //Bin 40,40 is used to save eumber of event for scaling.
68  sprintf(histo, "ES Energy Density Z %d P %d", iz, j+1);
69  hEnDensity_[i][j] = iBooker.book2D(histo, histo, 40, 0.5, 40.5, 40, 0.5, 40.5);
70  hEnDensity_[i][j]->setAxisTitle("Si X", 1);
71  hEnDensity_[i][j]->setAxisTitle("Si Y", 2);
72 
73  sprintf(histo, "ES Num of RecHits Z %d P %d", iz, j+1);
74  hRecNHit_[i][j] = iBooker.book1DD(histo, histo, 60, 0, 1920);
75  hRecNHit_[i][j]->setAxisTitle("# of RecHits", 1);
76  hRecNHit_[i][j]->setAxisTitle("Num of Events", 2);
77 
78  sprintf(histo, "ES Num of Good RecHits Z %d P %d", iz, j+1);
79  hGoodRecNHit_[i][j] = iBooker.book1DD(histo, histo, 60, 0, 1920);
80  hGoodRecNHit_[i][j]->setAxisTitle("# of good RecHits", 1);
81  hGoodRecNHit_[i][j]->setAxisTitle("Num of Events", 2);
82 
83  sprintf(histo, "ES RecHit Energy Z %d P %d", iz, j+1);
84  hEng_[i][j] = iBooker.book1DD(histo, histo, 50, 0, 0.001);
85  hEng_[i][j]->setAxisTitle("RecHit Energy", 1);
86  hEng_[i][j]->setAxisTitle("Num of ReHits", 2);
87 
88  sprintf(histo, "ES Event Energy Z %d P %d", iz, j+1);
89  hEvEng_[i][j] = iBooker.book1DD(histo, histo, 50, 0, 0.1);
90  hEvEng_[i][j]->setAxisTitle("Event Energy", 1);
91  hEvEng_[i][j]->setAxisTitle("Num of Events", 2);
92 
93  // histograms with selected hits
94  sprintf(histo, "ES RecHit Energy with selected hits Z %d P %d", iz, j+1);
95  hSelEng_[i][j] = iBooker.book1DD(histo, histo, 50, 0, 0.001);
96  hSelEng_[i][j]->setAxisTitle("RecHit Energy", 1);
97  hSelEng_[i][j]->setAxisTitle("Num of ReHits", 2);
98 
99  sprintf(histo, "ES Occupancy with selected hits Z %d P %d", iz, j+1);
100  hSelOCC_[i][j] = iBooker.book2D(histo, histo, 40, 0.5, 40.5, 40, 0.5, 40.5);
101  hSelOCC_[i][j]->setAxisTitle("Si X", 1);
102  hSelOCC_[i][j]->setAxisTitle("Si Y", 2);
103 
104  sprintf(histo, "ES Energy Density with selected hits Z %d P %d", iz, j+1);
105  hSelEnDensity_[i][j] = iBooker.book2D(histo, histo, 40, 0.5, 40.5, 40, 0.5, 40.5);
106  hSelEnDensity_[i][j]->setAxisTitle("Si X", 1);
107  hSelEnDensity_[i][j]->setAxisTitle("Si Y", 2);
108  }
109 
110  hE1E2_[0] = iBooker.book2D("ES+ EP1 vs EP2", "ES+ EP1 vs EP2", 50, 0, 0.1, 50, 0, 0.1);
111  hE1E2_[1] = iBooker.book2D("ES- EP1 vs EP2", "ES- EP1 vs EP2", 50, 0, 0.1, 50, 0, 0.1);
112 }
113 
115 
116  runNum_ = e.id().run();
117  eCount_++;
118 
119  // RecHits
120  int zside, plane, ix, iy;
121  int sum_RecHits[2][2], sum_GoodRecHits[2][2];
122  float sum_Energy[2][2];
123 
124  for (int i = 0; i < 2; ++i)
125  for (int j = 0; j < 2; ++j) {
126  sum_RecHits[i][j] = 0;
127  sum_GoodRecHits[i][j] = 0;
128  sum_Energy[i][j] = 0;
129  }
130 
132  if ( e.getByToken(rechittoken_, ESRecHit) ) {
133 
134  for (ESRecHitCollection::const_iterator hitItr = ESRecHit->begin(); hitItr != ESRecHit->end(); ++hitItr) {
135 
136  ESDetId id = ESDetId(hitItr->id());
137 
138  zside = id.zside();
139  plane = id.plane();
140  ix = id.six();
141  iy = id.siy();
142 
143  int i = (zside==1)? 0:1;
144  int j = plane-1;
145 
146  sum_RecHits[i][j]++;
147  sum_Energy[i][j] += hitItr->energy();
148  hRecOCC_[i][j]->Fill(ix, iy);
149  if (hitItr->energy() != 0) {
150  hEng_[i][j]->Fill(hitItr->energy());
151  hEnDensity_[i][j]->Fill(ix, iy, hitItr->energy());
152 
153  if (hitItr->recoFlag()==14 || hitItr->recoFlag()==1 || (hitItr->recoFlag()<=10 && hitItr->recoFlag()>=5)) continue;
154  sum_GoodRecHits[i][j]++;
155  hSelEng_[i][j]->Fill(hitItr->energy());
156  hSelEnDensity_[i][j]->Fill(ix, iy, hitItr->energy());
157  hSelOCC_[i][j]->Fill(ix, iy);
158  }
159 
160  }
161  } else {
162  LogWarning("ESOccupancyTask") << "RecHitCollection not available";
163  }
164 
165  //Fill histograms after a event
166  for (int i = 0; i < 2; ++i)
167  for (int j = 0; j < 2; ++j) {
168 
169  hRecNHit_[i][j]->Fill(sum_RecHits[i][j]);
170  hGoodRecNHit_[i][j]->Fill(sum_GoodRecHits[i][j]);
171  hEvEng_[i][j]->Fill(sum_Energy[i][j]);
172 
173  //Save eCount_ for Scaling
174  hRecOCC_[i][j]->setBinContent(40,40,eCount_);
175  hEnDensity_[i][j]->setBinContent(40,40,eCount_);
176 
177  hSelOCC_[i][j]->setBinContent(40,40,eCount_);
178  hSelEnDensity_[i][j]->setBinContent(40,40,eCount_);
179  }
180 
181  hE1E2_[0]->Fill(sum_Energy[0][0], sum_Energy[0][1]);
182  hE1E2_[1]->Fill(sum_Energy[1][0], sum_Energy[1][1]);
183 
184 }
185 
186 //define this as a plug-in
RunNumber_t run() const
Definition: EventID.h:39
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:579
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
std::vector< EcalRecHit >::const_iterator const_iterator
int zside(DetId const &)
void analyze(const edm::Event &, const edm::EventSetup &) override
int zside() const
Definition: ESDetId.h:45
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
void setCurrentFolder(const std::string &fullpath)
Definition: DQMStore.cc:274
MonitorElement * book2D(Args &&...args)
Definition: DQMStore.h:136
edm::EventID id() const
Definition: EventBase.h:60
HLT enums.
void setAxisTitle(const std::string &title, int axis=1)
set x-, y- or z-axis title (axis=1, 2, 3 respectively)
MonitorElement * book1DD(Args &&...args)
Definition: DQMStore.h:130
const_iterator begin() const
Definition: Run.h:44