CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_5/src/DQM/HcalMonitorTasks/src/HcalDeadCellMonitor.cc

Go to the documentation of this file.
00001 #include "DQM/HcalMonitorTasks/interface/HcalDeadCellMonitor.h"
00002 #include "FWCore/Framework/interface/LuminosityBlock.h"
00003 #include "CondFormats/HcalObjects/interface/HcalLogicalMap.h"
00004 
00005 HcalDeadCellMonitor::HcalDeadCellMonitor(const edm::ParameterSet& ps)
00006 {
00007   Online_                = ps.getUntrackedParameter<bool>("online",false);
00008   mergeRuns_             = ps.getUntrackedParameter<bool>("mergeRuns",false);
00009   enableCleanup_         = ps.getUntrackedParameter<bool>("enableCleanup",false);
00010   debug_                 = ps.getUntrackedParameter<int>("debug",0);
00011   makeDiagnostics_       = ps.getUntrackedParameter<bool>("makeDiagnostics",false);
00012   prefixME_              = ps.getUntrackedParameter<std::string>("subSystemFolder","Hcal/");
00013   if (prefixME_.substr(prefixME_.size()-1,prefixME_.size())!="/")
00014     prefixME_.append("/");
00015   subdir_                = ps.getUntrackedParameter<std::string>("TaskFolder","DeadCellMonitor_Hcal"); // DeadCellMonitor_Hcal
00016   if (subdir_.size()>0 && subdir_.substr(subdir_.size()-1,subdir_.size())!="/")
00017     subdir_.append("/");
00018   subdir_=prefixME_+subdir_;
00019   AllowedCalibTypes_     = ps.getUntrackedParameter<std::vector<int> > ("AllowedCalibTypes");
00020   skipOutOfOrderLS_      = ps.getUntrackedParameter<bool>("skipOutOfOrderLS",true);
00021   NLumiBlocks_           = ps.getUntrackedParameter<int>("NLumiBlocks",4000);
00022 
00023   badChannelStatusMask_   = ps.getUntrackedParameter<int>("BadChannelStatusMask",
00024                                                           ps.getUntrackedParameter<int>("BadChannelStatusMask",
00025                                                                                         (1<<HcalChannelStatus::HcalCellDead)));  // identify channel status values to mask
00026   // DeadCell-specific parameters
00027 
00028   // Collection type info
00029   digiLabel_             =ps.getUntrackedParameter<edm::InputTag>("digiLabel");
00030   hbheRechitLabel_       = ps.getUntrackedParameter<edm::InputTag>("hbheRechitLabel");
00031   hoRechitLabel_         = ps.getUntrackedParameter<edm::InputTag>("hoRechitLabel");
00032   hfRechitLabel_         = ps.getUntrackedParameter<edm::InputTag>("hfRechitLabel");
00033 
00034   // minimum number of events required for lumi section-based dead cell checks
00035   minDeadEventCount_    = ps.getUntrackedParameter<int>("minDeadEventCount",1000);
00036   excludeHORing2_       = ps.getUntrackedParameter<bool>("excludeHORing2",false);
00037   excludeHO1P02_        = ps.getUntrackedParameter<bool>("excludeHO1P02",false);
00038   endLumiProcessed_     = false;
00039 
00040   // Set which dead cell checks will be performed
00041   /* Dead cells can be defined in the following ways:
00042      1)  never present digi -- digi is never present in run
00043      2)  digis -- digi is absent for one or more lumi section 
00044      3)  never present rechit -- rechit > threshold energy never present (NOT redundant, since it requires not just that a rechit be present, but that it be above threshold as well.  )
00045      4)  rechits -- rechit is present, but rechit energy below threshold for one or more lumi sections
00046 
00047      Of these tests, never-present digis are always checked.
00048      Occasional digis are checked only if deadmon_test_digis_ is true,
00049      and both rechit tests are made only if deadmon_test_rechits_ is true
00050   */
00051   
00052   deadmon_test_digis_              = ps.getUntrackedParameter<bool>("test_digis",true);
00053   deadmon_test_rechits_            = ps.getUntrackedParameter<bool>("test_rechits",false);
00054 
00055   // rechit energy test -- cell must be below threshold value for a number of consecutive events to be considered dead
00056   energyThreshold_       = ps.getUntrackedParameter<double>("MissingRechitEnergyThreshold",0);
00057   HBenergyThreshold_     = ps.getUntrackedParameter<double>("HB_energyThreshold",energyThreshold_);
00058   HEenergyThreshold_     = ps.getUntrackedParameter<double>("HE_energyThreshold",energyThreshold_);
00059   HOenergyThreshold_     = ps.getUntrackedParameter<double>("HO_energyThreshold",energyThreshold_);
00060   HFenergyThreshold_     = ps.getUntrackedParameter<double>("HF_energyThreshold",energyThreshold_);
00061 
00062   needLogicalMap_=true;
00063   setupDone_=false;
00064 } //constructor
00065 
00066 HcalDeadCellMonitor::~HcalDeadCellMonitor()
00067 {
00068 } //destructor
00069 
00070 
00071 /* ------------------------------------ */ 
00072 
00073 void HcalDeadCellMonitor::setup()
00074 {
00075   if (setupDone_)
00076   {
00077     // Always do a zeroing/resetting so that empty histograms/counter
00078     // will always appear.
00079     zeroCounters(1); // make sure arrays are set up
00080     this->reset();
00081 
00082     return;
00083   }
00084   else
00085     setupDone_=true;
00086   
00087   HcalBaseDQMonitor::setup();
00088   if (debug_>0)
00089     std::cout <<"<HcalDeadCellMonitor::setup>  Setting up histograms"<<std::endl;
00090 
00091   if (!dbe_) return;
00092 
00093   dbe_->setCurrentFolder(subdir_);
00094   MonitorElement* excludeHO2=dbe_->bookInt("ExcludeHOring2");
00095   // Fill with 0 if ring is not to be excluded; fill with 1 if it is to be excluded
00096   if (excludeHO2) excludeHO2->Fill(excludeHORing2_==true ? 1 : 0);
00097 
00098   Nevents = dbe_->book1D("NumberOfDeadCellEvents","Number of Events Seen by DeadCellMonitor",2,0,2);
00099   Nevents->setBinLabel(1,"allEvents");
00100   Nevents->setBinLabel(2,"lumiCheck");
00101  // 1D plots count number of bad cells vs. luminosity block
00102   ProblemsVsLB=dbe_->bookProfile("TotalDeadCells_HCAL_vs_LS",
00103                                   "Total Number of Dead Hcal Cells (excluding known problems) vs LS;Lumi Section;Dead Cells", 
00104                                   NLumiBlocks_,0.5,NLumiBlocks_+0.5,
00105                                   100,0,10000);
00106   ProblemsVsLB_HB=dbe_->bookProfile("TotalDeadCells_HB_vs_LS",
00107                                      "Total Number of Dead HB Cells (excluding known problems) vs LS;Lumi Section;Dead Cells",
00108                                      NLumiBlocks_,0.5,NLumiBlocks_+0.5,
00109                                      100,0,10000);
00110   ProblemsVsLB_HE=dbe_->bookProfile("TotalDeadCells_HE_vs_LS",
00111                                      "Total Number of Dead HE Cells (excluding known problems) vs LS;Lumi Section;Dead Cells",
00112                                      NLumiBlocks_,0.5,NLumiBlocks_+0.5,100,0,10000);
00113   ProblemsVsLB_HO=dbe_->bookProfile("TotalDeadCells_HO_vs_LS",
00114                                       "Total Number of Dead HO Cells Ring 0,1 |ieta|<=10 (excluding known problems) vs LS;Lumi Section;Dead Cells",
00115                                       NLumiBlocks_,0.5,NLumiBlocks_+0.5,100,0,10000);
00116   ProblemsVsLB_HO2=dbe_->bookProfile("TotalDeadCells_HO2_vs_LS",
00117                                      "Total Number of Dead HO Cells Ring 2 |ieta|>10 (excluding known problems) vs LS;Lumi Section;Dead Cells",
00118                                      NLumiBlocks_,0.5,NLumiBlocks_+0.5,100,0,10000);
00119   ProblemsVsLB_HF=dbe_->bookProfile("TotalDeadCells_HF_vs_LS",
00120                                      "Total Number of Dead HF Cells (excluding known problems) vs LS;Lumi Section;Dead Cells",
00121                                      NLumiBlocks_,0.5,NLumiBlocks_+0.5,100,0,10000);
00122   ProblemsVsLB_HBHEHF=dbe_->bookProfile("TotalDeadCells_HBHEHF_vs_LS",
00123                                      "Total Number of Dead HBHEHF Cells (excluding known problems) vs LS;Lumi Section;Dead Cells",
00124                                      NLumiBlocks_,0.5,NLumiBlocks_+0.5,100,0,10000);
00125   
00126   (ProblemsVsLB->getTProfile())->SetMarkerStyle(20);
00127   (ProblemsVsLB_HB->getTProfile())->SetMarkerStyle(20);
00128   (ProblemsVsLB_HE->getTProfile())->SetMarkerStyle(20);
00129   (ProblemsVsLB_HO->getTProfile())->SetMarkerStyle(20);
00130   (ProblemsVsLB_HO2->getTProfile())->SetMarkerStyle(20);
00131   (ProblemsVsLB_HF->getTProfile())->SetMarkerStyle(20);
00132   (ProblemsVsLB_HBHEHF->getTProfile())->SetMarkerStyle(20);
00133 
00134   RBX_loss_VS_LB=dbe_->book2D("RBX_loss_VS_LB",
00135                               "RBX loss vs LS; Lumi Section; Index of lost RBX", 
00136                               NLumiBlocks_,0.5,NLumiBlocks_+0.5,156,0,156);
00137 
00138   ProblemsInLastNLB_HBHEHF_alarm=dbe_->book1D("ProblemsInLastNLB_HBHEHF_alarm",
00139                                               "Total Number of Dead HBHEHF Cells in last 10 LS. Last bin contains OverFlow",
00140                                               100,0,100);
00141   ProblemsInLastNLB_HO01_alarm=dbe_->book1D("ProblemsInLastNLB_HO01_alarm",
00142                                             "Total Number of Dead Cells Ring 0,1 (abs(ieta)<=10) in last 10 LS. Last bin contains OverFlow",
00143                                             100,0,100);
00144 
00145 
00146   dbe_->setCurrentFolder(subdir_+"dead_cell_parameters");
00147   MonitorElement* me=dbe_->bookInt("Test_NeverPresent_Digis");
00148   me->Fill(1);
00149   me=dbe_->bookInt("Test_DigiMissing_Periodic_Lumi_Check");
00150   if (deadmon_test_digis_)
00151     me->Fill(1);
00152   else 
00153     me->Fill(0);
00154   me=dbe_->bookInt("Min_Events_Required_Periodic_Lumi_Check");
00155   me->Fill(minDeadEventCount_);
00156   me=dbe_->bookInt("Test_NeverPresent_RecHits");
00157   deadmon_test_rechits_>0 ? me->Fill(1) : me->Fill(0);
00158   me=dbe_->bookFloat("HBMinimumRecHitEnergy");
00159   me->Fill(HBenergyThreshold_);
00160   me=dbe_->bookFloat("HEMinimumRecHitEnergy");
00161   me->Fill(HEenergyThreshold_);
00162   me=dbe_->bookFloat("HOMinimumRecHitEnergy");
00163   me->Fill(HOenergyThreshold_);
00164   me=dbe_->bookFloat("HFMinimumRecHitEnergy");
00165   me->Fill(HFenergyThreshold_);
00166   me=dbe_->bookInt("Test_RecHitsMissing_Periodic_Lumi_Check");
00167   deadmon_test_rechits_>0 ? me->Fill(1) : me->Fill(0);
00168 
00169   // ProblemCells plots are in HcalDeadCellClient!
00170       
00171   // Set up plots for each failure mode of dead cells
00172   std::stringstream units; // We'll need to set the titles individually, rather than passing units to SetupEtaPhiHists (since this also would affect the name of the histograms)
00173   std::stringstream name;
00174 
00175   // Never-present test will always be called, by definition of dead cell
00176 
00177   dbe_->setCurrentFolder(subdir_+"dead_digi_never_present");
00178   SetupEtaPhiHists(DigiPresentByDepth,
00179                    "Digi Present At Least Once","");
00180   // 1D plots count number of bad cells
00181   NumberOfNeverPresentDigis=dbe_->bookProfile("Problem_NeverPresentDigis_HCAL_vs_LS",
00182                                                "Total Number of Never-Present Hcal Cells vs LS;Lumi Section;Dead Cells",
00183                                                NLumiBlocks_,0.5,NLumiBlocks_+0.5,100,0,10000);
00184       
00185   NumberOfNeverPresentDigisHB=dbe_->bookProfile("Problem_NeverPresentDigis_HB_vs_LS",
00186                                                  "Total Number of Never-Present HB Cells vs LS;Lumi Section;Dead Cells",
00187                                                  NLumiBlocks_,0.5,NLumiBlocks_+0.5,100,0,10000);
00188       
00189   NumberOfNeverPresentDigisHE=dbe_->bookProfile("Problem_NeverPresentDigis_HE_vs_LS",
00190                                                  "Total Number of Never-Present HE Cells vs LS;Lumi Section;Dead Cells",
00191                                                  NLumiBlocks_,0.5,NLumiBlocks_+0.5,100,0,10000);
00192       
00193   NumberOfNeverPresentDigisHO=dbe_->bookProfile("Problem_NeverPresentDigis_HO_vs_LS",
00194                                                  "Total Number of Never-Present HO Cells vs LS;Lumi Section;Dead Cells",
00195                                                  NLumiBlocks_,0.5,NLumiBlocks_+0.5,100,0,10000);
00196       
00197   NumberOfNeverPresentDigisHF=dbe_->bookProfile("Problem_NeverPresentDigis_HF_vs_LS",
00198                                                  "Total Number of Never-Present HF Cells vs LS;Lumi Section;Dead Cells",
00199                                                  NLumiBlocks_,0.5,NLumiBlocks_+0.5,100,0,10000);
00200   (NumberOfNeverPresentDigis->getTProfile())->SetMarkerStyle(20);
00201   (NumberOfNeverPresentDigisHB->getTProfile())->SetMarkerStyle(20);
00202   (NumberOfNeverPresentDigisHE->getTProfile())->SetMarkerStyle(20);
00203   (NumberOfNeverPresentDigisHO->getTProfile())->SetMarkerStyle(20);
00204   (NumberOfNeverPresentDigisHF->getTProfile())->SetMarkerStyle(20);
00205 
00206   FillUnphysicalHEHFBins(DigiPresentByDepth);
00207 
00208   if (deadmon_test_digis_)
00209     {
00210       dbe_->setCurrentFolder(subdir_+"dead_digi_often_missing");
00211       //units<<"("<<deadmon_checkNevents_<<" consec. events)";
00212       name<<"Dead Cells with No Digis";
00213       SetupEtaPhiHists(RecentMissingDigisByDepth,
00214                        name.str(),
00215                        "");
00216       name.str("");
00217       name<<"HB HE HF Depth 1 Dead Cells with No Digis for at least 1 Full Luminosity Block"; 
00218       RecentMissingDigisByDepth.depth[0]->setTitle(name.str().c_str());
00219 
00220       name.str("");
00221       name<<"HB HE HF Depth 2 Dead Cells with No Digis for at least 1 Full Luminosity Block";
00222       RecentMissingDigisByDepth.depth[1]->setTitle(name.str().c_str());
00223 
00224       name.str("");
00225       name<<"HE Depth 3 Dead Cells with No Digis for at least 1 Full Luminosity Block";
00226       RecentMissingDigisByDepth.depth[2]->setTitle(name.str().c_str());
00227 
00228       name.str("");
00229       name<<"HO Depth 4 Dead Cells with No Digis for at least 1 Full Luminosity Block";
00230       RecentMissingDigisByDepth.depth[3]->setTitle(name.str().c_str());
00231       name.str("");
00232 
00233       // 1D plots count number of bad cells
00234       name<<"Total Number of Hcal Digis Unoccupied for at least 1 Full Luminosity Block"; 
00235       NumberOfRecentMissingDigis=dbe_->bookProfile("Problem_RecentMissingDigis_HCAL_vs_LS",
00236                                                     name.str(),
00237                                                     NLumiBlocks_,0.5,NLumiBlocks_+0.5,100,0,10000);
00238       name.str("");
00239       name<<"Total Number of HB Digis Unoccupied for at least 1 Full LS vs LS;Lumi Section; Dead Cells";
00240       NumberOfRecentMissingDigisHB=dbe_->bookProfile("Problem_RecentMissingDigis_HB_vs_LS",
00241                                                       name.str(),
00242                                                       NLumiBlocks_,0.5,NLumiBlocks_+0.5,100,0,10000);
00243       name.str("");
00244       name<<"Total Number of HE Digis Unoccupied for at least 1 Full LS vs LS;Lumi Section; Dead Cells";
00245       NumberOfRecentMissingDigisHE=dbe_->bookProfile("Problem_RecentMissingDigis_HE_vs_LS",
00246                                                       name.str(),
00247                                                       NLumiBlocks_,0.5,NLumiBlocks_+0.5,100,0,10000);
00248       name.str("");
00249       name<<"Total Number of HO Digis Unoccupied for at least 1 Full LS vs LS;Lumi Section; Dead Cells";
00250       NumberOfRecentMissingDigisHO=dbe_->bookProfile("Problem_RecentMissingDigis_HO_vs_LS",
00251                                                       name.str(),
00252                                                       NLumiBlocks_,0.5,NLumiBlocks_+0.5,100,0,10000);
00253       name.str("");
00254       name<<"Total Number of HF Digis Unoccupied for at least 1 Full LS vs LS;Lumi Section; Dead Cells";
00255       NumberOfRecentMissingDigisHF=dbe_->bookProfile("Problem_RecentMissingDigis_HF_vs_LS",
00256                                                       name.str(),
00257                                                       NLumiBlocks_,0.5,NLumiBlocks_+0.5,100,0,10000);
00258       (NumberOfRecentMissingDigis->getTProfile())->SetMarkerStyle(20);
00259       (NumberOfRecentMissingDigisHB->getTProfile())->SetMarkerStyle(20);
00260       (NumberOfRecentMissingDigisHE->getTProfile())->SetMarkerStyle(20);
00261       (NumberOfRecentMissingDigisHO->getTProfile())->SetMarkerStyle(20);
00262       (NumberOfRecentMissingDigisHF->getTProfile())->SetMarkerStyle(20);
00263 
00264     }
00265       
00266   if (deadmon_test_rechits_)
00267     {
00268       // test 1:  energy never above threshold
00269       dbe_->setCurrentFolder(subdir_+"dead_rechit_neverpresent");
00270       SetupEtaPhiHists(RecHitPresentByDepth,"RecHit Above Threshold At Least Once","");
00271       // set more descriptive titles for threshold plots
00272       units.str("");
00273       units<<"Cells Above Energy Threshold At Least Once: Depth 1 -- HB >="<<HBenergyThreshold_<<" GeV, HE >= "<<HEenergyThreshold_<<", HF >="<<HFenergyThreshold_<<" GeV";
00274       RecHitPresentByDepth.depth[0]->setTitle(units.str().c_str());
00275       units.str("");
00276       units<<"Cells Above Energy Threshold At Least Once: Depth 2 -- HB >="<<HBenergyThreshold_<<" GeV, HE >= "<<HEenergyThreshold_<<", HF >="<<HFenergyThreshold_<<" GeV";
00277       RecHitPresentByDepth.depth[1]->setTitle(units.str().c_str());
00278       units.str("");
00279       units<<"Cells Above Energy Threshold At Least Once: Depth 3 -- HE >="<<HEenergyThreshold_<<" GeV";
00280       RecHitPresentByDepth.depth[2]->setTitle(units.str().c_str());
00281       units.str("");
00282       units<<"Cells Above Energy Threshold At Least Once: Depth 4 -- HO >="<<HOenergyThreshold_<<" GeV";
00283       RecHitPresentByDepth.depth[3]->setTitle(units.str().c_str());
00284       units.str("");
00285 
00286       // 1D plots count number of bad cells
00287       NumberOfNeverPresentRecHits=dbe_->bookProfile("Problem_RecHitsNeverPresent_HCAL_vs_LS",
00288                                                      "Total Number of Hcal Rechits with Low Energy;Lumi Section;Dead Cells",
00289                                                      NLumiBlocks_,0.5,NLumiBlocks_+0.5,100,0,10000);
00290       name.str("");
00291       name<<"Total Number of HB RecHits with Energy Never >= "<<HBenergyThreshold_<<" GeV;Lumi Section;Dead Cells";
00292       NumberOfNeverPresentRecHitsHB=dbe_->bookProfile("Problem_RecHitsNeverPresent_HB_vs_LS",
00293                                                        name.str(),
00294                                                        NLumiBlocks_,0.5,NLumiBlocks_+0.5,100,0,10000);
00295       name.str("");
00296       name<<"Total Number of HE RecHits with Energy Never >= "<<HEenergyThreshold_<<" GeV;Lumi Section;Dead Cells";
00297       NumberOfNeverPresentRecHitsHE=dbe_->bookProfile("Problem_RecHitsNeverPresent_HE_vs_LS",
00298                                                        name.str(),
00299                                                        NLumiBlocks_,0.5,NLumiBlocks_+0.5,100,0,10000);
00300       name.str("");
00301       name<<"Total Number of HO RecHits with Energy Never >= "<<HOenergyThreshold_<<" GeV;Lumi Section;Dead Cells";
00302       NumberOfNeverPresentRecHitsHO=dbe_->bookProfile("Problem_RecHitsNeverPresent_HO_vs_LS",
00303                                                        name.str(),
00304                                                        NLumiBlocks_,0.5,NLumiBlocks_+0.5,100,0,10000);
00305       name.str("");
00306       name<<"Total Number of HF RecHits with Energy Never >= "<<HFenergyThreshold_<<" GeV;Lumi Section;Dead Cells";
00307       NumberOfNeverPresentRecHitsHF=dbe_->bookProfile("Problem_RecHitsNeverPresent_HF_vs_LS",
00308                                                        name.str(),
00309                                                        NLumiBlocks_,0.5,NLumiBlocks_+0.5,100,0,10000);
00310       (NumberOfNeverPresentRecHits->getTProfile())->SetMarkerStyle(20);
00311       (NumberOfNeverPresentRecHitsHB->getTProfile())->SetMarkerStyle(20);
00312       (NumberOfNeverPresentRecHitsHE->getTProfile())->SetMarkerStyle(20);
00313       (NumberOfNeverPresentRecHitsHO->getTProfile())->SetMarkerStyle(20);
00314       (NumberOfNeverPresentRecHitsHF->getTProfile())->SetMarkerStyle(20);
00315  
00316       dbe_->setCurrentFolder(subdir_+"dead_rechit_often_missing");
00317       SetupEtaPhiHists(RecentMissingRecHitsByDepth,"RecHits Failing Energy Threshold Test","");
00318       // set more descriptive titles for threshold plots
00319       units.str("");
00320       units<<"RecHits with Consistent Low Energy Depth 1 -- HB <"<<HBenergyThreshold_<<" GeV, HE < "<<HEenergyThreshold_<<", HF <"<<HFenergyThreshold_<<" GeV";
00321       RecentMissingRecHitsByDepth.depth[0]->setTitle(units.str().c_str());
00322       units.str("");
00323       units<<"RecHits with Consistent Low Energy Depth 2 -- HB <"<<HBenergyThreshold_<<" GeV, HE < "<<HEenergyThreshold_<<", HF <"<<HFenergyThreshold_<<" GeV";
00324       RecentMissingRecHitsByDepth.depth[1]->setTitle(units.str().c_str());
00325       units.str("");
00326       units<<"RecHits with Consistent Low Energy Depth 3 -- HE <"<<HEenergyThreshold_<<" GeV";
00327       RecentMissingRecHitsByDepth.depth[2]->setTitle(units.str().c_str());
00328       units.str("");
00329       units<<"RecHits with Consistent Low Energy Depth 4 -- HO <"<<HOenergyThreshold_<<" GeV";
00330       RecentMissingRecHitsByDepth.depth[3]->setTitle(units.str().c_str());
00331       units.str("");
00332 
00333 
00334       // 1D plots count number of bad cells
00335       name.str("");
00336       name<<"Total Number of Hcal RecHits with Consistent Low Energy;Lumi Section;Dead Cells";
00337       NumberOfRecentMissingRecHits=dbe_->bookProfile("Problem_BelowEnergyRecHits_HCAL_vs_LS",
00338                                                       name.str(),
00339                                                       NLumiBlocks_,0.5,NLumiBlocks_+0.5,100,0,10000);
00340       name.str("");
00341       name<<"Total Number of HB RecHits with Consistent Low Energy < "<<HBenergyThreshold_<<" GeV;Lumi Section;Dead Cells";
00342       NumberOfRecentMissingRecHitsHB=dbe_->bookProfile("Problem_BelowEnergyRecHits_HB_vs_LS",
00343                                                         name.str(),
00344                                                         NLumiBlocks_,0.5,NLumiBlocks_+0.5,100,0,10000);
00345       name.str("");
00346       name<<"Total Number of HE RecHits with Consistent Low Energy < "<<HEenergyThreshold_<<" GeV;Lumi Section;Dead Cells";
00347       NumberOfRecentMissingRecHitsHE=dbe_->bookProfile("Problem_BelowEnergyRecHits_HE_vs_LS",
00348                                                         name.str(),
00349                                                         NLumiBlocks_,0.5,NLumiBlocks_+0.5,100,0,10000);
00350       name.str("");
00351       name<<"Total Number of HO RecHits with Consistent Low Energy < "<<HOenergyThreshold_<<" GeV;Lumi Section;Dead Cells";
00352       NumberOfRecentMissingRecHitsHO=dbe_->bookProfile("Problem_BelowEnergyRecHits_HO_vs_LS",
00353                                                         name.str(),
00354                                                         NLumiBlocks_,0.5,NLumiBlocks_+0.5,100,0,10000);
00355       name.str("");
00356       name<<"Total Number of HF RecHits with Consistent Low Energy < "<<HFenergyThreshold_<<" GeV;Lumi Section;Dead Cells";
00357       NumberOfRecentMissingRecHitsHF=dbe_->bookProfile("Problem_BelowEnergyRecHits_HF_vs_LS",
00358                                                         name.str(),
00359                                                         NLumiBlocks_,0.5,NLumiBlocks_+0.5,100,0,10000);
00360       (NumberOfRecentMissingRecHits->getTProfile())->SetMarkerStyle(20);
00361       (NumberOfRecentMissingRecHitsHB->getTProfile())->SetMarkerStyle(20);
00362       (NumberOfRecentMissingRecHitsHE->getTProfile())->SetMarkerStyle(20);
00363       (NumberOfRecentMissingRecHitsHO->getTProfile())->SetMarkerStyle(20);
00364       (NumberOfRecentMissingRecHitsHF->getTProfile())->SetMarkerStyle(20);
00365 
00366     } // if (deadmon_test_rechits)
00367 
00368 
00369   if (makeDiagnostics_)
00370     {
00371       dbe_->setCurrentFolder(subdir_+"DiagnosticPlots");
00372       HBDeadVsEvent=dbe_->book1D("HBDeadVsEvent","HB Total Dead Cells Vs Event", NLumiBlocks_/10,-0.5,NLumiBlocks_-0.5);
00373       HEDeadVsEvent=dbe_->book1D("HEDeadVsEvent","HE Total Dead Cells Vs Event", NLumiBlocks_/10,-0.5,NLumiBlocks_-0.5);
00374       HODeadVsEvent=dbe_->book1D("HODeadVsEvent","HO Total Dead Cells Vs Event", NLumiBlocks_/10,-0.5,NLumiBlocks_-0.5);
00375       HFDeadVsEvent=dbe_->book1D("HFDeadVsEvent","HF Total Dead Cells Vs Event", NLumiBlocks_/10,-0.5,NLumiBlocks_-0.5);
00376     }
00377 
00378   return;
00379 
00380 } // void HcalDeadCellMonitor::setup(...)
00381 
00382 void HcalDeadCellMonitor::beginRun(const edm::Run& run, const edm::EventSetup& c)
00383 {
00384   if (debug_>1) std::cout <<"HcalDeadCellMonitor::beginRun"<<std::endl;
00385   HcalBaseDQMonitor::beginRun(run,c);
00386 
00387   if (tevt_==0) this->setup(); // set up histograms if they have not been created before
00388   if (mergeRuns_==false)
00389     this->reset();
00390 
00391   doReset_ = true;
00392 
00393   // Get known dead cells for this run
00394   KnownBadCells_.clear();
00395   if (badChannelStatusMask_>0)
00396     {
00397       edm::ESHandle<HcalChannelQuality> p;
00398       c.get<HcalChannelQualityRcd>().get(p);
00399       HcalChannelQuality* chanquality= new HcalChannelQuality(*p.product());
00400       std::vector<DetId> mydetids = chanquality->getAllChannels();
00401       for (std::vector<DetId>::const_iterator i = mydetids.begin();
00402            i!=mydetids.end();
00403            ++i)
00404         {
00405           if (i->det()!=DetId::Hcal) continue; // not an hcal cell
00406           HcalDetId id=HcalDetId(*i);
00407           int status=(chanquality->getValues(id))->getValue();
00408           if ((status & badChannelStatusMask_))
00409             KnownBadCells_[id.rawId()]=status;
00410         } 
00411       delete chanquality;
00412     } // if (badChannelStatusMask_>0)
00413   return;
00414 } //void HcalDeadCellMonitor::beginRun(...)
00415 
00416 void HcalDeadCellMonitor::reset()
00417 {
00418   if (debug_>1) std::cout <<"HcalDeadCellMonitor::reset()"<<std::endl;
00419   doReset_ = false;
00420 
00421   HcalBaseDQMonitor::reset();
00422   zeroCounters();
00423   deadevt_=0;
00424   is_RBX_loss_ = 0;
00425   beamMode_ = 0 ;
00426   alarmer_counter_ = 0;
00427   alarmer_counterHO01_ = 0;
00428   is_stable_beam = true;
00429   hbhedcsON = true; hfdcsON = true; hodcsON = true;
00430   ProblemsVsLB->Reset(); ProblemsVsLB_HB->Reset(); ProblemsVsLB_HE->Reset(); ProblemsVsLB_HO->Reset(); ProblemsVsLB_HO2->Reset(); ProblemsVsLB_HF->Reset(); ProblemsVsLB_HBHEHF->Reset();
00431   RBX_loss_VS_LB->Reset();
00432   ProblemsInLastNLB_HBHEHF_alarm->Reset();
00433   ProblemsInLastNLB_HO01_alarm->Reset();
00434   NumberOfNeverPresentDigis->Reset(); NumberOfNeverPresentDigisHB->Reset(); NumberOfNeverPresentDigisHE->Reset(); NumberOfNeverPresentDigisHO->Reset(); NumberOfNeverPresentDigisHF->Reset();
00435 
00436   for (unsigned int depth=0;depth<DigiPresentByDepth.depth.size();++depth)
00437     DigiPresentByDepth.depth[depth]->Reset();
00438 
00439   // Mark HORing2 channels as present  (fill with a 2, rather than a 1, to distinguish between this setting and actual presence)
00440   if (excludeHORing2_==true && DigiPresentByDepth.depth.size()>3)
00441     {
00442       for (int ieta=11;ieta<=15;++ieta)
00443         for (int iphi=1;iphi<=72;++iphi)
00444           {
00445             // Don't fill ring2 SiPMs, since they will still be active even if the rest of HO is excluded.
00446             if (isSiPM(ieta,iphi,4)==false)
00447               DigiPresentByDepth.depth[3]->Fill(ieta,iphi,2);
00448             //std::cout <<" FILLING ("<<-1*ieta<<", "<<iphi<<") with '2'"<<std::endl;
00449             DigiPresentByDepth.depth[3]->Fill(-1*ieta,iphi,2);
00450           }
00451     }
00452   FillUnphysicalHEHFBins(DigiPresentByDepth);
00453 
00454 
00455   if (deadmon_test_digis_)
00456     {
00457       NumberOfRecentMissingDigis->Reset(); NumberOfRecentMissingDigisHB->Reset(); NumberOfRecentMissingDigisHE->Reset(); NumberOfRecentMissingDigisHO->Reset(); NumberOfRecentMissingDigisHF->Reset();
00458       RecentMissingDigisByDepth.Reset();
00459     }
00460   if (deadmon_test_rechits_)
00461     {
00462       NumberOfRecentMissingRecHits->Reset();
00463       NumberOfRecentMissingRecHitsHB->Reset();
00464       NumberOfRecentMissingRecHitsHE->Reset();
00465       NumberOfRecentMissingRecHitsHO->Reset(); 
00466       NumberOfRecentMissingRecHitsHF->Reset();
00467       NumberOfNeverPresentRecHits->Reset(); 
00468       NumberOfNeverPresentRecHitsHB->Reset(); 
00469       NumberOfNeverPresentRecHitsHE->Reset(); 
00470       NumberOfNeverPresentRecHitsHO->Reset(); 
00471       NumberOfNeverPresentRecHitsHF->Reset();
00472       RecentMissingRecHitsByDepth.Reset();
00473       RecHitPresentByDepth.Reset();
00474       
00475       // Mark HORing2 channels as present  (fill with a 2, rather than a 1, to distinguish between this setting and actual presence)
00476       if (excludeHORing2_==true && RecHitPresentByDepth.depth.size()>3)
00477         {
00478           for (int ieta=11;ieta<=15;++ieta)
00479             for (int iphi=1;iphi<=72;++iphi)
00480               {
00481                 RecHitPresentByDepth.depth[3]->Fill(ieta,iphi,2);
00482                 RecHitPresentByDepth.depth[3]->Fill(-1*ieta,iphi,2);
00483               }
00484         }
00485       FillUnphysicalHEHFBins(RecHitPresentByDepth);
00486     }
00487 
00488   Nevents->Reset();
00489 }  // reset function is empty for now
00490 
00491 /* ------------------------------------------------------------------------- */
00492 
00493 
00494 void HcalDeadCellMonitor::cleanup()
00495 {
00496   if (!enableCleanup_) return;
00497   if (dbe_)
00498     {
00499       dbe_->setCurrentFolder(subdir_);
00500       dbe_->removeContents();
00501       dbe_->setCurrentFolder(subdir_+"dead_digi_never_present");
00502       dbe_->removeContents();
00503       dbe_->setCurrentFolder(subdir_+"dead_digi_often_missing");
00504       dbe_->removeContents();
00505       dbe_->setCurrentFolder(subdir_+"dead_rechit_neverpresent");
00506       dbe_->removeContents();
00507       dbe_->setCurrentFolder(subdir_+"dead_rechit_often_missing");
00508       dbe_->removeContents();
00509       dbe_->setCurrentFolder(subdir_+"dead_cell_parameters");
00510       dbe_->removeContents();
00511       dbe_->setCurrentFolder(subdir_+"LSvalues");
00512       dbe_->removeContents();
00513     }
00514   return;
00515 } // void HcalDeadCellMonitor::cleanup()
00516 
00517 /* ------------------------------------------------------------------------- */
00518 
00519 void HcalDeadCellMonitor::endLuminosityBlock(const edm::LuminosityBlock& lumiSeg,
00520                                              const edm::EventSetup& c)
00521 {
00522   // skip old lumi sections
00523   if (this->LumiInOrder(lumiSeg.luminosityBlock())==false) return;
00524 
00525   // Reset current LS histogram
00526   if (ProblemsCurrentLB)
00527       ProblemsCurrentLB->Reset();
00528 
00529   ProblemsInLastNLB_HBHEHF_alarm->Reset();
00530   ProblemsInLastNLB_HO01_alarm->Reset();
00531 
00532   //increase the number of LS counting, for alarmer. Only make alarms for HBHE
00533   if(hbhedcsON == true && hfdcsON == true && HBpresent_ == 1 && HEpresent_ == 1 && HFpresent_ == 1)
00534     ++alarmer_counter_;
00535   else 
00536     alarmer_counter_ = 0;
00537 
00538   if(hodcsON==true && HOpresent_ == 1)
00539     ++alarmer_counterHO01_;
00540   else 
00541     alarmer_counterHO01_ = 0;
00542 
00543   if (!is_stable_beam)
00544     {
00545       alarmer_counter_ = 0;
00546       alarmer_counterHO01_ = 0;
00547     }
00548 
00549   // Here is where we determine whether or not to process an event
00550   // Not enough events
00551   // there are less than minDeadEventCount_ in this LS, but RBXloss is found
00552   
00553   if (deadevt_>=10 && deadevt_<minDeadEventCount_ && is_RBX_loss_==1)
00554     {
00555       fillNevents_problemCells();
00556       fillNevents_recentrechits();
00557       fillNevents_recentdigis();
00558             
00559       endLumiProcessed_=true;
00560       is_RBX_loss_=0;
00561 
00562       for (unsigned int i=0;i<156;++i)
00563         rbxlost[i] = 0;
00564 
00565       if (ProblemsCurrentLB)
00566         {
00567           ProblemsCurrentLB->setBinContent(0,0, levt_);  // underflow bin contains number of events
00568           ProblemsCurrentLB->setBinContent(1,1, NumBadHB*levt_);
00569           ProblemsCurrentLB->setBinContent(2,1, NumBadHE*levt_);
00570           ProblemsCurrentLB->setBinContent(3,1, NumBadHO*levt_);
00571           ProblemsCurrentLB->setBinContent(4,1, NumBadHF*levt_);
00572           ProblemsCurrentLB->setBinContent(5,1, NumBadHO0*levt_);
00573           ProblemsCurrentLB->setBinContent(6,1, NumBadHO12*levt_);
00574           ProblemsCurrentLB->setBinContent(7,1, NumBadHFLUMI*levt_);
00575         }
00576     }
00577 
00578   if (deadevt_<minDeadEventCount_) // perform normal tasks, since no RBX loss is detected in this lumisections
00579       return;
00580     
00581   endLumiProcessed_=true;
00582   // fillNevents_problemCells checks for never-present cells
00583   fillNevents_problemCells();
00584   fillNevents_recentdigis();
00585   fillNevents_recentrechits();
00586 
00587   if (ProblemsCurrentLB)
00588     {
00589       ProblemsCurrentLB->setBinContent(0,0, levt_);  // underflow bin contains number of events
00590       ProblemsCurrentLB->setBinContent(1,1, NumBadHB*levt_);
00591       ProblemsCurrentLB->setBinContent(2,1, NumBadHE*levt_);
00592       ProblemsCurrentLB->setBinContent(3,1, NumBadHO*levt_);
00593       ProblemsCurrentLB->setBinContent(4,1, NumBadHF*levt_);
00594       ProblemsCurrentLB->setBinContent(5,1, NumBadHO0*levt_);
00595       ProblemsCurrentLB->setBinContent(6,1, NumBadHO12*levt_);
00596       ProblemsCurrentLB->setBinContent(7,1, NumBadHFLUMI*levt_);
00597     }
00598   zeroCounters();
00599   deadevt_=0;
00600   is_RBX_loss_=0;
00601   beamMode_ = 0;
00602   return;
00603 } //endLuminosityBlock()
00604 
00605 void HcalDeadCellMonitor::endRun(const edm::Run& run, const edm::EventSetup& c)
00606 {
00607   // Always carry out overall occupancy test at endRun, regardless minimum number of events?  
00608   // Or should we require an absolute lower bound?
00609   // We can always run this test; we'll use the summary client to implement a lower bound before calculating reportSummary values
00610   if (endLumiProcessed_==false) fillNevents_problemCells(); // always check for never-present cells
00611 
00612   return;
00613 }
00614 
00615 void HcalDeadCellMonitor::endJob()
00616 {
00617   if (debug_>0) std::cout <<"HcalDeadCellMonitor::endJob()"<<std::endl;
00618   if (enableCleanup_) cleanup(); // when do we force cleanup?
00619 }
00620 
00621 void HcalDeadCellMonitor::analyze(edm::Event const&e, edm::EventSetup const&s)
00622 {
00623   if (!IsAllowedCalibType()) return;
00624   endLumiProcessed_=false;
00625 
00626   if(doReset_) 
00627     this->reset();
00628 
00629   Nevents->Fill(0,1); // count all events of allowed calibration type, even if their lumi block is not in the right order
00630   if (LumiInOrder(e.luminosityBlock())==false) return;
00631   // try to get rechits and digis
00632   edm::Handle<HBHEDigiCollection> hbhe_digi;
00633   edm::Handle<HODigiCollection> ho_digi;
00634   edm::Handle<HFDigiCollection> hf_digi;
00635 
00636   edm::Handle<HBHERecHitCollection> hbhe_rechit;
00637   edm::Handle<HORecHitCollection> ho_rechit;
00638   edm::Handle<HFRecHitCollection> hf_rechit;
00639 
00640   edm::Handle<L1GlobalTriggerEvmReadoutRecord> gtEvm_handle;
00641  
00643   // check if detectors whether they were ON
00644   edm::Handle<DcsStatusCollection> dcsStatus;
00645   e.getByLabel("scalersRawToDigi", dcsStatus);
00646   
00647   if (dcsStatus.isValid() && dcsStatus->size() != 0) 
00648     {      
00649       if ((*dcsStatus)[0].ready(DcsStatus::HBHEa) &&
00650           (*dcsStatus)[0].ready(DcsStatus::HBHEb) &&   
00651           (*dcsStatus)[0].ready(DcsStatus::HBHEc))
00652         {       
00653           hbhedcsON = true;
00654           if (debug_) std::cout << "hbhe on" << std::endl;
00655         } 
00656       else hbhedcsON = false;
00657 
00658       if ((*dcsStatus)[0].ready(DcsStatus::HF))
00659         {
00660           hfdcsON = true;
00661           if (debug_) std::cout << "hf on" << std::endl;
00662         } 
00663       else hfdcsON = false;
00664       
00665       if ((*dcsStatus)[0].ready(DcsStatus::HO))
00666         {
00667           hodcsON = true;
00668           if (debug_) std::cout << "ho on" << std::endl;
00669         } 
00670       else hodcsON = false;     
00671     }
00673 
00674   if (!(e.getByLabel(digiLabel_,hbhe_digi)))
00675     {
00676       edm::LogWarning("HcalDeadCellMonitor")<< digiLabel_<<" hbhe_digi not available";
00677       return;
00678     }
00679   if (!(e.getByLabel(digiLabel_,ho_digi)))
00680     {
00681       edm::LogWarning("HcalDeadCellMonitor")<< digiLabel_<<" ho_digi not available";
00682       return;
00683     }
00684   if (!(e.getByLabel(digiLabel_,hf_digi)))
00685     {
00686       edm::LogWarning("HcalDeadCellMonitor")<< digiLabel_<<" hf_digi not available";
00687       return;
00688     }
00689 
00690   if (!(e.getByLabel(hbheRechitLabel_,hbhe_rechit)))
00691     {
00692       edm::LogWarning("HcalDeadCellMonitor")<< hbheRechitLabel_<<" hbhe_rechit not available";
00693       return;
00694     }
00695 
00696   if (!(e.getByLabel(hfRechitLabel_,hf_rechit)))
00697     {
00698       edm::LogWarning("HcalDeadCellMonitor")<< hfRechitLabel_<<" hf_rechit not available";
00699       return;
00700     }
00701   if (!(e.getByLabel(hoRechitLabel_,ho_rechit)))
00702     {
00703       edm::LogWarning("HcalDeadCellMonitor")<< hoRechitLabel_<<" ho_rechit not available";
00704       return;
00705     }
00706   if (!(e.getByLabel("gtEvmDigis", gtEvm_handle)))
00707     {
00708       edm::LogWarning("HcalDeadCellMonitor")<< "gtEvmDigis"<<" gtEvmDigis not available";
00709       return;
00710     }
00711   L1GtfeExtWord gtfeEvmExtWord = gtEvm_handle.product()->gtfeWord();
00712 
00713   if (debug_>1) std::cout <<"\t<HcalDeadCellMonitor::analyze>  Processing good event! event # = "<<ievt_<<std::endl;
00714   // Good event found; increment counter (via base class analyze method)
00715   // This also runs the allowed calibration /lumi in order tests again;  remove?
00716   HcalBaseDQMonitor::analyze(e,s);
00717   
00718   ++deadevt_; //increment local counter
00719   
00720   processEvent(*hbhe_rechit, *ho_rechit, *hf_rechit, *hbhe_digi, *ho_digi, *hf_digi);
00721       
00722   // check for presence of an RBX data loss
00723   if(levt_>10 && tevt_ % 10 == 0 ) //levt_ counts events perLS, but excludes 
00724     {                              //"wrong", calibration-type events. Compare with tevt_ instead...            
00725       for(int i=71; i<132; i++)
00726         {
00727           // These RBXs in HO are excluded, set to 1 to ignore
00728           // HO0: 96-107 (all)
00729           // HO1: 85-95, 109-119 (all odd)
00730           // HO2: 73, 75, 79, 81, 83, 121-131 (all odd)   
00731           if(i >= 72 && i < 95 && i%2==0)
00732             occupancy_RBX[i] = 1;
00733           if(i >=108 && i <= 131 && i%2==0)
00734             occupancy_RBX[i] = 1;
00735 
00736           if(i==117 || i==131) // HO SiPMs have much less hits, 10 events not enough. 
00737             occupancy_RBX[i] = 1;  // Also no RBX loss for SiPMs, so ignore for now.
00738           if(i==77)
00739             occupancy_RBX[i] = 1; 
00740         }
00741       
00742       // RBX loss detected
00743       for (unsigned int i=0;i<132;++i)
00744         if(occupancy_RBX[i] == 0) 
00745           {
00746             is_RBX_loss_ = 1;
00747             rbxlost[i] = 1;
00748           }
00749       
00750       int intensity1_ = gtfeEvmExtWord.totalIntensityBeam1();
00751       int intensity2_ = gtfeEvmExtWord.totalIntensityBeam2();
00752       
00753       is_stable_beam = gtfeEvmExtWord.beamMode() == 11 ? true : false; 
00754       
00755       for (unsigned int i=132;i<156;++i)
00756         if(occupancy_RBX[i] == 0 && gtfeEvmExtWord.beamMode() == 11) 
00757           if(intensity1_>100 && intensity2_>100)                     // only in stable beam mode (11) and with circulating beams, otherwise 
00758           {                                                          // this check is too sensitive in HF
00759             is_RBX_loss_ = 1;
00760             rbxlost[i] = 1;
00761           }
00762       
00763       // no RBX loss, reset the counters
00764       if (is_RBX_loss_ == 0)
00765         for (unsigned int i=0;i<156;++i)
00766           occupancy_RBX[i] = 0;
00767     }
00768 
00769   // if RBX is lost any time during the LS, don't allow the counters to increment
00770   if(is_RBX_loss_ == 1)
00771     for (unsigned int i=0;i<156;++i)
00772       if(rbxlost[i]==1) occupancy_RBX[i] = 0;
00773 
00774 } // void HcalDeadCellMonitor::analyze(...)
00775 
00776 /* --------------------------------------- */
00777 
00778 
00779 void HcalDeadCellMonitor::processEvent(const HBHERecHitCollection& hbHits,
00780                                        const HORecHitCollection&   hoHits,
00781                                        const HFRecHitCollection&   hfHits,
00782                                        const HBHEDigiCollection&   hbhedigi,
00783                                        const HODigiCollection&     hodigi,
00784                                        const HFDigiCollection&     hfdigi)
00785 {
00786   if (debug_>1) std::cout <<"<HcalDeadCellMonitor::processEvent> Processing event..."<<std::endl;
00787 
00788   // Do Digi-Based dead cell searches 
00789   
00790   // Make sure histograms update
00791   for (unsigned int i=0;i<DigiPresentByDepth.depth.size();++i)
00792     DigiPresentByDepth.depth[i]->update();
00793 
00794   NumberOfNeverPresentDigis->update();;
00795   NumberOfNeverPresentDigisHB->update();
00796   NumberOfNeverPresentDigisHE->update();
00797   NumberOfNeverPresentDigisHO->update();
00798   NumberOfNeverPresentDigisHF->update();
00799 
00800   if (deadmon_test_digis_)
00801     {
00802       
00803       for (unsigned int i=0;i<RecentMissingDigisByDepth.depth.size();++i)
00804         RecentMissingDigisByDepth.depth[i]->update();
00805 
00806       NumberOfRecentMissingDigis->update();
00807       NumberOfRecentMissingDigisHB->update();
00808       NumberOfRecentMissingDigisHE->update();
00809       NumberOfRecentMissingDigisHO->update();
00810       NumberOfRecentMissingDigisHF->update();
00811     }
00812   
00813   for (HBHEDigiCollection::const_iterator j=hbhedigi.begin();
00814        j!=hbhedigi.end(); ++j)
00815     {
00816       const HBHEDataFrame digi = (const HBHEDataFrame)(*j);
00817       processEvent_HBHEdigi(digi);
00818     }
00819     
00820   for (HODigiCollection::const_iterator j=hodigi.begin();
00821        j!=hodigi.end(); ++j)
00822     {
00823       const HODataFrame digi = (const HODataFrame)(*j);
00824       process_Digi(digi);
00825     }
00826   for (HFDigiCollection::const_iterator j=hfdigi.begin();
00827        j!=hfdigi.end(); ++j)
00828     {
00829       const HFDataFrame digi = (const HFDataFrame)(*j);  
00830       process_Digi(digi);
00831     }
00832   FillUnphysicalHEHFBins(DigiPresentByDepth);
00833   
00834   // Search for "dead" cells below a certain energy
00835   if (deadmon_test_rechits_) 
00836     {
00837       // Normalization Fill
00838       for (unsigned int i=0;i<RecentMissingRecHitsByDepth.depth.size();++i)
00839         RecentMissingRecHitsByDepth.depth[i]->update();
00840 
00841       NumberOfRecentMissingRecHits->update();
00842       NumberOfRecentMissingRecHitsHB->update();
00843       NumberOfRecentMissingRecHitsHE->update();
00844       NumberOfRecentMissingRecHitsHO->update();
00845       NumberOfRecentMissingRecHitsHF->update();
00846 
00847       for (HBHERecHitCollection::const_iterator j=hbHits.begin();
00848            j!=hbHits.end(); ++j)
00849         process_RecHit(j);
00850       
00851       for (HORecHitCollection::const_iterator k=hoHits.begin();
00852            k!=hoHits.end(); ++k)
00853         process_RecHit(k);
00854       
00855       for (HFRecHitCollection::const_iterator j=hfHits.begin();
00856            j!=hfHits.end(); ++j)
00857         process_RecHit(j);
00858         
00859     } // if (deadmon_test_rechits)
00860 
00861   if (!makeDiagnostics_) return;
00862   if (tevt_>=NLumiBlocks_) return;
00863   // Diagnostic plots -- add number of missing channels vs event number
00864   int hbpresent=0;
00865   int hepresent=0;
00866   int hopresent=0;
00867   int hfpresent=0;
00868   int ieta=0;
00869   for (int d=0;d<4;++d)
00870     {
00871       for (int phi=0;phi<72;++phi)
00872         {
00873           for (int eta=0;eta<85;++eta)
00874             {
00875               if (!present_digi[eta][phi][d]) continue;
00876               if (d==3) ++hopresent;
00877               else if (d==2) ++hepresent;
00878               else if (d==1)
00879                 {
00880                   ieta=binmapd2[eta];
00881                   //if (abs(ieta)>29) continue;
00882                   if (abs(ieta)>29) ++hfpresent;
00883                   else if (abs(ieta)<17) ++hbpresent; //depths 15&16
00884                   else ++hepresent;
00885                 }
00886               else if (d==0)
00887                 {
00888                   ieta=eta-42;
00889                   if (abs(ieta)>29) ++hfpresent;
00890                   else if (abs(ieta)<17) ++hbpresent;
00891                   else ++hepresent;
00892                 }
00893             }
00894         }
00895     } // for (int d=0;d<4;++d)
00896   HBDeadVsEvent->Fill(tevt_,2592-hbpresent);
00897   HEDeadVsEvent->Fill(tevt_,2592-hepresent);
00898   HODeadVsEvent->Fill(tevt_,2160-hopresent);
00899   HFDeadVsEvent->Fill(tevt_,1728-hfpresent);
00900   return;
00901 } // void HcalDeadCellMonitor::processEvent(...)
00902 
00903 /************************************/
00904 
00905 
00906 // Digi-based dead cell checks
00907 
00908 void HcalDeadCellMonitor::processEvent_HBHEdigi(const HBHEDataFrame digi)
00909 {
00910   // Simply check whether a digi is present.  If so, increment occupancy counter.
00911   process_Digi(digi);
00912   return;
00913 } //void HcalDeadCellMonitor::processEvent_HBHEdigi(HBHEDigiCollection::const_iterator j)
00914 
00915 template<class DIGI> 
00916 void HcalDeadCellMonitor::process_Digi(DIGI& digi)
00917 {
00918   // Remove the validate check when we figure out how to access bad digis in digi monitor
00919   //if (!digi.validate()) return; // digi must be good to be counted
00920   int ieta=digi.id().ieta();
00921   int iphi=digi.id().iphi();
00922   int depth=digi.id().depth();
00923 
00924   // Fill occupancy counter
00925   ++recentoccupancy_digi[CalcEtaBin(digi.id().subdet(),ieta,depth)][iphi-1][depth-1];
00926 
00927   // If previously-missing digi found, change boolean status and fill histogram
00928   if (present_digi[CalcEtaBin(digi.id().subdet(),ieta,depth)][iphi-1][depth-1]==false)
00929     {
00930       if (DigiPresentByDepth.depth[depth-1])
00931         {
00932           DigiPresentByDepth.depth[depth-1]->setBinContent(CalcEtaBin(digi.id().subdet(),ieta,depth)+1,iphi,1);
00933         }
00934       present_digi[CalcEtaBin(digi.id().subdet(),ieta,depth)][iphi-1][depth-1]=true;
00935     }
00936   return;
00937 }
00938 
00939 //RecHit-based dead cell checks
00940 
00941 template<class RECHIT>
00942 void HcalDeadCellMonitor::process_RecHit(RECHIT& rechit)
00943 {
00944   float en = rechit->energy();
00945   HcalDetId id(rechit->detid().rawId());
00946   int ieta = id.ieta();
00947   int iphi = id.iphi();
00948   int depth = id.depth();
00949   
00950   if (id.subdet()==HcalBarrel)
00951     {
00952       if (en>=HBenergyThreshold_)
00953         {
00954           ++recentoccupancy_rechit[CalcEtaBin(id.subdet(),ieta,depth)][iphi-1][depth-1];
00955           present_rechit[CalcEtaBin(id.subdet(),ieta,depth)][iphi-1][depth-1]=true;
00956           if (RecHitPresentByDepth.depth[depth-1])
00957             RecHitPresentByDepth.depth[depth-1]->setBinContent(CalcEtaBin(id.subdet(),ieta,depth)+1,iphi,1);
00958         }      
00960       // RBX index, HB RBX indices are 0-35
00961       int RBXindex = logicalMap_->getHcalFrontEndId(rechit->detid()).rbxIndex();
00962 
00963       occupancy_RBX[RBXindex]++;
00965     }
00966   else if (id.subdet()==HcalEndcap)
00967     {
00968       if (en>=HEenergyThreshold_)
00969         {
00970         ++recentoccupancy_rechit[CalcEtaBin(id.subdet(),ieta,depth)][iphi-1][depth-1];
00971         present_rechit[CalcEtaBin(id.subdet(),ieta,depth)][iphi-1][depth-1]=true;
00972         if (RecHitPresentByDepth.depth[depth-1])
00973           RecHitPresentByDepth.depth[depth-1]->setBinContent(CalcEtaBin(id.subdet(),ieta,depth)+1,iphi,1);
00974         }
00976       // RBX index, HE RBX indices are 36-71
00977       int RBXindex = logicalMap_->getHcalFrontEndId(rechit->detid()).rbxIndex();
00978       
00979       occupancy_RBX[RBXindex]++;
00981     }
00982   else if (id.subdet()==HcalForward)
00983     {
00984       if (en>=HFenergyThreshold_)
00985         {
00986           ++recentoccupancy_rechit[CalcEtaBin(id.subdet(),ieta,depth)][iphi-1][depth-1];
00987         
00988           present_rechit[CalcEtaBin(id.subdet(),ieta,depth)][iphi-1][depth-1]=true;
00989           if (RecHitPresentByDepth.depth[depth-1])
00990             RecHitPresentByDepth.depth[depth-1]->setBinContent(CalcEtaBin(id.subdet(),ieta,depth)+1,iphi,1);
00991         }
00993       // RBX index, HF RBX indices are 132-155
00994       int RBXindex = logicalMap_->getHcalFrontEndId(rechit->detid()).rbxIndex();
00995       
00996       occupancy_RBX[RBXindex]++;
00998     }
00999   else if (id.subdet()==HcalOuter)
01000     {
01001       if (en>=HOenergyThreshold_)
01002         {
01003           ++recentoccupancy_rechit[CalcEtaBin(id.subdet(),ieta,depth)][iphi-1][depth-1];
01004           present_rechit[CalcEtaBin(id.subdet(),ieta,depth)][iphi-1][depth-1]=true;
01005           if (RecHitPresentByDepth.depth[depth-1])
01006             RecHitPresentByDepth.depth[depth-1]->setBinContent(CalcEtaBin(id.subdet(),ieta,depth)+1,iphi,1); 
01007         }
01009       // RBX index, HO RBX indices are 73-95 (odd), 96-107 (all), 108-119 (odd), 120-130 (EXCL), 131
01010       int RBXindex = logicalMap_->getHcalFrontEndId(rechit->detid()).rbxIndex();
01011         
01012       occupancy_RBX[RBXindex]++;
01014     }
01015 }
01016 
01017 void HcalDeadCellMonitor::fillNevents_recentdigis()
01018 {
01019   // Fill Histograms showing digi cells with no occupancy for the past few lumiblocks
01020   if (!deadmon_test_digis_) return; // extra protection here against calling histograms than don't exist
01021 
01022   if (debug_>0)
01023     std::cout <<"<HcalDeadCellMonitor::fillNevents_recentdigis> CHECKING FOR RECENT MISSING DIGIS   evtcount = "<<deadevt_<<std::endl;
01024 
01025   int ieta=0;
01026   int iphi=0;
01027 
01028   int etabins=0;
01029   int phibins=0;
01030 
01032   if ((deadevt_ >= 10 && deadevt_<minDeadEventCount_) || (deadevt_ >= 10 && is_RBX_loss_==1)) // maybe not enough events to run the standard test
01033     // if( is_RBX_loss_ == 1 )                          // but enough to detect RBX loss
01034       for (unsigned int depth=0;depth<RecentMissingDigisByDepth.depth.size();++depth)
01035         {
01036           RecentMissingDigisByDepth.depth[depth]->setBinContent(0,0,ievt_);
01037           etabins=RecentMissingDigisByDepth.depth[depth]->getNbinsX();
01038           phibins=RecentMissingDigisByDepth.depth[depth]->getNbinsY();      
01039           for (int eta=0;eta<etabins;++eta)
01040             for (int phi=0;phi<phibins;++phi)
01041               {
01042                 iphi=phi+1;
01043                 for (int subdet=1;subdet<=4;++subdet)
01044                   {
01045                     ieta=CalcIeta((HcalSubdetector)subdet,eta,depth+1);
01046                     if (ieta==-9999) continue;
01047                     if (!validDetId((HcalSubdetector)subdet, ieta, iphi, depth+1))
01048                       continue;
01049                     // now check which dead cell tests failed; increment counter if any failed
01050                     HcalDetId TempID((HcalSubdetector)subdet, ieta, iphi, (int)depth+1);
01051                     
01052                     int index = logicalMap_->getHcalFrontEndId(TempID).rbxIndex();
01053                     // if(subdet==HcalForward) continue;
01054                     
01055                     if(occupancy_RBX[index]==0)
01056                       {
01057                         recentoccupancy_digi[eta][phi][depth] = 0;
01058                         RecentMissingDigisByDepth.depth[depth]->Fill(ieta,iphi,deadevt_);
01059                       }
01060                   }
01061               }
01062         }
01064 
01065   if (deadevt_ < minDeadEventCount_) return; // not enough entries to make a determination for this LS
01066 
01067   for (unsigned int depth=0;depth<RecentMissingDigisByDepth.depth.size();++depth)
01068     { 
01069       RecentMissingDigisByDepth.depth[depth]->setBinContent(0,0,ievt_);
01070       etabins=RecentMissingDigisByDepth.depth[depth]->getNbinsX();
01071       phibins=RecentMissingDigisByDepth.depth[depth]->getNbinsY();
01072       for (int eta=0;eta<etabins;++eta)
01073         {
01074           for (int subdet=1;subdet<=4;++subdet)
01075             {
01076               ieta=CalcIeta((HcalSubdetector)subdet,eta,depth+1);
01077               if (ieta==-9999) continue;
01078               for (int phi=0;phi<phibins;++phi)
01079                 {
01080                   iphi=phi+1;
01081                   
01082                   if (!validDetId((HcalSubdetector)subdet, ieta, iphi, depth+1))
01083                     continue;
01084                   
01085                   // Ignore subdetectors that weren't in run?
01086                   /*
01087                   if ((subdet==HcalBarrel && !HBpresent_) || 
01088                       (subdet==HcalEndcap &&!HEpresent_)  ||
01089                       (subdet==HcalOuter &&!HOpresent_)  || 
01090                       (subdet==HcalForward &&!HFpresent_))   continue;
01091                   */
01092                   int zside=0;
01093                   if (subdet==HcalForward) // shift HcalForward ieta
01094                     ieta<0 ? zside=-1 : zside=+1;
01095                   
01096                   if (recentoccupancy_digi[eta][phi][depth]==0)
01097                     {
01098                       if (debug_>0)
01099                         {
01100                           std::cout <<"DEAD CELL; NO RECENT OCCUPANCY: subdet = "<<subdet<<", ieta = "<<ieta<<", iphi = "<<iphi<<" depth = "<<depth+1<<std::endl;
01101                           std::cout <<"\t RAW COORDINATES:  eta = "<<eta<< " phi = "<<phi<<" depth = "<<depth<<std::endl;
01102                           std::cout <<"\t Present? "<<present_digi[eta][phi][depth]<<std::endl;
01103                         }
01104                       
01105                       // Don't fill HORing2 if boolean enabled
01106                       if (excludeHORing2_==true && abs(ieta)>10 && isSiPM(ieta,iphi,depth+1)==false)
01107                         continue;
01108 
01109                       // no digi was found for the N events; Fill cell as bad for all N events (N = checkN);
01110                       if (RecentMissingDigisByDepth.depth[depth]) RecentMissingDigisByDepth.depth[depth]->Fill(ieta+zside,iphi,deadevt_);
01111                     }
01112                 } // for (int subdet=1;subdet<=4;++subdet)
01113             } // for (int phi=0;...)
01114         } // for (int eta=0;...)
01115     } //for (int depth=1;...)
01116   FillUnphysicalHEHFBins(RecentMissingDigisByDepth);
01117 
01118   return;
01119 
01120 } // void HcalDeadCellMonitor::fillNevents_recentdigis()
01121 
01122 
01123 
01124 /* ----------------------------------- */
01125 
01126 void HcalDeadCellMonitor::fillNevents_recentrechits()
01127 {
01128   // Fill Histograms showing unoccupied rechits, or rec hits with low energy
01129 
01130   // This test is a bit pointless, unless the energy threshold is greater than the ZS threshold.
01131   // If we require that cells are always < thresh to be flagged by this test, and if 
01132   // thresh < ZS, then we will never catch any cells, since they'll show up as dead in the
01133   // neverpresent/occupancy test plots first.
01134   // Only exception is if something strange is going on between ZS ADC value an RecHit energy?
01135 
01136   if (!deadmon_test_rechits_) return;
01137   FillUnphysicalHEHFBins(RecHitPresentByDepth);  
01138 
01139   if (debug_>0)
01140     std::cout <<"<HcalDeadCellMonitor::fillNevents_energy> BELOW-ENERGY-THRESHOLD PLOTS"<<std::endl;
01141 
01142   int ieta=0;
01143   int iphi=0;
01144   
01145   int etabins=0;
01146   int phibins=0;
01147 
01149   if ((deadevt_ >= 10 && deadevt_<minDeadEventCount_) || (deadevt_ >= 10 && is_RBX_loss_==1)) // maybe not enough events to run the standard test
01150     // if( is_RBX_loss_ == 1 )                          // but enough to detect RBX loss
01151       for (unsigned int depth=0;depth<RecentMissingRecHitsByDepth.depth.size();++depth)
01152         {
01153           RecentMissingRecHitsByDepth.depth[depth]->setBinContent(0,0,ievt_);
01154           etabins=RecentMissingRecHitsByDepth.depth[depth]->getNbinsX();
01155           phibins=RecentMissingRecHitsByDepth.depth[depth]->getNbinsY();      
01156           for (int eta=0;eta<etabins;++eta)
01157             for (int phi=0;phi<phibins;++phi)
01158               {
01159                 iphi=phi+1;
01160                 for (int subdet=1;subdet<=4;++subdet)
01161                   {
01162                     ieta=CalcIeta((HcalSubdetector)subdet,eta,depth+1);
01163                     if (ieta==-9999) continue;
01164                     if (!validDetId((HcalSubdetector)subdet, ieta, iphi, depth+1))
01165                       continue;
01166                     // now check which dead cell tests failed; increment counter if any failed
01167                     HcalDetId TempID((HcalSubdetector)subdet, ieta, iphi, (int)depth+1);
01168                     
01169                     int index = logicalMap_->getHcalFrontEndId(TempID).rbxIndex();
01170                     // if(subdet==HcalForward) continue;
01171                     
01172                     if(occupancy_RBX[index]==0)
01173                       {
01174                         recentoccupancy_rechit[eta][phi][depth] = 0;
01175                         RecentMissingRecHitsByDepth.depth[depth]->Fill(ieta,iphi,deadevt_);
01176                       }
01177                   }
01178               }
01179         }
01181 
01182   if (deadevt_ < minDeadEventCount_) return; // not enough entries to make a determination for this LS
01183 
01184   for (unsigned int depth=0;depth<RecentMissingRecHitsByDepth.depth.size();++depth)
01185     { 
01186       RecentMissingRecHitsByDepth.depth[depth]->setBinContent(0,0,ievt_);
01187       etabins=RecentMissingRecHitsByDepth.depth[depth]->getNbinsX();
01188       phibins=RecentMissingRecHitsByDepth.depth[depth]->getNbinsY();
01189       for (int eta=0;eta<etabins;++eta)
01190         {
01191           for (int subdet=1;subdet<=4;++subdet)
01192             {
01193               ieta=CalcIeta((HcalSubdetector)subdet,eta,depth+1);
01194               if (ieta==-9999) continue;
01195               for (int phi=0;phi<phibins;++phi)
01196                 {
01197                   iphi=phi+1;
01198                   if (!validDetId((HcalSubdetector)subdet, ieta, iphi, depth+1))
01199                     continue;
01200                   
01201                   if (recentoccupancy_rechit[eta][phi][depth]>0) continue; // cell exceeded energy at least once, so it's not dead
01202                                   
01203                   // Ignore subdetectors that weren't in run?
01204                   /*
01205                   if ((subdet==HcalBarrel && !HBpresent_) || 
01206                       (subdet==HcalEndcap &&!HEpresent_)  ||
01207                       (subdet==HcalOuter &&!HOpresent_)  ||
01208                       (subdet==HcalForward &&!HFpresent_))   continue;
01209                   */
01210 
01211                   int zside=0;
01212                   if (subdet==HcalForward) // shift HcalForward ieta
01213                     {
01214                       ieta<0 ? zside=-1 : zside=+1;
01215                     }
01216                   
01217                   if (debug_>2) 
01218                     std::cout <<"DEAD CELL; BELOW ENERGY THRESHOLD; subdet = "<<subdet<<" ieta = "<<ieta<<", phi = "<<iphi<<" depth = "<<depth+1<<std::endl;
01219                   if (excludeHORing2_==true && abs(ieta)>10 && isSiPM(ieta,iphi,depth+1)==false)
01220                     continue;
01221           
01222                   if (RecentMissingRecHitsByDepth.depth[depth]) RecentMissingRecHitsByDepth.depth[depth]->Fill(ieta+zside,iphi,deadevt_);
01223                 } // loop on phi bins
01224             } // for (unsigned int depth=1;depth<=4;++depth)
01225         } // // loop on subdetectors
01226     } // for (int eta=0;...)
01227   
01228   FillUnphysicalHEHFBins(RecentMissingRecHitsByDepth);
01229 
01230   return;
01231 } // void HcalDeadCellMonitor::fillNevents_recentrechits()
01232 
01233 
01234 void HcalDeadCellMonitor::fillNevents_problemCells()
01235 {
01236   //fillNevents_problemCells now only performs checks of never-present cells
01237 
01238   if (debug_>0)
01239     std::cout <<"<HcalDeadCellMonitor::fillNevents_problemCells> FILLING PROBLEM CELL PLOTS"<<std::endl;
01240 
01241   int ieta=0;
01242   int iphi=0;
01243 
01244   // Count problem cells in each subdetector
01245 
01246   NumBadHB=0;
01247   NumBadHE=0;
01248   NumBadHO=0;
01249   NumBadHF=0;
01250   NumBadHFLUMI=0;
01251   NumBadHO01=0;
01252   NumBadHO2=0;
01253   NumBadHO12=0;
01254   NumBadHO1P02=0;
01255   
01256   int knownBadHB=0;
01257   int knownBadHE=0;
01258   int knownBadHF=0;
01259   int knownBadHO=0;
01260   int knownBadHFLUMI=0;
01261   int knownBadHO01=0;
01262   int knownBadHO2=0;
01263   int knownBadHO12=0;
01264 
01265 
01266   unsigned int neverpresentHB=0;
01267   unsigned int neverpresentHE=0;
01268   unsigned int neverpresentHO=0;
01269   unsigned int neverpresentHF=0;
01270   
01271   unsigned int unoccupiedHB=0;
01272   unsigned int unoccupiedHE=0;
01273   unsigned int unoccupiedHO=0;
01274   unsigned int unoccupiedHF=0;
01275     
01276   unsigned int belowenergyHB=0;
01277   unsigned int belowenergyHE=0;
01278   unsigned int belowenergyHO=0;
01279   unsigned int belowenergyHF=0;
01280   
01281   unsigned int energyneverpresentHB=0;
01282   unsigned int energyneverpresentHE=0;
01283   unsigned int energyneverpresentHO=0;
01284   unsigned int energyneverpresentHF=0;
01285 
01286   if (deadevt_>=minDeadEventCount_)
01287     Nevents->Fill(1,deadevt_);
01288 
01289   int etabins=0;
01290   int phibins=0;
01291 
01292   // Store values for number of bad channels in each lumi section, for plots of ProblemsVsLS.
01293   // This is different than the NumBadHB, etc. values, which must included even known bad channels 
01294   // in order to calculate reportSummaryByLS values correctly.
01295 
01297   //Check for RBX data loss
01298   unsigned int RBX_loss_HB=0;
01299   unsigned int RBX_loss_HE=0;
01300   unsigned int RBX_loss_HO01=0;
01301   unsigned int RBX_loss_HO2=0;
01302   unsigned int RBX_loss_HF=0;
01303 
01304   unsigned int counter_HB = 0;
01305   unsigned int counter_HE = 0;
01306   unsigned int counter_HO01 = 0;
01307   unsigned int counter_HO2 = 0;
01308   unsigned int counter_HF = 0;
01309 
01310   for(int i=0; i<156; i++)
01311     {
01312       if(occupancy_RBX[i]==0 && is_RBX_loss_ == 1)
01313         {
01314           if(i<=35)            //HB
01315             { counter_HB ++ ; RBX_loss_HB = 72*(counter_HB); }
01316           if(i>=36 && i<=71)   //HE
01317             { counter_HE ++ ; RBX_loss_HE = 72*(counter_HE); }
01318           if(i>=85 && i<=119) // HO Rings 0, 1
01319             { counter_HO01 ++ ; RBX_loss_HO01 = 72*(counter_HO01); }
01320           if(i>=121 || i<=83) // HO Ring 2
01321             { counter_HO2 ++ ; RBX_loss_HO2 = 72*(counter_HO2); }
01322           if(i>=132 && i<=155)  //HF
01323             { counter_HF ++ ; RBX_loss_HF = 72*(counter_HF); }
01324           
01325           if(excludeHO1P02_==true && i==109) NumBadHO1P02 = 72; // exclude HO1P02
01326         }      
01327       if(occupancy_RBX[i]>0)
01328         RBX_loss_VS_LB->Fill(currentLS, i, 0);
01329       if(occupancy_RBX[i]==0 && is_RBX_loss_ == 1)
01330         RBX_loss_VS_LB->Fill(currentLS, i, 1);      
01331     }  
01332   
01333   if (deadevt_ >= 10 && deadevt_<minDeadEventCount_) // maybe not enough events to run the standard test
01334     if( is_RBX_loss_ == 1 )                          // but enough to detect RBX loss
01335       { 
01336         NumBadHB+=RBX_loss_HB;
01337         NumBadHE+=RBX_loss_HE;
01338         NumBadHO+=RBX_loss_HO01+RBX_loss_HO2;
01339         NumBadHO01+=RBX_loss_HO01;
01340         NumBadHO2+=RBX_loss_HO2;
01341         NumBadHF+=RBX_loss_HF;
01342 
01343         belowenergyHB+=RBX_loss_HB;
01344         belowenergyHE+=RBX_loss_HE;
01345         belowenergyHO+=RBX_loss_HO01+RBX_loss_HO2;
01346         belowenergyHF+=RBX_loss_HF;
01347 
01348         unoccupiedHB+=RBX_loss_HB;
01349         unoccupiedHE+=RBX_loss_HE;
01350         unoccupiedHO+=RBX_loss_HO01+RBX_loss_HO2;
01351         unoccupiedHF+=RBX_loss_HF;
01352       }
01354 
01355   for (unsigned int depth=0;depth<DigiPresentByDepth.depth.size();++depth)
01356     {
01357       DigiPresentByDepth.depth[depth]->setBinContent(0,0,ievt_); 
01358       etabins=DigiPresentByDepth.depth[depth]->getNbinsX();
01359       phibins=DigiPresentByDepth.depth[depth]->getNbinsY();
01360       for (int eta=0;eta<etabins;++eta)
01361         {
01362           for (int phi=0;phi<phibins;++phi)
01363             {
01364               iphi=phi+1;
01365               for (int subdet=1;subdet<=4;++subdet)
01366                 {
01367                   ieta=CalcIeta((HcalSubdetector)subdet,eta,depth+1);
01368                   if (ieta==-9999) continue;
01369                   if (!validDetId((HcalSubdetector)subdet, ieta, iphi, depth+1))
01370                     continue;
01371                   // Ignore subdetectors that weren't in run?
01372                   /*
01373                   if ((subdet==HcalBarrel && !HBpresent_) || 
01374                       (subdet==HcalEndcap &&!HEpresent_)  ||
01375                       (subdet==HcalOuter &&!HOpresent_)  ||
01376                       (subdet==HcalForward &&!HFpresent_))   continue;
01377                   */
01378                   
01379                   /*
01380                   if ((!checkHB_ && subdet==HcalBarrel) ||
01381                       (!checkHE_ && subdet==HcalEndcap) ||
01382                       (!checkHO_ && subdet==HcalOuter) ||
01383                       (!checkHF_ && subdet==HcalForward))  continue;
01384                   */
01385 
01386                   // now check which dead cell tests failed; increment counter if any failed
01387                   if ((present_digi[eta][phi][depth]==0) ||
01388                       (deadmon_test_digis_ && recentoccupancy_digi[eta][phi][depth]==0 && (deadevt_>=minDeadEventCount_)) ||
01389                       (deadmon_test_rechits_ && recentoccupancy_rechit[eta][phi][depth]==0  && (deadevt_>=minDeadEventCount_))
01390                       )
01391                     {
01392                       HcalDetId TempID((HcalSubdetector)subdet, ieta, iphi, (int)depth+1);
01393                       if (subdet==HcalBarrel)      
01394                         { 
01395                           ++NumBadHB;
01396                           if (KnownBadCells_.find(TempID.rawId())!=KnownBadCells_.end())
01397                             ++knownBadHB;
01398                         }
01399                       else if (subdet==HcalEndcap) 
01400                         {
01401                           ++NumBadHE;
01402                           if (KnownBadCells_.find(TempID.rawId())!=KnownBadCells_.end())
01403                             ++knownBadHE;
01404                         }
01405 
01406                       else if (subdet==HcalOuter)  
01407                         {
01408                           ++NumBadHO;
01409                           if (abs(ieta)<=10) ++NumBadHO01;
01410                           else ++NumBadHO2;
01411                           // Don't include HORing2 if boolean set; subtract away those counters
01412                           if (excludeHORing2_==true && abs(ieta)>10 && isSiPM(ieta,iphi,depth+1)==false)
01413                             {
01414                               --NumBadHO;
01415                               --NumBadHO2;
01416                               --NumBadHO12;
01417                             }                     
01418                           // Don't include HO1P02 if boolean set, RBX does not repsond well to resets,; subtract away those counters
01419                           if (excludeHO1P02_==true && ( (ieta>4 && ieta<10) && (iphi<=10 || iphi>70) ) )
01420                             ++NumBadHO1P02;
01421 
01422                           if (KnownBadCells_.find(TempID.rawId())!=KnownBadCells_.end())
01423                             {
01424                               ++knownBadHO;
01425                               if (abs(ieta)<=10) ++knownBadHO01;
01426                               else ++knownBadHO2;
01427                               // Don't include HORing2 if boolean set; subtract away those counters
01428                               if (excludeHORing2_==true && abs(ieta)>10 && isSiPM(ieta,iphi,depth+1)==false)
01429                                 {
01430                                   --knownBadHO;
01431                                   --knownBadHO12;
01432                                 }
01433                             }
01434                         }
01435                       else if (subdet==HcalForward)
01436                         {
01437                           ++NumBadHF;
01438                           if (depth==1 && (abs(ieta)==33 || abs(ieta)==34))
01439                             ++NumBadHFLUMI;
01440                           else if (depth==2 && (abs(ieta)==35 || abs(ieta)==36))
01441                             ++NumBadHFLUMI;
01442                           if (KnownBadCells_.find(TempID.rawId())!=KnownBadCells_.end())
01443                             {
01444                               ++knownBadHF;
01445                               if (depth==1 && (abs(ieta)==33 || abs(ieta)==34))
01446                                 ++knownBadHFLUMI;
01447                               else if (depth==2 && (abs(ieta)==35 || abs(ieta)==36))
01448                                 ++knownBadHFLUMI;
01449                             }
01450                         }
01451                     }
01452                   if (present_digi[eta][phi][depth]==0 )
01453                     {
01454                       if (subdet==HcalBarrel) ++neverpresentHB;
01455                       else if (subdet==HcalEndcap) ++neverpresentHE;
01456                       else if (subdet==HcalOuter) 
01457                         {
01458                           ++neverpresentHO;
01459                           if (excludeHORing2_==true && abs(ieta)>10 && isSiPM(ieta,iphi,depth+1)==false)
01460                             --neverpresentHO;
01461                         }
01462                       else if (subdet==HcalForward) ++neverpresentHF;
01463                     }
01464                   // Count recent unoccupied digis if the total events in this lumi section is > minEvents_
01465                   if (deadmon_test_digis_ && recentoccupancy_digi[eta][phi][depth]==0 && deadevt_>=minDeadEventCount_)
01466                     {
01467                       HcalDetId TempID((HcalSubdetector)subdet, ieta, iphi, (int)depth+1);
01468                       if (subdet==HcalBarrel) ++unoccupiedHB;
01469                       else if (subdet==HcalEndcap) ++unoccupiedHE;
01470                       else if (subdet==HcalOuter) 
01471                         {
01472                           ++unoccupiedHO;
01473                           if (excludeHORing2_==true && abs(ieta)>10 && isSiPM(ieta,iphi,depth+1)==false)
01474                             --unoccupiedHO;
01475                           if (KnownBadCells_.find(TempID.rawId())!=KnownBadCells_.end() && abs(ieta)<=10)
01476                             --unoccupiedHO;
01477                         }
01478                       else if (subdet==HcalForward) ++unoccupiedHF;
01479                     }
01480                   // Look at rechit checks
01481                   if (deadmon_test_rechits_)
01482                     {
01483                       if (present_rechit[eta][phi][depth]==0)
01484                         {
01485                           if (subdet==HcalBarrel) ++energyneverpresentHB;
01486                           else if (subdet==HcalEndcap) ++energyneverpresentHE;
01487                           else if (subdet==HcalOuter) 
01488                             {
01489                               ++energyneverpresentHO;
01490                               if (excludeHORing2_==true && abs(ieta)>10 && isSiPM(ieta,iphi,depth+1)==false)
01491                                 --energyneverpresentHO; 
01492                             }
01493                           else if (subdet==HcalForward) ++energyneverpresentHF;
01494                         }
01495                       if (recentoccupancy_rechit[eta][phi][depth]==0 && deadevt_>=minDeadEventCount_)
01496                         {
01497                           HcalDetId TempID((HcalSubdetector)subdet, ieta, iphi, (int)depth+1);
01498                           if (subdet==HcalBarrel) ++belowenergyHB;
01499                           else if (subdet==HcalEndcap) ++belowenergyHE;
01500                           else if (subdet==HcalOuter) 
01501                             {
01502                               ++belowenergyHO;
01503                               if (excludeHORing2_==true && abs(ieta)>10 && isSiPM(ieta,iphi,depth+1)==false)
01504                                 --belowenergyHO;
01505                               if (KnownBadCells_.find(TempID.rawId())!=KnownBadCells_.end() && abs(ieta)<=10)
01506                                 --belowenergyHO;
01507                             }
01508                           else if (subdet==HcalForward) ++belowenergyHF;
01509                         }
01510                     }
01511                 } // subdet loop
01512             } // phi loop
01513         } //eta loop
01514     } // depth loop
01515 
01516   // Fill with number of problem cells found on this pass
01517   NumberOfNeverPresentDigisHB->Fill(currentLS,neverpresentHB);
01518   NumberOfNeverPresentDigisHE->Fill(currentLS,neverpresentHE);
01519   NumberOfNeverPresentDigisHO->Fill(currentLS,neverpresentHO);
01520   NumberOfNeverPresentDigisHF->Fill(currentLS,neverpresentHF);
01521   NumberOfNeverPresentDigis->Fill(currentLS,neverpresentHB+neverpresentHE+neverpresentHO+neverpresentHF);
01522 
01523   if (deadevt_>=minDeadEventCount_ && is_RBX_loss_ == 1 )
01524     {
01525       if( NumBadHB<RBX_loss_HB )
01526         NumBadHB+=RBX_loss_HB;
01527       if( NumBadHE<RBX_loss_HE )
01528         NumBadHE+=RBX_loss_HE;
01529       if( NumBadHO01<RBX_loss_HO01 )
01530         NumBadHO01+=RBX_loss_HO01;
01531       if( NumBadHO2<RBX_loss_HO2 )
01532         NumBadHO2+=RBX_loss_HO2;
01533       if( NumBadHF<RBX_loss_HF )
01534         NumBadHF+=RBX_loss_HF;
01535 
01536       if( belowenergyHB<RBX_loss_HB )
01537         belowenergyHB+=RBX_loss_HB;
01538       if( belowenergyHE<RBX_loss_HE )
01539         belowenergyHE+=RBX_loss_HE;
01540       if( belowenergyHO<RBX_loss_HO01+RBX_loss_HO2)
01541         belowenergyHO+=RBX_loss_HO01+RBX_loss_HO2;
01542       if( belowenergyHF<RBX_loss_HF )
01543         belowenergyHF+=RBX_loss_HF;
01544 
01545       if( unoccupiedHB<RBX_loss_HB )
01546         unoccupiedHB+=RBX_loss_HB;
01547       if( unoccupiedHE<RBX_loss_HE )
01548         unoccupiedHE+=RBX_loss_HE;
01549       if( unoccupiedHO<RBX_loss_HO01+RBX_loss_HO2 )
01550         unoccupiedHO+=RBX_loss_HO01+RBX_loss_HO2;
01551       if( unoccupiedHF<RBX_loss_HF )
01552         unoccupiedHF+=RBX_loss_HF;
01553 
01554       // is_RBX_loss_ = 0;
01555     }
01556 
01557   ProblemsVsLB_HB->Fill(currentLS,NumBadHB-knownBadHB+0.0001); // add a small offset, so that the histograms reset when no errors follow
01558   ProblemsVsLB_HE->Fill(currentLS,NumBadHE-knownBadHE+0.0001); // problematic LSs
01559   ProblemsVsLB_HO->Fill(currentLS,NumBadHO01-knownBadHO01+0.0001);
01560   ProblemsVsLB_HO2->Fill(currentLS,NumBadHO2-knownBadHO2+0.0001);
01561   ProblemsVsLB_HF->Fill(currentLS,NumBadHF-knownBadHF+0.0001);
01562   ProblemsVsLB_HBHEHF->Fill(currentLS,NumBadHB+NumBadHE+NumBadHF-knownBadHB-knownBadHE-knownBadHF+0.0001);
01563   ProblemsVsLB->Fill(currentLS,NumBadHB+NumBadHE+NumBadHO01+NumBadHO2+NumBadHF-knownBadHB-knownBadHE-knownBadHO01-knownBadHO2-knownBadHF+0.0001);
01564   
01565   if(excludeHO1P02_==true)
01566     ProblemsVsLB_HO->Fill(0, NumBadHO1P02);
01567 
01568   if( NumBadHB+NumBadHE+NumBadHF-knownBadHB-knownBadHE-knownBadHF < 30 )    
01569     alarmer_counter_ = 0;
01570   if( NumBadHO01-knownBadHO01 < 30 )    
01571     alarmer_counterHO01_ = 0;
01572     
01573   if( alarmer_counter_ >= 10 )
01574     ProblemsInLastNLB_HBHEHF_alarm->Fill( std::min(int(NumBadHB+NumBadHE+NumBadHF-knownBadHB-knownBadHE-knownBadHF), 99) );
01575   if( alarmer_counterHO01_ >= 10 )
01576     ProblemsInLastNLB_HO01_alarm->Fill( std::min(int(NumBadHO01-knownBadHO01), 99) );
01577 
01578   // if (deadevt_<minDeadEventCount_)
01579   //   return;
01580     
01581   if (deadmon_test_digis_)
01582     {
01583       NumberOfRecentMissingDigisHB->Fill(currentLS,unoccupiedHB);
01584       NumberOfRecentMissingDigisHE->Fill(currentLS,unoccupiedHE);
01585       NumberOfRecentMissingDigisHO->Fill(currentLS,unoccupiedHO);
01586       NumberOfRecentMissingDigisHF->Fill(currentLS,unoccupiedHF);
01587       NumberOfRecentMissingDigis->Fill(currentLS,unoccupiedHB+unoccupiedHE+unoccupiedHO+unoccupiedHF);
01588     }
01589 
01590   if (deadmon_test_rechits_)
01591     {
01592       NumberOfNeverPresentRecHitsHB->Fill(currentLS,energyneverpresentHB);
01593       NumberOfNeverPresentRecHitsHE->Fill(currentLS,energyneverpresentHE);
01594       NumberOfNeverPresentRecHitsHO->Fill(currentLS,energyneverpresentHO);
01595       NumberOfNeverPresentRecHitsHF->Fill(currentLS,energyneverpresentHF);
01596       NumberOfNeverPresentRecHits->Fill(currentLS,energyneverpresentHB+energyneverpresentHE+energyneverpresentHO+energyneverpresentHF);
01597       
01598       NumberOfRecentMissingRecHitsHB->Fill(currentLS,belowenergyHB);
01599       NumberOfRecentMissingRecHitsHE->Fill(currentLS,belowenergyHE);
01600       NumberOfRecentMissingRecHitsHO->Fill(currentLS,belowenergyHO);
01601       NumberOfRecentMissingRecHitsHF->Fill(currentLS,belowenergyHF);
01602       NumberOfRecentMissingRecHits->Fill(currentLS,belowenergyHB+belowenergyHE+belowenergyHO+belowenergyHF);
01603     }
01604 
01605   return;
01606 } // void HcalDeadCellMonitor::fillNevents_problemCells(void)
01607 
01608 
01609 void HcalDeadCellMonitor::zeroCounters(bool resetpresent)
01610 {
01611 
01612   // zero all counters
01613 
01614   // 2D histogram counters
01615   for (unsigned int i=0;i<85;++i)
01616     {
01617       for (unsigned int j=0;j<72;++j)
01618         {
01619           for (unsigned int k=0;k<4;++k)
01620             {
01621               if (resetpresent) present_digi[i][j][k]=false; // keeps track of whether digi was ever present
01622               if (resetpresent) present_rechit[i][j][k]=false;
01623               recentoccupancy_digi[i][j][k]=0; // counts occupancy in last (checkNevents) events
01624               recentoccupancy_rechit[i][j][k]=0; // counts instances of cell above threshold energy in last (checkNevents)
01625             }
01626         }
01627     }
01628 
01629   for (unsigned int i=0;i<156;++i)
01630     {
01631       occupancy_RBX[i] = 0;
01632       rbxlost[i] = 0;
01633     }
01634 
01635   return;
01636 } // void HcalDeadCellMonitor::zeroCounters(bool resetpresent)
01637 
01638 DEFINE_FWK_MODULE(HcalDeadCellMonitor);