CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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] = 0;
36  hRecNHit_[i][j] = 0;
37  hEng_[i][j] = 0;
38  hEvEng_[i][j] = 0;
39  hEnDensity_[i][i] = 0;
40  hDigiNHit_[i][j] = 0;
41 
42  hSelEng_[i][j] = 0;
43  hSelOCC_[i][j] = 0;
44  hSelEnDensity_[i][j] = 0;
45  }
46 
47  for (int i = 0; i<2; ++i)
48  hE1E2_[i]=0;
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  hDigiNHit_[i][j] = iBooker.book1DD(histo, histo, 60, 0, 1920);
80  hDigiNHit_[i][j]->setAxisTitle("# of good RecHits", 1);
81  hDigiNHit_[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_DigiHits[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_DigiHits[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  hSelEng_[i][j]->Fill(hitItr->energy());
155  hSelEnDensity_[i][j]->Fill(ix, iy, hitItr->energy());
156  hSelOCC_[i][j]->Fill(ix, iy);
157  }
158 
159  }
160  } else {
161  LogWarning("ESOccupancyTask") << "RecHitCollection not available";
162  }
163 
164  //Fill histograms after a event
165  for (int i = 0; i < 2; ++i)
166  for (int j = 0; j < 2; ++j) {
167 
168  hRecNHit_[i][j]->Fill(sum_RecHits[i][j]);
169  hDigiNHit_[i][j]->Fill(sum_DigiHits[i][j]);
170  hEvEng_[i][j]->Fill(sum_Energy[i][j]);
171 
172  //Save eCount_ for Scaling
173  hRecOCC_[i][j]->setBinContent(40,40,eCount_);
174  hEnDensity_[i][j]->setBinContent(40,40,eCount_);
175 
176  hSelOCC_[i][j]->setBinContent(40,40,eCount_);
177  hSelEnDensity_[i][j]->setBinContent(40,40,eCount_);
178  }
179 
180  hE1E2_[0]->Fill(sum_Energy[0][0], sum_Energy[0][1]);
181  hE1E2_[1]->Fill(sum_Energy[1][0], sum_Energy[1][1]);
182 
183 }
184 
185 //define this as a plug-in
RunNumber_t run() const
Definition: EventID.h:42
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
int i
Definition: DBlmapReader.cc:9
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:434
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
std::vector< EcalRecHit >::const_iterator const_iterator
int zside(DetId const &)
int j
Definition: DBlmapReader.cc:9
virtual void analyze(const edm::Event &, const edm::EventSetup &) override
int zside() const
Definition: ESDetId.h:44
ESOccupancyTask(const edm::ParameterSet &ps)
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:131
edm::EventID id() const
Definition: EventBase.h:56
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:125
Definition: Run.h:41