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