CMS 3D CMS Logo

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