CMS 3D CMS Logo

CMSSW_4_4_3_patch1/src/DQM/HLTEvF/plugins/TrigResRateMon.cc

Go to the documentation of this file.
00001 // $Id: TrigResRateMon.cc,v 1.12 2010/09/29 23:07:08 rekovic Exp $
00002 // See header file for information. 
00003 #include "TMath.h"
00004 #include "DQM/HLTEvF/interface/TrigResRateMon.h"
00005 #include "FWCore/Common/interface/TriggerNames.h"
00006 
00007 #include <map>
00008 #include <utility>
00009 
00010 
00011 using namespace edm;
00012 using namespace trigger;
00013 using namespace std;
00014 
00015 TrigResRateMon::TrigResRateMon(const edm::ParameterSet& iConfig): currentRun_(-99)
00016 {
00017 
00018   LogDebug("TrigResRateMon") << "constructor...." ;
00019 
00020   fIsSetup = false;
00021 
00022   dbe_ = Service < DQMStore > ().operator->();
00023   if ( ! dbe_ ) {
00024     LogInfo("TrigResRateMon") << "unabel to get DQMStore service?";
00025   }
00026   if (iConfig.getUntrackedParameter < bool > ("DQMStore", false)) {
00027     dbe_->setVerbose(0);
00028   }
00029   
00030   dirname_ = iConfig.getUntrackedParameter("dirname", std::string("HLT/TrigResults/"));
00031   //dirname_ +=  iConfig.getParameter<std::string>("@module_label");
00032   
00033   if (dbe_ != 0 ) {
00034     dbe_->setCurrentFolder(dirname_);
00035   }
00036 
00037   doCombineRuns_ = iConfig.getUntrackedParameter<bool>("doCombineRuns", false);
00038   doVBTFMuon_ = iConfig.getUntrackedParameter<bool>("doVBTFMuon", true);
00039   
00040   processname_ = iConfig.getParameter<std::string>("processname");
00041   fCustomBXPath = iConfig.getUntrackedParameter<std::string>("customBXPath", std::string("HLT_MinBiasBSC"));
00042 
00043   referenceBX_ = iConfig.getUntrackedParameter<unsigned int>("referenceBX",51);
00044   Nbx_ = iConfig.getUntrackedParameter<unsigned int>("Nbx",3564);
00045 
00046   // plotting paramters
00047   ptMin_ = iConfig.getUntrackedParameter<double>("ptMin",0.);
00048   ptMax_ = iConfig.getUntrackedParameter<double>("ptMax",1000.);
00049   nBins_ = iConfig.getUntrackedParameter<unsigned int>("Nbins",20);
00050   nBins2D_ = iConfig.getUntrackedParameter<unsigned int>("Nbins2D",40);
00051   dRMax_ = iConfig.getUntrackedParameter<double>("dRMax",1.0);
00052   dRMaxElectronMuon_ = iConfig.getUntrackedParameter<double>("dRMaxElectronMuon",0.3);
00053   nBinsDR_ = iConfig.getUntrackedParameter<unsigned int>("NbinsDR",10);
00054   nBinsOneOverEt_ = iConfig.getUntrackedParameter<unsigned int>("NbinsOneOverEt",10000);
00055   nLS_   = iConfig.getUntrackedParameter<unsigned int>("NLuminositySegments",10);
00056   LSsize_   = iConfig.getUntrackedParameter<double>("LuminositySegmentSize",23);
00057   thresholdFactor_ = iConfig.getUntrackedParameter<double>("thresholdFactor",1.0);
00058 
00059   
00060   plotAll_ = iConfig.getUntrackedParameter<bool>("plotAll", false);
00061      // this is the list of paths to look at.
00062   std::vector<edm::ParameterSet> paths = 
00063   iConfig.getParameter<std::vector<edm::ParameterSet> >("paths");
00064 
00065   for(std::vector<edm::ParameterSet>::iterator pathconf = paths.begin() ; pathconf != paths.end(); pathconf++) {
00066 
00067     custompathnamepairs_.push_back(
00068         make_pair(
00069           pathconf->getParameter<std::string>("pathname"),
00070           pathconf->getParameter<std::string>("denompathname")
00071         )
00072     );
00073 
00074   }
00075 
00076   if (hltPaths_.size() > 0)
00077   {
00078       // book a histogram of scalers
00079      scalersSelect = dbe_->book1D("selectedScalers","Selected Scalers", hltPaths_.size(), 0.0, (double)hltPaths_.size());
00080 
00081   }
00082 
00083   triggerSummaryLabel_ = iConfig.getParameter<edm::InputTag>("triggerSummaryLabel");
00084   triggerResultsLabel_ = iConfig.getParameter<edm::InputTag>("triggerResultsLabel");
00085 
00086 
00087   /*
00088   muonRecoCollectionName_ = iConfig.getUntrackedParameter("muonRecoCollectionName", std::string("muons"));
00089 
00090   electronEtaMax_ = iConfig.getUntrackedParameter<double>("electronEtaMax",2.5);
00091   electronEtMin_ = iConfig.getUntrackedParameter<double>("electronEtMin",3.0);
00092   electronDRMatch_  =iConfig.getUntrackedParameter<double>("electronDRMatch",0.3); 
00093   electronL1DRMatch_  =iConfig.getUntrackedParameter<double>("electronL1DRMatch",0.3); 
00094 
00095   muonEtaMax_ = iConfig.getUntrackedParameter<double>("muonEtaMax",2.1);
00096   muonEtMin_ = iConfig.getUntrackedParameter<double>("muonEtMin",0.0);
00097   muonDRMatch_  =iConfig.getUntrackedParameter<double>("muonDRMatch",0.3); 
00098   muonL1DRMatch_  =iConfig.getUntrackedParameter<double>("muonL1DRMatch",0.3); 
00099 
00100   tauEtaMax_ = iConfig.getUntrackedParameter<double>("tauEtaMax",2.5);
00101   tauEtMin_ = iConfig.getUntrackedParameter<double>("tauEtMin",3.0);
00102   tauDRMatch_  =iConfig.getUntrackedParameter<double>("tauDRMatch",0.3); 
00103   tauL1DRMatch_  =iConfig.getUntrackedParameter<double>("tauL1DRMatch",0.5); 
00104 
00105   jetEtaMax_ = iConfig.getUntrackedParameter<double>("jetEtaMax",5.0);
00106   jetEtMin_ = iConfig.getUntrackedParameter<double>("jetEtMin",10.0);
00107   jetDRMatch_  =iConfig.getUntrackedParameter<double>("jetDRMatch",0.3); 
00108   jetL1DRMatch_  =iConfig.getUntrackedParameter<double>("jetL1DRMatch",0.5); 
00109 
00110   bjetEtaMax_ = iConfig.getUntrackedParameter<double>("bjetEtaMax",2.5);
00111   bjetEtMin_ = iConfig.getUntrackedParameter<double>("bjetEtMin",10.0);
00112   bjetDRMatch_  =iConfig.getUntrackedParameter<double>("bjetDRMatch",0.3); 
00113   bjetL1DRMatch_  =iConfig.getUntrackedParameter<double>("bjetL1DRMatch",0.3); 
00114 
00115   photonEtaMax_ = iConfig.getUntrackedParameter<double>("photonEtaMax",2.5);
00116   photonEtMin_ = iConfig.getUntrackedParameter<double>("photonEtMin",3.0);
00117   photonDRMatch_  =iConfig.getUntrackedParameter<double>("photonDRMatch",0.3); 
00118   photonL1DRMatch_  =iConfig.getUntrackedParameter<double>("photonL1DRMatch",0.3); 
00119 
00120   trackEtaMax_ = iConfig.getUntrackedParameter<double>("trackEtaMax",2.5);
00121   trackEtMin_ = iConfig.getUntrackedParameter<double>("trackEtMin",3.0);
00122   trackDRMatch_  =iConfig.getUntrackedParameter<double>("trackDRMatch",0.3); 
00123   trackL1DRMatch_  =iConfig.getUntrackedParameter<double>("trackL1DRMatch",0.3); 
00124 
00125   metEtaMax_ = iConfig.getUntrackedParameter<double>("metEtaMax",5);
00126   metMin_ = iConfig.getUntrackedParameter<double>("metMin",10.0);
00127   metDRMatch_  =iConfig.getUntrackedParameter<double>("metDRMatch",0.5); 
00128   metL1DRMatch_  =iConfig.getUntrackedParameter<double>("metL1DRMatch",0.5); 
00129 
00130   htEtaMax_ = iConfig.getUntrackedParameter<double>("htEtaMax",5);
00131   htMin_ = iConfig.getUntrackedParameter<double>("htMin",10.0);
00132   htDRMatch_  =iConfig.getUntrackedParameter<double>("htDRMatch",0.5); 
00133   htL1DRMatch_  =iConfig.getUntrackedParameter<double>("htL1DRMatch",0.5); 
00134   */
00135 
00136   sumEtMin_ = iConfig.getUntrackedParameter<double>("sumEtMin",10.0);
00137 
00138       // Muon quality cuts
00139       dxyCut_ = iConfig.getUntrackedParameter<double>("DxyCut", 0.2);   // dxy < 0.2 cm 
00140       normalizedChi2Cut_ = iConfig.getUntrackedParameter<double>("NormalizedChi2Cut", 10.); // chi2/ndof (of global fit) <10.0
00141       trackerHitsCut_ = iConfig.getUntrackedParameter<int>("TrackerHitsCut", 11);  // Tracker Hits >10 
00142       pixelHitsCut_ = iConfig.getUntrackedParameter<int>("PixelHitsCut", 1); // Pixel Hits >0
00143       muonHitsCut_ = iConfig.getUntrackedParameter<int>("MuonHitsCut", 1);  // Valid Muon Hits >0 
00144       isAlsoTrackerMuon_ = iConfig.getUntrackedParameter<bool>("IsAlsoTrackerMuon", true);
00145       nMatchesCut_ = iConfig.getUntrackedParameter<int>("NMatchesCut", 2); // At least 2 Chambers with matches 
00146 
00147   specialPaths_ = iConfig.getParameter<std::vector<std::string > >("SpecialPaths");
00148 
00149   pathsSummaryFolder_ = iConfig.getUntrackedParameter ("pathsSummaryFolder",std::string("HLT/TrigResults/PathsSummary/HLT Counts/"));
00150   pathsSummaryStreamsFolder_ = iConfig.getUntrackedParameter ("pathsSummaryFolder",std::string("HLT/TrigResults/PathsSummary/"));
00151   //pathsSummaryStreamsFolder_ = iConfig.getUntrackedParameter ("pathsSummaryFolder",std::string("HLT/TrigResults/PathsSummary/Streams/"));
00152   pathsSummaryHLTCorrelationsFolder_ = iConfig.getUntrackedParameter ("hltCorrelationsFolder",std::string("HLT/TrigResults/PathsSummary/HLT Correlations/"));
00153   pathsSummaryFilterCountsFolder_ = iConfig.getUntrackedParameter ("filterCountsFolder",std::string("HLT/TrigResults/PathsSummary/Filters Counts/"));
00154 
00155   pathsSummaryHLTPathsPerLSFolder_ = iConfig.getUntrackedParameter ("individualPathsPerLSFolder",std::string("HLT/TrigResults/PathsSummary/HLT LS/"));
00156   pathsIndividualHLTPathsPerLSFolder_ = iConfig.getUntrackedParameter ("individualPathsPerLSFolder",std::string("HLT/TrigResults/PathsSummary/HLT LS/Paths/"));
00157   pathsSummaryHLTPathsPerBXFolder_ = iConfig.getUntrackedParameter ("individualPathsPerBXFolder",std::string("HLT/TrigResults/PathsSummary/HLT BX/"));
00158 
00159   fLumiFlag = true;
00160   ME_HLTAll_LS = NULL;
00161   ME_HLT_BX = NULL;
00162   ME_HLT_CUSTOM_BX = NULL;
00163 
00164   //jetID = new reco::helper::JetIDHelper(iConfig.getParameter<ParameterSet>("JetIDParams"));
00165 
00166     recHitsEBTag_ = iConfig.getUntrackedParameter<edm::InputTag>("RecHitsEBTag",edm::InputTag("reducedEcalRecHitsEB"));
00167       recHitsEETag_ = iConfig.getUntrackedParameter<edm::InputTag>("RecHitsEETag",edm::InputTag("reducedEcalRecHitsEE"));
00168 
00169   
00170 }
00171 
00172 
00173 TrigResRateMon::~TrigResRateMon()
00174 {
00175  
00176   // do anything here that needs to be done at desctruction time
00177   // (e.g. close files, deallocate resources etc.)
00178 
00179 }
00180 
00181 
00182 //
00183 // member functions
00184 //
00185 
00186 // ------------ method called to for each event  ------------
00187 void
00188 TrigResRateMon::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup)
00189 {
00190 
00191   //if(! fLumiFlag ) return;
00192 
00193   using namespace edm;
00194   using namespace trigger;
00195   ++nev_;
00196   LogDebug("TrigResRateMon")<< " analyze...." ;
00197 
00198 
00199   
00200 
00201   edm::Handle<TriggerResults> triggerResults;
00202   iEvent.getByLabel(triggerResultsLabel_,triggerResults);
00203   if(!triggerResults.isValid()) {
00204     edm::InputTag triggerResultsLabelFU(triggerResultsLabel_.label(),triggerResultsLabel_.instance(), "FU");
00205    iEvent.getByLabel(triggerResultsLabelFU,triggerResults);
00206   if(!triggerResults.isValid()) {
00207     edm::LogInfo("TrigResRateMon") << "TriggerResults not found, "
00208       "skipping event"; 
00209     return;
00210    }
00211   }
00212   triggerResults_ = triggerResults;
00213   const edm::TriggerNames & triggerNames = iEvent.triggerNames(*triggerResults);
00214 
00215   //int npath = triggerResults->size();
00216 
00217 
00218   // int bx = iEvent.bunchCrossing();
00219   /*
00220   // Fill HLTPassed_Correlation Matrix bin (i,j) = (Any,Any)
00221   // --------------------------------------------------------
00222   int anyBinNumber = ME_HLTPassPass->getTH2F()->GetXaxis()->FindBin("HLT_Any");      
00223   // any triger accepted
00224   if(triggerResults->accept()){
00225 
00226     ME_HLTPassPass->Fill(anyBinNumber-1,anyBinNumber-1);//binNumber1 = 0 = first filter
00227 
00228   }
00229   */
00230 
00231   fillHltMatrix(triggerNames);
00232 
00233   return;
00234 
00235 
00236   // Loop over paths
00237   // --------------------
00238   for(PathInfoCollection::iterator v = hltPathsDiagonal_.begin(); v!= hltPathsDiagonal_.end(); ++v ) { 
00239 
00240     /*
00241     LogTrace("TrigResRateMon") << " unique path " << v->getPath() << endl;
00242 
00243     unsigned int pathByIndex = triggerNames.triggerIndex(v->getPath());
00244 
00245     // path must be in the menu
00246     if(pathByIndex >= triggerResults_->size() ) continue;
00247 
00248   
00249     // Fill HLTPassed Matrix and HLTPassFail Matrix
00250     // --------------------------------------------------------
00251 
00252     if(triggerResults->accept(pathByIndex)){
00253   
00254       int pathBinNumber = ME_HLT_BX->getTH2F()->GetYaxis()->FindBin(v->getPath().c_str());      
00255       ME_HLT_BX->Fill(bx,pathBinNumber-1);
00256 
00257       //if(hasHLTPassed(fCustomBXPath,triggerNames)) {
00258 
00259         ME_HLT_CUSTOM_BX->Fill(bx,pathBinNumber-1);
00260 
00261       //}
00262 
00263     } // end if accept
00264 
00265     */
00266   
00267     /*
00268     // Fill histogram of filter ocupancy for each HLT path
00269     // ---------------------------------
00270     unsigned int lastModule = triggerResults->index(pathByIndex);
00271 
00272     //check if hlt passed
00273     bool hltPathPassed = triggerResults->accept(pathByIndex);
00274   
00275     //go through the list of filters
00276     for(unsigned int filt = 0; filt < v->filtersAndIndices.size(); filt++){
00277       
00278       int binNumber = v->getFiltersHisto()->getTH1()->GetXaxis()->FindBin(v->filtersAndIndices[filt].first.c_str());      
00279       
00280       // if hlt path passed, then all the modules passed
00281       // otherwise the module that issued the decision is the first fail
00282       // this means that all modules before it passed
00283       if(hltPathPassed) {
00284 
00285         v->getFiltersHisto()->Fill(binNumber-1);//binNumber1 = 0 = first filter
00286       }
00287       else if(v->filtersAndIndices[filt].second < lastModule){
00288         v->getFiltersHisto()->Fill(binNumber-1);//binNumber1 = 0 = first filter
00289       }
00290   
00291     } // end for filt
00292     */
00293 
00294   } // end for diag paths
00295 
00296 }
00297 
00298 
00299 
00300 // -- method called once each job just before starting event loop  --------
00301 void 
00302 TrigResRateMon::beginJob()
00303 {
00304   nev_ = 0;
00305   DQMStore *dbe = 0;
00306   dbe = Service<DQMStore>().operator->();
00307   
00308   if (dbe) {
00309     dbe->setCurrentFolder(dirname_);
00310   }
00311   
00312   
00313   MonitorElement* reportSummaryME = dbe->book1D("reportSummaryMap","report Summary Map",2,0,2);
00314   if(reportSummaryME) reportSummaryME->Fill(1);
00315 
00316 
00317 }
00318 
00319 // - method called once each job just after ending the event loop  ------------
00320 void 
00321 TrigResRateMon::endJob() 
00322 {
00323    LogInfo("TrigResRateMon") << "analyzed " << nev_ << " events";
00324    return;
00325 }
00326 
00327 
00328 // BeginRun
00329 void TrigResRateMon::beginRun(const edm::Run& run, const edm::EventSetup& c)
00330 {
00331 
00332   LogDebug("TrigResRateMon") << "beginRun, run " << run.id();
00333 
00334   if(fIsSetup) return;
00335   
00336   // HLT config does not change within runs!
00337   bool changed=false;
00338  
00339   if (!hltConfig_.init(run, c, processname_, changed)) {
00340 
00341     processname_ = "FU";
00342 
00343     if (!hltConfig_.init(run, c, processname_, changed)){
00344 
00345       LogDebug("TrigResRateMon") << "HLTConfigProvider failed to initialize.";
00346 
00347     }
00348 
00349     // check if trigger name in (new) config
00350     //  cout << "Available TriggerNames are: " << endl;
00351     //  hltConfig_.dump("Triggers");
00352   }
00353 
00354   if (1) {
00355 
00356     DQMStore *dbe = 0;
00357     dbe = Service<DQMStore>().operator->();
00358   
00359     if (dbe) {
00360       dbe->setCurrentFolder(dirname_);
00361     }
00362 
00363 
00364     const unsigned int n(hltConfig_.size());
00365 
00366 
00367     if (plotAll_){
00368 
00369       for (unsigned int j=0; j!=n; ++j) {
00370   
00371         std::string pathname = hltConfig_.triggerName(j);  
00372 
00373         string l1pathname = getL1ConditionModuleName(pathname);
00374 
00375         int l1ModuleIndex = hltConfig_.moduleIndex(pathname, l1pathname);
00376       
00377         int objectType =  getTriggerTypeParsePathName(pathname);
00378   
00379         for (unsigned int i=0; i!=n; ++i) {
00380   
00381           std::string denompathname = hltConfig_.triggerName(i);  
00382           int denomobjectType =  getTriggerTypeParsePathName(denompathname);
00383 
00384       
00385          
00386           std::string filtername("dummy");
00387           float ptMin = 0.0;
00388           float ptMax = 100.0;
00389           if (plotAll_ && denomobjectType == objectType && objectType != 0) {
00390           
00391             int hltThreshold = getThresholdFromName(pathname);
00392             int l1Threshold = getThresholdFromName(l1pathname);
00393             hltPaths_.push_back(PathInfo(denompathname, pathname, l1pathname, l1ModuleIndex, filtername, processname_, objectType, ptMin, ptMax, hltThreshold, l1Threshold));
00394 
00395           }
00396 
00397         }
00398       }
00399 
00400     } // end if plotAll
00401     else {
00402 
00403       // plot all diagonal combinations plus any other specified pairs
00404       for (unsigned int i=0; i!=n; ++i) {
00405 
00406          std::string denompathname = "";  
00407          std::string pathname = hltConfig_.triggerName(i);  
00408          //parse pathname to guess object type
00409          int objectType =  getTriggerTypeParsePathName(pathname);
00410 
00411         string l1pathname = getL1ConditionModuleName(pathname);
00412         int l1ModuleIndex = hltConfig_.moduleIndex(pathname, l1pathname);
00413   
00414         std::string filtername("dummy");
00415         float ptMin = 0.0;
00416         float ptMax = 100.0;
00417 
00418         if (objectType == trigger::TriggerPhoton) ptMax = 100.0;
00419         if (objectType == trigger::TriggerElectron) ptMax = 100.0;
00420         if (objectType == trigger::TriggerMuon) ptMax = 150.0;
00421         if (objectType == trigger::TriggerTau) ptMax = 100.0;
00422         if (objectType == trigger::TriggerJet) ptMax = 300.0;
00423         if (objectType == trigger::TriggerBJet) ptMax = 300.0;
00424         if (objectType == trigger::TriggerMET) ptMax = 300.0;
00425         if (objectType == trigger::TriggerTET) ptMax = 300.0;
00426         if (objectType == trigger::TriggerTrack) ptMax = 100.0;
00427     
00428         // keep track of all paths, except for FinalPath
00429         if (objectType != -1 && pathname.find("FinalPath") == std::string::npos){
00430 
00431           int hltThreshold = getThresholdFromName(pathname);
00432           int l1Threshold = getThresholdFromName(l1pathname);
00433   
00434           hltPaths_.push_back(PathInfo(denompathname, pathname, l1pathname, l1ModuleIndex, filtername, processname_, objectType, ptMin, ptMax, hltThreshold, l1Threshold));
00435 
00436           hltPathsDiagonal_.push_back(PathInfo(denompathname, pathname, l1pathname, l1ModuleIndex, filtername, processname_, objectType, ptMin, ptMax, hltThreshold, l1Threshold));
00437   
00438         }
00439 
00440       } // end for i
00441 
00442         
00443       // now loop over denom/num path pairs specified in cfg, 
00444       // recording the off-diagonal ones
00445       for (std::vector<std::pair<std::string, std::string> >::iterator custompathnamepair = custompathnamepairs_.begin(); custompathnamepair != custompathnamepairs_.end(); ++custompathnamepair) {
00446             
00447         std::string numpathname = custompathnamepair->first;  
00448         std::string denompathname = custompathnamepair->second;  
00449   
00450         if (numpathname != denompathname) {
00451   
00452           // check that denominator exists
00453           bool founddenominator = false;
00454           for (unsigned int k=0; k!=n; ++k) {
00455 
00456             string n_pathname = hltConfig_.triggerName(k);
00457 
00458             if (n_pathname.find(denompathname) != std::string::npos) {
00459               
00460               LogDebug("TrigResRateMon") << "denompathname is selected to be = " << n_pathname << endl;;
00461               founddenominator = true;
00462 
00463               break;
00464 
00465             }
00466           }
00467 
00468           if (!founddenominator) {
00469   
00470             edm::LogInfo("TrigResRateMon") << "denompathname not found, go to the next pair numearator-denominator" << endl;
00471             
00472             // go to the next pair
00473             continue;
00474   
00475           }
00476 
00477           // check that numerator exists
00478           bool foundnumerator = false;
00479           for (unsigned int j=0; j!=n; ++j) {
00480 
00481             string pathname = hltConfig_.triggerName(j);
00482 
00483             LogDebug("TrigResRateMon") << "check if path " << pathname << " is numpathname = " << numpathname << endl;
00484             if (hltConfig_.triggerName(j).find(numpathname)!= std::string::npos) {
00485               
00486               LogDebug("TrigResRateMon") << "pathname is selected to be = " << denompathname << endl;;
00487               foundnumerator = true;
00488 
00489             }
00490   
00491   
00492             if (!foundnumerator) {
00493     
00494               edm::LogInfo("TrigResRateMon") << "pathname not found, ignoring " << pathname;
00495               continue;
00496   
00497             }
00498   
00499   
00500             string l1pathname = getL1ConditionModuleName(pathname);
00501             int l1ModuleIndex = hltConfig_.moduleIndex(pathname, l1pathname);
00502             int objectType =  getTriggerTypeParsePathName(pathname);
00503   
00504           std::string filtername("dummy");
00505           float ptMin = 0.0;
00506           float ptMax = 100.0;
00507           if (objectType == trigger::TriggerPhoton) ptMax = 100.0;
00508           if (objectType == trigger::TriggerElectron) ptMax = 100.0;
00509           if (objectType == trigger::TriggerMuon) ptMax = 150.0;
00510           if (objectType == trigger::TriggerTau) ptMax = 100.0;
00511           if (objectType == trigger::TriggerJet) ptMax = 300.0;
00512           if (objectType == trigger::TriggerBJet) ptMax = 300.0;
00513           if (objectType == trigger::TriggerMET) ptMax = 300.0;
00514           if (objectType == trigger::TriggerTET) ptMax = 300.0;
00515           if (objectType == trigger::TriggerTrack) ptMax = 100.0;
00516   
00517           // monitor regardless of the objectType of the path
00518           if (objectType != 0) {
00519             int hltThreshold = getThresholdFromName(pathname);
00520             int l1Threshold = getThresholdFromName(l1pathname);
00521             hltPaths_.push_back(PathInfo(denompathname, pathname, l1pathname, l1ModuleIndex, filtername, processname_, objectType, ptMin, ptMax, hltThreshold, l1Threshold));
00522 
00523           }
00524       
00525         } // end for j, loop over paths
00526 
00527        }  // end if not same num and denominator 
00528   
00529       } // end for pair
00530 
00531     } // end else
00532 
00533 
00534     /*
00535     vector<string> muonPaths;
00536     vector<string> egammaPaths;
00537     vector<string> tauPaths;
00538     vector<string> jetmetPaths;
00539     vector<string> restPaths;
00540     */
00541     vector<string> allPaths;
00542 
00543     // fill vectors of Muon, Egamma, JetMET, Rest, and Special paths
00544     for(PathInfoCollection::iterator v = hltPathsDiagonal_.begin(); v!= hltPathsDiagonal_.end(); ++v ) {
00545 
00546       std::string pathName = v->getPath();
00547       //int objectType = v->getObjectType();
00548 
00549       vector<int> tempCount(5,0);
00550 
00551       fPathTempCountPair.push_back(make_pair(pathName,0));
00552       fPathBxTempCountPair.push_back(make_pair(pathName,tempCount));
00553 
00554       allPaths.push_back(pathName);
00555 
00556       /*
00557       switch (objectType) {
00558         case trigger::TriggerMuon :
00559           muonPaths.push_back(pathName);
00560           break;
00561 
00562         case trigger::TriggerElectron :
00563         case trigger::TriggerPhoton :
00564           egammaPaths.push_back(pathName);
00565           break;
00566 
00567         case trigger::TriggerTau :
00568           tauPaths.push_back(pathName);
00569           break;
00570 
00571         case trigger::TriggerJet :
00572         case trigger::TriggerMET :
00573           jetmetPaths.push_back(pathName);
00574           break;
00575 
00576         default:
00577           restPaths.push_back(pathName);
00578       }
00579       */
00580 
00581     }
00582 
00583     fPathTempCountPair.push_back(make_pair("HLT_Any",0));
00584 
00585     fGroupName.push_back("AllSelectedPaths");
00586     /*
00587     fGroupName.push_back("Muon");
00588     fGroupName.push_back("Egamma");
00589     fGroupName.push_back("Tau");
00590     fGroupName.push_back("JetMET");
00591     fGroupName.push_back("Rest");
00592     fGroupName.push_back("Special");
00593     */
00594 
00595     for(unsigned int g=0; g<fGroupName.size(); g++) {
00596 
00597       //fGroupTempCountPair.push_back(make_pair(fGroupName[g],0));
00598       //fGroupL1TempCountPair.push_back(make_pair(fGroupName[g],0));
00599 
00600     }
00601   
00602     dbe_->setCurrentFolder(pathsSummaryFolder_.c_str());
00603 
00604 
00605 
00606     fGroupNamePathsPair.push_back(make_pair("AllSelectedPaths",allPaths));
00607 
00608     /*
00609     fGroupNamePathsPair.push_back(make_pair("Muon",muonPaths));
00610 
00611     fGroupNamePathsPair.push_back(make_pair("Egamma",egammaPaths));
00612 
00613     fGroupNamePathsPair.push_back(make_pair("Tau",tauPaths));
00614 
00615     fGroupNamePathsPair.push_back(make_pair("JetMET",jetmetPaths));
00616 
00617     fGroupNamePathsPair.push_back(make_pair("Rest",restPaths));
00618 
00619     fGroupNamePathsPair.push_back(make_pair("Special",specialPaths_));
00620     */
00621 
00623     //vector<string> datasetNames =  hltConfig_.datasetNames() ;
00624     vector<string> datasetNames =  hltConfig_.streamContent("A") ;
00625     for (unsigned int i=0;i<datasetNames.size();i++) {
00626 
00627       vector<string> datasetPaths = hltConfig_.datasetContent(datasetNames[i]);
00628       fGroupNamePathsPair.push_back(make_pair(datasetNames[i],datasetPaths));
00629 
00630     }
00631 
00632     // push stream A and its PDs
00633     fGroupNamePathsPair.push_back(make_pair("A",datasetNames));
00634 
00635 
00636     for (unsigned int g=0;g<fGroupNamePathsPair.size();g++) {
00637 
00638       fGroupTempCountPair.push_back(make_pair(fGroupNamePathsPair[g].first,0));
00639       fGroupL1TempCountPair.push_back(make_pair(fGroupNamePathsPair[g].first,0));
00640       setupHltMatrix(fGroupNamePathsPair[g].first,fGroupNamePathsPair[g].second);
00641 
00642     }
00643 
00644 /*
00645     // HLT matrices from Streams
00646     const std::vector<std::string> streamNames = hltConfig_.streamNames();
00647 
00648     for (unsigned int s=0;s<streamNames.size();s++) {
00649 
00651       vector<string> streamDatasetNames =  hltConfig_.streamContent(streamNames[s]) ;
00652       if(streamNames[s] == "A") setupStreamMatrix(streamNames[s],streamDatasetNames);
00653 
00654     }
00655 */
00656 
00657     setupHltLsPlots();
00658 
00659     setupHltBxPlots();
00660 
00661 
00662     for(PathInfoCollection::iterator v = hltPathsDiagonal_.begin(); v!= hltPathsDiagonal_.end(); ++v ) {
00663 
00664        // -------------------------
00665        //
00666        //  Filters for each path
00667        //
00668        // -------------------------
00669        
00670        // get all modules in this HLT path
00671        vector<string> moduleNames = hltConfig_.moduleLabels( v->getPath() ); 
00672        
00673        int numModule = 0;
00674        string moduleName, moduleType;
00675        unsigned int moduleIndex;
00676        
00677        //print module name
00678        vector<string>::const_iterator iDumpModName;
00679        for (iDumpModName = moduleNames.begin();iDumpModName != moduleNames.end();iDumpModName++) {
00680 
00681          moduleName = *iDumpModName;
00682          moduleType = hltConfig_.moduleType(moduleName);
00683          moduleIndex = hltConfig_.moduleIndex(v->getPath(), moduleName);
00684 
00685          LogTrace ("TrigResRateMon") << "Module "      << numModule
00686              << " is called " << moduleName
00687              << " , type = "  << moduleType
00688              << " , index = " << moduleIndex
00689              << endl;
00690 
00691          numModule++;
00692 
00693          if((moduleType.find("Filter") != string::npos && moduleType.find("HLTTriggerTypeFilter") == string::npos ) || 
00694             (moduleType.find("Associator") != string::npos) || 
00695             (moduleType.find("HLTLevel1GTSeed") != string::npos) || 
00696             (moduleType.find("HLTGlobalSumsCaloMET") != string::npos) ||
00697             (moduleType.find("HLTPrescaler") != string::npos) ) {
00698 
00699            //std::pair<std::string, int> filterIndexPair;
00700            //filterIndexPair.first   = moduleName;
00701            //filterIndexPair.second  = moduleIndex;
00702            //v->filtersAndIndices.push_back(filterIndexPair);
00703            v->filtersAndIndices.push_back(make_pair(moduleName,moduleIndex));
00704 
00705          }
00706 
00707 
00708        }//end for modulesName
00709 
00710        dbe_->setCurrentFolder(pathsSummaryFilterCountsFolder_.c_str()); 
00711 
00712        //int nbin_sub = 5;
00713        int nbin_sub = v->filtersAndIndices.size()+2;
00714     
00715        // count plots for subfilter
00716        MonitorElement* filters = dbe_->book1D("Filters_" + v->getPath(), 
00717                               "Filters_" + v->getPath(),
00718                               nbin_sub+1, -0.5, 0.5+(double)nbin_sub);
00719        
00720        for(unsigned int filt = 0; filt < v->filtersAndIndices.size(); filt++){
00721 
00722          filters->setBinLabel(filt+1, (v->filtersAndIndices[filt]).first);
00723 
00724        }
00725 
00726        // book Count vs LS
00727        dbe_->setCurrentFolder(pathsIndividualHLTPathsPerLSFolder_.c_str());
00728        MonitorElement* tempME = dbe_->book1D(v->getPath() + "_count_per_LS", 
00729                               v->getPath() + " rate [Hz]",
00730                               nLS_, 0,nLS_);
00731        tempME->setAxisTitle("Luminosity Section");
00732 
00733        v->setFilterHistos(filters);
00734 
00735     } // end for paths
00736 
00737     // now set up all of the histos for each path-denom
00738     for(PathInfoCollection::iterator v = hltPaths_.begin(); v!= hltPaths_.end(); ++v ) {
00739 
00740       /*
00741       MonitorElement *NOn, *onEtOn, *onOneOverEtOn, *onEtavsonPhiOn=0;
00742       MonitorElement *NOff, *offEtOff, *offEtavsoffPhiOff=0;
00743       MonitorElement *NL1, *l1EtL1, *l1Etavsl1PhiL1=0;
00744       MonitorElement *NL1On, *l1EtL1On, *l1Etavsl1PhiL1On=0;
00745       MonitorElement *NL1Off, *offEtL1Off, *offEtavsoffPhiL1Off=0;
00746       MonitorElement *NOnOff, *offEtOnOff, *offEtavsoffPhiOnOff=0;
00747       MonitorElement *NL1OnUM, *l1EtL1OnUM, *l1Etavsl1PhiL1OnUM=0;
00748       MonitorElement *NL1OffUM, *offEtL1OffUM, *offEtavsoffPhiL1OffUM=0;
00749       MonitorElement *NOnOffUM, *offEtOnOffUM, *offEtavsoffPhiOnOffUM=0;
00750       MonitorElement *offDRL1Off, *offDROnOff, *l1DRL1On=0;
00751       */
00752       
00753 
00754       std::string labelname("dummy");
00755       labelname = v->getPath() + "_wrt_" + v->getDenomPath();
00756       std::string histoname(labelname+"_NOn");
00757       std::string title(labelname+" N online");
00758       double histEtaMax = 2.5;
00759 
00760       if (v->getObjectType() == trigger::TriggerMuon || v->getObjectType() == trigger::TriggerL1Mu) {
00761 
00762         histEtaMax = muonEtaMax_;
00763 
00764       }
00765       else if (v->getObjectType() == trigger::TriggerElectron || v->getObjectType() == trigger::TriggerL1NoIsoEG || v->getObjectType() == trigger::TriggerL1IsoEG )
00766       {
00767         histEtaMax = electronEtaMax_;
00768       }
00769         else if (v->getObjectType() == trigger::TriggerTau || v->getObjectType() == trigger::TriggerL1TauJet )
00770       {
00771         histEtaMax = tauEtaMax_;
00772       }
00773       else if (v->getObjectType() == trigger::TriggerJet || v->getObjectType() == trigger::TriggerL1CenJet || v->getObjectType() == trigger::TriggerL1ForJet )
00774       {
00775         histEtaMax = jetEtaMax_; 
00776       }
00777         else if (v->getObjectType() == trigger::TriggerBJet)
00778       {
00779         histEtaMax = bjetEtaMax_;
00780       }
00781       else if (v->getObjectType() == trigger::TriggerMET || v->getObjectType() == trigger::TriggerL1ETM )
00782       {
00783         histEtaMax = metEtaMax_; 
00784       }
00785         else if (v->getObjectType() == trigger::TriggerPhoton)
00786       {
00787         histEtaMax = photonEtaMax_; 
00788       }
00789       else if (v->getObjectType() == trigger::TriggerTrack)
00790       {
00791         histEtaMax = trackEtaMax_; 
00792       }
00793 
00794       TString pathfolder = dirname_ + TString("/FourVector/") + v->getPath();
00795       /*
00796       dbe_->setCurrentFolder(pathfolder.Data());
00797 
00798       NOn =  dbe->book1D(histoname.c_str(), title.c_str(),10, 0.5, 10.5);
00799 
00800 
00801        histoname = labelname+"_NOff";
00802        title = labelname+" N Off";
00803        NOff =  dbe->book1D(histoname.c_str(), title.c_str(),10, 0.5, 10.5);
00804        
00805        histoname = labelname+"_NL1";
00806        title = labelname+" N L1";
00807        NL1 =  dbe->book1D(histoname.c_str(), title.c_str(),10, 0.5, 10.5);
00808        
00809        histoname = labelname+"_NL1On";
00810        title = labelname+" N L1On";
00811        NL1On =  dbe->book1D(histoname.c_str(), title.c_str(),10, 0.5, 10.5);
00812        
00813        histoname = labelname+"_NL1Off";
00814        title = labelname+" N L1Off";
00815        NL1Off =  dbe->book1D(histoname.c_str(), title.c_str(),10, 0.5, 10.5);
00816        
00817        histoname = labelname+"_NOnOff";
00818        title = labelname+" N OnOff";
00819        NOnOff =  dbe->book1D(histoname.c_str(), title.c_str(),10, 0.5, 10.5);
00820        
00821        
00822        histoname = labelname+"_NL1OnUM";
00823        title = labelname+" N L1OnUM";
00824        NL1OnUM =  dbe->book1D(histoname.c_str(), title.c_str(),10, 0.5, 10.5);
00825        
00826        histoname = labelname+"_NL1OffUM";
00827        title = labelname+" N L1OffUM";
00828        NL1OffUM =  dbe->book1D(histoname.c_str(), title.c_str(),10, 0.5, 10.5);
00829        
00830        histoname = labelname+"_NOnOffUM";
00831        title = labelname+" N OnOffUM";
00832        NOnOffUM =  dbe->book1D(histoname.c_str(), title.c_str(),10, 0.5, 10.5);
00833        
00834        
00835        histoname = labelname+"_onEtOn";
00836        title = labelname+" onE_t online";
00837        onEtOn =  dbe->book1D(histoname.c_str(), title.c_str(),nBins_, v->getPtMin(), v->getPtMax());
00838        
00839        histoname = labelname+"_onOneOverEtOn";
00840        title = labelname+" 1 / onE_t online";
00841        onOneOverEtOn =  dbe->book1D(histoname.c_str(), title.c_str(),nBinsOneOverEt_, 0, 1);
00842        onOneOverEtOn->setAxisTitle("HLT 1/Et [1/GeV]");
00843        
00844        histoname = labelname+"_offEtOff";
00845        title = labelname+" offE_t offline";
00846        offEtOff =  dbe->book1D(histoname.c_str(), title.c_str(),nBins_, v->getPtMin(), v->getPtMax());
00847        
00848        histoname = labelname+"_l1EtL1";
00849        title = labelname+" l1E_t L1";
00850        l1EtL1 =  dbe->book1D(histoname.c_str(), title.c_str(),nBins_, v->getPtMin(), v->getPtMax());
00851        
00852        
00853        histoname = labelname+"_onEtaonPhiOn";
00854        title = labelname+" on#eta vs on#phi online";
00855        onEtavsonPhiOn =  dbe->book2D(histoname.c_str(), title.c_str(), nBins2D_,-histEtaMax,histEtaMax, nBins2D_,-TMath::Pi(), TMath::Pi());
00856        
00857        histoname = labelname+"_offEtaoffPhiOff";
00858        title = labelname+" off#eta vs off#phi offline";
00859        offEtavsoffPhiOff =  dbe->book2D(histoname.c_str(), title.c_str(), nBins2D_,-histEtaMax,histEtaMax, nBins2D_,-TMath::Pi(), TMath::Pi());
00860        
00861        histoname = labelname+"_l1Etal1PhiL1";
00862        title = labelname+" l1#eta vs l1#phi L1";
00863        l1Etavsl1PhiL1 =  dbe->book2D(histoname.c_str(), title.c_str(), nBins2D_,-histEtaMax,histEtaMax, nBins2D_,-TMath::Pi(), TMath::Pi());
00864        
00865        histoname = labelname+"_l1EtL1On";
00866        title = labelname+" l1E_t L1+online";
00867        l1EtL1On =  dbe->book1D(histoname.c_str(), title.c_str(),nBins_, v->getPtMin(), v->getPtMax());
00868        
00869        histoname = labelname+"_offEtL1Off";
00870        title = labelname+" offE_t L1+offline";
00871        offEtL1Off =  dbe->book1D(histoname.c_str(), title.c_str(),nBins_, v->getPtMin(), v->getPtMax());
00872        
00873        histoname = labelname+"_offEtOnOff";
00874        title = labelname+" offE_t online+offline";
00875        offEtOnOff =  dbe->book1D(histoname.c_str(), title.c_str(),nBins_, v->getPtMin(), v->getPtMax());
00876        
00877        histoname = labelname+"_l1Etal1PhiL1On";
00878        title = labelname+" l1#eta vs l1#phi L1+online";
00879        l1Etavsl1PhiL1On =  dbe->book2D(histoname.c_str(), title.c_str(), nBins2D_,-histEtaMax,histEtaMax, nBins2D_,-TMath::Pi(), TMath::Pi());
00880        
00881        histoname = labelname+"_offEtaoffPhiL1Off";
00882        title = labelname+" off#eta vs off#phi L1+offline";
00883        offEtavsoffPhiL1Off =  dbe->book2D(histoname.c_str(), title.c_str(), nBins2D_,-histEtaMax,histEtaMax, nBins2D_,-TMath::Pi(), TMath::Pi());
00884        
00885        histoname = labelname+"_offEtaoffPhiOnOff";
00886        title = labelname+" off#eta vs off#phi online+offline";
00887        offEtavsoffPhiOnOff =  dbe->book2D(histoname.c_str(), title.c_str(), nBins2D_,-histEtaMax,histEtaMax, nBins2D_,-TMath::Pi(), TMath::Pi());
00888        
00889        histoname = labelname+"_l1EtL1OnUM";
00890        title = labelname+" l1E_t L1+onlineUM";
00891        l1EtL1OnUM =  dbe->book1D(histoname.c_str(), title.c_str(),nBins_, v->getPtMin(), v->getPtMax());
00892        
00893        histoname = labelname+"_offEtL1OffUM";
00894        title = labelname+" offE_t L1+offlineUM";
00895        offEtL1OffUM =  dbe->book1D(histoname.c_str(), title.c_str(),nBins_, v->getPtMin(), v->getPtMax());
00896        
00897        histoname = labelname+"_offEtOnOffUM";
00898        title = labelname+" offE_t online+offlineUM";
00899        offEtOnOffUM =  dbe->book1D(histoname.c_str(), title.c_str(),nBins_, v->getPtMin(), v->getPtMax());
00900        
00901        histoname = labelname+"_l1Etal1PhiL1OnUM";
00902        title = labelname+" l1#eta vs l1#phi L1+onlineUM";
00903        l1Etavsl1PhiL1OnUM =  dbe->book2D(histoname.c_str(), title.c_str(), nBins2D_,-histEtaMax,histEtaMax, nBins2D_,-TMath::Pi(), TMath::Pi());
00904        
00905        histoname = labelname+"_offEtaoffPhiL1OffUM";
00906        title = labelname+" off#eta vs off#phi L1+offlineUM";
00907        offEtavsoffPhiL1OffUM =  dbe->book2D(histoname.c_str(), title.c_str(), nBins2D_,-histEtaMax,histEtaMax, nBins2D_,-TMath::Pi(), TMath::Pi());
00908        
00909        histoname = labelname+"_offEtaoffPhiOnOffUM";
00910        title = labelname+" off#eta vs off#phi online+offlineUM";
00911        offEtavsoffPhiOnOffUM =  dbe->book2D(histoname.c_str(), title.c_str(), nBins2D_,-histEtaMax,histEtaMax, nBins2D_,-TMath::Pi(), TMath::Pi());
00912        
00913        
00914        
00915        
00916        histoname = labelname+"_l1DRL1On";
00917        title = labelname+" l1DR L1+online";
00918        l1DRL1On =  dbe->book1D(histoname.c_str(), title.c_str(),nBinsDR_, 0, dRMax_); 
00919        
00920        histoname = labelname+"_offDRL1Off";
00921        title = labelname+" offDR L1+offline";
00922        offDRL1Off =  dbe->book1D(histoname.c_str(), title.c_str(),nBinsDR_, 0, dRMax_);
00923        
00924        histoname = labelname+"_offDROnOff";
00925        title = labelname+" offDR online+offline";
00926        offDROnOff =  dbe->book1D(histoname.c_str(), title.c_str(),nBinsDR_, 0, dRMax_); 
00927        */
00928 
00929 
00930        //v->setHistos( NOn, onEtOn, onOneOverEtOn, onEtavsonPhiOn, NOff, offEtOff, offEtavsoffPhiOff, NL1, l1EtL1, l1Etavsl1PhiL1, NL1On, l1EtL1On, l1Etavsl1PhiL1On, NL1Off, offEtL1Off, offEtavsoffPhiL1Off, NOnOff, offEtOnOff, offEtavsoffPhiOnOff, NL1OnUM, l1EtL1OnUM, l1Etavsl1PhiL1OnUM, NL1OffUM, offEtL1OffUM, offEtavsoffPhiL1OffUM, NOnOffUM, offEtOnOffUM, offEtavsoffPhiOnOffUM, offDRL1Off, offDROnOff, l1DRL1On );
00931 
00932 
00933     }  // end for hltPath
00934 
00935     // HLT_Any
00936     // book Count vs LS
00937     dbe_->setCurrentFolder(pathsIndividualHLTPathsPerLSFolder_.c_str());
00938     MonitorElement* tempME = dbe_->book1D("HLT_Any_count_per_LS", 
00939                            "HLT_Any rate [Hz]",
00940                            nLS_, 0,nLS_);
00941     tempME->setAxisTitle("Luminosity Section");
00942 
00943   } // end if(1) dummy
00944 
00945  if(doCombineRuns_) fIsSetup = true;
00946 
00947  return;
00948 
00949 }
00950 
00952 void TrigResRateMon::endRun(const edm::Run& run, const edm::EventSetup& c)
00953 {
00954 
00955   LogDebug("TrigResRateMon") << "endRun, run " << run.id();
00956 
00957 }
00958 
00959 
00960 void TrigResRateMon::setupHltMatrix(const std::string& label, vector<std::string>& paths) {
00961 
00962     //string groupLabelAny = "HLT_"+label+"_Any";
00963     //paths.push_back(groupLabelAny.c_str());
00964     //paths.push_back("HLT_"+label+"_L1_Any");
00965     paths.push_back("");
00966     paths.push_back("Total "+label);
00967     //paths.push_back("HLT_Any");
00968 
00969     string h_name; 
00970     string h_title; 
00971 
00972     dbe_->setCurrentFolder(pathsSummaryFolder_.c_str());
00973 
00974     h_name= "HLT_"+label+"_PassPass";
00975     h_title = "HLT_"+label+"_PassPass (x=Pass, y=Pass)";
00976     MonitorElement* ME = dbe_->book2D(h_name.c_str(), h_title.c_str(),
00977                            paths.size(), -0.5, paths.size()-0.5, paths.size(), -0.5, paths.size()-0.5);
00978 
00979     h_name= "HLT_"+label+"_Pass_Any";
00980     h_title = "HLT_"+label+"_Pass (x=Pass, Any=Pass) normalized to HLT_Any Pass";
00981     MonitorElement* ME_Any = dbe_->book1D(h_name.c_str(), h_title.c_str(),
00982                            paths.size(), -0.5, paths.size()-0.5);
00983 
00984     dbe_->setCurrentFolder(pathsSummaryHLTCorrelationsFolder_.c_str());
00985     h_name= "HLT_"+label+"_PassPass_Normalized";
00986     h_title = "HLT_"+label+"_PassPass (x=Pass, y=Pass) normalized to xBin=Pass";
00987     MonitorElement* ME_Normalized = dbe_->book2D(h_name.c_str(), h_title.c_str(),
00988                            paths.size(), -0.5, paths.size()-0.5, paths.size(), -0.5, paths.size()-0.5);
00989     h_name= "HLT_"+label+"_Pass_Normalized_Any";
00990     h_title = "HLT_"+label+"_Pass (x=Pass, Any=Pass) normalized to HLT_Any Pass";
00991     MonitorElement* ME_Normalized_Any = dbe_->book1D(h_name.c_str(), h_title.c_str(),
00992                            paths.size(), -0.5, paths.size()-0.5);
00993 
00994     dbe_->setCurrentFolder(pathsSummaryHLTPathsPerLSFolder_.c_str());
00995     h_name= "HLT_"+label+"_Total_LS";
00996     h_title = label+" HLT paths total combined rate [Hz]";
00997     MonitorElement* ME_Total_LS = dbe_->book1D(h_name.c_str(), h_title.c_str(), nLS_, 0, nLS_);
00998     ME_Total_LS->setAxisTitle("LS");
00999 
01000     h_name= "HLT_"+label+"_LS";
01001     h_title = label+" HLT paths rate [Hz]";
01002     MonitorElement* ME_Group_LS = dbe_->book2D(h_name.c_str(), h_title.c_str(), nLS_, 0, nLS_, paths.size(), -0.5, paths.size()-0.5);
01003     ME_Group_LS->setAxisTitle("LS");
01005     v_ME_HLTAll_LS.push_back(ME_Group_LS);
01006 
01007     /*
01008     h_name= "HLT_"+label+"_L1_Total_LS";
01009     h_title = label+" HLT paths total combined rate [Hz]";
01010     MonitorElement* ME_Total_L1_LS = dbe_->book1D(h_name.c_str(), h_title.c_str(), nLS_, 0, nLS_);
01011     ME_Total_L1_LS->setAxisTitle("LS");
01012 
01013     h_name= "HLT_"+label+"_L1_LS";
01014     h_title = label+" HLT L1s rate [Hz]";
01015     MonitorElement* ME_Group_L1_LS = dbe_->book2D(h_name.c_str(), h_title.c_str(), nLS_, 0, nLS_, paths.size(), -0.5, paths.size()-0.5);
01016     ME_Group_L1_LS->setAxisTitle("LS");
01017 
01018     dbe_->setCurrentFolder(pathsSummaryHLTPathsPerBXFolder_.c_str());
01019     h_name= "HLT_"+label+"_BX_LS";
01020     h_title = label+" HLT paths total count combined per BX ";
01021     MonitorElement* ME_Total_BX = dbe_->book2D(h_name.c_str(), h_title.c_str(),  nLS_, 0, nLS_, 5, -2.5, 2.5);
01022     ME_Total_BX->setAxisTitle("LS",1);
01023     v_ME_Total_BX.push_back(ME_Total_BX);
01024 
01025     h_name= "HLT_"+label+"_BX_LS_Norm";
01026     h_title = label+" HLT paths total count combined per BX Normalized to LS";
01027     MonitorElement* ME_Total_BX_Norm = dbe_->book2D(h_name.c_str(), h_title.c_str(),  nLS_, 0, nLS_, 5, -2.5, 2.5);
01028     ME_Total_BX_Norm->setAxisTitle("LS",1);
01029     v_ME_Total_BX_Norm.push_back(ME_Total_BX_Norm);
01030     */
01031 
01032     for(unsigned int i = 0; i < paths.size(); i++){
01033 
01034       ME->getTH2F()->GetXaxis()->SetBinLabel(i+1, (paths[i]).c_str());
01035       ME->getTH2F()->GetYaxis()->SetBinLabel(i+1, (paths[i]).c_str());
01036       ME_Group_LS->getTH2F()->GetYaxis()->SetBinLabel(i+1, (paths[i]).c_str());
01037 
01038       ME_Normalized->getTH2F()->GetXaxis()->SetBinLabel(i+1, (paths[i]).c_str());
01039       ME_Normalized->getTH2F()->GetYaxis()->SetBinLabel(i+1, (paths[i]).c_str());
01040       ME_Normalized_Any->getTH1F()->GetXaxis()->SetBinLabel(i+1, (paths[i]).c_str());
01041       ME_Any->getTH1F()->GetXaxis()->SetBinLabel(i+1, (paths[i]).c_str());
01042 
01043     }
01044     
01045 }
01046 
01047 
01048 void TrigResRateMon::setupStreamMatrix(const std::string& label, vector<std::string>& paths) {
01049 
01050 
01051     paths.push_back("");
01052     paths.push_back("HLT_"+label+"_Any");
01053 
01054     string h_name; 
01055     string h_title; 
01056 
01057     dbe_->setCurrentFolder(pathsSummaryFolder_.c_str());
01058 
01059     h_name= "HLT_"+label+"_PassPass";
01060     h_title = "HLT_"+label+"_PassPass (x=Pass, y=Pass)";
01061     MonitorElement* ME = dbe_->book2D(h_name.c_str(), h_title.c_str(),
01062                            paths.size(), -0.5, paths.size()-0.5, paths.size(), -0.5, paths.size()-0.5);
01063 
01064     h_name= "HLT_"+label+"_Pass_Any";
01065     h_title = "HLT_"+label+"_Pass (x=Pass, Any=Pass) normalized to HLT_Any Pass";
01066     MonitorElement* ME_Any = dbe_->book1D(h_name.c_str(), h_title.c_str(),
01067                            paths.size(), -0.5, paths.size()-0.5);
01068 
01069     dbe_->setCurrentFolder(pathsSummaryHLTCorrelationsFolder_.c_str());
01070     h_name= "HLT_"+label+"_PassPass_Normalized";
01071     h_title = "HLT_"+label+"_PassPass (x=Pass, y=Pass) normalized to xBin=Pass";
01072     MonitorElement* ME_Normalized = dbe_->book2D(h_name.c_str(), h_title.c_str(),
01073                            paths.size(), -0.5, paths.size()-0.5, paths.size(), -0.5, paths.size()-0.5);
01074     h_name= "HLT_"+label+"_Pass_Normalized_Any";
01075     h_title = "HLT_"+label+"_Pass (x=Pass, Any=Pass) normalized to HLT_Any Pass";
01076     MonitorElement* ME_Normalized_Any = dbe_->book1D(h_name.c_str(), h_title.c_str(),
01077                            paths.size(), -0.5, paths.size()-0.5);
01078 
01079     for(unsigned int i = 0; i < paths.size(); i++){
01080 
01081       ME->getTH2F()->GetXaxis()->SetBinLabel(i+1, (paths[i]).c_str());
01082       ME->getTH2F()->GetYaxis()->SetBinLabel(i+1, (paths[i]).c_str());
01083 
01084       ME_Normalized->getTH2F()->GetXaxis()->SetBinLabel(i+1, (paths[i]).c_str());
01085       ME_Normalized->getTH2F()->GetYaxis()->SetBinLabel(i+1, (paths[i]).c_str());
01086 
01087       ME_Any->getTH1F()->GetXaxis()->SetBinLabel(i+1, (paths[i]).c_str());
01088       ME_Normalized_Any->getTH1F()->GetXaxis()->SetBinLabel(i+1, (paths[i]).c_str());
01089 
01090     }
01091 
01092 }
01093 
01094 void TrigResRateMon::fillHltMatrix(const edm::TriggerNames & triggerNames) {
01095 
01096  string fullPathToME; 
01097  std::vector <std::pair<std::string, bool> > groupAcceptPair;
01098 
01099   for (unsigned int mi=0;mi<fGroupNamePathsPair.size();mi++) {
01100 
01101 
01102   fullPathToME = pathsSummaryFolder_ + "HLT_"+fGroupNamePathsPair[mi].first+"_PassPass";
01103   MonitorElement* ME_2d = dbe_->get(fullPathToME);
01104   fullPathToME = pathsSummaryFolder_ + "HLT_"+fGroupNamePathsPair[mi].first+"_Pass_Any";
01105   MonitorElement* ME_1d = dbe_->get(fullPathToME);
01106   if(!ME_2d || !ME_1d) {  
01107 
01108     LogTrace("TrigResRateMon") << " ME not valid although I gave full path" << endl;
01109     continue;
01110 
01111   }
01112 
01113   TH2F * hist_2d = ME_2d->getTH2F();
01114   TH1F * hist_1d = ME_1d->getTH1F();
01115 
01116   // Fill HLTPassed Matrix bin (i,j) = (Any,Any)
01117   // --------------------------------------------------------
01118   int anyBinNumber = hist_2d->GetXaxis()->FindBin("HLT_Any");      
01119 
01120   //string groupBinLabel = "HLT_"+fGroupNamePathsPair[mi].first+"_Any";
01121   string groupBinLabel = "Total "+fGroupNamePathsPair[mi].first;
01122   int groupBinNumber = hist_2d->GetXaxis()->FindBin(groupBinLabel.c_str()); 
01123 
01124   // any triger accepted
01125   if(triggerResults_->accept()){
01126 
01127     hist_2d->Fill(anyBinNumber-1,anyBinNumber-1);//binNumber1 = 0 = first filter
01128     hist_1d->Fill(anyBinNumber-1);//binNumber1 = 0 = first filter
01129 
01130   }
01131 
01132   bool groupPassed = false;
01133   bool groupL1Passed = false;
01134 
01135   // Main loop over paths
01136   // --------------------
01137 
01138   //for (int i=1; i< hist_2d->GetNbinsX();i++) 
01139   for (unsigned int i=0; i< fGroupNamePathsPair[mi].second.size(); i++)
01140   { 
01141 
01142     //string hltPathName =  hist_2d->GetXaxis()->GetBinLabel(i);
01143     string hltPathName =  fGroupNamePathsPair[mi].second[i];
01144 
01145     // check if this is hlt path name
01146     //unsigned int pathByIndex = triggerNames.triggerIndex(hltPathName);
01147     unsigned int pathByIndex = triggerNames.triggerIndex(fGroupNamePathsPair[mi].second[i]);
01148     if(pathByIndex >= triggerResults_->size() ) continue;
01149 
01150     // check if its L1 passed
01151     // comment out below but set groupL1Passed to true always
01152     //if(hasL1Passed(hltPathName,triggerNames)) groupL1Passed = true;
01153     //groupL1Passed = true;
01154 
01155     // Fill HLTPassed Matrix and HLTPassFail Matrix
01156     // --------------------------------------------------------
01157 
01158     if(triggerResults_->accept(pathByIndex)){
01159 
01160       groupPassed = true;
01161       groupL1Passed = true;
01162 
01163       hist_2d->Fill(i,anyBinNumber-1);//binNumber1 = 0 = first filter
01164       hist_2d->Fill(anyBinNumber-1,i);//binNumber1 = 0 = first filter
01165 
01166       hist_2d->Fill(i,groupBinNumber-1);//binNumber1 = 0 = first filter
01167       hist_2d->Fill(groupBinNumber-1,i);//binNumber1 = 0 = first filter
01168      
01169       hist_1d->Fill(i);//binNumber1 = 0 = first filter
01170 
01171 
01172       //for (int j=1; j< hist_2d->GetNbinsY();j++) 
01173       for (unsigned int j=0; j< fGroupNamePathsPair[mi].second.size(); j++)
01174       { 
01175 
01176         string crossHltPathName =  fGroupNamePathsPair[mi].second[j];
01177   
01178         //unsigned int crosspathByIndex = triggerNames.triggerIndex(hist_2d->GetXaxis()->GetBinLabel(j));
01179         //unsigned int crosspathByIndex = triggerNames.triggerIndex(crossHltPathName);
01180         unsigned int crosspathByIndex = triggerNames.triggerIndex(fGroupNamePathsPair[mi].second[j]);
01181 
01182         if(crosspathByIndex >= triggerResults_->size() ) continue;
01183   
01184         if(triggerResults_->accept(crosspathByIndex)){
01185   
01186           hist_2d->Fill(i,j);//binNumber1 = 0 = first filter
01187   
01188         } // end if j path passed
01189   
01190       } // end for j 
01191   
01192     } // end if i passed
01193     
01194 
01195   } // end for i
01196 
01197   if(groupPassed) {
01198     
01199     hist_1d->Fill(groupBinNumber-1);//binNumber1 = 0 = first filter
01200     hist_2d->Fill(groupBinNumber-1,groupBinNumber-1);//binNumber1 = 0 = first filter
01201     hist_2d->Fill(anyBinNumber-1,groupBinNumber-1);//binNumber1 = 0 = first filter
01202     hist_2d->Fill(groupBinNumber-1,anyBinNumber-1);//binNumber1 = 0 = first filter
01203 
01204   }
01205 
01206   // if the group belongs to stream A
01207   // store groupName and Bool if it has passed 
01208   bool isGroupFromStreamA = false;
01209 
01210   vector<string> streamDatasetNames =  hltConfig_.streamContent("A") ;
01211   for (unsigned int g=0;g<streamDatasetNames.size();g++) {
01212 
01213     if(streamDatasetNames[g] == fGroupNamePathsPair[mi].first) 
01214     {
01215 
01216       isGroupFromStreamA = true;
01217       break;
01218 
01219     }
01220   }
01221 
01222   if(isGroupFromStreamA) groupAcceptPair.push_back(make_pair(fGroupNamePathsPair[mi].first,groupPassed));
01223 
01224 
01225   // L1 groups  - not used anymore
01226   string groupL1BinLabel = "HLT_"+fGroupNamePathsPair[mi].first+"_L1_Any";
01227   int groupL1BinNumber = hist_2d->GetXaxis()->FindBin(groupL1BinLabel.c_str());      
01228 
01229   if(groupL1Passed) hist_1d->Fill(groupL1BinNumber-1);//binNumber1 = 0 = first filter
01230 
01231  } // end for mi
01232 
01233   fullPathToME = pathsSummaryFolder_ + "HLT_A_PassPass";
01234   MonitorElement* ME_2d_Stream = dbe_->get(fullPathToME);
01235   fullPathToME = pathsSummaryFolder_ + "HLT_A_Pass_Any";
01236   MonitorElement* ME_1d_Stream = dbe_->get(fullPathToME);
01237   if(!ME_2d_Stream || !ME_1d_Stream) {  
01238 
01239     LogTrace("TrigResRateMon") << " ME not valid although I gave full path" << endl;
01240     return;
01241 
01242   }
01243   else {
01244 
01245     TH2F * hist_2d_Stream = ME_2d_Stream->getTH2F();
01246     TH1F * hist_1d_Stream = ME_1d_Stream->getTH1F();
01247     
01248     int streamBinNumber = hist_1d_Stream->GetXaxis()->GetLast();
01249 
01250     bool acceptedStreamA = false;
01251     
01252     // loop over groups
01253     for (unsigned int i=0;i<groupAcceptPair.size();i++) {
01254 
01255      if(groupAcceptPair[i].second) {
01256 
01257        acceptedStreamA = true;
01258 
01259        int groupBinNumber_i = hist_2d_Stream->GetXaxis()->FindBin(groupAcceptPair[i].first.c_str()); 
01260        //LogTrace("TrigResRateMon")  << "Accepted group X " << groupAcceptPair[i].first.c_str() << "    bin number " << groupBinNumber_i << endl;
01261        hist_1d_Stream->Fill(groupBinNumber_i-1);//binNumber1 = 0 = first filter
01262        hist_2d_Stream->Fill(groupBinNumber_i-1,streamBinNumber-1);//binNumber1 = 0 = first filter
01263        hist_2d_Stream->Fill(streamBinNumber-1,groupBinNumber_i-1);//binNumber1 = 0 = first filter
01264     
01265        for (unsigned int j=0;j<groupAcceptPair.size();j++) {
01266     
01267 
01268         if(groupAcceptPair[j].second) {
01269     
01270           int groupBinNumber_j = hist_2d_Stream->GetXaxis()->FindBin(groupAcceptPair[j].first.c_str()); 
01271           //LogTrace("TrigResRateMon") << "Accepted group Y " << groupAcceptPair[j].first.c_str() << "    bin number " << groupBinNumber_j << endl;
01272 
01273           // fill StreamMatrix(i,j)
01274           hist_2d_Stream->Fill(groupBinNumber_i-1,groupBinNumber_j-1);//binNumber1 = 0 = first filter
01275 
01276         } // end if j-th group accepted
01277     
01278       } // end for j
01279     
01280      } // end if i-th group accepted
01281     
01282     } // end for i
01283 
01284     if(acceptedStreamA) {
01285       
01286       hist_2d_Stream->Fill(streamBinNumber-1,streamBinNumber-1);//binNumber1 = 0 = first filter
01287       hist_1d_Stream->Fill(streamBinNumber-1);//binNumber1 = 0 = first filter
01288 
01289     }
01290 
01291  } // end else
01292 
01293 }
01294 
01295 void TrigResRateMon::setupHltBxPlots()
01296 {
01297 
01298   //pathsSummaryFolder_ = TString("HLT/TrigResults/PathsSummary/");
01299   //dbe_->setCurrentFolder(pathsSummaryFolder_.c_str());
01300   dbe_->setCurrentFolder(pathsSummaryFolder_);
01301 
01302   // setup HLT bx plot
01303   unsigned int npaths = hltPathsDiagonal_.size();
01304 
01305   ME_HLT_BX = dbe_->book2D("HLT_bx",
01306                          "HLT counts vs Event bx",
01307                          Nbx_+1, -0.5, Nbx_+1-0.5, npaths, -0.5, npaths-0.5);
01308   ME_HLT_CUSTOM_BX = dbe_->book2D("HLT_Custom_bx",
01309                          "HLT counts vs Event bx",
01310                          Nbx_+1, -0.5, Nbx_+1-0.5, npaths, -0.5, npaths-0.5);
01311   ME_HLT_BX->setAxisTitle("Bunch Crossing");
01312   ME_HLT_CUSTOM_BX->setAxisTitle("Bunch Crossing");
01313 
01314 
01315   // Set up bin labels on Y axis continuing to cover all npaths
01316   for(unsigned int i = 0; i < npaths; i++){
01317 
01318     ME_HLT_BX->getTH2F()->GetYaxis()->SetBinLabel(i+1, (hltPathsDiagonal_[i]).getPath().c_str());
01319     ME_HLT_CUSTOM_BX->getTH2F()->GetYaxis()->SetBinLabel(i+1, (hltPathsDiagonal_[i]).getPath().c_str());
01320 
01321   }
01322 
01323 
01324 }
01325 
01326 void TrigResRateMon::setupHltLsPlots()
01327 {
01328  
01329   unsigned int npaths = hltPathsDiagonal_.size();
01330 
01331   //pathsSummaryHLTPathsPerLSFolder_ = TString("HLT/TrigResults/PathsSummary/HLT LS/");
01332   //dbe_->setCurrentFolder(pathsSummaryHLTPathsPerLSFolder_.c_str());
01333   dbe_->setCurrentFolder(pathsSummaryHLTPathsPerLSFolder_);
01334 
01335   ME_HLTAll_LS  = dbe_->book2D("AllSelectedPaths_count_LS",
01336                     "AllSelectedPaths paths rate [Hz]",
01337                          nLS_, 0, nLS_, npaths+1, -0.5, npaths+1-0.5);
01338   ME_HLTAll_LS->setAxisTitle("Luminosity Section");
01339 
01340   // Set up bin labels on Y axis continuing to cover all npaths
01341   for(unsigned int i = 0; i < npaths; i++){
01342 
01343     ME_HLTAll_LS->getTH2F()->GetYaxis()->SetBinLabel(i+1, (hltPathsDiagonal_[i]).getPath().c_str());
01344 
01345   }
01346 
01347   unsigned int i = npaths;
01348   ME_HLTAll_LS->getTH2F()->GetYaxis()->SetBinLabel(i+1, "HLT_Any");
01349 
01350   int nBinsPerLSHisto = 20;
01351   int nLSHistos = npaths/nBinsPerLSHisto;
01352   for (int nh=0;nh<nLSHistos+1;nh++) {
01353 
01354     char name[200];
01355     char title[200];
01356 
01357     sprintf(name, "Group_%d_paths_count_LS",nLSHistos-nh);
01358     sprintf(title, "Group %d, paths rate [Hz]",nLSHistos-nh);
01359 
01360     MonitorElement* tempME  = dbe_->book2D(name,title,
01361                     nLS_, 0, nLS_, nBinsPerLSHisto+3, -0.5, nBinsPerLSHisto+3-0.5);
01362 
01363     tempME->setAxisTitle("LS");
01364 
01365     // Set up bin labels on Y axis continuing to cover all npaths
01366     for(int i = nh*nBinsPerLSHisto; i < (nh+1)*nBinsPerLSHisto; i++){
01367 
01368       if (i == int(npaths)) break;
01369 
01370       int bin;
01371       if(nh == 0){
01372 
01373        bin = i;
01374 
01375       }
01376       else {
01377 
01378        bin = i % nBinsPerLSHisto;
01379 
01380       }
01381 
01382       tempME->setBinLabel(bin+1, hltPathsDiagonal_[i].getPath().c_str(), 2);
01383 
01384     }
01385 
01386     tempME->setBinLabel(nBinsPerLSHisto+3, "HLT_Any", 2);
01387     tempME->setBinLabel(nBinsPerLSHisto+2, "HLT_PhysicsDeclared", 2);
01388 
01389     v_ME_HLTAll_LS.push_back(tempME);
01390 
01391   }
01392 
01393 
01394 }
01395 
01396 
01397 void TrigResRateMon::beginLuminosityBlock(const edm::LuminosityBlock& lumiSeg, const edm::EventSetup& c){   
01398 
01399    //int lumi = int(lumiSeg.id().luminosityBlock());
01400    //if(lumi < 74 || lumi > 77) fLumiFlag = false;
01401    //else fLumiFlag = true;
01402 
01403 }
01404 
01405 void TrigResRateMon::endLuminosityBlock(const edm::LuminosityBlock& lumiSeg, const edm::EventSetup& c)
01406 {
01407 
01408    int lumi = int(lumiSeg.id().luminosityBlock());
01409    LogTrace("TrigResRateMon") << " end lumiSection number " << lumi << endl;
01410 
01411   countHLTPathHitsEndLumiBlock(lumi);
01412   countHLTGroupHitsEndLumiBlock(lumi);
01413   //countHLTGroupL1HitsEndLumiBlock(lumi);
01414   //countHLTGroupBXHitsEndLumiBlock(lumi);
01415 
01416   normalizeHLTMatrix();
01417 
01418 }
01419 
01420 void TrigResRateMon::countHLTGroupBXHitsEndLumiBlock(const int& lumi)
01421 {
01422 
01423  LogTrace("TrigResRateMon") << " countHLTGroupBXHitsEndLumiBlock() lumiSection number " << lumi << endl;
01424 
01425    if(! ME_HLT_BX) return;
01426 
01427    TH2F * hist_2d_bx = ME_HLT_BX->getTH2F();
01428 
01429    for (std::vector<std::pair<std::string, vector<int> > >::iterator ip = fPathBxTempCountPair.begin(); ip != fPathBxTempCountPair.end(); ++ip) {
01430   
01431     // get the path and its previous count
01432     std::string pathname = ip->first;  
01433     vector<int> prevCount = ip->second;  
01434 
01435     // vector of 5 zeros
01436     vector<int> currCount (5,0);
01437     vector<int> diffCount (5,0);
01438     
01439     // get the current count of path up to now
01440     int pathBin = hist_2d_bx->GetYaxis()->FindBin(pathname.c_str());      
01441 
01442     if(pathBin > hist_2d_bx->GetNbinsY()) {
01443       
01444       LogTrace("TrigResRateMon") << " Cannot find the bin for path " << pathname << endl;
01445       continue;
01446 
01447     }
01448 
01449     for (unsigned int b =0;b<currCount.size();b++) { 
01450 
01451       int bxOffset = b-2;
01452       int bunch = referenceBX_+bxOffset;
01453       if(bunch < 1) bunch += Nbx_ ;
01454       int bxBin = bunch +1; // add one to get the right bin
01455 
01456       
01457       currCount[b] = int(hist_2d_bx->GetBinContent(bxBin, pathBin));  // add one to get the right bin
01458 
01459       LogTrace("TrigResRateMon") << "currCount = " << currCount[b] << endl;
01460 
01461       // count due to prev lumi sec is a difference bw current and previous
01462       diffCount[b] = currCount[b] - prevCount[b];
01463 
01464       LogTrace("TrigResRateMon") << " lumi = " << lumi << "  path " << pathname << "bxOffset = " << bxOffset << "  count = " << diffCount[b] <<  endl;
01465 
01466     } // end for bx b
01467 
01468     // set the counter in the pair to current count
01469     ip->second = currCount;  
01470 
01472    // fill the 2D Group paths' BX count per LS, using currCount
01474    LogTrace("TrigResRateMon")  << "Find " << pathname << endl;
01475 
01476    //check if the path is in this group
01477    //for (unsigned int j=0;j<fGroupNamePathsPair.size();j++) 
01478    for (unsigned int j=0;j<v_ME_Total_BX.size();j++) 
01479    { 
01480 
01481       bool isMember = false;
01482 
01483       LogTrace("TrigResRateMon")  << " ---- Group " << fGroupNamePathsPair[j].first << endl;
01484 
01485       // decide if pathname is member of this group
01486       for (unsigned int k = 0; k<(fGroupNamePathsPair[j].second).size();k++) {
01487 
01488         LogTrace("TrigResRateMon")  << " comparing to " <<  fGroupNamePathsPair[j].second[k] << endl; 
01489 
01490         if(fGroupNamePathsPair[j].second[k] == pathname) {
01491 
01492           isMember = true;
01493           break;
01494 
01495         }
01496 
01497       } // end for k
01498 
01499       if(!isMember) {
01500       
01501       LogTrace("TrigResRateMon")  << "Could not find a group to which the path belongs, path = " << pathname << "    group = " << fGroupNamePathsPair[j].first << endl;
01502       continue;
01503 
01504       }
01505 
01506       MonitorElement* ME_2d = v_ME_Total_BX[j];
01507 
01508       if (! ME_2d) {
01509 
01510         LogDebug("TrigResRateMon") << " cannot find ME_2d for group " << fGroupNamePathsPair[j].first  <<  endl;
01511         continue;
01512 
01513       }
01514 
01515       vector<int> updatedLumiCount(5,0);
01516 
01517       float entireBXWindowUpdatedLumiCount = 0;
01518       
01519       TH2F* hist_All = ME_2d->getTH2F();
01520 
01521       for (unsigned int b = 0; b<diffCount.size();b++) {
01522 
01523         // find the bin
01524         int binNumber = b+1; // add one to get right bin
01525 
01526         // update  the bin content  (must do that since events don't ncessarily come in the order
01527         int currentLumiCount = int(hist_All->GetBinContent(lumi+1,binNumber));
01528         updatedLumiCount[b] = currentLumiCount + diffCount[b];
01529         hist_All->SetBinContent(lumi+1,binNumber,updatedLumiCount[b]);
01530 
01531         entireBXWindowUpdatedLumiCount += updatedLumiCount[b];
01532         
01533       } // end for bx b
01534 
01535       MonitorElement* ME_2d_Norm = v_ME_Total_BX_Norm[j];
01536 
01537       if (! ME_2d_Norm) {
01538 
01539         LogDebug("TrigResRateMon") << " cannot find ME_2d_Norm for group " << fGroupNamePathsPair[j].first  <<  endl;
01540         continue;
01541 
01542       }
01543 
01544       TH2F* hist_All_Norm = ME_2d_Norm->getTH2F();
01545 
01546       for (unsigned int b = 0; b<diffCount.size();b++) {
01547 
01548         // find the bin
01549         int binNumber = b+1; // add one to get right bin
01550 
01551         // update  the bin content  but normalized to the whole columb (BX windw +/- 2)
01552         hist_All_Norm->SetBinContent(lumi+1,binNumber,float(updatedLumiCount[b])/entireBXWindowUpdatedLumiCount);
01553 
01554       } // end for bx b
01555     
01556     } // end for group j
01557     
01558   } // end for ip
01559 
01560 }
01561 
01562 void TrigResRateMon::countHLTGroupL1HitsEndLumiBlock(const int& lumi)
01563 {
01564 
01565  LogTrace("TrigResRateMon") << " countHLTGroupL1HitsEndLumiBlock() lumiSection number " << lumi << endl;
01566 
01567  for(unsigned int i=0; i<fGroupNamePathsPair.size(); i++){
01568 
01569    // get the count of path up to now
01570    string fullPathToME = pathsSummaryFolder_ +  "HLT_" + fGroupNamePathsPair[i].first+ "_Pass_Any";
01571    MonitorElement* ME_1d = dbe_->get(fullPathToME);
01572 
01573    if(! ME_1d) {
01574 
01575      LogTrace("TrigResRateMon") << " could not find 1d matrix " << fullPathToME << endl;
01576 
01577      continue;
01578 
01579    }
01580 
01581    LogTrace("TrigResRateMon") << " Looking in histogram "  << fullPathToME << endl;
01582 
01583    TH1F * hist_1d = ME_1d->getTH1F();
01584 
01585    for (std::vector<std::pair<std::string, float> >::iterator ip = fGroupL1TempCountPair.begin(); ip != fGroupL1TempCountPair.end(); ++ip) {
01586   
01587     // get the path and its previous count
01588     string pathname = ip->first;  
01589     float prevCount = ip->second;  
01590 
01591     string binLabel = "HLT_"+pathname+"_L1_Any";
01592     
01593     LogTrace("TrigResRateMon") << " Looking for binLabel = " << binLabel <<  endl;
01594     // get the current count of path up to now
01595     int pathBin = hist_1d->GetXaxis()->FindBin(binLabel.c_str());      
01596 
01597     LogTrace("TrigResRateMon") << " pathBin = " << pathBin <<  "  out of histogram total number of bins " << hist_1d->GetNbinsX() <<  endl;
01598     if(pathBin == -1) {
01599       
01600       LogTrace("TrigResRateMon") << " Cannot find the bin for path " << pathname << endl;
01601       continue;
01602 
01603     }
01604 
01605     float currCount = hist_1d->GetBinContent(pathBin)/LSsize_;
01606 
01607     // count due to prev lumi sec is a difference bw current and previous
01608     float diffCount = currCount - prevCount;
01609 
01610     LogTrace("TrigResRateMon") << " lumi = " << lumi << "  path " << pathname << "  count " << diffCount <<  endl;
01611 
01612     // set the counter in the pair to current count
01613     ip->second = currCount;  
01614 
01615 
01617     // fill the 1D individual path count per LS
01619     string fullPathToME_count = pathsSummaryHLTPathsPerLSFolder_ +"HLT_" + pathname + "_L1_Total_LS";
01620     MonitorElement* ME_1d = dbe_->get(fullPathToME_count);
01621     if ( ME_1d) { 
01622 
01623       // update  the bin content  (must do that since events don't ncessarily come in the order
01624       float currentLumiCount = ME_1d->getTH1()->GetBinContent(lumi+1);
01625       float updatedLumiCount = currentLumiCount + diffCount;
01626       ME_1d->getTH1()->SetBinContent(lumi+1,updatedLumiCount);
01627 
01628     }
01629     else {
01630 
01631       LogDebug("TrigResRateMon") << " cannot find ME " << fullPathToME_count  <<  endl;
01632 
01633     }
01634 
01635    } // end for ip
01636 
01637  } // end for i
01638 
01639 }
01640 
01641 
01642 void TrigResRateMon::countHLTGroupHitsEndLumiBlock(const int& lumi)
01643 {
01644 
01645  LogTrace("TrigResRateMon") << " countHLTGroupHitsEndLumiBlock() lumiSection number " << lumi << endl;
01646  for(unsigned int i=0; i<fGroupNamePathsPair.size(); i++){
01647 
01648    // get the count of path up to now
01649    string fullPathToME = pathsSummaryFolder_ + "HLT_" + fGroupNamePathsPair[i].first + "_Pass_Any";
01650    MonitorElement* ME_1d = dbe_->get(fullPathToME);
01651 
01652    if(! ME_1d) {
01653 
01654      LogTrace("TrigResRateMon") << " could not find 1d matrix " << fullPathToME << endl;
01655 
01656      continue;
01657 
01658    }
01659 
01660    LogTrace("TrigResRateMon") << " Looking in histogram "  << fullPathToME << endl;
01661 
01662    TH1F * hist_1d = ME_1d->getTH1F();
01663 
01664    for (std::vector<std::pair<std::string, float> >::iterator ip = fGroupTempCountPair.begin(); ip != fGroupTempCountPair.end(); ++ip) {
01665   
01666     // get the path and its previous count
01667     string pathname = ip->first;  
01668     float prevCount = ip->second;  
01669 
01670     string binLabel = "Total "+pathname;
01671     
01672     LogTrace("TrigResRateMon") << " Looking for binLabel = " << binLabel <<  endl;
01673 
01674     // get the current count of path up to now
01675     int pathBin = hist_1d->GetXaxis()->FindBin(binLabel.c_str());      
01676 
01677     LogTrace("TrigResRateMon") << " pathBin = " << pathBin <<  "  out of histogram total number of bins " << hist_1d->GetNbinsX() <<  endl;
01678     if(pathBin == -1) {
01679       
01680       binLabel = pathname;
01681       int alternativePathBin = hist_1d->GetXaxis()->FindBin(binLabel.c_str());      
01682 
01683       if(alternativePathBin == -1) {
01684 
01685         LogTrace("TrigResRateMon") << " Cannot find the bin for path " << pathname << endl;
01686 
01687         continue;
01688 
01689       }
01690       else {
01691 
01692         pathBin = alternativePathBin;
01693 
01694       }
01695 
01696     }
01697 
01698     float currCount = hist_1d->GetBinContent(pathBin)/LSsize_;
01699 
01700     // count due to prev lumi sec is a difference bw current and previous
01701     float diffCount = currCount - prevCount;
01702 
01703     LogTrace("TrigResRateMon") << " lumi = " << lumi << "  path " << pathname << "  diffCount " << diffCount <<  endl;
01704 
01705     // set the counter in the pair to current count
01706     ip->second = currCount;  
01707 
01709     // fill the 1D and 2D gruop and 2d_Stream_A count per LS
01711     string fullPathToME_count = pathsSummaryHLTPathsPerLSFolder_ +"HLT_" + pathname + "_Total_LS";
01712     MonitorElement* ME_1d = dbe_->get(fullPathToME_count);
01713 
01714     string fullPathToME_2D_count = pathsSummaryHLTPathsPerLSFolder_ +"HLT_" + pathname + "_LS";
01715     MonitorElement* ME_2d = dbe_->get(fullPathToME_2D_count);
01716 
01717     string fullPathToME_Stream_A_2D_count = pathsSummaryHLTPathsPerLSFolder_ +"HLT_A_LS";
01718     MonitorElement* ME_Stream_A_2d = dbe_->get(fullPathToME_Stream_A_2D_count);
01719 
01720     if ( ME_1d && ME_2d && ME_Stream_A_2d) { 
01721 
01722       // update  the bin content  (must do that since events don't ncessarily come in the order
01723 
01724       float currentLumiCount = ME_1d->getTH1()->GetBinContent(lumi+1);
01725       float updatedLumiCount = currentLumiCount + diffCount;
01726       ME_1d->getTH1()->SetBinContent(lumi+1,updatedLumiCount);
01727 
01728       string groupBinLabel = "Total " + fGroupNamePathsPair[i].first;
01729       int groupBin = ME_2d->getTH2F()->GetYaxis()->FindBin(groupBinLabel.c_str());      
01730       if(groupBin != -1) ME_2d->getTH2F()->SetBinContent(lumi+1,groupBin,updatedLumiCount);
01731       
01732       // this is to deal with Stream A and bins with names of PDs
01733       groupBinLabel = fGroupNamePathsPair[i].first;
01734       groupBin = ME_Stream_A_2d->getTH2F()->GetYaxis()->FindBin(groupBinLabel.c_str());      
01735       if(groupBin != -1) ME_Stream_A_2d->getTH2F()->SetBinContent(lumi+1,groupBin,updatedLumiCount);
01736 
01737     }
01738     else {
01739 
01740       LogDebug("TrigResRateMon") << " cannot find ME " << fullPathToME_count  <<  endl;
01741 
01742     }
01743 
01744    } // end for ip
01745 
01746  } // end for i
01747 
01748 }
01749 
01750 
01751 void TrigResRateMon::countHLTPathHitsEndLumiBlock(const int& lumi)
01752 {
01753 
01754    LogTrace("TrigResRateMon") << " countHLTPathHitsEndLumiBlock() lumiSection number " << lumi << endl;
01755     // get the count of path up to now
01756    string fullPathToME = pathsSummaryFolder_ + "HLT_AllSelectedPaths_PassPass";
01757    MonitorElement* ME_2d = dbe_->get(fullPathToME);
01758 
01759    if(! ME_2d) {
01760 
01761      LogTrace("TrigResRateMon") << " could not fine 2d matrix " << fullPathToME << endl;
01762 
01763      return;
01764 
01765    }
01766 
01767    TH2F * hist_2d = ME_2d->getTH2F();
01768 
01769    for (std::vector<std::pair<std::string, float> >::iterator ip = fPathTempCountPair.begin(); ip != fPathTempCountPair.end(); ++ip) {
01770   
01771     // get the path and its previous count
01772     std::string pathname = ip->first;  
01773     float prevCount = ip->second;  
01774     
01775     // get the current count of path up to now
01776     float pathBin = hist_2d->GetXaxis()->FindBin(pathname.c_str());      
01777 
01778     if(pathBin > hist_2d->GetNbinsX()) {
01779       
01780       LogTrace("TrigResRateMon") << " Cannot find the bin for path " << pathname << endl;
01781       continue;
01782 
01783     }
01784 
01785     float currCount = hist_2d->GetBinContent(pathBin, pathBin)/LSsize_;
01786 
01787     // count due to prev lumi sec is a difference bw current and previous
01788     float diffCount = currCount - prevCount;
01789 
01790     LogTrace("TrigResRateMon") << " lumi = " << lumi << "  path " << pathname << "  count " << diffCount <<  endl;
01791 
01792     // set the counter in the pair to current count
01793     ip->second = currCount;  
01794 
01796     // fill the 2D All paths' count per LS
01798     if ( ME_HLTAll_LS) {
01799 
01800       TH2F* hist_All = ME_HLTAll_LS->getTH2F();
01801 
01802       // find the bin
01803       int pathBinNumber = hist_All->GetYaxis()->FindBin(pathname.c_str());
01804       
01805       // update  the bin content  (must do that since events don't ncessarily come in the order
01806       float currentLumiCount = hist_All->GetBinContent(lumi+1,pathBinNumber);
01807       float updatedLumiCount = currentLumiCount + diffCount;
01808       hist_All->SetBinContent(lumi+1,pathBinNumber,updatedLumiCount);
01809     
01810     }
01811     else {
01812 
01813       LogDebug("TrigResRateMon") << " cannot find ME_HLTAll_LS" <<  endl;
01814 
01815     }
01816     
01817     for (unsigned int i=0 ; i< v_ME_HLTAll_LS.size(); i++) {  
01818       
01819       MonitorElement* tempME = v_ME_HLTAll_LS[i];
01820 
01821       if ( tempME ) {
01822   
01823         TH2F* hist_All = tempME->getTH2F();
01824   
01825         // find the bin
01826         int pathBinNumber = hist_All->GetYaxis()->FindBin(pathname.c_str());
01827         // update  the bin content  (must do that since events don't ncessarily come in the order
01828         float currentLumiCount = hist_All->GetBinContent(lumi+1,pathBinNumber);
01829         float updatedLumiCount = currentLumiCount + diffCount;
01830         hist_All->SetBinContent(lumi+1,pathBinNumber,updatedLumiCount);
01831       
01832       }
01833       else {
01834   
01835         LogDebug("TrigResRateMon") << " cannot find tempME " <<  endl;
01836   
01837       }
01838 
01839     }
01840 
01841 
01843     // fill the 1D individual path count per LS
01845     string fullPathToME_count = pathsIndividualHLTPathsPerLSFolder_ + pathname + "_count_per_LS";
01846     MonitorElement* ME_1d = dbe_->get(fullPathToME_count);
01847     if ( ME_1d) { 
01848 
01849       // update  the bin content  (must do that since events don't ncessarily come in the order
01850       float currentLumiCount = ME_1d->getTH1()->GetBinContent(lumi+1);
01851       float updatedLumiCount = currentLumiCount + diffCount;
01852       ME_1d->getTH1()->SetBinContent(lumi+1,updatedLumiCount);
01853 
01854     }
01855     else {
01856 
01857       LogDebug("TrigResRateMon") << " cannot find ME " << fullPathToME_count  <<  endl;
01858 
01859     }
01860 
01861   } // end for ip
01862 
01863 }
01864 
01865 int TrigResRateMon::getTriggerTypeParsePathName(const string& pathname)
01866 {
01867 
01868    int objectType = 0;
01869 
01870          if (pathname.find("MET") != std::string::npos) 
01871            objectType = trigger::TriggerMET;    
01872          if (pathname.find("SumET") != std::string::npos) 
01873            objectType = trigger::TriggerTET;    
01874          if (pathname.find("HT") != std::string::npos) 
01875            objectType = trigger::TriggerTET;    
01876          if (pathname.find("Jet") != std::string::npos) 
01877            objectType = trigger::TriggerJet;    
01878          if (pathname.find("Mu") != std::string::npos)
01879            objectType = trigger::TriggerMuon;    
01880          if (pathname.find("Ele") != std::string::npos) 
01881            objectType = trigger::TriggerElectron;    
01882          if (pathname.find("Photon") != std::string::npos) 
01883            objectType = trigger::TriggerPhoton;    
01884          if (pathname.find("EG") != std::string::npos) 
01885            objectType = trigger::TriggerPhoton;    
01886          if (pathname.find("Tau") != std::string::npos) 
01887            objectType = trigger::TriggerTau;    
01888          if (pathname.find("IsoTrack") != std::string::npos) 
01889            objectType = trigger::TriggerTrack;    
01890          if (pathname.find("BTag") != std::string::npos) 
01891            objectType = trigger::TriggerBJet;    
01892 
01893    return objectType;
01894 }
01895 
01896 const string TrigResRateMon::getL1ConditionModuleName(const string& pathname)
01897 {
01898 
01899   // find L1 condition for numpath with numpath objecttype 
01900   // find PSet for L1 global seed for numpath, 
01901   // list module labels for numpath
01902   string l1pathname = "dummy";
01903 
01904   vector<string> numpathmodules = hltConfig_.moduleLabels(pathname);
01905 
01906   for(vector<string>::iterator numpathmodule = numpathmodules.begin();
01907   numpathmodule!= numpathmodules.end(); ++numpathmodule ) {
01908 
01909     if (hltConfig_.moduleType(*numpathmodule) == "HLTLevel1GTSeed") {
01910 
01911      l1pathname = *numpathmodule;
01912      break; 
01913 
01914     }
01915 
01916   } // end for
01917 
01918   return l1pathname;
01919 
01920 }
01921 
01922 
01923 bool TrigResRateMon::hasL1Passed(const string& pathname, const edm::TriggerNames & triggerNames)
01924 {
01925   
01926   bool rc = false;
01927   int l1ModuleIndex = 999;
01928   // --------------------
01929   for(PathInfoCollection::iterator v = hltPathsDiagonal_.begin(); v!= hltPathsDiagonal_.end(); ++v ) { 
01930 
01931     if(v->getPath() == pathname ) l1ModuleIndex = v->getL1ModuleIndex();
01932 
01933   }
01934 
01935   unsigned int pathByIndex = triggerNames.triggerIndex(pathname);
01936   if(pathByIndex >= triggerResults_->size() ) return rc; // path is not in the menu
01937 
01938   // get index of the last module that issued the decision
01939   int lastModule = triggerResults_->index(pathByIndex);
01940 
01941   // if L1 passed, then it must not be the module that 
01942   // issued the last decision
01943   rc = (l1ModuleIndex < lastModule);
01944 
01945   return rc;
01946 
01947 }
01948 
01949 bool TrigResRateMon::hasHLTPassed(const string& pathname, const edm::TriggerNames & triggerNames)
01950 {
01951   
01952   bool rc = false;
01953 
01954   unsigned int pathByIndex = triggerNames.triggerIndex(pathname);
01955   if(pathByIndex >= triggerResults_->size() ) return rc; // path is not in the menu
01956 
01957   rc  = triggerResults_->accept(pathByIndex);
01958 
01959   return rc;
01960 
01961 }
01962 
01963 
01964 int TrigResRateMon::getThresholdFromName(const string & name)
01965 {
01966   
01967   std::string pathname = name;
01968   //cout << "----------------------------------------------" << endl;
01969   //cout << pathname << endl;
01970 
01971   //remove "L1" substr
01972   if(pathname.find("L1") != std::string::npos) pathname.replace(pathname.find("L1"),2,"");
01973   //remove "L2" substr
01974   if(pathname.find("L2") != std::string::npos) pathname.replace(pathname.find("L2"),2,"");
01975   //remove "8E29" substr
01976   if(pathname.find("8E29") != std::string::npos) pathname.replace(pathname.find("8E29"),4,"");
01977 
01978   int digitLocation=0;
01979   for (unsigned int i=0; i < pathname.length(); i++)
01980   {
01981      if (isdigit(pathname.at(i))) {
01982 
01983        digitLocation = i;
01984        break;
01985 
01986      }
01987   }
01988 
01989   // get the string from the location of the first digit to the end
01990   string hltThresholdString = pathname.substr(digitLocation);
01991 
01992   int hltThreshold = 0;
01993 
01994   // get intiger at the begining of the string
01995   sscanf (hltThresholdString.c_str(),"%d%*s",&hltThreshold);
01996   //printf ("%s -> %s -> %d\n",pathname.c_str(), hltThresholdString.c_str(), hltThreshold);
01997 
01998   return hltThreshold;
01999 
02000 }
02001 
02002 void TrigResRateMon::normalizeHLTMatrix() {
02003 
02004   string fullPathToME; 
02005 
02006   // again, get hold of dataset names 
02007   //vector<string> datasetNames =  hltConfig_.datasetNames() ;
02008   vector<string> datasetNames =  hltConfig_.streamContent("A") ;
02009 
02010   // fill vectors of MEs needed in  normalization
02011   for (unsigned int i=0;i<datasetNames.size();i++) {
02012 
02013     fullPathToME = pathsSummaryFolder_ +"HLT_"+datasetNames[i]+"_PassPass";
02014     v_ME_HLTPassPass.push_back( dbe_->get(fullPathToME));
02015 
02016     fullPathToME = pathsSummaryHLTCorrelationsFolder_+"HLT_"+datasetNames[i]+"_PassPass_Normalized";
02017     v_ME_HLTPassPass_Normalized.push_back( dbe_->get(fullPathToME));
02018 
02019     fullPathToME = pathsSummaryHLTCorrelationsFolder_+"HLT_"+datasetNames[i]+"_Pass_Normalized_Any";
02020     v_ME_HLTPass_Normalized_Any.push_back( dbe_->get(fullPathToME));
02021 
02022   }
02023 
02024   // add stream MEs
02025   fullPathToME = pathsSummaryFolder_ +"HLT_A_PassPass";
02026   v_ME_HLTPassPass.push_back( dbe_->get(fullPathToME));
02027 
02028   fullPathToME = pathsSummaryHLTCorrelationsFolder_+"HLT_A_PassPass_Normalized";
02029   v_ME_HLTPassPass_Normalized.push_back( dbe_->get(fullPathToME));
02030 
02031   fullPathToME = pathsSummaryHLTCorrelationsFolder_+"HLT_A_Pass_Normalized_Any";
02032   v_ME_HLTPass_Normalized_Any.push_back( dbe_->get(fullPathToME));
02033 
02034   for (unsigned int i =0;i<v_ME_HLTPassPass.size();i++) {
02035 
02036     MonitorElement* ME_HLTPassPass = v_ME_HLTPassPass[i]; 
02037     MonitorElement* ME_HLTPassPass_Normalized = v_ME_HLTPassPass_Normalized[i]; 
02038     MonitorElement* ME_HLTPass_Normalized_Any = v_ME_HLTPass_Normalized_Any[i]; 
02039 
02040     if(!ME_HLTPassPass || !ME_HLTPassPass_Normalized || !ME_HLTPass_Normalized_Any) return;
02041 
02042     float passCount = 0;
02043     unsigned int nBinsX = ME_HLTPassPass->getTH2F()->GetNbinsX();
02044     unsigned int nBinsY = ME_HLTPassPass->getTH2F()->GetNbinsY();
02045 
02046     for(unsigned int binX = 0; binX < nBinsX+1; binX++) {
02047        
02048       passCount = ME_HLTPassPass->getTH2F()->GetBinContent(binX,binX);
02049 
02050 
02051       for(unsigned int binY = 0; binY < nBinsY+1; binY++) {
02052 
02053         if(passCount != 0) {
02054 
02055           // normalize each bin to number of passCount
02056           float normalizedBinContentPassPass = (ME_HLTPassPass->getTH2F()->GetBinContent(binX,binY))/passCount;
02057           //float normalizedBinContentPassFail = (ME_HLTPassFail_->getTH2F()->GetBinContent(binX,binY))/passCount;
02058 
02059           ME_HLTPassPass_Normalized->getTH2F()->SetBinContent(binX,binY,normalizedBinContentPassPass);
02060           //ME_HLTPassFail_Normalized_->getTH2F()->SetBinContent(binX,binY,normalizedBinContentPassFail);
02061 
02062           if(binX == nBinsX) {
02063 
02064             ME_HLTPass_Normalized_Any->getTH1F()->SetBinContent(binY,normalizedBinContentPassPass);
02065 
02066           }
02067 
02068         }
02069         else {
02070 
02071           ME_HLTPassPass_Normalized->getTH2F()->SetBinContent(binX,binY,0);
02072           //ME_HLTPassFail_Normalized_->getTH2F()->SetBinContent(binX,binY,0);
02073 
02074         } // end if else
02075      
02076       } // end for binY
02077 
02078     } // end for binX
02079   
02080   } // end for i
02081 
02082 }