CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
EEOccupancyClient.cc
Go to the documentation of this file.
1 /*
2  * \file EEOccupancyClient.cc
3  *
4  * \author G. Della Ricca
5  * \author F. Cossutti
6  *
7 */
8 
9 #include <memory>
10 #include <iostream>
11 #include <fstream>
12 #include <iomanip>
13 #include <math.h>
14 
16 
19 
20 #ifdef WITH_ECAL_COND_DB
24 #endif
25 
28 
30 
32 
33  // cloneME switch
34  cloneME_ = ps.getUntrackedParameter<bool>("cloneME", true);
35 
36  // verbose switch
37  verbose_ = ps.getUntrackedParameter<bool>("verbose", true);
38 
39  // debug switch
40  debug_ = ps.getUntrackedParameter<bool>("debug", false);
41 
42  // prefixME path
43  prefixME_ = ps.getUntrackedParameter<std::string>("prefixME", "");
44 
45  // enableCleanup_ switch
46  enableCleanup_ = ps.getUntrackedParameter<bool>("enableCleanup", false);
47 
48  // vector of selected Super Modules (Defaults to all 18).
49  superModules_.reserve(18);
50  for ( unsigned int i = 1; i <= 18; i++ ) superModules_.push_back(i);
51  superModules_ = ps.getUntrackedParameter<std::vector<int> >("superModules", superModules_);
52 
53  for ( unsigned int i=0; i<superModules_.size(); i++ ) {
54  int ism = superModules_[i];
55  i01_[ism-1] = 0;
56  i02_[ism-1] = 0;
57  }
58 
59  for ( int i=0; i<3; i++) {
60  h01_[0][i] = 0;
61  h01ProjEta_[0][i] = 0;
62  h01ProjPhi_[0][i] = 0;
63  h01_[1][i] = 0;
64  h01ProjEta_[1][i] = 0;
65  h01ProjPhi_[1][i] = 0;
66  }
67 
68  for ( int i=0; i<2; i++) {
69  h02_[0][i] = 0;
70  h02ProjEta_[0][i] = 0;
71  h02ProjPhi_[0][i] = 0;
72  h02_[1][i] = 0;
73  h02ProjEta_[1][i] = 0;
74  h02ProjPhi_[1][i] = 0;
75  }
76 
77 }
78 
80 
81 }
82 
84 
86 
87  if ( debug_ ) std::cout << "EEOccupancyClient: beginJob" << std::endl;
88 
89  ievt_ = 0;
90  jevt_ = 0;
91 
92 }
93 
95 
96  if ( debug_ ) std::cout << "EEOccupancyClient: beginRun" << std::endl;
97 
98  jevt_ = 0;
99 
100  this->setup();
101 
102 }
103 
105 
106  if ( debug_ ) std::cout << "EEOccupancyClient: endJob, ievt = " << ievt_ << std::endl;
107 
108  this->cleanup();
109 
110 }
111 
113 
114  if ( debug_ ) std::cout << "EEOccupancyClient: endRun, jevt = " << jevt_ << std::endl;
115 
116  this->cleanup();
117 
118 }
119 
121 
122  dqmStore_->setCurrentFolder( prefixME_ + "/EEOccupancyClient" );
123 
124 }
125 
127 
128  if ( ! enableCleanup_ ) return;
129 
130  if ( cloneME_ ) {
131 
132  for ( unsigned int i=0; i<superModules_.size(); i++ ) {
133  int ism = superModules_[i];
134  if ( i01_[ism-1] ) delete i01_[ism-1];
135  if ( i02_[ism-1] ) delete i02_[ism-1];
136  }
137 
138  for ( int i=0; i<3; ++i ) {
139  if ( h01_[0][i] ) delete h01_[0][i];
140  if ( h01ProjEta_[0][i] ) delete h01ProjEta_[0][i];
141  if ( h01ProjPhi_[0][i] ) delete h01ProjPhi_[0][i];
142  if ( h01_[1][i] ) delete h01_[1][i];
143  if ( h01ProjEta_[1][i] ) delete h01ProjEta_[1][i];
144  if ( h01ProjPhi_[1][i] ) delete h01ProjPhi_[1][i];
145  }
146 
147  for ( int i=0; i<2; ++i ) {
148  if ( h02_[0][i] ) delete h02_[0][i];
149  if ( h02ProjEta_[0][i] ) delete h02ProjEta_[0][i];
150  if ( h02ProjPhi_[0][i] ) delete h02ProjPhi_[0][i];
151  if ( h01_[1][i] ) delete h01_[1][i];
152  if ( h01ProjEta_[1][i] ) delete h01ProjEta_[1][i];
153  if ( h01ProjPhi_[1][i] ) delete h01ProjPhi_[1][i];
154  }
155 
156  }
157 
158  for ( int i=0; i<3; i++) {
159  h01_[0][i] = 0;
160  h01ProjEta_[0][i] = 0;
161  h01ProjPhi_[0][i] = 0;
162  h01_[1][i] = 0;
163  h01ProjEta_[1][i] = 0;
164  h01ProjPhi_[1][i] = 0;
165  }
166 
167  for ( int i=0; i<2; i++) {
168  h02_[0][i] = 0;
169  h02ProjEta_[0][i] = 0;
170  h02ProjPhi_[0][i] = 0;
171  h02_[1][i] = 0;
172  h02ProjEta_[1][i] = 0;
173  h02ProjPhi_[1][i] = 0;
174  }
175 
176 }
177 
178 #ifdef WITH_ECAL_COND_DB
179 bool EEOccupancyClient::writeDb(EcalCondDBInterface* econn, RunIOV* runiov, MonRunIOV* moniov, bool& status) {
180 
181  status = true;
182 
183  EcalLogicID ecid;
184 
186  std::map<EcalLogicID, MonOccupancyDat> dataset;
187 
188  for ( unsigned int i=0; i<superModules_.size(); i++ ) {
189 
190  int ism = superModules_[i];
191 
192  if ( verbose_ ) {
193  std::cout << " " << Numbers::sEE(ism) << " (ism=" << ism << ")" << std::endl;
194  std::cout << std::endl;
195  }
196 
197  const float n_min_tot = 1000.;
198  const float n_min_bin = 10.;
199 
200  float num01, num02;
201  float mean01, mean02;
202  float rms01, rms02;
203 
204  for ( int ix = 1; ix <= 50; ix++ ) {
205  for ( int iy = 1; iy <= 50; iy++ ) {
206 
207  int jx = ix + Numbers::ix0EE(ism);
208  int jy = iy + Numbers::iy0EE(ism);
209 
210  if ( ism >= 1 && ism <= 9 ) jx = 101 - jx;
211 
212  if ( ! Numbers::validEE(ism, jx, jy) ) continue;
213 
214  num01 = num02 = -1.;
215  mean01 = mean02 = -1.;
216  rms01 = rms02 = -1.;
217 
218  bool update_channel = false;
219 
220  if ( i01_[ism-1] && i01_[ism-1]->GetEntries() >= n_min_tot ) {
221  num01 = i01_[ism-1]->GetBinContent(i01_[ism-1]->GetBin(ix, iy));
222  if ( num01 >= n_min_bin ) update_channel = true;
223  }
224 
225  if ( i02_[ism-1] && i02_[ism-1]->GetEntries() >= n_min_tot ) {
226  num02 = i02_[ism-1]->GetBinEntries(i02_[ism-1]->GetBin(ix, iy));
227  if ( num02 >= n_min_bin ) {
228  mean02 = i02_[ism-1]->GetBinContent(ix, iy);
229  rms02 = i02_[ism-1]->GetBinError(ix, iy);
230  }
231  }
232 
233  if ( update_channel ) {
234 
235  if ( Numbers::icEE(ism, jx, jy) == 1 ) {
236 
237  if ( verbose_ ) {
238  std::cout << "Preparing dataset for " << Numbers::sEE(ism) << " (ism=" << ism << ")" << std::endl;
239  std::cout << "Digi (" << Numbers::ix0EE(i+1)+ix << "," << Numbers::iy0EE(i+1)+iy << ") " << num01 << " " << mean01 << " " << rms01 << std::endl;
240  std::cout << "RecHitThr (" << Numbers::ix0EE(i+1)+ix << "," << Numbers::iy0EE(i+1)+iy << ") " << num02 << " " << mean02 << " " << rms02 << std::endl;
241  std::cout << std::endl;
242  }
243 
244  }
245 
246  o.setEventsOverLowThreshold(int(num01));
247  o.setEventsOverHighThreshold(int(num02));
248 
249  o.setAvgEnergy(mean02);
250 
251  int ic = Numbers::indexEE(ism, jx, jy);
252 
253  if ( ic == -1 ) continue;
254 
255  if ( econn ) {
256  ecid = LogicID::getEcalLogicID("EE_crystal_number", Numbers::iSM(ism, EcalEndcap), ic);
257  dataset[ecid] = o;
258  }
259 
260  }
261 
262  }
263  }
264 
265  }
266 
267  if ( econn ) {
268  try {
269  if ( verbose_ ) std::cout << "Inserting MonOccupancyDat ..." << std::endl;
270  if ( dataset.size() != 0 ) econn->insertDataArraySet(&dataset, moniov);
271  if ( verbose_ ) std::cout << "done." << std::endl;
272  } catch (std::runtime_error &e) {
273  std::cerr << e.what() << std::endl;
274  }
275  }
276 
277  return true;
278 
279 }
280 #endif
281 
283 
284  ievt_++;
285  jevt_++;
286  if ( ievt_ % 10 == 0 ) {
287  if ( debug_ ) std::cout << "EEOccupancyClient: ievt/jevt = " << ievt_ << "/" << jevt_ << std::endl;
288  }
289 
290  MonitorElement* me;
291 
292  for ( unsigned int i=0; i<superModules_.size(); i++ ) {
293 
294  int ism = superModules_[i];
295 
296  me = dqmStore_->get( prefixME_ + "/EEOccupancyTask/EEOT digi occupancy " + Numbers::sEE(ism) );
297  i01_[ism-1] = UtilsClient::getHisto( me, cloneME_, i01_[ism-1] );
298 
299  me = dqmStore_->get( prefixME_ + "/EEOccupancyTask/EEOT rec hit energy " + Numbers::sEE(ism) );
300  i02_[ism-1] = UtilsClient::getHisto( me, cloneME_, i02_[ism-1] );
301 
302  }
303 
304  me = dqmStore_->get( "/EEOccupancyTask/EEOT digi occupancy EE -" );
305  h01_[0][0] = UtilsClient::getHisto( me, cloneME_, h01_[0][0] );
306 
307  me = dqmStore_->get( "/EEOccupancyTask/EEOT digi occupancy EE - projection eta" );
309 
310  me = dqmStore_->get( "/EEOccupancyTask/EEOT digi occupancy EE - projection phi" );
312 
313  me = dqmStore_->get( "/EEOccupancyTask/EEOT digi occupancy EE +" );
314  h01_[1][0] = UtilsClient::getHisto( me, cloneME_, h01_[1][0] );
315 
316  me = dqmStore_->get( "/EEOccupancyTask/EEOT digi occupancy EE + projection eta" );
318 
319  me = dqmStore_->get( "/EEOccupancyTask/EEOT digi occupancy EE + projection phi" );
321 
322  me = dqmStore_->get( "/EEOccupancyTask/EEOT rec hit occupancy EE -" );
323  h01_[0][1] = UtilsClient::getHisto( me, cloneME_, h01_[0][1] );
324 
325  me = dqmStore_->get( "/EEOccupancyTask/EEOT rec hit occupancy EE - projection eta" );
327 
328  me = dqmStore_->get( "/EEOccupancyTask/EEOT rec hit occupancy EE - projection phi" );
330 
331  me = dqmStore_->get( "/EEOccupancyTask/EEOT rec hit occupancy EE +" );
332  h01_[1][1] = UtilsClient::getHisto( me, cloneME_, h01_[1][1] );
333 
334  me = dqmStore_->get( "/EEOccupancyTask/EEOT rec hit occupancy EE + projection eta" );
336 
337  me = dqmStore_->get( "/EEOccupancyTask/EEOT rec hit occupancy EE + projection phi" );
339 
340  me = dqmStore_->get( "/EEOccupancyTask/EEOT TP digi occupancy EE -" );
341  h01_[0][2] = UtilsClient::getHisto( me, cloneME_, h01_[0][2] );
342 
343  me = dqmStore_->get( "/EEOccupancyTask/EEOT TP digi occupancy EE - projection eta" );
345 
346  me = dqmStore_->get( "/EEOccupancyTask/EEOT TP digi occupancy EE - projection phi" );
348 
349  me = dqmStore_->get( "/EEOccupancyTask/EEOT TP digi occupancy EE +" );
350  h01_[1][2] = UtilsClient::getHisto( me, cloneME_, h01_[1][2] );
351 
352  me = dqmStore_->get( "/EEOccupancyTask/EEOT TP digi occupancy EE + projection eta" );
354 
355  me = dqmStore_->get( "/EEOccupancyTask/EEOT TP digi occupancy EE + projection phi" );
357 
358  me = dqmStore_->get( "/EEOccupancyTask/EEOT rec hit thr occupancy EE -" );
359  h02_[0][0] = UtilsClient::getHisto( me, cloneME_, h02_[0][0] );
360 
361  me = dqmStore_->get( "/EEOccupancyTask/EEOT rec hit thr occupancy EE - projection eta" );
363 
364  me = dqmStore_->get( "/EEOccupancyTask/EEOT rec hit thr occupancy EE - projection phi" );
366 
367  me = dqmStore_->get( "/EEOccupancyTask/EEOT rec hit thr occupancy EE +" );
368  h02_[1][0] = UtilsClient::getHisto( me, cloneME_, h02_[1][0] );
369 
370  me = dqmStore_->get( "/EEOccupancyTask/EEOT rec hit thr occupancy EE + projection eta" );
372 
373  me = dqmStore_->get( "/EEOccupancyTask/EEOT rec hit thr occupancy EE + projection phi" );
375 
376  me = dqmStore_->get( "/EEOccupancyTask/EEOT TP digi thr occupancy EE -" );
377  h02_[0][1] = UtilsClient::getHisto( me, cloneME_, h02_[0][1] );
378 
379  me = dqmStore_->get( "/EEOccupancyTask/EEOT TP digi thr occupancy EE - projection eta" );
381 
382  me = dqmStore_->get( "/EEOccupancyTask/EEOT TP digi thr occupancy EE - projection phi" );
384 
385  me = dqmStore_->get( "/EEOccupancyTask/EEOT TP digi thr occupancy EE +" );
386  h02_[1][1] = UtilsClient::getHisto( me, cloneME_, h02_[1][1] );
387 
388  me = dqmStore_->get( "/EEOccupancyTask/EEOT TP digi thr occupancy EE + projection eta" );
390 
391  me = dqmStore_->get( "/EEOccupancyTask/EEOT TP digi thr occupancy EE + projection phi" );
393 
394 }
395 
Cache logicID vector from database.
T getUntrackedParameter(std::string const &, T const &) const
static std::string sEE(const unsigned ism)
Definition: Numbers.cc:223
int i
Definition: DBlmapReader.cc:9
static bool validEE(const unsigned ism, const unsigned ix, const unsigned iy)
Definition: Numbers.cc:829
void setup(void)
Setup.
static unsigned icEE(const unsigned ism, const unsigned ix, const unsigned iy)
Definition: Numbers.cc:736
void setAvgEnergy(float energy)
static T getHisto(const MonitorElement *me, bool clone=false, T ret=0)
Returns the histogram contained by the Monitor Element.
Definition: UtilsClient.h:89
Some &quot;id&quot; conversions.
void setEventsOverLowThreshold(int events)
TProfile2D * i02_[18]
virtual ~EEOccupancyClient()
Destructor.
EEOccupancyClient(const edm::ParameterSet &ps)
Constructor.
static int ix0EE(const unsigned ism)
Definition: Numbers.cc:770
static int iy0EE(const unsigned ism)
Definition: Numbers.cc:809
void endRun(void)
EndRun.
TH1F * h02ProjEta_[2][2]
void endJob(void)
EndJob.
MonitorElement * get(const std::string &path) const
get ME from full pathname (e.g. &quot;my/long/dir/my_histo&quot;)
Definition: DQMStore.cc:1623
void beginRun(void)
BeginRun.
TH1F * h02ProjPhi_[2][2]
Ecal Monitor Utils for Client.
TH1F * h01ProjEta_[2][3]
tuple dataset
Definition: dataset.py:393
void cleanup(void)
Cleanup.
std::vector< int > superModules_
void setEventsOverHighThreshold(int events)
TH1F * h01ProjPhi_[2][3]
static unsigned indexEE(const unsigned ism, const unsigned ix, const unsigned iy)
Definition: Numbers.cc:709
static unsigned iSM(const unsigned ism, const EcalSubdetector subdet)
Definition: Numbers.cc:243
void insertDataArraySet(const std::map< EcalLogicID, DATT > *data, IOVT *iov)
tuple cout
Definition: gather_cfg.py:121
tuple status
Definition: ntuplemaker.py:245
void analyze(void)
Analyze.
static EcalLogicID getEcalLogicID(const char *name, const int id1=EcalLogicID::NULLID, const int id2=EcalLogicID::NULLID, const int id3=EcalLogicID::NULLID)
Definition: LogicID.h:29
Definition: RunIOV.h:13
int ism(int ieta, int iphi)
Definition: EcalPyUtils.cc:56
void beginJob(void)
BeginJob.
void setCurrentFolder(const std::string &fullpath)
Definition: DQMStore.cc:584