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  * $Date: 2012/04/27 13:46:08 $
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 
39 
40  // cloneME switch
41  cloneME_ = ps.getUntrackedParameter<bool>("cloneME", true);
42 
43  // verbose switch
44  verbose_ = ps.getUntrackedParameter<bool>("verbose", true);
45 
46  // debug switch
47  debug_ = ps.getUntrackedParameter<bool>("debug", false);
48 
49  // prefixME path
50  prefixME_ = ps.getUntrackedParameter<std::string>("prefixME", "");
51 
52  // enableCleanup_ switch
53  enableCleanup_ = ps.getUntrackedParameter<bool>("enableCleanup", false);
54 
55  // vector of selected Super Modules (Defaults to all 18).
56  superModules_.reserve(18);
57  for ( unsigned int i = 1; i <= 18; i++ ) superModules_.push_back(i);
58  superModules_ = ps.getUntrackedParameter<std::vector<int> >("superModules", superModules_);
59 
60  nHitThreshold_ = ps.getUntrackedParameter<int>("timingNHitThreshold", 5);
61 
62  for ( unsigned int i=0; i<superModules_.size(); i++ ) {
63 
64  int ism = superModules_[i];
65 
66  h01_[ism-1] = 0;
67  h02_[ism-1] = 0;
68 
69  meh01_[ism-1] = 0;
70  meh02_[ism-1] = 0;
71 
72  }
73 
74  for ( unsigned int i=0; i<superModules_.size(); i++ ) {
75 
76  int ism = superModules_[i];
77 
78  meg01_[ism-1] = 0;
79 
80  mea01_[ism-1] = 0;
81 
82  mep01_[ism-1] = 0;
83 
84  mer01_[ism-1] = 0;
85 
86  }
87 
92 
93  expectedMean_ = 0.;
94  meanThreshold_ = 3.;
95  rmsThreshold_ = 6.;
96 }
97 
99 
100 }
101 
103 
105 
106  if ( debug_ ) std::cout << "EETimingClient: beginJob" << std::endl;
107 
108  ievt_ = 0;
109  jevt_ = 0;
110 
111 }
112 
114 
115  if ( debug_ ) std::cout << "EETimingClient: beginRun" << std::endl;
116 
117  jevt_ = 0;
118 
119  this->setup();
120 
121 }
122 
124 
125  if ( debug_ ) std::cout << "EETimingClient: endJob, ievt = " << ievt_ << std::endl;
126 
127  this->cleanup();
128 
129 }
130 
132 
133  if ( debug_ ) std::cout << "EETimingClient: endRun, jevt = " << jevt_ << std::endl;
134 
135  this->cleanup();
136 
137 }
138 
140 
141  std::string name;
142 
143  dqmStore_->setCurrentFolder( prefixME_ + "/EETimingClient" );
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 = "EETMT timing quality " + Numbers::sEE(ism);
151  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.);
152  meg01_[ism-1]->setAxisTitle("ix", 1);
153  if ( ism >= 1 && ism <= 9 ) meg01_[ism-1]->setAxisTitle("101-ix", 1);
154  meg01_[ism-1]->setAxisTitle("iy", 2);
155 
156  if ( mea01_[ism-1] ) dqmStore_->removeElement( mea01_[ism-1]->getName() );
157  name = "EETMT timing " + Numbers::sEE(ism);
158  mea01_[ism-1] = dqmStore_->book1D(name, name, 850, 0., 850.);
159  mea01_[ism-1]->setAxisTitle("channel", 1);
160  mea01_[ism-1]->setAxisTitle("time (ns)", 2);
161 
162  if ( mep01_[ism-1] ) dqmStore_->removeElement( mep01_[ism-1]->getName() );
163  name = "EETMT timing mean " + Numbers::sEE(ism);
164  mep01_[ism-1] = dqmStore_->book1D(name, name, 100, -25., 25.);
165  mep01_[ism-1]->setAxisTitle("mean (ns)", 1);
166 
167  if ( mer01_[ism-1] ) dqmStore_->removeElement( mer01_[ism-1]->getName() );
168  name = "EETMT timing rms " + Numbers::sEE(ism);
169  mer01_[ism-1] = dqmStore_->book1D(name, name, 100, 0.0, 10.);
170  mer01_[ism-1]->setAxisTitle("rms (ns)", 1);
171 
172  }
173 
174  name = "EETMT timing projection eta EE -";
175  meTimeSummaryMapProjEta_[0] = dqmStore_->bookProfile(name, name, 20, -3.0, -1.479, -20., 20.,"");
177  meTimeSummaryMapProjEta_[0]->setAxisTitle("time (ns)", 2);
178 
179  name = "EETMT timing projection eta EE +";
180  meTimeSummaryMapProjEta_[1] = dqmStore_->bookProfile(name, name, 20, 1.479, 3.0, -20., 20.,"");
182  meTimeSummaryMapProjEta_[1]->setAxisTitle("time (ns)", 2);
183 
184  name = "EETMT timing projection phi EE -";
185  meTimeSummaryMapProjPhi_[0] = dqmStore_->bookProfile(name, name, 50, -M_PI, M_PI, -20., 20.,"");
187  meTimeSummaryMapProjPhi_[0]->setAxisTitle("time (ns)", 2);
188 
189  name = "EETMT timing projection phi EE +";
190  meTimeSummaryMapProjPhi_[1] = dqmStore_->bookProfile(name, name, 50, -M_PI, M_PI, -20., 20.,"");
192  meTimeSummaryMapProjPhi_[1]->setAxisTitle("time (ns)", 2);
193 
194  for ( unsigned int i=0; i<superModules_.size(); i++ ) {
195 
196  int ism = superModules_[i];
197 
198  if ( meg01_[ism-1] ) meg01_[ism-1]->Reset();
199 
200  for ( int ix = 1; ix <= 50; ix++ ) {
201  for ( int iy = 1; iy <= 50; iy++ ) {
202 
203  if ( meg01_[ism-1] ) meg01_[ism-1]->setBinContent( ix, iy, 6. );
204 
205  int jx = ix + Numbers::ix0EE(ism);
206  int jy = iy + Numbers::iy0EE(ism);
207 
208  if ( ism >= 1 && ism <= 9 ) jx = 101 - jx;
209 
210  if ( Numbers::validEE(ism, jx, jy) ) {
211  if ( meg01_[ism-1] ) meg01_[ism-1]->setBinContent( ix, iy, 2. );
212  }
213 
214  }
215  }
216 
217  if ( mea01_[ism-1] ) mea01_[ism-1]->Reset();
218  if ( mep01_[ism-1] ) mep01_[ism-1]->Reset();
219  if ( mer01_[ism-1] ) mer01_[ism-1]->Reset();
220 
221  }
222 
223 }
224 
226 
227  if ( ! enableCleanup_ ) return;
228 
229  for ( unsigned int i=0; i<superModules_.size(); i++ ) {
230 
231  int ism = superModules_[i];
232 
233  if ( cloneME_ ) {
234  if ( h01_[ism-1] ) delete h01_[ism-1];
235  if ( h02_[ism-1] ) delete h02_[ism-1];
236  }
237 
238  h01_[ism-1] = 0;
239  h02_[ism-1] = 0;
240 
241  meh01_[ism-1] = 0;
242  meh02_[ism-1] = 0;
243 
244  }
245 
246  dqmStore_->setCurrentFolder( prefixME_ + "/EETimingClient" );
247 
248  for ( unsigned int i=0; i<superModules_.size(); i++ ) {
249 
250  int ism = superModules_[i];
251 
252  if ( meg01_[ism-1] ) dqmStore_->removeElement( meg01_[ism-1]->getName() );
253  meg01_[ism-1] = 0;
254 
255  if ( mea01_[ism-1] ) dqmStore_->removeElement( mea01_[ism-1]->getName() );
256  mea01_[ism-1] = 0;
257 
258  if ( mep01_[ism-1] ) dqmStore_->removeElement( mep01_[ism-1]->getName() );
259  mep01_[ism-1] = 0;
260 
261  if ( mer01_[ism-1] ) dqmStore_->removeElement( mer01_[ism-1]->getName() );
262  mer01_[ism-1] = 0;
263 
264  }
265 
266  for(int i=0; i<2; i++){
269 
272  }
273 
274 }
275 
276 #ifdef WITH_ECAL_COND_DB
277 bool EETimingClient::writeDb(EcalCondDBInterface* econn, RunIOV* runiov, MonRunIOV* moniov, bool& status) {
278 
279  status = true;
280 
281  EcalLogicID ecid;
282 
284  std::map<EcalLogicID, MonTimingCrystalDat> dataset;
285 
286  for ( unsigned int i=0; i<superModules_.size(); i++ ) {
287 
288  int ism = superModules_[i];
289 
290  if ( verbose_ ) {
291  std::cout << " " << Numbers::sEE(ism) << " (ism=" << ism << ")" << std::endl;
292  std::cout << std::endl;
293  UtilsClient::printBadChannels(meg01_[ism-1], h01_[ism-1]);
294  }
295 
296  float num01;
297  float mean01;
298  float rms01;
299 
300  for ( int ix = 1; ix <= 50; ix++ ) {
301  for ( int iy = 1; iy <= 50; iy++ ) {
302 
303  int jx = ix + Numbers::ix0EE(ism);
304  int jy = iy + Numbers::iy0EE(ism);
305 
306  if ( ism >= 1 && ism <= 9 ) jx = 101 - jx;
307 
308  if ( ! Numbers::validEE(ism, jx, jy) ) continue;
309 
310  bool update01;
311 
312  update01 = UtilsClient::getBinStatistics(h01_[ism-1], ix, iy, num01, mean01, rms01, nHitThreshold_);
313  // Task timing map is shifted of +50 ns for graphical reasons. Shift back it.
314  mean01 -= 50.;
315 
316  if ( update01 ) {
317 
318  if ( Numbers::icEE(ism, jx, jy) == 1 ) {
319 
320  if ( verbose_ ) {
321  std::cout << "Preparing dataset for " << Numbers::sEE(ism) << " (ism=" << ism << ")" << std::endl;
322  std::cout << "crystal (" << Numbers::ix0EE(i+1)+ix << "," << Numbers::iy0EE(i+1)+iy << ") " << num01 << " " << mean01 << " " << rms01 << std::endl;
323  std::cout << std::endl;
324  }
325 
326  }
327 
328  t.setTimingMean(mean01);
329  t.setTimingRMS(rms01);
330 
331  if ( UtilsClient::getBinStatus(meg01_[ism-1], ix, iy) ) {
332  t.setTaskStatus(true);
333  } else {
334  t.setTaskStatus(false);
335  }
336 
337  status = status && UtilsClient::getBinQuality(meg01_[ism-1], ix, iy);
338 
339  int ic = Numbers::indexEE(ism, jx, jy);
340 
341  if ( ic == -1 ) continue;
342 
343  if ( econn ) {
344  ecid = LogicID::getEcalLogicID("EE_crystal_number", Numbers::iSM(ism, EcalEndcap), ic);
345  dataset[ecid] = t;
346  }
347 
348  }
349 
350  }
351  }
352 
353  }
354 
355  if ( econn ) {
356  try {
357  if ( verbose_ ) std::cout << "Inserting MonTimingCrystalDat ..." << std::endl;
358  if ( dataset.size() != 0 ) econn->insertDataArraySet(&dataset, moniov);
359  if ( verbose_ ) std::cout << "done." << std::endl;
360  } catch (std::runtime_error &e) {
361  std::cerr << e.what() << std::endl;
362  }
363  }
364 
365  return true;
366 
367 }
368 #endif
369 
371 
372  ievt_++;
373  jevt_++;
374  if ( ievt_ % 10 == 0 ) {
375  if ( debug_ ) std::cout << "EETimingClient: ievt/jevt = " << ievt_ << "/" << jevt_ << std::endl;
376  }
377 
378  uint32_t bits01 = 0;
380 
381  MonitorElement* me;
382 
384 
385  for(int iz=0; iz<2; iz++){
386  int zside = -1 + iz * 2;
387  me = dqmStore_->get(prefixME_ + "/EETimingTask/EETMT timing map EE " + (zside==0 ? "-" : "+"));
388  TProfile2D *hmap = 0;
389  if( me ) hmap = (TProfile2D *)me->getRootObject();
390  if( hmap ){
391 
392  int nx = hmap->GetNbinsX();
393  int ny = hmap->GetNbinsY();
394 
395  for(int jx=1; jx<=nx; jx++){
396  for(int jy=1; jy<=ny; jy++){
397 
398  int ix = (jx-1)*5 + 1;
399  int iy = (jy-1)*5 + 1;
400  if( !EEDetId::validDetId(ix, iy, zside) ) continue;
401 
402  EEDetId id(ix, iy, zside);
403 
404  float yval = hmap->GetBinContent(jx,jy) - 50.;
405 
408  }
409  }
410  }
411  }
412 
413  }
414 
415  for(int i=0; i<2; i++){
418  }
419 
420  for ( unsigned int i=0; i<superModules_.size(); i++ ) {
421 
422  int ism = superModules_[i];
423 
424  me = dqmStore_->get( prefixME_ + "/EETimingTask/EETMT timing " + Numbers::sEE(ism) );
425  h01_[ism-1] = UtilsClient::getHisto( me, cloneME_, h01_[ism-1] );
426  meh01_[ism-1] = me;
427 
428  me = dqmStore_->get( prefixME_ + "/EETimingTask/EETMT timing vs amplitude " + Numbers::sEE(ism) );
429  h02_[ism-1] = UtilsClient::getHisto( me, cloneME_, h02_[ism-1] );
430  meh02_[ism-1] = me;
431 
432  if ( meg01_[ism-1] ) meg01_[ism-1]->Reset();
433  if ( mea01_[ism-1] ) mea01_[ism-1]->Reset();
434  if ( mep01_[ism-1] ) mep01_[ism-1]->Reset();
435  if ( mer01_[ism-1] ) mer01_[ism-1]->Reset();
436 
437  int iz = ism / 10;
438 
439  for ( int ix = 1; ix <= 50; ix++ ) {
440  for ( int iy = 1; iy <= 50; iy++ ) {
441 
442  if ( meg01_[ism-1] ) meg01_[ism-1]->setBinContent(ix, iy, 6.);
443 
444  int jx = ix + Numbers::ix0EE(ism);
445  int jy = iy + Numbers::iy0EE(ism);
446 
447  if ( ism >= 1 && ism <= 9 ) jx = 101 - jx;
448 
449  if ( Numbers::validEE(ism, jx, jy) ) {
450  if ( meg01_[ism-1] ) meg01_[ism-1]->setBinContent( ix, iy, 2. );
451  }
452 
453  bool update01;
454 
455  float num01;
456  float mean01;
457  float rms01;
458 
459  update01 = UtilsClient::getBinStatistics(h01_[ism-1], ix, iy, num01, mean01, rms01, nHitThreshold_);
460  // Task timing map is shifted of +50 ns for graphical reasons. Shift back it.
461  mean01 -= 50.;
462 
463  if ( update01 ) {
464 
465  EEDetId id(jx, jy, -1 + iz * 2);
466 
467  float val(1.);
468 
469  if ( std::abs(mean01 - expectedMean_) > meanThreshold_ || rms01 > rmsThreshold_ ) val = 0.;
470 
471  if ( meg01_[ism-1] ) meg01_[ism-1]->setBinContent(ix, iy, val);
472 
473  int ic = Numbers::icEE(ism, jx, jy);
474 
475  if ( ic != -1 ) {
476  if ( mea01_[ism-1] ) {
477  mea01_[ism-1]->setBinContent(ic, mean01);
478  mea01_[ism-1]->setBinError(ic, rms01);
479  }
480 
481  if ( mep01_[ism-1] ) mep01_[ism-1]->Fill(mean01);
482  if ( mer01_[ism-1] ) mer01_[ism-1]->Fill(rms01);
483  }
484 
487 
488  }
489 
490  if ( Masks::maskChannel(ism, ix, iy, bits01, EcalEndcap) ) UtilsClient::maskBinContent( meg01_[ism-1], ix, iy );
491 
492  }
493  }
494 
495  }
496 
497 }
498 
Cache logicID vector from database.
T getUntrackedParameter(std::string const &, T const &) const
static std::string sEE(const unsigned ism)
Definition: Numbers.cc:226
int i
Definition: DBlmapReader.cc:9
static bool validEE(const unsigned ism, const unsigned ix, const unsigned iy)
Definition: Numbers.cc:832
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:60
MonitorElement * mea01_[18]
static unsigned icEE(const unsigned ism, const unsigned ix, const unsigned iy)
Definition: Numbers.cc:739
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
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:91
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
#define abs(x)
Definition: mlp_lapack.h:159
static int ix0EE(const unsigned ism)
Definition: Numbers.cc:773
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 bool validDetId(int crystal_ix, int crystal_iy, int iz)
Definition: EEDetId.cc:562
static int iy0EE(const unsigned ism)
Definition: Numbers.cc:812
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:2572
channel masking
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: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_[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
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:929
MonitorElement * meg01_[18]
static unsigned indexEE(const unsigned ism, const unsigned ix, const unsigned iy)
Definition: Numbers.cc:712
static unsigned iSM(const unsigned ism, const EcalSubdetector subdet)
Definition: Numbers.cc:246
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:845
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:31
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:429
static float phi(const DetId &id)
Definition: Numbers.cc:936