CMS 3D CMS Logo

HcalDeadCellMonitor.cc

Go to the documentation of this file.
00001 #include "DQM/HcalMonitorTasks/interface/HcalDeadCellMonitor.h"
00002 
00003 #define OUT if(fverbosity_)cout
00004 #define BITSHIFT 5
00005 
00006 using namespace std;
00007 
00008 HcalDeadCellMonitor::HcalDeadCellMonitor()
00009 {
00010   ievt_=0;
00011   // Default initialization
00012   showTiming   = false;
00013   fVerbosity   = 0;
00014   deadmon_makeDiagnostics_ = false;
00015 } //constructor
00016 
00017 HcalDeadCellMonitor::~HcalDeadCellMonitor()
00018 {
00019 } //destructor
00020 
00021 
00022 /* ------------------------------------ */ 
00023 
00024 void HcalDeadCellMonitor::setup(const edm::ParameterSet& ps,
00025                                 DQMStore* dbe)
00026 {
00027   HcalBaseMonitor::setup(ps,dbe);
00028   if (showTiming)
00029     {
00030       cpu_timer.reset(); cpu_timer.start();
00031     }
00032   baseFolder_ = rootFolder_+"DeadCellMonitor_Hcal";
00033   if (fVerbosity>0)
00034     cout <<"<HcalDeadCellMonitor::setup>  Setting up histograms"<<endl;
00035 
00036   // Assume subdetectors not present until shown otherwise
00037   HBpresent_=false;
00038   HEpresent_=false;
00039   HOpresent_=false;
00040   HFpresent_=false;
00041 
00042   // Dead Cell Monitor - specific cfg variables
00043 
00044   if (fVerbosity>1)
00045     cout <<"<HcalDeadCellMonitor::setup>  Getting variable values from cfg files"<<endl;
00046   // determine whether database pedestals are in FC or ADC
00047   doFCpeds_ = ps.getUntrackedParameter<bool>("DeadCellMonitor_pedestalsInFC", true);
00048 
00049   // deadmon_makeDiagnostics_ will take on base task value unless otherwise specified
00050   deadmon_makeDiagnostics_ = ps.getUntrackedParameter<bool>("DeadCellMonitor_makeDiagnosticPlots",makeDiagnostics);
00051   
00052   // Set checkNevents values
00053   deadmon_checkNevents_ = ps.getUntrackedParameter<int>("DeadCellMonitor_checkNevents",checkNevents_);
00054   deadmon_checkNevents_occupancy_ = ps.getUntrackedParameter<int>("DeadCellMonitor_checkNevents_occupancy",deadmon_checkNevents_);
00055   deadmon_checkNevents_rechit_occupancy_ = ps.getUntrackedParameter<int>("DeadCellMonitor_checkNevents_rechit_occupancy",deadmon_checkNevents_);
00056   deadmon_checkNevents_pedestal_  = ps.getUntrackedParameter<int>("DeadCellMonitor_checkNevents_pedestal" ,deadmon_checkNevents_);
00057   deadmon_checkNevents_neighbor_  = ps.getUntrackedParameter<int>("DeadCellMonitor_checkNevents_neighbor" ,deadmon_checkNevents_);
00058   deadmon_checkNevents_energy_    = ps.getUntrackedParameter<int>("DeadCellMonitor_checkNevents_energy"   ,deadmon_checkNevents_);
00059  
00060   // Set which dead cell checks will be performed
00061   deadmon_test_occupancy_         = ps.getUntrackedParameter<bool>("DeadCellMonitor_test_occupancy", true);
00062   deadmon_test_rechit_occupancy_  = ps.getUntrackedParameter<bool>("DeadCellMonitor_test_rechit_occupancy", true);
00063 
00064   deadmon_test_pedestal_          = ps.getUntrackedParameter<bool>("DeadCellMonitor_test_pedestal",  true);
00065   deadmon_test_neighbor_          = ps.getUntrackedParameter<bool>("DeadCellMonitor_test_neighbor",  true);
00066   deadmon_test_energy_            = ps.getUntrackedParameter<bool>("DeadCellMonitor_test_energy",    true);
00067 
00068   deadmon_minErrorFlag_ = ps.getUntrackedParameter<double>("DeadCellMonitor_minErrorFlag",0.0);
00069 
00070   // pedestal test -- cell must be below pedestal+nsigma for a number of consecutive events to be considered dead
00071   nsigma_       = ps.getUntrackedParameter<double>("DeadCellMonitor_pedestal_Nsigma",         -10);
00072   HBnsigma_     = ps.getUntrackedParameter<double>("DeadCellMonitor_pedestal_HB_Nsigma",  nsigma_);
00073   HEnsigma_     = ps.getUntrackedParameter<double>("DeadCellMonitor_pedestal_HE_Nsigma",  nsigma_);
00074   HOnsigma_     = ps.getUntrackedParameter<double>("DeadCellMonitor_pedestal_HO_Nsigma",  nsigma_);
00075   HFnsigma_     = ps.getUntrackedParameter<double>("DeadCellMonitor_pedestal_HF_Nsigma",  nsigma_);
00076   ZDCnsigma_    = ps.getUntrackedParameter<double>("DeadCellMonitor_pedestal_ZDC_Nsigma", nsigma_);
00077 
00078   // rechit energy test -- cell must be below threshold value for a number of consecutive events to be considered dead
00079   energyThreshold_       = ps.getUntrackedParameter<double>("DeadCellMonitor_energyThreshold",                  1);
00080   HBenergyThreshold_     = ps.getUntrackedParameter<double>("DeadCellMonitor_HB_energyThreshold",energyThreshold_);
00081   HEenergyThreshold_     = ps.getUntrackedParameter<double>("DeadCellMonitor_HE_energyThreshold",energyThreshold_);
00082   HOenergyThreshold_     = ps.getUntrackedParameter<double>("DeadCellMonitor_HO_energyThreshold",energyThreshold_);
00083   HFenergyThreshold_     = ps.getUntrackedParameter<double>("DeadCellMonitor_HF_energyThreshold",energyThreshold_);
00084   HFenergyThreshold_     = ps.getUntrackedParameter<double>("DeadCellMonitor_HF_energyThreshold",            -999);
00085   ZDCenergyThreshold_    = ps.getUntrackedParameter<double>("DeadCellMonitor_ZDC_energyThreshold",           -999);
00086 
00087   // neighboring-cell tests
00088   defaultNeighborParams_.DeltaIphi = ps.getUntrackedParameter<int>("DeadCellMonitor_neighbor_deltaIphi", 1);
00089   defaultNeighborParams_.DeltaIeta = ps.getUntrackedParameter<int>("DeadCellMonitor_neighbor_deltaIeta", 1);
00090   defaultNeighborParams_.DeltaDepth = ps.getUntrackedParameter<int>("DeadCellMonitor_neighbor_deltaDepth", 0);
00091   defaultNeighborParams_.maxCellEnergy = ps.getUntrackedParameter<double>("DeadCellMonitor_neighbor_maxCellEnergy",3.);
00092   defaultNeighborParams_.minNeighborEnergy = ps.getUntrackedParameter<double>("DeadCellMonitor_neighbor_minNeighborEnergy",1.);
00093   defaultNeighborParams_.minGoodNeighborFrac = ps.getUntrackedParameter<double>("DeadCellMonitor_neighbor_minGoodNeighborFrac",0.7);
00094   defaultNeighborParams_.maxEnergyFrac = ps.getUntrackedParameter<double>("DeadCellMonitor_neighbor_maxEnergyFrac",0.2);
00095   setupNeighborParams(ps,HBNeighborParams_ ,"HB");
00096   setupNeighborParams(ps,HENeighborParams_ ,"HE");
00097   setupNeighborParams(ps,HONeighborParams_ ,"HO");
00098   setupNeighborParams(ps,HFNeighborParams_ ,"HF");
00099   setupNeighborParams(ps,ZDCNeighborParams_,"ZDC");
00100   HFNeighborParams_.DeltaIphi*=2; // HF cell segmentation is 10 degrees, not 5 (mostly).  Need to multiply by 2 to convert from cell range to degree format
00101 
00102   // Set initial event # to 0
00103   ievt_=0;
00104 
00105   // zero all counters
00106   for (int i=0;i<ETABINS;++i)
00107     {
00108       for (int j=0;j<PHIBINS;++j)
00109         {
00110           for (int k=0;k<4;++k)
00111             {
00112               occupancy[i][j][k]=0;
00113               rechit_occupancy[i][j][k]=0;
00114               abovepedestal[i][j][k]=0;
00115               belowneighbors[i][j][k]=0;
00116               aboveenergy[i][j][k]=0;
00117             }
00118         }
00119     }
00120 
00121   // Set up histograms
00122   if (m_dbe)
00123     {
00124       if (fVerbosity>1)
00125         cout <<"<HcalDeadCellMonitor::setup>  Setting up histograms"<<endl;
00126 
00127       m_dbe->setCurrentFolder(baseFolder_);
00128       meEVT_ = m_dbe->bookInt("Dead Cell Task Event Number");
00129       meEVT_->Fill(ievt_);
00130 
00131       // Create problem cell plots
00132       // Overall plot gets an initial " " in its name
00133       ProblemDeadCells=m_dbe->book2D(" ProblemDeadCells",
00134                                      " Problem Dead Cell Rate for all HCAL",
00135                                      etaBins_,etaMin_,etaMax_,
00136                                      phiBins_,phiMin_,phiMax_);
00137       ProblemDeadCells->setAxisTitle("i#eta",1);
00138       ProblemDeadCells->setAxisTitle("i#phi",2);
00139       // Only show problem cells that are above problem threshold
00140       (ProblemDeadCells->getTH2F())->SetMinimum(deadmon_minErrorFlag_);
00141       (ProblemDeadCells->getTH2F())->SetMaximum(1.);
00142       
00143       // Overall Problem plot appears in main directory; plots by depth appear \in subdirectory
00144       m_dbe->setCurrentFolder(baseFolder_+"/problem_deadcells");
00145       setupDepthHists2D(ProblemDeadCellsByDepth, " Problem Dead Cell Rate","");
00146       setMinMaxHists2D(ProblemDeadCellsByDepth,deadmon_minErrorFlag_,1.);
00147 
00148       // Set up plots for each failure mode of dead cells
00149       stringstream units; // We'll need to set the titles individually, rather than passing units to setupDepthHists2D (since this also would affect the name of the histograms)
00150       m_dbe->setCurrentFolder(baseFolder_+"/dead_unoccupied_digi");
00151       //units<<"("<<deadmon_checkNevents_occupancy_<<" consec. events)";
00152       setupDepthHists2D(UnoccupiedDeadCellsByDepth,
00153                         "Dead Cells with No Digis","");
00154       setMinMaxHists2D(UnoccupiedDeadCellsByDepth,0.,1.);
00155 
00156       m_dbe->setCurrentFolder(baseFolder_+"/dead_unoccupied_rechit");
00157       setupDepthHists2D(UnoccupiedRecHitsByDepth,
00158                         "Dead Cells with No Rec Hits","");
00159       setMinMaxHists2D(UnoccupiedRecHitsByDepth,0.,1.);
00160 
00161       m_dbe->setCurrentFolder(baseFolder_+"/dead_pedestaltest");
00162       setupDepthHists2D(BelowPedestalDeadCellsByDepth,"Dead Cells Failing Pedestal Test","");
00163       setMinMaxHists2D(BelowPedestalDeadCellsByDepth,0.,1.);
00164       // set more descriptive titles for pedestal plots
00165       units.str("");
00166       units<<"Dead Cells Failing Pedestal Test Depth 1 -- HB < ped + "<<HBnsigma_<<" #sigma, HF < ped + "<<HFnsigma_<<" #sigma";
00167       BelowPedestalDeadCellsByDepth[0]->setTitle(units.str().c_str());
00168       units.str("");
00169       units<<"Dead Cells Failing Pedestal Test Depth 2 -- HB < ped + "<<HBnsigma_<<" #sigma, HF < ped + "<<HFnsigma_<<" #sigma";
00170       BelowPedestalDeadCellsByDepth[1]->setTitle(units.str().c_str());
00171       units.str("");
00172       units<<"Dead Cells Failing Pedestal Test Depth 3 -- HE < ped + "<<HEnsigma_<<" #sigma";
00173       BelowPedestalDeadCellsByDepth[2]->setTitle(units.str().c_str());
00174       units.str("");
00175       units<<"Dead Cells Failing Pedestal Test Depth 4 -- HO < ped + "<<HOnsigma_<<" #sigma, ZDC TBD";
00176       BelowPedestalDeadCellsByDepth[3]->setTitle(units.str().c_str());
00177       units.str("");
00178       units<<"Dead Cells Failing Pedestal Test Depth 1 -- HE < ped + "<<HEnsigma_<<" #sigma";
00179       BelowPedestalDeadCellsByDepth[4]->setTitle(units.str().c_str());
00180       units.str("");
00181       units<<"Dead Cells Failing Pedestal Test Depth 2 -- HE < ped + "<<HEnsigma_<<" #sigma";
00182       BelowPedestalDeadCellsByDepth[5]->setTitle(units.str().c_str());
00183       units.str("");
00184 
00185       m_dbe->setCurrentFolder(baseFolder_+"/dead_neighbortest");
00186       setupDepthHists2D(BelowNeighborsDeadCellsByDepth,"Dead Cells Failing Neighbor Test","");
00187       setMinMaxHists2D(BelowNeighborsDeadCellsByDepth,0.,1.);
00188 
00189       m_dbe->setCurrentFolder(baseFolder_+"/dead_energytest");
00190       setupDepthHists2D(BelowEnergyThresholdCellsByDepth,"Dead Cells Failing Energy Threshold Test","");
00191       setMinMaxHists2D(BelowEnergyThresholdCellsByDepth,0.,1.);
00192       // set more descriptive titles for threshold plots
00193       units.str("");
00194       units<<"Dead Cells with Consistent Low Energy Depth 1 -- HB <"<<HBenergyThreshold_<<" GeV, HF <"<<HFenergyThreshold_<<" GeV";
00195       BelowEnergyThresholdCellsByDepth[0]->setTitle(units.str().c_str());
00196       units.str("");
00197       units<<"Dead Cells with Consistent Low Energy Depth 2 -- HB <"<<HBenergyThreshold_<<" GeV, HF <"<<HFenergyThreshold_<<" GeV";
00198       BelowEnergyThresholdCellsByDepth[1]->setTitle(units.str().c_str());
00199       units.str("");
00200       units<<"Dead Cells with Consistent Low Energy Depth 3 -- HE <"<<HEenergyThreshold_<<" GeV";
00201       BelowEnergyThresholdCellsByDepth[2]->setTitle(units.str().c_str());
00202       units.str("");
00203       units<<"Dead Cells with Consistent Low Energy Depth 4 -- HO <"<<HOenergyThreshold_<<" GeV, ZDC TBD";
00204       BelowEnergyThresholdCellsByDepth[3]->setTitle(units.str().c_str());
00205       units.str("");
00206       units<<"Dead Cells with Consistent Low Energy Depth 1 -- HE <"<<HEenergyThreshold_<<" GeV";
00207       BelowEnergyThresholdCellsByDepth[4]->setTitle(units.str().c_str());
00208       units.str("");
00209       units<<"Dead Cells with Consistent Low Energy Depth 2 -- HE <"<<HEenergyThreshold_<<" GeV";
00210       BelowEnergyThresholdCellsByDepth[5]->setTitle(units.str().c_str());
00211       units.str("");
00212 
00213       if (deadmon_makeDiagnostics_)
00214         {
00215           m_dbe->setCurrentFolder(baseFolder_+"/diagnostics/pedestal");
00216           d_HBnormped=m_dbe->book1D("HB_normped","HB Dead Cell pedestal diagnostic ",300,-10,20);
00217           d_HEnormped=m_dbe->book1D("HE_normped","HE Dead Cell pedestal diagnostic",300,-10,20);
00218           d_HOnormped=m_dbe->book1D("HO_normped","HO Dead Cell pedestal diagnostic",300,-10,20);
00219           d_HFnormped=m_dbe->book1D("HF_normped","HF Dead Cell pedestal diagnostic",300,-10,20);
00220 
00221           d_HBnormped->setAxisTitle("(avg ADC-pedestal)/#sigma",1);
00222           d_HEnormped->setAxisTitle("(avg ADC-pedestal)/#sigma",1);
00223           d_HOnormped->setAxisTitle("(avg ADC-pedestal)/#sigma",1);
00224           d_HFnormped->setAxisTitle("(avg ADC-pedestal)/#sigma",1);
00225 
00226           m_dbe->setCurrentFolder(baseFolder_+"/diagnostics/energythreshold");
00227           d_HBrechitenergy=m_dbe->book1D("HB_rechitenergy","HB rechit energy",500,-10,40);
00228           d_HErechitenergy=m_dbe->book1D("HE_rechitenergy","HE rechit energy",500,-10,40);
00229           d_HOrechitenergy=m_dbe->book1D("HO_rechitenergy","HO rechit energy",500,-10,40);
00230           d_HFrechitenergy=m_dbe->book1D("HF_rechitenergy","HF rechit energy",500,-10,40);
00231 
00232           m_dbe->setCurrentFolder(baseFolder_+"/diagnostics/neighborcells");
00233           d_HBenergyVsNeighbor=m_dbe->book2D("HB_energyVsNeighbor","HB rec hit energy vs.  #Sigma Neighbors",100,0,25,100,-5,15);
00234           d_HEenergyVsNeighbor=m_dbe->book2D("HE_energyVsNeighbor","HE rec hit energy vs.  #Sigma Neighbors",100,0,25,100,-5,15);
00235           d_HOenergyVsNeighbor=m_dbe->book2D("HO_energyVsNeighbor","HO rec hit energy vs.  #Sigma Neighbors",100,0,25,100,-5,15);
00236           d_HFenergyVsNeighbor=m_dbe->book2D("HF_energyVsNeighbor","HF rec hit energy vs.  #Sigma Neighbors",100,0,25,100,-5,15);
00237 
00238         } // if (deadmon_makeDiagnostics_)
00239     } // if (m_dbe)
00240 
00241   return;
00242 } //void HcalDeadCellMonitor::setup(...)
00243 
00244 /* --------------------------- */
00245 void HcalDeadCellMonitor::setupNeighborParams(const edm::ParameterSet& ps,
00246                                               neighborParams& N,
00247                                               char* type)
00248 {
00249   // sets up parameters for neighboring-cell algorithm for each subdetector
00250   ostringstream myname;
00251   myname<<"DeadCellMonitor_"<<type<<"_neighbor_deltaIphi";
00252   N.DeltaIphi = ps.getUntrackedParameter<int>(myname.str().c_str(),
00253                                               defaultNeighborParams_.DeltaIphi);
00254   myname.str("");
00255   myname<<"DeadCellMonitor_"<<type<<"_neighbor_deltaIeta";
00256   N.DeltaIeta = ps.getUntrackedParameter<int>(myname.str().c_str(),
00257                                               defaultNeighborParams_.DeltaIeta);
00258   myname.str("");
00259   myname<<"DeadCellMonitor_"<<type<<"_neighbor_deltaDepth";
00260   N.DeltaDepth = ps.getUntrackedParameter<int>(myname.str().c_str(),
00261                                                defaultNeighborParams_.DeltaDepth);
00262   myname.str("");
00263   myname<<"DeadCellMonitor_"<<type<<"_neighbor_maxCellEnergy";
00264   N.maxCellEnergy = ps.getUntrackedParameter<double>(myname.str().c_str(),
00265                                                      defaultNeighborParams_.maxCellEnergy);
00266   myname.str("");
00267   myname<<"DeadCellMonitor_"<<type<<"_neighbor_minNeighborEnergy";
00268   N.minNeighborEnergy = ps.getUntrackedParameter<double>(myname.str().c_str(),
00269                                                          defaultNeighborParams_.minNeighborEnergy);
00270   myname.str("");
00271   myname<<"DeadCellMonitor_"<<type<<"_neighbor_minGoodNeighborFrac";
00272   N.minGoodNeighborFrac = ps.getUntrackedParameter<double>(myname.str().c_str(),
00273                                                            defaultNeighborParams_.minGoodNeighborFrac);
00274   myname.str("");
00275   myname<<"DeadCellMonitor_"<<type<<"_neighbor_maxEnergyFrac";
00276   N.maxEnergyFrac = ps.getUntrackedParameter<double>(myname.str().c_str(),
00277                                                      defaultNeighborParams_.maxEnergyFrac);
00278   return;
00279 } // void HcalDeadCellMonitor::setupNeighborParams
00280 
00281 /* --------------------------- */
00282 
00283 void HcalDeadCellMonitor::reset(){}  // reset function is empty for now
00284 
00285 /* --------------------------- */
00286 
00287 void HcalDeadCellMonitor::createMaps(const HcalDbService& cond)
00288 {
00289 
00290   // Creates maps for pedestals, widths, and pedestals+Nsigma*widths, using HcalDetIds as keys
00291   
00292   if (!deadmon_test_pedestal_) return; // no need to create maps if we're not running the pedestal-based dead cell finder
00293 
00294   if (showTiming)
00295     {
00296       cpu_timer.reset(); cpu_timer.start();
00297     }
00298   
00299   if (fVerbosity>0)
00300     cout <<"<HcalDeadCellMonitor::createMaps>:  Making pedestal maps"<<endl;
00301   double ped=0;
00302   double width=0;
00303   HcalCalibrations calibs;
00304   const HcalQIEShape* shape = cond.getHcalShape();
00305 
00306   double myNsigma=0;
00307   double myADC=0;
00308 
00309   for (int ieta=static_cast<int>(etaMin_);ieta<=static_cast<int>(etaMax_);++ieta)
00310     {
00311       for (int iphi=static_cast<int>(phiMin_);iphi<=static_cast<int>(phiMax_);++iphi)
00312         {
00313           for (int depth=1;depth<=4;++depth)
00314             {
00315               for (int subdet=1;subdet<=4;++subdet)
00316                 {
00317                   if (!validDetId((HcalSubdetector)subdet, ieta, iphi, depth))
00318                     continue;
00319                   HcalDetId hcal((HcalSubdetector)(subdet), ieta, iphi, depth);
00320                   
00321                   if (hcal.subdet()==HcalBarrel)
00322                     myNsigma=HBnsigma_;
00323                   else if (hcal.subdet()==HcalEndcap)
00324                     myNsigma=HEnsigma_;
00325                   else if (hcal.subdet()==HcalOuter)
00326                     myNsigma=HOnsigma_;
00327                   else if (hcal.subdet()==HcalForward)
00328                     myNsigma=HFnsigma_;
00329                   
00330                   calibs=cond.getHcalCalibrations(hcal);
00331                   const HcalPedestalWidth* pedw = cond.getPedestalWidth(hcal);
00332                    
00333                   ped=0.;
00334                   width=0.;
00335                   myADC=0.;
00336                   // loop over capids
00337                   for (int capid=0;capid<4;++capid)
00338                     {
00339                       // pedestals from calibs.pedestal are always in fC
00340                       const HcalQIECoder* channelCoder=cond.getHcalCoder(hcal);
00341                       
00342                       // Convert pedestals to ADC
00343                       myADC=channelCoder->adc(*shape,
00344                                               (float)calibs.pedestal(capid),
00345                                               capid);
00346                       ped+=myADC;
00347 
00348                       // Now the tricky part -- need to convert widths to ADC if provided in fC
00349                       if (doFCpeds_)
00350                         {
00351                           // Form width by summing the diagonal terms of the covariance matrix (sigma_ii),
00352                           // and scale by ADC/fC ratio to convert from fC^2 to ADC^2
00353                           width+=(pedw->getSigma(capid,capid)*pow(myADC/calibs.pedestal(capid),2));
00354                         }
00355                       else
00356                         width+=pedw->getSigma(capid,capid);
00357                     } // for (int capid=0;capid<4;++capid)
00358 
00359                   ped/=4.;  // pedestal value is average over capids
00360                   width=pow(width,0.5)/4.;
00361 
00362                   pedestals_[hcal]=ped;
00363                   widths_[hcal]=width;
00364                   if (fVerbosity>1) cout <<"<HcalDeadCellMonitor::createMaps>  Pedestal Value -- ID = "<<(HcalSubdetector)subdet<<"  ("<<ieta<<", "<<iphi<<", "<<depth<<"): "<<ped<<"; width = "<<width<<endl;
00365                   pedestal_thresholds_[hcal]=ped+myNsigma*width;
00366                 } // for (int subdet=1,...)
00367             } // for (int depth=1;...)
00368         } // for (int phi ...)
00369     } // for (int ieta...)
00370   
00371   return;
00372 } // void HcalDeadCellMonitor::createMaps
00373 
00374 
00375 
00376 
00377 /* ------------------------- */
00378 
00379 void HcalDeadCellMonitor::done(std::map<HcalDetId, unsigned int>& myqual)
00380 {
00381   if (dump2database==0) 
00382     return;
00383 
00384   // Dump to ascii file for database -- now taken care of through ChannelStatus objects
00385   /*
00386   char buffer [1024];
00387   
00388   ofstream fOutput("hcalDeadCells.txt", ios::out);
00389   sprintf (buffer, "# %15s %15s %15s %15s %8s %10s\n", "eta", "phi", "dep", "det", "value", "DetId");
00390   fOutput << buffer;
00391   */
00392 
00393   int eta,phi;
00394   float binval;
00395   int mydepth;
00396 
00397   int subdet;
00398   char* subdetname;
00399   if (fVerbosity>1)
00400     {
00401       cout <<"<HcalDeadCellMonitor>  Summary of Dead Cells in Run: "<<endl;
00402       cout <<"(Error rate must be >= "<<deadmon_minErrorFlag_*100.<<"% )"<<endl;  
00403     }
00404   for (int ieta=1;ieta<=etaBins_;++ieta)
00405     {
00406       for (int iphi=1;iphi<=phiBins_;++iphi)
00407         {
00408           eta=ieta+int(etaMin_)-1;
00409           phi=iphi+int(phiMin_)-1;
00410 
00411           for (int d=0;d<6;++d)
00412             {
00413               binval=ProblemDeadCellsByDepth[d]->getBinContent(ieta,iphi);
00414              
00415               // Set subdetector labels for output
00416               if (d<2) // HB/HF
00417                 {
00418                   if (abs(eta)<29)
00419                     {
00420                       subdetname="HB";
00421                       subdet=1;
00422                     }
00423                   else
00424                     {
00425                       subdetname="HF";
00426                       subdet=4;
00427                     }
00428                 }
00429               else if (d==3)
00430                 {
00431                   if (abs(eta)==43)
00432                     {
00433                       subdetname="ZDC";
00434                       subdet=7; // correct value??
00435                     }
00436                   else
00437                     {
00438                       subdetname="HO";
00439                       subdet=3;
00440                     }
00441                 }
00442               else
00443                 {
00444                   subdetname="HE";
00445                   subdet=2;
00446                 }
00447               // Set correct depth label
00448               if (d>3)
00449                 mydepth=d-3;
00450               else
00451                 mydepth=d+1;
00452               HcalDetId myid((HcalSubdetector)(subdet), eta, phi, mydepth);
00453               if (!validDetId((HcalSubdetector)(subdet), eta, phi, mydepth))
00454                 continue;
00455 
00456               if (fVerbosity>0 && binval>deadmon_minErrorFlag_)
00457                 cout <<"Dead Cell "<<subdet<<"("<<eta<<", "<<phi<<", "<<mydepth<<"):  "<<binval*100.<<"%"<<endl;
00458               int value = 0;
00459               if (binval>deadmon_minErrorFlag_)
00460                 value=1;
00461               
00462               if (value==1)
00463               if (myqual.find(myid)==myqual.end())
00464                 {
00465                   myqual[myid]=(value<<BITSHIFT);  // deadcell shifted to bit 5
00466                 }
00467               else
00468                 {
00469                   int mask=(1<<BITSHIFT);
00470                   if (value==1)
00471                     myqual[myid] |=mask;
00472 
00473                   else
00474                     myqual[myid] &=~mask;
00475                   if (value==1 && fVerbosity>1) cout <<"myqual = "<<std::hex<<myqual[myid]<<std::dec<<"  MASK = "<<std::hex<<mask<<std::dec<<endl;
00476                 }
00477               /*
00478               sprintf(buffer, "  %15i %15i %15i %15s %8X %10X \n",eta,phi,mydepth,subdetname,(value<<BITSHIFT),int(myid.rawId()));
00479               fOutput<<buffer;
00480               */
00481             } // for (int d=0;d<6;++d) // loop over depth histograms
00482         } // for (int iphi=1;iphi<=phiBins_;++iphi)
00483     } // for (int ieta=1;ieta<=etaBins_;++ieta)
00484   //fOutput.close();
00485 
00486   return;
00487 
00488 } // void HcalDeadCellMonitor::done()
00489 
00490 
00491 
00492 /* --------------------------------- */
00493 
00494 void HcalDeadCellMonitor::clearME()
00495 {
00496   // I don't think this function gets cleared any more.  
00497   // And need to add code to clear out subfolders as well?
00498   if (m_dbe)
00499     {
00500       m_dbe->setCurrentFolder(baseFolder_);
00501       m_dbe->removeContents();
00502     }
00503   return;
00504 } // void HcalDeadCellMonitor::clearME()
00505 
00506 /* -------------------------------- */
00507 
00508 
00509 void HcalDeadCellMonitor::processEvent(const HBHERecHitCollection& hbHits,
00510                                        const HORecHitCollection& hoHits,
00511                                        const HFRecHitCollection& hfHits,
00512                                        //const ZDCRecHitCollection& zdcHits,
00513                                        const HBHEDigiCollection& hbhedigi,
00514                                        const HODigiCollection& hodigi,
00515                                        const HFDigiCollection& hfdigi,
00516                                        //const ZDCDigiCollection& zdcdigi,
00517                                        const HcalDbService& cond
00518                                        )
00519 {
00520 
00521   if (showTiming)
00522     {
00523       cpu_timer.reset(); cpu_timer.start();
00524     }
00525 
00526   ++ievt_;
00527   if (m_dbe) meEVT_->Fill(ievt_);
00528   
00529   HOpresent_ = (hodigi.size()>0||hoHits.size()>0);
00530   HFpresent_ = (hfdigi.size()>0||hfHits.size()>0);
00531   if (fVerbosity>1) cout <<"<HcalDeadCellMonitor::processEvent> Processing event..."<<endl;
00532 
00533   // Do Digi-Based dead cell searches 
00534 
00535   if (deadmon_test_occupancy_ || deadmon_test_pedestal_)
00536     processEvent_digi(hbhedigi,hodigi,hfdigi,cond);
00537 
00538   // Search for "dead" cells below a certain energy
00539   if (deadmon_test_energy_ || deadmon_test_rechit_occupancy_)
00540     {
00541       processEvent_rechitenergy(hbHits, hoHits,hfHits);
00542     }
00543 
00544   // Search for cells that are "dead" compared to their neighbors
00545   if (deadmon_test_neighbor_)
00546     {
00547       processEvent_rechitneighbors(hbHits, hoHits, hfHits);
00548     }
00549   
00550   // Fill problem cells
00551   if (((ievt_%deadmon_checkNevents_occupancy_ ==0) && deadmon_test_occupancy_ )||
00552       ((ievt_%deadmon_checkNevents_pedestal_  ==0) && deadmon_test_pedestal_  )||
00553       ((ievt_%deadmon_checkNevents_neighbor_  ==0) && deadmon_test_neighbor_  )||
00554       ((ievt_%deadmon_checkNevents_energy_    ==0) && deadmon_test_energy_    ))
00555     {
00556       fillNevents_problemCells();
00557     }
00558 
00559   return;
00560 } // void HcalDeadCellMonitor::processEvent(...)
00561 
00562 /* --------------------------------------- */
00563 
00564 void HcalDeadCellMonitor::fillDeadHistosAtEndRun()
00565 {
00566   // Fill histograms one last time at endRun call
00567   
00568   /*
00569     I'm not sure I like this feature.  Suppose checkNevents=500, and the end run occurs at 501?
00570     Then the occupancy plot would create errors for whichever digis were not found in a single event.
00571     That's not desired behavior.
00572     We could just exclude the occupancy test from running here, but I'm not sure that's the best solution either.
00573     For now (28 Oct. 2008), just disable this functionality.  We'll come back to it if necessary.
00574   */
00575   return;
00576 
00577   if (deadmon_test_occupancy_ && ievt_%deadmon_checkNevents_occupancy_>0) fillNevents_occupancy();
00578   if (deadmon_test_pedestal_  && ievt_%deadmon_checkNevents_pedestal_ >0) fillNevents_pedestal();
00579   if (deadmon_test_neighbor_  && ievt_%deadmon_checkNevents_neighbor_ >0) fillNevents_neighbor();
00580   if (deadmon_test_energy_    && ievt_%deadmon_checkNevents_energy_   >0) fillNevents_energy();
00581   if (deadmon_test_occupancy_ || deadmon_test_pedestal_ || 
00582       deadmon_test_neighbor_  || deadmon_test_energy_)  
00583    {
00584      fillNevents_problemCells();
00585      FillUnphysicalHEHFBins(ProblemDeadCellsByDepth);
00586    }
00587 }
00588 
00589 /* --------------------------------------- */
00590 
00591 
00592 void HcalDeadCellMonitor::processEvent_rechitenergy( const HBHERecHitCollection& hbheHits,
00593                                                      const HORecHitCollection& hoHits,
00594                                                      const HFRecHitCollection& hfHits)
00595                                                 
00596 {
00597   // Looks at rechits of cells and compares to threshold energies.
00598   // Cells below thresholds get marked as dead candidates
00599 
00600   if (showTiming)
00601     {
00602       cpu_timer.reset(); cpu_timer.start();
00603     }
00604 
00605  if (fVerbosity>1) cout <<"<HcalDeadCellMonitor::processEvent_rechitenergy> Processing rechits..."<<endl;
00606  if (deadmon_test_neighbor_)   rechitEnergies_.clear();
00607 
00608  // loop over HBHE
00609  for (HBHERecHitCollection::const_iterator HBHEiter=hbheHits.begin(); HBHEiter!=hbheHits.end(); ++HBHEiter) 
00610    { // loop over all hits
00611      float en = HBHEiter->energy();
00612      //float ti = HBHEiter->time();
00613 
00614      HcalDetId id(HBHEiter->detid().rawId());
00615      int ieta = id.ieta();
00616      int iphi = id.iphi();
00617      int depth = id.depth();
00618      if (id.subdet()==HcalBarrel)
00619        {
00620          HBpresent_=true;
00621          if (!checkHB_) continue;
00622          if (deadmon_makeDiagnostics_) d_HBrechitenergy->Fill(en);
00623          ++rechit_occupancy[static_cast<int>(ieta+(etaBins_-2)/2)][iphi-1][depth-1];
00624          if (en>=HBenergyThreshold_)
00625            ++aboveenergy[static_cast<int>(ieta+(etaBins_-2)/2)][iphi-1][depth-1];
00626        }
00627      else //if (id.subdet()==HcalEndcap)
00628        {
00629          HEpresent_=true;
00630          if (!checkHE_) continue;
00631          if (deadmon_makeDiagnostics_) d_HErechitenergy->Fill(en);
00632          ++rechit_occupancy[static_cast<int>(ieta+(etaBins_-2)/2)][iphi-1][depth-1];
00633          if (en>=HEenergyThreshold_)
00634            ++aboveenergy[static_cast<int>(ieta+(etaBins_-2)/2)][iphi-1][depth-1];
00635        }
00636      if (deadmon_test_neighbor_) rechitEnergies_[id]=en;
00637    } //for (HBHERecHitCollection::const_iterator HBHEiter=...)
00638 
00639  // loop over HO
00640  if (checkHO_)
00641    {
00642      for (HORecHitCollection::const_iterator HOiter=hoHits.begin(); HOiter!=hoHits.end(); ++HOiter) 
00643        { // loop over all hits
00644          float en = HOiter->energy();
00645          
00646          HcalDetId id(HOiter->detid().rawId());
00647          int ieta = id.ieta();
00648          int iphi = id.iphi();
00649          int depth = id.depth();
00650          ++rechit_occupancy[static_cast<int>(ieta+(etaBins_-2)/2)][iphi-1][depth-1];
00651          if (deadmon_makeDiagnostics_) d_HOrechitenergy->Fill(en);
00652          if (en>=HOenergyThreshold_)
00653            ++aboveenergy[static_cast<int>(ieta+(etaBins_-2)/2)][iphi-1][depth-1];
00654          if (deadmon_test_neighbor_) rechitEnergies_[id]=en;
00655        }
00656    } // if (checkHO_)
00657  
00658  // loop over HF
00659  if (checkHF_)
00660    {
00661      for (HFRecHitCollection::const_iterator HFiter=hfHits.begin(); HFiter!=hfHits.end(); ++HFiter) 
00662        { // loop over all hits
00663          float en = HFiter->energy();
00664          
00665          HcalDetId id(HFiter->detid().rawId());
00666          int ieta = id.ieta();
00667          int iphi = id.iphi();
00668          int depth = id.depth();
00669          if (deadmon_makeDiagnostics_) d_HFrechitenergy->Fill(en);
00670          ++rechit_occupancy[static_cast<int>(ieta+(etaBins_-2)/2)][iphi-1][depth+1];
00671          if (en>=HFenergyThreshold_)
00672            ++aboveenergy[static_cast<int>(ieta+(etaBins_-2)/2)][iphi-1][depth+1]; // HF depths get shifted up by +2
00673          if (deadmon_test_neighbor_) rechitEnergies_[id]=en;
00674        }
00675    } // if (checkHF_)
00676  
00677  
00678  // Fill histograms 
00679   if (ievt_%deadmon_checkNevents_energy_==0)
00680     {
00681         if (fVerbosity>0) cout <<"<HcalDeadCellMonitor::processEvent_rechitenergy> Filling DeadCell Energy plots"<<endl;
00682         fillNevents_energy();
00683     }
00684 
00685  if (showTiming)
00686    {
00687      cpu_timer.stop();  cout <<"TIMER:: HcalDeadCellMonitor PROCESSEVENT_RECHITENERGY -> "<<cpu_timer.cpuTime()<<endl;
00688    }
00689  return;
00690 } // void HcalDeadCellMonitor::processEvent_rechitenergy
00691 
00692 /* --------------------------------------- */
00693 
00694 
00695 void HcalDeadCellMonitor::processEvent_rechitneighbors( const HBHERecHitCollection& hbheHits,
00696                                                         const HORecHitCollection& hoHits,
00697                                                         const HFRecHitCollection& hfHits
00698                                                         )
00699 {
00700   // Compares energy to energy of neighboring cells.
00701   // Perhaps promising, but energies tend to be centered around 0 (positive AND negative)
00702   // negative-energy rechits make this method pretty useless.  Keep it disabled for now.
00703 
00704   if (showTiming)
00705     {
00706       cpu_timer.reset(); cpu_timer.start();
00707     }
00708 
00709  if (fVerbosity>1) cout <<"<HcalDeadCellMonitor::processEvent_rechitneighbors> Processing rechits..."<<endl;
00710 
00711  // if Energy test wasn't run, need to creat map of Detid:rechitenergy here
00712  if (!deadmon_test_energy_)
00713    {
00714      rechitEnergies_.clear(); // clear old map
00715      for (HBHERecHitCollection::const_iterator HBHEiter=hbheHits.begin(); HBHEiter!=hbheHits.end(); ++HBHEiter) 
00716        { // loop over all hits
00717          float en = HBHEiter->energy();
00718          HcalDetId id(HBHEiter->detid().rawId());
00719          if (id.subdet()==HcalBarrel)
00720            {
00721              HBpresent_=true;
00722              if (!checkHB_)
00723                continue;
00724            }
00725          else
00726            {
00727              HEpresent_=true;
00728              if (!checkHE_)
00729                continue;
00730            }
00731          rechitEnergies_[id]=en;
00732        }
00733      // HO
00734      if (checkHO_)
00735        {
00736          for (HORecHitCollection::const_iterator HOiter=hoHits.begin(); HOiter!=hoHits.end(); ++HOiter) 
00737            { // loop over all hits
00738              float en = HOiter->energy();
00739              HcalDetId id(HOiter->detid().rawId());
00740              rechitEnergies_[id]=en;
00741            }
00742        } // if (checkHO_)
00743      //HF
00744      if (checkHF_)
00745        {
00746          for (HFRecHitCollection::const_iterator HFiter=hfHits.begin(); HFiter!=hfHits.end(); ++HFiter) 
00747            { // loop over all hits
00748              float en = HFiter->energy();
00749              HcalDetId id(HFiter->detid().rawId());
00750              rechitEnergies_[id]=en;
00751            }
00752        } // if (checkHF_)
00753 
00754    } // if (!deadmon_test_energy_)   
00755 
00756  // Now do "real" loop, checking against each cell against its neighbors
00757  
00758  /* Note:  This works a little differently than the other tests.  The other tests check that a cell consistently
00759     fails its test condition for N consecutive events.  The neighbor test will flag a cell for every event in which
00760     it's significantly less than its neighbors, regardless of whether that condition persists for a number of events.
00761  */
00762 
00763  int ieta, iphi, depth;
00764  float en;
00765 
00766  int cellsfound=0;
00767  int allneighbors=0;
00768  float enNeighbor=0;
00769 
00770  // loop over HBHE
00771  for (HBHERecHitCollection::const_iterator HBHEiter=hbheHits.begin(); 
00772       HBHEiter!=hbheHits.end(); 
00773       ++HBHEiter) 
00774    { // loop over all hits
00775      
00776      en = HBHEiter->energy();
00777      HcalDetId id(HBHEiter->detid().rawId());
00778      ieta = id.ieta();
00779      iphi = id.iphi();
00780      depth = id.depth();
00781 
00782      if (id.subdet()==HcalBarrel)
00783        {
00784          HBpresent_=true;
00785          if (!checkHB_) continue;
00786          // Search keys for neighboring cells
00787          if (en>HBNeighborParams_.maxCellEnergy) // cells above maxCellEnergy not considered dead
00788            continue;
00789          allneighbors=0;
00790          cellsfound=0;
00791          enNeighbor=0;
00792          for (int nD=-1*HBNeighborParams_.DeltaDepth;nD<=HBNeighborParams_.DeltaDepth;++nD)
00793            {
00794              for (int nP =-1*HBNeighborParams_.DeltaIphi;nP<=HBNeighborParams_.DeltaIphi;++nP)
00795                {
00796                  for (int nE =-1*HBNeighborParams_.DeltaIeta;nE<=HBNeighborParams_.DeltaIeta;++nE)
00797                    {
00798                      if (nD==0 && nE==0 && nP==0) 
00799                        continue; // don't count the cell itself
00800                      int myphi=nP+iphi;
00801                      if (myphi>72) myphi-=72; // allow for wrapping of cells
00802                      if (myphi<=0) myphi+=72;
00803                      if (!validDetId((HcalSubdetector)(1),nE+ieta, myphi, nD+depth)) continue;
00804                      HcalDetId myid((HcalSubdetector)(1), nE+ieta, myphi, nD+depth); // HB
00805                      ++allneighbors;
00806                      if (rechitEnergies_.find(myid)==rechitEnergies_.end())
00807                        continue;
00808                      if (rechitEnergies_[myid]<HBNeighborParams_.minNeighborEnergy)
00809                        continue;
00810                      ++cellsfound;
00811                      enNeighbor+=rechitEnergies_[myid];
00812                    } // loop over nE (neighbor eta)
00813                } // loop over nP (neighbor phi)
00814            } // loop over nD depths
00815 
00816          if (deadmon_makeDiagnostics_)
00817            d_HBenergyVsNeighbor->Fill(enNeighbor,en);
00818          
00819          // Case 1:  Not enough good neighbors found
00820          if (1.*cellsfound/allneighbors<HBNeighborParams_.minGoodNeighborFrac)
00821            continue;
00822          // Case 2:  energy/(avg. neighbor energy) too large for cell to be considered dead
00823          if (1.*en/(enNeighbor/allneighbors)>HENeighborParams_.maxEnergyFrac)
00824            continue;
00825          // Case 3:  Tests passed; cell marked as dead
00826          ++belowneighbors[static_cast<int>(ieta+(etaBins_-2)/2)][iphi-1][depth-1];
00827        }
00828      else //if (id.subdet()==HcalEndcap)
00829        {
00830          HEpresent_=true;
00831          if (!checkHE_) continue;
00832          // Search keys for neighboring cells
00833          if (en>HENeighborParams_.maxCellEnergy) // cells above maxCellEnergy not considered dead
00834            continue;
00835          allneighbors=0;
00836          cellsfound=0;
00837          enNeighbor=0;
00838          int HEDeltaIphi = HENeighborParams_.DeltaIphi;
00839          // now correct for boundaries
00840          if (abs(ieta)>20) HEDeltaIphi*=2; // double iphi boundary range when segmentation switches to 10 degrees
00841          // This still needs to be worked on to properly deal with boundaries
00842          for (int nD=-1*HENeighborParams_.DeltaDepth;nD<=HENeighborParams_.DeltaDepth;++nD)
00843            {
00844              for (int nP =-1*HEDeltaIphi;nP<=HEDeltaIphi;++nP)
00845                {
00846                  for (int nE =-1*HENeighborParams_.DeltaIeta;nE<=HENeighborParams_.DeltaIeta;++nE)
00847                    {
00848                      if (nD==0 && nE==0 && nP==0) 
00849                        continue; // don't count the cell itself
00850                      
00851                      int myphi=nP+iphi;
00852                      if (myphi>72) myphi-=72; // allow for wrapping of cells
00853                      if (myphi<=0) myphi+=72;
00854                      if (!validDetId((HcalSubdetector)(2),nE+ieta, myphi, nD+depth)) continue;
00855                      HcalDetId myid((HcalSubdetector)(2), nE+ieta, myphi, nD+depth); // HE
00856                      ++allneighbors;
00857                      if (rechitEnergies_.find(myid)==rechitEnergies_.end())
00858                        continue;
00859                      if (rechitEnergies_[myid]<HENeighborParams_.minNeighborEnergy)
00860                        continue;
00861                      ++cellsfound;
00862                      enNeighbor+=rechitEnergies_[myid];
00863                    } // loop over nE (neighbor eta)
00864                } // loop over nP (neighbor phi)
00865            } // loop over nD depths
00866 
00867          if (deadmon_makeDiagnostics_)
00868            d_HEenergyVsNeighbor->Fill(enNeighbor,en);
00869          
00870          // Case 1:  Not enough good neighbors found
00871          if (1.*cellsfound/allneighbors<HENeighborParams_.minGoodNeighborFrac)
00872            continue;
00873          // Case 2:  energy/(avg. neighbor energy) too large for cell to be considered dead
00874          if (1.*en/(enNeighbor/allneighbors)>HENeighborParams_.maxEnergyFrac)
00875            continue;
00876          // Case 3:  Tests passed; cell marked as dead
00877          ++belowneighbors[static_cast<int>(ieta+(etaBins_-2)/2)][iphi-1][depth-1];
00878        }
00879    } //for (HBHERecHitCollection::const_iterator HBHEiter=...)
00880 
00881  // loop over HO
00882  if (checkHO_)
00883    {
00884      for (HORecHitCollection::const_iterator HOiter=hoHits.begin(); HOiter!=hoHits.end(); ++HOiter) 
00885        { // loop over all hits
00886          float en = HOiter->energy();
00887          HcalDetId id(HOiter->detid().rawId());
00888          int ieta = id.ieta();
00889          int iphi = id.iphi();
00890          int depth = id.depth();
00891 
00892          // Search keys for neighboring cells
00893          if (en>HONeighborParams_.maxCellEnergy) // cells above maxCellEnergy not considered dead
00894            continue;
00895          allneighbors=0;
00896          cellsfound=0;
00897          enNeighbor=0;
00898          for (int nD=-1*HONeighborParams_.DeltaDepth;nD<=HONeighborParams_.DeltaDepth;++nD)
00899            {
00900              for (int nP =-1*HONeighborParams_.DeltaIphi;nP<=HONeighborParams_.DeltaIphi;++nP)
00901                {
00902                  for (int nE =-1*HONeighborParams_.DeltaIeta;nE<=HONeighborParams_.DeltaIeta;++nE)
00903                    {
00904                      if (nD==0 && nE==0 && nP==0) 
00905                        continue; // don't count the cell itself
00906                      int myphi=nP+iphi;
00907                      if (myphi>72) myphi-=72; // allow for wrapping of cells
00908                      if (myphi<=0) myphi+=72;
00909                      if (!validDetId((HcalSubdetector)(3),nE+ieta, myphi, nD+depth)) continue;
00910                      HcalDetId myid((HcalSubdetector)(3), nE+ieta, myphi, nD+depth); // HO
00911                      ++allneighbors;
00912                      if (rechitEnergies_.find(myid)==rechitEnergies_.end())
00913                        continue;
00914                      if (rechitEnergies_[myid]<HONeighborParams_.minNeighborEnergy)
00915                        continue;
00916                      ++cellsfound;
00917                      enNeighbor+=rechitEnergies_[myid];
00918                    } // loop over nE (neighbor eta)
00919                } // loop over nP (neighbor phi)
00920            } // loop over nD depths
00921 
00922          if (deadmon_makeDiagnostics_)
00923            d_HOenergyVsNeighbor->Fill(enNeighbor,en);
00924          
00925          // Case 1:  Not enough good neighbors found
00926          if (1.*cellsfound/allneighbors<HONeighborParams_.minGoodNeighborFrac)
00927            continue;
00928          // Case 2:  energy/(avg. neighbor energy) too large for cell to be considered dead
00929          if (1.*en/(enNeighbor/allneighbors)>HONeighborParams_.maxEnergyFrac)
00930            continue;
00931          // Case 3:  Tests passed; cell marked as dead
00932          ++belowneighbors[static_cast<int>(ieta+(etaBins_-2)/2)][iphi-1][depth-1];
00933        }
00934    } // if (checkHO_)
00935  
00936  // loop over HF
00937  if (checkHF_)
00938    {
00939      for (HFRecHitCollection::const_iterator HFiter=hfHits.begin(); HFiter!=hfHits.end(); ++HFiter) 
00940        { // loop over all hits
00941          float en = HFiter->energy();
00942          HcalDetId id(HFiter->detid().rawId());
00943          int ieta = id.ieta();
00944          int iphi = id.iphi();
00945          int depth = id.depth();
00946 
00947           // Search keys for neighboring cells
00948          if (en>HFNeighborParams_.maxCellEnergy) // cells above maxCellEnergy not considered dead
00949            continue;
00950          allneighbors=0;
00951          cellsfound=0;
00952          enNeighbor=0;
00953          int HFDeltaIphi = HFNeighborParams_.DeltaIphi;
00954          if (abs(ieta)>39) HFDeltaIphi*=2;  // double phi range when segmentation switches to 20 degrees
00955          // Still need to create a more robust handling of boundary cases
00956          for (int nD=-1*HFNeighborParams_.DeltaDepth;nD<=HFNeighborParams_.DeltaDepth;++nD)
00957            {
00958              for (int nP =-1*HFDeltaIphi;nP<=HFDeltaIphi;++nP)
00959                {
00960                  for (int nE =-1*HFNeighborParams_.DeltaIeta;nE<=HFNeighborParams_.DeltaIeta;++nE)
00961                    {
00962                      if (nD==0 && nE==0 && nP==0) 
00963                        continue; // don't count the cell itself
00964                      int myphi=nP+iphi;
00965                      if (myphi>72) myphi-=72; // allow for wrapping of cells
00966                      if (myphi<=0) myphi+=72;
00967                      if (!validDetId((HcalSubdetector)(4),nE+ieta, myphi, nD+depth)) continue;
00968                      HcalDetId myid((HcalSubdetector)(4), nE+ieta, myphi, nD+depth); // HF
00969                      
00970                      ++allneighbors;
00971                      if (rechitEnergies_.find(myid)==rechitEnergies_.end())
00972                        continue;
00973                      if (rechitEnergies_[myid]<HFNeighborParams_.minNeighborEnergy)
00974                        continue;
00975                      ++cellsfound;
00976                      enNeighbor+=rechitEnergies_[myid];
00977                    } // loop over nE (neighbor eta)
00978                } // loop over nP (neighbor phi)
00979            } // loop over nD depths
00980 
00981          if (deadmon_makeDiagnostics_)
00982            d_HFenergyVsNeighbor->Fill(enNeighbor,en);
00983          
00984          // Case 1:  Not enough good neighbors found
00985          if (1.*cellsfound/allneighbors<HFNeighborParams_.minGoodNeighborFrac)
00986            continue;
00987          // Case 2:  energy/(avg. neighbor energy) too large for cell to be considered dead
00988          if (1.*en/(enNeighbor/allneighbors)>HFNeighborParams_.maxEnergyFrac)
00989            continue;
00990          // Case 3:  Tests passed; cell marked as dead
00991          // remember that HF gets shifted up by 2 in depth
00992          ++belowneighbors[static_cast<int>(ieta+(etaBins_-2)/2)][iphi-1][depth+1];
00993        }
00994    } // if (checkHF_)
00995  
00996  
00997  // Fill histograms 
00998   if (ievt_%deadmon_checkNevents_neighbor_==0)
00999     {
01000         if (fVerbosity>1) cout <<"<HcalDeadCellMonitor::processEvent_rechitneighbor> Filling DeadCell Neighbor plots"<<endl;
01001         fillNevents_neighbor();
01002     }
01003 
01004  if (showTiming)
01005    {
01006      cpu_timer.stop();  cout <<"TIMER:: HcalDeadCellMonitor PROCESSEVENT_RECHITNEIGHBOR -> "<<cpu_timer.cpuTime()<<endl;
01007    }
01008  return;
01009 } // void HcalDeadCellMonitor::processEvent_rechitneighbor
01010 
01011 
01012 /* --------------------------------------- */
01013 
01014 
01015 void HcalDeadCellMonitor::processEvent_digi( const HBHEDigiCollection& hbhedigi,
01016                                              const HODigiCollection& hodigi,
01017                                              const HFDigiCollection& hfdigi,
01018                                              //const ZDCDigiCollection& zdcdigi, 
01019                                              const HcalDbService& cond
01020                                              )
01021 {
01022   
01023   if (showTiming)
01024     {
01025       cpu_timer.reset(); cpu_timer.start();
01026     }
01027 
01028   if (fVerbosity>1) cout <<"<HcalDeadCellMonitor::processEvent_digi> Processing digis..."<<endl;
01029 
01030   // Variables used in pedestal check
01031   float digival=0;
01032   float maxval=0;
01033   int maxbin=0;
01034   float ADCsum=0;
01035 
01036   // Variables used in occupancy check
01037   int ieta=0;
01038   int iphi=0;
01039   int depth=0;
01040 
01041   HcalCalibrationWidths widths;
01042   HcalCalibrations calibs;
01043   const HcalQIEShape* shape=cond.getHcalShape();
01044 
01045   // Loop over HBHE digis
01046 
01047   if (fVerbosity>1) cout <<"<HcalDeadCellMonitor::processEvent_digi> Processing HBHE..."<<endl;
01048 
01049   for (HBHEDigiCollection::const_iterator j=hbhedigi.begin();
01050        j!=hbhedigi.end(); ++j)
01051     {
01052       digival=0;
01053       maxval=0;
01054       maxbin=0;
01055       ADCsum=0;
01056       const HBHEDataFrame digi = (const HBHEDataFrame)(*j);
01057       if ((HcalSubdetector)(digi.id().subdet())==HcalBarrel)
01058         {
01059           HBpresent_=true;
01060           if (!checkHB_)
01061             continue;
01062         }
01063       else 
01064         {
01065           HEpresent_=true;
01066           if (!checkHE_)
01067             continue;
01068         }
01069       ieta=digi.id().ieta();
01070       iphi=digi.id().iphi();
01071       depth=digi.id().depth();
01072 
01073       ++occupancy[static_cast<int>(ieta+(etaBins_-2)/2)][iphi-1][depth-1];
01074 
01075       if (!deadmon_test_pedestal_)
01076         continue;
01077       
01078       HcalDetId myid = digi.id();
01079       cond.makeHcalCalibrationWidth(digi.id(),&widths);
01080       //const HcalCalibrationWidths widths = cond.getHcalCalibrationWidths(digi.id() );
01081 
01082       calibs = cond.getHcalCalibrations(digi.id());
01083 
01084       // Find digi time slice with maximum (pedestal-subtracted) ADC count
01085       for (int i=0;i<digi.size();++i)
01086         {
01087           int thisCapid = digi.sample(i).capid();
01088           if (doFCpeds_)
01089             {
01090               const HcalQIECoder* coder  = cond.getHcalCoder(digi.id());
01091               digival = coder->charge(*shape,digi.sample(i).adc(),digi.sample(i).capid())-calibs.pedestal(thisCapid);
01092             }
01093           else
01094             digival=digi.sample(i).adc()-calibs.pedestal(thisCapid);
01095           
01096           // Find maximum pedestal-subtracted digi value
01097           if (digival>maxval)
01098             {
01099               maxval=digival;
01100               maxbin=i;
01101             }
01102         } // for (int i=0;i<digi.size();++i)
01103       
01104       // We'll assume steeply-peaked distribution, so that charge deposit occurs
01105       // in slices (i-1) -> (i+2) around maximum deposit time i
01106       
01107       int bins=0;
01108       for (int i=max(0,maxbin-1);i<=min(digi.size()-1,maxbin+2);++i)
01109         {
01110           ADCsum+=digi.sample(i).adc();
01111           ++bins;
01112         } // for (int i=max(0,maxbin-1);...)      
01113 
01114       // Compare ADCsum to minimum expected value (pedestal+nsigma)
01115       // we want to compare the average over the sum to the average (ped+nsigma)
01116       ADCsum*=1./bins;
01117 
01118       // Search for digi in map of pedestal+threshold values
01119       if (pedestal_thresholds_.find(myid)!=pedestal_thresholds_.end())
01120         {
01121           if (ADCsum >= pedestal_thresholds_[myid])
01122             ++abovepedestal[static_cast<int>(ieta+(etaBins_-2)/2)][iphi-1][depth-1];
01123           if (deadmon_makeDiagnostics_)
01124             {
01125               if (widths_[myid]==0) continue;
01126 
01127               if (myid.subdet()==HcalBarrel)
01128                 d_HBnormped->Fill(1.*(ADCsum-pedestals_[myid])/widths_[myid]);
01129               else
01130                 d_HEnormped->Fill(1.*(ADCsum-pedestals_[myid])/widths_[myid]);
01131             } // if (deadmon_makeDiagnostics)
01132         }
01133       else if (ADCsum>0) // if pedestal can't be found, just make sure ADC counts are non-zero
01134         ++abovepedestal[static_cast<int>(ieta+(etaBins_-2)/2)][iphi-1][depth-1];
01135     } // for (HBHEDigiCollection...)
01136 
01137   // Loop over HO
01138   if (checkHO_)
01139     {
01140       if (fVerbosity>1) cout <<"<HcalDeadCellMonitor::processEvent_digi> Processing HO..."<<endl;
01141       
01142       for (HODigiCollection::const_iterator j=hodigi.begin();
01143            j!=hodigi.end(); ++j)
01144         {
01145           digival=0;
01146           maxval=0;
01147           maxbin=0;
01148           ADCsum=0;
01149           const HODataFrame digi = (const HODataFrame)(*j);
01150           
01151           ieta=digi.id().ieta();
01152           iphi=digi.id().iphi();
01153           depth=digi.id().depth();
01154           
01155           //if (deadmon_test_occupancy_) // do this for every digi?  Or just ignore occupancy array when filling histos?
01156           ++occupancy[static_cast<int>(ieta+(etaBins_-2)/2)][iphi-1][depth-1];
01157           
01158           if (!deadmon_test_pedestal_)
01159             continue;
01160           
01161           HcalDetId myid = digi.id();
01162           //const HcalCalibrationWidths widths = cond.getHcalCalibrationWidths(digi.id() );
01163           cond.makeHcalCalibrationWidth(digi.id(),&widths);
01164 
01165           calibs = cond.getHcalCalibrations(digi.id());
01166           
01167           for (int i=0;i<digi.size();++i)
01168             {
01169               int thisCapid = digi.sample(i).capid();
01170               if (doFCpeds_)
01171                 {
01172                   const HcalQIECoder* coder  = cond.getHcalCoder(digi.id());
01173                   digival = coder->charge(*shape,digi.sample(i).adc(),digi.sample(i).capid())-calibs.pedestal(thisCapid);
01174                 }
01175               else
01176                 digival=digi.sample(i).adc()-calibs.pedestal(thisCapid);
01177           
01178               // Find maximum pedestal-subtracted digi value
01179               if (digival>maxval)
01180                 {
01181                   maxval=digival;
01182                   maxbin=i;
01183                 }
01184             } // for (int i=0;i<digi.size();++i)
01185       
01186           // We'll assume steeply-peaked distribution, so that charge deposit occurs
01187           // in slices (i-1) -> (i+2) around maximum deposit time i
01188       
01189           int bins=0;
01190           for (int i=max(0,maxbin-1);i<=min(digi.size()-1,maxbin+2);++i)
01191             {
01192               ADCsum+=digi.sample(i).adc();
01193               ++bins;
01194             } // for (int i=max(0,maxbin-1);...)      
01195           
01196           ADCsum*=1./bins;
01197           // Search for digi in map of pedestal+threshold values
01198           if (pedestal_thresholds_.find(myid)!=pedestal_thresholds_.end())
01199             {
01200               if (ADCsum >= pedestal_thresholds_[myid])
01201                 ++abovepedestal[static_cast<int>(ieta+(etaBins_-2)/2)][iphi-1][depth-1];
01202               if (deadmon_makeDiagnostics_)
01203                 {
01204                   if (widths_[myid]==0) continue;
01205                   d_HOnormped->Fill(1.*(ADCsum-pedestals_[myid])/widths_[myid]);
01206                 } // if (deadmon_makeDiagnostics)
01207             }
01208           else if (ADCsum>0)
01209             ++abovepedestal[static_cast<int>(ieta+(etaBins_-2)/2)][iphi-1][depth-1];
01210 
01211         } // for (HODigiCollection...)
01212     } // if (checkHO_)
01213 
01214   if (checkHF_)
01215     {
01216       // Loop over HF
01217       if (fVerbosity>1) cout <<"<HcalDeadCellMonitor::processEvent_digi> Processing HF..."<<endl;
01218 
01219       for (HFDigiCollection::const_iterator j=hfdigi.begin();
01220            j!=hfdigi.end(); ++j)
01221         {
01222           digival=0;
01223           maxval=0;
01224           maxbin=0;
01225           ADCsum=0;
01226           const HFDataFrame digi = (const HFDataFrame)(*j);
01227 
01228           ieta=digi.id().ieta();
01229           iphi=digi.id().iphi();
01230           depth=digi.id().depth()+2; // offset depth by 2 for HF
01231 
01232           //if (deadmon_test_occupancy_) // do this for every digi?  Or just ignore occupancy array when filling histos?
01233           ++occupancy[static_cast<int>(ieta+(etaBins_-2)/2)][iphi-1][depth-1];
01234 
01235           if (!deadmon_test_pedestal_)
01236             continue;
01237       
01238           HcalDetId myid = digi.id();
01239           //const HcalCalibrationWidths widths = cond.getHcalCalibrationWidths(digi.id() );
01240           cond.makeHcalCalibrationWidth(digi.id(),&widths);
01241           calibs = cond.getHcalCalibrations(digi.id());
01242 
01243           for (int i=0;i<digi.size();++i)
01244             {
01245               int thisCapid = digi.sample(i).capid();
01246               if (doFCpeds_)
01247                 {
01248                   const HcalQIECoder* coder  = cond.getHcalCoder(digi.id());
01249                   digival = coder->charge(*shape,digi.sample(i).adc(),digi.sample(i).capid())-calibs.pedestal(thisCapid);
01250                 }
01251               else
01252                 digival=digi.sample(i).adc()-calibs.pedestal(thisCapid);
01253           
01254               // Find maximum pedestal-subtracted digi value
01255               if (digival>maxval)
01256                 {
01257                   maxval=digival;
01258                   maxbin=i;
01259                 }
01260             } // for (int i=0;i<digi.size();++i)
01261       
01262           // We'll assume steeply-peaked distribution, so that charge deposit occurs
01263           // in slices (i-1) -> (i+2) around maximum deposit time i
01264       
01265           int bins=0;
01266           for (int i=max(0,maxbin-1);i<=min(digi.size()-1,maxbin+2);++i)
01267             {
01268               ADCsum+=digi.sample(i).adc();
01269               ++bins;
01270             } // for (int i=max(0,maxbin-1);...)      
01271 
01272           ADCsum*=1./bins;
01273           // Search for digi in map of pedestal+threshold values
01274           if (pedestal_thresholds_.find(myid)!=pedestal_thresholds_.end())
01275             {
01276               if (ADCsum >= pedestal_thresholds_[myid])
01277                 ++abovepedestal[static_cast<int>(ieta+(etaBins_-2)/2)][iphi-1][depth-1];
01278               if (deadmon_makeDiagnostics_)
01279                 {
01280                   if (widths_[myid]==0) continue;
01281                   d_HFnormped->Fill(1.*(ADCsum-pedestals_[myid])/widths_[myid]);
01282                 } // if (deadmon_makeDiagnostics)
01283             }
01284           else if (ADCsum>0)
01285             ++abovepedestal[static_cast<int>(ieta+(etaBins_-2)/2)][iphi-1][depth-1];
01286 
01287         } // for (HFDigiCollection...)
01288     } // if (checkHF_)
01289 
01290   // Fill histograms 
01291   if (ievt_%deadmon_checkNevents_occupancy_==0)
01292     {
01293     if (deadmon_test_occupancy_)
01294       {
01295         if (fVerbosity>1) cout <<"<HcalDeadCellMonitor::processEvent_digi> Filling DeadCell Occupancy plots"<<endl;
01296         fillNevents_occupancy();
01297       }
01298     }
01299 
01300   if (ievt_%deadmon_checkNevents_pedestal_==0)
01301     {
01302       if( deadmon_test_pedestal_)
01303         {
01304           if (fVerbosity>1) cout <<"<HcalDeadCellMonitor::processEvent_digi> Filling DeadCell Pedestal plots"<<endl;
01305           fillNevents_pedestal();
01306         }
01307     }
01308 
01309    if (showTiming)
01310     {
01311       cpu_timer.stop();  cout <<"TIMER:: HcalDeadCellMonitor PROCESSEVENT_DIGI -> "<<cpu_timer.cpuTime()<<endl;
01312     }
01313 
01314   return;
01315 } // void HcalDeadCellMonitor::processEvent_digi
01316 
01317 
01318 /* ----------------------------------- */
01319 
01320 void HcalDeadCellMonitor::fillNevents_occupancy(void)
01321 {
01322   // Fill Histograms showing digi cells with no occupancy
01323 
01324   if (showTiming)
01325     {
01326       cpu_timer.reset(); cpu_timer.start();
01327     }
01328 
01329   if (fVerbosity>0)
01330     cout <<"<HcalDeadCellMonitor::fillNevents_occupancy> FILLING OCCUPANCY PLOTS"<<endl;
01331 
01332   int mydepth=0;
01333   int ieta=0;
01334   int iphi=0;
01335   for (int eta=0;eta<(etaBins_-2);++eta)
01336     {
01337       ieta=eta-int((etaBins_-2)/2);
01338       for (int phi=0;phi<72;++phi)
01339         {
01340           iphi=phi+1;
01341           for (int depth=0;depth<4;++depth) // this is one unit less "true" depth (for indexing purposes)
01342             {
01343               for (int subdet=1;subdet<=4;++subdet)
01344                 {
01345                   if (!validDetId((HcalSubdetector)subdet, ieta, iphi, depth+1))
01346                     continue;
01347                   // Ignore subdetectors that weren't in run
01348                   if ((subdet==1 && !HBpresent_) || (subdet==2 &&!HEpresent_)||(subdet==3 &&!HOpresent_) || (subdet==4 &&!HFpresent_)) continue;
01349                   // ignore subdetectors we explicitly mask off 
01350                   if ((!checkHB_ && subdet==1) ||
01351                       (!checkHE_ && subdet==2) ||
01352                       (!checkHO_ && subdet==3) ||
01353                       (!checkHF_ && subdet==4)) continue;
01354                   mydepth=depth;
01355                   if (subdet==4) // remember that HF's elements stored in depths (2,3), not (0,1)
01356                     mydepth=depth+2;
01357                   if (occupancy[eta][phi][mydepth]==0)
01358                     {
01359                       if (fVerbosity>0) cout <<"DEAD CELL; NO OCCUPANCY = "<<subdet<<" eta = "<<ieta<<", phi = "<<iphi<<" depth = "<<depth+1<<endl;
01360                       if (subdet==2 && depth<2) // HE depth positions(0,1) found -- shift up to positions (4,5)
01361                         mydepth=depth+4;
01362                       else
01363                         mydepth=depth; // switches back HF to its correct depth
01364                       // no digi was found for the N events; set histogram error rate
01365                       int oldevts=(ievt_/deadmon_checkNevents_occupancy_);
01366                       if (ievt_%deadmon_checkNevents_occupancy_==0)
01367                         oldevts-=1;
01368                       oldevts*=deadmon_checkNevents_occupancy_;
01369                       int newevts=ievt_-oldevts;
01370                       if (newevts<0) newevts=0;
01371                       if (fVerbosity>2)
01372                         {
01373                           cout <<"\t MYDEPTH = "<<mydepth<<endl;
01374                           cout <<"\t oldevents = "<<oldevts<<"  new = "<<newevts<<endl;
01375                           cout <<"\t\t"<<(oldevts*UnoccupiedDeadCellsByDepth[mydepth]->getBinContent(eta+2,phi+2)+newevts)*1./ievt_<<endl;
01376                         }
01377                       // BinContent starts at 1, not 0 (offset by 0)
01378                       // Offset by another 1 due to empty bins at edges
01379                       UnoccupiedDeadCellsByDepth[mydepth]->setBinContent( eta+2,phi+2,
01380                                                                           (oldevts*UnoccupiedDeadCellsByDepth[mydepth]->getBinContent(eta+2,phi+2)+newevts)*1./ievt_);
01381                     }
01382                   else //reset counter
01383                     occupancy[eta][phi][depth]=0;
01384                 } // for (int subdet=1;subdet<=4;++subdet)
01385 
01386             } // for (int depth=0;depth<4;++depth)
01387         } // for (int phi=0;...)
01388     } // for (int eta=0;...)
01389   FillUnphysicalHEHFBins(UnoccupiedDeadCellsByDepth);
01390   if (showTiming)
01391     {
01392       cpu_timer.stop();  cout <<"TIMER:: HcalDeadCellMonitor FILLNEVENTS_OCCUPANCY -> "<<cpu_timer.cpuTime()<<endl;
01393     }
01394 
01395   return;
01396 
01397 
01398 } // void HcalDeadCellMonitor::fillNevents_occupancy(void)
01399 
01400 
01401 
01402 
01403 /* ----------------------------------- */
01404 
01405 void HcalDeadCellMonitor::fillNevents_pedestal(void)
01406 {
01407   // Fill Histograms showing digi cells below pedestal values
01408 
01409   if (showTiming)
01410     {
01411       cpu_timer.reset(); cpu_timer.start();
01412     }
01413 
01414   if (fVerbosity>0)
01415     cout <<"<HcalDeadCellMonitor::fillNevents_pedestal> FILLING OCCUPANCY PLOTS"<<endl;
01416 
01417   int mydepth=0;
01418   int ieta=0;
01419   int iphi=0;
01420   for (int eta=0;eta<(etaBins_-2);++eta)
01421     {
01422       ieta=eta-int((etaBins_-2)/2);
01423       for (int phi=0;phi<72;++phi)
01424         {
01425           iphi=phi+1;
01426           for (int depth=0;depth<4;++depth) // this is one unit less "true" depth (for indexing purposes)
01427             {
01428               for (int subdet=1;subdet<=4;++subdet)
01429                 {
01430                   if (!validDetId((HcalSubdetector)subdet, ieta, iphi, depth+1))
01431                     continue;
01432                   // Ignore subdetectors that weren't in run
01433                   if ((subdet==1 && !HBpresent_) || (subdet==2 &&!HEpresent_)||(subdet==3 &&!HOpresent_) || (subdet==4 &&!HFpresent_)) continue;
01434                   
01435                   if ((!checkHB_ && subdet==1) ||
01436                       (!checkHE_ && subdet==2) ||
01437                       (!checkHO_ && subdet==3) ||
01438                       (!checkHF_ && subdet==4)) continue;
01439                   
01440                   if (occupancy[eta][phi][mydepth]==0)
01441                     {
01442                       abovepedestal[eta][phi][mydepth]=0; // reset counter (shouldn't be necessary)
01443                       continue; // no cell found; it gets flagged as bad in occupancy tests, so don't check it here as well
01444                     }
01445                   int oldevts=(ievt_/deadmon_checkNevents_pedestal_);
01446                   if (ievt_%deadmon_checkNevents_pedestal_==0)
01447                     oldevts-=1;
01448                   oldevts*=deadmon_checkNevents_pedestal_;
01449                   int newevts=ievt_-oldevts;
01450                   if (newevts<0) newevts=0; // shouldn't happen
01451 
01452                   mydepth=depth;
01453                   if (subdet==4) // remember that HF's elements stored in depths (2,3), not (0,1)
01454                     mydepth=depth+2;
01455 
01456                   // Now that we have a valid cell, check whether it was ever above the pedestal threshold
01457                   if (abovepedestal[eta][phi][mydepth]>0)
01458                     {
01459                       abovepedestal[eta][phi][mydepth]=0;
01460                       continue; // cell was above pedestal threshold at least once; ignore it
01461                     }
01462 
01463 
01464                   if (fVerbosity>0) cout <<"DEAD CELL; BELOW PEDESTAL THRESHOLD = "<<subdet<<" eta = "<<ieta<<", phi = "<<iphi<<" depth = "<<depth+1<<endl;
01465                   if (subdet==2 && depth<2) // HE depth positions(0,1) found -- shift up to positions (4,5)
01466                     mydepth=depth+4;
01467                   else
01468                     mydepth=depth; // switches back HF to its correct depth
01469                   // no digi was found for the N events; set histogram error rate
01470                   
01471                   if (fVerbosity>0)
01472                     {
01473                       cout <<"\t MYDEPTH = "<<mydepth<<endl;
01474                       cout <<"\t oldevents = "<<oldevts<<"  new = "<<newevts<<endl;
01475                       cout <<"\t\t"<<(oldevts*BelowPedestalDeadCellsByDepth[mydepth]->getBinContent(eta+2,phi+2)+newevts)*1./ievt_<<endl;
01476                     }
01477                   // BinContent starts at 1, not 0 (offset by 0)
01478                   // Offset by another 1 due to empty bins at edges
01479                   BelowPedestalDeadCellsByDepth[mydepth]->setBinContent( eta+2,phi+2,
01480                                                                          (oldevts*BelowPedestalDeadCellsByDepth[mydepth]->getBinContent(eta+2,phi+2)+newevts)*1./ievt_);
01481                   //reset counter -- shouldn't be necessary (counter should already be 0).
01482                   abovepedestal[eta][phi][depth]=0;
01483                 } // for (int subdet=1;subdet<=4;++subdet)
01484               
01485             } // for (int depth=0;depth<4;++depth)
01486         } // for (int phi=0;...)
01487     } // for (int eta=0;...)
01488   FillUnphysicalHEHFBins(BelowPedestalDeadCellsByDepth);
01489   if (showTiming)
01490     {
01491       cpu_timer.stop();  cout <<"TIMER:: HcalDeadCellMonitor FILLNEVENTS_BELOWPEDESTAL -> "<<cpu_timer.cpuTime()<<endl;
01492     }
01493 
01494   return;
01495 
01496 
01497 } // void HcalDeadCellMonitor::fillNevents_pedestal(void)
01498 
01499 
01500 /* ----------------------------------- */
01501 
01502 void HcalDeadCellMonitor::fillNevents_energy(void)
01503 {
01504   // Fill Histograms showing rec hits with low energy
01505 
01506   if (showTiming)
01507     {
01508       cpu_timer.reset(); cpu_timer.start();
01509     }
01510 
01511   if (fVerbosity>0)
01512     cout <<"<HcalDeadCellMonitor::fillNevents_energy> BELOW-ENERGY-THRESHOLD PLOTS"<<endl;
01513 
01514   int mydepth=0;
01515   int ieta=0;
01516   int iphi=0;
01517   for (int eta=0;eta<(etaBins_-2);++eta)
01518     {
01519       ieta=eta-int((etaBins_-2)/2);
01520       for (int phi=0;phi<72;++phi)
01521         {
01522           iphi=phi+1;
01523           for (int depth=0;depth<4;++depth) // this is one unit less "true" depth (for indexing purposes)
01524             {
01525               for (int subdet=1;subdet<=4;++subdet)
01526                 {
01527                   if (!validDetId((HcalSubdetector)subdet, ieta, iphi, depth+1))
01528                     continue;
01529                   // Ignore subdetectors that weren't in run
01530                   if ((subdet==1 && !HBpresent_) || (subdet==2 &&!HEpresent_)||(subdet==3 &&!HOpresent_) || (subdet==4 &&!HFpresent_)) continue;
01531 
01532                   if ((!checkHB_ && subdet==1) ||
01533                       (!checkHE_ && subdet==2) ||
01534                       (!checkHO_ && subdet==3) ||
01535                       (!checkHF_ && subdet==4)) continue;
01536                   mydepth=depth;
01537                   if (subdet==4) // remember that HF's elements stored in depths (2,3), not (0,1)
01538                     mydepth=depth+2;
01539                   
01540 
01541                   // Allow for case when we perform check at end of run, so that ievt_%checkNevents != 0 ?
01542                   
01543                   int oldevts=(ievt_/deadmon_checkNevents_pedestal_);
01544                   if (ievt_%deadmon_checkNevents_pedestal_==0)
01545                     oldevts-=1;
01546                   oldevts*=deadmon_checkNevents_pedestal_;
01547                   int newevts=ievt_-oldevts;
01548                   if (newevts<0) newevts=0; // shouldn't happen
01549                   if (rechit_occupancy[eta][phi][mydepth]==0 && deadmon_test_rechit_occupancy_) // no rechits found; ignore energy test
01550                     {
01551                       int filldepth=depth;
01552                       if (subdet==2 && depth<2) filldepth+=4;
01553                       UnoccupiedRecHitsByDepth[filldepth]->setBinContent( eta+2,phi+2,
01554                                                                         (oldevts*UnoccupiedRecHitsByDepth[filldepth]->getBinContent(eta+2,phi+2)+newevts)*1./ievt_);
01555                       aboveenergy[eta][phi][mydepth]=0; // shouldn't be necessary
01556                       continue;
01557                     }
01558 
01559                   if (!deadmon_test_energy_) continue;
01560                   if (aboveenergy[eta][phi][mydepth]>0)
01561                     {
01562                       // Cell exceeded energy threshold at least once in this pass;  ignore it and reset counter
01563                       aboveenergy[eta][phi][mydepth]=0;
01564                       continue;
01565                     }
01566 
01567                   if (fVerbosity>2) 
01568                     cout <<"DEAD CELL; BELOW ENERGY THRESHOLD = "<<subdet<<" eta = "<<ieta<<", phi = "<<iphi<<" depth = "<<depth+1<<endl;
01569                   if (subdet==2 && depth<2) // HE depth positions(0,1) found -- shift up to positions (4,5)
01570                     mydepth=depth+4;
01571                   else
01572                     mydepth=depth; // switches back HF to its correct depth
01573                   
01574                   // Cell is below energy for all 'newevts' consecutive events; update histogram
01575                   // BinContent starts at 1, not 0 (offset by 0)
01576                   // Offset by another 1 due to empty bins at edges
01577                   
01578                   BelowEnergyThresholdCellsByDepth[mydepth]->setBinContent( eta+2,phi+2,
01579                                                                             (oldevts*BelowEnergyThresholdCellsByDepth[mydepth]->getBinContent(eta+2,phi+2)+newevts)*1./ievt_);
01580                 } // for (int subdet=1;subdet<=4;++subdet)
01581               // reset counters
01582               aboveenergy[eta][phi][depth]=0;
01583               rechit_occupancy[eta][phi][depth]=0;
01584             } // for (int depth=0;depth<4;++depth)
01585         } // for (int phi=0;...)
01586     } // for (int eta=0;...)
01587     FillUnphysicalHEHFBins(UnoccupiedRecHitsByDepth);
01588     FillUnphysicalHEHFBins(BelowEnergyThresholdCellsByDepth);
01589   if (showTiming)
01590     {
01591       cpu_timer.stop();  cout <<"TIMER:: HcalDeadCellMonitor FILLNEVENTS_ENERGY -> "<<cpu_timer.cpuTime()<<endl;
01592     }
01593 
01594   return;
01595 
01596 
01597 } // void HcalDeadCellMonitor::fillNevents_energy(void)
01598 
01599 
01600 
01601 /* ----------------------------------- */
01602 
01603 void HcalDeadCellMonitor::fillNevents_neighbor(void)
01604 {
01605   // Fill Histograms showing rec hits with energy much less than neighbors' average
01606 
01607   if (showTiming)
01608     {
01609       cpu_timer.reset(); cpu_timer.start();
01610     }
01611 
01612   if (fVerbosity>0)
01613     cout <<"<HcalDeadCellMonitor::fillNevents_neighbor> FILLING BELOW-NEIGHBOR-ENERGY PLOTS"<<endl;
01614 
01615   int mydepth=0;
01616   int ieta=0;
01617   int iphi=0;
01618   for (int eta=0;eta<(etaBins_-2);++eta)
01619     {
01620       ieta=eta-int((etaBins_-2)/2);
01621       for (int phi=0;phi<72;++phi)
01622         {
01623           iphi=phi+1;
01624           for (int depth=0;depth<4;++depth) // this is one unit less "true" depth (for indexing purposes)
01625             {
01626               for (int subdet=1;subdet<=4;++subdet)
01627                 {
01628                   if (!validDetId((HcalSubdetector)subdet, ieta, iphi, depth+1))
01629                     continue;
01630                   // Ignore subdetectors that weren't in run
01631                   if ((subdet==1 && !HBpresent_) || (subdet==2 &&!HEpresent_)||(subdet==3 &&!HOpresent_) || (subdet==4 &&!HFpresent_)) continue;
01632                   if ((!checkHB_ && subdet==1) ||
01633                       (!checkHE_ && subdet==2) ||
01634                       (!checkHO_ && subdet==3) ||
01635                       (!checkHF_ && subdet==4)) continue;
01636                   mydepth=depth;
01637                   if (subdet==4) // remember that HF's elements stored in depths (2,3), not (0,1)
01638                     mydepth=depth+2;
01639                   if (rechit_occupancy[eta][phi][mydepth]==0) // no rechits found; ignore test
01640                     {
01641                       belowneighbors[eta][phi][mydepth]=0; // shouldn't be necessary
01642                       continue;
01643                     }
01644                   if (belowneighbors[eta][phi][mydepth]>0)
01645                     {
01646                       if (fVerbosity>2) cout <<"DEAD CELL; BELOW NEIGHBORS = "<<subdet<<" eta = "<<ieta<<", phi = "<<iphi<<" depth = "<<depth+1<<endl;
01647                       if (subdet==2 && depth<2) // HE depth positions(0,1) found -- shift up to positions (4,5)
01648                         mydepth=depth+4;
01649                       else
01650                         mydepth=depth; // switches back HF to its correct depth
01651                       // no digi was found for the N events; set histogram error rate
01652                       int oldevts=(ievt_/deadmon_checkNevents_neighbor_);
01653                       if (ievt_%deadmon_checkNevents_neighbor_==0)
01654                         oldevts-=1;
01655                       oldevts*=deadmon_checkNevents_neighbor_;
01656                       // BinContent starts at 1, not 0 (offset by 0)
01657                       // Offset by another 1 due to empty bins at edges
01658                       BelowNeighborsDeadCellsByDepth[mydepth]->setBinContent( eta+2,phi+2,
01659                                                                           (oldevts*BelowNeighborsDeadCellsByDepth[mydepth]->getBinContent(eta+2,phi+2)+belowneighbors[eta][phi][mydepth])*1./ievt_);
01660                       //reset counter
01661                       belowneighbors[eta][phi][depth]=0;
01662                     } // if (belowneighbors[eta][phi][mydepth]>0)
01663                 } // for (int subdet=1;subdet<=4;++subdet)
01664 
01665             } // for (int depth=0;depth<4;++depth)
01666         } // for (int phi=0;...)
01667     } // for (int eta=0;...)
01668   FillUnphysicalHEHFBins(BelowNeighborsDeadCellsByDepth);
01669   if (showTiming)
01670     {
01671       cpu_timer.stop();  cout <<"TIMER:: HcalDeadCellMonitor FILLNEVENTS_NEIGHBOR -> "<<cpu_timer.cpuTime()<<endl;
01672     }
01673 
01674   return;
01675 
01676 
01677 } // void HcalDeadCellMonitor::fillNevents_neighbor(void)
01678 
01679 
01680 
01681 
01682 
01683 
01684 void HcalDeadCellMonitor::fillNevents_problemCells(void)
01685 {
01686   if (showTiming)
01687     {
01688       cpu_timer.reset(); cpu_timer.start();
01689     }
01690 
01691   if (fVerbosity>0)
01692     cout <<"<HcalDeadCellMonitor::fillNevents_problemCells> FILLING PROBLEM CELL PLOTS"<<endl;
01693 
01694   int ieta=0;
01695   int iphi=0;
01696 
01697   double problemvalue=0;
01698   double sumproblemvalue=0; // summed over all depths
01699   for (int eta=0;eta<(etaBins_-2);++eta)
01700     {
01701       ieta=eta-int((etaBins_-2)/2);
01702       for (int phi=0;phi<72;++phi)
01703         {
01704           iphi=phi+1;
01705           sumproblemvalue=0;
01706           for (int mydepth=0;mydepth<6;++mydepth)
01707             {
01708               // total bad fraction is sum of fractions from individual tests
01709               // (eventually, do we want to be more careful about how we handle this, in case checkNevents is
01710               //  drastically different for the different tests?)
01711               problemvalue=0;
01712               if (deadmon_test_occupancy_)
01713                 {
01714                   problemvalue+=UnoccupiedDeadCellsByDepth[mydepth]->getBinContent(eta+2,phi+2);
01715                   sumproblemvalue+=UnoccupiedDeadCellsByDepth[mydepth]->getBinContent(eta+2,phi+2);
01716                 }
01717               if (deadmon_test_rechit_occupancy_)
01718                 {
01719                   problemvalue+=UnoccupiedRecHitsByDepth[mydepth]->getBinContent(eta+2,phi+2);
01720                   sumproblemvalue+=UnoccupiedRecHitsByDepth[mydepth]->getBinContent(eta+2,phi+2);
01721                 }
01722               if (deadmon_test_pedestal_)
01723                 {
01724                   problemvalue+=BelowPedestalDeadCellsByDepth[mydepth]->getBinContent(eta+2,phi+2);
01725                   sumproblemvalue+=BelowPedestalDeadCellsByDepth[mydepth]->getBinContent(eta+2,phi+2);
01726                 }
01727               if (deadmon_test_neighbor_)
01728                 {
01729                   problemvalue+=BelowNeighborsDeadCellsByDepth[mydepth]->getBinContent(eta+2,phi+2);
01730                   sumproblemvalue+=BelowNeighborsDeadCellsByDepth[mydepth]->getBinContent(eta+2,phi+2);
01731                 }
01732               if (deadmon_test_energy_)
01733                 {
01734                   problemvalue+=BelowEnergyThresholdCellsByDepth[mydepth]->getBinContent(eta+2,phi+2);
01735                   sumproblemvalue+=BelowEnergyThresholdCellsByDepth[mydepth]->getBinContent(eta+2,phi+2);
01736                 }
01737 
01738               problemvalue=min(1.,problemvalue);
01739               ProblemDeadCellsByDepth[mydepth]->setBinContent(eta+2,phi+2,problemvalue);
01740             } // for (int mydepth=0;mydepth<6;...)
01741           sumproblemvalue=min(1.,sumproblemvalue);
01742           ProblemDeadCells->setBinContent(eta+2,phi+2,sumproblemvalue);
01743         } // loop on phi=0;phi<72
01744     } // loop on eta=0; eta<(etaBins_-2)
01745   
01746   if (showTiming)
01747     {
01748       cpu_timer.stop();  cout <<"TIMER:: HcalDeadCellMonitor FILLNEVENTS_PROBLEMCELLS -> "<<cpu_timer.cpuTime()<<endl;
01749     }
01750 
01751 } // void HcalDeadCellMonitor::fillNevents_problemCells(void)

Generated on Tue Jun 9 17:33:01 2009 for CMSSW by  doxygen 1.5.4