CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_6/src/DQM/HLTEvF/plugins/OccupancyPlotter.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Package:    OccupancyPlotter
00004 // Class:      OccupancyPlotter
00005 // 
00013 //
00014 // Original Author:  Jason Michael Slaunwhite,512 1-008,`+41227670494,
00015 //         Created:  Fri Aug  5 10:34:47 CEST 2011
00016 // $Id: OccupancyPlotter.cc,v 1.14 2012/04/05 19:52:43 halil Exp $
00017 //
00018 //
00019 
00020 // system include files
00021 #include <memory>
00022 
00023 // user include files
00024 #include "DQMServices/Core/interface/DQMStore.h"
00025 #include "DQMServices/Core/interface/MonitorElement.h"
00026 
00027 #include "DataFormats/Common/interface/TriggerResults.h"
00028 #include "DataFormats/HLTReco/interface/TriggerObject.h"
00029 #include "DataFormats/HLTReco/interface/TriggerEvent.h"
00030 #include "DataFormats/HLTReco/interface/TriggerTypeDefs.h"
00031 #include "DataFormats/Scalers/interface/DcsStatus.h"
00032 #include "DataFormats/Scalers/interface/LumiScalers.h"
00033 
00034 
00035 #include "FWCore/Framework/interface/Frameworkfwd.h"
00036 #include "FWCore/Framework/interface/EDAnalyzer.h"
00037 #include "FWCore/Framework/interface/Event.h"
00038 #include "FWCore/Framework/interface/MakerMacros.h"
00039 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00040 #include "FWCore/ServiceRegistry/interface/Service.h"
00041 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00042 
00043 #include "HLTrigger/HLTcore/interface/HLTConfigProvider.h"
00044 
00045 #include "TMath.h"
00046 
00047 #include "TStyle.h"
00048 //
00049 // class declaration
00050 //
00051 
00052 using namespace edm;
00053 using namespace trigger;
00054 using std::vector;
00055 using std::string;
00056 
00057 
00058 class OccupancyPlotter : public edm::EDAnalyzer {
00059    public:
00060       explicit OccupancyPlotter(const edm::ParameterSet&);
00061       ~OccupancyPlotter();
00062 
00063   //static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
00064 
00065 
00066    private:
00067       virtual void beginJob() ;
00068       virtual void analyze(const edm::Event&, const edm::EventSetup&);
00069       virtual void endJob() ;
00070 
00071       virtual void beginRun(edm::Run const&, edm::EventSetup const&);
00072       virtual void endRun(edm::Run const&, edm::EventSetup const&);
00073       virtual void beginLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&);
00074       virtual void endLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&);
00075       virtual void setupHltMatrix(std::string, int);
00076   virtual void fillHltMatrix(std::string, std::string, double, double, bool);
00077 
00078   // a method to unpack the dcs info
00079   bool checkDcsInfo (const edm::Event & jEvent);
00080 
00081   void checkLumiInfo (const edm::Event & jEvent);
00082 
00083   // ----------member data ---------------------------
00084 
00085 
00086   bool debugPrint;
00087   bool outputPrint;
00088 
00089   std::string plotDirectoryName;
00090 
00091   DQMStore * dbe;
00092 
00093   HLTConfigProvider hltConfig_;
00094 
00095   vector< vector<string> > PDsVectorPathsVector;
00096 
00097   // Lumi info
00098   float _instLumi;
00099   float _instLumi_err;
00100   float _pileup;
00101 
00102   // Store the HV info
00103   bool dcs[25];
00104   bool thisiLumiValue;
00105 
00106   // counters
00107   int cntevt;
00108   int cntBadHV;
00109 
00110   // histograms
00111   TH1F * hist_LumivsLS;
00112   TH1F * hist_PUvsLS;
00113   
00114 };
00115 
00116 //
00117 // constants, enums and typedefs
00118 //
00119 
00120 //
00121 // static data member definitions
00122 //
00123 
00124 //
00125 // constructors and destructor
00126 //
00127 OccupancyPlotter::OccupancyPlotter(const edm::ParameterSet& iConfig)
00128 
00129 {
00130    //now do what ever initialization is needed
00131 
00132   debugPrint = false;
00133   outputPrint = false;
00134   thisiLumiValue = false;
00135   cntevt=0;
00136   cntBadHV=0;
00137   if (debugPrint) std::cout << "Inside Constructor" << std::endl;
00138 
00139   plotDirectoryName = iConfig.getUntrackedParameter<std::string>("dirname", "HLT/Test");
00140 
00141   if (debugPrint) std::cout << "Got plot dirname = " << plotDirectoryName << std::endl;
00142 
00143 
00144 }
00145 
00146 
00147 OccupancyPlotter::~OccupancyPlotter()
00148 {
00149  
00150    // do anything here that needs to be done at desctruction time
00151    // (e.g. close files, deallocate resources etc.)
00152 
00153 }
00154 
00155 
00156 //
00157 // member functions
00158 //
00159 
00160 // ------------ method called for each event  ------------
00161 void
00162 OccupancyPlotter::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup)
00163 {
00164    using namespace edm;
00165    using std::string;
00166    int lumisection = (int)iEvent.luminosityBlock();
00167 
00168    if (debugPrint) std::cout << "Inside analyze" << std::endl;
00169    ++cntevt;
00170    if (cntevt % 10000 == 0) std::cout << "[OccupancyPlotter::analyze] Received event " << cntevt << std::endl;
00171    // === Check the HV and the lumi
00172    bool highVoltageOK = checkDcsInfo ( iEvent );
00173    if (!highVoltageOK) {
00174       if (debugPrint) std::cout << "Skipping event: DCS problem\n";
00175       ++cntBadHV;
00176       return; 
00177    } 
00178    checkLumiInfo( iEvent);
00179 
00180    if (debugPrint) std::cout << "instantaneous luminosity=" << _instLumi << " ± " << _instLumi_err << std::endl;
00181 
00182    if (thisiLumiValue){
00183      thisiLumiValue = false;
00184      std::cout << "LS = " << lumisection << ", Lumi = " << _instLumi << " ± " << _instLumi_err << ", pileup = " << _pileup << std::endl;
00185 
00186      hist_LumivsLS = dbe->get("HLT/OccupancyPlots/HLT_LumivsLS")->getTH1F();
00187      hist_LumivsLS->SetBinContent(lumisection+1,_instLumi);
00188      hist_LumivsLS->SetBinError(lumisection+1,_instLumi_err);
00189      //
00190      hist_PUvsLS = dbe->get("HLT/OccupancyPlots/HLT_PUvsLS")->getTH1F();
00191      hist_PUvsLS->SetBinContent(lumisection+1,_pileup);
00192 
00193    }
00194 
00195     // Access Trigger Results
00196    edm::Handle<edm::TriggerResults> triggerResults;
00197    iEvent.getByLabel(InputTag("TriggerResults","", "HLT"), triggerResults);
00198    
00199    if (!triggerResults.isValid()) {
00200      if (debugPrint) std::cout << "Trigger results not valid" << std::endl;
00201      return; }
00202 
00203     if (debugPrint) std::cout << "Found triggerResults" << std::endl;
00204 
00205    edm::Handle<trigger::TriggerEvent>         aodTriggerEvent;   
00206    iEvent.getByLabel(InputTag("hltTriggerSummaryAOD", "", "HLT"), aodTriggerEvent);
00207    
00208    if ( !aodTriggerEvent.isValid() ) { 
00209      if (debugPrint) std::cout << "No AOD trigger summary found! Returning..."; 
00210      return; 
00211    }
00212 
00213    const TriggerObjectCollection objects = aodTriggerEvent->getObjects();
00214 
00215 
00216    vector<string> datasetNames =  hltConfig_.streamContent("A");
00217 // Loop over PDs
00218    for (unsigned int iPD = 0; iPD < datasetNames.size(); iPD++) { 
00219 
00220      //     if (datasetNames[iPD] != "SingleMu" && datasetNames[iPD] != "SingleElectron" && datasetNames[iPD] != "Jet") continue;  
00221 
00222      unsigned int keyTracker[1000]; // Array to eliminate double counts by tracking what Keys have already been fired
00223    for(unsigned int irreproduceableIterator = 0; irreproduceableIterator < 1000; irreproduceableIterator++) {
00224      keyTracker[irreproduceableIterator] = 1001;
00225    }
00226 // Loop over Paths in each PD
00227    for (unsigned int iPath = 0; iPath < PDsVectorPathsVector[iPD].size(); iPath++) { //Andrew - where does PDsVectorPathsVector get defined?
00228      
00229      std::string pathName = PDsVectorPathsVector[iPD][iPath];
00230 
00231      if (debugPrint) std::cout << "Looking at path " << pathName << std::endl;
00232      
00233      unsigned int index = hltConfig_.triggerIndex(pathName);
00234      
00235      if (debugPrint) std::cout << "Index = " << index << " triggerResults->size() = " << triggerResults->size() << std::endl;
00236 
00237      if (index < triggerResults->size()) {
00238        if(triggerResults->accept(index)) {
00239 
00240          if (debugPrint) std::cout << "We fired path " << pathName << std::endl;
00241 
00242          // look up module labels for this path
00243 
00244          vector<std::string> modulesThisPath = hltConfig_.moduleLabels(pathName);
00245 
00246          if (debugPrint) std::cout << "Looping over module labels " << std::endl;
00247 
00248          // Loop backward through module names
00249          for ( int iModule = (modulesThisPath.size()-1); iModule >= 0; iModule--) {
00250 
00251            if (debugPrint) std::cout << "Module name is " << modulesThisPath[iModule] << std::endl;
00252 
00253            // check to see if you have savetags information
00254            if (hltConfig_.saveTags(modulesThisPath[iModule])) {
00255 
00256              if (debugPrint) std::cout << "For path " << pathName << " this module " << modulesThisPath[iModule] <<" is a saveTags module of type " << hltConfig_.moduleType(modulesThisPath[iModule]) << std::endl;
00257 
00258              if (hltConfig_.moduleType(modulesThisPath[iModule]) == "HLTLevel1GTSeed") break;
00259 
00260              InputTag moduleWhoseResultsWeWant(modulesThisPath[iModule], "", "HLT");
00261 
00262              unsigned int indexOfModuleInAodTriggerEvent = aodTriggerEvent->filterIndex(moduleWhoseResultsWeWant);
00263 
00264              if ( indexOfModuleInAodTriggerEvent < aodTriggerEvent->sizeFilters() ) {
00265                const Keys &keys = aodTriggerEvent->filterKeys( indexOfModuleInAodTriggerEvent );
00266                if (debugPrint) std::cout << "Got Keys for index " << indexOfModuleInAodTriggerEvent <<", size of keys is " << keys.size() << std::endl;
00267                
00268                for ( size_t iKey = 0; iKey < keys.size(); iKey++ ) {
00269                  TriggerObject foundObject = objects[keys[iKey]];
00270                  bool first_count = false;
00271 
00272                  if(keyTracker[iKey] != iKey) first_count = true;
00273                         
00274                  if (debugPrint || outputPrint) std::cout << "This object has (pt, eta, phi) = "
00275                                                           << std::setw(10) << foundObject.pt()
00276                                                           << ", " << std::setw(10) << foundObject.eta() 
00277                                                           << ", " << std::setw(10) << foundObject.phi()
00278                                                           << "    for path = " << std::setw(20) << pathName
00279                                                           << " module " << std::setw(40) << modulesThisPath[iModule]
00280                                                           << " iKey " << iKey << std::endl;
00281 
00282                  fillHltMatrix(datasetNames[iPD],pathName,foundObject.eta(),foundObject.phi(),first_count);
00283                       
00284                  keyTracker[iKey] = iKey;
00285                  
00286 
00287                }// end for each key               
00288              }// end if filter in aodTriggerEvent
00289              
00290 
00291              // OK, we found the last module. No need to look at the others.
00292              // get out of the loop
00293 
00294              break;
00295            }// end if saveTags
00296          }//end Loop backward through module names   
00297        }// end if(triggerResults->accept(index))
00298      }// end if (index < triggerResults->size())
00299    }// end Loop over Paths in each PD
00300    }//end Loop over PDs
00301 
00302 
00303    
00304 
00305 }
00306 
00307 
00308 // ------------ method called once each job just before starting event loop  ------------
00309 void 
00310 OccupancyPlotter::beginJob()
00311 {
00312 
00313   if (debugPrint) std::cout << "Inside begin job" << std::endl; 
00314 
00315   dbe = Service<DQMStore>().operator->();
00316 
00317   if (dbe) {
00318 
00319     dbe->setCurrentFolder(plotDirectoryName);
00320 
00321   }
00322 
00323 }
00324 
00325 // ------------ method called once each job just after ending the event loop  ------------
00326 void 
00327 OccupancyPlotter::endJob() 
00328 {
00329 }
00330 
00331 // ------------ method called when starting to processes a run  ------------
00332 void 
00333 OccupancyPlotter::beginRun(edm::Run const& iRun, edm::EventSetup const& iSetup)
00334 {
00335 
00336   if (debugPrint) std::cout << "Inside beginRun" << std::endl;
00337 
00338   bool changed = true;
00339   if (hltConfig_.init(iRun, iSetup, "HLT", changed)) {
00340     if(debugPrint)
00341       if(debugPrint) std::cout << "HLT config with process name " 
00342                 << "HLT" << " successfully extracted" << std::endl;
00343   } else {
00344     if (debugPrint)
00345       if (debugPrint) std::cout << "Warning, didn't find process HLT" << std::endl;
00346   }
00347 
00348   vector<string> datasetNames =  hltConfig_.streamContent("A");
00349   for (unsigned int i=0;i<datasetNames.size();i++) {
00350 
00351     if (debugPrint) std::cout << "This is dataset " << datasetNames[i] <<std::endl;
00352 
00353     vector<string> datasetPaths = hltConfig_.datasetContent(datasetNames[i]);
00354 
00355     if (debugPrint) std::cout << "datasetPaths.size() = " << datasetPaths.size() << std::endl;
00356 
00357     PDsVectorPathsVector.push_back(datasetPaths);
00358 
00359     if (debugPrint) std::cout <<"Found PD: " << datasetNames[i]  << std::endl;     
00360     setupHltMatrix(datasetNames[i],i);   
00361     int maxLumisection=1000;
00362     dbe->setCurrentFolder("HLT/OccupancyPlots/");
00363     hist_LumivsLS = new TH1F("HLT_LumivsLS", "; Lumisection; Instantaneous Luminosity (cm^{-2} s^{-1})",maxLumisection,0,maxLumisection);
00364     dbe->book1D("HLT_LumivsLS", hist_LumivsLS);
00365     hist_PUvsLS = new TH1F("HLT_PUvsLS", "; Lumisection; Pileup",maxLumisection,0,maxLumisection);
00366     dbe->book1D("HLT_PUvsLS", hist_PUvsLS);
00367 
00368   }// end of loop over dataset names
00369 
00370 }// end of beginRun
00371 
00372 // ------------ method called when ending the processing of a run  ------------
00373 void OccupancyPlotter::endRun(edm::Run const&, edm::EventSetup const&)
00374 {
00375    std::cout << "[OccupancyPlotter::endRun] Total events received=" << cntevt << ", events with HV problem=" << cntBadHV << std::endl;
00376 }
00377 
00378 void OccupancyPlotter::setupHltMatrix(std::string label, int iPD) {
00379 
00380 std::string h_name;
00381 std::string h_title;
00382 std::string h_name_1dEta;
00383 std::string h_name_1dPhi;
00384 std::string h_title_1dEta;
00385 std::string h_title_1dPhi;
00386 std::string h_name_1dEtaPath;
00387 std::string h_name_1dPhiPath;
00388 std::string h_title_1dEtaPath;
00389 std::string h_title_1dPhiPath;
00390 std::string pathName;
00391 std::string PD_Folder;
00392 std::string Path_Folder;
00393 
00394 PD_Folder = TString("HLT/OccupancyPlots");
00395 if (label != "SingleMu" && label != "SingleElectron" && label != "Jet")  PD_Folder = TString("HLT/OccupancyPlots/"+label); 
00396 
00397 dbe->setCurrentFolder(PD_Folder.c_str());
00398 
00399 h_name = "HLT_"+label+"_EtaVsPhi";
00400 h_title = "HLT_"+label+"_EtaVsPhi; eta; phi";
00401 h_name_1dEta = "HLT_"+label+"_1dEta";
00402 h_name_1dPhi = "HLT_"+label+"_1dPhi";
00403 h_title_1dEta = label+" Occupancy Vs Eta";
00404 h_title_1dPhi = label+" Occupancy Vs Phi";
00405 //Int_t numBinsEta = 12;
00406 //Int_t numBinsPhi = 8;
00407 Int_t numBinsEta = 30;
00408 Int_t numBinsPhi = 34;
00409 Int_t numBinsEtaFine = 60;
00410 Int_t numBinsPhiFine = 66;
00411 Double_t EtaMax = 2.610;
00412 Double_t PhiMax = 17.0*TMath::Pi()/16.0;
00413 Double_t PhiMaxFine = 33.0*TMath::Pi()/32.0;
00414 
00415   //Double_t eta_bins[] = {-2.610,-2.349,-2.088,-1.827,-1.740,-1.653,-1.566,-1.479,-1.392,-1.305,-1.044,-0.783,-0.522,-0.261,0,0.261,0.522,0.783,1.044,1.305,1.392,1.479,1.566,1.653,1.740,1.827,2.088,2.349,2.610}; //Has narrower bins in Barrel/Endcap border region
00416 //Double_t eta_bins[] = {-2.610,-2.175,-1.740,-1.305,-0.870,-0.435,0,0.435,0.870,1.305,1.740,2.175,2.610};
00417 //Double_t phi_bins[] = {-TMath::Pi(),-3*TMath::Pi()/4,-TMath::Pi()/2,-TMath::Pi()/4,0,TMath::Pi()/4,TMath::Pi()/2,3*TMath::Pi()/4,TMath::Pi()};
00418 
00419  TH2F * hist_EtaVsPhi = new TH2F(h_name.c_str(),h_title.c_str(),numBinsEta,-EtaMax,EtaMax,numBinsPhi,-PhiMax,PhiMax);
00420  TH1F * hist_1dEta = new TH1F(h_name_1dEta.c_str(),h_title_1dEta.c_str(),numBinsEtaFine,-EtaMax,EtaMax);
00421  TH1F * hist_1dPhi = new TH1F(h_name_1dPhi.c_str(),h_title_1dPhi.c_str(),numBinsPhiFine,-PhiMaxFine,PhiMaxFine);
00422 
00423  hist_EtaVsPhi->SetMinimum(0);
00424  hist_1dEta->SetMinimum(0);
00425  hist_1dPhi->SetMinimum(0);
00426 
00427 dbe->book2D(h_name.c_str(),hist_EtaVsPhi);
00428 dbe->book1D(h_name_1dEta.c_str(),hist_1dEta);
00429 dbe->book1D(h_name_1dPhi.c_str(),hist_1dPhi);
00430 
00431   for (unsigned int iPath = 0; iPath < PDsVectorPathsVector[iPD].size(); iPath++) { 
00432     pathName = PDsVectorPathsVector[iPD][iPath];
00433     h_name_1dEtaPath = "HLT_"+pathName+"_1dEta";
00434     h_name_1dPhiPath = "HLT_"+pathName+"_1dPhi";
00435     h_title_1dEtaPath = pathName+" Occupancy Vs Eta";
00436     h_title_1dPhiPath = pathName+"Occupancy Vs Phi";
00437     Path_Folder = TString("HLT/OccupancyPlots/"+label+"/Paths");
00438     dbe->setCurrentFolder(Path_Folder.c_str());
00439 
00440     dbe->book1D(h_name_1dEtaPath.c_str(),h_title_1dEtaPath.c_str(),numBinsEtaFine,-EtaMax,EtaMax);
00441     dbe->book1D(h_name_1dPhiPath.c_str(),h_title_1dPhiPath.c_str(),numBinsPhiFine,-PhiMaxFine,PhiMaxFine);
00442   
00443     if (debugPrint) std::cout << "book1D for " << pathName << std::endl;
00444   }
00445    
00446  if (debugPrint) std::cout << "Success setupHltMatrix( " << label << " , " << iPD << " )" << std::cout;
00447 } //End setupHltMatrix
00448 
00449 void OccupancyPlotter::fillHltMatrix(std::string label, std::string path,double Eta, double Phi, bool first_count) {
00450 
00451   if (debugPrint) std::cout << "Inside fillHltMatrix( " << label << " , " << path << " ) " << std::endl;
00452 
00453   std::string fullPathToME;
00454   std::string fullPathToME1dEta;
00455   std::string fullPathToME1dPhi;
00456   std::string fullPathToME1dEtaPath;
00457   std::string fullPathToME1dPhiPath;
00458 
00459  fullPathToME = "HLT/OccupancyPlots/HLT_"+label+"_EtaVsPhi"; 
00460  fullPathToME1dEta = "HLT/OccupancyPlots/HLT_"+label+"_1dEta";
00461  fullPathToME1dPhi = "HLT/OccupancyPlots/HLT_"+label+"_1dPhi";
00462 
00463 if (label != "SingleMu" && label != "SingleElectron" && label != "Jet") {
00464  fullPathToME = "HLT/OccupancyPlots/"+label+"/HLT_"+label+"_EtaVsPhi"; 
00465  fullPathToME1dEta = "HLT/OccupancyPlots/"+label+"/HLT_"+label+"_1dEta";
00466  fullPathToME1dPhi = "HLT/OccupancyPlots/"+label+"/HLT_"+label+"_1dPhi";
00467  }
00468  
00469  fullPathToME1dEtaPath = "HLT/OccupancyPlots/"+label+"/Paths/HLT_"+path+"_1dEta";
00470  fullPathToME1dPhiPath = "HLT/OccupancyPlots/"+label+"/Paths/HLT_"+path+"_1dPhi";
00471 
00472   if (debugPrint) std::cout << "fullPathToME = " << std::endl;
00473 
00474   MonitorElement * ME_2d = dbe->get(fullPathToME);
00475   MonitorElement * ME_1dEta = dbe->get(fullPathToME1dEta);
00476   MonitorElement * ME_1dPhi = dbe->get(fullPathToME1dPhi);  
00477   MonitorElement * ME_1dEtaPath = dbe->get(fullPathToME1dEtaPath);
00478   MonitorElement * ME_1dPhiPath = dbe->get(fullPathToME1dPhiPath);
00479 
00480   if (debugPrint) std::cout << "MonitorElement * " << std::endl;
00481 
00482   TH2F * hist_2d = ME_2d->getTH2F();
00483   TH1F * hist_1dEta = ME_1dEta->getTH1F();
00484   TH1F * hist_1dPhi = ME_1dPhi->getTH1F();
00485   TH1F * hist_1dEtaPath = ME_1dEtaPath->getTH1F();
00486   TH1F * hist_1dPhiPath = ME_1dPhiPath->getTH1F();
00487 
00488   if (debugPrint) std::cout << "TH2F *" << std::endl;
00489 
00490   //int i=2;
00491   //if (Eta>1.305 && Eta<1.872) i=0;
00492   //if (Eta<-1.305 && Eta>-1.872) i=0;
00493   //for (int ii=i; ii<3; ++ii) hist_2d->Fill(Eta,Phi); //Scales narrow bins in Barrel/Endcap border region
00494 
00495   if(first_count) {
00496     hist_1dEta->Fill(Eta);
00497     hist_1dPhi->Fill(Phi); 
00498     hist_2d->Fill(Eta,Phi); }
00499     hist_1dEtaPath->Fill(Eta); 
00500     hist_1dPhiPath->Fill(Phi);
00501 
00502  if (debugPrint) std::cout << "hist->Fill" << std::endl;
00503 
00504 } //End fillHltMatrix
00505 
00506 //=========================================================
00507 
00508 bool OccupancyPlotter::checkDcsInfo (const edm::Event & jEvent) {
00509 
00510   //Copy of code from DQMServices/Components/src/DQMDcsInfo.cc
00511 
00512   edm::Handle<DcsStatusCollection> dcsStatus;
00513   if ( ! jEvent.getByLabel("hltScalersRawToDigi", dcsStatus) )
00514     {
00515       std::cout  << "[OccupancyPlotter::checkDcsInfo] Could not get scalersRawToDigi by label\n" ;
00516       for (int i=0;i<24;i++) dcs[i]=false;
00517       return false;
00518     }//if (debugPrint) 
00519 
00520   if ( ! dcsStatus.isValid() ) 
00521     {
00522       std::cout  << "[OccupancyPlotter::checkDcsInfo] scalersRawToDigi not valid\n" ;
00523       for (int i=0;i<24;i++) dcs[i]=false; // info not available: set to false
00524       return false;
00525     }
00526   
00527   // initialize all to "true"
00528   for (int i=0; i<24; i++) dcs[i]=true;
00529   
00530   for (DcsStatusCollection::const_iterator dcsStatusItr = dcsStatus->begin(); 
00531        dcsStatusItr != dcsStatus->end(); ++dcsStatusItr) 
00532     {
00533       
00534       if (debugPrint) std::cout << (*dcsStatusItr) << std::endl;
00535       
00536       if (!dcsStatusItr->ready(DcsStatus::CSCp))   dcs[0]=false;
00537       if (!dcsStatusItr->ready(DcsStatus::CSCm))   dcs[1]=false;   
00538       if (!dcsStatusItr->ready(DcsStatus::DT0))    dcs[2]=false;
00539       if (!dcsStatusItr->ready(DcsStatus::DTp))    dcs[3]=false;
00540       if (!dcsStatusItr->ready(DcsStatus::DTm))    dcs[4]=false;
00541       if (!dcsStatusItr->ready(DcsStatus::EBp))    dcs[5]=false;
00542       if (!dcsStatusItr->ready(DcsStatus::EBm))    dcs[6]=false;
00543       if (!dcsStatusItr->ready(DcsStatus::EEp))    dcs[7]=false;
00544       if (!dcsStatusItr->ready(DcsStatus::EEm))    dcs[8]=false;
00545       if (!dcsStatusItr->ready(DcsStatus::ESp))    dcs[9]=false;
00546       if (!dcsStatusItr->ready(DcsStatus::ESm))    dcs[10]=false; 
00547       if (!dcsStatusItr->ready(DcsStatus::HBHEa))  dcs[11]=false;
00548       if (!dcsStatusItr->ready(DcsStatus::HBHEb))  dcs[12]=false;
00549       if (!dcsStatusItr->ready(DcsStatus::HBHEc))  dcs[13]=false; 
00550       if (!dcsStatusItr->ready(DcsStatus::HF))     dcs[14]=false;
00551 //      if (!dcsStatusItr->ready(DcsStatus::HO))     dcs[15]=false; // ignore HO
00552       if (!dcsStatusItr->ready(DcsStatus::BPIX))   dcs[16]=false;
00553       if (!dcsStatusItr->ready(DcsStatus::FPIX))   dcs[17]=false;
00554       if (!dcsStatusItr->ready(DcsStatus::RPC))    dcs[18]=false;
00555       if (!dcsStatusItr->ready(DcsStatus::TIBTID)) dcs[19]=false;
00556       if (!dcsStatusItr->ready(DcsStatus::TOB))    dcs[20]=false;
00557       if (!dcsStatusItr->ready(DcsStatus::TECp))   dcs[21]=false;
00558       if (!dcsStatusItr->ready(DcsStatus::TECm))   dcs[22]=false;
00559 //      if (!dcsStatusItr->ready(DcsStatus::CASTOR)) dcs[23]=false;
00560     }
00561 
00562 
00563   // now we should add some logic that tests the HV status
00564   bool decision = true;
00565   for (int i=0; i<24; i++) decision=decision && dcs[i];
00566   if (debugPrint) {
00567      std::cout << "[OccupancyPlotter::checkDcsInfo] DCS Status:";
00568      for (int i=0; i<24; i++) std::cout << dcs[i] << "-";
00569      std::cout << "; Decision: " << decision << std::endl;
00570   }
00571   //std::cout << "; Decision: " << decision << std::endl;
00572   return decision;
00573   
00574 }
00575 
00576 void OccupancyPlotter::checkLumiInfo (const edm::Event & jEvent) {
00577 
00578   if (debugPrint) std::cout << "Inside method check lumi info" << std::endl;
00579   
00580   edm::Handle<LumiScalersCollection> lumiScalers;
00581   bool lumiHandleOK = jEvent.getByLabel(InputTag("hltScalersRawToDigi","",""), lumiScalers);
00582 
00583   if (!lumiHandleOK || !lumiScalers.isValid()){
00584     if (debugPrint) std::cout << "scalers not valid" << std::endl;
00585     return;
00586   }
00587 
00588   if (lumiScalers->size() == 0) {
00589     if (debugPrint) std::cout << "scalers has size < 0" << std::endl;
00590     return;    
00591   }
00592 
00593   LumiScalersCollection::const_iterator it3 = lumiScalers->begin();
00594   //unsigned int lumisection = it3->sectionNumber();
00595 
00596   _instLumi = it3->instantLumi();
00597   _instLumi_err = it3->instantLumiErr();
00598   _pileup = it3->pileup();
00599 
00600   if (debugPrint) std::cout << "Instanteous Lumi is " << _instLumi << std::endl;
00601   if (debugPrint) std::cout << "Instanteous Lumi Error is " << _instLumi_err << std::endl;
00602   if (debugPrint) std::cout << "Lumi Fill is " <<it3->lumiFill() << std::endl;
00603   if (debugPrint) std::cout << "Lumi Fill is " <<it3->lumiRun() << std::endl;
00604   if (debugPrint) std::cout << "Live Lumi Fill is " <<it3->liveLumiFill() << std::endl;
00605   if (debugPrint) std::cout << "Live Lumi Run is " <<it3->liveLumiRun() << std::endl;
00606   if (debugPrint) std::cout << "Pileup? = " << _pileup << std::endl;
00607 
00608   return;
00609   
00610 }
00611 
00612 //=========================================================
00613 
00614 // ------------ method called when starting to processes a luminosity block  ------------
00615 void OccupancyPlotter::beginLuminosityBlock(edm::LuminosityBlock const &lb, edm::EventSetup const&)
00616 {
00617  unsigned int thisLumiSection = 0;
00618  thisLumiSection = lb.luminosityBlock();
00619  std::cout << "[OccupancyPlotter::beginLuminosityBlock] New luminosity block: " << thisLumiSection << std::endl; 
00620  thisiLumiValue=true; // add the instantaneous luminosity of the first event to the LS-Lumi plot
00621 }
00622 
00623 // ------------ method called when ending the processing of a luminosity block  ------------
00624 void 
00625 OccupancyPlotter::endLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&)
00626 {
00627 }
00628 
00629 // ------------ method fills 'descriptions' with the allowed parameters for the module  ------------
00630 // void
00631 // OccupancyPlotter::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
00632 //   //The following says we do not know what parameters are allowed so do no validation
00633 //   // Please change this to state exactly what you do use, even if it is no parameters
00634 //   edm::ParameterSetDescription desc;
00635 //   desc.setUnknown();
00636 //   descriptions.addDefault(desc);
00637 // }
00638 
00639 //define this as a plug-in
00640 DEFINE_FWK_MODULE(OccupancyPlotter);