Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:10:02

0001 #include "DQM/EcalPreshowerMonitorClient/interface/ESIntegrityClient.h"
0002 
0003 #include "FWCore/ParameterSet/interface/FileInPath.h"
0004 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0005 
0006 #include <fstream>
0007 #include <iomanip>
0008 #include <iostream>
0009 #include <memory>
0010 
0011 using namespace std;
0012 
0013 ESIntegrityClient::ESIntegrityClient(const edm::ParameterSet &ps)
0014     : ESClient(ps),
0015       hFED_(nullptr),
0016       hFiberOff_(nullptr),
0017       hFiberBadStatus_(nullptr),
0018       hKF1_(nullptr),
0019       hKF2_(nullptr),
0020       hKBC_(nullptr),
0021       hKEC_(nullptr),
0022       hL1ADiff_(nullptr),
0023       hBXDiff_(nullptr),
0024       hOrbitNumberDiff_(nullptr),
0025       hSLinkCRCErr_(nullptr) {
0026   // read in look-up table
0027   for (int i = 0; i < 2; ++i)
0028     for (int j = 0; j < 2; ++j)
0029       for (int k = 0; k < 40; ++k)
0030         for (int m = 0; m < 40; ++m) {
0031           fed_[i][j][k][m] = -1;
0032           kchip_[i][j][k][m] = -1;
0033           fiber_[i][j][k][m] = -1;
0034         }
0035 
0036   for (int i = 0; i < 56; ++i) {
0037     fedStatus_[i] = -1;
0038     syncStatus_[i] = -1;
0039     slinkCRCStatus_[i] = -1;
0040     for (int j = 0; j < 36; ++j)
0041       fiberStatus_[i][j] = -1;
0042   }
0043 
0044   for (int i = 0; i < 2; ++i)
0045     for (int j = 0; j < 2; ++j) {
0046       meFED_[i][j] = nullptr;
0047       meKCHIP_[i][j] = nullptr;
0048     }
0049 
0050   std::string lutPath(ps.getUntrackedParameter<edm::FileInPath>("LookupTable").fullPath());
0051 
0052   int nLines, z, iz, ip, ix, iy, fed, kchip, pace, bundle, fiber, optorx;
0053   ifstream file(lutPath);
0054 
0055   if (file.is_open()) {
0056     file >> nLines;
0057 
0058     for (int i = 0; i < nLines; ++i) {
0059       file >> iz >> ip >> ix >> iy >> fed >> kchip >> pace >> bundle >> fiber >> optorx;
0060 
0061       z = (iz == -1) ? 2 : iz;
0062       fed_[z - 1][ip - 1][ix - 1][iy - 1] = fed;
0063       kchip_[z - 1][ip - 1][ix - 1][iy - 1] = kchip;
0064       fiber_[z - 1][ip - 1][ix - 1][iy - 1] = (fiber - 1) + (optorx - 1) * 12;
0065     }
0066 
0067     file.close();
0068   } else {
0069     cout << "ESIntegrityClient : Look up table file can not be found in " << lutPath << endl;
0070   }
0071 }
0072 
0073 ESIntegrityClient::~ESIntegrityClient() {}
0074 
0075 void ESIntegrityClient::book(DQMStore::IBooker &_ibooker) {
0076   char histo[200];
0077 
0078   _ibooker.setCurrentFolder(prefixME_ + "/ESIntegrityClient");
0079 
0080   for (int i = 0; i < 2; ++i)
0081     for (int j = 0; j < 2; ++j) {
0082       int iz = (i == 0) ? 1 : -1;
0083       snprintf(histo, 200, "ES Integrity Summary 1 Z %d P %d", iz, j + 1);
0084       meFED_[i][j] = _ibooker.book2D(histo, histo, 40, 0.5, 40.5, 40, 0.5, 40.5);
0085       meFED_[i][j]->setAxisTitle("Si X", 1);
0086       meFED_[i][j]->setAxisTitle("Si Y", 2);
0087 
0088       snprintf(histo, 200, "ES Integrity Summary 2 Z %d P %d", iz, j + 1);
0089       meKCHIP_[i][j] = _ibooker.book2D(histo, histo, 40, 0.5, 40.5, 40, 0.5, 40.5);
0090       meKCHIP_[i][j]->setAxisTitle("Si X", 1);
0091       meKCHIP_[i][j]->setAxisTitle("Si Y", 2);
0092     }
0093 }
0094 
0095 void ESIntegrityClient::endLumiAnalyze(DQMStore::IGetter &_igetter) {
0096   double nDI_FedErr[56];
0097   for (int i = 0; i < 56; ++i)
0098     nDI_FedErr[i] = 0;
0099 
0100   MonitorElement *me = nullptr;
0101 
0102   me = _igetter.get(prefixME_ + "/ESIntegrityTask/ES FEDs used for data taking");
0103   hFED_ = getHisto(me, cloneME_, hFED_);
0104 
0105   me = _igetter.get(prefixME_ + "/ESIntegrityTask/ES Fiber Off");
0106   hFiberOff_ = getHisto(me, cloneME_, hFiberOff_);
0107 
0108   me = _igetter.get(prefixME_ + "/ESIntegrityTask/ES Fiber Bad Status");
0109   hFiberBadStatus_ = getHisto(me, cloneME_, hFiberBadStatus_);
0110 
0111   me = _igetter.get(prefixME_ + "/ESIntegrityTask/ES SLink CRC Errors");
0112   hSLinkCRCErr_ = getHisto(me, cloneME_, hSLinkCRCErr_);
0113 
0114   int xval = 0;
0115   int nevFEDs = 0;
0116   if (hFED_) {
0117     for (int i = 1; i <= 56; ++i)
0118       if (nevFEDs < hFED_->GetBinContent(i))
0119         nevFEDs = (int)hFED_->GetBinContent(i);
0120   }
0121 
0122   // FED integrity
0123   for (int i = 1; i <= 56; ++i) {
0124     if (hFED_) {
0125       if (hFED_->GetBinContent(i) > 0)
0126         fedStatus_[i - 1] = 1;
0127     }
0128     if (hSLinkCRCErr_) {
0129       if (hSLinkCRCErr_->GetBinContent(i) > 0)
0130         slinkCRCStatus_[i - 1] = 1;
0131     }
0132     for (int j = 0; j < 36; ++j) {
0133       if (hFiberBadStatus_) {
0134         if (hFiberBadStatus_->GetBinContent(i, j + 1) > 0)
0135           fiberStatus_[i - 1][j] = 2;  // bad
0136         else
0137           fiberStatus_[i - 1][j] = 1;  // good
0138       }
0139       if (hFiberOff_)
0140         if (hFiberOff_->GetBinContent(i, j + 1) > 0) {
0141           fiberStatus_[i - 1][j] = 0;  // off
0142         }
0143     }
0144   }
0145 
0146   // obtain MEs from ESRawDataTask
0147   me = _igetter.get(prefixME_ + "/ESRawDataTask/ES L1A DCC errors");
0148   hL1ADiff_ = getHisto(me, cloneME_, hL1ADiff_);
0149 
0150   me = _igetter.get(prefixME_ + "/ESRawDataTask/ES BX DCC errors");
0151   hBXDiff_ = getHisto(me, cloneME_, hBXDiff_);
0152 
0153   me = _igetter.get(prefixME_ + "/ESRawDataTask/ES Orbit Number DCC errors");
0154   hOrbitNumberDiff_ = getHisto(me, cloneME_, hOrbitNumberDiff_);
0155 
0156   for (int i = 1; i <= 56; ++i) {
0157     if (hL1ADiff_ && hBXDiff_) {
0158       if (hL1ADiff_->GetBinContent(i) > 0 || hBXDiff_->GetBinContent(i) > 0) {
0159         syncStatus_[i - 1] = 1;
0160         if (hL1ADiff_->GetBinContent(i) > nDI_FedErr[i - 1])
0161           nDI_FedErr[i - 1] = hL1ADiff_->GetBinContent(i);
0162         if (hBXDiff_->GetBinContent(i) > nDI_FedErr[i - 1])
0163           nDI_FedErr[i - 1] = hBXDiff_->GetBinContent(i);
0164       }
0165     }
0166     // if (hOrbitNumberDiff_->GetBinContent(i) > 0) syncStatus_[i-1] = 1;
0167   }
0168 
0169   // KCHIP integrity
0170   me = _igetter.get(prefixME_ + "/ESIntegrityTask/ES KChip Flag 1 Error codes");
0171   hKF1_ = getHisto(me, cloneME_, hKF1_);
0172 
0173   me = _igetter.get(prefixME_ + "/ESIntegrityTask/ES KChip Flag 2 Error codes");
0174   hKF2_ = getHisto(me, cloneME_, hKF2_);
0175 
0176   me = _igetter.get(prefixME_ + "/ESIntegrityTask/ES KChip BC mismatch with OptoRX");
0177   hKBC_ = getHisto(me, cloneME_, hKBC_);
0178 
0179   me = _igetter.get(prefixME_ + "/ESIntegrityTask/ES KChip EC mismatch with OptoRX");
0180   hKEC_ = getHisto(me, cloneME_, hKEC_);
0181 
0182   Int_t kchip_xval[1550];
0183   for (int i = 0; i < 1550; ++i) {
0184     xval = 3;
0185     Int_t kErr = 0;
0186     for (int j = 1; j < 16; ++j) {
0187       if (hKF1_) {
0188         if (hKF1_->GetBinContent(i, j + 1) > 0) {
0189           xval = 2;
0190           kErr++;
0191         }
0192       }
0193       if (hKF2_) {
0194         if (hKF2_->GetBinContent(i, j + 1) > 0) {
0195           xval = 4;
0196           kErr++;
0197         }
0198       }
0199     }
0200     if (hKBC_) {
0201       if (hKBC_->GetBinContent(i) > 0) {
0202         xval = 5;
0203         kErr++;
0204       }
0205     }
0206     if (hKEC_) {
0207       if (hKEC_->GetBinContent(i) > 0) {
0208         xval = 6;
0209         kErr++;
0210       }
0211     }
0212     if (kErr > 1)
0213       xval = 7;
0214     kchip_xval[i] = xval;
0215   }
0216 
0217   // detailed KCHIP summary (i.e. summary 2)
0218   for (int iz = 0; iz < 2; ++iz)
0219     for (int ip = 0; ip < 2; ++ip)
0220       for (int ix = 0; ix < 40; ++ix)
0221         for (int iy = 0; iy < 40; ++iy) {
0222           if (fed_[iz][ip][ix][iy] == -1)
0223             continue;
0224           if (fedStatus_[fed_[iz][ip][ix][iy] - 520] == -1 ||
0225               fiberStatus_[fed_[iz][ip][ix][iy] - 520][fiber_[iz][ip][ix][iy]] == 0)
0226             kchip_xval[kchip_[iz][ip][ix][iy] - 1] = 0;
0227           if ((kchip_[iz][ip][ix][iy] - 2) >= 0)
0228             meKCHIP_[iz][ip]->setBinContent(ix + 1, iy + 1, kchip_xval[kchip_[iz][ip][ix][iy] - 2]);
0229         }
0230 
0231   // FED, Fiber, KCHIP summary (i.e. summary 1)
0232   Int_t nErr = 0;
0233   for (int iz = 0; iz < 2; ++iz)
0234     for (int ip = 0; ip < 2; ++ip)
0235       for (int ix = 0; ix < 40; ++ix)
0236         for (int iy = 0; iy < 40; ++iy) {
0237           if (fed_[iz][ip][ix][iy] == -1)
0238             continue;
0239           nErr = 0;
0240 
0241           if (fedStatus_[fed_[iz][ip][ix][iy] - 520] == 1) {
0242             if (hFED_) {
0243               if (hFED_->GetBinContent(fed_[iz][ip][ix][iy] - 520 + 1) == nevFEDs)
0244                 xval = 3;
0245               else {
0246                 xval = 4;  // FED problem
0247                 nErr++;
0248               }
0249             }
0250 
0251             if (fiberStatus_[fed_[iz][ip][ix][iy] - 520][fiber_[iz][ip][ix][iy]] == 2) {
0252               xval = 2;  // fiber problem
0253               nErr++;
0254             }
0255             if (fiberStatus_[fed_[iz][ip][ix][iy] - 520][fiber_[iz][ip][ix][iy]] == 0) {
0256               xval = 0;  // fiber off
0257             }
0258             if (kchip_xval[kchip_[iz][ip][ix][iy] - 1] != 3 && kchip_xval[kchip_[iz][ip][ix][iy] - 1] != 0) {
0259               xval = 5;  // kchip problem
0260               nErr++;
0261             }
0262             if (syncStatus_[fed_[iz][ip][ix][iy] - 520] == 1) {
0263               xval = 6;
0264               nErr++;
0265             }
0266             if (slinkCRCStatus_[fed_[iz][ip][ix][iy] - 520] == 1) {
0267               xval = 8;
0268               nErr++;
0269             }
0270             if (nErr > 1)
0271               xval = 7;
0272           } else if (fedStatus_[fed_[iz][ip][ix][iy] - 520] == -1) {
0273             xval = 0;
0274           }
0275 
0276           meFED_[iz][ip]->setBinContent(ix + 1, iy + 1, xval);
0277         }
0278 }