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