CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
ESIntegrityTask.cc
Go to the documentation of this file.
1 #include <iostream>
2 #include <fstream>
3 #include <vector>
4 
9 
12 
19 
21 
22 using namespace cms;
23 using namespace edm;
24 using namespace std;
25 
27 
28  init_ = false;
29 
30  dqmStore_ = Service<DQMStore>().operator->();
31 
32  prefixME_ = ps.getUntrackedParameter<string>("prefixME", "");
33  enableCleanup_ = ps.getUntrackedParameter<bool>("enableCleanup", false);
34  mergeRuns_ = ps.getUntrackedParameter<bool>("mergeRuns", false);
35  lookup_ = ps.getUntrackedParameter<FileInPath>("LookupTable");
36 
37  dccCollections_ = consumes<ESRawDataCollection>(ps.getParameter<InputTag>("ESDCCCollections"));
38  kchipCollections_ = consumes<ESLocalRawDataCollection>(ps.getParameter<InputTag>("ESKChipCollections"));
39 
40  doLumiAnalysis_ = ps.getParameter<bool>("DoLumiAnalysis");
41 
42  // read in look-up table
43  for (int i=0; i<2; ++i)
44  for (int j=0; j<2; ++j)
45  for (int k=0; k<40; ++k)
46  for (int m=0; m<40; ++m) {
47  fed_[i][j][k][m] = -1;
48  kchip_[i][j][k][m] = -1;
49  fiber_[i][j][k][m] = -1;
50  }
51 
52  int nLines_, z, iz, ip, ix, iy, fed, kchip, pace, bundle, fiber, optorx;
53  ifstream file;
54  file.open(lookup_.fullPath().c_str());
55  if( file.is_open() ) {
56 
57  file >> nLines_;
58 
59  for (int i=0; i<nLines_; ++i) {
60  file>> iz >> ip >> ix >> iy >> fed >> kchip >> pace >> bundle >> fiber >> optorx;
61 
62  z = (iz==-1) ? 2:iz;
63  fed_[z-1][ip-1][ix-1][iy-1] = fed;
64  kchip_[z-1][ip-1][ix-1][iy-1] = kchip;
65  fiber_[z-1][ip-1][ix-1][iy-1] = (fiber-1)+(optorx-1)*12;
66  }
67  }
68  else {
69  cout<<"ESIntegrityTask : Look up table file can not be found in "<<lookup_.fullPath().c_str()<<endl;
70  }
71 
72 }
73 
75 }
76 
78 
79  ievt_ = 0;
80 
81  if ( dqmStore_ ) {
82  dqmStore_->setCurrentFolder(prefixME_ + "/ESIntegrityTask");
83  dqmStore_->rmdir(prefixME_ + "/ESIntegrityTask");
84  }
85 
86 }
87 
88 void ESIntegrityTask::beginRun(const Run& r, const EventSetup& c) {
89 
90  if ( ! init_ ) this->setup();
91  if ( ! mergeRuns_ ) this->reset();
92 
93 }
94 
95 void ESIntegrityTask::endRun(const Run& r, const EventSetup& c) {
96  // In case of Lumi based analysis Disable SoftReset from Integrity histogram to get full statistics
97  if (doLumiAnalysis_) {
98  for (int i=0; i<2; ++i) {
99  for (int j=0; j<2; ++j) {
100  if (meDIErrors_[i][j]) {
101  dqmStore_->disableSoftReset(meDIErrors_[i][j]);
102  }
103  }
104  }
105  }
106 }
107 
109 
110  LogInfo("ESIntegrityTask") << "analyzed " << ievt_ << " events";
111  // In case of Lumi based analysis SoftReset the Integrity histogram
112  if (doLumiAnalysis_) {
113  for (int i=0; i<2; ++i) {
114  for (int j=0; j<2; ++j) {
115  if (meDIErrors_[i][j]) {
116  dqmStore_->softReset(meDIErrors_[i][j]);
117  }
118  }
119  }
120  ievt_ = 0;
121  }
122 }
123 
125  if (doLumiAnalysis_) calculateDIFraction();
126 }
127 
129  /*
130  if ( meFED_ ) meFED_->Reset();
131  if ( meGain_ ) meGain_->Reset();
132  if ( meDCCErr_ ) meDCCErr_->Reset();
133  if ( meOptoRX_ ) meOptoRX_->Reset();
134  if ( meOptoBC_ ) meOptoBC_->Reset();
135  if ( meFiberStatus_ ) meFiberStatus_->Reset();
136  if ( meKF1_ ) meKF1_->Reset();
137  if ( meKF2_ ) meKF2_->Reset();
138  if ( meKBC_ ) meKBC_->Reset();
139  if ( meKEC_ ) meKEC_->Reset();
140  */
141 }
142 
144 
145  init_ = true;
146 
147  char histo[200];
148 
149  if (dqmStore_) {
150  dqmStore_->setCurrentFolder(prefixME_ + "/ESIntegrityTask");
151 
152  sprintf(histo, "ES FEDs used for data taking");
153  meFED_ = dqmStore_->book1D(histo, histo, 56, 519.5, 575.5);
154  meFED_->setAxisTitle("ES FED", 1);
155  meFED_->setAxisTitle("Num of Events", 2);
156 
157  sprintf(histo, "ES Gain used for data taking");
158  meGain_ = dqmStore_->book1D(histo, histo, 2, -0.5, 1.5);
159  meGain_->setAxisTitle("ES Gain", 1);
160  meGain_->setAxisTitle("Num of Events", 2);
161 
162  sprintf(histo, "ES DCC Error codes");
163  meDCCErr_ = dqmStore_->book2D(histo, histo, 56, 519.5, 575.5, 6, -0.5, 5.5);
164  meDCCErr_->setAxisTitle("ES FED", 1);
165  meDCCErr_->setAxisTitle("ES DCC Error code", 2);
166 
167  sprintf(histo, "ES SLink CRC Errors");
168  meSLinkCRCErr_ = dqmStore_->book1D(histo, histo, 56, 519.5, 575.5);
169  meSLinkCRCErr_->setAxisTitle("ES FED", 1);
170  meSLinkCRCErr_->setAxisTitle("Num of Events", 2);
171 
172  sprintf(histo, "ES DCC CRC Errors");
173  meDCCCRCErr_ = dqmStore_->book2D(histo, histo, 56, 519.5, 575.5, 3, -0.5, 2.5);
174  meDCCCRCErr_->setAxisTitle("ES FED", 1);
175  meDCCCRCErr_->setAxisTitle("ES OptoRX", 2);
176 
177  sprintf(histo, "ES OptoRX used for data taking");
178  meOptoRX_ = dqmStore_->book2D(histo, histo, 56, 519.5, 575.5, 3, -0.5, 2.5);
179  meOptoRX_->setAxisTitle("ES FED", 1);
180  meOptoRX_->setAxisTitle("ES OptoRX", 2);
181 
182  sprintf(histo, "ES OptoRX BC mismatch");
183  meOptoBC_ = dqmStore_->book2D(histo, histo, 56, 519.5, 575.5, 3, -0.5, 2.5);
184  meOptoBC_->setAxisTitle("ES FED", 1);
185  meOptoBC_->setAxisTitle("ES OptoRX", 2);
186 
187  sprintf(histo, "ES Fiber Bad Status");
188  meFiberBadStatus_ = dqmStore_->book2D(histo, histo, 56, 519.5, 575.5, 36, 0.5, 36.5);
189  meFiberBadStatus_->setAxisTitle("ES FED", 1);
190  meFiberBadStatus_->setAxisTitle("Fiber Number", 2);
191 
192  sprintf(histo, "ES Fiber Error Code");
193  meFiberErrCode_ = dqmStore_->book1D(histo, histo, 17, -0.5, 16.5);
194  meFiberErrCode_->setAxisTitle("Fiber Error Code", 1);
195 
196  sprintf(histo, "ES Fiber Off");
197 
198  meFiberOff_ = dqmStore_->book2D(histo, histo, 56, 519.5, 575.5, 36, 0.5, 36.5);
199  meFiberOff_->setAxisTitle("ES FED", 1);
200  meFiberOff_->setAxisTitle("Fiber Number", 2);
201 
202  sprintf(histo, "ES Warning Event Dropped");
203  meEVDR_ = dqmStore_->book2D(histo, histo, 56, 519.5, 575.5, 36, 0.5, 36.5);
204  meEVDR_->setAxisTitle("ES FED", 1);
205  meEVDR_->setAxisTitle("Fiber Number", 2);
206 
207  sprintf(histo, "ES KChip Flag 1 Error codes");
208  meKF1_ = dqmStore_->book2D(histo, histo, 1550, -0.5, 1549.5, 16, -0.5, 15.5);
209  meKF1_->setAxisTitle("ES KChip", 1);
210  meKF1_->setAxisTitle("ES KChip F1 Error Code ", 2);
211 
212  sprintf(histo, "ES KChip Flag 2 Error codes");
213  meKF2_ = dqmStore_->book2D(histo, histo, 1550, -0.5, 1549.5, 16, -0.5, 15.5);
214  meKF2_->setAxisTitle("ES KChip", 1);
215  meKF2_->setAxisTitle("ES KChip F1 Error Code ", 2);
216 
217  sprintf(histo, "ES KChip BC mismatch with OptoRX");
218  meKBC_ = dqmStore_->book1D(histo, histo, 1550, -0.5, 1549.5);
219  meKBC_->setAxisTitle("ES KChip", 1);
220  meKBC_->setAxisTitle("Num of BC mismatch", 2);
221 
222  sprintf(histo, "ES KChip EC mismatch with OptoRX");
223  meKEC_ = dqmStore_->book1D(histo, histo, 1550, -0.5, 1549.5);
224  meKEC_->setAxisTitle("ES KChip", 1);
225  meKEC_->setAxisTitle("Num of EC mismatch", 2);
226 
227  for (int i=0; i<2; ++i)
228  for (int j=0; j<2; ++j) {
229  int iz = (i==0)? 1:-1;
230  sprintf(histo, "ES Integrity Errors Z %d P %d", iz, j+1);
231  meDIErrors_[i][j] = dqmStore_->book2D(histo, histo, 40, 0.5, 40.5, 40, 0.5, 40.5);
232  meDIErrors_[i][j]->setAxisTitle("Si X", 1);
233  meDIErrors_[i][j]->setAxisTitle("Si Y", 2);
234  }
235 
236  if (doLumiAnalysis_) {
237  sprintf(histo, "ES Good Channel Fraction");
238  meDIFraction_ = dqmStore_->book2D(histo, histo, 3, 1.0, 3.0, 3, 1.0, 3.0);
239  meDIFraction_->setLumiFlag();
240  }
241  }
242 
243 
244 }
245 
247 
248  if ( ! init_ ) return;
249 
250  if ( dqmStore_ ) {
251 
252  }
253 
254  init_ = false;
255 
256 }
257 
259 
260  LogInfo("ESIntegrityTask") << "analyzed " << ievt_ << " events";
261 
262  if ( enableCleanup_ ) this->cleanup();
263 
264 }
265 
267 
268  if ( ! init_ ) this->setup();
269 
270  ievt_++;
271 
274 
275  // Fill # of events
276  meDCCErr_->Fill(575, 2, 1);
277  meDCCCRCErr_->Fill(575, 2, 1);
278  meOptoRX_->Fill(575, 2, 1);
279  meOptoBC_->Fill(575, 2, 1);
280  meFiberBadStatus_->Fill(575, 36, 1);
281  meFiberOff_->Fill(575, 36, 1);
282  meEVDR_->Fill(575, 36, 1);
283 
284  // # of DI errors
285  Double_t nDIErr[56][36];
286  for (int i=0; i<56; ++i)
287  for (int j=0; j<36; ++j)
288  nDIErr[i][j] = 0;
289 
290  // DCC
291  vector<int> fiberStatus;
292  if ( e.getByToken(dccCollections_, dccs) ) {
293 
294  for (ESRawDataCollection::const_iterator dccItr = dccs->begin(); dccItr != dccs->end(); ++dccItr) {
295  ESDCCHeaderBlock dcc = (*dccItr);
296 
297  meFED_->Fill(dcc.fedId());
298 
299  meDCCErr_->Fill(dcc.fedId(), dcc.getDCCErrors());
300 
301  // SLink CRC error
302  if (dcc.getDCCErrors() == 101) {
303  meSLinkCRCErr_->Fill(dcc.fedId());
304  for (int j=0; j<36; ++j) nDIErr[dcc.fedId()-520][j]++;
305  }
306 
307  if (dcc.getOptoRX0() == 129) {
308  meOptoRX_->Fill(dcc.fedId(), 0);
309  if (((dcc.getOptoBC0()-15) & 0x0fff) != dcc.getBX()) meOptoBC_->Fill(dcc.fedId(), 0);
310  }
311  if (dcc.getOptoRX1() == 129) {
312  meOptoRX_->Fill(dcc.fedId(), 1);
313  if (((dcc.getOptoBC1()-15) & 0x0fff) != dcc.getBX()) meOptoBC_->Fill(dcc.fedId(), 1);
314  }
315  if (dcc.getOptoRX2() == 129) {
316  meOptoRX_->Fill(dcc.fedId(), 2);
317  if (((dcc.getOptoBC2()-15) & 0x0fff) != dcc.getBX()) meOptoBC_->Fill(dcc.fedId(), 2);
318  }
319 
320  if (dcc.getOptoRX0() == 128) {
321  meDCCCRCErr_->Fill(dcc.fedId(), 0);
322  for (int j=0; j<12; ++j) nDIErr[dcc.fedId()-520][j]++;
323  }
324  if (dcc.getOptoRX1() == 128) {
325  meDCCCRCErr_->Fill(dcc.fedId(), 1);
326  for (int j=12; j<24; ++j) nDIErr[dcc.fedId()-520][j]++;
327  }
328  if (dcc.getOptoRX2() == 128) {
329  meDCCCRCErr_->Fill(dcc.fedId(), 2);
330  for (int j=24; j<36; ++j) nDIErr[dcc.fedId()-520][j]++;
331  }
332 
333  fiberStatus = dcc.getFEChannelStatus();
334 
335  for (unsigned int i=0; i<fiberStatus.size(); ++i) {
336  if (fiberStatus[i]==4 || fiberStatus[i]==8 || fiberStatus[i]==10 || fiberStatus[i]==11 || fiberStatus[i]==12) {
337  meFiberBadStatus_->Fill(dcc.fedId(), i+1, 1);
338  meFiberErrCode_->Fill(fiberStatus[i]);
339  nDIErr[dcc.fedId()-520][i]++;
340  }
341  if (fiberStatus[i]==7)
342  meFiberOff_->Fill(dcc.fedId(), i+1, 1);
343  if (fiberStatus[i]==6) {
344  meFiberErrCode_->Fill(fiberStatus[i]);
345  meEVDR_->Fill(dcc.fedId(), i+1, 1);
346  }
347  }
348 
349  runtype_ = dcc.getRunType();
350  seqtype_ = dcc.getSeqType();
351  dac_ = dcc.getDAC();
352  gain_ = dcc.getGain();
353  precision_ = dcc.getPrecision();
354 
355  meGain_->Fill(gain_);
356  }
357  } else {
358  LogWarning("ESIntegrityTask") << "dccCollections not available";
359  }
360 
361  // KCHIP's
362  if ( e.getByToken(kchipCollections_, kchips) ) {
363 
364  for (ESLocalRawDataCollection::const_iterator kItr = kchips->begin(); kItr != kchips->end(); ++kItr) {
365 
366  ESKCHIPBlock kchip = (*kItr);
367 
368  meKF1_->Fill(kchip.id(), kchip.getFlag1());
369  meKF2_->Fill(kchip.id(), kchip.getFlag2());
370  if (kchip.getBC() != kchip.getOptoBC()) meKBC_->Fill(kchip.id());
371  if (kchip.getEC() != kchip.getOptoEC()) meKEC_->Fill(kchip.id());
372  }
373  } else {
374  LogWarning("ESIntegrityTask") << "kchipCollections not available";
375  }
376 
377  // Fill # of DI errors
378  for (int iz=0; iz<2; ++iz)
379  for (int ip=0; ip<2; ++ip)
380  for (int ix=0; ix<40; ++ix)
381  for (int iy=0; iy<40; ++iy) {
382 
383  if (fed_[iz][ip][ix][iy] == -1) continue;
384 
385  if (nDIErr[fed_[iz][ip][ix][iy]-520][fiber_[iz][ip][ix][iy]] > 0)
386  meDIErrors_[iz][ip]->Fill(ix+1, iy+1, 1);
387 
388  }
389 
390 }
391 //
392 // -- Calculate Data Integrity Fraction
393 //
395 
396  float nValidChannels=0;
397  float nGlobalErrors=0;
398 
399  for (int i=0; i<2; ++i) {
400  for (int j=0; j<2; ++j) {
401  float nValidChannelsES=0;
402  float nGlobalErrorsES = 0;
403  float reportSummaryES = -1;
404  if (!meDIErrors_[i][j]) continue;
405  for (int x=0; x<40; ++x) {
406  for (int y=0; y<40; ++y) {
407  float val = meDIErrors_[i][j]->getBinContent(x+1, y+1);
408  if (fed_[i][j][x][y] == -1) continue;
409  if (ievt_ != 0) nGlobalErrors += val/ievt_;
410  nValidChannels++;
411  if (ievt_ != 0) nGlobalErrorsES += val/ievt_;
412  nValidChannelsES++;
413  }
414  }
415  if (nValidChannelsES != 0) reportSummaryES = 1 - nGlobalErrorsES/nValidChannelsES;
416  meDIFraction_->setBinContent(i+1, j+1, reportSummaryES);
417  }
418  }
419  float reportSummary = -1.0;
420  if (nValidChannels != 0) reportSummary = 1.0 - nGlobalErrors/nValidChannels;
421  meDIFraction_->setBinContent(3,3, reportSummary);
422 }
T getParameter(std::string const &) const
int getOptoBC2() const
int getGain() const
T getUntrackedParameter(std::string const &, T const &) const
int i
Definition: DBlmapReader.cc:9
const int & id() const
Definition: ESKCHIPBlock.h:15
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:434
tuple lumi
Definition: fjr2json.py:35
std::vector< ESDCCHeaderBlock >::const_iterator const_iterator
int getEC() const
Definition: ESKCHIPBlock.h:36
static void cleanup(const Factory::MakerMap::value_type &v)
Definition: Factory.cc:12
int getOptoRX0() const
int getOptoRX1() const
int getFlag1() const
Definition: ESKCHIPBlock.h:39
int getBC() const
Definition: ESKCHIPBlock.h:35
virtual ~ESIntegrityTask()
void beginRun(const edm::Run &r, const edm::EventSetup &c)
BeginRun.
void endJob(void)
EndJob.
float float float z
int getOptoBC1() const
const std::vector< int > & getFEChannelStatus() const
void cleanup(void)
Cleanup.
int getBX() const
void endRun(const edm::Run &r, const edm::EventSetup &c)
EndRun.
void endLuminosityBlock(const edm::LuminosityBlock &lumi, const edm::EventSetup &c)
End Lumi.
void beginLuminosityBlock(const edm::LuminosityBlock &lumi, const edm::EventSetup &c)
Begin Lumi.
int getRunType() const
void calculateDIFraction(void)
Calculate Data Integrity Fraction.
int getFlag2() const
Definition: ESKCHIPBlock.h:40
int j
Definition: DBlmapReader.cc:9
void reset(void)
Reset.
int getSeqType() const
int getOptoEC() const
Definition: ESKCHIPBlock.h:38
void analyze(const edm::Event &e, const edm::EventSetup &c)
Analyze.
int k[5][pyjets_maxn]
DEFINE_FWK_MODULE(CaloMETProducer)
int getOptoBC0() const
int getPrecision() const
int getDCCErrors() const
static const char gain_[]
int getDAC() const
int getOptoBC() const
Definition: ESKCHIPBlock.h:37
tuple cout
Definition: gather_cfg.py:121
ESIntegrityTask(const edm::ParameterSet &ps)
void setup(void)
Setup.
const int fedId() const
Definition: DDAxes.h:10
int getOptoRX2() const
void beginJob(void)
BeginJob.
void reset(double vett[256])
Definition: TPedValues.cc:11
void setup(std::vector< TH2F > &depth, std::string name, std::string units="")
Definition: Run.h:41