CMS 3D CMS Logo

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