CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
EEPedestalOnlineClient.cc
Go to the documentation of this file.
1 /*
2  * \file EEPedestalOnlineClient.cc
3  *
4  * $Date: 2012/04/27 13:46:08 $
5  * $Revision: 1.117 $
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
28 #endif
29 
31 
34 
36 
38 
40 
41  // cloneME switch
42  cloneME_ = ps.getUntrackedParameter<bool>("cloneME", true);
43 
44  // verbose switch
45  verbose_ = ps.getUntrackedParameter<bool>("verbose", true);
46 
47  // debug switch
48  debug_ = ps.getUntrackedParameter<bool>("debug", false);
49 
50  // prefixME path
51  prefixME_ = ps.getUntrackedParameter<std::string>("prefixME", "");
52 
53  subfolder_ = ps.getUntrackedParameter<std::string>("subfolder", "");
54 
55  // enableCleanup_ switch
56  enableCleanup_ = ps.getUntrackedParameter<bool>("enableCleanup", false);
57 
58  // vector of selected Super Modules (Defaults to all 18).
59  superModules_.reserve(18);
60  for ( unsigned int i = 1; i <= 18; i++ ) superModules_.push_back(i);
61  superModules_ = ps.getUntrackedParameter<std::vector<int> >("superModules", superModules_);
62 
63  for ( unsigned int i=0; i<superModules_.size(); i++ ) {
64 
65  int ism = superModules_[i];
66 
67  h03_[ism-1] = 0;
68 
69  }
70 
71  for ( unsigned int i=0; i<superModules_.size(); i++ ) {
72 
73  int ism = superModules_[i];
74 
75  meg03_[ism-1] = 0;
76 
77  mep03_[ism-1] = 0;
78 
79  mer03_[ism-1] = 0;
80 
81  }
82 
83  expectedMean_ = 200.0;
84  discrepancyMean_ = 25.0;
85  RMSThreshold_ = 4.0;
87 
88 }
89 
91 
92 }
93 
95 
97 
98  if ( debug_ ) std::cout << "EEPedestalOnlineClient: beginJob" << std::endl;
99 
100  ievt_ = 0;
101  jevt_ = 0;
102 
103 }
104 
106 
107  if ( debug_ ) std::cout << "EEPedestalOnlineClient: beginRun" << std::endl;
108 
109  jevt_ = 0;
110 
111  this->setup();
112 
113 }
114 
116 
117  if ( debug_ ) std::cout << "EEPedestalOnlineClient: endJob, ievt = " << ievt_ << std::endl;
118 
119  this->cleanup();
120 
121 }
122 
124 
125  if ( debug_ ) std::cout << "EEPedestalOnlineClient: endRun, jevt = " << jevt_ << std::endl;
126 
127  this->cleanup();
128 
129 }
130 
132 
134 
135  dqmStore_->setCurrentFolder( prefixME_ + "/EEPedestalOnlineClient" );
136 
137  if(subfolder_.size())
138  dqmStore_->setCurrentFolder(prefixME_ + "/EEPedestalOnlineClient/" + subfolder_);
139 
140  for ( unsigned int i=0; i<superModules_.size(); i++ ) {
141 
142  int ism = superModules_[i];
143 
144  if ( meg03_[ism-1] ) dqmStore_->removeElement( meg03_[ism-1]->getName() );
145  name = "EEPOT pedestal quality G12 " + Numbers::sEE(ism);
146  meg03_[ism-1] = dqmStore_->book2D(name, name, 50, Numbers::ix0EE(ism)+0., Numbers::ix0EE(ism)+50., 50, Numbers::iy0EE(ism)+0., Numbers::iy0EE(ism)+50.);
147  meg03_[ism-1]->setAxisTitle("ix", 1);
148  if ( ism >= 1 && ism <= 9 ) meg03_[ism-1]->setAxisTitle("101-ix", 1);
149  meg03_[ism-1]->setAxisTitle("iy", 2);
150 
151  if ( mep03_[ism-1] ) dqmStore_->removeElement( mep03_[ism-1]->getName() );
152  name = "EEPOT pedestal mean G12 " + Numbers::sEE(ism);
153  mep03_[ism-1] = dqmStore_->book1D(name, name, 100, 150., 250.);
154  mep03_[ism-1]->setAxisTitle("mean", 1);
155 
156  if ( mer03_[ism-1] ) dqmStore_->removeElement( mer03_[ism-1]->getName() );
157  name = "EEPOT pedestal rms G12 " + Numbers::sEE(ism);
158  mer03_[ism-1] = dqmStore_->book1D(name, name, 100, 0., 10.);
159  mer03_[ism-1]->setAxisTitle("rms", 1);
160 
161  }
162 
163  for ( unsigned int i=0; i<superModules_.size(); i++ ) {
164 
165  int ism = superModules_[i];
166 
167  if ( meg03_[ism-1] ) meg03_[ism-1]->Reset();
168 
169  for ( int ix = 1; ix <= 50; ix++ ) {
170  for ( int iy = 1; iy <= 50; iy++ ) {
171 
172  meg03_[ism-1]->setBinContent( ix, iy, 6. );
173 
174  int jx = ix + Numbers::ix0EE(ism);
175  int jy = iy + Numbers::iy0EE(ism);
176 
177  if ( ism >= 1 && ism <= 9 ) jx = 101 - jx;
178 
179  if ( Numbers::validEE(ism, jx, jy) ) {
180  meg03_[ism-1]->setBinContent( ix, iy, 2. );
181  }
182 
183  }
184  }
185 
186  if ( mep03_[ism-1] ) mep03_[ism-1]->Reset();
187  if ( mer03_[ism-1] ) mer03_[ism-1]->Reset();
188 
189  }
190 
191 }
192 
194 
195  if ( ! enableCleanup_ ) return;
196 
197  for ( unsigned int i=0; i<superModules_.size(); i++ ) {
198 
199  int ism = superModules_[i];
200 
201  if ( cloneME_ ) {
202  if ( h03_[ism-1] ) delete h03_[ism-1];
203  }
204 
205  h03_[ism-1] = 0;
206 
207  }
208 
209  dqmStore_->setCurrentFolder( prefixME_ + "/EEPedestalOnlineClient" );
210 
211  if(subfolder_.size())
212  dqmStore_->setCurrentFolder(prefixME_ + "/EEPedestalOnlineClient/" + subfolder_);
213 
214  for ( unsigned int i=0; i<superModules_.size(); i++ ) {
215 
216  int ism = superModules_[i];
217 
218  if ( meg03_[ism-1] ) dqmStore_->removeElement( meg03_[ism-1]->getName() );
219  meg03_[ism-1] = 0;
220 
221  if ( mep03_[ism-1] ) dqmStore_->removeElement( mep03_[ism-1]->getName() );
222  mep03_[ism-1] = 0;
223 
224  if ( mer03_[ism-1] ) dqmStore_->removeElement( mer03_[ism-1]->getName() );
225  mer03_[ism-1] = 0;
226 
227  }
228 
229 }
230 
231 #ifdef WITH_ECAL_COND_DB
232 bool EEPedestalOnlineClient::writeDb(EcalCondDBInterface* econn, RunIOV* runiov, MonRunIOV* moniov, bool& status) {
233 
234  status = true;
235 
236  EcalLogicID ecid;
237 
239  std::map<EcalLogicID, MonPedestalsOnlineDat> dataset;
240 
241  for ( unsigned int i=0; i<superModules_.size(); i++ ) {
242 
243  int ism = superModules_[i];
244 
245  if ( verbose_ ) {
246  std::cout << " " << Numbers::sEE(ism) << " (ism=" << ism << ")" << std::endl;
247  std::cout << std::endl;
248  UtilsClient::printBadChannels(meg03_[ism-1], h03_[ism-1]);
249  }
250 
251  float num03;
252  float mean03;
253  float rms03;
254 
255  for ( int ix = 1; ix <= 50; ix++ ) {
256  for ( int iy = 1; iy <= 50; iy++ ) {
257 
258  int jx = ix + Numbers::ix0EE(ism);
259  int jy = iy + Numbers::iy0EE(ism);
260 
261  if ( ism >= 1 && ism <= 9 ) jx = 101 - jx;
262 
263  if ( ! Numbers::validEE(ism, jx, jy) ) continue;
264 
265  bool update03;
266 
267  update03 = UtilsClient::getBinStatistics(h03_[ism-1], ix, iy, num03, mean03, rms03);
268 
269  if ( update03 ) {
270 
271  if ( Numbers::icEE(ism, jx, jy) == 1 ) {
272 
273  if ( verbose_ ) {
274  std::cout << "Preparing dataset for " << Numbers::sEE(ism) << " (ism=" << ism << ")" << std::endl;
275  std::cout << "G12 (" << Numbers::ix0EE(i+1)+ix << "," << Numbers::iy0EE(i+1)+iy << ") " << num03 << " " << mean03 << " " << rms03 << std::endl;
276  std::cout << std::endl;
277  }
278 
279  }
280 
281  p.setADCMeanG12(mean03);
282  p.setADCRMSG12(rms03);
283 
284  if ( UtilsClient::getBinStatus(meg03_[ism-1], ix, iy) ) {
285  p.setTaskStatus(true);
286  } else {
287  p.setTaskStatus(false);
288  }
289 
290  status = status && UtilsClient::getBinQuality(meg03_[ism-1], ix, iy);
291 
292  int ic = Numbers::indexEE(ism, jx, jy);
293 
294  if ( ic == -1 ) continue;
295 
296  if ( econn ) {
297  ecid = LogicID::getEcalLogicID("EE_crystal_number", Numbers::iSM(ism, EcalEndcap), ic);
298  dataset[ecid] = p;
299  }
300 
301  }
302 
303  }
304  }
305 
306  }
307 
308  if ( econn ) {
309  try {
310  if ( verbose_ ) std::cout << "Inserting MonPedestalsOnlineDat ..." << std::endl;
311  if ( dataset.size() != 0 ) econn->insertDataArraySet(&dataset, moniov);
312  if ( verbose_ ) std::cout << "done." << std::endl;
313  } catch (std::runtime_error &e) {
314  std::cerr << e.what() << std::endl;
315  }
316  }
317 
318  return true;
319 
320 }
321 #endif
322 
324 
325  ievt_++;
326  jevt_++;
327  if ( ievt_ % 10 == 0 ) {
328  if ( debug_ ) std::cout << "EEPedestalOnlineClient: ievt/jevt = " << ievt_ << "/" << jevt_ << std::endl;
329  }
330 
331  uint32_t bits03 = 0;
334 
335  std::string subdir(subfolder_.size() ? subfolder_ + "/" : "");
336 
337  MonitorElement* me;
338 
339  for ( unsigned int i=0; i<superModules_.size(); i++ ) {
340 
341  int ism = superModules_[i];
342 
343  me = dqmStore_->get( prefixME_ + "/EEPedestalOnlineTask/" + subdir + "Gain12/EEPOT pedestal " + Numbers::sEE(ism) + " G12" );
344  h03_[ism-1] = UtilsClient::getHisto( me, cloneME_, h03_[ism-1] );
345 
346  if ( meg03_[ism-1] ) meg03_[ism-1]->Reset();
347  if ( mep03_[ism-1] ) mep03_[ism-1]->Reset();
348  if ( mer03_[ism-1] ) mer03_[ism-1]->Reset();
349 
350  for ( int ix = 1; ix <= 50; ix++ ) {
351  for ( int iy = 1; iy <= 50; iy++ ) {
352 
353  if ( meg03_[ism-1] ) meg03_[ism-1]->setBinContent(ix, iy, 6.);
354 
355  int jx = ix + Numbers::ix0EE(ism);
356  int jy = iy + Numbers::iy0EE(ism);
357 
358  if ( ism >= 1 && ism <= 9 ) jx = 101 - jx;
359 
360  if ( Numbers::validEE(ism, jx, jy) ) {
361  if ( meg03_[ism-1] ) meg03_[ism-1]->setBinContent( ix, iy, 2. );
362  }
363 
364  // OOT pileup affects the region near beam pipe mostly. Use higher threshold for these crystals
365  float radius = std::sqrt((jx-50.)*(jx-50.)+(jy-50.)*(jy-50.));
366 
367  bool update03;
368 
369  float num03;
370  float mean03;
371  float rms03;
372 
373  update03 = UtilsClient::getBinStatistics(h03_[ism-1], ix, iy, num03, mean03, rms03);
374 
375  if ( update03 ) {
376 
377  float val;
378 
379  val = 1.;
380  if ( std::abs(mean03 - expectedMean_) > discrepancyMean_ )
381  val = 0.;
382  if ( (radius >= 20. && rms03 > RMSThreshold_) || (radius < 20. && rms03 > RMSThresholdInternal_) )
383  val = 0.;
384  if ( meg03_[ism-1] ) meg03_[ism-1]->setBinContent(ix, iy, val);
385 
386  if ( mep03_[ism-1] ) mep03_[ism-1]->Fill(mean03);
387  if ( mer03_[ism-1] ) mer03_[ism-1]->Fill(rms03);
388 
389  }
390 
391  if ( Masks::maskChannel(ism, ix, iy, bits03, EcalEndcap) ) UtilsClient::maskBinContent( meg03_[ism-1], ix, iy );
392 
393  }
394  }
395 
396  }
397 
398 }
399 
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 setBinContent(int binx, double content)
set content of bin (1-D)
std::vector< int > superModules_
static bool maskChannel(int ism, int i1, int i2, uint32_t bits, const EcalSubdetector subdet)
Definition: Masks.cc:60
static unsigned icEE(const unsigned ism, const unsigned ix, const unsigned iy)
Definition: Numbers.cc:739
MonitorElement * book1D(const char *name, const char *title, int nchX, double lowX, double highX)
Book 1D histogram.
Definition: DQMStore.cc:722
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.
MonitorElement * mer03_[18]
static bool getBinQuality(const MonitorElement *me, const int ix, const int iy)
Returns true if the bin quality is good or masked.
Definition: UtilsClient.cc:201
void beginJob(void)
BeginJob.
static const int PEDESTAL_ONLINE_HIGH_GAIN_RMS_ERROR
#define abs(x)
Definition: mlp_lapack.h:159
MonitorElement * meg03_[18]
void beginRun(void)
BeginRun.
static int ix0EE(const unsigned ism)
Definition: Numbers.cc:773
static void maskBinContent(const MonitorElement *me, const int ix, const int iy)
Mask the bin content.
Definition: UtilsClient.cc:231
static int iy0EE(const unsigned ism)
Definition: Numbers.cc:812
void Fill(long long x)
static bool getBinStatus(const MonitorElement *me, const int ix, const int iy)
Returns true if the bin status is red/dark red.
Definition: UtilsClient.cc:216
MonitorElement * mep03_[18]
void setTaskStatus(bool status)
T sqrt(T t)
Definition: SSEVec.h:48
void removeElement(const std::string &name)
Definition: DQMStore.cc:2577
channel masking
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 setADCMeanG12(float mean)
Ecal Monitor Utils for Client.
static bool getBinStatistics(TH1 *histo, const int ix, const int iy, float &num, float &mean, float &rms, float minEntries=1.)
Returns true if the bin contains good statistical data.
Definition: UtilsClient.cc:74
tuple dataset
Definition: dataset.py:393
static const int PEDESTAL_ONLINE_HIGH_GAIN_MEAN_ERROR
EEPedestalOnlineClient(const edm::ParameterSet &ps)
Constructor.
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
MonitorElement * book2D(const char *name, const char *title, int nchX, double lowX, double highX, int nchY, double lowY, double highY)
Book 2D histogram.
Definition: DQMStore.cc:850
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 setAxisTitle(const std::string &title, int axis=1)
set x-, y- or z-axis title (axis=1, 2, 3 respectively)
void Reset(void)
reset ME (ie. contents, errors, etc)
static void printBadChannels(const MonitorElement *me, TH1 *hi, bool positive_only=false)
Print the bad channels.
Definition: UtilsClient.cc:14
void setCurrentFolder(const std::string &fullpath)
Definition: DQMStore.cc:434
virtual ~EEPedestalOnlineClient()
Destructor.