CMS 3D CMS Logo

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