CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
EBTimingClient.cc
Go to the documentation of this file.
1 /*
2  * \file EBTimingClient.cc
3  *
4  * $Date: 2012/04/27 13:45:59 $
5  * $Revision: 1.115 $
6  * \author G. Della Ricca
7  *
8 */
9 
10 #include <memory>
11 #include <iostream>
12 #include <fstream>
13 #include <iomanip>
14 #include <math.h>
15 
17 
20 
21 #ifdef WITH_ECAL_COND_DB
27 #endif
28 
30 
33 
35 
37 
38  // cloneME switch
39  cloneME_ = ps.getUntrackedParameter<bool>("cloneME", true);
40 
41  // verbose switch
42  verbose_ = ps.getUntrackedParameter<bool>("verbose", true);
43 
44  // debug switch
45  debug_ = ps.getUntrackedParameter<bool>("debug", false);
46 
47  // prefixME path
48  prefixME_ = ps.getUntrackedParameter<std::string>("prefixME", "");
49 
50  // enableCleanup_ switch
51  enableCleanup_ = ps.getUntrackedParameter<bool>("enableCleanup", false);
52 
53  // vector of selected Super Modules (Defaults to all 36).
54  superModules_.reserve(36);
55  for ( unsigned int i = 1; i <= 36; i++ ) superModules_.push_back(i);
56  superModules_ = ps.getUntrackedParameter<std::vector<int> >("superModules", superModules_);
57 
58  for ( unsigned int i=0; i<superModules_.size(); i++ ) {
59 
60  int ism = superModules_[i];
61 
62  h01_[ism-1] = 0;
63  h02_[ism-1] = 0;
64 
65  meh01_[ism-1] = 0;
66  meh02_[ism-1] = 0;
67 
68  }
69 
70  for ( unsigned int i=0; i<superModules_.size(); i++ ) {
71 
72  int ism = superModules_[i];
73 
74  meg01_[ism-1] = 0;
75 
76  mea01_[ism-1] = 0;
77 
78  mep01_[ism-1] = 0;
79 
80  mer01_[ism-1] = 0;
81 
82  }
83 
86 
87  expectedMean_ = 0.0;
88  discrepancyMean_ = 2.0;
89  RMSThreshold_ = 6.0;
90 
91  nHitThreshold_ = ps.getUntrackedParameter<int>("timingNHitThrehold", 5);
92 
93  ievt_ = 0;
94  jevt_ = 0;
95  dqmStore_ = 0;
96 }
97 
99 
100 }
101 
103 
105 
106  if ( debug_ ) std::cout << "EBTimingClient: beginJob" << std::endl;
107 
108  ievt_ = 0;
109  jevt_ = 0;
110 
111 }
112 
114 
115  if ( debug_ ) std::cout << "EBTimingClient: beginRun" << std::endl;
116 
117  jevt_ = 0;
118 
119  this->setup();
120 
121 }
122 
124 
125  if ( debug_ ) std::cout << "EBTimingClient: endJob, ievt = " << ievt_ << std::endl;
126 
127  this->cleanup();
128 
129 }
130 
132 
133  if ( debug_ ) std::cout << "EBTimingClient: endRun, jevt = " << jevt_ << std::endl;
134 
135  this->cleanup();
136 
137 }
138 
140 
141  std::string name;
142 
143  dqmStore_->setCurrentFolder( prefixME_ + "/EBTimingClient" );
144 
145  for ( unsigned int i=0; i<superModules_.size(); i++ ) {
146 
147  int ism = superModules_[i];
148 
149  if ( meg01_[ism-1] ) dqmStore_->removeElement( meg01_[ism-1]->getName() );
150  name = "EBTMT timing quality " + Numbers::sEB(ism);
151  meg01_[ism-1] = dqmStore_->book2D(name, name, 85, 0., 85., 20, 0., 20.);
152  meg01_[ism-1]->setAxisTitle("ieta", 1);
153  meg01_[ism-1]->setAxisTitle("iphi", 2);
154 
155  if ( mea01_[ism-1] ) dqmStore_->removeElement( mea01_[ism-1]->getName() );
156  name = "EBTMT timing " + Numbers::sEB(ism);
157  mea01_[ism-1] = dqmStore_->book1D(name, name, 1700, 0., 1700.);
158  mea01_[ism-1]->setAxisTitle("channel", 1);
159  mea01_[ism-1]->setAxisTitle("time (ns)", 2);
160 
161  if ( mep01_[ism-1] ) dqmStore_->removeElement( mep01_[ism-1]->getName() );
162  name = "EBTMT timing mean " + Numbers::sEB(ism);
163  mep01_[ism-1] = dqmStore_->book1D(name, name, 100, -25.0, 25.0);
164  mep01_[ism-1]->setAxisTitle("mean (ns)", 1);
165 
166  if ( mer01_[ism-1] ) dqmStore_->removeElement( mer01_[ism-1]->getName() );
167  name = "EBTMT timing rms " + Numbers::sEB(ism);
168  mer01_[ism-1] = dqmStore_->book1D(name, name, 100, 0.0, 10.0);
169  mer01_[ism-1]->setAxisTitle("rms (ns)", 1);
170 
171  }
172 
173  name = "EBTMT timing projection eta";
174  meTimeSummaryMapProjEta_ = dqmStore_->bookProfile(name, name, 34, -85., 85., -20., 20., "");
176  meTimeSummaryMapProjEta_->setAxisTitle("time (ns)", 2);
177 
178  name = "EBTMT timing projection phi";
179  meTimeSummaryMapProjPhi_ = dqmStore_->bookProfile(name, name, 72, 0., 360., -20., 20., "");
181  meTimeSummaryMapProjPhi_->setAxisTitle("time (ns)", 2);
182 
183  for ( unsigned int i=0; i<superModules_.size(); i++ ) {
184 
185  int ism = superModules_[i];
186 
187  if ( meg01_[ism-1] ) meg01_[ism-1]->Reset();
188 
189  for ( int ie = 1; ie <= 85; ie++ ) {
190  for ( int ip = 1; ip <= 20; ip++ ) {
191 
192  if ( meg01_[ism-1] ) meg01_[ism-1]->setBinContent( ie, ip, 2. );
193 
194  }
195  }
196 
197  if ( mea01_[ism-1] ) mea01_[ism-1]->Reset();
198  if ( mep01_[ism-1] ) mep01_[ism-1]->Reset();
199  if ( mer01_[ism-1] ) mer01_[ism-1]->Reset();
200 
201  }
202 
203 
204 
205 }
206 
208 
209  if ( ! enableCleanup_ ) return;
210 
211  for ( unsigned int i=0; i<superModules_.size(); i++ ) {
212 
213  int ism = superModules_[i];
214 
215  if ( cloneME_ ) {
216  if ( h01_[ism-1] ) delete h01_[ism-1];
217  if ( h02_[ism-1] ) delete h02_[ism-1];
218  }
219 
220  h01_[ism-1] = 0;
221  h02_[ism-1] = 0;
222 
223  meh01_[ism-1] = 0;
224  meh02_[ism-1] = 0;
225 
226  }
227 
228  dqmStore_->setCurrentFolder( prefixME_ + "/EBTimingClient" );
229 
230  for ( unsigned int i=0; i<superModules_.size(); i++ ) {
231 
232  int ism = superModules_[i];
233 
234  if ( meg01_[ism-1] ) dqmStore_->removeElement( meg01_[ism-1]->getName() );
235  meg01_[ism-1] = 0;
236 
237  if ( mea01_[ism-1] ) dqmStore_->removeElement( mea01_[ism-1]->getName() );
238  mea01_[ism-1] = 0;
239 
240  if ( mep01_[ism-1] ) dqmStore_->removeElement( mep01_[ism-1]->getName() );
241  mep01_[ism-1] = 0;
242 
243  if ( mer01_[ism-1] ) dqmStore_->removeElement( mer01_[ism-1]->getName() );
244  mer01_[ism-1] = 0;
245 
246  }
247 
250 
251 }
252 
253 #ifdef WITH_ECAL_COND_DB
254 bool EBTimingClient::writeDb(EcalCondDBInterface* econn, RunIOV* runiov, MonRunIOV* moniov, bool& status) {
255 
256  status = true;
257 
258  EcalLogicID ecid;
259 
261  std::map<EcalLogicID, MonTimingCrystalDat> dataset;
262 
263  for ( unsigned int i=0; i<superModules_.size(); i++ ) {
264 
265  int ism = superModules_[i];
266 
267  if ( verbose_ ) {
268  std::cout << " " << Numbers::sEB(ism) << " (ism=" << ism << ")" << std::endl;
269  std::cout << std::endl;
270  UtilsClient::printBadChannels(meg01_[ism-1], h01_[ism-1]);
271  }
272 
273  float num01;
274  float mean01;
275  float rms01;
276 
277  for ( int ie = 1; ie <= 85; ie++ ) {
278  for ( int ip = 1; ip <= 20; ip++ ) {
279 
280  bool update01;
281 
282  update01 = UtilsClient::getBinStatistics(h01_[ism-1], ie, ip, num01, mean01, rms01, nHitThreshold_);
283  // Task timing map is shifted of +50 ns for graphical reasons. Shift back it.
284  mean01 -= 50.;
285 
286  if ( update01 ) {
287 
288  if ( Numbers::icEB(ism, ie, ip) == 1 ) {
289 
290  if ( verbose_ ) {
291  std::cout << "Preparing dataset for " << Numbers::sEB(ism) << " (ism=" << ism << ")" << std::endl;
292  std::cout << "crystal (" << ie << "," << ip << ") " << num01 << " " << mean01 << " " << rms01 << std::endl;
293  std::cout << std::endl;
294  }
295 
296  }
297 
298  t.setTimingMean(mean01);
299  t.setTimingRMS(rms01);
300 
301  if ( UtilsClient::getBinStatus(meg01_[ism-1], ie, ip) ) {
302  t.setTaskStatus(true);
303  } else {
304  t.setTaskStatus(false);
305  }
306 
307  status = status && UtilsClient::getBinQuality(meg01_[ism-1], ie, ip);
308 
309  int ic = Numbers::indexEB(ism, ie, ip);
310 
311  if ( econn ) {
312  ecid = LogicID::getEcalLogicID("EB_crystal_number", Numbers::iSM(ism, EcalBarrel), ic);
313  dataset[ecid] = t;
314  }
315 
316  }
317 
318  }
319  }
320 
321  }
322 
323  if ( econn ) {
324  try {
325  if ( verbose_ ) std::cout << "Inserting MonTimingCrystalDat ..." << std::endl;
326  if ( dataset.size() != 0 ) econn->insertDataArraySet(&dataset, moniov);
327  if ( verbose_ ) std::cout << "done." << std::endl;
328  } catch (std::runtime_error &e) {
329  std::cerr << e.what() << std::endl;
330  }
331  }
332 
333  return true;
334 
335 }
336 #endif
337 
339 
340  ievt_++;
341  jevt_++;
342  if ( ievt_ % 10 == 0 ) {
343  if ( debug_ ) std::cout << "EBTimingClient: ievt/jevt = " << ievt_ << "/" << jevt_ << std::endl;
344  }
345 
346  uint32_t bits01 = 0;
348 
349  MonitorElement* me;
350 
353 
354  for ( unsigned int i=0; i<superModules_.size(); i++ ) {
355 
356  int ism = superModules_[i];
357 
358  me = dqmStore_->get( prefixME_ + "/EBTimingTask/EBTMT timing " + Numbers::sEB(ism) );
359  h01_[ism-1] = UtilsClient::getHisto<TProfile2D*>( me, cloneME_, h01_[ism-1] );
360  meh01_[ism-1] = me;
361 
362  me = dqmStore_->get( prefixME_ + "/EBTimingTask/EBTMT timing vs amplitude " + Numbers::sEB(ism) );
363  h02_[ism-1] = UtilsClient::getHisto<TH2F*>( me, cloneME_, h02_[ism-1] );
364  meh02_[ism-1] = me;
365 
366  if ( meg01_[ism-1] ) meg01_[ism-1]->Reset();
367  if ( mea01_[ism-1] ) mea01_[ism-1]->Reset();
368  if ( mep01_[ism-1] ) mep01_[ism-1]->Reset();
369  if ( mer01_[ism-1] ) mer01_[ism-1]->Reset();
370 
371  for ( int ie = 1; ie <= 85; ie++ ) {
372  for ( int ip = 1; ip <= 20; ip++ ) {
373 
374  if ( meg01_[ism-1] ) meg01_[ism-1]->setBinContent(ie, ip, 2.);
375 
376  bool update01;
377 
378  float num01;
379  float mean01;
380  float rms01;
381 
382  update01 = UtilsClient::getBinStatistics(h01_[ism-1], ie, ip, num01, mean01, rms01, nHitThreshold_);
383  // Task timing map is shifted of +50 ns for graphical reasons. Shift back it.
384  mean01 -= 50.;
385 
386  if ( update01 ) {
387 
388  float val;
389 
390  val = 1.;
391  if ( std::abs(mean01 - expectedMean_) > discrepancyMean_ )
392  val = 0.;
393  if ( rms01 > RMSThreshold_ )
394  val = 0.;
395  if ( meg01_[ism-1] ) meg01_[ism-1]->setBinContent(ie, ip, val);
396 
397  int ic = Numbers::icEB(ism, ie, ip);
398 
399  if ( mea01_[ism-1] ) {
400  mea01_[ism-1]->setBinContent(ic, mean01);
401  mea01_[ism-1]->setBinError(ic, rms01);
402  }
403  if ( mep01_[ism-1] ) mep01_[ism-1]->Fill(mean01);
404  if ( mer01_[ism-1] ) mer01_[ism-1]->Fill(rms01);
405 
406  float eta, phi;
407 
408  if ( ism <= 18 ) {
409  eta = -ie+0.5;
410  phi = ip+20*(ism-1)-0.5;
411  } else {
412  eta = ie-0.5;
413  phi = (20-ip)+20*(ism-19)+0.5;
414  }
415 
418 
419  }
420 
421  if ( Masks::maskChannel(ism, ie, ip, bits01, EcalBarrel) ) UtilsClient::maskBinContent( meg01_[ism-1], ie, ip );
422 
423 
424 
425  }
426  }
427 
428  }
429 
430 }
431 
Cache logicID vector from database.
T getUntrackedParameter(std::string const &, T const &) const
const std::string & getName(void) const
get name of ME
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
void analyze(void)
Analyze.
MonitorElement * mep01_[36]
static const int PHYSICS_BAD_CHANNEL_WARNING
MonitorElement * book1D(const char *name, const char *title, int nchX, double lowX, double highX)
Book 1D histogram.
Definition: DQMStore.cc:717
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
#define abs(x)
Definition: mlp_lapack.h:159
MonitorElement * mer01_[36]
T eta() const
void setTimingMean(float mean)
Definition: ITimingDat.h:45
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 endJob(void)
EndJob.
MonitorElement * meTimeSummaryMapProjPhi_
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
TProfile2D * h01_[36]
std::string prefixME_
MonitorElement * meh01_[36]
void beginRun(void)
BeginRun.
EBTimingClient(const edm::ParameterSet &ps)
Constructor.
MonitorElement * meh02_[36]
void removeElement(const std::string &name)
Definition: DQMStore.cc:2572
channel masking
DQMStore * dqmStore_
static unsigned indexEB(const unsigned ism, const unsigned ie, const unsigned ip)
Definition: Numbers.cc:698
void setBinError(int binx, double error)
set uncertainty on content of bin (1-D)
MonitorElement * bookProfile(const char *name, const char *title, int nchX, double lowX, double highX, int nchY, double lowY, double highY, const char *option="s")
Definition: DQMStore.cc:1031
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:1468
MonitorElement * meTimeSummaryMapProjEta_
Ecal Monitor Utils for Client.
TH2F * h02_[36]
void setTaskStatus(bool status)
Definition: ITimingDat.h:51
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
MonitorElement * meg01_[36]
void setTimingRMS(float rms)
Definition: ITimingDat.h:48
tuple dataset
Definition: dataset.py:393
virtual ~EBTimingClient()
Destructor.
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
MonitorElement * mea01_[36]
tuple status
Definition: ntuplemaker.py:245
void cleanup(void)
Cleanup.
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:845
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 endRun(void)
EndRun.
void setCurrentFolder(const std::string &fullpath)
Definition: DQMStore.cc:429
void beginJob(void)
BeginJob.
void setup(void)
Setup.
Definition: DDAxes.h:10