00001 #include <memory>
00002 #include <iostream>
00003 #include <fstream>
00004 #include <iomanip>
00005
00006 #include "DQMServices/Core/interface/DQMStore.h"
00007
00008 #include "DQM/EcalCommon/interface/UtilsClient.h"
00009 #include "DQM/EcalPreshowerMonitorClient/interface/ESIntegrityClient.h"
00010
00011 using namespace edm;
00012 using namespace std;
00013
00014 ESIntegrityClient::ESIntegrityClient(const ParameterSet& ps) {
00015
00016 cloneME_ = ps.getUntrackedParameter<bool>("cloneME", true);
00017 verbose_ = ps.getUntrackedParameter<bool>("verbose", true);
00018 debug_ = ps.getUntrackedParameter<bool>("debug", false);
00019 prefixME_ = ps.getUntrackedParameter<string>("prefixME", "");
00020 enableCleanup_ = ps.getUntrackedParameter<bool>("enableCleanup", false);
00021 lookup_ = ps.getUntrackedParameter<FileInPath>("LookupTable", edm::FileInPath("EventFilter/ESDigiToRaw/data/ES_lookup_table.dat"));
00022
00023
00024 for (int i=0; i<2; ++i)
00025 for (int j=0; j<2; ++j)
00026 for (int k=0; k<40; ++k)
00027 for (int m=0; m<40; ++m) {
00028 fed_[i][j][k][m] = -1;
00029 kchip_[i][j][k][m] = -1;
00030 }
00031
00032 for (int i=0; i<56; ++i) {
00033 fedStatus_[i] = -1;
00034 syncStatus_[i] = -1;
00035 slinkCRCStatus_[i] = -1;
00036 for (int j=0; j<36; ++j)
00037 fiberStatus_[i][j] = -1;
00038 }
00039
00040 int nLines_, z, iz, ip, ix, iy, fed, kchip, pace, bundle, fiber, optorx;
00041 ifstream file;
00042 file.open(lookup_.fullPath().c_str());
00043 if( file.is_open() ) {
00044
00045 file >> nLines_;
00046
00047 for (int i=0; i<nLines_; ++i) {
00048 file>> iz >> ip >> ix >> iy >> fed >> kchip >> pace >> bundle >> fiber >> optorx;
00049
00050 z = (iz==-1) ? 2:iz;
00051 fed_[z-1][ip-1][ix-1][iy-1] = fed;
00052 kchip_[z-1][ip-1][ix-1][iy-1] = kchip;
00053 fiber_[z-1][ip-1][ix-1][iy-1] = (fiber-1)+(optorx-1)*12;
00054 }
00055 }
00056 else {
00057 cout<<"ESIntegrityClient : Look up table file can not be found in "<<lookup_.fullPath().c_str()<<endl;
00058 }
00059
00060 hFED_ = 0;
00061 hFiberOff_ = 0;
00062 hFiberBadStatus_ = 0;
00063 hKF1_ = 0;
00064 hKF2_ = 0;
00065 hKBC_ = 0;
00066 hKEC_ = 0;
00067 hL1ADiff_ = 0;
00068 hBXDiff_ = 0;
00069 hOrbitNumberDiff_ = 0;
00070 hSLinkCRCErr_ = 0;
00071
00072 ievt_ = 0;
00073 jevt_ = 0;
00074 }
00075
00076 ESIntegrityClient::~ESIntegrityClient() {
00077 }
00078
00079 void ESIntegrityClient::beginJob(DQMStore* dqmStore) {
00080
00081 dqmStore_ = dqmStore;
00082
00083 if ( debug_ ) cout << "ESIntegrityClient: beginJob" << endl;
00084
00085 ievt_ = 0;
00086 jevt_ = 0;
00087 }
00088
00089 void ESIntegrityClient::beginRun(void) {
00090
00091 if ( debug_ ) cout << "ESIntegrityClient: beginRun" << endl;
00092
00093 jevt_ = 0;
00094
00095 this->setup();
00096
00097 }
00098
00099 void ESIntegrityClient::endJob(void) {
00100
00101 if ( debug_ ) cout << "ESIntegrityClient: endJob, ievt = " << ievt_ << endl;
00102
00103 this->cleanup();
00104
00105 }
00106
00107 void ESIntegrityClient::endRun(void) {
00108
00109 if ( debug_ ) cout << "ESIntegrityClient: endRun, jevt = " << jevt_ << endl;
00110
00111 this->cleanup();
00112
00113 }
00114
00115 void ESIntegrityClient::setup(void) {
00116
00117 char histo[200];
00118
00119 dqmStore_->setCurrentFolder( prefixME_ + "/ESIntegrityClient" );
00120
00121 for (int i=0 ; i<2; ++i)
00122 for (int j=0 ; j<2; ++j) {
00123 int iz = (i==0)? 1:-1;
00124 snprintf(histo, 200, "ES Integrity Summary 1 Z %d P %d", iz, j+1);
00125 meFED_[i][j] = dqmStore_->book2D(histo, histo, 40, 0.5, 40.5, 40, 0.5, 40.5);
00126 meFED_[i][j]->setAxisTitle("Si X", 1);
00127 meFED_[i][j]->setAxisTitle("Si Y", 2);
00128
00129 snprintf(histo, 200, "ES Integrity Summary 2 Z %d P %d", iz, j+1);
00130 meKCHIP_[i][j] = dqmStore_->book2D(histo, histo, 40, 0.5, 40.5, 40, 0.5, 40.5);
00131 meKCHIP_[i][j]->setAxisTitle("Si X", 1);
00132 meKCHIP_[i][j]->setAxisTitle("Si Y", 2);
00133 }
00134 }
00135
00136 void ESIntegrityClient::cleanup(void) {
00137
00138 if ( ! enableCleanup_ ) return;
00139
00140 }
00141
00142 void ESIntegrityClient::analyze(void) {
00143
00144 double nDI_FedErr[56];
00145 for (int i=0; i<56; ++i) nDI_FedErr[i] = 0;
00146
00147 MonitorElement* me = 0;
00148
00149 me = dqmStore_->get(prefixME_ + "/ESIntegrityTask/ES FEDs used for data taking");
00150 hFED_ = UtilsClient::getHisto<TH1F*>( me, cloneME_, hFED_ );
00151
00152 me = dqmStore_->get(prefixME_ + "/ESIntegrityTask/ES Fiber Off");
00153 hFiberOff_ = UtilsClient::getHisto<TH2F*>( me, cloneME_, hFiberOff_ );
00154
00155 me = dqmStore_->get(prefixME_ + "/ESIntegrityTask/ES Fiber Bad Status");
00156 hFiberBadStatus_ = UtilsClient::getHisto<TH2F*>( me, cloneME_, hFiberBadStatus_ );
00157
00158 me = dqmStore_->get(prefixME_ + "/ESIntegrityTask/ES SLink CRC Errors");
00159 hSLinkCRCErr_ = UtilsClient::getHisto<TH1F*>( me, cloneME_, hSLinkCRCErr_ );
00160
00161 int xval = 0;
00162 int nevFEDs = 0;
00163 if (hFED_) {
00164 for (int i=1; i<=56; ++i)
00165 if (nevFEDs < hFED_->GetBinContent(i))
00166 nevFEDs = (int) hFED_->GetBinContent(i);
00167 }
00168
00169
00170 for (int i=1; i<=56; ++i) {
00171 if (hFED_) {
00172 if (hFED_->GetBinContent(i) > 0)
00173 fedStatus_[i-1] = 1;
00174 }
00175 if (hSLinkCRCErr_) {
00176 if (hSLinkCRCErr_->GetBinContent(i) > 0)
00177 slinkCRCStatus_[i-1] = 1;
00178 }
00179 for (int j=0; j<36; ++j) {
00180 if (hFiberBadStatus_) {
00181 if (hFiberBadStatus_->GetBinContent(i, j+1) > 0)
00182 fiberStatus_[i-1][j] = 2;
00183 else
00184 fiberStatus_[i-1][j] = 1;
00185 }
00186 if (hFiberOff_)
00187 if (hFiberOff_->GetBinContent(i, j+1) > 0) {
00188 fiberStatus_[i-1][j] = 0;
00189 }
00190 }
00191 }
00192
00193
00194 me = dqmStore_->get(prefixME_ + "/ESRawDataTask/ES L1A DCC errors");
00195 hL1ADiff_ = UtilsClient::getHisto<TH1F*>( me, cloneME_, hL1ADiff_ );
00196
00197 me = dqmStore_->get(prefixME_ + "/ESRawDataTask/ES BX DCC errors");
00198 hBXDiff_ = UtilsClient::getHisto<TH1F*>( me, cloneME_, hBXDiff_ );
00199
00200 me = dqmStore_->get(prefixME_ + "/ESRawDataTask/ES Orbit Number DCC errors");
00201 hOrbitNumberDiff_ = UtilsClient::getHisto<TH1F*>( me, cloneME_, hOrbitNumberDiff_ );
00202
00203 for (int i=1; i<=56; ++i) {
00204 if (hL1ADiff_ && hBXDiff_) {
00205 if (hL1ADiff_->GetBinContent(i) > 0 || hBXDiff_->GetBinContent(i) > 0) {
00206 syncStatus_[i-1] = 1;
00207 if (hL1ADiff_->GetBinContent(i) > nDI_FedErr[i-1]) nDI_FedErr[i-1] = hL1ADiff_->GetBinContent(i);
00208 if (hBXDiff_->GetBinContent(i) > nDI_FedErr[i-1]) nDI_FedErr[i-1] = hBXDiff_->GetBinContent(i);
00209 }
00210 }
00211
00212 }
00213
00214
00215 me = dqmStore_->get(prefixME_ + "/ESIntegrityTask/ES KChip Flag 1 Error codes");
00216 hKF1_ = UtilsClient::getHisto<TH2F*>( me, cloneME_, hKF1_ );
00217
00218 me = dqmStore_->get(prefixME_ + "/ESIntegrityTask/ES KChip Flag 2 Error codes");
00219 hKF2_ = UtilsClient::getHisto<TH2F*>( me, cloneME_, hKF2_ );
00220
00221 me = dqmStore_->get(prefixME_ + "/ESIntegrityTask/ES KChip BC mismatch with OptoRX");
00222 hKBC_ = UtilsClient::getHisto<TH1F*>( me, cloneME_, hKBC_ );
00223
00224 me = dqmStore_->get(prefixME_ + "/ESIntegrityTask/ES KChip EC mismatch with OptoRX");
00225 hKEC_ = UtilsClient::getHisto<TH1F*>( me, cloneME_, hKEC_ );
00226
00227 Int_t kchip_xval[1550];
00228 for (int i=0; i<1550; ++i) {
00229
00230 xval = 3;
00231 Int_t kErr = 0;
00232 for (int j=1; j<16; ++j) {
00233 if (hKF1_) {
00234 if (hKF1_->GetBinContent(i, j+1)>0) {
00235 xval = 2;
00236 kErr++;
00237 }
00238 }
00239 if (hKF2_) {
00240 if (hKF2_->GetBinContent(i, j+1)>0) {
00241 xval = 4;
00242 kErr++;
00243 }
00244 }
00245 }
00246 if (hKBC_) {
00247 if (hKBC_->GetBinContent(i)>0) {
00248 xval = 5;
00249 kErr++;
00250 }
00251 }
00252 if (hKEC_) {
00253 if (hKEC_->GetBinContent(i)>0) {
00254 xval = 6;
00255 kErr++;
00256 }
00257 }
00258 if (kErr>1) xval = 7;
00259 kchip_xval[i] = xval;
00260 }
00261
00262
00263 for (int iz=0; iz<2; ++iz)
00264 for (int ip=0; ip<2; ++ip)
00265 for (int ix=0; ix<40; ++ix)
00266 for (int iy=0; iy<40; ++iy) {
00267 if (fed_[iz][ip][ix][iy] == -1) continue;
00268 if (fedStatus_[fed_[iz][ip][ix][iy]-520]==-1 || fiberStatus_[fed_[iz][ip][ix][iy]-520][fiber_[iz][ip][ix][iy]] == 0)
00269 kchip_xval[kchip_[iz][ip][ix][iy]-1] = 0;
00270 if ((kchip_[iz][ip][ix][iy]-2) >= 0)
00271 meKCHIP_[iz][ip]->setBinContent(ix+1, iy+1, kchip_xval[kchip_[iz][ip][ix][iy]-2]);
00272 }
00273
00274
00275 Int_t nErr = 0;
00276 for (int iz=0; iz<2; ++iz)
00277 for (int ip=0; ip<2; ++ip)
00278 for (int ix=0; ix<40; ++ix)
00279 for (int iy=0; iy<40; ++iy) {
00280
00281 if (fed_[iz][ip][ix][iy] == -1) continue;
00282 nErr = 0;
00283
00284 if (fedStatus_[fed_[iz][ip][ix][iy]-520] == 1) {
00285
00286 if (hFED_) {
00287 if (hFED_->GetBinContent(fed_[iz][ip][ix][iy]-520+1) == nevFEDs)
00288 xval = 3;
00289 else {
00290 xval = 4;
00291 nErr++;
00292 }
00293 }
00294
00295 if (fiberStatus_[fed_[iz][ip][ix][iy]-520][fiber_[iz][ip][ix][iy]] == 2) {
00296 xval = 2;
00297 nErr++;
00298 }
00299 if (fiberStatus_[fed_[iz][ip][ix][iy]-520][fiber_[iz][ip][ix][iy]] == 0) {
00300 xval = 0;
00301 }
00302 if (kchip_xval[kchip_[iz][ip][ix][iy]-1] != 3 && kchip_xval[kchip_[iz][ip][ix][iy]-1] != 0) {
00303 xval = 5;
00304 nErr++;
00305 }
00306 if (syncStatus_[fed_[iz][ip][ix][iy]-520] == 1) {
00307 xval = 6;
00308 nErr++;
00309 }
00310 if (slinkCRCStatus_[fed_[iz][ip][ix][iy]-520] == 1) {
00311 xval = 8;
00312 nErr++;
00313 }
00314 if (nErr > 1) xval = 7;
00315 } else if (fedStatus_[fed_[iz][ip][ix][iy]-520] == -1) {
00316 xval = 0;
00317 }
00318
00319 meFED_[iz][ip]->setBinContent(ix+1, iy+1, xval);
00320 }
00321
00322 }
00323
00324 void ESIntegrityClient::softReset(bool flag) {
00325
00326 }
00327
00328