CMS 3D CMS Logo

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