CMS 3D CMS Logo

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