CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_5_3_14/src/DQM/HcalMonitorClient/src/HcalRawDataClient.cc

Go to the documentation of this file.
00001 #include "DQM/HcalMonitorClient/interface/HcalRawDataClient.h"
00002 #include "DQM/HcalMonitorClient/interface/HcalClientUtils.h"
00003 #include "DQM/HcalMonitorClient/interface/HcalHistoUtils.h"
00004 
00005 #include "CondFormats/HcalObjects/interface/HcalChannelStatus.h"
00006 #include "CondFormats/HcalObjects/interface/HcalChannelQuality.h"
00007 #include "CondFormats/HcalObjects/interface/HcalCondObjectContainer.h"
00008 
00009 #include "FWCore/Framework/interface/ESHandle.h"
00010 #include "CalibFormats/HcalObjects/interface/HcalDbService.h"
00011 #include "CalibFormats/HcalObjects/interface/HcalDbRecord.h"
00012 #include "DataFormats/FEDRawData/interface/FEDNumbering.h"
00013 
00014 #include <iostream>
00015 
00016 /*
00017  * \file HcalRawDataClient.cc
00018  * 
00019  * $Date: 2012/07/04 15:43:18 $
00020  * $Revision: 1.14 $
00021  * \author J. St. John
00022  * \brief Hcal Raw Data Client class
00023  */
00024 
00025 HcalRawDataClient::HcalRawDataClient(std::string myname)
00026 {
00027   name_=myname;
00028 }
00029 
00030 HcalRawDataClient::HcalRawDataClient(std::string myname, const edm::ParameterSet& ps)
00031 {
00032   name_=myname;
00033   enableCleanup_         = ps.getUntrackedParameter<bool>("enableCleanup",false);
00034   debug_                 = ps.getUntrackedParameter<int>("debug",0);
00035   prefixME_              = ps.getUntrackedParameter<std::string>("subSystemFolder","Hcal/");
00036   if (prefixME_.substr(prefixME_.size()-1,prefixME_.size())!="/")
00037     prefixME_.append("/");
00038   subdir_                = ps.getUntrackedParameter<std::string>("RawDataFolder","RawDataMonitor_Hcal/"); // RawDataMonitor
00039   if (subdir_.size()>0 && subdir_.substr(subdir_.size()-1,subdir_.size())!="/")
00040     subdir_.append("/");
00041   subdir_=prefixME_+subdir_;
00042 
00043   validHtmlOutput_       = ps.getUntrackedParameter<bool>("RawData_validHtmlOutput",true);
00044   cloneME_ = ps.getUntrackedParameter<bool>("cloneME", true);
00045   badChannelStatusMask_   = ps.getUntrackedParameter<int>("RawData_BadChannelStatusMask",
00046                                                           ps.getUntrackedParameter<int>("BadChannelStatusMask",0));
00047   
00048   minerrorrate_ = ps.getUntrackedParameter<double>("RawData_minerrorrate",
00049                                                    ps.getUntrackedParameter<double>("minerrorrate",0.01));
00050   minevents_    = ps.getUntrackedParameter<int>("RawData_minevents",
00051                                                 ps.getUntrackedParameter<int>("minevents",1));
00052 
00053   excludeHORing2_       = ps.getUntrackedParameter<bool>("excludeHOring2_backup",false);
00054   Online_                = ps.getUntrackedParameter<bool>("online",false);
00055 
00056   ProblemCells=0;
00057   ProblemCellsByDepth=0;
00058 }
00059 
00060 void HcalRawDataClient::endLuminosityBlock() {
00061 //  if (LBprocessed_==true) return;  // LB already processed
00062 //  UpdateMEs();
00063 //  LBprocessed_=true; 
00064   if (debug_>2) std::cout <<"\tHcalRawDataClient::endLuminosityBlock()"<<std::endl;
00065   calculateProblems();
00066   return;
00067 }
00068 
00069 
00070 void HcalRawDataClient::analyze()
00071 {
00072   if (debug_>2) std::cout <<"\tHcalRawDataClient::analyze()"<<std::endl;
00073   calculateProblems();
00074 }
00075 
00076 void HcalRawDataClient::calculateProblems()
00077 {
00078  if (debug_>2) std::cout <<"\t\tHcalRawDataClient::calculateProblems()"<<std::endl;
00079   if(!dqmStore_) return;
00080   double totalevents=0;
00081   int etabins=0, phibins=0, zside=0;
00082   double problemvalue=0;
00083   
00084   //Get number of events to normalize by
00085   MonitorElement* me;
00086   me = dqmStore_->get(subdir_+"Events_Processed_Task_Histogram");
00087   if (me) totalevents=me->getBinContent(1);
00088 
00089   // Clear away old problems
00090   if (ProblemCells!=0)
00091     {
00092       ProblemCells->Reset();
00093       (ProblemCells->getTH2F())->SetMaximum(1.05);
00094       (ProblemCells->getTH2F())->SetMinimum(0.);
00095     }
00096   for  (unsigned int d=0;ProblemCellsByDepth!=0 && d<ProblemCellsByDepth->depth.size();++d)
00097     {
00098       if (ProblemCellsByDepth->depth[d]!=0) 
00099         {
00100           ProblemCellsByDepth->depth[d]->Reset();
00101           (ProblemCellsByDepth->depth[d]->getTH2F())->SetMaximum(1.05);
00102           (ProblemCellsByDepth->depth[d]->getTH2F())->SetMinimum(0.);
00103         }
00104       for (unsigned int eta=0; eta<85;++eta) //spans largest ieta breadth
00105         {
00106           for (unsigned int phi=0;phi<72;++phi) //spans largest (only!) iphi breadth
00107             {
00108               problemcount[eta][phi][d]=0.0;
00109             }
00110         }
00111     }
00112   enoughevents_=true;
00113 
00114   // Try to read excludeHOring2 status from file
00115   
00116   MonitorElement* temp_exclude = dqmStore_->get(subdir_+"ExcludeHOring2");
00117 
00118   // If value can't be read from file, keep the excludeHOring2_backup status
00119   if (temp_exclude != 0)
00120     {
00121       if (temp_exclude->getIntValue()>0)
00122         excludeHORing2_ = true;  
00123       else
00124         excludeHORing2_ = false;
00125     }
00126 
00127 
00128 
00129   //Get the plots showing raw data errors,
00130   //fill problemcount[][][] 
00131   fillProblemCountArray();
00132 
00133   std::vector<std::string> name = HcalEtaPhiHistNames();
00134 
00135   // Because we're clearing and re-forming the problem cell histogram here, we don't need to do any cute
00136   // setting of the underflow bin to 0, and we can plot results as a raw rate between 0-1.
00137   
00138   for (unsigned int d=0;ProblemCellsByDepth!=0 && d<ProblemCellsByDepth->depth.size();++d)
00139     {
00140       if (ProblemCellsByDepth->depth[d]==0) continue;
00141     
00142       if (totalevents==0 || totalevents<minevents_) continue;
00143       etabins=(ProblemCellsByDepth->depth[d]->getTH2F())->GetNbinsX();
00144       phibins=(ProblemCellsByDepth->depth[d]->getTH2F())->GetNbinsY();
00145       problemvalue=0;
00146       for (int eta=0;eta<etabins;++eta)
00147         {
00148           int ieta=CalcIeta(eta,d+1);
00149           if (ieta==-9999) continue;
00150           for (int phi=0;phi<phibins;++phi)
00151             {
00152               problemvalue=0;
00153               problemvalue=((uint64_t) problemcount[eta][phi][d] );
00154 
00155               if (problemvalue==0) continue;
00156               problemvalue/=totalevents; // problem value is a rate; should be between 0 and 1
00157               problemvalue = std::min(1.,problemvalue);
00158               
00159               zside=0;
00160               if (isHF(eta,d+1)) // shift ieta by 1 for HF
00161                 ieta<0 ? zside = -1 : zside = 1;
00162               
00163               if (debug_>0) std::cout <<"problemvalue = "<<problemvalue<<"  ieta = "<<zside<<"  iphi = "<<phi+1<<"  d = "<<d+1<<std::endl;
00164               // For problem cells that exceed our allowed rate,
00165               // set the values to -1 if the cells are already marked in the status database
00166 
00167               if (problemvalue>minerrorrate_)
00168                 {
00169                   HcalSubdetector subdet=HcalEmpty;
00170                   if (isHB(eta,d+1))subdet=HcalBarrel;
00171                   else if (isHE(eta,d+1)) subdet=HcalEndcap;
00172                   else if (isHF(eta,d+1)) subdet=HcalForward;
00173                   else if (isHO(eta,d+1)) subdet=HcalOuter;
00174                   HcalDetId hcalid(subdet, ieta, phi+1, (int)(d+1));
00175                   if (badstatusmap.find(hcalid)!=badstatusmap.end())
00176                     problemvalue=999;           
00177                 }
00178               
00179               ProblemCellsByDepth->depth[d]->setBinContent(eta+1,phi+1,problemvalue);
00180               if (ProblemCells!=0) ProblemCells->Fill(ieta+zside,phi+1,problemvalue);
00181             } // loop on phi
00182         } // loop on eta
00183     } // loop on depth
00184 
00185   if (ProblemCells==0)
00186     {
00187       if (debug_>0) std::cout <<"<HcalRawDataClient::analyze> ProblemCells histogram does not exist!"<<std::endl;
00188       return;
00189     }
00190 
00191   // Normalization of ProblemCell plot, in the case where there are errors in multiple depths
00192   etabins=(ProblemCells->getTH2F())->GetNbinsX();
00193   phibins=(ProblemCells->getTH2F())->GetNbinsY();
00194   for (int eta=0;eta<etabins;++eta)
00195     {
00196       for (int phi=0;phi<phibins;++phi)
00197         {
00198           if (ProblemCells->getBinContent(eta+1,phi+1)>1. && ProblemCells->getBinContent(eta+1,phi+1)<999)
00199             ProblemCells->setBinContent(eta+1,phi+1,1.);
00200         }
00201     }
00202 
00203   FillUnphysicalHEHFBins(*ProblemCellsByDepth);
00204   FillUnphysicalHEHFBins(ProblemCells);
00205   return;
00206 }
00207 
00208 void HcalRawDataClient::beginJob()
00209 {
00210   dqmStore_ = edm::Service<DQMStore>().operator->();
00211   if (debug_>0) 
00212     {
00213       std::cout <<"<HcalRawDataClient::beginJob()>  Displaying dqmStore directory structure:"<<std::endl;
00214       dqmStore_->showDirStructure();
00215     }
00216 }
00217 void HcalRawDataClient::endJob(){}
00218 
00219 void HcalRawDataClient::stashHDI(int thehash, HcalDetId thehcaldetid) {
00220   //Let's not allow indexing off the array...
00221   if ((thehash<0)||(thehash>=(NUMDCCS*NUMSPGS*HTRCHANMAX)))return;
00222   //...but still do the job requested.
00223   hashedHcalDetId_[thehash] = thehcaldetid;
00224 }
00225 
00226 
00227 void HcalRawDataClient::beginRun(void)
00228 {
00229   if (debug_>2) std::cout <<"<HcalRawDataClient::beginRun>"<<std::endl;
00230   edm::ESHandle<HcalDbService> pSetup;
00231   c->get<HcalDbRecord>().get( pSetup );
00232 
00233   if (debug_>2) std::cout <<"\t<HcalRawDataClient::beginRun> Get Hcal mapping"<<std::endl;
00234   readoutMap_=pSetup->getHcalMapping();
00235   DetId detid_;
00236   HcalDetId hcaldetid_; 
00237 
00238   // Build a map of readout hardware unit to calorimeter channel
00239   std::vector <HcalElectronicsId> AllElIds = readoutMap_->allElectronicsIdPrecision();
00240   uint32_t itsdcc    =0;
00241   uint32_t itsspigot =0;
00242   uint32_t itshtrchan=0;
00243   
00244   if (debug_>2) std::cout <<"\t<HcalRawDataClient::beginRun> Loop over AllEIds"<<std::endl;
00245   // by looping over all precision (non-trigger) items.
00246   for (std::vector <HcalElectronicsId>::iterator eid = AllElIds.begin();
00247        eid != AllElIds.end();
00248        eid++) {
00249 
00250     //Get the HcalDetId from the HcalElectronicsId
00251     detid_ = readoutMap_->lookup(*eid);
00252     // NULL if illegal; ignore
00253     if (!detid_.null()) {
00254       if (detid_.det()!=4) continue; //not Hcal
00255       if (detid_.subdetId()!=HcalBarrel &&
00256           detid_.subdetId()!=HcalEndcap &&
00257           detid_.subdetId()!=HcalOuter  &&
00258           detid_.subdetId()!=HcalForward) continue;
00259 
00260       itsdcc    =(uint32_t) eid->dccid(); 
00261       itsspigot =(uint32_t) eid->spigot();
00262       itshtrchan=(uint32_t) eid->htrChanId();
00263       hcaldetid_ = HcalDetId(detid_);
00264       stashHDI(hashup(itsdcc,itsspigot,itshtrchan),
00265                hcaldetid_);
00266     } // if (!detid_.null()) 
00267   } 
00268 
00269   if (debug_>2) std::cout <<"\t<HcalRawDataClient::beginRun> Completed loop."<<std::endl;
00270 
00271   enoughevents_=false;
00272   if (!dqmStore_) 
00273     {
00274       if (debug_>0) std::cout <<"<HcalRawDataClient::beginRun> dqmStore does not exist!"<<std::endl;
00275       return;
00276     }
00277 
00278   dqmStore_->setCurrentFolder(subdir_);
00279   problemnames_.clear();
00280   // Put the appropriate name of your problem summary here
00281   ProblemCells=dqmStore_->book2D(" ProblemRawData",
00282                                  " Problem Raw Data Rate for all HCAL;ieta;iphi",
00283                                  85,-42.5,42.5,
00284                                  72,0.5,72.5);
00285   problemnames_.push_back(ProblemCells->getName());
00286   if (debug_>1)
00287     std::cout << "Tried to create ProblemCells Monitor Element in directory "<<subdir_<<"  \t  Failed?  "<<(ProblemCells==0)<<std::endl;
00288   dqmStore_->setCurrentFolder(subdir_+"problem_rawdata");
00289   ProblemCellsByDepth = new EtaPhiHists();
00290 
00291   ProblemCells->getTH2F()->SetMinimum(0);
00292   ProblemCells->getTH2F()->SetMaximum(1.05);
00293 
00294   ProblemCellsByDepth->setup(dqmStore_," Problem Raw Data Rate");
00295   for (unsigned int i=0; i<ProblemCellsByDepth->depth.size();++i)
00296     problemnames_.push_back(ProblemCellsByDepth->depth[i]->getName());
00297 
00298   nevts_=0;
00299 }
00300 
00301 void HcalRawDataClient::endRun(void){analyze();}
00302 
00303 void HcalRawDataClient::setup(void){}
00304 void HcalRawDataClient::cleanup(void){}
00305 
00306 bool HcalRawDataClient::hasErrors_Temp(void)
00307 {
00308   if (!ProblemCells)
00309     {
00310       if (debug_>1) std::cout <<"<HcalRawDataClient::hasErrors_Temp>  ProblemCells histogram does not exist!"<<std::endl;
00311       return false;
00312     }
00313   int problemcount=0;
00314   int ieta=-9999;
00315 
00316   for (int depth=0;depth<4; ++depth)
00317     {
00318       int etabins  = (ProblemCells->getTH2F())->GetNbinsX();
00319       int phibins  = (ProblemCells->getTH2F())->GetNbinsY();
00320       for (int hist_eta=0;hist_eta<etabins;++hist_eta)
00321         {
00322           for (int hist_phi=0; hist_phi<phibins;++hist_phi)
00323             {
00324               ieta=CalcIeta(hist_eta,depth+1);
00325               if (ieta==-9999) continue;
00326               if (ProblemCellsByDepth->depth[depth]==0)
00327                 continue;
00328               if (ProblemCellsByDepth->depth[depth]->getBinContent(hist_eta,hist_phi)>minerrorrate_)
00329                 ++problemcount;
00330             } // for (int hist_phi=1;...)
00331         } // for (int hist_eta=1;...)
00332     } // for (int depth=0;...)
00333 
00334   if (problemcount>0) return true;
00335   return false;
00336 }
00337 
00338 bool HcalRawDataClient::hasWarnings_Temp(void){return false;}
00339 bool HcalRawDataClient::hasOther_Temp(void){return false;}
00340 bool HcalRawDataClient::test_enabled(void){return true;}
00341 
00342 
00343 void HcalRawDataClient::updateChannelStatus(std::map<HcalDetId, unsigned int>& myqual)
00344 {
00345   // This gets called by HcalMonitorClient
00346   // see dead or hot cell code for an example
00347 
00348 } //void HcalRawDataClient::updateChannelStatus
00349 
00350 
00351 void HcalRawDataClient::getHardwareSpaceHistos(void){
00352   MonitorElement* me;
00353   std::string s;
00354   if (debug_>1) std::cout<<"\t<HcalRawDataClient>: getHardwareSpaceHistos()"<<std::endl;
00355   s=subdir_+"Corruption/01 Common Data Format violations";
00356   me=dqmStore_->get(s.c_str());  
00357   meCDFErrorFound_=HcalUtilsClient::getHisto<TH2F*>(me, cloneME_, meCDFErrorFound_, debug_);
00358   if (!meCDFErrorFound_ & (debug_>0)) std::cout <<"<HcalRawDataClient::analyze> "<<s<<" histogram does not exist!"<<std::endl;
00359 
00360   s=subdir_+"Corruption/02 DCC Event Format violation";
00361   me=dqmStore_->get(s.c_str());  
00362   meDCCEventFormatError_=HcalUtilsClient::getHisto<TH2F*>(me, cloneME_, meDCCEventFormatError_, debug_);
00363   if (!meDCCEventFormatError_ & (debug_>0)) std::cout <<"<HcalRawDataClient::analyze> "<<s<<" histogram does not exist!"<<std::endl;
00364 
00365   s=subdir_+"Corruption/03 OrN Inconsistent - HTR vs DCC";
00366   me=dqmStore_->get(s.c_str());  
00367   meOrNSynch_=HcalUtilsClient::getHisto<TH2F*>(me, cloneME_, meOrNSynch_, debug_);
00368   if (!meOrNSynch_ & (debug_>0)) std::cout <<"<HcalRawDataClient::analyze> "<<s<<" histogram does not exist!"<<std::endl;
00369 
00370   s=subdir_+"Corruption/05 BCN Inconsistent - HTR vs DCC";
00371   me=dqmStore_->get(s.c_str());  
00372   meBCNSynch_=HcalUtilsClient::getHisto<TH2F*>(me, cloneME_, meBCNSynch_, debug_);
00373   if (!meBCNSynch_ & (debug_>0)) std::cout <<"<HcalRawDataClient::analyze> "<<s<<" histogram does not exist!"<<std::endl;
00374 
00375   s=subdir_+"Corruption/06 EvN Inconsistent - HTR vs DCC";
00376   me=dqmStore_->get(s.c_str());  
00377   meEvtNumberSynch_=HcalUtilsClient::getHisto<TH2F*>(me, cloneME_, meEvtNumberSynch_, debug_);
00378   if (!meEvtNumberSynch_ & (debug_>0)) std::cout <<"<HcalRawDataClient::analyze> "<<s<<" histogram does not exist!"<<std::endl;
00379 
00380   s=subdir_+"Corruption/07 LRB Data Corruption Indicators";
00381   me=dqmStore_->get(s.c_str());  
00382   LRBDataCorruptionIndicators_=HcalUtilsClient::getHisto<TH2F*>(me, cloneME_, LRBDataCorruptionIndicators_, debug_);
00383   if (!LRBDataCorruptionIndicators_ & (debug_>0)) std::cout <<"<HcalRawDataClient::analyze> "<<s<<" histogram does not exist!"<<std::endl;
00384 
00385   s=subdir_+"Corruption/08 Half-HTR Data Corruption Indicators";
00386   me=dqmStore_->get(s.c_str());  
00387   HalfHTRDataCorruptionIndicators_=HcalUtilsClient::getHisto<TH2F*>(me, cloneME_, HalfHTRDataCorruptionIndicators_, debug_);
00388   if (!HalfHTRDataCorruptionIndicators_ & (debug_>0)) std::cout <<"<HcalRawDataClient::analyze> "<<s<<" histogram does not exist!"<<std::endl;
00389 
00390   s=subdir_+"Corruption/09 Channel Integrity Summarized by Spigot";
00391   me=dqmStore_->get(s.c_str());  
00392   ChannSumm_DataIntegrityCheck_=HcalUtilsClient::getHisto<TH2F*>(me, cloneME_, ChannSumm_DataIntegrityCheck_, debug_);
00393   if (!ChannSumm_DataIntegrityCheck_ & (debug_>0)) std::cout <<"<HcalRawDataClient::analyze> "<<s<<" histogram does not exist!"<<std::endl;
00394   if (ChannSumm_DataIntegrityCheck_)
00395     ChannSumm_DataIntegrityCheck_->SetMinimum(0);
00396 
00397   char chararray[150];
00398   for (int i=0; i<NUMDCCS; i++) {
00399     sprintf(chararray,"Corruption/Channel Data Integrity/FED %03d Channel Integrity", i+700);
00400     s=subdir_+std::string(chararray);
00401     me=dqmStore_->get(s.c_str());  
00402     Chann_DataIntegrityCheck_[i]=HcalUtilsClient::getHisto<TH2F*>(me, cloneME_, Chann_DataIntegrityCheck_[i], debug_);
00403     if (!Chann_DataIntegrityCheck_[i] & (debug_>0)) std::cout <<"<HcalRawDataClient::analyze> "<<s<<" histogram does not exist!"<<std::endl;
00404     if (Chann_DataIntegrityCheck_[i])
00405       Chann_DataIntegrityCheck_[i]->SetMinimum(0);
00406   }
00407 }
00408 void HcalRawDataClient::fillProblemCountArray(void){
00409   if (debug_>1) std::cout <<"\t<HcalRawDataClient>::fillProblemCountArray(): getHardwareSpaceHistos()"<<std::endl;
00410   getHardwareSpaceHistos();
00411   float n=0.0;
00412   int dcc_=-999;
00413 
00414   bool CheckmeCDFErrorFound_                   = false; 
00415   bool CheckmeDCCEventFormatError_             = false;
00416   bool CheckmeOrNSynch_                        = false;
00417   bool CheckmeBCNSynch_                        = false;
00418   bool CheckmeEvtNumberSynch_                  = false;
00419   bool CheckLRBDataCorruptionIndicators_       = false;
00420   bool CheckHalfHTRDataCorruptionIndicators_   = false;
00421   bool CheckChannSumm_DataIntegrityCheck_      = false;
00422   bool CheckChann_DataIntegrityCheck_[NUMDCCS] = {false}; 
00423 
00424   if (meCDFErrorFound_!=0)                  CheckmeCDFErrorFound_                   = true;
00425   if (meDCCEventFormatError_!=0)            CheckmeDCCEventFormatError_             = true;
00426   if (meOrNSynch_!=0)                       CheckmeOrNSynch_                        = true;
00427   if (meBCNSynch_!=0)                       CheckmeBCNSynch_                        = true;
00428   if (meEvtNumberSynch_!=0)                 CheckmeEvtNumberSynch_                  = true;
00429   if (LRBDataCorruptionIndicators_!=0)      CheckLRBDataCorruptionIndicators_       = true;
00430   if (HalfHTRDataCorruptionIndicators_!=0)  CheckHalfHTRDataCorruptionIndicators_   = true;
00431   if (ChannSumm_DataIntegrityCheck_!=0)     CheckChannSumm_DataIntegrityCheck_      = true;
00432 
00433   int fed2offset=0;
00434   int fed3offset=0;
00435   int spg2offset=0;
00436   int spg3offset=0;
00437   int chn2offset=0;
00438 
00439   //Project all types of errors in these two plots onto
00440   //the x axis to get total errors per FED.
00441   TH1D* ProjXmeCDFErrorFound_       = 0;
00442   bool CheckProjXmeCDFErrorFound_ = false;
00443   if (CheckmeCDFErrorFound_)
00444     ProjXmeCDFErrorFound_=meCDFErrorFound_->ProjectionX();
00445   if (ProjXmeCDFErrorFound_!=0) CheckProjXmeCDFErrorFound_=true;
00446   TH1D* ProjXmeDCCEventFormatError_ = 0;
00447   bool CheckProjXmeDCCEventFormatError_ = false;
00448   if (CheckmeDCCEventFormatError_)
00449     ProjXmeDCCEventFormatError_=meDCCEventFormatError_->ProjectionX();
00450   if (ProjXmeDCCEventFormatError_!=0) CheckProjXmeDCCEventFormatError_ = true;
00451 
00452   for (int dccid=FEDNumbering::MINHCALFEDID; dccid<=FEDNumbering::MAXHCALFEDID; dccid++) {
00453     dcc_=dccid-FEDNumbering::MINHCALFEDID; // Numbering FEDS [0:31] is more useful for array indices.
00454     if (Chann_DataIntegrityCheck_[dcc_]!=0) 
00455       CheckChann_DataIntegrityCheck_[dcc_] = true;
00456     
00457     if (CheckProjXmeCDFErrorFound_) {
00458       n = ProjXmeCDFErrorFound_->GetBinContent(1+dcc_);
00459       if (n>0.0) mapDCCproblem(dcc_,n);
00460     }
00461     if (CheckProjXmeDCCEventFormatError_) {
00462       n = ProjXmeDCCEventFormatError_->GetBinContent(1+dcc_);
00463       if (n>0.0) mapDCCproblem(dcc_,n);
00464     }
00465   
00466     fed3offset = 1 + (4*dcc_); //3 bins, plus one of margin, each DCC (FED)
00467     fed2offset = 1 + (3*dcc_); //2 bins, plus one of margin, each DCC (FED)
00468     for (int spigot=0; spigot<NUMSPGS; spigot++) {
00469       
00470       if (CheckmeOrNSynch_) {
00471         n = meOrNSynch_->GetBinContent(1+dcc_, 1+spigot);
00472         if (n>0.0) mapHTRproblem(dcc_,spigot,n);
00473       }
00474       if (CheckmeBCNSynch_) {
00475         n = meBCNSynch_->GetBinContent(1+dcc_, 1+spigot);
00476         if (n>0.0) mapHTRproblem(dcc_,spigot,n);
00477       }
00478       if (CheckmeEvtNumberSynch_) {
00479         n = meEvtNumberSynch_->GetBinContent(1+dcc_, 1+spigot);
00480         if (n>0.0) mapHTRproblem(dcc_,spigot,n);
00481       }
00482       spg3offset = 1 + (4*spigot); //3 bins, plus one of margin, each spigot
00483       if (CheckLRBDataCorruptionIndicators_    ){
00484         n=0.0; //Sum errors of all ten types 
00485         n+=LRBDataCorruptionIndicators_->GetBinContent(fed3offset,
00486                                                        spg3offset);
00487         for (int xbin=1; xbin<=3; xbin++) {
00488           for (int ybin=1; ybin<=3; ybin++) {
00489             n+=LRBDataCorruptionIndicators_->GetBinContent(fed3offset+xbin,
00490                                                            spg3offset+ybin);
00491           }
00492         }
00493         if (n>0.0) mapHTRproblem(dcc_,spigot,n);
00494       }
00495       if (CheckHalfHTRDataCorruptionIndicators_){
00496         n=0.0; //Sum errors of all nine types 
00497         for (int xbin=1; xbin<=3; xbin++) {
00498           for (int ybin=1; ybin<=3; ybin++) {
00499             n+=HalfHTRDataCorruptionIndicators_->GetBinContent(fed3offset+xbin,
00500                                                                spg3offset+ybin);
00501           }
00502         }
00503         if (n>0.0) mapHTRproblem(dcc_,spigot,n);
00504       }
00505       spg2offset = 1 + (3*spigot); //2 bins, plus one of margin, each spigot
00506       if (CheckChann_DataIntegrityCheck_[dcc_] &&
00507           CheckChannSumm_DataIntegrityCheck_      ){
00508         //Each spigot may be configured for its own number of TimeSlices, per event.
00509         //Keep an array of the values:
00510         numTS_[(dcc_*NUMSPGS)+spigot]=-1.0 * ChannSumm_DataIntegrityCheck_->GetBinContent(fed2offset,
00511                                                                                           spg2offset+1);
00512         for (int chnnum=0; chnnum<HTRCHANMAX; chnnum++) {
00513           chn2offset = 1 + (3*chnnum); //2 bins, plus one of margin, each channel
00514           n = 0.0;
00515           //Sum errors of all types, 
00516           //but not !DV, at xbin==1, ybin==2.
00517           //Weight less if error can occur every timeslice
00518           // or between any two timeslices
00519           float tsFactor=numTS_[spigot +(dcc_*NUMSPGS)]; 
00520           float CRweight = 0.0;
00521           float Erweight = 0.0;
00522           if (tsFactor>0) {
00523             CRweight = (1.0 / (tsFactor-1.0));
00524             Erweight = (1.0 / (tsFactor    ));
00525           }
00526           int xbin=1; int ybin=1; // Timeslices per event check for error here
00527           n += Chann_DataIntegrityCheck_[dcc_]->GetBinContent(chn2offset+xbin,
00528                                                               spg2offset+ybin);
00529           xbin=2; //move right one bin: CapID Rotation here
00530           n += CRweight * Chann_DataIntegrityCheck_[dcc_]->GetBinContent(chn2offset+xbin,
00531                                                                          spg2offset+ybin);
00532           ybin=2; //move up one bin: Er bit here
00533           n += Erweight * Chann_DataIntegrityCheck_[dcc_]->GetBinContent(chn2offset+xbin,
00534                                                                          spg2offset+ybin);
00535           if  (n>=0.0)
00536             mapChannproblem(dcc_,spigot,chnnum,n);
00537         } //loop over channels
00538       } //check to see if FED had any channel problems  
00539     } //loop over spigot
00540   } //loop over dccid
00541 }
00542 
00543 void HcalRawDataClient::mapDCCproblem(int dcc, float n) {
00544   int myeta   = 0;
00545   int myphi   =-1;
00546   int mydepth = 0;
00547   HcalDetId HDI;
00548   //Light up all affected cells.
00549   for (int i=hashup(dcc); 
00550        i<hashup(dcc)+(NUMSPGS*HTRCHANMAX); 
00551        i++) {
00552     HDI = hashedHcalDetId_[i];
00553     if (HDI==HcalDetId::Undefined) 
00554       continue;
00555     mydepth = HDI.depth();
00556     myphi   = HDI.iphi();
00557     myeta = CalcEtaBin(HDI.subdet(),
00558                        HDI.ieta(),
00559                        mydepth);
00560     if (myeta>=0 && myeta<85 &&
00561         (myphi-1)>=0 && (myphi-1)<72 &&
00562         (mydepth-1)>=0 && (mydepth-1)<4){
00563       if (problemcount[myeta][myphi-1][mydepth-1]< n)
00564         problemcount[myeta][myphi-1][mydepth-1]=n;
00565 
00566       //exclude the decommissioned HO ring2, except SiPMs 
00567       if(mydepth==4 && excludeHORing2_==true)
00568         if (abs(HDI.ieta())>=11 && abs(HDI.ieta())<=15  && !isSiPM(HDI.ieta(),HDI.iphi(),mydepth))
00569           problemcount[myeta][myphi-1][mydepth-1] = 0.0;
00570 
00571       if (debug_>0)
00572         std::cout<<" mapDCCproblem found error! "<<HDI.subdet()<<"("<<HDI.ieta()<<", "<<HDI.iphi()<<", "<<HDI.depth()<<")"<<std::endl;
00573     }
00574   }
00575 }
00576 void HcalRawDataClient::mapHTRproblem(int dcc, int spigot, float n) {
00577   int myeta = 0;
00578   int myphi   =-1;
00579   int mydepth = 0;
00580   HcalDetId HDI;
00581   //Light up all affected cells.
00582   for (int i=hashup(dcc,spigot); 
00583        i<hashup(dcc,spigot)+(HTRCHANMAX); //nice, linear hash....
00584        i++) {
00585     HDI = hashedHcalDetId_[i];
00586     if (HDI==HcalDetId::Undefined) {
00587       continue;
00588     }
00589     mydepth = HDI.depth();
00590     myphi   = HDI.iphi();
00591     myeta = CalcEtaBin(HDI.subdet(),
00592                        HDI.ieta(),
00593                        mydepth);
00594     if (myeta>=0 && myeta<85 &&
00595         (myphi-1)>=0 && (myphi-1)<72 &&
00596         (mydepth-1)>=0 && (mydepth-1)<4){
00597       if (problemcount[myeta][myphi-1][mydepth-1]< n)
00598         problemcount[myeta][myphi-1][mydepth-1]=n;
00599       
00600       //exlcude the decommissioned HO ring2, except SiPMs 
00601       if(mydepth==4 && excludeHORing2_==true)
00602         if (abs(HDI.ieta())>=11 && abs(HDI.ieta())<=15  && !isSiPM(HDI.ieta(),HDI.iphi(),mydepth))
00603           problemcount[myeta][myphi-1][mydepth-1] = 0.0;
00604 
00605       if (debug_>0)
00606         std::cout<<" mapHTRproblem found error! "<<HDI.subdet()<<"("<<HDI.ieta()<<", "<<HDI.iphi()<<", "<<HDI.depth()<<")"<<std::endl;
00607     }    
00608   }
00609 }   // void HcalRawDataClient::mapHTRproblem(...)
00610 
00611 void HcalRawDataClient::mapChannproblem(int dcc, int spigot, int htrchan, float n) {
00612   int myeta = 0;
00613   int myphi   =-1;
00614   int mydepth = 0;
00615   HcalDetId HDI;
00616   //Light up the affected cell.
00617   int i=hashup(dcc,spigot,htrchan); 
00618   HDI = HashToHDI(i);
00619   if (HDI==HcalDetId::Undefined) {
00620     return; // Do nothing at all, instead.
00621   } 
00622   mydepth = HDI.depth();
00623   myphi   = HDI.iphi();
00624   myeta = CalcEtaBin(HDI.subdet(),
00625                      HDI.ieta(),
00626                      mydepth);
00627 
00628   if (myeta>=0 && myeta<85 &&
00629       (myphi-1)>=0 && (myphi-1)<72 &&
00630       (mydepth-1)>=0 && (mydepth-1)<4){
00631     if (problemcount[myeta][myphi-1][mydepth-1]< n) {
00632       problemcount[myeta][myphi-1][mydepth-1]=n;
00633 
00634       //exlcude the decommissioned HO ring2, except SiPMs 
00635       if(mydepth==4 && excludeHORing2_==true)
00636         if (abs(HDI.ieta())>=11 && abs(HDI.ieta())<=15  && !isSiPM(HDI.ieta(),HDI.iphi(),mydepth))
00637           problemcount[myeta][myphi-1][mydepth-1] = 0.0;
00638 
00639       if (debug_>0)
00640         std::cout<<" mapChannproblem found error! "<<HDI.subdet()<<"("<<HDI.ieta()<<", "<<HDI.iphi()<<", "<<HDI.depth()<<")"<<std::endl;
00641     }
00642   }
00643 }   // void HcalRawDataClient::mapChannproblem(...)
00644 
00645 
00646 void HcalRawDataClient::normalizeHardwareSpaceHistos(void){
00648 //  // Get histograms that are used in testing
00649 //  getHardwareSpaceHistos();
00650 //
00651 //  int fed2offset=0;
00652 //  int spg2offset=0;
00653 //  int chn2offset=0;
00654 //  float tsFactor=1.0;
00655 //  float val=0.0;
00656 //
00657 //  if (!ChannSumm_DataIntegrityCheck_) return;
00658 //  //Normalize by the number of events each channel spake. (Handles ZS!)
00659 //  for (int fednum=0;fednum<NUMDCCS;fednum++) {
00660 //    fed2offset = 1 + (3*fednum); //2 bins, plus one of margin, each DCC 
00661 //    for (int spgnum=0; spgnum<15; spgnum++) {
00662 //      spg2offset = 1 + (3*spgnum); //2 bins, plus one of margin, each spigot
00663 //      numTS_[(fednum*NUMSPGS)+spgnum]=ChannSumm_DataIntegrityCheck_->GetBinContent(fed2offset,
00664 //                                                                                 spg2offset+1);
00665 //
00666 //      for (int xbin=1; xbin<=2; xbin++) {
00667 //      for (int ybin=1; ybin<=2; ybin++) {
00668 //        val = ChannSumm_DataIntegrityCheck_->GetBinContent(fed2offset+xbin,
00669 //                                                           spg2offset+ybin);
00670 //        if ( (val) && (nevts_) ) {
00671 //          //Lower pair of bins don't scale with just the timesamples per event.
00672 //          if (ybin==2) tsFactor=numTS_[spgnum +(fednum*NUMSPGS)]; 
00673 //          else {
00674 //            if (xbin==2) tsFactor=numTS_[spgnum +(fednum*NUMSPGS)]-1;
00675 //            else tsFactor=1.0;
00676 //          }
00677 //          if (tsFactor)
00678 //            ChannSumm_DataIntegrityCheck_->SetBinContent(fed2offset+xbin,
00679 //                                                         spg2offset+ybin,
00680 //                                                         val/(nevts_*tsFactor));
00681 //          val=0.0;
00682 //        }
00683 //      }
00684 //      }
00685 //      //Clear the numTS, which clutter the final plot.
00686 //      ChannSumm_DataIntegrityCheck_->SetBinContent(fed2offset  ,
00687 //                                                 spg2offset  , 0.0);
00688 //      ChannSumm_DataIntegrityCheck_->SetBinContent(fed2offset  ,
00689 //                                                 spg2offset+1, 0.0);
00690 //
00691 //      if (!Chann_DataIntegrityCheck_[fednum]) continue;  
00692 //      for (int chnnum=0; chnnum<24; chnnum++) {
00693 //      chn2offset = 1 + (3*chnnum); //2 bins, plus one of margin, each channel
00694 //      if (! (Chann_DataIntegrityCheck_[fednum]))  
00695 //        continue;
00696 //      for (int xbin=1; xbin<=2; xbin++) {
00697 //        for (int ybin=1; ybin<=2; ybin++) {
00698 //          val = Chann_DataIntegrityCheck_[fednum]->GetBinContent(chn2offset+xbin,
00699 //                                                                 spg2offset+ybin);
00700 //          if ( (val) && (nevts_) ) {
00701 //            //Lower pair of bins don't scale with just the timesamples per event.
00702 //            if (ybin==2) tsFactor=numTS_[spgnum +(fednum*NUMSPGS)]; 
00703 //            else {
00704 //              if (xbin==2) tsFactor=numTS_[spgnum +(fednum*NUMSPGS)]-1;
00705 //              else tsFactor=1.0;
00706 //            }
00707 //            if (tsFactor)
00708 //              Chann_DataIntegrityCheck_[fednum]->SetBinContent(chn2offset+xbin,
00709 //                                                               spg2offset+ybin,
00710 //                                                               val/(nevts_*tsFactor));
00711 //          }
00712 //        }
00713 //      }
00714 //      //Remove the channel's event count from sight.
00715 //      Chann_DataIntegrityCheck_[fednum]->SetBinContent(chn2offset,
00716 //                                                       spg2offset,0.0);
00717 //      }
00718 //    }
00719 //  }  
00720 }
00721 
00722 HcalRawDataClient::~HcalRawDataClient()
00723 {}