CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
EBPedestalOnlineClient.cc
Go to the documentation of this file.
1 /*
2  * \file EBPedestalOnlineClient.cc
3  *
4  * $Date: 2012/04/27 13:45:59 $
5  * $Revision: 1.167 $
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 
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 36).
57  superModules_.reserve(36);
58  for ( unsigned int i = 1; i <= 36; 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_ = 3.0;
85 
86 }
87 
89 
90 }
91 
93 
95 
96  if ( debug_ ) std::cout << "EBPedestalOnlineClient: beginJob" << std::endl;
97 
98  ievt_ = 0;
99  jevt_ = 0;
100 
101 }
102 
104 
105  if ( debug_ ) std::cout << "EBPedestalOnlineClient: beginRun" << std::endl;
106 
107  jevt_ = 0;
108 
109  this->setup();
110 
111 }
112 
114 
115  if ( debug_ ) std::cout << "EBPedestalOnlineClient: endJob, ievt = " << ievt_ << std::endl;
116 
117  this->cleanup();
118 
119 }
120 
122 
123  if ( debug_ ) std::cout << "EBPedestalOnlineClient: endRun, jevt = " << jevt_ << std::endl;
124 
125  this->cleanup();
126 
127 }
128 
130 
132 
133  dqmStore_->setCurrentFolder( prefixME_ + "/EBPedestalOnlineClient" );
134 
135  if(subfolder_.size())
136  dqmStore_->setCurrentFolder( prefixME_ + "/EBPedestalOnlineClient/" + 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 = "EBPOT pedestal quality G12 " + Numbers::sEB(ism);
144  meg03_[ism-1] = dqmStore_->book2D(name, name, 85, 0., 85., 20, 0., 20.);
145  meg03_[ism-1]->setAxisTitle("ieta", 1);
146  meg03_[ism-1]->setAxisTitle("iphi", 2);
147 
148  if ( mep03_[ism-1] ) dqmStore_->removeElement( mep03_[ism-1]->getName() );
149  name = "EBPOT pedestal mean G12 " + Numbers::sEB(ism);
150  mep03_[ism-1] = dqmStore_->book1D(name, name, 100, 150., 250.);
151  mep03_[ism-1]->setAxisTitle("mean", 1);
152 
153  if ( mer03_[ism-1] ) dqmStore_->removeElement( mer03_[ism-1]->getName() );
154  name = "EBPOT pedestal rms G12 " + Numbers::sEB(ism);
155  mer03_[ism-1] = dqmStore_->book1D(name, name, 100, 0., 10.);
156  mer03_[ism-1]->setAxisTitle("rms", 1);
157 
158  }
159 
160  for ( unsigned int i=0; i<superModules_.size(); i++ ) {
161 
162  int ism = superModules_[i];
163 
164  if ( meg03_[ism-1] ) meg03_[ism-1]->Reset();
165 
166  for ( int ie = 1; ie <= 85; ie++ ) {
167  for ( int ip = 1; ip <= 20; ip++ ) {
168 
169  meg03_[ism-1]->setBinContent( ie, ip, 2. );
170 
171  }
172  }
173 
174  if ( mep03_[ism-1] ) mep03_[ism-1]->Reset();
175  if ( mer03_[ism-1] ) mer03_[ism-1]->Reset();
176 
177  }
178 
179 }
180 
182 
183  if ( ! enableCleanup_ ) return;
184 
185  for ( unsigned int i=0; i<superModules_.size(); i++ ) {
186 
187  int ism = superModules_[i];
188 
189  if ( cloneME_ ) {
190  if ( h03_[ism-1] ) delete h03_[ism-1];
191  }
192 
193  h03_[ism-1] = 0;
194 
195  }
196 
197  dqmStore_->setCurrentFolder( prefixME_ + "/EBPedestalOnlineClient" );
198 
199  if(subfolder_.size())
200  dqmStore_->setCurrentFolder( prefixME_ + "/EBPedestalOnlineClient/" + subfolder_);
201 
202  for ( unsigned int i=0; i<superModules_.size(); i++ ) {
203 
204  int ism = superModules_[i];
205 
206  if ( meg03_[ism-1] ) dqmStore_->removeElement( meg03_[ism-1]->getName() );
207  meg03_[ism-1] = 0;
208 
209  if ( mep03_[ism-1] ) dqmStore_->removeElement( mep03_[ism-1]->getName() );
210  mep03_[ism-1] = 0;
211 
212  if ( mer03_[ism-1] ) dqmStore_->removeElement( mer03_[ism-1]->getName() );
213  mer03_[ism-1] = 0;
214 
215  }
216 
217 }
218 
219 #ifdef WITH_ECAL_COND_DB
220 bool EBPedestalOnlineClient::writeDb(EcalCondDBInterface* econn, RunIOV* runiov, MonRunIOV* moniov, bool& status) {
221 
222  status = true;
223 
224  EcalLogicID ecid;
225 
227  std::map<EcalLogicID, MonPedestalsOnlineDat> dataset;
228 
229  for ( unsigned int i=0; i<superModules_.size(); i++ ) {
230 
231  int ism = superModules_[i];
232 
233  if ( verbose_ ) {
234  std::cout << " " << Numbers::sEB(ism) << " (ism=" << ism << ")" << std::endl;
235  std::cout << std::endl;
236  UtilsClient::printBadChannels(meg03_[ism-1], h03_[ism-1]);
237  }
238 
239  float num03;
240  float mean03;
241  float rms03;
242 
243  for ( int ie = 1; ie <= 85; ie++ ) {
244  for ( int ip = 1; ip <= 20; ip++ ) {
245 
246  bool update03;
247 
248  update03 = UtilsClient::getBinStatistics(h03_[ism-1], ie, ip, num03, mean03, rms03);
249 
250  if ( update03 ) {
251 
252  if ( Numbers::icEB(ism, ie, ip) == 1 ) {
253 
254  if ( verbose_ ) {
255  std::cout << "Preparing dataset for " << Numbers::sEB(ism) << " (ism=" << ism << ")" << std::endl;
256  std::cout << "G12 (" << ie << "," << ip << ") " << num03 << " " << mean03 << " " << rms03 << std::endl;
257  std::cout << std::endl;
258  }
259 
260  }
261 
262  p.setADCMeanG12(mean03);
263  p.setADCRMSG12(rms03);
264 
265  if ( UtilsClient::getBinStatus(meg03_[ism-1], ie, ip) ) {
266  p.setTaskStatus(true);
267  } else {
268  p.setTaskStatus(false);
269  }
270 
271  status = status && UtilsClient::getBinQuality(meg03_[ism-1], ie, ip);
272 
273  int ic = Numbers::indexEB(ism, ie, ip);
274 
275  if ( econn ) {
276  ecid = LogicID::getEcalLogicID("EB_crystal_number", Numbers::iSM(ism, EcalBarrel), ic);
277  dataset[ecid] = p;
278  }
279 
280  }
281 
282  }
283  }
284 
285  }
286 
287  if ( econn ) {
288  try {
289  if ( verbose_ ) std::cout << "Inserting MonPedestalsOnlineDat ..." << std::endl;
290  if ( dataset.size() != 0 ) econn->insertDataArraySet(&dataset, moniov);
291  if ( verbose_ ) std::cout << "done." << std::endl;
292  } catch (std::runtime_error &e) {
293  std::cerr << e.what() << std::endl;
294  }
295  }
296 
297  return true;
298 
299 }
300 #endif
301 
303 
304  ievt_++;
305  jevt_++;
306  if ( ievt_ % 10 == 0 ) {
307  if ( debug_ ) std::cout << "EBPedestalOnlineClient: ievt/jevt = " << ievt_ << "/" << jevt_ << std::endl;
308  }
309 
310  uint32_t bits03 = 0;
313 
314  std::string subdir(subfolder_.size() ? subfolder_ + "/" : "");
315 
316  MonitorElement* me;
317 
318  for ( unsigned int i=0; i<superModules_.size(); i++ ) {
319 
320  int ism = superModules_[i];
321 
322  me = dqmStore_->get( prefixME_ + "/EBPedestalOnlineTask/" + subdir + "Gain12/EBPOT pedestal " + Numbers::sEB(ism) + " G12" );
323  h03_[ism-1] = UtilsClient::getHisto<TProfile2D*>( me, cloneME_, h03_[ism-1] );
324  if ( meg03_[ism-1] ) meg03_[ism-1]->Reset();
325  if ( mep03_[ism-1] ) mep03_[ism-1]->Reset();
326  if ( mer03_[ism-1] ) mer03_[ism-1]->Reset();
327 
328  for ( int ie = 1; ie <= 85; ie++ ) {
329  for ( int ip = 1; ip <= 20; ip++ ) {
330 
331  if ( meg03_[ism-1] ) meg03_[ism-1]->setBinContent(ie, ip, 2.);
332 
333  bool update03;
334 
335  float num03;
336  float mean03;
337  float rms03;
338 
339  update03 = UtilsClient::getBinStatistics(h03_[ism-1], ie, ip, num03, mean03, rms03);
340 
341  if ( update03 ) {
342 
343  float val;
344 
345  val = 1.;
346  if ( std::abs(mean03 - expectedMean_) > discrepancyMean_ )
347  val = 0.;
348  if ( (ie<=40 && rms03 > RMSThreshold_) || (ie>40 && rms03 > RMSThresholdHighEta_) )
349  val = 0.;
350  if ( meg03_[ism-1] ) meg03_[ism-1]->setBinContent(ie, ip, val);
351 
352  if ( mep03_[ism-1] ) mep03_[ism-1]->Fill(mean03);
353  if ( mer03_[ism-1] ) mer03_[ism-1]->Fill(rms03);
354 
355  }
356 
357  if ( Masks::maskChannel(ism, ie, ip, bits03, EcalBarrel) ) UtilsClient::maskBinContent( meg03_[ism-1], ie, ip );
358 
359  }
360  }
361 
362  }
363 
364 }
365 
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)
static bool maskChannel(int ism, int i1, int i2, uint32_t bits, const EcalSubdetector subdet)
Definition: Masks.cc:60
EBPedestalOnlineClient(const edm::ParameterSet &ps)
Constructor.
MonitorElement * mer03_[36]
MonitorElement * book1D(const char *name, const char *title, int nchX, double lowX, double highX)
Book 1D histogram.
Definition: DQMStore.cc:722
Some &quot;id&quot; conversions.
static std::string sEB(const unsigned ism)
Definition: Numbers.cc:94
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
static const int PEDESTAL_ONLINE_HIGH_GAIN_RMS_ERROR
#define abs(x)
Definition: mlp_lapack.h:159
static unsigned icEB(const unsigned ism, const unsigned ix, const unsigned iy)
Definition: Numbers.cc:729
static void maskBinContent(const MonitorElement *me, const int ix, const int iy)
Mask the bin content.
Definition: UtilsClient.cc:231
std::vector< int > superModules_
void beginRun(void)
BeginRun.
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
virtual ~EBPedestalOnlineClient()
Destructor.
void setTaskStatus(bool status)
void removeElement(const std::string &name)
Definition: DQMStore.cc:2577
channel masking
static unsigned indexEB(const unsigned ism, const unsigned ie, const unsigned ip)
Definition: Numbers.cc:698
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)
void beginJob(void)
BeginJob.
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
MonitorElement * meg03_[36]
MonitorElement * mep03_[36]
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