CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
EEBeamCaloClient.cc
Go to the documentation of this file.
1 /*
2  * \file EEBeamCaloClient.cc
3  *
4  * $Date: 2011/08/30 09:29:44 $
5  * $Revision: 1.66 $
6  * \author G. Della Ricca
7  * \author A. Ghezzi
8  *
9  */
10 
11 #include <memory>
12 #include <iostream>
13 #include <sstream>
14 #include <iomanip>
15 #include <algorithm>
16 #include <cmath>
17 #include <math.h>
18 
20 
23 
24 #ifdef WITH_ECAL_COND_DB
28 #endif
29 
32 
34 
36 
37  // cloneME switch
38  cloneME_ = ps.getUntrackedParameter<bool>("cloneME", true);
39 
40  // verbose switch
41  verbose_ = ps.getUntrackedParameter<bool>("verbose", true);
42 
43  // debug switch
44  debug_ = ps.getUntrackedParameter<bool>("debug", false);
45 
46  // prefixME path
47  prefixME_ = ps.getUntrackedParameter<std::string>("prefixME", "");
48 
49  // enableCleanup_ switch
50  enableCleanup_ = ps.getUntrackedParameter<bool>("enableCleanup", false);
51 
52  // vector of selected Super Modules (Defaults to all 18).
53  superModules_.reserve(18);
54  for ( unsigned int i = 1; i <= 18; i++ ) superModules_.push_back(i);
55  superModules_ = ps.getUntrackedParameter<std::vector<int> >("superModules", superModules_);
56 
57  checkedSteps_.reserve(86);
58  // there should be not more than a eta row in an autoscan
59  minEvtNum_ = 1800;//
60  //FIX ME, this should be configurable and change with the beam energy
61  aveEne1_ = 1850; E1Th_ = 900;
62  aveEne3x3_ = 2600; E3x3Th_ = 2600;
63  RMSEne3x3_ = 800;
64 
65  ReadCryErrThr_ = 0.01;// 1%
66  //FIX ME, this should follow the prescaling in the monitoring
67  prescaling_ = 20;
68 
70  for(int u=0;u<cryInArray_;u++) {
71  hBGains_[u] = 0;
72  hBpulse_[u] = 0;
73  //hBGainsMoving_[u] = 0;
74  }
75  hBEne1_ = 0;
76  //hBEne1Moving_ = 0;
77  hBAllNeededCry_ = 0;
78  hBNumReadCry_ = 0;
79  hBE3x3_ = 0;
80  hBE3x3Moving_ = 0;
81  hBCryOnBeam_ = 0;
82  hBMaxEneCry_ = 0;
83  hBReadCryErrors_ = 0;
84  hBE1vsCry_ = 0;
85  hBE3x3vsCry_ = 0;
86  hBEntriesvsCry_ = 0;
87  hBcryDone_ = 0;
88  hBBeamCentered_ = 0;
89  hbTBmoving_ = 0;
90  hbE1MaxCry_ = 0;
91  hbDesync_ = 0;
93 
97 }
98 
100 
101 }
102 
104 
106 
107  if ( debug_ ) std::cout << "EEBeamCaloClient: beginJob" << std::endl;
108 
109  ievt_ = 0;
110  jevt_ = 0;
111 
112 }
113 
115 
116  if ( debug_ ) std::cout << "EEBeamCaloClient: beginRun" << std::endl;
117 
118  jevt_ = 0;
119 
120  this->setup();
121 
122 }
123 
125 
126  if ( debug_ ) std::cout << "EEBeamCaloClient: endJob, ievt = " << ievt_ << std::endl;
127 
128  this->cleanup();
129 
130 }
131 
133 
134  if ( debug_ ) std::cout << "EEBeamCaloClient: endRun, jevt = " << jevt_ << std::endl;
135 
136  this->cleanup();
137 
138 }
139 
141 
142  std::string name;
143 
144  dqmStore_->setCurrentFolder( prefixME_ + "/EEBeamCaloClient" );
145 
147  name = "EEBCT quality";
148  meEEBCaloRedGreen_ = dqmStore_->book2D(name, name, 85, 0., 85., 20, 0., 20.);
149 
151 
152  for ( int ie = 1; ie <= 85; ie++ ) {
153  for ( int ip = 1; ip <= 20; ip++ ) {
154 
155  meEEBCaloRedGreen_ ->setBinContent( ie, ip, 2. );
156 
157  }
158  }
159 
161  name = "EEBCT quality read crystal errors";
162  meEEBCaloRedGreenReadCry_ = dqmStore_->book2D(name, name, 1, 0., 1., 1, 0., 1.);
165 
167  name = "EEBCT quality entries or read crystals errors";
168  meEEBCaloRedGreenSteps_ = dqmStore_->book2D(name, name, 86, 1., 87., 1, 0., 1.);
169  meEEBCaloRedGreenSteps_->setAxisTitle("step in the scan");
171  for( int bin=1; bin <87; bin++) { meEEBCaloRedGreenSteps_->setBinContent( bin, 1, 2. );}
172 
173 }
174 
176  if ( ! enableCleanup_ ) return;
177  if ( cloneME_ ) {
178  for(int u=0;u<cryInArray_;u++) {
179  if(hBGains_[u]) delete hBGains_[u];
180  if(hBpulse_[u]) delete hBpulse_[u];
181  //if(hBGainsMoving_[u])delete hBGainsMoving_[u];
182  }
183  if(hBEne1_) delete hBEne1_;
184  // if(hBEne1Moving_) delete hBEne1Moving_;
185  if(hBAllNeededCry_) delete hBAllNeededCry_;
186  if(hBNumReadCry_) delete hBNumReadCry_;
187  if(hBE3x3_) delete hBE3x3_;
188  if(hBE3x3Moving_) delete hBE3x3Moving_;
189  if(hBCryOnBeam_) delete hBCryOnBeam_;
190  if(hBMaxEneCry_) delete hBMaxEneCry_;
192  if(hBE1vsCry_) delete hBE1vsCry_;
193  if(hBE3x3vsCry_) delete hBE3x3vsCry_;
194  if(hBEntriesvsCry_) delete hBEntriesvsCry_;
195  if(hBcryDone_) delete hBcryDone_;
196  if(hBBeamCentered_) delete hBBeamCentered_;
197  if(hbTBmoving_) delete hbTBmoving_;
198  if(hbE1MaxCry_) delete hbE1MaxCry_;
199  if(hbDesync_) delete hbDesync_;
201  }
202 
203  for(int u=0;u<cryInArray_;u++) {
204  hBGains_[u] = 0;
205  hBpulse_[u] = 0;
206  //hBGainsMoving_[u] = 0;
207  }
208  hBEne1_ = 0;
209  //hBEne1Moving_ = 0;
210  hBAllNeededCry_ = 0;
211  hBNumReadCry_ = 0;
212  hBE3x3_ = 0;
213  hBE3x3Moving_ = 0;
214  hBCryOnBeam_ = 0;
215  hBMaxEneCry_ = 0;
216  hBReadCryErrors_ = 0;
217  hBE1vsCry_ = 0;
218  hBE3x3vsCry_ = 0;
219  hBEntriesvsCry_ = 0;
220  hBcryDone_ = 0;
221  hBBeamCentered_ = 0;
222  hbTBmoving_ = 0;
223  hbE1MaxCry_ = 0;
224  hbDesync_ = 0;
226 
227  dqmStore_->setCurrentFolder( prefixME_ + "/EEBeamCaloClient" );
228 
230  meEEBCaloRedGreen_ = 0;
235 }
236 
237 #ifdef WITH_ECAL_COND_DB
238 bool EEBeamCaloClient::writeDb(EcalCondDBInterface* econn, RunIOV* runiov, MonRunIOV* moniov, bool& status) {
239 
240  status = true;
241 
242  EcalLogicID ecid;
243 
245  std::map<EcalLogicID, MonOccupancyDat> dataset;
246 
247  for ( unsigned int i=0; i<superModules_.size(); i++ ) {
248 
249  int ism = superModules_[i];
250 
251  if ( verbose_ ) {
252  std::cout << " " << Numbers::sEE(ism) << " (ism=" << ism << ")" << std::endl;
253  std::cout << std::endl;
254  }
255 
256  const float n_min_tot = 1000.;
257 
258  float num01, num02;
259  float mean01;
260 
261  for ( int ie = 1; ie <= 85; ie++ ) {
262  for ( int ip = 1; ip <= 20; ip++ ) {
263 
264  num01 = num02 = -1.;
265  mean01 = -1.;
266 
267  bool update_channel = false;
268 
269  if ( hBCryOnBeam_ && hBCryOnBeam_->GetEntries() >= n_min_tot ) {
270  num01 = hBCryOnBeam_->GetBinContent(ie, ip);
271  update_channel = true;
272  }
273 
274  if ( hBMaxEneCry_ && hBMaxEneCry_->GetEntries() >= n_min_tot ) {
275  num02 = hBMaxEneCry_->GetBinContent(ie, ip);
276  update_channel = true;
277  }
278 
279  mean01 = 0.;
280  //int cry = ip+20*(ie-1);
281  int ic = (ip-1) + 20*(ie-1) + 1;
282  int step = 0;
283  if (hBcryDone_) { step = (int) hBcryDone_->GetBinContent(ic);}
284  if( step > 0 && step < 86) {
285  //if(hBE3x3vsCry_) {mean01 = hBE3x3vsCry_->GetBinContent(step);}// E in the 3x3
286  if( hBE1vsCry_ ) {mean01 = hBE1vsCry_->GetBinContent(ic);} // E1
287  }
288 
289  if ( update_channel ) {
290 
291  if ( Numbers::icEB(ism, ie, ip) == 1 ) {
292 
293  if ( verbose_ ) {
294  std::cout << "Preparing dataset for " << Numbers::sEE(ism) << " (ism=" << ism << ")" << std::endl;
295  std::cout << "CryOnBeam (" << ie << "," << ip << ") " << num01 << std::endl;
296  std::cout << "MaxEneCry (" << ie << "," << ip << ") " << num02 << std::endl;
297  std::cout << "E1 (" << ie << "," << ip << ") " << mean01 << std::endl;
298  std::cout << std::endl;
299  }
300 
301  }
302 
303  o.setEventsOverHighThreshold(int(num01));
304  o.setEventsOverLowThreshold(int(num02));
305 
306  o.setAvgEnergy(mean01);
307 
308  if ( econn ) {
309  ecid = LogicID::getEcalLogicID("EE_crystal_number", ism, ic);
310  dataset[ecid] = o;
311  }
312 
313  }
314 
315  }
316  }
317 
318  }
319 
320  if ( econn ) {
321  try {
322  if ( verbose_ ) std::cout << "Inserting MonOccupancyDat ..." << std::endl;
323  if ( dataset.size() != 0 ) econn->insertDataArraySet(&dataset, moniov);
324  if ( verbose_ ) std::cout << "done." << std::endl;
325  } catch (std::runtime_error &e) {
326  std::cerr << e.what() << std::endl;
327  }
328  }
329 
330  return true;
331 
332 }
333 #endif
334 
336 
337  ievt_++;
338  jevt_++;
339  if ( ievt_ % 10 == 0 ) {
340  if ( debug_ ) std::cout << "EEBeamCaloClient: ievt/jevt = " << ievt_ << "/" << jevt_ << std::endl;
341  }
342 
343  MonitorElement* me = 0;
344 
345  me = dqmStore_->get( prefixME_ + "/EEBeamCaloTask/EEBCT crystals done" );
347 
348  me = dqmStore_->get( prefixME_ + "/EEBeamCaloTask/EEBCT crystal on beam" );
350 
351  me = dqmStore_->get( prefixME_ + "/EEBeamCaloTask/EEBCT all needed crystals readout" );
353 
354  me = dqmStore_->get( prefixME_ + "/EEBeamCaloTask/EEBCT readout crystals number" );
356 
357  me = dqmStore_->get( prefixME_ + "/EEBeamCaloTask/EEBCT rec Ene sum 3x3" );
359 
360  me = dqmStore_->get( prefixME_ + "/EEBeamCaloTask/EEBCT readout crystals errors" );
362 
363  me = dqmStore_->get( prefixME_ + "/EEBeamCaloTask/EEBCT rec energy cry 5" );
365 
366  me = dqmStore_->get( prefixME_ + "/EEBeamCaloTask/EEBCT crystal with maximum rec energy" );
368 
369  me = dqmStore_->get( prefixME_ + "/EEBeamCaloTask/EEBCT average rec energy in the 3x3 array" );
371 
372  me = dqmStore_->get( prefixME_ + "/EEBeamCaloTask/EEBCT average rec energy in the single crystal" );
374 
375  me = dqmStore_->get( prefixME_ + "/EEBeamCaloTask/EEBCT number of entries" );
377 
378  me = dqmStore_->get( prefixME_ + "/EEBeamCaloTask/EEBCT energy deposition in the 3x3" );
380 
381  me = dqmStore_->get( prefixME_ + "/EEBeamCaloTask/EEBCT table is moving" );
383 
384  me = dqmStore_->get( prefixME_ + "/EEBeamCaloTask/EEBCT crystal in beam vs event" );
386 
387  me = dqmStore_->get( prefixME_ + "/EEBeamCaloTask/EEBCT E1 in the max cry" );
389 
390  me = dqmStore_->get( prefixME_ + "/EEBeamCaloTask/EEBCT Desynchronization vs step" );
392 
393  std::stringstream ss;
394 
395  for(int ind = 0; ind < cryInArray_; ind ++) {
396  ss.str("");
397  ss << prefixME_ << "/EEBeamCaloTask/EEBCT pulse profile in G12 cry " << std::setfill('0') << std::setw(1) << (ind+1);
398  me = dqmStore_->get( ss.str() );
399  hBpulse_[ind] = UtilsClient::getHisto( me, cloneME_, hBpulse_[ind]);
400 
401  ss.str("");
402  ss << prefixME_ << "/EEBeamCaloTask/EEBCT found gains cry " << std::setfill('0') << std::setw(1) << (ind+1);
403  me = dqmStore_->get( ss.str() );
404  hBGains_[ind] = UtilsClient::getHisto( me, cloneME_, hBGains_[ind]);
405  }
406 
407  int DoneCry = 0;//if it stays 1 the run is not an autoscan
408  if (hBcryDone_) {
409  for(int cry=1 ; cry<1701 ; cry ++) {
410  int step = (int) hBcryDone_->GetBinContent(cry);
411  if( step>0 ) {//this crystal has been scanned or is being scanned
412  DoneCry++;
413  float E3x3RMS = -1, E3x3 =-1, E1=-1;
414  if(hBE3x3vsCry_) {
415  E3x3RMS = hBE3x3vsCry_->GetBinError(cry);
416  E3x3 = hBE3x3vsCry_->GetBinContent(cry);
417  }
418  if( hBE1vsCry_) {E1=hBE1vsCry_->GetBinContent(cry);}
419  bool RMS3x3 = ( E3x3RMS < RMSEne3x3_ && E3x3RMS >= 0 );
420  bool Mean3x3 = ( std::abs( E3x3 - aveEne3x3_ ) < E3x3Th_);
421  bool Mean1 = ( std::abs( E1 - aveEne1_ ) < E1Th_ );
422  int ieta = ( cry - 1)/20 + 1 ;//+1 for the bin
423  int iphi = ( cry - 1)%20 + 1 ;//+1 for the bin
424  //fill the RedGreen histo
425  if(ieta >0 && iphi >0 ) {
426  if(RMS3x3 && Mean3x3 && Mean1) {meEEBCaloRedGreen_->setBinContent(ieta,iphi,1.);}
427  else {meEEBCaloRedGreen_->setBinContent(ieta,iphi,0.);}
428  }
429 
430  float Entries = -1;
431  //if ( hBEntriesvsCry_ ) {Entries = hBEntriesvsCry_->GetBinContent(step);}
432  if ( hBEntriesvsCry_ ) {Entries = hBEntriesvsCry_->GetBinContent(cry);}
433  bool Nent = ( Entries * prescaling_ > minEvtNum_ );
434  bool readCryOk = true;
435  if( hBReadCryErrors_ ) {
436  int step_bin = hBReadCryErrors_->GetXaxis()->FindFixBin(step);
437  if ( step_bin > 0 && step_bin < hBReadCryErrors_->GetNbinsX() ) {
438  if ( hBReadCryErrors_->GetBinContent(step_bin) <= Entries*ReadCryErrThr_ ) {readCryOk = true;}
439  else {readCryOk = false;}
440  }
441  }
442 
443  if(Nent && readCryOk ) { meEEBCaloRedGreenSteps_->setBinContent(step,1,1.);}
444  else{ meEEBCaloRedGreenSteps_->setBinContent(step,1,0.);}
445 
446  if (readCryOk && meEEBCaloRedGreenReadCry_->getBinContent(1,1) != 0.) { meEEBCaloRedGreenReadCry_->setBinContent(1,1, 1.);}
447  else if ( !readCryOk ) { meEEBCaloRedGreenReadCry_->setBinContent(1,1, 0.);}
448  }// end of if (step>0)
449  }//end of loop over cry
450  }//end of if(hBcryDone_)
451 
452  if(DoneCry == 1) {//this is probably not an auotscan or it is the first crystal
453  float nEvt = 0;
454  if(hBE3x3_) {nEvt = hBE3x3_->GetEntries();}
455  if(nEvt > 1*prescaling_ && hBE3x3_ && hBEne1_ && hBCryOnBeam_ && meEEBCaloRedGreen_) {//check for mean and RMS
456  bool RMS3x3 = ( hBE3x3_->GetRMS() < RMSEne3x3_ );
457  bool Mean3x3 = ( std::abs( hBE3x3_->GetMean() - aveEne3x3_ ) < E3x3Th_ );
458  bool Mean1 = ( std::abs( hBEne1_->GetMean() - aveEne1_ ) < E1Th_ );
459  //fill the RedGreen histo
460  int ieta=0,iphi=0;
461  float found =0; //there should be just one bin filled but...
462  for (int b_eta =1; b_eta<86; b_eta++) {
463  for (int b_phi =1; b_phi<21; b_phi++) {
464  float bc = hBCryOnBeam_->GetBinContent(b_eta,b_phi);//FIX ME check if this is the correct binning
465  if(bc > found) { found =bc; ieta = b_eta; iphi= b_phi;}
466  }
467  }
468  if(ieta >0 && iphi >0 ) {
469  if(RMS3x3 && Mean3x3 && Mean1) {meEEBCaloRedGreen_->setBinContent(ieta,iphi,1.);}
470  else {meEEBCaloRedGreen_->setBinContent(ieta,iphi,0.);}
471  }
472  }
473  if(hBReadCryErrors_) {
474  float nErr = hBReadCryErrors_->GetBinContent(1);// for a non autoscan just the first bin should be filled
475  if( nErr > nEvt*ReadCryErrThr_ ) { meEEBCaloRedGreenReadCry_->setBinContent(1,1,0.);}
476  else { meEEBCaloRedGreenReadCry_->setBinContent(1,1,1.);}
477  }
478  }
479 
480 }
481 
void beginRun(void)
BeginRun.
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
TH1F * hBGains_[cryInArray_]
MonitorElement * meEEBCaloRedGreenSteps_
void setBinContent(int binx, double content)
set content of bin (1-D)
void endJob(void)
EndJob.
DQMStore * dqmStore_
std::vector< int > superModules_
void setAvgEnergy(float energy)
list step
Definition: launcher.py:15
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.
void setEventsOverLowThreshold(int events)
static std::string sEE(const int ism)
Definition: Numbers.cc:205
void cleanup(void)
Cleanup.
#define abs(x)
Definition: mlp_lapack.h:159
TProfile * hBpulse_[cryInArray_]
static int icEB(const int ism, const int ix, const int iy)
Definition: Numbers.cc:898
virtual ~EEBeamCaloClient()
Destructor.
EEBeamCaloClient(const edm::ParameterSet &ps)
Constructor.
void setup(void)
Setup.
void endRun(void)
EndRun.
void analyze(void)
Analyze.
void removeElement(const std::string &name)
Definition: DQMStore.cc:2353
MonitorElement * meEEBCaloRedGreen_
TProfile * pBCriInBeamEvents_
void beginJob(void)
BeginJob.
MonitorElement * get(const std::string &path) const
get ME from full pathname (e.g. &quot;my/long/dir/my_histo&quot;)
Definition: DQMStore.cc:1265
Ecal Monitor Utils for Client.
static const int cryInArray_
std::string prefixME_
std::vector< int > checkedSteps_
double getBinContent(int binx) const
get content of bin (1-D)
void setEventsOverHighThreshold(int events)
void insertDataArraySet(const std::map< EcalLogicID, DATT > *data, IOVT *iov)
tuple cout
Definition: gather_cfg.py:41
MonitorElement * meEEBCaloRedGreenReadCry_
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:642
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)
TProfile * hBE3x3vsCry_
void setCurrentFolder(const std::string &fullpath)
Definition: DQMStore.cc:232