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  * $Date: 2012/04/27 13:46:07 $
5  * $Revision: 1.46 $
6  * \author G. Della Ricca
7  * \author F. Cossutti
8  *
9 */
10 
11 #include <memory>
12 #include <iostream>
13 #include <fstream>
14 #include <iomanip>
15 #include <math.h>
16 
18 
21 
22 #ifdef WITH_ECAL_COND_DB
26 #endif
27 
30 
32 
34 
35  // cloneME switch
36  cloneME_ = ps.getUntrackedParameter<bool>("cloneME", true);
37 
38  // verbose switch
39  verbose_ = ps.getUntrackedParameter<bool>("verbose", true);
40 
41  // debug switch
42  debug_ = ps.getUntrackedParameter<bool>("debug", false);
43 
44  // prefixME path
45  prefixME_ = ps.getUntrackedParameter<std::string>("prefixME", "");
46 
47  // enableCleanup_ switch
48  enableCleanup_ = ps.getUntrackedParameter<bool>("enableCleanup", false);
49 
50  // vector of selected Super Modules (Defaults to all 18).
51  superModules_.reserve(18);
52  for ( unsigned int i = 1; i <= 18; i++ ) superModules_.push_back(i);
53  superModules_ = ps.getUntrackedParameter<std::vector<int> >("superModules", superModules_);
54 
55  for ( unsigned int i=0; i<superModules_.size(); i++ ) {
56  int ism = superModules_[i];
57  i01_[ism-1] = 0;
58  i02_[ism-1] = 0;
59  }
60 
61  for ( int i=0; i<3; i++) {
62  h01_[0][i] = 0;
63  h01ProjEta_[0][i] = 0;
64  h01ProjPhi_[0][i] = 0;
65  h01_[1][i] = 0;
66  h01ProjEta_[1][i] = 0;
67  h01ProjPhi_[1][i] = 0;
68  }
69 
70  for ( int i=0; i<2; i++) {
71  h02_[0][i] = 0;
72  h02ProjEta_[0][i] = 0;
73  h02ProjPhi_[0][i] = 0;
74  h02_[1][i] = 0;
75  h02ProjEta_[1][i] = 0;
76  h02ProjPhi_[1][i] = 0;
77  }
78 
79 }
80 
82 
83 }
84 
86 
88 
89  if ( debug_ ) std::cout << "EEOccupancyClient: beginJob" << std::endl;
90 
91  ievt_ = 0;
92  jevt_ = 0;
93 
94 }
95 
97 
98  if ( debug_ ) std::cout << "EEOccupancyClient: beginRun" << std::endl;
99 
100  jevt_ = 0;
101 
102  this->setup();
103 
104 }
105 
107 
108  if ( debug_ ) std::cout << "EEOccupancyClient: endJob, ievt = " << ievt_ << std::endl;
109 
110  this->cleanup();
111 
112 }
113 
115 
116  if ( debug_ ) std::cout << "EEOccupancyClient: endRun, jevt = " << jevt_ << std::endl;
117 
118  this->cleanup();
119 
120 }
121 
123 
124  dqmStore_->setCurrentFolder( prefixME_ + "/EEOccupancyClient" );
125 
126 }
127 
129 
130  if ( ! enableCleanup_ ) return;
131 
132  if ( cloneME_ ) {
133 
134  for ( unsigned int i=0; i<superModules_.size(); i++ ) {
135  int ism = superModules_[i];
136  if ( i01_[ism-1] ) delete i01_[ism-1];
137  if ( i02_[ism-1] ) delete i02_[ism-1];
138  }
139 
140  for ( int i=0; i<3; ++i ) {
141  if ( h01_[0][i] ) delete h01_[0][i];
142  if ( h01ProjEta_[0][i] ) delete h01ProjEta_[0][i];
143  if ( h01ProjPhi_[0][i] ) delete h01ProjPhi_[0][i];
144  if ( h01_[1][i] ) delete h01_[1][i];
145  if ( h01ProjEta_[1][i] ) delete h01ProjEta_[1][i];
146  if ( h01ProjPhi_[1][i] ) delete h01ProjPhi_[1][i];
147  }
148 
149  for ( int i=0; i<2; ++i ) {
150  if ( h02_[0][i] ) delete h02_[0][i];
151  if ( h02ProjEta_[0][i] ) delete h02ProjEta_[0][i];
152  if ( h02ProjPhi_[0][i] ) delete h02ProjPhi_[0][i];
153  if ( h01_[1][i] ) delete h01_[1][i];
154  if ( h01ProjEta_[1][i] ) delete h01ProjEta_[1][i];
155  if ( h01ProjPhi_[1][i] ) delete h01ProjPhi_[1][i];
156  }
157 
158  }
159 
160  for ( int i=0; i<3; i++) {
161  h01_[0][i] = 0;
162  h01ProjEta_[0][i] = 0;
163  h01ProjPhi_[0][i] = 0;
164  h01_[1][i] = 0;
165  h01ProjEta_[1][i] = 0;
166  h01ProjPhi_[1][i] = 0;
167  }
168 
169  for ( int i=0; i<2; i++) {
170  h02_[0][i] = 0;
171  h02ProjEta_[0][i] = 0;
172  h02ProjPhi_[0][i] = 0;
173  h02_[1][i] = 0;
174  h02ProjEta_[1][i] = 0;
175  h02ProjPhi_[1][i] = 0;
176  }
177 
178 }
179 
180 #ifdef WITH_ECAL_COND_DB
181 bool EEOccupancyClient::writeDb(EcalCondDBInterface* econn, RunIOV* runiov, MonRunIOV* moniov, bool& status) {
182 
183  status = true;
184 
185  EcalLogicID ecid;
186 
188  std::map<EcalLogicID, MonOccupancyDat> dataset;
189 
190  for ( unsigned int i=0; i<superModules_.size(); i++ ) {
191 
192  int ism = superModules_[i];
193 
194  if ( verbose_ ) {
195  std::cout << " " << Numbers::sEE(ism) << " (ism=" << ism << ")" << std::endl;
196  std::cout << std::endl;
197  }
198 
199  const float n_min_tot = 1000.;
200  const float n_min_bin = 10.;
201 
202  float num01, num02;
203  float mean01, mean02;
204  float rms01, rms02;
205 
206  for ( int ix = 1; ix <= 50; ix++ ) {
207  for ( int iy = 1; iy <= 50; iy++ ) {
208 
209  int jx = ix + Numbers::ix0EE(ism);
210  int jy = iy + Numbers::iy0EE(ism);
211 
212  if ( ism >= 1 && ism <= 9 ) jx = 101 - jx;
213 
214  if ( ! Numbers::validEE(ism, jx, jy) ) continue;
215 
216  num01 = num02 = -1.;
217  mean01 = mean02 = -1.;
218  rms01 = rms02 = -1.;
219 
220  bool update_channel = false;
221 
222  if ( i01_[ism-1] && i01_[ism-1]->GetEntries() >= n_min_tot ) {
223  num01 = i01_[ism-1]->GetBinContent(i01_[ism-1]->GetBin(ix, iy));
224  if ( num01 >= n_min_bin ) update_channel = true;
225  }
226 
227  if ( i02_[ism-1] && i02_[ism-1]->GetEntries() >= n_min_tot ) {
228  num02 = i02_[ism-1]->GetBinEntries(i02_[ism-1]->GetBin(ix, iy));
229  if ( num02 >= n_min_bin ) {
230  mean02 = i02_[ism-1]->GetBinContent(ix, iy);
231  rms02 = i02_[ism-1]->GetBinError(ix, iy);
232  }
233  }
234 
235  if ( update_channel ) {
236 
237  if ( Numbers::icEE(ism, jx, jy) == 1 ) {
238 
239  if ( verbose_ ) {
240  std::cout << "Preparing dataset for " << Numbers::sEE(ism) << " (ism=" << ism << ")" << std::endl;
241  std::cout << "Digi (" << Numbers::ix0EE(i+1)+ix << "," << Numbers::iy0EE(i+1)+iy << ") " << num01 << " " << mean01 << " " << rms01 << std::endl;
242  std::cout << "RecHitThr (" << Numbers::ix0EE(i+1)+ix << "," << Numbers::iy0EE(i+1)+iy << ") " << num02 << " " << mean02 << " " << rms02 << std::endl;
243  std::cout << std::endl;
244  }
245 
246  }
247 
248  o.setEventsOverLowThreshold(int(num01));
249  o.setEventsOverHighThreshold(int(num02));
250 
251  o.setAvgEnergy(mean02);
252 
253  int ic = Numbers::indexEE(ism, jx, jy);
254 
255  if ( ic == -1 ) continue;
256 
257  if ( econn ) {
258  ecid = LogicID::getEcalLogicID("EE_crystal_number", Numbers::iSM(ism, EcalEndcap), ic);
259  dataset[ecid] = o;
260  }
261 
262  }
263 
264  }
265  }
266 
267  }
268 
269  if ( econn ) {
270  try {
271  if ( verbose_ ) std::cout << "Inserting MonOccupancyDat ..." << std::endl;
272  if ( dataset.size() != 0 ) econn->insertDataArraySet(&dataset, moniov);
273  if ( verbose_ ) std::cout << "done." << std::endl;
274  } catch (std::runtime_error &e) {
275  std::cerr << e.what() << std::endl;
276  }
277  }
278 
279  return true;
280 
281 }
282 #endif
283 
285 
286  ievt_++;
287  jevt_++;
288  if ( ievt_ % 10 == 0 ) {
289  if ( debug_ ) std::cout << "EEOccupancyClient: ievt/jevt = " << ievt_ << "/" << jevt_ << std::endl;
290  }
291 
292  MonitorElement* me;
293 
294  for ( unsigned int i=0; i<superModules_.size(); i++ ) {
295 
296  int ism = superModules_[i];
297 
298  me = dqmStore_->get( prefixME_ + "/EEOccupancyTask/EEOT digi occupancy " + Numbers::sEE(ism) );
299  i01_[ism-1] = UtilsClient::getHisto( me, cloneME_, i01_[ism-1] );
300 
301  me = dqmStore_->get( prefixME_ + "/EEOccupancyTask/EEOT rec hit energy " + Numbers::sEE(ism) );
302  i02_[ism-1] = UtilsClient::getHisto( me, cloneME_, i02_[ism-1] );
303 
304  }
305 
306  me = dqmStore_->get( "/EEOccupancyTask/EEOT digi occupancy EE -" );
307  h01_[0][0] = UtilsClient::getHisto( me, cloneME_, h01_[0][0] );
308 
309  me = dqmStore_->get( "/EEOccupancyTask/EEOT digi occupancy EE - projection eta" );
311 
312  me = dqmStore_->get( "/EEOccupancyTask/EEOT digi occupancy EE - projection phi" );
314 
315  me = dqmStore_->get( "/EEOccupancyTask/EEOT digi occupancy EE +" );
316  h01_[1][0] = UtilsClient::getHisto( me, cloneME_, h01_[1][0] );
317 
318  me = dqmStore_->get( "/EEOccupancyTask/EEOT digi occupancy EE + projection eta" );
320 
321  me = dqmStore_->get( "/EEOccupancyTask/EEOT digi occupancy EE + projection phi" );
323 
324  me = dqmStore_->get( "/EEOccupancyTask/EEOT rec hit occupancy EE -" );
325  h01_[0][1] = UtilsClient::getHisto( me, cloneME_, h01_[0][1] );
326 
327  me = dqmStore_->get( "/EEOccupancyTask/EEOT rec hit occupancy EE - projection eta" );
329 
330  me = dqmStore_->get( "/EEOccupancyTask/EEOT rec hit occupancy EE - projection phi" );
332 
333  me = dqmStore_->get( "/EEOccupancyTask/EEOT rec hit occupancy EE +" );
334  h01_[1][1] = UtilsClient::getHisto( me, cloneME_, h01_[1][1] );
335 
336  me = dqmStore_->get( "/EEOccupancyTask/EEOT rec hit occupancy EE + projection eta" );
338 
339  me = dqmStore_->get( "/EEOccupancyTask/EEOT rec hit occupancy EE + projection phi" );
341 
342  me = dqmStore_->get( "/EEOccupancyTask/EEOT TP digi occupancy EE -" );
343  h01_[0][2] = UtilsClient::getHisto( me, cloneME_, h01_[0][2] );
344 
345  me = dqmStore_->get( "/EEOccupancyTask/EEOT TP digi occupancy EE - projection eta" );
347 
348  me = dqmStore_->get( "/EEOccupancyTask/EEOT TP digi occupancy EE - projection phi" );
350 
351  me = dqmStore_->get( "/EEOccupancyTask/EEOT TP digi occupancy EE +" );
352  h01_[1][2] = UtilsClient::getHisto( me, cloneME_, h01_[1][2] );
353 
354  me = dqmStore_->get( "/EEOccupancyTask/EEOT TP digi occupancy EE + projection eta" );
356 
357  me = dqmStore_->get( "/EEOccupancyTask/EEOT TP digi occupancy EE + projection phi" );
359 
360  me = dqmStore_->get( "/EEOccupancyTask/EEOT rec hit thr occupancy EE -" );
361  h02_[0][0] = UtilsClient::getHisto( me, cloneME_, h02_[0][0] );
362 
363  me = dqmStore_->get( "/EEOccupancyTask/EEOT rec hit thr occupancy EE - projection eta" );
365 
366  me = dqmStore_->get( "/EEOccupancyTask/EEOT rec hit thr occupancy EE - projection phi" );
368 
369  me = dqmStore_->get( "/EEOccupancyTask/EEOT rec hit thr occupancy EE +" );
370  h02_[1][0] = UtilsClient::getHisto( me, cloneME_, h02_[1][0] );
371 
372  me = dqmStore_->get( "/EEOccupancyTask/EEOT rec hit thr occupancy EE + projection eta" );
374 
375  me = dqmStore_->get( "/EEOccupancyTask/EEOT rec hit thr occupancy EE + projection phi" );
377 
378  me = dqmStore_->get( "/EEOccupancyTask/EEOT TP digi thr occupancy EE -" );
379  h02_[0][1] = UtilsClient::getHisto( me, cloneME_, h02_[0][1] );
380 
381  me = dqmStore_->get( "/EEOccupancyTask/EEOT TP digi thr occupancy EE - projection eta" );
383 
384  me = dqmStore_->get( "/EEOccupancyTask/EEOT TP digi thr occupancy EE - projection phi" );
386 
387  me = dqmStore_->get( "/EEOccupancyTask/EEOT TP digi thr occupancy EE +" );
388  h02_[1][1] = UtilsClient::getHisto( me, cloneME_, h02_[1][1] );
389 
390  me = dqmStore_->get( "/EEOccupancyTask/EEOT TP digi thr occupancy EE + projection eta" );
392 
393  me = dqmStore_->get( "/EEOccupancyTask/EEOT TP digi thr occupancy EE + projection phi" );
395 
396 }
397 
Cache logicID vector from database.
T getUntrackedParameter(std::string const &, T const &) const
static std::string sEE(const unsigned ism)
Definition: Numbers.cc:226
int i
Definition: DBlmapReader.cc:9
static bool validEE(const unsigned ism, const unsigned ix, const unsigned iy)
Definition: Numbers.cc:832
void setup(void)
Setup.
static unsigned icEE(const unsigned ism, const unsigned ix, const unsigned iy)
Definition: Numbers.cc:739
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:91
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:773
static int iy0EE(const unsigned ism)
Definition: Numbers.cc:812
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:1473
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:712
static unsigned iSM(const unsigned ism, const EcalSubdetector subdet)
Definition: Numbers.cc:246
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:31
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:434