CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
EETimingClient.cc
Go to the documentation of this file.
1 /*
2  * \file EETimingClient.cc
3  *
4  * \author G. Della Ricca
5  *
6 */
7 
8 #include <memory>
9 #include <iostream>
10 #include <fstream>
11 #include <iomanip>
12 #include <math.h>
13 
15 
18 
19 #ifdef WITH_ECAL_COND_DB
25 #endif
26 
28 
31 
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 18).
54  superModules_.reserve(18);
55  for ( unsigned int i = 1; i <= 18; i++ ) superModules_.push_back(i);
56  superModules_ = ps.getUntrackedParameter<std::vector<int> >("superModules", superModules_);
57 
58  nHitThreshold_ = ps.getUntrackedParameter<int>("timingNHitThreshold", 5);
59 
60  for ( unsigned int i=0; i<superModules_.size(); i++ ) {
61 
62  int ism = superModules_[i];
63 
64  h01_[ism-1] = 0;
65  h02_[ism-1] = 0;
66 
67  meh01_[ism-1] = 0;
68  meh02_[ism-1] = 0;
69 
70  }
71 
72  for ( unsigned int i=0; i<superModules_.size(); i++ ) {
73 
74  int ism = superModules_[i];
75 
76  meg01_[ism-1] = 0;
77 
78  mea01_[ism-1] = 0;
79 
80  mep01_[ism-1] = 0;
81 
82  mer01_[ism-1] = 0;
83 
84  }
85 
90 
91  expectedMean_ = 0.;
92  meanThreshold_ = 3.;
93  rmsThreshold_ = 6.;
94 }
95 
97 
98 }
99 
101 
103 
104  if ( debug_ ) std::cout << "EETimingClient: beginJob" << std::endl;
105 
106  ievt_ = 0;
107  jevt_ = 0;
108 
109 }
110 
112 
113  if ( debug_ ) std::cout << "EETimingClient: beginRun" << std::endl;
114 
115  jevt_ = 0;
116 
117  this->setup();
118 
119 }
120 
122 
123  if ( debug_ ) std::cout << "EETimingClient: endJob, ievt = " << ievt_ << std::endl;
124 
125  this->cleanup();
126 
127 }
128 
130 
131  if ( debug_ ) std::cout << "EETimingClient: endRun, jevt = " << jevt_ << std::endl;
132 
133  this->cleanup();
134 
135 }
136 
138 
140 
141  dqmStore_->setCurrentFolder( prefixME_ + "/EETimingClient" );
142 
143  for ( unsigned int i=0; i<superModules_.size(); i++ ) {
144 
145  int ism = superModules_[i];
146 
147  if ( meg01_[ism-1] ) dqmStore_->removeElement( meg01_[ism-1]->getName() );
148  name = "EETMT timing quality " + Numbers::sEE(ism);
149  meg01_[ism-1] = dqmStore_->book2D(name, name, 50, Numbers::ix0EE(ism)+0., Numbers::ix0EE(ism)+50., 50, Numbers::iy0EE(ism)+0., Numbers::iy0EE(ism)+50.);
150  meg01_[ism-1]->setAxisTitle("ix", 1);
151  if ( ism >= 1 && ism <= 9 ) meg01_[ism-1]->setAxisTitle("101-ix", 1);
152  meg01_[ism-1]->setAxisTitle("iy", 2);
153 
154  if ( mea01_[ism-1] ) dqmStore_->removeElement( mea01_[ism-1]->getName() );
155  name = "EETMT timing " + Numbers::sEE(ism);
156  mea01_[ism-1] = dqmStore_->book1D(name, name, 850, 0., 850.);
157  mea01_[ism-1]->setAxisTitle("channel", 1);
158  mea01_[ism-1]->setAxisTitle("time (ns)", 2);
159 
160  if ( mep01_[ism-1] ) dqmStore_->removeElement( mep01_[ism-1]->getName() );
161  name = "EETMT timing mean " + Numbers::sEE(ism);
162  mep01_[ism-1] = dqmStore_->book1D(name, name, 100, -25., 25.);
163  mep01_[ism-1]->setAxisTitle("mean (ns)", 1);
164 
165  if ( mer01_[ism-1] ) dqmStore_->removeElement( mer01_[ism-1]->getName() );
166  name = "EETMT timing rms " + Numbers::sEE(ism);
167  mer01_[ism-1] = dqmStore_->book1D(name, name, 100, 0.0, 10.);
168  mer01_[ism-1]->setAxisTitle("rms (ns)", 1);
169 
170  }
171 
172  name = "EETMT timing projection eta EE -";
173  meTimeSummaryMapProjEta_[0] = dqmStore_->bookProfile(name, name, 20, -3.0, -1.479, -20., 20.,"");
175  meTimeSummaryMapProjEta_[0]->setAxisTitle("time (ns)", 2);
176 
177  name = "EETMT timing projection eta EE +";
178  meTimeSummaryMapProjEta_[1] = dqmStore_->bookProfile(name, name, 20, 1.479, 3.0, -20., 20.,"");
180  meTimeSummaryMapProjEta_[1]->setAxisTitle("time (ns)", 2);
181 
182  name = "EETMT timing projection phi EE -";
183  meTimeSummaryMapProjPhi_[0] = dqmStore_->bookProfile(name, name, 50, -M_PI, M_PI, -20., 20.,"");
185  meTimeSummaryMapProjPhi_[0]->setAxisTitle("time (ns)", 2);
186 
187  name = "EETMT timing projection phi EE +";
188  meTimeSummaryMapProjPhi_[1] = dqmStore_->bookProfile(name, name, 50, -M_PI, M_PI, -20., 20.,"");
190  meTimeSummaryMapProjPhi_[1]->setAxisTitle("time (ns)", 2);
191 
192  for ( unsigned int i=0; i<superModules_.size(); i++ ) {
193 
194  int ism = superModules_[i];
195 
196  if ( meg01_[ism-1] ) meg01_[ism-1]->Reset();
197 
198  for ( int ix = 1; ix <= 50; ix++ ) {
199  for ( int iy = 1; iy <= 50; iy++ ) {
200 
201  if ( meg01_[ism-1] ) meg01_[ism-1]->setBinContent( ix, iy, 6. );
202 
203  int jx = ix + Numbers::ix0EE(ism);
204  int jy = iy + Numbers::iy0EE(ism);
205 
206  if ( ism >= 1 && ism <= 9 ) jx = 101 - jx;
207 
208  if ( Numbers::validEE(ism, jx, jy) ) {
209  if ( meg01_[ism-1] ) meg01_[ism-1]->setBinContent( ix, iy, 2. );
210  }
211 
212  }
213  }
214 
215  if ( mea01_[ism-1] ) mea01_[ism-1]->Reset();
216  if ( mep01_[ism-1] ) mep01_[ism-1]->Reset();
217  if ( mer01_[ism-1] ) mer01_[ism-1]->Reset();
218 
219  }
220 
221 }
222 
224 
225  if ( ! enableCleanup_ ) return;
226 
227  for ( unsigned int i=0; i<superModules_.size(); i++ ) {
228 
229  int ism = superModules_[i];
230 
231  if ( cloneME_ ) {
232  if ( h01_[ism-1] ) delete h01_[ism-1];
233  if ( h02_[ism-1] ) delete h02_[ism-1];
234  }
235 
236  h01_[ism-1] = 0;
237  h02_[ism-1] = 0;
238 
239  meh01_[ism-1] = 0;
240  meh02_[ism-1] = 0;
241 
242  }
243 
244  dqmStore_->setCurrentFolder( prefixME_ + "/EETimingClient" );
245 
246  for ( unsigned int i=0; i<superModules_.size(); i++ ) {
247 
248  int ism = superModules_[i];
249 
250  if ( meg01_[ism-1] ) dqmStore_->removeElement( meg01_[ism-1]->getName() );
251  meg01_[ism-1] = 0;
252 
253  if ( mea01_[ism-1] ) dqmStore_->removeElement( mea01_[ism-1]->getName() );
254  mea01_[ism-1] = 0;
255 
256  if ( mep01_[ism-1] ) dqmStore_->removeElement( mep01_[ism-1]->getName() );
257  mep01_[ism-1] = 0;
258 
259  if ( mer01_[ism-1] ) dqmStore_->removeElement( mer01_[ism-1]->getName() );
260  mer01_[ism-1] = 0;
261 
262  }
263 
264  for(int i=0; i<2; i++){
267 
270  }
271 
272 }
273 
274 #ifdef WITH_ECAL_COND_DB
275 bool EETimingClient::writeDb(EcalCondDBInterface* econn, RunIOV* runiov, MonRunIOV* moniov, bool& status) {
276 
277  status = true;
278 
279  EcalLogicID ecid;
280 
282  std::map<EcalLogicID, MonTimingCrystalDat> dataset;
283 
284  for ( unsigned int i=0; i<superModules_.size(); i++ ) {
285 
286  int ism = superModules_[i];
287 
288  if ( verbose_ ) {
289  std::cout << " " << Numbers::sEE(ism) << " (ism=" << ism << ")" << std::endl;
290  std::cout << std::endl;
291  UtilsClient::printBadChannels(meg01_[ism-1], h01_[ism-1]);
292  }
293 
294  float num01;
295  float mean01;
296  float rms01;
297 
298  for ( int ix = 1; ix <= 50; ix++ ) {
299  for ( int iy = 1; iy <= 50; iy++ ) {
300 
301  int jx = ix + Numbers::ix0EE(ism);
302  int jy = iy + Numbers::iy0EE(ism);
303 
304  if ( ism >= 1 && ism <= 9 ) jx = 101 - jx;
305 
306  if ( ! Numbers::validEE(ism, jx, jy) ) continue;
307 
308  bool update01;
309 
310  update01 = UtilsClient::getBinStatistics(h01_[ism-1], ix, iy, num01, mean01, rms01, nHitThreshold_);
311  // Task timing map is shifted of +50 ns for graphical reasons. Shift back it.
312  mean01 -= 50.;
313 
314  if ( update01 ) {
315 
316  if ( Numbers::icEE(ism, jx, jy) == 1 ) {
317 
318  if ( verbose_ ) {
319  std::cout << "Preparing dataset for " << Numbers::sEE(ism) << " (ism=" << ism << ")" << std::endl;
320  std::cout << "crystal (" << Numbers::ix0EE(i+1)+ix << "," << Numbers::iy0EE(i+1)+iy << ") " << num01 << " " << mean01 << " " << rms01 << std::endl;
321  std::cout << std::endl;
322  }
323 
324  }
325 
326  t.setTimingMean(mean01);
327  t.setTimingRMS(rms01);
328 
329  if ( UtilsClient::getBinStatus(meg01_[ism-1], ix, iy) ) {
330  t.setTaskStatus(true);
331  } else {
332  t.setTaskStatus(false);
333  }
334 
335  status = status && UtilsClient::getBinQuality(meg01_[ism-1], ix, iy);
336 
337  int ic = Numbers::indexEE(ism, jx, jy);
338 
339  if ( ic == -1 ) continue;
340 
341  if ( econn ) {
342  ecid = LogicID::getEcalLogicID("EE_crystal_number", Numbers::iSM(ism, EcalEndcap), ic);
343  dataset[ecid] = t;
344  }
345 
346  }
347 
348  }
349  }
350 
351  }
352 
353  if ( econn ) {
354  try {
355  if ( verbose_ ) std::cout << "Inserting MonTimingCrystalDat ..." << std::endl;
356  if ( dataset.size() != 0 ) econn->insertDataArraySet(&dataset, moniov);
357  if ( verbose_ ) std::cout << "done." << std::endl;
358  } catch (std::runtime_error &e) {
359  std::cerr << e.what() << std::endl;
360  }
361  }
362 
363  return true;
364 
365 }
366 #endif
367 
369 
370  ievt_++;
371  jevt_++;
372  if ( ievt_ % 10 == 0 ) {
373  if ( debug_ ) std::cout << "EETimingClient: ievt/jevt = " << ievt_ << "/" << jevt_ << std::endl;
374  }
375 
376  uint32_t bits01 = 0;
378 
379  MonitorElement* me;
380 
382 
383  for(int iz=0; iz<2; iz++){
384  int zside = -1 + iz * 2;
385  me = dqmStore_->get(prefixME_ + "/EETimingTask/EETMT timing map EE " + (zside==0 ? "-" : "+"));
386  TProfile2D *hmap = 0;
387  if( me ) hmap = (TProfile2D *)me->getRootObject();
388  if( hmap ){
389 
390  int nx = hmap->GetNbinsX();
391  int ny = hmap->GetNbinsY();
392 
393  for(int jx=1; jx<=nx; jx++){
394  for(int jy=1; jy<=ny; jy++){
395 
396  int ix = (jx-1)*5 + 1;
397  int iy = (jy-1)*5 + 1;
398  if( !EEDetId::validDetId(ix, iy, zside) ) continue;
399 
400  EEDetId id(ix, iy, zside);
401 
402  float yval = hmap->GetBinContent(jx,jy) - 50.;
403 
406  }
407  }
408  }
409  }
410 
411  }
412 
413  for(int i=0; i<2; i++){
416  }
417 
418  for ( unsigned int i=0; i<superModules_.size(); i++ ) {
419 
420  int ism = superModules_[i];
421 
422  me = dqmStore_->get( prefixME_ + "/EETimingTask/EETMT timing " + Numbers::sEE(ism) );
423  h01_[ism-1] = UtilsClient::getHisto( me, cloneME_, h01_[ism-1] );
424  meh01_[ism-1] = me;
425 
426  me = dqmStore_->get( prefixME_ + "/EETimingTask/EETMT timing vs amplitude " + Numbers::sEE(ism) );
427  h02_[ism-1] = UtilsClient::getHisto( me, cloneME_, h02_[ism-1] );
428  meh02_[ism-1] = me;
429 
430  if ( meg01_[ism-1] ) meg01_[ism-1]->Reset();
431  if ( mea01_[ism-1] ) mea01_[ism-1]->Reset();
432  if ( mep01_[ism-1] ) mep01_[ism-1]->Reset();
433  if ( mer01_[ism-1] ) mer01_[ism-1]->Reset();
434 
435  int iz = ism / 10;
436 
437  for ( int ix = 1; ix <= 50; ix++ ) {
438  for ( int iy = 1; iy <= 50; iy++ ) {
439 
440  if ( meg01_[ism-1] ) meg01_[ism-1]->setBinContent(ix, iy, 6.);
441 
442  int jx = ix + Numbers::ix0EE(ism);
443  int jy = iy + Numbers::iy0EE(ism);
444 
445  if ( ism >= 1 && ism <= 9 ) jx = 101 - jx;
446 
447  if ( Numbers::validEE(ism, jx, jy) ) {
448  if ( meg01_[ism-1] ) meg01_[ism-1]->setBinContent( ix, iy, 2. );
449  }
450 
451  bool update01;
452 
453  float num01;
454  float mean01;
455  float rms01;
456 
457  update01 = UtilsClient::getBinStatistics(h01_[ism-1], ix, iy, num01, mean01, rms01, nHitThreshold_);
458  // Task timing map is shifted of +50 ns for graphical reasons. Shift back it.
459  mean01 -= 50.;
460 
461  if ( update01 ) {
462 
463  EEDetId id(jx, jy, -1 + iz * 2);
464 
465  float val(1.);
466 
467  if ( std::abs(mean01 - expectedMean_) > meanThreshold_ || rms01 > rmsThreshold_ ) val = 0.;
468 
469  if ( meg01_[ism-1] ) meg01_[ism-1]->setBinContent(ix, iy, val);
470 
471  int ic = Numbers::icEE(ism, jx, jy);
472 
473  if ( ic != -1 ) {
474  if ( mea01_[ism-1] ) {
475  mea01_[ism-1]->setBinContent(ic, mean01);
476  mea01_[ism-1]->setBinError(ic, rms01);
477  }
478 
479  if ( mep01_[ism-1] ) mep01_[ism-1]->Fill(mean01);
480  if ( mer01_[ism-1] ) mer01_[ism-1]->Fill(rms01);
481  }
482 
485 
486  }
487 
488  if ( Masks::maskChannel(ism, ix, iy, bits01, EcalEndcap) ) UtilsClient::maskBinContent( meg01_[ism-1], ix, iy );
489 
490  }
491  }
492 
493  }
494 
495 }
496 
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 analyze(void)
Analyze.
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:57
MonitorElement * mea01_[18]
static unsigned icEE(const unsigned ism, const unsigned ix, const unsigned iy)
Definition: Numbers.cc:736
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:872
void setup(void)
Setup.
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.
std::vector< int > superModules_
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 int ix0EE(const unsigned ism)
Definition: Numbers.cc:770
void setTimingMean(float mean)
Definition: ITimingDat.h:45
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)
DQMStore * dqmStore_
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 * meTimeSummaryMapProjPhi_[2]
void cleanup(void)
Cleanup.
TProfile2D * h01_[18]
MonitorElement * mep01_[18]
MonitorElement * mer01_[18]
void removeElement(const std::string &name)
Definition: DQMStore.cc:2772
channel masking
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
void beginJob(void)
BeginJob.
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:1186
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
MonitorElement * meTimeSummaryMapProjEta_[2]
Ecal Monitor Utils for Client.
void endJob(void)
EndJob.
virtual ~EETimingClient()
Destructor.
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
#define M_PI
Definition: BFit3D.cc:3
EETimingClient(const edm::ParameterSet &ps)
Constructor.
TObject * getRootObject(void) const
static bool validDetId(int crystal_ix, int crystal_iy, int iz)
Definition: EEDetId.h:248
void endRun(void)
EndRun.
void setTimingRMS(float rms)
Definition: ITimingDat.h:48
tuple dataset
Definition: dataset.py:393
void beginRun(void)
BeginRun.
static float eta(const DetId &id)
Definition: Numbers.cc:926
MonitorElement * meg01_[18]
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
TH2F * h02_[18]
void insertDataArraySet(const std::map< EcalLogicID, DATT > *data, IOVT *iov)
tuple cout
Definition: gather_cfg.py:121
tuple status
Definition: ntuplemaker.py:245
MonitorElement * meh01_[18]
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
std::string prefixME_
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
MonitorElement * meh02_[18]
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
static float phi(const DetId &id)
Definition: Numbers.cc:933