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  * \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 
36  // cloneME switch
37  cloneME_ = ps.getUntrackedParameter<bool>("cloneME", true);
38 
39  // verbose switch
40  verbose_ = ps.getUntrackedParameter<bool>("verbose", true);
41 
42  // debug switch
43  debug_ = ps.getUntrackedParameter<bool>("debug", false);
44 
45  // prefixME path
46  prefixME_ = ps.getUntrackedParameter<std::string>("prefixME", "");
47 
48  // enableCleanup_ switch
49  enableCleanup_ = ps.getUntrackedParameter<bool>("enableCleanup", false);
50 
51  // vector of selected Super Modules (Defaults to all 36).
52  superModules_.reserve(36);
53  for ( unsigned int i = 1; i <= 36; i++ ) superModules_.push_back(i);
54  superModules_ = ps.getUntrackedParameter<std::vector<int> >("superModules", superModules_);
55 
56  for ( unsigned int i=0; i<superModules_.size(); i++ ) {
57 
58  int ism = superModules_[i];
59 
60  h01_[ism-1] = 0;
61  h02_[ism-1] = 0;
62 
63  meh01_[ism-1] = 0;
64  meh02_[ism-1] = 0;
65 
66  }
67 
68  for ( unsigned int i=0; i<superModules_.size(); i++ ) {
69 
70  int ism = superModules_[i];
71 
72  meg01_[ism-1] = 0;
73 
74  mea01_[ism-1] = 0;
75 
76  mep01_[ism-1] = 0;
77 
78  mer01_[ism-1] = 0;
79 
80  }
81 
84 
85  expectedMean_ = 0.0;
86  discrepancyMean_ = 2.0;
87  RMSThreshold_ = 6.0;
88 
89  nHitThreshold_ = ps.getUntrackedParameter<int>("timingNHitThrehold", 5);
90 
91  ievt_ = 0;
92  jevt_ = 0;
93  dqmStore_ = 0;
94 }
95 
97 
98 }
99 
101 
103 
104  if ( debug_ ) std::cout << "EBTimingClient: beginJob" << std::endl;
105 
106  ievt_ = 0;
107  jevt_ = 0;
108 
109 }
110 
112 
113  if ( debug_ ) std::cout << "EBTimingClient: beginRun" << std::endl;
114 
115  jevt_ = 0;
116 
117  this->setup();
118 
119 }
120 
122 
123  if ( debug_ ) std::cout << "EBTimingClient: endJob, ievt = " << ievt_ << std::endl;
124 
125  this->cleanup();
126 
127 }
128 
130 
131  if ( debug_ ) std::cout << "EBTimingClient: endRun, jevt = " << jevt_ << std::endl;
132 
133  this->cleanup();
134 
135 }
136 
138 
140 
141  dqmStore_->setCurrentFolder( prefixME_ + "/EBTimingClient" );
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 = "EBTMT timing quality " + Numbers::sEB(ism);
149  meg01_[ism-1] = dqmStore_->book2D(name, name, 85, 0., 85., 20, 0., 20.);
150  meg01_[ism-1]->setAxisTitle("ieta", 1);
151  meg01_[ism-1]->setAxisTitle("iphi", 2);
152 
153  if ( mea01_[ism-1] ) dqmStore_->removeElement( mea01_[ism-1]->getName() );
154  name = "EBTMT timing " + Numbers::sEB(ism);
155  mea01_[ism-1] = dqmStore_->book1D(name, name, 1700, 0., 1700.);
156  mea01_[ism-1]->setAxisTitle("channel", 1);
157  mea01_[ism-1]->setAxisTitle("time (ns)", 2);
158 
159  if ( mep01_[ism-1] ) dqmStore_->removeElement( mep01_[ism-1]->getName() );
160  name = "EBTMT timing mean " + Numbers::sEB(ism);
161  mep01_[ism-1] = dqmStore_->book1D(name, name, 100, -25.0, 25.0);
162  mep01_[ism-1]->setAxisTitle("mean (ns)", 1);
163 
164  if ( mer01_[ism-1] ) dqmStore_->removeElement( mer01_[ism-1]->getName() );
165  name = "EBTMT timing rms " + Numbers::sEB(ism);
166  mer01_[ism-1] = dqmStore_->book1D(name, name, 100, 0.0, 10.0);
167  mer01_[ism-1]->setAxisTitle("rms (ns)", 1);
168 
169  }
170 
171  name = "EBTMT timing projection eta";
172  meTimeSummaryMapProjEta_ = dqmStore_->bookProfile(name, name, 34, -85., 85., -20., 20., "");
174  meTimeSummaryMapProjEta_->setAxisTitle("time (ns)", 2);
175 
176  name = "EBTMT timing projection phi";
177  meTimeSummaryMapProjPhi_ = dqmStore_->bookProfile(name, name, 72, 0., 360., -20., 20., "");
179  meTimeSummaryMapProjPhi_->setAxisTitle("time (ns)", 2);
180 
181  for ( unsigned int i=0; i<superModules_.size(); i++ ) {
182 
183  int ism = superModules_[i];
184 
185  if ( meg01_[ism-1] ) meg01_[ism-1]->Reset();
186 
187  for ( int ie = 1; ie <= 85; ie++ ) {
188  for ( int ip = 1; ip <= 20; ip++ ) {
189 
190  if ( meg01_[ism-1] ) meg01_[ism-1]->setBinContent( ie, ip, 2. );
191 
192  }
193  }
194 
195  if ( mea01_[ism-1] ) mea01_[ism-1]->Reset();
196  if ( mep01_[ism-1] ) mep01_[ism-1]->Reset();
197  if ( mer01_[ism-1] ) mer01_[ism-1]->Reset();
198 
199  }
200 
201 
202 
203 }
204 
206 
207  if ( ! enableCleanup_ ) return;
208 
209  for ( unsigned int i=0; i<superModules_.size(); i++ ) {
210 
211  int ism = superModules_[i];
212 
213  if ( cloneME_ ) {
214  if ( h01_[ism-1] ) delete h01_[ism-1];
215  if ( h02_[ism-1] ) delete h02_[ism-1];
216  }
217 
218  h01_[ism-1] = 0;
219  h02_[ism-1] = 0;
220 
221  meh01_[ism-1] = 0;
222  meh02_[ism-1] = 0;
223 
224  }
225 
226  dqmStore_->setCurrentFolder( prefixME_ + "/EBTimingClient" );
227 
228  for ( unsigned int i=0; i<superModules_.size(); i++ ) {
229 
230  int ism = superModules_[i];
231 
232  if ( meg01_[ism-1] ) dqmStore_->removeElement( meg01_[ism-1]->getName() );
233  meg01_[ism-1] = 0;
234 
235  if ( mea01_[ism-1] ) dqmStore_->removeElement( mea01_[ism-1]->getName() );
236  mea01_[ism-1] = 0;
237 
238  if ( mep01_[ism-1] ) dqmStore_->removeElement( mep01_[ism-1]->getName() );
239  mep01_[ism-1] = 0;
240 
241  if ( mer01_[ism-1] ) dqmStore_->removeElement( mer01_[ism-1]->getName() );
242  mer01_[ism-1] = 0;
243 
244  }
245 
248 
249 }
250 
251 #ifdef WITH_ECAL_COND_DB
252 bool EBTimingClient::writeDb(EcalCondDBInterface* econn, RunIOV* runiov, MonRunIOV* moniov, bool& status) {
253 
254  status = true;
255 
256  EcalLogicID ecid;
257 
259  std::map<EcalLogicID, MonTimingCrystalDat> dataset;
260 
261  for ( unsigned int i=0; i<superModules_.size(); i++ ) {
262 
263  int ism = superModules_[i];
264 
265  if ( verbose_ ) {
266  std::cout << " " << Numbers::sEB(ism) << " (ism=" << ism << ")" << std::endl;
267  std::cout << std::endl;
268  UtilsClient::printBadChannels(meg01_[ism-1], h01_[ism-1]);
269  }
270 
271  float num01;
272  float mean01;
273  float rms01;
274 
275  for ( int ie = 1; ie <= 85; ie++ ) {
276  for ( int ip = 1; ip <= 20; ip++ ) {
277 
278  bool update01;
279 
280  update01 = UtilsClient::getBinStatistics(h01_[ism-1], ie, ip, num01, mean01, rms01, nHitThreshold_);
281  // Task timing map is shifted of +50 ns for graphical reasons. Shift back it.
282  mean01 -= 50.;
283 
284  if ( update01 ) {
285 
286  if ( Numbers::icEB(ism, ie, ip) == 1 ) {
287 
288  if ( verbose_ ) {
289  std::cout << "Preparing dataset for " << Numbers::sEB(ism) << " (ism=" << ism << ")" << std::endl;
290  std::cout << "crystal (" << ie << "," << ip << ") " << num01 << " " << mean01 << " " << rms01 << std::endl;
291  std::cout << std::endl;
292  }
293 
294  }
295 
296  t.setTimingMean(mean01);
297  t.setTimingRMS(rms01);
298 
299  if ( UtilsClient::getBinStatus(meg01_[ism-1], ie, ip) ) {
300  t.setTaskStatus(true);
301  } else {
302  t.setTaskStatus(false);
303  }
304 
305  status = status && UtilsClient::getBinQuality(meg01_[ism-1], ie, ip);
306 
307  int ic = Numbers::indexEB(ism, ie, ip);
308 
309  if ( econn ) {
310  ecid = LogicID::getEcalLogicID("EB_crystal_number", Numbers::iSM(ism, EcalBarrel), ic);
311  dataset[ecid] = t;
312  }
313 
314  }
315 
316  }
317  }
318 
319  }
320 
321  if ( econn ) {
322  try {
323  if ( verbose_ ) std::cout << "Inserting MonTimingCrystalDat ..." << std::endl;
324  if ( dataset.size() != 0 ) econn->insertDataArraySet(&dataset, moniov);
325  if ( verbose_ ) std::cout << "done." << std::endl;
326  } catch (std::runtime_error &e) {
327  std::cerr << e.what() << std::endl;
328  }
329  }
330 
331  return true;
332 
333 }
334 #endif
335 
337 
338  ievt_++;
339  jevt_++;
340  if ( ievt_ % 10 == 0 ) {
341  if ( debug_ ) std::cout << "EBTimingClient: ievt/jevt = " << ievt_ << "/" << jevt_ << std::endl;
342  }
343 
344  uint32_t bits01 = 0;
346 
347  MonitorElement* me;
348 
351 
352  for ( unsigned int i=0; i<superModules_.size(); i++ ) {
353 
354  int ism = superModules_[i];
355 
356  me = dqmStore_->get( prefixME_ + "/EBTimingTask/EBTMT timing " + Numbers::sEB(ism) );
357  h01_[ism-1] = UtilsClient::getHisto<TProfile2D*>( me, cloneME_, h01_[ism-1] );
358  meh01_[ism-1] = me;
359 
360  me = dqmStore_->get( prefixME_ + "/EBTimingTask/EBTMT timing vs amplitude " + Numbers::sEB(ism) );
361  h02_[ism-1] = UtilsClient::getHisto<TH2F*>( me, cloneME_, h02_[ism-1] );
362  meh02_[ism-1] = me;
363 
364  if ( meg01_[ism-1] ) meg01_[ism-1]->Reset();
365  if ( mea01_[ism-1] ) mea01_[ism-1]->Reset();
366  if ( mep01_[ism-1] ) mep01_[ism-1]->Reset();
367  if ( mer01_[ism-1] ) mer01_[ism-1]->Reset();
368 
369  for ( int ie = 1; ie <= 85; ie++ ) {
370  for ( int ip = 1; ip <= 20; ip++ ) {
371 
372  if ( meg01_[ism-1] ) meg01_[ism-1]->setBinContent(ie, ip, 2.);
373 
374  bool update01;
375 
376  float num01;
377  float mean01;
378  float rms01;
379 
380  update01 = UtilsClient::getBinStatistics(h01_[ism-1], ie, ip, num01, mean01, rms01, nHitThreshold_);
381  // Task timing map is shifted of +50 ns for graphical reasons. Shift back it.
382  mean01 -= 50.;
383 
384  if ( update01 ) {
385 
386  float val;
387 
388  val = 1.;
389  if ( std::abs(mean01 - expectedMean_) > discrepancyMean_ )
390  val = 0.;
391  if ( rms01 > RMSThreshold_ )
392  val = 0.;
393  if ( meg01_[ism-1] ) meg01_[ism-1]->setBinContent(ie, ip, val);
394 
395  int ic = Numbers::icEB(ism, ie, ip);
396 
397  if ( mea01_[ism-1] ) {
398  mea01_[ism-1]->setBinContent(ic, mean01);
399  mea01_[ism-1]->setBinError(ic, rms01);
400  }
401  if ( mep01_[ism-1] ) mep01_[ism-1]->Fill(mean01);
402  if ( mer01_[ism-1] ) mer01_[ism-1]->Fill(rms01);
403 
404  float eta, phi;
405 
406  if ( ism <= 18 ) {
407  eta = -ie+0.5;
408  phi = ip+20*(ism-1)-0.5;
409  } else {
410  eta = ie-0.5;
411  phi = (20-ip)+20*(ism-19)+0.5;
412  }
413 
416 
417  }
418 
419  if ( Masks::maskChannel(ism, ie, ip, bits01, EcalBarrel) ) UtilsClient::maskBinContent( meg01_[ism-1], ie, ip );
420 
421 
422 
423  }
424  }
425 
426  }
427 
428 }
429 
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:57
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:872
Some &quot;id&quot; conversions.
static std::string sEB(const unsigned ism)
Definition: Numbers.cc:91
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
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:726
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:2772
channel masking
DQMStore * dqmStore_
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
static unsigned indexEB(const unsigned ism, const unsigned ie, const unsigned ip)
Definition: Numbers.cc:695
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_
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:243
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:1000
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
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:584
void beginJob(void)
BeginJob.
void setup(void)
Setup.
Definition: DDAxes.h:10