CMS 3D CMS Logo

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