CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/DQM/EcalPreshowerMonitorClient/src/ESIntegrityClient.cc

Go to the documentation of this file.
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   // read in look-up table
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       sprintf(histo, "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       sprintf(histo, "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   char histo[200];
00145 
00146   double nDI_FedErr[56];
00147   for (int i=0; i<56; ++i) nDI_FedErr[i] = 0;
00148 
00149   MonitorElement* me = 0;
00150   
00151   sprintf(histo, (prefixME_ + "/ESIntegrityTask/ES FEDs used for data taking").c_str());
00152   me = dqmStore_->get(histo);
00153   hFED_ = UtilsClient::getHisto<TH1F*>( me, cloneME_, hFED_ ); 
00154 
00155   sprintf(histo, (prefixME_ + "/ESIntegrityTask/ES Fiber Off").c_str());
00156   me = dqmStore_->get(histo);
00157   hFiberOff_ = UtilsClient::getHisto<TH2F*>( me, cloneME_, hFiberOff_ ); 
00158 
00159   sprintf(histo, (prefixME_ + "/ESIntegrityTask/ES Fiber Bad Status").c_str());
00160   me = dqmStore_->get(histo);
00161   hFiberBadStatus_ = UtilsClient::getHisto<TH2F*>( me, cloneME_, hFiberBadStatus_ ); 
00162 
00163   sprintf(histo, (prefixME_ + "/ESIntegrityTask/ES SLink CRC Errors").c_str());
00164   me = dqmStore_->get(histo);
00165   hSLinkCRCErr_ = UtilsClient::getHisto<TH1F*>( me, cloneME_, hSLinkCRCErr_ ); 
00166 
00167   int xval = 0;
00168   int nevFEDs = 0;
00169   if (hFED_) {
00170     for (int i=1; i<=56; ++i) 
00171       if (nevFEDs < hFED_->GetBinContent(i))
00172         nevFEDs = (int) hFED_->GetBinContent(i);
00173   }
00174 
00175   // FED integrity
00176   for (int i=1; i<=56; ++i) {
00177     if (hFED_) {
00178       if (hFED_->GetBinContent(i) > 0) 
00179         fedStatus_[i-1] = 1;      
00180     }
00181     if (hSLinkCRCErr_) {
00182       if (hSLinkCRCErr_->GetBinContent(i) > 0) 
00183         slinkCRCStatus_[i] = 1;
00184     }
00185     for (int j=0; j<36; ++j) {
00186       if (hFiberBadStatus_) {
00187         if (hFiberBadStatus_->GetBinContent(i, j+1) > 0) 
00188           fiberStatus_[i-1][j] = 2; // bad
00189         else 
00190           fiberStatus_[i-1][j] = 1; // good
00191       }
00192       if (hFiberOff_) 
00193         if (hFiberOff_->GetBinContent(i, j+1) > 0) {
00194           fiberStatus_[i-1][j] = 0; // off
00195         }
00196     }
00197   }
00198 
00199   // obtain MEs from ESRawDataTask
00200   sprintf(histo, (prefixME_ + "/ESRawDataTask/ES L1A DCC errors").c_str());
00201   me = dqmStore_->get(histo);
00202   hL1ADiff_ = UtilsClient::getHisto<TH1F*>( me, cloneME_, hL1ADiff_ ); 
00203 
00204   sprintf(histo, (prefixME_ + "/ESRawDataTask/ES BX DCC errors").c_str());
00205   me = dqmStore_->get(histo);
00206   hBXDiff_ = UtilsClient::getHisto<TH1F*>( me, cloneME_, hBXDiff_ ); 
00207 
00208   sprintf(histo, (prefixME_ + "/ESRawDataTask/ES Orbit Number DCC errors").c_str());
00209   me = dqmStore_->get(histo);
00210   hOrbitNumberDiff_ = UtilsClient::getHisto<TH1F*>( me, cloneME_, hOrbitNumberDiff_ ); 
00211 
00212   for (int i=1; i<=56; ++i) {
00213     if (hL1ADiff_ && hBXDiff_) {
00214       if (hL1ADiff_->GetBinContent(i) > 0 || hBXDiff_->GetBinContent(i) > 0) {
00215         syncStatus_[i-1] = 1;
00216         if (hL1ADiff_->GetBinContent(i) > nDI_FedErr[i-1]) nDI_FedErr[i-1] = hL1ADiff_->GetBinContent(i);
00217         if (hBXDiff_->GetBinContent(i) > nDI_FedErr[i-1]) nDI_FedErr[i-1] = hBXDiff_->GetBinContent(i);
00218       }
00219     }
00220     //if (hOrbitNumberDiff_->GetBinContent(i) > 0) syncStatus_[i-1] = 1;
00221   }
00222 
00223   // KCHIP integrity
00224   sprintf(histo, (prefixME_ + "/ESIntegrityTask/ES KChip Flag 1 Error codes").c_str());
00225   me = dqmStore_->get(histo);
00226   hKF1_ = UtilsClient::getHisto<TH2F*>( me, cloneME_, hKF1_ ); 
00227 
00228   sprintf(histo, (prefixME_ + "/ESIntegrityTask/ES KChip Flag 2 Error codes").c_str());
00229   me = dqmStore_->get(histo);
00230   hKF2_ = UtilsClient::getHisto<TH2F*>( me, cloneME_, hKF2_ ); 
00231 
00232   sprintf(histo, (prefixME_ + "/ESIntegrityTask/ES KChip BC mismatch with OptoRX").c_str());
00233   me = dqmStore_->get(histo);
00234   hKBC_ = UtilsClient::getHisto<TH1F*>( me, cloneME_, hKBC_ ); 
00235 
00236   sprintf(histo, (prefixME_ + "/ESIntegrityTask/ES KChip EC mismatch with OptoRX").c_str());
00237   me = dqmStore_->get(histo);
00238   hKEC_ = UtilsClient::getHisto<TH1F*>( me, cloneME_, hKEC_ ); 
00239 
00240   Int_t kchip_xval[1550];
00241   for (int i=0; i<=1550; ++i) {
00242 
00243     xval = 3;
00244     Int_t kErr = 0;
00245     for (int j=1; j<16; ++j) { 
00246       if (hKF1_) {
00247         if (hKF1_->GetBinContent(i, j+1)>0) {
00248           xval = 2;
00249           kErr++;
00250         }
00251       }
00252       if (hKF2_) {
00253         if (hKF2_->GetBinContent(i, j+1)>0) {
00254           xval = 4;
00255           kErr++;
00256         }
00257       }
00258     }
00259     if (hKBC_) {
00260       if (hKBC_->GetBinContent(i)>0) {
00261         xval = 5;
00262         kErr++;
00263       } 
00264     }
00265     if (hKEC_) {
00266       if (hKEC_->GetBinContent(i)>0) {
00267         xval = 6;
00268         kErr++;
00269       } 
00270     }
00271     if (kErr>1) xval = 7; 
00272     kchip_xval[i] = xval;
00273   }
00274 
00275   // detailed KCHIP summary (i.e. summary 2)
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           if (fed_[iz][ip][ix][iy] == -1) continue;
00281           if (fedStatus_[fed_[iz][ip][ix][iy]-520]==-1 || fiberStatus_[fed_[iz][ip][ix][iy]-520][fiber_[iz][ip][ix][iy]] == 0)
00282             kchip_xval[kchip_[iz][ip][ix][iy]-1] = 0;
00283           if ((kchip_[iz][ip][ix][iy]-2) >= 0) 
00284             meKCHIP_[iz][ip]->setBinContent(ix+1, iy+1, kchip_xval[kchip_[iz][ip][ix][iy]-2]); 
00285         }
00286 
00287   // FED, Fiber, KCHIP summary (i.e. summary 1) 
00288   Int_t nErr = 0;
00289   for (int iz=0; iz<2; ++iz) 
00290     for (int ip=0; ip<2; ++ip)
00291       for (int ix=0; ix<40; ++ix)
00292         for (int iy=0; iy<40; ++iy) {
00293 
00294           if (fed_[iz][ip][ix][iy] == -1) continue;
00295           nErr = 0;
00296 
00297           if (fedStatus_[fed_[iz][ip][ix][iy]-520] == 1) {
00298 
00299             if (hFED_) {
00300               if (hFED_->GetBinContent(fed_[iz][ip][ix][iy]-520+1) == nevFEDs) 
00301                 xval = 3;
00302               else {
00303                 xval = 4; // FED problem
00304                 nErr++;
00305               }
00306             }
00307 
00308             if (fiberStatus_[fed_[iz][ip][ix][iy]-520][fiber_[iz][ip][ix][iy]] == 2) {
00309               xval = 2; // fiber problem
00310               nErr++;
00311             }
00312             if (fiberStatus_[fed_[iz][ip][ix][iy]-520][fiber_[iz][ip][ix][iy]] == 0) {
00313               xval = 0; // fiber off
00314             } 
00315             if (kchip_xval[kchip_[iz][ip][ix][iy]-1] != 3 && kchip_xval[kchip_[iz][ip][ix][iy]-1] != 0) {
00316               xval = 5; // kchip problem
00317               nErr++;
00318             }
00319             if (syncStatus_[fed_[iz][ip][ix][iy]-520] == 1) {
00320               xval = 6;
00321               nErr++;
00322             }
00323             if (slinkCRCStatus_[fed_[iz][ip][ix][iy]-520] == 1) {
00324               xval = 8;
00325               nErr++;
00326             }
00327             if (nErr > 1) xval = 7;
00328           } else if (fedStatus_[fed_[iz][ip][ix][iy]-520] == -1) {
00329             xval = 0;
00330           } 
00331           
00332           meFED_[iz][ip]->setBinContent(ix+1, iy+1, xval); 
00333         }
00334   
00335 }
00336 
00337 void ESIntegrityClient::softReset(bool flag) {
00338   
00339 }
00340 
00341