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  * \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
26 #endif
27 
29 
32 
34 
36 
38 
39  // cloneME switch
40  cloneME_ = ps.getUntrackedParameter<bool>("cloneME", true);
41 
42  // verbose switch
43  verbose_ = ps.getUntrackedParameter<bool>("verbose", true);
44 
45  // debug switch
46  debug_ = ps.getUntrackedParameter<bool>("debug", false);
47 
48  // prefixME path
49  prefixME_ = ps.getUntrackedParameter<std::string>("prefixME", "");
50 
51  subfolder_ = ps.getUntrackedParameter<std::string>("subfolder", "");
52 
53  // enableCleanup_ switch
54  enableCleanup_ = ps.getUntrackedParameter<bool>("enableCleanup", false);
55 
56  // vector of selected Super Modules (Defaults to all 18).
57  superModules_.reserve(18);
58  for ( unsigned int i = 1; i <= 18; i++ ) superModules_.push_back(i);
59  superModules_ = ps.getUntrackedParameter<std::vector<int> >("superModules", superModules_);
60 
61  for ( unsigned int i=0; i<superModules_.size(); i++ ) {
62 
63  int ism = superModules_[i];
64 
65  h03_[ism-1] = 0;
66 
67  }
68 
69  for ( unsigned int i=0; i<superModules_.size(); i++ ) {
70 
71  int ism = superModules_[i];
72 
73  meg03_[ism-1] = 0;
74 
75  mep03_[ism-1] = 0;
76 
77  mer03_[ism-1] = 0;
78 
79  }
80 
81  expectedMean_ = 200.0;
82  discrepancyMean_ = 25.0;
83  RMSThreshold_ = 4.0;
85 
86 }
87 
89 
90 }
91 
93 
95 
96  if ( debug_ ) std::cout << "EEPedestalOnlineClient: beginJob" << std::endl;
97 
98  ievt_ = 0;
99  jevt_ = 0;
100 
101 }
102 
104 
105  if ( debug_ ) std::cout << "EEPedestalOnlineClient: beginRun" << std::endl;
106 
107  jevt_ = 0;
108 
109  this->setup();
110 
111 }
112 
114 
115  if ( debug_ ) std::cout << "EEPedestalOnlineClient: endJob, ievt = " << ievt_ << std::endl;
116 
117  this->cleanup();
118 
119 }
120 
122 
123  if ( debug_ ) std::cout << "EEPedestalOnlineClient: endRun, jevt = " << jevt_ << std::endl;
124 
125  this->cleanup();
126 
127 }
128 
130 
132 
133  dqmStore_->setCurrentFolder( prefixME_ + "/EEPedestalOnlineClient" );
134 
135  if(subfolder_.size())
136  dqmStore_->setCurrentFolder(prefixME_ + "/EEPedestalOnlineClient/" + subfolder_);
137 
138  for ( unsigned int i=0; i<superModules_.size(); i++ ) {
139 
140  int ism = superModules_[i];
141 
142  if ( meg03_[ism-1] ) dqmStore_->removeElement( meg03_[ism-1]->getName() );
143  name = "EEPOT pedestal quality G12 " + Numbers::sEE(ism);
144  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.);
145  meg03_[ism-1]->setAxisTitle("ix", 1);
146  if ( ism >= 1 && ism <= 9 ) meg03_[ism-1]->setAxisTitle("101-ix", 1);
147  meg03_[ism-1]->setAxisTitle("iy", 2);
148 
149  if ( mep03_[ism-1] ) dqmStore_->removeElement( mep03_[ism-1]->getName() );
150  name = "EEPOT pedestal mean G12 " + Numbers::sEE(ism);
151  mep03_[ism-1] = dqmStore_->book1D(name, name, 100, 150., 250.);
152  mep03_[ism-1]->setAxisTitle("mean", 1);
153 
154  if ( mer03_[ism-1] ) dqmStore_->removeElement( mer03_[ism-1]->getName() );
155  name = "EEPOT pedestal rms G12 " + Numbers::sEE(ism);
156  mer03_[ism-1] = dqmStore_->book1D(name, name, 100, 0., 10.);
157  mer03_[ism-1]->setAxisTitle("rms", 1);
158 
159  }
160 
161  for ( unsigned int i=0; i<superModules_.size(); i++ ) {
162 
163  int ism = superModules_[i];
164 
165  if ( meg03_[ism-1] ) meg03_[ism-1]->Reset();
166 
167  for ( int ix = 1; ix <= 50; ix++ ) {
168  for ( int iy = 1; iy <= 50; iy++ ) {
169 
170  meg03_[ism-1]->setBinContent( ix, iy, 6. );
171 
172  int jx = ix + Numbers::ix0EE(ism);
173  int jy = iy + Numbers::iy0EE(ism);
174 
175  if ( ism >= 1 && ism <= 9 ) jx = 101 - jx;
176 
177  if ( Numbers::validEE(ism, jx, jy) ) {
178  meg03_[ism-1]->setBinContent( ix, iy, 2. );
179  }
180 
181  }
182  }
183 
184  if ( mep03_[ism-1] ) mep03_[ism-1]->Reset();
185  if ( mer03_[ism-1] ) mer03_[ism-1]->Reset();
186 
187  }
188 
189 }
190 
192 
193  if ( ! enableCleanup_ ) return;
194 
195  for ( unsigned int i=0; i<superModules_.size(); i++ ) {
196 
197  int ism = superModules_[i];
198 
199  if ( cloneME_ ) {
200  if ( h03_[ism-1] ) delete h03_[ism-1];
201  }
202 
203  h03_[ism-1] = 0;
204 
205  }
206 
207  dqmStore_->setCurrentFolder( prefixME_ + "/EEPedestalOnlineClient" );
208 
209  if(subfolder_.size())
210  dqmStore_->setCurrentFolder(prefixME_ + "/EEPedestalOnlineClient/" + subfolder_);
211 
212  for ( unsigned int i=0; i<superModules_.size(); i++ ) {
213 
214  int ism = superModules_[i];
215 
216  if ( meg03_[ism-1] ) dqmStore_->removeElement( meg03_[ism-1]->getName() );
217  meg03_[ism-1] = 0;
218 
219  if ( mep03_[ism-1] ) dqmStore_->removeElement( mep03_[ism-1]->getName() );
220  mep03_[ism-1] = 0;
221 
222  if ( mer03_[ism-1] ) dqmStore_->removeElement( mer03_[ism-1]->getName() );
223  mer03_[ism-1] = 0;
224 
225  }
226 
227 }
228 
229 #ifdef WITH_ECAL_COND_DB
230 bool EEPedestalOnlineClient::writeDb(EcalCondDBInterface* econn, RunIOV* runiov, MonRunIOV* moniov, bool& status) {
231 
232  status = true;
233 
234  EcalLogicID ecid;
235 
237  std::map<EcalLogicID, MonPedestalsOnlineDat> dataset;
238 
239  for ( unsigned int i=0; i<superModules_.size(); i++ ) {
240 
241  int ism = superModules_[i];
242 
243  if ( verbose_ ) {
244  std::cout << " " << Numbers::sEE(ism) << " (ism=" << ism << ")" << std::endl;
245  std::cout << std::endl;
246  UtilsClient::printBadChannels(meg03_[ism-1], h03_[ism-1]);
247  }
248 
249  float num03;
250  float mean03;
251  float rms03;
252 
253  for ( int ix = 1; ix <= 50; ix++ ) {
254  for ( int iy = 1; iy <= 50; iy++ ) {
255 
256  int jx = ix + Numbers::ix0EE(ism);
257  int jy = iy + Numbers::iy0EE(ism);
258 
259  if ( ism >= 1 && ism <= 9 ) jx = 101 - jx;
260 
261  if ( ! Numbers::validEE(ism, jx, jy) ) continue;
262 
263  bool update03;
264 
265  update03 = UtilsClient::getBinStatistics(h03_[ism-1], ix, iy, num03, mean03, rms03);
266 
267  if ( update03 ) {
268 
269  if ( Numbers::icEE(ism, jx, jy) == 1 ) {
270 
271  if ( verbose_ ) {
272  std::cout << "Preparing dataset for " << Numbers::sEE(ism) << " (ism=" << ism << ")" << std::endl;
273  std::cout << "G12 (" << Numbers::ix0EE(i+1)+ix << "," << Numbers::iy0EE(i+1)+iy << ") " << num03 << " " << mean03 << " " << rms03 << std::endl;
274  std::cout << std::endl;
275  }
276 
277  }
278 
279  p.setADCMeanG12(mean03);
280  p.setADCRMSG12(rms03);
281 
282  if ( UtilsClient::getBinStatus(meg03_[ism-1], ix, iy) ) {
283  p.setTaskStatus(true);
284  } else {
285  p.setTaskStatus(false);
286  }
287 
288  status = status && UtilsClient::getBinQuality(meg03_[ism-1], ix, iy);
289 
290  int ic = Numbers::indexEE(ism, jx, jy);
291 
292  if ( ic == -1 ) continue;
293 
294  if ( econn ) {
295  ecid = LogicID::getEcalLogicID("EE_crystal_number", Numbers::iSM(ism, EcalEndcap), ic);
296  dataset[ecid] = p;
297  }
298 
299  }
300 
301  }
302  }
303 
304  }
305 
306  if ( econn ) {
307  try {
308  if ( verbose_ ) std::cout << "Inserting MonPedestalsOnlineDat ..." << std::endl;
309  if ( dataset.size() != 0 ) econn->insertDataArraySet(&dataset, moniov);
310  if ( verbose_ ) std::cout << "done." << std::endl;
311  } catch (std::runtime_error &e) {
312  std::cerr << e.what() << std::endl;
313  }
314  }
315 
316  return true;
317 
318 }
319 #endif
320 
322 
323  ievt_++;
324  jevt_++;
325  if ( ievt_ % 10 == 0 ) {
326  if ( debug_ ) std::cout << "EEPedestalOnlineClient: ievt/jevt = " << ievt_ << "/" << jevt_ << std::endl;
327  }
328 
329  uint32_t bits03 = 0;
332 
333  std::string subdir(subfolder_.size() ? subfolder_ + "/" : "");
334 
335  MonitorElement* me;
336 
337  for ( unsigned int i=0; i<superModules_.size(); i++ ) {
338 
339  int ism = superModules_[i];
340 
341  me = dqmStore_->get( prefixME_ + "/EEPedestalOnlineTask/" + subdir + "Gain12/EEPOT pedestal " + Numbers::sEE(ism) + " G12" );
342  h03_[ism-1] = UtilsClient::getHisto( me, cloneME_, h03_[ism-1] );
343 
344  if ( meg03_[ism-1] ) meg03_[ism-1]->Reset();
345  if ( mep03_[ism-1] ) mep03_[ism-1]->Reset();
346  if ( mer03_[ism-1] ) mer03_[ism-1]->Reset();
347 
348  for ( int ix = 1; ix <= 50; ix++ ) {
349  for ( int iy = 1; iy <= 50; iy++ ) {
350 
351  if ( meg03_[ism-1] ) meg03_[ism-1]->setBinContent(ix, iy, 6.);
352 
353  int jx = ix + Numbers::ix0EE(ism);
354  int jy = iy + Numbers::iy0EE(ism);
355 
356  if ( ism >= 1 && ism <= 9 ) jx = 101 - jx;
357 
358  if ( Numbers::validEE(ism, jx, jy) ) {
359  if ( meg03_[ism-1] ) meg03_[ism-1]->setBinContent( ix, iy, 2. );
360  }
361 
362  // OOT pileup affects the region near beam pipe mostly. Use higher threshold for these crystals
363  float radius = std::sqrt((jx-50.)*(jx-50.)+(jy-50.)*(jy-50.));
364 
365  bool update03;
366 
367  float num03;
368  float mean03;
369  float rms03;
370 
371  update03 = UtilsClient::getBinStatistics(h03_[ism-1], ix, iy, num03, mean03, rms03);
372 
373  if ( update03 ) {
374 
375  float val;
376 
377  val = 1.;
378  if ( std::abs(mean03 - expectedMean_) > discrepancyMean_ )
379  val = 0.;
380  if ( (radius >= 20. && rms03 > RMSThreshold_) || (radius < 20. && rms03 > RMSThresholdInternal_) )
381  val = 0.;
382  if ( meg03_[ism-1] ) meg03_[ism-1]->setBinContent(ix, iy, val);
383 
384  if ( mep03_[ism-1] ) mep03_[ism-1]->Fill(mean03);
385  if ( mer03_[ism-1] ) mer03_[ism-1]->Fill(rms03);
386 
387  }
388 
389  if ( Masks::maskChannel(ism, ix, iy, bits03, EcalEndcap) ) UtilsClient::maskBinContent( meg03_[ism-1], ix, iy );
390 
391  }
392  }
393 
394  }
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:223
int i
Definition: DBlmapReader.cc:9
static bool validEE(const unsigned ism, const unsigned ix, const unsigned iy)
Definition: Numbers.cc:829
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:57
static unsigned icEE(const unsigned ism, const unsigned ix, const unsigned iy)
Definition: Numbers.cc:736
MonitorElement * book1D(const char *name, const char *title, int nchX, double lowX, double highX)
Book 1D histogram.
Definition: DQMStore.cc:872
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.
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
MonitorElement * meg03_[18]
void beginRun(void)
BeginRun.
static int ix0EE(const unsigned ism)
Definition: Numbers.cc:770
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:809
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:2772
channel masking
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
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 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: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
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:1000
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 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:584
virtual ~EEPedestalOnlineClient()
Destructor.