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: 2011/08/30 09:29:45 $
5  * $Revision: 1.113 $
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  // 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 
131  std::string name;
132 
133  dqmStore_->setCurrentFolder( prefixME_ + "/EEPedestalOnlineClient" );
134 
135  for ( unsigned int i=0; i<superModules_.size(); i++ ) {
136 
137  int ism = superModules_[i];
138 
139  if ( meg03_[ism-1] ) dqmStore_->removeElement( meg03_[ism-1]->getName() );
140  name = "EEPOT pedestal quality G12 " + Numbers::sEE(ism);
141  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.);
142  meg03_[ism-1]->setAxisTitle("ix", 1);
143  if ( ism >= 1 && ism <= 9 ) meg03_[ism-1]->setAxisTitle("101-ix", 1);
144  meg03_[ism-1]->setAxisTitle("iy", 2);
145 
146  if ( mep03_[ism-1] ) dqmStore_->removeElement( mep03_[ism-1]->getName() );
147  name = "EEPOT pedestal mean G12 " + Numbers::sEE(ism);
148  mep03_[ism-1] = dqmStore_->book1D(name, name, 100, 150., 250.);
149  mep03_[ism-1]->setAxisTitle("mean", 1);
150 
151  if ( mer03_[ism-1] ) dqmStore_->removeElement( mer03_[ism-1]->getName() );
152  name = "EEPOT pedestal rms G12 " + Numbers::sEE(ism);
153  mer03_[ism-1] = dqmStore_->book1D(name, name, 100, 0., 10.);
154  mer03_[ism-1]->setAxisTitle("rms", 1);
155 
156  }
157 
158  for ( unsigned int i=0; i<superModules_.size(); i++ ) {
159 
160  int ism = superModules_[i];
161 
162  if ( meg03_[ism-1] ) meg03_[ism-1]->Reset();
163 
164  for ( int ix = 1; ix <= 50; ix++ ) {
165  for ( int iy = 1; iy <= 50; iy++ ) {
166 
167  meg03_[ism-1]->setBinContent( ix, iy, 6. );
168 
169  int jx = ix + Numbers::ix0EE(ism);
170  int jy = iy + Numbers::iy0EE(ism);
171 
172  if ( ism >= 1 && ism <= 9 ) jx = 101 - jx;
173 
174  if ( Numbers::validEE(ism, jx, jy) ) {
175  meg03_[ism-1]->setBinContent( ix, iy, 2. );
176  }
177 
178  }
179  }
180 
181  if ( mep03_[ism-1] ) mep03_[ism-1]->Reset();
182  if ( mer03_[ism-1] ) mer03_[ism-1]->Reset();
183 
184  }
185 
186 }
187 
189 
190  if ( ! enableCleanup_ ) return;
191 
192  for ( unsigned int i=0; i<superModules_.size(); i++ ) {
193 
194  int ism = superModules_[i];
195 
196  if ( cloneME_ ) {
197  if ( h03_[ism-1] ) delete h03_[ism-1];
198  }
199 
200  h03_[ism-1] = 0;
201 
202  }
203 
204  dqmStore_->setCurrentFolder( prefixME_ + "/EEPedestalOnlineClient" );
205 
206  for ( unsigned int i=0; i<superModules_.size(); i++ ) {
207 
208  int ism = superModules_[i];
209 
210  if ( meg03_[ism-1] ) dqmStore_->removeElement( meg03_[ism-1]->getName() );
211  meg03_[ism-1] = 0;
212 
213  if ( mep03_[ism-1] ) dqmStore_->removeElement( mep03_[ism-1]->getName() );
214  mep03_[ism-1] = 0;
215 
216  if ( mer03_[ism-1] ) dqmStore_->removeElement( mer03_[ism-1]->getName() );
217  mer03_[ism-1] = 0;
218 
219  }
220 
221 }
222 
223 #ifdef WITH_ECAL_COND_DB
224 bool EEPedestalOnlineClient::writeDb(EcalCondDBInterface* econn, RunIOV* runiov, MonRunIOV* moniov, bool& status) {
225 
226  status = true;
227 
228  EcalLogicID ecid;
229 
231  std::map<EcalLogicID, MonPedestalsOnlineDat> dataset;
232 
233  for ( unsigned int i=0; i<superModules_.size(); i++ ) {
234 
235  int ism = superModules_[i];
236 
237  if ( verbose_ ) {
238  std::cout << " " << Numbers::sEE(ism) << " (ism=" << ism << ")" << std::endl;
239  std::cout << std::endl;
240  UtilsClient::printBadChannels(meg03_[ism-1], h03_[ism-1]);
241  }
242 
243  float num03;
244  float mean03;
245  float rms03;
246 
247  for ( int ix = 1; ix <= 50; ix++ ) {
248  for ( int iy = 1; iy <= 50; iy++ ) {
249 
250  int jx = ix + Numbers::ix0EE(ism);
251  int jy = iy + Numbers::iy0EE(ism);
252 
253  if ( ism >= 1 && ism <= 9 ) jx = 101 - jx;
254 
255  if ( ! Numbers::validEE(ism, jx, jy) ) continue;
256 
257  bool update03;
258 
259  update03 = UtilsClient::getBinStatistics(h03_[ism-1], ix, iy, num03, mean03, rms03);
260 
261  if ( update03 ) {
262 
263  if ( Numbers::icEE(ism, jx, jy) == 1 ) {
264 
265  if ( verbose_ ) {
266  std::cout << "Preparing dataset for " << Numbers::sEE(ism) << " (ism=" << ism << ")" << std::endl;
267  std::cout << "G12 (" << Numbers::ix0EE(i+1)+ix << "," << Numbers::iy0EE(i+1)+iy << ") " << num03 << " " << mean03 << " " << rms03 << std::endl;
268  std::cout << std::endl;
269  }
270 
271  }
272 
273  p.setADCMeanG12(mean03);
274  p.setADCRMSG12(rms03);
275 
276  if ( UtilsClient::getBinStatus(meg03_[ism-1], ix, iy) ) {
277  p.setTaskStatus(true);
278  } else {
279  p.setTaskStatus(false);
280  }
281 
282  status = status && UtilsClient::getBinQuality(meg03_[ism-1], ix, iy);
283 
284  int ic = Numbers::indexEE(ism, jx, jy);
285 
286  if ( ic == -1 ) continue;
287 
288  if ( econn ) {
289  ecid = LogicID::getEcalLogicID("EE_crystal_number", Numbers::iSM(ism, EcalEndcap), ic);
290  dataset[ecid] = p;
291  }
292 
293  }
294 
295  }
296  }
297 
298  }
299 
300  if ( econn ) {
301  try {
302  if ( verbose_ ) std::cout << "Inserting MonPedestalsOnlineDat ..." << std::endl;
303  if ( dataset.size() != 0 ) econn->insertDataArraySet(&dataset, moniov);
304  if ( verbose_ ) std::cout << "done." << std::endl;
305  } catch (std::runtime_error &e) {
306  std::cerr << e.what() << std::endl;
307  }
308  }
309 
310  return true;
311 
312 }
313 #endif
314 
316 
317  ievt_++;
318  jevt_++;
319  if ( ievt_ % 10 == 0 ) {
320  if ( debug_ ) std::cout << "EEPedestalOnlineClient: ievt/jevt = " << ievt_ << "/" << jevt_ << std::endl;
321  }
322 
323  uint32_t bits03 = 0;
326 
327  MonitorElement* me;
328 
329  for ( unsigned int i=0; i<superModules_.size(); i++ ) {
330 
331  int ism = superModules_[i];
332 
333  me = dqmStore_->get( prefixME_ + "/EEPedestalOnlineTask/Gain12/EEPOT pedestal " + Numbers::sEE(ism) + " G12" );
334  h03_[ism-1] = UtilsClient::getHisto( me, cloneME_, h03_[ism-1] );
335 
336  if ( meg03_[ism-1] ) meg03_[ism-1]->Reset();
337  if ( mep03_[ism-1] ) mep03_[ism-1]->Reset();
338  if ( mer03_[ism-1] ) mer03_[ism-1]->Reset();
339 
340  for ( int ix = 1; ix <= 50; ix++ ) {
341  for ( int iy = 1; iy <= 50; iy++ ) {
342 
343  if ( meg03_[ism-1] ) meg03_[ism-1]->setBinContent(ix, iy, 6.);
344 
345  int jx = ix + Numbers::ix0EE(ism);
346  int jy = iy + Numbers::iy0EE(ism);
347 
348  if ( ism >= 1 && ism <= 9 ) jx = 101 - jx;
349 
350  if ( Numbers::validEE(ism, jx, jy) ) {
351  if ( meg03_[ism-1] ) meg03_[ism-1]->setBinContent( ix, iy, 2. );
352  }
353 
354  // OOT pileup affects the region near beam pipe mostly. Use higher threshold for these crystals
355  float radius = std::sqrt((jx-50.)*(jx-50.)+(jy-50.)*(jy-50.));
356 
357  bool update03;
358 
359  float num03;
360  float mean03;
361  float rms03;
362 
363  update03 = UtilsClient::getBinStatistics(h03_[ism-1], ix, iy, num03, mean03, rms03);
364 
365  if ( update03 ) {
366 
367  float val;
368 
369  val = 1.;
370  if ( std::abs(mean03 - expectedMean_) > discrepancyMean_ )
371  val = 0.;
372  if ( (radius >= 20. && rms03 > RMSThreshold_) || (radius < 20. && rms03 > RMSThresholdInternal_) )
373  val = 0.;
374  if ( meg03_[ism-1] ) meg03_[ism-1]->setBinContent(ix, iy, val);
375 
376  if ( mep03_[ism-1] ) mep03_[ism-1]->Fill(mean03);
377  if ( mer03_[ism-1] ) mer03_[ism-1]->Fill(rms03);
378 
379  }
380 
381  if ( Masks::maskChannel(ism, ix, iy, bits03, EcalEndcap) ) UtilsClient::maskBinContent( meg03_[ism-1], ix, iy );
382 
383  }
384  }
385 
386  }
387 
388 }
389 
Cache logicID vector from database.
T getUntrackedParameter(std::string const &, T const &) const
int i
Definition: DBlmapReader.cc:9
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
MonitorElement * book1D(const char *name, const char *title, int nchX, double lowX, double highX)
Book 1D histogram.
Definition: DQMStore.cc:514
static int iy0EE(const int ism)
Definition: Numbers.cc:987
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 std::string sEE(const int ism)
Definition: Numbers.cc:205
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 void maskBinContent(const MonitorElement *me, const int ix, const int iy)
Mask the bin content.
Definition: UtilsClient.cc:231
static int indexEE(const int ism, const int ix, const int iy)
Definition: Numbers.cc:877
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
static int iSM(const int ism, const EcalSubdetector subdet)
Definition: Numbers.cc:222
MonitorElement * mep03_[18]
static int icEE(const int ism, const int ix, const int iy)
Definition: Numbers.cc:906
void setTaskStatus(bool status)
T sqrt(T t)
Definition: SSEVec.h:28
void removeElement(const std::string &name)
Definition: DQMStore.cc:2353
channel masking
std::string getName(Reflex::Type &cc)
Definition: ClassFiller.cc:18
MonitorElement * get(const std::string &path) const
get ME from full pathname (e.g. &quot;my/long/dir/my_histo&quot;)
Definition: DQMStore.cc:1265
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
static const int PEDESTAL_ONLINE_HIGH_GAIN_MEAN_ERROR
EEPedestalOnlineClient(const edm::ParameterSet &ps)
Constructor.
static int ix0EE(const int ism)
Definition: Numbers.cc:952
void insertDataArraySet(const std::map< EcalLogicID, DATT > *data, IOVT *iov)
tuple cout
Definition: gather_cfg.py:41
tuple status
Definition: ntuplemaker.py:245
static bool validEE(const int ism, const int ix, const int iy)
Definition: Numbers.cc:1005
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:642
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:232
virtual ~EEPedestalOnlineClient()
Destructor.