CMS 3D CMS Logo

CMSSW_4_4_3_patch1/src/DQM/HcalMonitorTasks/src/HcalDigiMonitor.cc

Go to the documentation of this file.
00001 #include "DQM/HcalMonitorTasks/interface/HcalDigiMonitor.h"
00002 #include "EventFilter/HcalRawToDigi/interface/HcalDCCHeader.h"
00003 #include <cmath>
00004 
00005 #include "FWCore/Common/interface/TriggerNames.h" 
00006 #include "FWCore/Framework/interface/LuminosityBlock.h"
00007 #include "DataFormats/Common/interface/TriggerResults.h"
00008 #include "DataFormats/L1GlobalTrigger/interface/L1GlobalTriggerReadoutRecord.h"
00009 #include "DataFormats/HcalRecHit/interface/HcalRecHitCollections.h"
00010 #include "Geometry/HcalTowerAlgo/src/HcalHardcodeGeometryData.h" // for eta bounds
00011 #include "CondFormats/HcalObjects/interface/HcalChannelQuality.h"
00012 
00013 // constructor
00014 HcalDigiMonitor::HcalDigiMonitor(const edm::ParameterSet& ps) 
00015 {
00016   Online_                = ps.getUntrackedParameter<bool>("online",false);
00017   mergeRuns_             = ps.getUntrackedParameter<bool>("mergeRuns",false);
00018   enableCleanup_         = ps.getUntrackedParameter<bool>("enableCleanup",false);
00019   debug_                 = ps.getUntrackedParameter<int>("debug",0);
00020   prefixME_              = ps.getUntrackedParameter<std::string>("subSystemFolder","Hcal/");
00021   if (prefixME_.substr(prefixME_.size()-1,prefixME_.size())!="/")
00022     prefixME_.append("/");
00023   subdir_                = ps.getUntrackedParameter<std::string>("TaskFolder","DigiMonitor_Hcal"); 
00024   if (subdir_.size()>0 && subdir_.substr(subdir_.size()-1,subdir_.size())!="/")
00025     subdir_.append("/");
00026   subdir_=prefixME_+subdir_;
00027   AllowedCalibTypes_     = ps.getUntrackedParameter<std::vector<int> > ("AllowedCalibTypes");
00028   skipOutOfOrderLS_      = ps.getUntrackedParameter<bool>("skipOutOfOrderLS",true);
00029   NLumiBlocks_           = ps.getUntrackedParameter<int>("NLumiBlocks",4000);
00030   makeDiagnostics_       = ps.getUntrackedParameter<bool>("makeDiagnostics",false);
00031   digiLabel_             = ps.getUntrackedParameter<edm::InputTag>("digiLabel");
00032   hfRechitLabel_        = ps.getUntrackedParameter<edm::InputTag>("hfRechitLabel");
00033   shapeThresh_           = ps.getUntrackedParameter<int>("shapeThresh",20);
00034   //shapeThresh_ is used for plotting pulse shapes for all digis with pedestal-subtracted ADC sum > shapeThresh_;
00035   shapeThreshHB_ = ps.getUntrackedParameter<int>("shapeThreshHB",shapeThresh_);
00036   shapeThreshHE_ = ps.getUntrackedParameter<int>("shapeThreshHE",shapeThresh_);
00037   shapeThreshHF_ = ps.getUntrackedParameter<int>("shapeThreshHF",shapeThresh_);
00038   shapeThreshHO_ = ps.getUntrackedParameter<int>("shapeThreshHO",shapeThresh_);
00039   
00040   hltresultsLabel_       = ps.getUntrackedParameter<edm::InputTag>("HLTResultsLabel");
00041   MinBiasHLTBits_        = ps.getUntrackedParameter<std::vector<std::string> >("MinBiasHLTBits");
00042   excludeHORing2_       = ps.getUntrackedParameter<bool>("excludeHORing2",false);
00043   excludeHO1P02_        = ps.getUntrackedParameter<bool>("excludeHO1P02",false);
00044 
00045   if (debug_>0)
00046     std::cout <<"<HcalDigiMonitor> Digi shape ADC threshold set to: >" << shapeThresh_ <<" counts above nominal pedestal (3*10)"<< std::endl;
00047   
00048   // Specify which tests to run when looking for problem digis
00049   digi_checkoccupancy_ = ps.getUntrackedParameter<bool>("checkForMissingDigis",false); // off by default -- checked by dead cell monitor
00050   digi_checkcapid_     = ps.getUntrackedParameter<bool>("checkCapID",true);
00051   digi_checkdigisize_  = ps.getUntrackedParameter<bool>("checkDigiSize",true);
00052   digi_checkadcsum_    = ps.getUntrackedParameter<bool>("checkADCsum",true);
00053   digi_checkdverr_     = ps.getUntrackedParameter<bool>("checkDVerr",true);
00054   mindigisizeHBHE_     = ps.getUntrackedParameter<int>("minDigiSizeHBHE",1);
00055   maxdigisizeHBHE_     = ps.getUntrackedParameter<int>("maxDigiSizeHBHE",10);
00056   mindigisizeHO_       = ps.getUntrackedParameter<int>("minDigiSizeHO",1);
00057   maxdigisizeHO_       = ps.getUntrackedParameter<int>("maxDigiSizeHO",10);
00058   mindigisizeHF_       = ps.getUntrackedParameter<int>("minDigiSizeHF",1);
00059   maxdigisizeHF_       = ps.getUntrackedParameter<int>("maxDigiSizeHF",10);
00060 
00061 
00062   badChannelStatusMask_   = ps.getUntrackedParameter<int>("BadChannelStatusMask",
00063                                                           ps.getUntrackedParameter<int>("BadChannelStatusMask",
00064                                                                                         (1<<HcalChannelStatus::HcalCellDead)));  // identify channel status values to mask
00065   if (debug_>1)
00066     {
00067       std::cout <<"<HcalDigiMonitor> Checking for the following problems:"<<std::endl; 
00068       if (digi_checkcapid_) std::cout <<"\tChecking that cap ID rotation is correct;"<<std::endl;
00069       if (digi_checkdigisize_)
00070         {
00071           std::cout <<"\tChecking that HBHE digi size is between ["<<mindigisizeHBHE_<<" - "<<maxdigisizeHBHE_<<"];"<<std::endl;
00072           std::cout <<"\tChecking that HO digi size is between ["<<mindigisizeHO_<<" - "<<maxdigisizeHO_<<"];"<<std::endl;
00073           std::cout <<"\tChecking that HF digi size is between ["<<mindigisizeHF_<<" - "<<maxdigisizeHF_<<"];"<<std::endl;
00074         }
00075       if (digi_checkadcsum_) std::cout <<"\tChecking that ADC sum of digi is greater than 0;"<<std::endl; 
00076       if (digi_checkdverr_) std::cout <<"\tChecking that data valid bit is true and digi error bit is false;\n"<<std::endl;
00077     }
00078   
00079   shutOffOrbitTest_ = ps.getUntrackedParameter<bool>("shutOffOrbitTest",false);
00080   DigiMonitor_ExpectedOrbitMessageTime_=ps.getUntrackedParameter<int>("ExpectedOrbitMessageTime",3559); // -1 means that orbit mismatches won't be checked
00081 
00082   HFtiming_totaltime2D=0;
00083   HFtiming_occupancy2D=0;
00084   HFtiming_etaProfile=0;
00085   HFP_shape=0;
00086   HFM_shape=0;
00087 }
00088 
00089 // destructor
00090 HcalDigiMonitor::~HcalDigiMonitor() {}
00091 
00092 // Checks capid rotation; returns false if no problems with rotation
00093 static bool bitUpset(int last, int now){
00094   if(last ==-1) return false;
00095   int v = last+1; 
00096   if(v==4) v=0;
00097   if(v==now) return false;
00098   return true;
00099 } // static bool bitUpset(...)
00100 
00101 void HcalDigiMonitor::cleanup()
00102 {
00103   // Need to add code to clear out subfolders as well?
00104   if (debug_>0) std::cout <<"HcalDigiMonitor::cleanup()"<<std::endl;
00105   if (!enableCleanup_) return;
00106   if (dbe_)
00107     {
00108       // removeContents doesn't remove subdirectories
00109       dbe_->setCurrentFolder(subdir_);
00110       dbe_->removeContents();
00111       dbe_->setCurrentFolder(subdir_+"digi_parameters");  dbe_->removeContents();
00112       dbe_->setCurrentFolder(subdir_+"bad_digis/bad_digi_occupancy");  dbe_->removeContents();
00113       dbe_->setCurrentFolder(subdir_+"bad_digis/1D_digi_plots");  dbe_->removeContents();
00114       dbe_->setCurrentFolder(subdir_+"bad_digis/badcapID");  dbe_->removeContents();
00115       dbe_->setCurrentFolder(subdir_+"bad_digis/data_invalid_error");  dbe_->removeContents();
00116       dbe_->setCurrentFolder(subdir_+"bad_digis/bad_reportUnpackerErrors");  dbe_->removeContents();
00117       dbe_->setCurrentFolder(subdir_+"bad_digis/baddigisize");  dbe_->removeContents();
00118       dbe_->setCurrentFolder(subdir_+"digi_info");  dbe_->removeContents();
00119       dbe_->setCurrentFolder(subdir_+"bad_digis/badfibBCNoff");  dbe_->removeContents();
00120       dbe_->setCurrentFolder(subdir_+"good_digis/1D_digi_plots");  dbe_->removeContents();
00121       dbe_->setCurrentFolder(subdir_+"good_digis/digi_occupancy");  dbe_->removeContents();
00122       dbe_->setCurrentFolder(subdir_+"bad_digis/bad_digi_occupancy");  dbe_->removeContents();
00123       dbe_->setCurrentFolder(subdir_+"bad_digis");  dbe_->removeContents();
00124       dbe_->setCurrentFolder(subdir_+"good_digis/");  dbe_->removeContents();
00125       dbe_->setCurrentFolder(subdir_+"digi_info/HB");  dbe_->removeContents();
00126       dbe_->setCurrentFolder(subdir_+"digi_info/HE");  dbe_->removeContents();
00127       dbe_->setCurrentFolder(subdir_+"digi_info/HO");  dbe_->removeContents();
00128       dbe_->setCurrentFolder(subdir_+"digi_info/HF");  dbe_->removeContents();
00129       dbe_->setCurrentFolder(subdir_+"LSvalues");
00130       dbe_->removeContents();
00131     } // if(dbe_)
00132 
00133 } // void HcalDigiMonitor::cleanup();
00134 
00135 
00136 void HcalDigiMonitor::endRun(const edm::Run& run, const edm::EventSetup& c)
00137 {
00138   // Anything to do here?
00139 }
00140 
00141 void HcalDigiMonitor::endJob()
00142 {
00143   if (debug_>0) std::cout <<"HcalDigiMonitor::endJob()"<<std::endl;
00144   if (enableCleanup_) cleanup(); // when do we force cleanup?
00145 }
00146 
00147 
00148 void HcalDigiMonitor::setup()
00149 {
00150   // Call base class setup
00151   HcalBaseDQMonitor::setup();
00152   if (!dbe_) return;
00153 
00154   /******* Set up all histograms  ********/
00155   if (debug_>1)
00156     std::cout <<"<HcalDigiMonitor::beginRun>  Setting up histograms"<<std::endl;
00157 
00158   std::ostringstream name;
00159   dbe_->setCurrentFolder(subdir_);
00160   
00161   dbe_->setCurrentFolder(subdir_+"digi_parameters");
00162   MonitorElement* ExpectedOrbit = dbe_->bookInt("ExpectedOrbitMessageTime");
00163   ExpectedOrbit->Fill(DigiMonitor_ExpectedOrbitMessageTime_);
00164 
00165   MonitorElement* shapeT = dbe_->bookInt("DigiShapeThresh");
00166   shapeT->Fill(shapeThresh_);
00167   MonitorElement* shapeTHB = dbe_->bookInt("DigiShapeThreshHB");
00168   shapeTHB->Fill(shapeThreshHB_);
00169   MonitorElement* shapeTHE = dbe_->bookInt("DigiShapeThreshHE");
00170   shapeTHE->Fill(shapeThreshHE_);
00171   MonitorElement* shapeTHO = dbe_->bookInt("DigiShapeThreshHO");
00172   shapeTHO->Fill(shapeThreshHO_);
00173   MonitorElement* shapeTHF = dbe_->bookInt("DigiShapeThreshHF");
00174   shapeTHF->Fill(shapeThreshHF_);
00175   
00176   dbe_->setCurrentFolder(subdir_+"bad_digis/bad_digi_occupancy");
00177   SetupEtaPhiHists(DigiErrorsByDepth,"Bad Digi Map","");
00178   dbe_->setCurrentFolder(subdir_+"bad_digis/1D_digi_plots");
00179   ProblemsVsLB=dbe_->bookProfile("BadDigisVsLB","Number Bad Digis vs Luminosity block;Lumi block;# of Bad digis",
00180                                  NLumiBlocks_,0.5,NLumiBlocks_+0.5,100,0,10000);
00181   ProblemsVsLB_HB=dbe_->bookProfile("HB Bad Quality Digis vs LB","HB Bad Quality Digis vs Luminosity Block",
00182                                      NLumiBlocks_,0.5,NLumiBlocks_+0.5,
00183                                      100,0,10000);   
00184   ProblemsVsLB_HE=dbe_->bookProfile("HE Bad Quality Digis vs LB","HE Bad Quality Digis vs Luminosity Block",
00185                                      NLumiBlocks_,0.5,NLumiBlocks_+0.5,
00186                                      100,0,10000);
00187   ProblemsVsLB_HO=dbe_->bookProfile("HO Bad Quality Digis vs LB","HO Bad Quality Digis vs Luminosity Block",
00188                                      NLumiBlocks_,0.5,NLumiBlocks_+0.5,
00189                                      100,0,10000);
00190   ProblemsVsLB_HF=dbe_->bookProfile("HF Bad Quality Digis vs LB","HF Bad Quality Digis vs Luminosity Block",
00191                                      NLumiBlocks_,0.5,NLumiBlocks_+0.5,
00192                                      100,0,10000);
00193   ProblemsVsLB_HBHEHF=dbe_->bookProfile("HBHEHF Bad Quality Digis vs LB","HBHEHF Bad Quality Digis vs Luminosity Block",
00194                                      NLumiBlocks_,0.5,NLumiBlocks_+0.5,
00195                                      100,0,10000);
00196 
00197   if (makeDiagnostics_) 
00198     {
00199       // by default, unpacked digis won't have these errors
00200       dbe_->setCurrentFolder(subdir_+"diagnostics/bad_digis/badcapID");
00201       SetupEtaPhiHists(DigiErrorsBadCapID," Digis with Bad Cap ID Rotation", "");
00202       dbe_->setCurrentFolder(subdir_+"diagnostics/bad_digis/data_invalid_error");
00203       SetupEtaPhiHists(DigiErrorsDVErr," Digis with Data Invalid or Error Bit Set", "");
00204     }
00205   
00206   if (Online_)
00207     {
00208       // Special histograms for Pawel's timing study
00209       dbe_->setCurrentFolder(subdir_+"HFTimingStudy");
00210       HFtiming_etaProfile=dbe_->bookProfile("HFTiming_etaProfile","HFTiming Eta Profile;ieta;average time (time slice)",83,-41.5,41.5,200,0,10);
00211       HFP_shape=dbe_->book1D("HFP_signal_shape","HFP signal shape",10,-0.5,9.5);
00212       HFM_shape=dbe_->book1D("HFM_signal_shape","HFM signal shape",10,-0.5,9.5);
00213       dbe_->setCurrentFolder(subdir_+"HFTimingStudy/sumplots");
00214       HFtiming_totaltime2D=dbe_->book2D("HFTiming_Total_Time","HFTiming Total Time",83,-41.5,41.5,72,0.5,72.5);
00215       HFtiming_occupancy2D=dbe_->book2D("HFTiming_Occupancy","HFTiming Occupancy",83,-41.5,41.5,72,0.5,72.5);
00216     }
00217   
00218   dbe_->setCurrentFolder(subdir_+"bad_digis/bad_reportUnpackerErrors");
00219   SetupEtaPhiHists(DigiErrorsUnpacker," Bad Unpacker Digis", "");
00220   
00221   dbe_->setCurrentFolder(subdir_+"bad_digis/baddigisize");
00222   SetupEtaPhiHists(DigiErrorsBadDigiSize," Digis with Bad Size", "");
00223   
00224   dbe_->setCurrentFolder(subdir_+"digi_info");
00225   
00226   h_valid_digis=dbe_->book1D("ValidEvents","Events with minimum number of valid digis",2,-0.5,1.5);
00227   h_valid_digis->setBinLabel(1,"Valid");
00228   h_valid_digis->setBinLabel(2,"Invalid");
00229   
00230   h_invalid_orbitnumMod103=dbe_->book1D("InvalidDigiEvents_ORN","Orbit Number (mod 103) for Events with Many Unpacker Errors",103,-0.5,102.5);
00231   h_invalid_bcn=dbe_->book1D("InvalidDigiEvents_BCN","Bunch Crossing Number fo Events with Many Unpacker Errors",3464,-0.5,3563.5);
00232 
00233   DigiSize = dbe_->book2D("Digi Size", "Digi Size",4,0,4,20,-0.5,19.5);
00234   DigiSize->setBinLabel(1,"HB",1);
00235   DigiSize->setBinLabel(2,"HE",1);
00236   DigiSize->setBinLabel(3,"HO",1);
00237   DigiSize->setBinLabel(4,"HF",1);
00238   DigiSize->setAxisTitle("Subdetector",1);
00239   DigiSize->setAxisTitle("Digi Size",2);
00240   
00241   dbe_->setCurrentFolder(subdir_+"bad_digis/badfibBCNoff");
00242   SetupEtaPhiHists(DigiErrorsBadFibBCNOff," Digis with non-zero Fiber Orbit Msg Idle BCN Offsets", "");
00243   
00244   dbe_->setCurrentFolder(subdir_+"good_digis/1D_digi_plots");
00245   HBocc_vs_LB=dbe_->bookProfile("HBoccVsLB","HB digi occupancy vs Luminosity Block;Lumi block;# of Good digis",
00246                                  NLumiBlocks_,0.5,NLumiBlocks_+0.5,
00247                                  0,2600);
00248   HEocc_vs_LB=dbe_->bookProfile("HEoccVsLB","HE digi occupancy vs Luminosity Block;Lumi block;# of Good digis",
00249                                  NLumiBlocks_,0.5,NLumiBlocks_+0.5,
00250                                  0,2600);
00251   HOocc_vs_LB=dbe_->bookProfile("HOoccVsLB","HO digi occupancy vs Luminosity Block;Lumi block;# of Good digis",
00252                                  NLumiBlocks_,0.5,NLumiBlocks_+0.5,
00253                                  0,2200);
00254   HFocc_vs_LB=dbe_->bookProfile("HFoccVsLB","HF digi occupancy vs Luminosity Block;Lumi block;# of Good digis",
00255                                  NLumiBlocks_,0.5,NLumiBlocks_+0.5,
00256                                  0,1800);
00257   
00258   dbe_->setCurrentFolder(subdir_+"good_digis/digi_occupancy");
00259   SetupEtaPhiHists(DigiOccupancyByDepth," Digi Eta-Phi Occupancy Map","");
00260   DigiOccupancyPhi= dbe_->book1D("Digi Phi Occupancy Map",
00261                                   "Digi Phi Occupancy Map;i#phi;# of Events",
00262                                   72,0.5,72.5);
00263   DigiOccupancyEta= dbe_->book1D("Digi Eta Occupancy Map",
00264                                   "Digi Eta Occupancy Map;i#eta;# of Events",
00265                                   83,-41.5,41.5);
00266   DigiOccupancyVME = dbe_->book2D("Digi VME Occupancy Map",
00267                                    "Digi VME Occupancy Map;HTR Slot;VME Crate Id",
00268                                    40,-0.25,19.75,18,-0.5,17.5);
00269   
00270   DigiOccupancySpigot = dbe_->book2D("Digi Spigot Occupancy Map",
00271                                       "Digi Spigot Occupancy Map;Spigot;DCC Id",
00272                                       HcalDCCHeader::SPIGOT_COUNT,-0.5,HcalDCCHeader::SPIGOT_COUNT-0.5,
00273                                       36,-0.5,35.5);
00274   
00275   dbe_->setCurrentFolder(subdir_+"bad_digis/bad_digi_occupancy");
00276   DigiErrorVME = dbe_->book2D("Digi VME Error Map",
00277                                "Digi VME Error Map;HTR Slot;VME Crate Id",
00278                                40,-0.25,19.75,18,-0.5,17.5);
00279   
00280   DigiErrorSpigot = dbe_->book2D("Digi Spigot Error Map",
00281                                   "Digi Spigot Error Map;Spigot;DCC Id",
00282                                   HcalDCCHeader::SPIGOT_COUNT,-0.5,HcalDCCHeader::SPIGOT_COUNT-0.5,
00283                                   36,-0.5,35.5);
00284   
00285   dbe_->setCurrentFolder(subdir_+"bad_digis");
00286   int nbins = sizeof(bins_cellcount_new)/sizeof(float)-1;
00287 
00288   DigiBQ = dbe_->book1D("NumBadQualDigis","Number Bad Qual Digis within Digi Collection",nbins, bins_cellcount_new);
00289 
00290   nbins=sizeof(bins_fraccount_new)/sizeof(float)-1;
00291 
00292   DigiBQFrac =  dbe_->book1D("Bad Digi Fraction","Bad Digi Fraction;Bad Quality Digi Fraction for digis in collection; # of Events",
00293                              nbins, bins_fraccount_new);
00294   
00295   nbins = sizeof(bins_cellcount_new)/sizeof(float)-1;
00296   DigiUnpackerErrorCount = dbe_->book1D("Unpacker Error Count", "Number of Bad Digis from Unpacker; Bad Unpacker Digis; # of Events",nbins, bins_cellcount_new);
00297   
00298   nbins=sizeof(bins_fraccount_new)/sizeof(float)-1;
00299   DigiUnpackerErrorFrac = dbe_->book1D("Unpacker Bad Digi Fraction", 
00300                                        "Bad Digis From Unpacker/ (Bad Digis From Unpacker + Good Digis); Bad Unpacker Fraction; # of Events",
00301                                        nbins,bins_fraccount_new);
00302   
00303   dbe_->setCurrentFolder(subdir_+"good_digis/");
00304   DigiNum = dbe_->book1D("NumGoodDigis","Number of Digis;# of Good Digis;# of Events",DIGI_NUM+1,-0.5,DIGI_NUM+1-0.5);
00305     
00306   setupSubdetHists(hbHists,"HB");
00307   setupSubdetHists(heHists,"HE");
00308   setupSubdetHists(hoHists,"HO");
00309   setupSubdetHists(hfHists,"HF");
00310 
00311   this->reset();
00312   return;
00313 } // void HcalDigiMonitor::setup()
00314 
00315 void HcalDigiMonitor::beginRun(const edm::Run& run, const edm::EventSetup& c)
00316 {
00317   HcalBaseDQMonitor::beginRun(run,c);
00318   if (mergeRuns_ && tevt_>0) return; // don't reset counters if merging runs
00319 
00320   if (debug_>1) std::cout <<"\t<HcalDigiMonitor::setup> Getting conditions from DB!"<<std::endl;
00321   c.get<HcalDbRecord>().get(conditions_);
00322 
00323   // Get all pedestals by Cap ID
00324   edm::ESHandle<HcalChannelQuality> p;
00325   c.get<HcalChannelQualityRcd>().get(p);
00326   HcalChannelQuality *chanquality= new HcalChannelQuality(*p.product());
00327   std::vector<DetId> mydetids = chanquality->getAllChannels();
00328   PedestalsByCapId_.clear();
00329 
00330   const HcalQIEShape* shape = conditions_->getHcalShape();
00331   for (std::vector<DetId>::const_iterator chan = mydetids.begin();chan!=mydetids.end();++chan)
00332     {
00333       if (chan->det()!=DetId::Hcal) continue; // not hcal
00334       std::vector <double> peds;  // could be ints, right?
00335       peds.clear();
00336       HcalCalibrations calibs=conditions_->getHcalCalibrations(*chan);
00337       const HcalQIECoder* channelCoder = conditions_->getHcalCoder(*chan);
00338       //double total=0; // use this is we want to calculate average pedestal value
00339       for (int capid=0;capid<4;++capid)
00340         {
00341           // temp_ADC should be an int, right?
00342           double temp_ADC=channelCoder->adc(*shape,(float)calibs.pedestal(capid),capid);
00343           peds.push_back(temp_ADC);
00344           //total=total+temp_ADC;
00345         }
00346       //for (int capid=0;capid<4;++capid) peds.push_back(total/4.); // use this if we just want to use average value
00347       PedestalsByCapId_[*chan]=peds;
00348     } // loop on DetIds
00349 
00350   if (tevt_==0) this->setup(); // create all histograms; not necessary if merging runs together
00351   if (mergeRuns_==false) this->reset(); // call reset at start of all runs
00352   delete chanquality;
00353 
00354   // Get known dead cells for this run
00355   KnownBadCells_.clear();
00356   if (badChannelStatusMask_>0)
00357     {
00358       edm::ESHandle<HcalChannelQuality> p;
00359       c.get<HcalChannelQualityRcd>().get(p);
00360       HcalChannelQuality* chanquality= new HcalChannelQuality(*p.product());
00361       std::vector<DetId> mydetids = chanquality->getAllChannels();
00362       for (std::vector<DetId>::const_iterator i = mydetids.begin();
00363            i!=mydetids.end();
00364            ++i)
00365         {
00366           if (i->det()!=DetId::Hcal) continue; // not an hcal cell
00367           HcalDetId id=HcalDetId(*i);
00368           int status=(chanquality->getValues(id))->getValue();
00369           if ((status & badChannelStatusMask_))
00370             {
00371               KnownBadCells_[id.rawId()]=status;
00372             }
00373         } 
00374         delete chanquality;
00375     } // if (badChannelStatusMask_>0)
00376 
00377 } // void HcalDigiMonitor::beginRun()
00378 
00379 
00380 void HcalDigiMonitor::setupSubdetHists(DigiHists& hist, std::string subdet)
00381 {
00382   if (!dbe_) return;
00383   std::stringstream name;
00384   int nChan=0;
00385   if (subdet=="HB" || subdet=="HE") nChan=2592;
00386   else if (subdet == "HO") nChan=2160;
00387   else if (subdet == "HF") nChan=1728;
00388 
00389   dbe_->setCurrentFolder(subdir_+"digi_info/"+subdet);
00390   hist.shape = dbe_->book1D(subdet+" Digi Shape",subdet+" Digi Shape;Time Slice",10,-0.5,9.5);
00391   hist.shapeThresh = dbe_->book1D(subdet+" Digi Shape - over thresh",
00392                                   subdet+" Digi Shape - over thresh passing trigger and HF HT cuts;Time slice",
00393                                   10,-0.5,9.5);
00394   hist.ThreshCount = dbe_->book1D(subdet+" Total Digis Over Threshold",
00395                                   subdet+" Total Digis Over Threshold",
00396                                   1,-0.5,0.5);
00397   // Create plots of sums of adjacent time slices
00398   for (int ts=0;ts<9;++ts)
00399     {
00400       name<<subdet<<" Plus Time Slices "<<ts<<" and "<<ts+1;
00401       hist.TS_sum_plus.push_back(dbe_->book1D(name.str().c_str(),name.str().c_str(),50,-5.5,44.5));
00402       name.str("");
00403       name<<subdet<<" Minus Time Slices "<<ts<<" and "<<ts+1;
00404       hist.TS_sum_minus.push_back(dbe_->book1D(name.str().c_str(),name.str().c_str(),50,-5.5,44.5));
00405       name.str("");
00406     }
00407   hist.presample= dbe_->book1D(subdet+" Digi Presamples",subdet+" Digi Presamples",50,-0.5,49.5);
00408   hist.BQ = dbe_->book1D(subdet+" Bad Quality Digis",subdet+" Bad Quality Digis",nChan+1,-0.5,nChan+0.5);
00409   //(hist.BQ->getTH1F())->LabelsOption("v");
00410   hist.BQFrac = dbe_->book1D(subdet+" Bad Quality Digi Fraction",subdet+" Bad Quality Digi Fraction",DIGI_BQ_FRAC_NBINS,(0-0.5/(DIGI_BQ_FRAC_NBINS-1)),1+0.5/(DIGI_BQ_FRAC_NBINS-1));
00411   hist.DigiFirstCapID = dbe_->book1D(subdet+" Capid 1st Time Slice",subdet+" Capid for 1st Time Slice;CapId (T0)- 1st CapId (T0);# of Events",7,-3.5,3.5);
00412 
00413   hist.DVerr = dbe_->book1D(subdet+" Data Valid Err Bits",subdet+" QIE Data Valid Err Bits",4,-0.5,3.5);
00414   hist.DVerr ->setBinLabel(1,"Err=0, DV=0",1);
00415   hist.DVerr ->setBinLabel(2,"Err=0, DV=1",1);
00416   hist.DVerr ->setBinLabel(3,"Err=1, DV=0",1);
00417   hist.DVerr ->setBinLabel(4,"Err=1, DV=1",1);
00418   hist.CapID = dbe_->book1D(subdet+" CapID",subdet+" CapID",4,-0.5,3.5);
00419   hist.ADC = dbe_->book1D(subdet+" ADC count per time slice",subdet+" ADC count per time slice",200,-0.5,199.5);
00420   hist.ADCsum = dbe_->book1D(subdet+" ADC sum", subdet+" ADC sum",200,-0.5,199.5);
00421   hist.fibBCNOff = dbe_->book1D(subdet+" Fiber Orbit Message Idle BCN Offset", subdet+" Fiber Orbit Message Idle BCN Offset;Offset from Expected",
00422                                  15, -7.5, 7.5);
00423 }
00424 
00425 void HcalDigiMonitor::analyze(edm::Event const&e, edm::EventSetup const&s)
00426 {
00427   if (!IsAllowedCalibType()) return;
00428   if (LumiInOrder(e.luminosityBlock())==false) return;
00429 
00430   // Get HLT trigger information for HF timing study
00431   passedMinBiasHLT_=false;
00432 
00433   edm::Handle<edm::TriggerResults> hltRes;
00434   if (!(e.getByLabel(hltresultsLabel_,hltRes)))
00435     {
00436       if (debug_>0) edm::LogWarning("HcalDigiMonitor")<<" Could not get HLT results with tag "<<hltresultsLabel_<<std::endl;
00437     }
00438   else
00439     {
00440       const edm::TriggerNames & triggerNames = e.triggerNames(*hltRes);
00441       const unsigned int nTrig(triggerNames.size());
00442       for (unsigned int i=0;i<nTrig;++i){
00443           // repeat for minbias triggers
00444           for (unsigned int k=0;k<MinBiasHLTBits_.size();++k)
00445             {
00446               // if (triggerNames.triggerName(i)==MinBiasHLTBits_[k] && hltRes->accept(i))
00447               if (triggerNames.triggerName(i).find(MinBiasHLTBits_[k])!=std::string::npos && hltRes->accept(i))
00448                 { 
00449                   passedMinBiasHLT_=true;
00450                   break;
00451                 }
00452             }
00453         }
00454     } //else
00455   
00456   // Now get collections we need
00457   HT_HFP_=0;
00458   HT_HFM_=0;
00459   bool rechitsFound=false;
00460   edm::Handle<HFRecHitCollection> hf_rechit;
00461   if (e.getByLabel(hfRechitLabel_,hf_rechit))
00462     {
00463       rechitsFound=true;
00464       for (HFRecHitCollection::const_iterator HF=hf_rechit->begin();HF!=hf_rechit->end();++HF)
00465         {
00466           float en=HF->energy();
00467           int ieta=HF->id().ieta();
00468           // ieta for HF starts at 29, so subtract away 29 when computing fEta
00469           double fEta=fabs(0.5*(theHFEtaBounds[abs(ieta)-28]+theHFEtaBounds[abs(ieta)-29]));
00470           ieta>0 ?  HT_HFP_+=en/cosh(fEta) : HT_HFM_+=en/cosh(fEta);
00471         }
00472     }
00473   else
00474     {
00475       // if no rechits found, form above-threshold plots based only on digi comparison to ADC threshold 
00476       HT_HFP_=999;
00477       HT_HFM_=999;
00478     }
00479 
00480   // try to get digis
00481   edm::Handle<HBHEDigiCollection> hbhe_digi;
00482   edm::Handle<HODigiCollection> ho_digi;
00483   edm::Handle<HFDigiCollection> hf_digi;
00484 
00485   if (!(e.getByLabel(digiLabel_,hbhe_digi)))
00486     {
00487       edm::LogWarning("HcalDigiMonitor")<< digiLabel_<<" hbhe_digi not available";
00488       return;
00489     }
00490   
00491   if (!(e.getByLabel(digiLabel_,hf_digi)))
00492     {
00493       edm::LogWarning("HcalDigiMonitor")<< digiLabel_<<" hf_digi not available";
00494       return;
00495     }
00496   if (!(e.getByLabel(digiLabel_,ho_digi)))
00497     {
00498       edm::LogWarning("HcalDigiMonitor")<< digiLabel_<<" ho_digi not available";
00499       return;
00500     }
00501   edm::Handle<HcalUnpackerReport> report;  
00502   if (!(e.getByLabel(digiLabel_,report)))
00503     {
00504       edm::LogWarning("HcalDigiMonitor")<< digiLabel_<<" unpacker report not available";
00505       return;
00506     }
00507 
00508   // all objects grabbed; event is good
00509   if (debug_>1) std::cout <<"\t<HcalDigiMonitor::analyze>  Processing good event! event # = "<<ievt_<<std::endl;
00510 
00511   HcalBaseDQMonitor::analyze(e,s); // base class increments ievt_, etc. counters
00512 
00513   // Digi collection was grabbed successfully; process the Event
00514   processEvent(*hbhe_digi, *ho_digi, *hf_digi, *conditions_,
00515                *report, e.orbitNumber(),e.bunchCrossing());
00516   
00517 } //void HcalDigiMonitor::analyze(...)
00518 
00519 void HcalDigiMonitor::processEvent(const HBHEDigiCollection& hbhe,
00520                                    const HODigiCollection& ho,
00521                                    const HFDigiCollection& hf,
00522                                    const HcalDbService& cond,
00523                                    const HcalUnpackerReport& report,
00524                                    int orN, int bcN)
00525 { 
00526   if(!dbe_) 
00527     { 
00528       if(debug_) 
00529         std::cout <<"HcalDigiMonitor::processEvent   DQMStore not instantiated!!!"<<std::endl; 
00530       return; 
00531     }
00532 
00533   // Skip events in which minimal good digis found -- still getting some strange (calib?) events through DQM
00534 
00535   DigiUnpackerErrorCount->Fill(report.badQualityDigis());
00536   
00537   unsigned int allgooddigis= hbhe.size()+ho.size()+hf.size();
00538   // bad threshold:  ignore events in which bad outnumber good by more than 100:1
00539   // (one RBX in HBHE seems to send valid data occasionally even on QIE resets, which is why we can't just require allgooddigis==0 when looking for events to skip)
00540   if ((allgooddigis==0) ||
00541       (1.*report.badQualityDigis()>100*allgooddigis))
00542     {
00543       h_valid_digis->Fill(1);
00544       if (bcN>-1)
00545         h_invalid_bcn->Fill(bcN);
00546       if (orN>-1)
00547         h_invalid_orbitnumMod103->Fill(orN%103);
00548       return;
00549     }
00550   
00551   h_valid_digis->Fill(0);
00552 
00553   // hbHists.count_bad=0;
00554   // hbHists.count_good=0;
00555   // heHists.count_bad=0;
00556   // heHists.count_good=0;
00557   // hoHists.count_bad=0;
00558   // hoHists.count_good=0;
00559   // hfHists.count_bad=0;
00560   // hfHists.count_good=0;
00561 
00562   // int HO0bad=0;
00563   // int HO12bad=0;
00564   // int HFlumibad=0;
00565 
00566   // Check unpacker report for bad digis
00567 
00568   typedef std::vector<DetId> DetIdVector;
00569 
00570   for ( DetIdVector::const_iterator baddigi_iter=report.bad_quality_begin(); 
00571         baddigi_iter != report.bad_quality_end();
00572         ++baddigi_iter)
00573     {
00574       HcalDetId id(baddigi_iter->rawId());
00575       int rDepth = id.depth();
00576       int rPhi   = id.iphi();
00577       int rEta   = id.ieta();
00578       int binEta = CalcEtaBin(id.subdet(), rEta, rDepth); // why is this here?
00579       if (id.subdet()==HcalBarrel) ++hbHists.count_bad;
00580       else if (id.subdet()==HcalEndcap) ++heHists.count_bad;
00581       else if (id.subdet()==HcalForward) 
00582         {
00583           ++hfHists.count_bad;
00584           if (rDepth==1 && (abs(rEta)==33 || abs(rEta)==34)) ++HFlumibad;
00585           else if (rDepth==2 && (abs(rEta)==35 || abs(rEta)==36)) ++HFlumibad;
00586         }
00587       else if (id.subdet()==HcalOuter) 
00588         {
00589           // Mark HORing+/-2 channels as present, HO/YB+/-2 has HV off (at 100V).
00590           if (excludeHORing2_==true && rDepth==4)
00591             if (abs(rEta)>=11 && abs(rEta)<=15 && !isSiPM(rEta,rPhi,rDepth)) continue;
00592 
00593           if (excludeHO1P02_==true)
00594             if( (rEta>4 && rEta<10) && (rPhi<=10 || rPhi>70) ) continue;
00595           
00596           if (KnownBadCells_.find(id)!=KnownBadCells_.end()) continue;
00597 
00598           ++hoHists.count_bad;
00599           if (abs(rEta)<5) ++HO0bad;
00600           else ++HO12bad;
00601         }
00602       else 
00603         continue; // skip anything that isn't HB, HE, HO, HF
00604       // extra protection against nonsensical values -- prevents occasional crashes
00605       if (binEta < 85 && binEta >= 0 
00606           && (rPhi-1) >= 0 && (rPhi-1)<72 
00607           && (rDepth-1) >= 0 && (rDepth-1)<4)
00608         {
00609           ++badunpackerreport[binEta][rPhi-1][rDepth-1];
00610           ++baddigis[binEta][rPhi-1][rDepth-1];  
00611         }
00612     }
00613 
00615 
00616   int firsthbcap=-1;
00617   int firsthecap=-1;
00618   int firsthocap=-1;
00619   int firsthfcap=-1;
00620 
00621   for (HBHEDigiCollection::const_iterator j=hbhe.begin(); j!=hbhe.end(); ++j)
00622     {
00623         const HBHEDataFrame digi = (const HBHEDataFrame)(*j);
00624           
00625         if (digi.id().subdet()==HcalBarrel)
00626           {
00627             if (!HBpresent_) continue;
00628             if (KnownBadCells_.find(digi.id())!=KnownBadCells_.end()) continue;
00629           
00630             process_Digi(digi, hbHists, firsthbcap);
00631           }
00632         else if (digi.id().subdet()==HcalEndcap)
00633           {
00634             if (!HEpresent_) continue;
00635             process_Digi(digi, heHists,firsthecap);
00636           }     
00637     }
00638 
00639   // // Fill good digis vs lumi block; also fill bad errors?
00640   // HBocc_vs_LB->Fill(currentLS,hbHists.count_good);
00641   // HEocc_vs_LB->Fill(currentLS,heHists.count_good);
00642 
00643   // Calculate number of bad quality cells and bad quality fraction
00644   if (HBpresent_ && (hbHists.count_good>0 || hbHists.count_bad>0))
00645     {
00646       int counter=hbHists.count_bad;
00647       if (counter<DIGI_SUBDET_NUM)
00648         ++hbHists.count_BQ[counter];
00649       float counter2 = (1.*hbHists.count_bad)/(hbHists.count_bad+hbHists.count_good)*(DIGI_BQ_FRAC_NBINS-1);
00650       if (counter2<DIGI_SUBDET_NUM) ++hbHists.count_BQFrac[(int)counter2];
00651     }
00652 
00653   if (HEpresent_ && (heHists.count_good>0 || heHists.count_bad>0))
00654     {
00655       int counter=heHists.count_bad;
00656       if (counter<DIGI_SUBDET_NUM)
00657         ++heHists.count_BQ[counter];
00658       float counter2 = (1.*heHists.count_bad)/(heHists.count_bad+heHists.count_good)*(DIGI_BQ_FRAC_NBINS-1);
00659       if (counter2<DIGI_SUBDET_NUM) ++heHists.count_BQFrac[int(counter2)];
00660     }
00661 
00663   if (HOpresent_)
00664     {
00665       for (HODigiCollection::const_iterator j=ho.begin(); j!=ho.end(); ++j)
00666         {
00667           const HODataFrame digi = (const HODataFrame)(*j);
00668           // Mark HORing+/-2 channels as present, HO/YB+/-2 has HV off (at 100V).
00669           if (excludeHORing2_==true && digi.id().depth()==4)
00670             if (abs(digi.id().ieta())>=11 && abs(digi.id().ieta())<=15 && 
00671                 !isSiPM(digi.id().ieta(),digi.id().iphi(),digi.id().depth())) continue;
00672           
00673           if (excludeHO1P02_==true)       
00674             if( (digi.id().ieta()>4 && digi.id().ieta()<10) 
00675                 && (digi.id().iphi()<=10 || digi.id().iphi()>70) ) continue;
00676 
00677           if (KnownBadCells_.find(digi.id())!=KnownBadCells_.end()) continue;
00678           
00679           process_Digi(digi, hoHists, firsthocap);
00680         } // for (HODigiCollection)
00681       
00682       if (hoHists.count_bad>0 || hoHists.count_good>0)
00683         {
00684           int counter=hoHists.count_bad;
00685           if (counter<DIGI_SUBDET_NUM)
00686             ++hoHists.count_BQ[counter];
00687 
00688           float counter2 = (1.*hoHists.count_bad)/(hoHists.count_bad+hoHists.count_good)*(DIGI_BQ_FRAC_NBINS-1);
00689           if (counter2<DIGI_SUBDET_NUM) ++hoHists.count_BQFrac[int(counter2)];
00690         }
00691       HOocc_vs_LB->Fill(currentLS,hoHists.count_good);
00692     } // if (HOpresent_)
00693   
00695   if (HFpresent_)
00696     {
00697       for (HFDigiCollection::const_iterator j=hf.begin(); j!=hf.end(); ++j)
00698         {
00699           const HFDataFrame digi = (const HFDataFrame)(*j);
00700           process_Digi(digi, hfHists, firsthfcap);
00701         } // for (HFDigiCollection)
00702 
00703       if (hfHists.count_bad>0 || hfHists.count_good>0)
00704         {
00705           int counter=hfHists.count_bad;
00706           if (counter<DIGI_SUBDET_NUM)
00707             ++hfHists.count_BQ[counter];
00708           float counter2 = (1.*hfHists.count_bad)/(hfHists.count_bad+hfHists.count_good)*(DIGI_BQ_FRAC_NBINS-1);
00709           if (counter2<DIGI_SUBDET_NUM) ++hfHists.count_BQFrac[int(counter2)];
00710         }
00711       HFocc_vs_LB->Fill(currentLS,hfHists.count_good);
00712     } // if (HFpresent_)
00713   
00714   // This only counts digis that are present but bad somehow; it does not count digis that are missing
00715   int count_good=hbHists.count_good+heHists.count_good+hoHists.count_good+hfHists.count_good;
00716   int count_bad=hbHists.count_bad+heHists.count_bad+hoHists.count_bad+hfHists.count_bad;
00717 
00718   if (count_good<DIGI_NUM)
00719     ++diginum[count_good];
00720 
00721   // Fill bad quality histograms
00722   DigiUnpackerErrorFrac->Fill(1.*report.badQualityDigis()/(report.badQualityDigis()+count_good));
00723   DigiBQ->Fill(count_bad);
00724   if (count_bad>0 || count_good>0)
00725     DigiBQFrac->Fill(1.*count_bad/(count_bad+count_good));
00726 
00727   // Call 'update' on all histograms so that they update in online DQM  
00728   UpdateHists(hbHists);
00729   UpdateHists(heHists);
00730   UpdateHists(hoHists);
00731   UpdateHists(hfHists);
00732 
00733   // Now update global (non-subdetector-specific) histograms
00734   DigiNum->update();
00735   DigiErrorVME->update();
00736   DigiErrorSpigot->update();
00737   DigiBQ->update();
00738   DigiBQFrac->update();
00739   DigiUnpackerErrorCount->update();
00740   DigiUnpackerErrorFrac->update();
00741 
00742   // Update eta-phi hists
00743   for (unsigned int zz=0;zz<DigiErrorOccupancyByDepth.depth.size();++zz)
00744       DigiErrorOccupancyByDepth.depth[zz]->update();
00745   for (unsigned int zz=0;zz<DigiErrorsByDepth.depth.size();++zz)
00746       DigiErrorsByDepth.depth[zz]->update();
00747   for (unsigned int zz=0;zz<DigiErrorsBadCapID.depth.size();++zz)
00748       DigiErrorsBadCapID.depth[zz]->update();
00749   for (unsigned int zz=0;zz<DigiErrorsDVErr.depth.size();++zz)
00750       DigiErrorsDVErr.depth[zz]->update();
00751   for (unsigned int zz=0;zz<DigiErrorsBadDigiSize.depth.size();++zz)
00752       DigiErrorsBadDigiSize.depth[zz]->update();
00753   for (unsigned int zz=0;zz<DigiErrorsBadADCSum.depth.size();++zz)
00754       DigiErrorsBadADCSum.depth[zz]->update();
00755   for (unsigned int zz=0;zz<DigiErrorsUnpacker.depth.size();++zz)
00756       DigiErrorsUnpacker.depth[zz]->update();
00757   for (unsigned int zz=0;zz<DigiErrorsBadFibBCNOff.depth.size();++zz)
00758     DigiErrorsBadFibBCNOff.depth[zz]->update();
00759 
00760   DigiOccupancyEta->update();
00761   DigiOccupancyPhi->update();
00762   DigiOccupancyVME->update();
00763   DigiOccupancySpigot->update();
00764   DigiSize->update();
00765 
00766   // // Fill problems vs. lumi block plots
00767   // ProblemsVsLB->Fill(currentLS,count_bad);
00768   // ProblemsVsLB_HB->Fill(currentLS,hbHists.count_bad);
00769   // ProblemsVsLB_HE->Fill(currentLS,heHists.count_bad);
00770   // ProblemsVsLB_HO->Fill(currentLS,hoHists.count_bad);
00771   // ProblemsVsLB_HF->Fill(currentLS,hfHists.count_bad);
00772   // ProblemsVsLB_HBHEHF->Fill(currentLS,hbHists.count_bad+heHists.count_bad+hfHists.count_bad);
00773 
00774   // // Fill the number of problem digis in each channel
00775   // ProblemsCurrentLB->Fill(-1,-1,1);  // event counter
00776   // ProblemsCurrentLB->Fill(0,0,hbHists.count_bad);
00777   // ProblemsCurrentLB->Fill(1,0,heHists.count_bad);
00778   // ProblemsCurrentLB->Fill(2,0,hoHists.count_bad);
00779   // ProblemsCurrentLB->Fill(3,0,hfHists.count_bad);
00780   // ProblemsCurrentLB->Fill(4,0,HO0bad);
00781   // ProblemsCurrentLB->Fill(5,0,HO12bad);
00782   // ProblemsCurrentLB->Fill(6,0,HFlumibad);
00783 
00784   // Call fill method every checkNevents
00785   //fill_Nevents();
00786   
00787   return;
00788 } // void HcalDigiMonitor::processEvent(...)
00789 
00790 
00791 
00792 template <class DIGI>
00793 int HcalDigiMonitor::process_Digi(DIGI& digi, DigiHists& h, int& firstcap)
00794 {
00795   int err=0x0;
00796   bool bitUp = false;
00797   int ADCcount=0;
00798 
00799   int shapeThresh=0;
00800   
00801   int mindigisize=1;
00802   int maxdigisize=10;
00803 
00804   if (digi.id().subdet()==HcalBarrel)
00805     {
00806       shapeThresh=shapeThreshHB_;
00807       mindigisize=mindigisizeHBHE_;
00808       maxdigisize=maxdigisizeHBHE_;
00809     }
00810   else if (digi.id().subdet()==HcalEndcap)
00811     {
00812       shapeThresh=shapeThreshHE_;
00813       mindigisize=mindigisizeHBHE_;
00814       maxdigisize=maxdigisizeHBHE_;
00815     }
00816   else if (digi.id().subdet()==HcalOuter)
00817     {
00818       shapeThresh=shapeThreshHO_;
00819       mindigisize=mindigisizeHO_;
00820       maxdigisize=maxdigisizeHO_;
00821     }
00822   else if (digi.id().subdet()==HcalForward)
00823     {
00824       shapeThresh=shapeThreshHF_;
00825       mindigisize=mindigisizeHF_;
00826       maxdigisize=maxdigisizeHF_;
00827     }
00828   int iEta = digi.id().ieta();
00829   int iPhi = digi.id().iphi();
00830   int iDepth = digi.id().depth();
00831   int calcEta = CalcEtaBin(digi.id().subdet(),iEta,iDepth);
00832 
00833   // Check that digi size is correct
00834   if (digi.size()<mindigisize || digi.size()>maxdigisize)
00835     {
00836       if (digi_checkdigisize_) err|=0x1;
00837       ++baddigisize[calcEta][iPhi-1][iDepth-1];
00838     }
00839   // Check digi size; if > 20, increment highest bin of digisize array
00840   if (digi.size()<20)
00841     ++digisize[static_cast<int>(digi.size())][digi.id().subdet()-1];
00842   else
00843     ++digisize[19][digi.id().subdet()-1];
00844 
00845   // loop over time slices of digi to check capID and errors
00846   ++h.count_presample[digi.presamples()];
00847 
00848   // Check CapID rotation
00849   if (firstcap==-1) firstcap = digi.sample(0).capid();
00850   int capdif = digi.sample(0).capid() - firstcap;
00851   //capdif = capdif%3 - capdif/3; // unnecessary?
00852   // capdif should run from -3 to +3
00853   if (capdif >-4 && capdif<4)
00854     ++h.capIDdiff[capdif+3];
00855   else
00856       ++h.capIDdiff[7];
00857 
00858   int last=-1;
00859   
00860   int offset = digi.fiberIdleOffset();
00861 
00862   // Only count BCN offset errors if ExpectedOrbitMessage Time is >-1
00863   // For offline (and thus cfg default), this won't be checked, since
00864   // we can't keep up to date with changes.
00865   if (offset != -1000 && DigiMonitor_ExpectedOrbitMessageTime_>-1) 
00866     {
00867       // increment counters only for non-zero offsets?
00868       ++h.fibbcnoff[offset + 7];
00869       if (offset != 0)
00870         {
00871           ++badFibBCNOff[calcEta][iPhi-1][iDepth-1];
00872           if (shutOffOrbitTest_ == false) err |= 0xF; // not an error if test turned off
00873         }
00874     }
00875   
00876   int tssum=0;
00877 
00878   bool digi_error=false;
00879 
00880   const int DigiSize=digi.size();
00881   for (int i=0;i<10;++i) pedSubtractedADC_[i]=0;
00882   const int pedSubADCsize=sizeof(pedSubtractedADC_)/sizeof(double);
00883 
00884   std::map<HcalDetId, std::vector<double> >::iterator  foundID = PedestalsByCapId_.find(digi.id());
00885   for (int i=0;i<DigiSize;++i)
00886     {
00887       int thisCapid = digi.sample(i).capid();
00888       if (thisCapid>=0 && thisCapid<4) ++h.capid[thisCapid];
00889 
00890       if (makeDiagnostics_)
00891         {
00892           if(bitUpset(last,thisCapid)) bitUp=true; // checking capID rotation
00893           last = thisCapid;
00894           // Check for digi error bits
00895           if (digi_checkdverr_)
00896             {
00897               if(digi.sample(i).er()) err=(err|0x2);
00898               if(!digi.sample(i).dv()) err=(err|0x2);
00899             }
00900           if ((digi_error==false) && (digi.sample(i).er() || !digi.sample(i).dv()))
00901             {
00902               ++digierrorsdverr[calcEta][iPhi-1][iDepth-1];
00903               digi_error=true; // only count 1 error per digi in this plot
00904             }
00905           ++h.dverr[static_cast<int>(2*digi.sample(i).er()+digi.sample(i).dv())];
00906         } // if (makeDiagnostics_)
00907 
00908       h.count_shape[i]+=digi.sample(i).adc();
00909       
00910       // Calculate ADC sum of adjacent samples -- still necessary?
00911       if (i==digi.size()-1) continue;
00912       tssum= digi.sample(i).adc()+digi.sample(i+1).adc();
00913       if (tssum<45 && tssum>=-5)
00914         {
00915           if (iEta>0)
00916             ++h.tssumplus[tssum+5][i];
00917           else
00918             ++h.tssumminus[tssum+5][i];
00919         }
00920 
00921       if (digi.sample(i).adc()<0) ++h.adc[0];
00922       else if (digi.sample(i).adc()<200) ++h.adc[digi.sample(i).adc()];
00923       else ++h.adc[199];
00924 
00925       if (i>=pedSubADCsize) continue; // don't exceed maximum array length when checking digis
00926       
00927       if (foundID!=PedestalsByCapId_.end())
00928         {
00929           pedSubtractedADC_[i]=digi.sample(i).adc()-(foundID->second)[thisCapid];
00930           ADCcount+=(int)(digi.sample(i).adc()-(foundID->second)[thisCapid]);
00931         }
00932       else
00933         {
00934           pedSubtractedADC_[i]=digi.sample(i).adc()-3;
00935           ADCcount+=digi.sample(i).adc()-3; // default pedestal subtraction of 3 ADC counts
00936         }
00937     } // for (int i=0;i<digi.size();++i)
00938   
00939   // capid error found
00940   if(bitUp) 
00941     {
00942       if (digi_checkcapid_) err=(err|0x4);
00943       ++badcapID[calcEta][iPhi-1][iDepth-1];
00944     }
00945 
00946   // These plots generally don't get filled, unless we turn off the suppression of bad digis
00947   if (err>0)
00948     {
00949       ++h.count_bad;
00950       ++baddigis[calcEta][iPhi-1][iDepth-1];
00951       ++errorVME[static_cast<int>(2*(digi.elecId().htrSlot()+0.5*digi.elecId().htrTopBottom()))][static_cast<int>(digi.elecId().readoutVMECrateId())];
00952       ++errorSpigot[static_cast<int>(digi.elecId().spigot())][static_cast<int>(digi.elecId().dccid())];
00953 
00954       return err;
00955     }
00956 
00957   if (ADCcount<0) ADCcount=0;
00958   if (ADCcount<199)
00959     ++h.adcsum[ADCcount];
00960   else
00961     ++h.adcsum[199]; // effective overflow bin
00962 
00963   // require larger threshold to look at pulse shapes
00964   
00965   if (ADCcount>shapeThresh && passedMinBiasHLT_  && HT_HFP_>1 && HT_HFM_>1)
00966     {
00967       h.ThreshCount->Fill(0,1);
00968       if (digi.id().subdet()!=HcalOuter || isSiPM(iEta,iPhi, iDepth)==false)
00969         {
00970           for (int i=0;i<pedSubADCsize;++i)
00971             h.count_shapeThresh[i]+=pedSubtractedADC_[i];
00972         }
00973     }
00974 
00975   // occupancy plots are only filled for good histograms
00976   ++h.count_good;
00977   ++occupancyEtaPhi[calcEta][iPhi-1][iDepth-1];
00978   ++occupancyEta[iEta+41];
00979   ++occupancyPhi[iPhi-1];
00980   // htr Slots run from 0-20, incremented by 0.5 for top/bottom
00981   ++occupancyVME[static_cast<int>(2*(digi.elecId().htrSlot()+0.5*digi.elecId().htrTopBottom()))][static_cast<int>(digi.elecId().readoutVMECrateId())];
00982   ++occupancySpigot[static_cast<int>(digi.elecId().spigot())][static_cast<int>(digi.elecId().dccid())];
00983 
00984   // Pawel's code for HF timing checks -- run only in online mode for non-calib events
00985   if (digi.id().subdet()==HcalForward 
00986       && Online_  //only run online 
00987       && currenttype_==0  // require non-calibration event
00988       && passedMinBiasHLT_ // require min bias trigger
00989       )
00990     {
00991       int maxtime=-1;
00992       double maxenergy=-1, fullenergy=0;
00993       int digisize=digi.size();
00994       for (int ff=0;ff<digisize;++ff)
00995         {
00996           fullenergy+=digi.sample(ff).nominal_fC()-2.5;
00997           if (digi.sample(ff).nominal_fC()-2.5>maxenergy)
00998             {
00999               maxenergy=digi.sample(ff).nominal_fC()-2.5;
01000               maxtime=ff;
01001             }
01002         }
01003       
01004       if (maxtime>=2 && maxtime<=5 && maxenergy>20 && maxenergy<100)  // only look between time slices 2-5; anything else should be nonsense
01005         {
01006           for (int ff=0;ff<digisize;++ff){
01007             if(fullenergy>0){
01008               if(digi.id().ieta()>0)HFP_shape->Fill(ff,(digi.sample(ff).nominal_fC()-2.5)/fullenergy);
01009               if(digi.id().ieta()<0)HFM_shape->Fill(ff,(digi.sample(ff).nominal_fC()-2.5)/fullenergy);
01010             }
01011           }
01012 
01013           double time_den=0, time_num=0;
01014           // form weighted time sum
01015           int startslice=std::max(0,maxtime-1);
01016           int endslice=std::min(digisize-1,maxtime+1);
01017           for (int ss=startslice;ss<=endslice;++ss)
01018             {
01019               // subtract 'default' pedestal of 2.5 fC
01020               time_num+=ss*(digi.sample(ss).nominal_fC()-2.5);
01021               time_den+=digi.sample(ss).nominal_fC()-2.5;
01022             }
01023 
01024           int myiphi=iPhi;
01025           if (iDepth==2) ++myiphi;
01026           if (HFtiming_etaProfile!=0 && time_den!=0)
01027             HFtiming_etaProfile->Fill(iEta,time_num/time_den);
01028           if (HFtiming_totaltime2D!=0 && time_den!=0)
01029             HFtiming_totaltime2D->Fill(iEta,myiphi,time_num/time_den);
01030           if (HFtiming_occupancy2D!=0 && time_den!=0)
01031             HFtiming_occupancy2D->Fill(iEta,myiphi,1);
01032         } //maxtime>-1
01033     } // if HcalForward
01034 
01035   return err;
01036 } // template <class DIGI> int HcalDigiMonitor::process_Digi
01037 
01038 void HcalDigiMonitor::beginLuminosityBlock(const edm::LuminosityBlock& lumiSeg,
01039                                              const edm::EventSetup& c) 
01040 {
01041   HcalBaseDQMonitor::beginLuminosityBlock(lumiSeg,c);
01042   ProblemsCurrentLB->Reset();
01043 }
01044 
01045 void HcalDigiMonitor::endLuminosityBlock(const edm::LuminosityBlock& lumiSeg,
01046                                            const edm::EventSetup& c)
01047 {
01048   if (LumiInOrder(lumiSeg.luminosityBlock())==false) return;
01049 
01050   // Reset current LS histogram
01051   if (ProblemsCurrentLB)
01052     ProblemsCurrentLB->Reset();
01053   
01054   fill_Nevents();
01055 
01056   zeroCounters(); // reset counters of good/bad digis
01057  
01058   return;
01059 }
01060 
01061 void HcalDigiMonitor::fill_Nevents()
01062 {
01063   if (debug_>0)
01064     std::cout <<"<HcalDigiMonitor> Calling fill_Nevents for event  "<<tevt_<< " (processed events = "<<ievt_<<")"<<std::endl;
01065   int iPhi, iEta, iDepth;
01066   bool valid=false;
01067 
01068   // Fill problems vs. lumi block plots
01069   ProblemsVsLB->Fill(currentLS,hbHists.count_bad+heHists.count_bad+hoHists.count_bad+hfHists.count_bad);
01070   ProblemsVsLB_HB->Fill(currentLS,hbHists.count_bad);
01071   ProblemsVsLB_HE->Fill(currentLS,heHists.count_bad);
01072   ProblemsVsLB_HO->Fill(currentLS,hoHists.count_bad);
01073   ProblemsVsLB_HF->Fill(currentLS,hfHists.count_bad);
01074   ProblemsVsLB_HBHEHF->Fill(currentLS,hbHists.count_bad+heHists.count_bad+hfHists.count_bad);
01075   
01076   // Fill the number of problem digis in each channel
01077   if (ProblemsCurrentLB)
01078     {      
01079       ProblemsCurrentLB->Fill(-1,-1,1);  // event counter
01080       ProblemsCurrentLB->Fill(0,0,hbHists.count_bad);
01081       ProblemsCurrentLB->Fill(1,0,heHists.count_bad);
01082       ProblemsCurrentLB->Fill(2,0,hoHists.count_bad);
01083       ProblemsCurrentLB->Fill(3,0,hfHists.count_bad);
01084       ProblemsCurrentLB->Fill(4,0,HO0bad);
01085       ProblemsCurrentLB->Fill(5,0,HO12bad);
01086       ProblemsCurrentLB->Fill(6,0,HFlumibad);
01087     }
01088 
01089   // Fill plots of sums of adjacent digi samples
01090   for (int i=0;i<10;++i)
01091     {
01092       for (int j=0;j<50;++j)
01093         {
01094           if (hbHists.tssumplus[j][i]>0) hbHists.TS_sum_plus[i]->Fill(j, hbHists.tssumplus[j][i]);
01095           if (hbHists.tssumminus[j][i]>0) hbHists.TS_sum_minus[i]->Fill(j, hbHists.tssumminus[j][i]);     
01096           if (heHists.tssumplus[j][i]>0) heHists.TS_sum_plus[i]->Fill(j, heHists.tssumplus[j][i]); 
01097           if (heHists.tssumminus[j][i]>0) heHists.TS_sum_minus[i]->Fill(j, heHists.tssumminus[j][i]); 
01098           if (hoHists.tssumplus[j][i]>0) hoHists.TS_sum_plus[i]->Fill(j, hoHists.tssumplus[j][i]); 
01099           if (hoHists.tssumminus[j][i]>0) hoHists.TS_sum_minus[i]->Fill(j, hoHists.tssumminus[j][i]); 
01100           if (hfHists.tssumplus[j][i]>0) hfHists.TS_sum_plus[i]->Fill(j, hfHists.tssumplus[j][i]); 
01101           if (hfHists.tssumminus[j][i]>0) hfHists.TS_sum_minus[i]->Fill(j, hfHists.tssumminus[j][i]); 
01102         }
01103     } // for (int i=0;i<10;++i)
01104 
01105   for (int i=0;i<DIGI_NUM;++i)
01106     {
01107       if (diginum[i]>0) DigiNum->Fill(i, diginum[i]);
01108       if (i>=DIGI_SUBDET_NUM) continue;
01109 
01110       if (hbHists.count_BQ[i]>0) hbHists.BQ->Fill(i, hbHists.count_BQ[i]);
01111       if (heHists.count_BQ[i]>0) heHists.BQ->Fill(i, heHists.count_BQ[i]);
01112       if (hoHists.count_BQ[i]>0) hoHists.BQ->Fill(i, hoHists.count_BQ[i]);
01113       if (hfHists.count_BQ[i]>0) hfHists.BQ->Fill(i, hfHists.count_BQ[i]);
01114     }//for int i=0;i<DIGI_NUM;++i)
01115 
01116 
01117   // Fill data-valid/error plots and capid plots
01118   for (int i=0;i<4;++i)
01119     {
01120       if (hbHists.dverr[i]>0) hbHists.DVerr->Fill(i, hbHists.dverr[i]);
01121       if (heHists.dverr[i]>0) heHists.DVerr->Fill(i, heHists.dverr[i]);
01122       if (hoHists.dverr[i]>0) hoHists.DVerr->Fill(i, hoHists.dverr[i]);
01123       if (hfHists.dverr[i]>0) hfHists.DVerr->Fill(i, hfHists.dverr[i]);
01124 
01125       if (hbHists.capid[i]>0) hbHists.CapID->Fill(i, hbHists.capid[i]);
01126       if (heHists.capid[i]>0) heHists.CapID->Fill(i, heHists.capid[i]);
01127       if (hoHists.capid[i]>0) hoHists.CapID->Fill(i, hoHists.capid[i]);
01128       if (hfHists.capid[i]>0) hfHists.CapID->Fill(i, hfHists.capid[i]);
01129     }
01130 
01131   for (int i=0;i<200;++i)
01132     {
01133       if (hbHists.adc[i]>0) hbHists.ADC->Fill(i, hbHists.adc[i]);
01134 
01135       if (heHists.adc[i]>0) heHists.ADC->Fill(i, heHists.adc[i]);
01136       if (hoHists.adc[i]>0) hoHists.ADC->Fill(i, hoHists.adc[i]);
01137       if (hfHists.adc[i]>0) hfHists.ADC->Fill(i, hfHists.adc[i]);
01138 
01139       if (hbHists.adcsum[i]>0) hbHists.ADCsum->Fill(i, hbHists.adcsum[i]);
01140       if (heHists.adcsum[i]>0) heHists.ADCsum->Fill(i, heHists.adcsum[i]);
01141       if (hoHists.adcsum[i]>0) hoHists.ADCsum->Fill(i, hoHists.adcsum[i]);
01142       if (hfHists.adcsum[i]>0) hfHists.ADCsum->Fill(i, hfHists.adcsum[i]);
01143     }
01144 
01145   for (int i = 0; i < 15; ++i)
01146     {
01147       if (hbHists.fibbcnoff[i]>0) hbHists.fibBCNOff->Fill(i-7, 
01148                                                           hbHists.fibbcnoff[i]);
01149       if (heHists.fibbcnoff[i]>0) heHists.fibBCNOff->Fill(i-7, 
01150                                                           heHists.fibbcnoff[i]);
01151       if (hfHists.fibbcnoff[i]>0) hfHists.fibBCNOff->Fill(i-7, 
01152                                                           hfHists.fibbcnoff[i]);
01153       if (hoHists.fibbcnoff[i]>0) hoHists.fibBCNOff->Fill(i-7,
01154                                                           hoHists.fibbcnoff[i]);
01155     }
01156 
01157   // Fill plots of bad fraction of digis found
01158   for (int i=0;i<DIGI_BQ_FRAC_NBINS;++i)
01159     {
01160       if (DIGI_BQ_FRAC_NBINS==1) break;
01161       if (hbHists.count_BQFrac[i]>0) hbHists.BQFrac->Fill(1.*i/(DIGI_BQ_FRAC_NBINS-1), hbHists.count_BQFrac[i]);
01162       if (heHists.count_BQFrac[i]>0) heHists.BQFrac->Fill(1.*i/(DIGI_BQ_FRAC_NBINS-1), heHists.count_BQFrac[i]);
01163       if (hoHists.count_BQFrac[i]>0) 
01164         {
01165           hoHists.BQFrac->Fill(1.*i/(DIGI_BQ_FRAC_NBINS), hoHists.count_BQFrac[i]);
01166         }
01167       if (hfHists.count_BQFrac[i]>0) hfHists.BQFrac->Fill(1.*i/(DIGI_BQ_FRAC_NBINS-1), hfHists.count_BQFrac[i]);
01168     }//for (int i=0;i<DIGI_BQ_FRAC_NBINS;++i)
01169 
01170   // Fill presample plots
01171   for (int i=0;i<50;++i)
01172     {
01173       if (hbHists.count_presample[i]>0) hbHists.presample->Fill(i, hbHists.count_presample[i]);
01174       if (heHists.count_presample[i]>0) heHists.presample->Fill(i, heHists.count_presample[i]);
01175       if (hoHists.count_presample[i]>0) hoHists.presample->Fill(i, hoHists.count_presample[i]);
01176       if (hfHists.count_presample[i]>0) hfHists.presample->Fill(i, hfHists.count_presample[i]);
01177     } //for (int i=0;i<50;++i)
01178 
01179   // Fill shape plots
01180   for (int i=0;i<10;++i)
01181     {
01182       if (hbHists.count_shape[i]>0) hbHists.shape->Fill(i, hbHists.count_shape[i]);
01183       if (hbHists.count_shapeThresh[i]>0) hbHists.shapeThresh->Fill(i, hbHists.count_shapeThresh[i]);
01184       if (heHists.count_shape[i]>0) heHists.shape->Fill(i, heHists.count_shape[i]);
01185       if (heHists.count_shapeThresh[i]>0) heHists.shapeThresh->Fill(i, heHists.count_shapeThresh[i]);
01186       if (hoHists.count_shape[i]>0) hoHists.shape->Fill(i, hoHists.count_shape[i]);
01187       if (hoHists.count_shapeThresh[i]>0) hoHists.shapeThresh->Fill(i, hoHists.count_shapeThresh[i]);
01188       if (hfHists.count_shape[i]>0) hfHists.shape->Fill(i, hfHists.count_shape[i]);
01189       if (hfHists.count_shapeThresh[i]>0) hfHists.shapeThresh->Fill(i, hfHists.count_shapeThresh[i]);
01190     }//  for (int i=0;i<10;++i)
01191 
01192   // Fill capID difference plots
01193   for (int i=0;i<8;++i)
01194     {
01195       if (hbHists.capIDdiff[i]>0) hbHists.DigiFirstCapID->Fill(i, hbHists.capIDdiff[i]);
01196       if (heHists.capIDdiff[i]>0) heHists.DigiFirstCapID->Fill(i, heHists.capIDdiff[i]);
01197       if (hoHists.capIDdiff[i]>0) hoHists.DigiFirstCapID->Fill(i, hoHists.capIDdiff[i]);
01198       if (hfHists.capIDdiff[i]>0) hfHists.DigiFirstCapID->Fill(i, hfHists.capIDdiff[i]);
01199     }
01200 
01201   // Fill VME plots
01202   for (int i=0;i<40;++i)
01203     {
01204       for (int j=0;j<18;++j)
01205         {
01206           if (errorVME[i][j]>0) DigiErrorVME->Fill(i, j,errorVME[i][j]);
01207           if (occupancyVME[i][j]>0) DigiOccupancyVME->Fill(i, j,occupancyVME[i][j]);
01208         }
01209     } //for (int i=0;i<40;++i)
01210 
01211   // Fill SPIGOT plots
01212   for (int i=0;i<HcalDCCHeader::SPIGOT_COUNT;++i)
01213     {
01214       for (int j=0;j<36;++j)
01215         {
01216           if (errorSpigot[i][j]>0) DigiErrorSpigot->Fill(i, j,errorSpigot[i][j]);
01217           if (occupancySpigot[i][j]>0) DigiOccupancySpigot->Fill(i, j,occupancySpigot[i][j]);
01218         }
01219     } //for (int i=0;i<HcalDCCHeader::SPIGOT_COUNT;++i)
01220 
01221   // Loop over subdetectors
01222   for (int sub=0;sub<4;++sub)
01223     {
01224       for (int dsize=0;dsize<20;++dsize)
01225         {
01226           if (digisize[dsize][sub]>0)
01227             DigiSize->Fill(sub,dsize,digisize[dsize][sub]);
01228         }
01229     } // for (int sub=0;sub<4;++sub)
01230 
01231   // Loop over eta, phi, depth
01232   for (int d=0;d<4;++d)
01233     {
01234       iDepth=d+1;
01235       DigiErrorsByDepth.depth[d]->setBinContent(0,0,ievt_); // underflow bin contains event counter
01236       DigiOccupancyByDepth.depth[d]->setBinContent(0,0,ievt_);
01237       DigiErrorsBadDigiSize.depth[d]->setBinContent(0,0,ievt_);
01238       DigiErrorsUnpacker.depth[d]->setBinContent(0,0,ievt_);
01239       DigiErrorsBadFibBCNOff.depth[d]->setBinContent(0,0,ievt_);
01240 
01241       for (int phi=0;phi<72;++phi)
01242         {
01243           iPhi=phi+1;
01244           DigiOccupancyPhi->Fill(iPhi,occupancyPhi[phi]);
01245           for (int eta=0;eta<83;++eta)
01246             {
01247               // DigiOccupanyEta uses 'true' ieta (included the overlap at +/- 29)
01248               iEta=eta-41;
01249               if (phi==0)
01250                 DigiOccupancyEta->Fill(iEta,occupancyEta[eta]);
01251               valid=false;
01252         
01253               // HB
01254               if (validDetId(HcalBarrel, iEta, iPhi, iDepth))
01255                 {
01256                   valid=true;
01257                   if (HBpresent_)
01258                     {
01259                       int calcEta = CalcEtaBin(HcalBarrel,iEta,iDepth);
01260 
01261                       DigiOccupancyByDepth.depth[d]->Fill(iEta, iPhi,
01262                                                     occupancyEtaPhi[calcEta][phi][d]);
01263                       
01264                       if (makeDiagnostics_)
01265                         {
01266                           DigiErrorsBadCapID.depth[d]->Fill(iEta, iPhi,
01267                                                             badcapID[calcEta][phi][d]);
01268                           DigiErrorsDVErr.depth[d]->Fill(iEta, iPhi,
01269                                                          digierrorsdverr[calcEta][phi][d]);
01270                         }
01271                       DigiErrorsBadDigiSize.depth[d]->Fill(iEta, iPhi,
01272                                                            baddigisize[calcEta][phi][d]);
01273                       DigiErrorsBadFibBCNOff.depth[d]->Fill(iEta, iPhi,
01274                                                             badFibBCNOff[calcEta][phi][d]);
01275                       DigiErrorsUnpacker.depth[d]->Fill(iEta, iPhi,
01276                                                         badunpackerreport[calcEta][phi][d]);
01277                       DigiErrorsByDepth.depth[d]->Fill(iEta, iPhi,
01278                                                        baddigis[calcEta][phi][d]);
01279                       // Use this for testing purposes only
01280                       //DigiErrorsByDepth[d]->Fill(iEta, iPhi, ievt_);
01281                     } // if (HBpresent_)
01282                 } // validDetId(HB)
01283               // HE
01284               if (validDetId(HcalEndcap, iEta, iPhi, iDepth))
01285                 {
01286                   valid=true;
01287                   if (HEpresent_)
01288                     {
01289                       int calcEta = CalcEtaBin(HcalEndcap,iEta,iDepth);
01290 
01291                       DigiOccupancyByDepth.depth[d]->Fill(iEta, iPhi,
01292                                                     occupancyEtaPhi[calcEta][phi][d]);
01293                       
01294                       if (makeDiagnostics_)
01295                         {
01296                           DigiErrorsBadCapID.depth[d]->Fill(iEta, iPhi,
01297                                                             badcapID[calcEta][phi][d]);
01298                           DigiErrorsDVErr.depth[d]->Fill(iEta, iPhi,
01299                                                          digierrorsdverr[calcEta][phi][d]);
01300                         }
01301                       DigiErrorsBadDigiSize.depth[d]->Fill(iEta, iPhi,
01302                                                            baddigisize[calcEta][phi][d]);
01303                       DigiErrorsBadFibBCNOff.depth[d]->Fill(iEta, iPhi,
01304                                                             badFibBCNOff[calcEta][phi][d]);
01305                       DigiErrorsUnpacker.depth[d]->Fill(iEta, iPhi,
01306                                                         badunpackerreport[calcEta][phi][d]);
01307                       DigiErrorsByDepth.depth[d]->Fill(iEta, iPhi,
01308                                                        baddigis[calcEta][phi][d]);
01309                     } // if (HEpresent_)
01310                 } // valid HE found
01311               // HO
01312               if (validDetId(HcalOuter,iEta,iPhi,iDepth))
01313                 {
01314                   valid=true;
01315                   if (HOpresent_)
01316                     {
01317                       int calcEta = CalcEtaBin(HcalOuter,iEta,iDepth);
01318                       DigiOccupancyByDepth.depth[d]->Fill(iEta, iPhi,
01319                                                           occupancyEtaPhi[calcEta][phi][d]);
01320                       if (makeDiagnostics_)
01321                         {
01322                           DigiErrorsBadCapID.depth[d]->Fill(iEta, iPhi,
01323                                                             badcapID[calcEta][phi][d]);
01324                           DigiErrorsDVErr.depth[d]->Fill(iEta, iPhi,
01325                                                          digierrorsdverr[calcEta][phi][d]);
01326                         }
01327                       DigiErrorsBadDigiSize.depth[d]->Fill(iEta, iPhi,
01328                                                            baddigisize[calcEta][phi][d]);
01329                       DigiErrorsBadFibBCNOff.depth[d]->Fill(iEta, iPhi,
01330                                                             badFibBCNOff[calcEta][phi][d]);
01331                       DigiErrorsUnpacker.depth[d]->Fill(iEta, iPhi,
01332                                                         badunpackerreport[calcEta][phi][d]);
01333                       
01334                       DigiErrorsByDepth.depth[d]->Fill(iEta,iPhi,
01335                                                        baddigis[calcEta][phi][d]);
01336                     } // if (HOpresent_)
01337                 }//validDetId(HO)
01338               // HF
01339               if (validDetId(HcalForward,iEta,iPhi,iDepth))
01340                 {
01341                   valid=true;
01342                   if (HFpresent_)
01343                     {
01344                       int calcEta = CalcEtaBin(HcalForward,iEta,iDepth);
01345                       int zside = iEta/abs(iEta);
01346                       DigiOccupancyByDepth.depth[d]->Fill(iEta+zside, iPhi,
01347                                                     occupancyEtaPhi[calcEta][phi][d]);
01348                       
01349                       if (makeDiagnostics_)
01350                         {
01351                           DigiErrorsBadCapID.depth[d]->Fill(iEta+zside, iPhi,
01352                                                             badcapID[calcEta][phi][d]);
01353                           DigiErrorsDVErr.depth[d]->Fill(iEta+zside, iPhi,
01354                                                          digierrorsdverr[calcEta][phi][d]);
01355                         }
01356                       DigiErrorsBadDigiSize.depth[d]->Fill(iEta+zside, iPhi,
01357                                                      baddigisize[calcEta][phi][d]);
01358                       DigiErrorsBadFibBCNOff.depth[d]->Fill(iEta+zside, iPhi,
01359                                                          badFibBCNOff[calcEta][phi][d]);
01360                       DigiErrorsUnpacker.depth[d]->Fill(iEta+zside, iPhi,
01361                                                         badunpackerreport[calcEta][phi][d]);
01362                       DigiErrorsByDepth.depth[d]->Fill(iEta+zside, iPhi,
01363                                                        baddigis[calcEta][phi][d]);
01364                     } // if (HFpresent_)
01365                 }
01366             } // for (int eta=0;...)
01367         } // for (int phi=0;...)
01368     } // for (int d=0;...)
01369 
01370   // Now fill all the unphysical cell values
01371   FillUnphysicalHEHFBins(DigiErrorsByDepth);
01372   if (makeDiagnostics_)
01373     {
01374       FillUnphysicalHEHFBins(DigiErrorsBadCapID);
01375       FillUnphysicalHEHFBins(DigiErrorsDVErr);
01376     }
01377   FillUnphysicalHEHFBins(DigiErrorsBadDigiSize);
01378   FillUnphysicalHEHFBins(DigiOccupancyByDepth);
01379   FillUnphysicalHEHFBins(DigiErrorsBadFibBCNOff);
01380   FillUnphysicalHEHFBins(DigiErrorsUnpacker);
01381 
01382   //  zeroCounters(); // reset counters of good/bad digis
01383  
01384   return;
01385 } // void HcalDigiMonitor::fill_Nevents()
01386 
01387 
01388 void HcalDigiMonitor::zeroCounters()
01389 {
01390   // Set all histogram counters back to 0
01391   // Call this after all every N evnets
01392 
01393   /******** Zero all counters *******/
01394   
01395 
01396   hbHists.count_bad=0;
01397   hbHists.count_good=0;
01398   heHists.count_bad=0;
01399   heHists.count_good=0;
01400   hoHists.count_bad=0;
01401   hoHists.count_good=0;
01402   hfHists.count_bad=0;
01403   hfHists.count_good=0;
01404 
01405   HO0bad=0;
01406   HO12bad=0;
01407   HFlumibad=0;
01408 
01409   for (int i=0;i<85;++i)
01410     {
01411       occupancyEta[i]=0;
01412       if (i<72)
01413         occupancyPhi[i]=0;
01414       for (int j=0;j<72;++j)
01415         {
01416           for (int k=0;k<4;++k)
01417             {
01418               baddigis[i][j][k]=0;
01419               badcapID[i][j][k]=0;
01420               baddigisize[i][j][k]=0;
01421               occupancyEtaPhi[i][j][k]=0;
01422               digierrorsdverr[i][j][k]=0;
01423               badFibBCNOff[i][j][k]=0;
01424               badunpackerreport[i][j][k]=0;
01425             }
01426         } // for (int j=0;j<72;++i)
01427     } // for (int i=0;i<85;++i)
01428 
01429   for (int i=0;i<40;++i)
01430     {
01431       for (int j=0;j<18;++j)
01432         {
01433           occupancyVME[i][j]=0;
01434           errorVME[i][j]=0;
01435         }
01436     }
01437 
01438   for (int i=0;i<HcalDCCHeader::SPIGOT_COUNT;++i)
01439     {
01440       for (int j=0;j<36;++j)
01441         {
01442           occupancySpigot[i][j]=0;
01443           errorSpigot[i][j]=0;
01444         }
01445     }
01446 
01447 
01448   for (int i=0;i<20;++i)
01449     {
01450       for (int j=0;j<4;++j)
01451         digisize[i][j]=0;
01452     }
01453 
01454   for (int i=0;i<DIGI_NUM;++i)
01455     {
01456       diginum[i]=0;
01457       
01458       // set all DigiHists counters to 0
01459       if (i<4)
01460         {
01461           hbHists.dverr[i]=0;
01462           heHists.dverr[i]=0;
01463           hoHists.dverr[i]=0;
01464           hfHists.dverr[i]=0;
01465           hbHists.capid[i]=0;
01466           heHists.capid[i]=0;
01467           hoHists.capid[i]=0;
01468           hfHists.capid[i]=0;
01469         }
01470       if (i<8)
01471         {
01472           hbHists.capIDdiff[i]=0;
01473           heHists.capIDdiff[i]=0;
01474           hoHists.capIDdiff[i]=0;
01475           hfHists.capIDdiff[i]=0;
01476         }
01477 
01478       if (i<10)
01479         {
01480           hbHists.count_shape[i]=0;
01481           heHists.count_shape[i]=0;
01482           hoHists.count_shape[i]=0;
01483           hfHists.count_shape[i]=0;
01484          
01485           hbHists.count_shapeThresh[i]=0;
01486           heHists.count_shapeThresh[i]=0;
01487           hoHists.count_shapeThresh[i]=0;
01488           hfHists.count_shapeThresh[i]=0;
01489         }
01490       if (i<50)
01491         {
01492           hbHists.count_presample[i]=0;
01493           heHists.count_presample[i]=0;
01494           hoHists.count_presample[i]=0;
01495           hfHists.count_presample[i]=0;
01496           for (int j=0;j<10;++j)
01497             {
01498               hbHists.tssumplus[i][j]=0;
01499               heHists.tssumplus[i][j]=0;
01500               hoHists.tssumplus[i][j]=0;
01501               hfHists.tssumplus[i][j]=0;
01502               hbHists.tssumminus[i][j]=0;
01503               heHists.tssumminus[i][j]=0;
01504               hoHists.tssumminus[i][j]=0;
01505               hfHists.tssumminus[i][j]=0;
01506             }
01507         }
01508 
01509       if (i<15)
01510         {
01511           hbHists.fibbcnoff[i]=0;
01512           heHists.fibbcnoff[i]=0;
01513           hoHists.fibbcnoff[i]=0;
01514           hfHists.fibbcnoff[i]=0;
01515         }
01516 
01517       if (i<200)
01518         {
01519           hbHists.adc[i]=0;
01520           heHists.adc[i]=0;
01521           hoHists.adc[i]=0;
01522           hfHists.adc[i]=0;
01523           hbHists.adcsum[i]=0;
01524           heHists.adcsum[i]=0;
01525           hoHists.adcsum[i]=0;
01526           hfHists.adcsum[i]=0;
01527         }
01528       if (i<DIGI_SUBDET_NUM)
01529         {
01530           hbHists.count_BQ[i]=0;
01531           heHists.count_BQ[i]=0;
01532           hoHists.count_BQ[i]=0;
01533           hfHists.count_BQ[i]=0;
01534         }
01535       if (i<DIGI_BQ_FRAC_NBINS)
01536         {
01537           hbHists.count_BQFrac[i]=0;
01538           heHists.count_BQFrac[i]=0;
01539           hoHists.count_BQFrac[i]=0;
01540           hfHists.count_BQFrac[i]=0;
01541         }
01542     } // for (int i=0;i<DIGI_NUM;++i)
01543 
01544 
01545   return;
01546 }
01547 
01548 void HcalDigiMonitor::UpdateHists(DigiHists& h)
01549 {
01550   // call update command for all histograms (should make them update when running in online DQM?)
01551   h.shape->update();
01552   h.shapeThresh->update();
01553   h.presample->update();
01554   h.BQ->update();
01555   h.BQFrac->update();
01556   h.DigiFirstCapID->update();
01557   h.DVerr->update();
01558   h.CapID->update();
01559   h.ADC->update();
01560   h.ADCsum->update();
01561   h.fibBCNOff->update();
01562 
01563   for (unsigned int i=0;i<h.TS_sum_plus.size();++i)
01564     h.TS_sum_plus[i]->update();
01565   for (unsigned int i=0;i<h.TS_sum_minus.size();++i)
01566     h.TS_sum_minus[i]->update();
01567 } //void HcalDigiMonitor::UpdateHists(DigiHists& h)
01568 
01569 
01570 void HcalDigiMonitor::reset()
01571 {
01572   // reset the temporary histograms
01573   zeroCounters();
01574   
01575   // then reset the MonitorElements
01576 
01577   DigiErrorsByDepth.Reset();
01578   DigiErrorsBadCapID.Reset();
01579   DigiErrorsDVErr.Reset();
01580   DigiErrorsBadDigiSize.Reset();
01581   DigiErrorsBadADCSum.Reset();
01582   DigiErrorsUnpacker.Reset();
01583   DigiErrorsBadFibBCNOff.Reset();
01584   DigiOccupancyByDepth.Reset();
01585   DigiErrorOccupancyByDepth.Reset();
01586 
01587   DigiOccupancyEta->Reset();
01588   DigiOccupancyPhi->Reset();
01589   DigiOccupancyVME->Reset();
01590   DigiOccupancySpigot->Reset();
01591   DigiErrorVME->Reset();
01592   DigiErrorSpigot->Reset();
01593   
01594   DigiBQ->Reset();
01595   DigiBQFrac->Reset();
01596   DigiUnpackerErrorCount->Reset();
01597   DigiUnpackerErrorFrac->Reset();
01598 
01599   DigiNum->Reset();
01600 
01601   hbHists.shape->Reset();
01602   hbHists.shapeThresh->Reset();
01603   hbHists.presample->Reset();
01604   hbHists.BQ->Reset();
01605   hbHists.BQFrac->Reset();
01606   hbHists.DigiFirstCapID->Reset();
01607   hbHists.DVerr->Reset();
01608   hbHists.CapID->Reset();
01609   hbHists.ADC->Reset();
01610   hbHists.ADCsum->Reset();
01611   hbHists.fibBCNOff->Reset();
01612   for (unsigned int i=0;i<hbHists.TS_sum_plus.size();++i)
01613     hbHists.TS_sum_plus[i]->Reset();
01614   for (unsigned int i=0;i<hbHists.TS_sum_minus.size();++i)
01615     hbHists.TS_sum_minus[i]->Reset();
01616 
01617   heHists.shape->Reset();
01618   heHists.shapeThresh->Reset();
01619   heHists.presample->Reset();
01620   heHists.BQ->Reset();
01621   heHists.BQFrac->Reset();
01622   heHists.DigiFirstCapID->Reset();
01623   heHists.DVerr->Reset();
01624   heHists.CapID->Reset();
01625   heHists.ADC->Reset();
01626   heHists.ADCsum->Reset();
01627   heHists.fibBCNOff->Reset();
01628   for (unsigned int i=0;i<heHists.TS_sum_plus.size();++i)
01629     heHists.TS_sum_plus[i]->Reset();
01630   for (unsigned int i=0;i<heHists.TS_sum_minus.size();++i)
01631     heHists.TS_sum_minus[i]->Reset();
01632 
01633   hoHists.shape->Reset();
01634   hoHists.shapeThresh->Reset();
01635   hoHists.presample->Reset();
01636   hoHists.BQ->Reset();
01637   hoHists.BQFrac->Reset();
01638   hoHists.DigiFirstCapID->Reset();
01639   hoHists.DVerr->Reset();
01640   hoHists.CapID->Reset();
01641   hoHists.ADC->Reset();
01642   hoHists.ADCsum->Reset();
01643   hoHists.fibBCNOff->Reset();
01644   for (unsigned int i=0;i<hoHists.TS_sum_plus.size();++i)
01645     hoHists.TS_sum_plus[i]->Reset();
01646   for (unsigned int i=0;i<hoHists.TS_sum_minus.size();++i)
01647     hoHists.TS_sum_minus[i]->Reset();
01648 
01649   hfHists.shape->Reset();
01650   hfHists.shapeThresh->Reset();
01651   hfHists.presample->Reset();
01652   hfHists.BQ->Reset();
01653   hfHists.BQFrac->Reset();
01654   hfHists.DigiFirstCapID->Reset();
01655   hfHists.DVerr->Reset();
01656   hfHists.CapID->Reset();
01657   hfHists.ADC->Reset();
01658   hfHists.ADCsum->Reset();
01659   hfHists.fibBCNOff->Reset();
01660   for (unsigned int i=0;i<hfHists.TS_sum_plus.size();++i)
01661     hfHists.TS_sum_plus[i]->Reset();
01662   for (unsigned int i=0;i<hfHists.TS_sum_minus.size();++i)
01663     hfHists.TS_sum_minus[i]->Reset();
01664 
01665   return;
01666 }
01667 DEFINE_FWK_MODULE(HcalDigiMonitor);
01668