CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/DQMOffline/Trigger/src/BTagHLTOfflineSource.cc

Go to the documentation of this file.
00001 /*
00002   New version of HLT Offline DQM code for BTagMu paths
00003   responsible: Jyothsna Komaragiri
00004 */
00005 
00006 #include "TMath.h"
00007 #include "FWCore/Framework/interface/EDAnalyzer.h"
00008 #include "DataFormats/Common/interface/Handle.h"
00009 #include "FWCore/Framework/interface/Run.h"
00010 #include "FWCore/Framework/interface/MakerMacros.h"
00011 #include "FWCore/Framework/interface/ESHandle.h"
00012 
00013 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00014 #include "DQMOffline/Trigger/interface/BTagHLTOfflineSource.h"
00015 
00016 #include "DataFormats/Common/interface/TriggerResults.h"
00017 #include "DataFormats/HLTReco/interface/TriggerEvent.h"
00018 #include "DataFormats/HLTReco/interface/TriggerObject.h"
00019 #include "FWCore/Common/interface/TriggerNames.h"
00020 #include "DataFormats/HLTReco/interface/TriggerTypeDefs.h"
00021 #include "HLTrigger/HLTcore/interface/HLTConfigProvider.h"
00022 
00023 #include "DataFormats/Math/interface/deltaR.h"
00024 
00025 #include "DQMServices/Core/interface/MonitorElement.h"
00026 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00027 #include "math.h"
00028 #include "TH1F.h"
00029 #include "TProfile.h"
00030 #include "TH2F.h"
00031 #include "TPRegexp.h"
00032 
00033 using namespace edm;
00034 using namespace reco;
00035 using namespace std;
00036 
00037   
00038 BTagHLTOfflineSource::BTagHLTOfflineSource(const edm::ParameterSet& iConfig):
00039   isSetup_(false)
00040 {
00041 
00042 
00043   SelectedCaloJets = new reco::CaloJetCollection;
00044   SelectedMuons = new reco::MuonCollection;
00045 
00046   LogDebug("BTagHLTOfflineSource") << "constructor....";
00047 
00048   dbe = Service < DQMStore > ().operator->();
00049   if ( ! dbe ) {
00050     LogDebug("BTagHLTOfflineSource") << "unabel to get DQMStore service?";
00051   }
00052   if (iConfig.getUntrackedParameter < bool > ("DQMStore", false)) {
00053     dbe->setVerbose(0);
00054   }
00055   
00056 
00057   dirname_ = iConfig.getUntrackedParameter("dirname",
00058                                            std::string("HLT/BTag/"));
00059   
00060   processname_  = iConfig.getParameter<std::string>("processname");
00061   verbose_      = iConfig.getUntrackedParameter< bool >("verbose", false);
00062   plotEff_      = iConfig.getUntrackedParameter< bool >("plotEff", false);
00063   nameForEff_   = iConfig.getUntrackedParameter< bool >("nameForEff", true);
00064 
00065   jetID = new reco::helper::JetIDHelper(iConfig.getParameter<ParameterSet>("JetIDParams"));
00066   
00067   // plotting paramters
00068   MuonTrigPaths_ = iConfig.getUntrackedParameter<vector<std::string> >("pathnameMuon");
00069   MBTrigPaths_   = iConfig.getUntrackedParameter<vector<std::string> >("pathnameMB");
00070   caloJetsTag_   = iConfig.getParameter<edm::InputTag>("CaloJetCollectionLabel");
00071   muonTag_       = iConfig.getParameter<edm::InputTag>("MuonCollectionLabel");
00072 
00073   triggerSummaryLabel_ = iConfig.getParameter<edm::InputTag>("triggerSummaryLabel");
00074   triggerResultsLabel_ = iConfig.getParameter<edm::InputTag>("triggerResultsLabel");
00075   custompathname       = iConfig.getUntrackedParameter<vector<std::string> >("paths");
00076 
00077   //Jet selection cuts
00078   _jetpt   = iConfig.getUntrackedParameter< double >("jetpt", 20.);
00079   _jeteta  = iConfig.getUntrackedParameter< double >("jeteta", 2.40);
00080   _fEMF    = iConfig.getUntrackedParameter< double >("fEMF", 0.01);
00081   _fHPD    = iConfig.getUntrackedParameter< double >("fHPD", 0.98);
00082   _n90Hits = iConfig.getUntrackedParameter< double >("n90Hits", 1.0);
00083 
00084   //Muon selection cuts
00085   _mupt             = iConfig.getUntrackedParameter< double >("mupt", 6.);
00086   _mueta            = iConfig.getUntrackedParameter< double >("mueta", 2.40);
00087   _muonHits         = iConfig.getUntrackedParameter< int >("muonHits");
00088   _nMatches         = iConfig.getUntrackedParameter< int >("nMatches");
00089   _trackerHits      = iConfig.getUntrackedParameter< int >("trackerHits");
00090   _pixelHits        = iConfig.getUntrackedParameter< int >("pixelHits");
00091   _outerHits        = iConfig.getUntrackedParameter< int >("outerHits");
00092   _tknormalizedChi2 = iConfig.getUntrackedParameter< double >("tknormalizedChi2");
00093   _gmnormalizedChi2 = iConfig.getUntrackedParameter< double >("gmnormalizedChi2");
00094   _mudZ             = iConfig.getUntrackedParameter< double >("mudZ");
00095   _mujetdR          = iConfig.getUntrackedParameter< double >("mujetdR");
00096 
00097 
00098   // this is the list of paths to look at.
00099   std::vector<edm::ParameterSet> paths =  iConfig.getParameter<std::vector<edm::ParameterSet> >("pathPairs");
00100   for(std::vector<edm::ParameterSet>::iterator pathconf = paths.begin() ; pathconf != paths.end();  pathconf++) {
00101     std::pair<std::string, std::string> custompathnamepair;
00102     custompathnamepair.first =pathconf->getParameter<std::string>("pathname"); 
00103     custompathnamepair.second = pathconf->getParameter<std::string>("denompathname");   
00104     custompathnamepairs_.push_back(custompathnamepair);
00105   } 
00106   
00107 }
00108 
00109 //--------------------------------------------------------
00110 BTagHLTOfflineSource::~BTagHLTOfflineSource() {
00111  
00112   // do anything here that needs to be done at desctruction time
00113   // (e.g. close files, deallocate resources etc.)
00114   
00115   delete SelectedCaloJets;
00116   delete SelectedMuons;
00117 
00118 }
00119 
00120 //--------------------------------------------------------
00121 void BTagHLTOfflineSource::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup){
00122   
00123   using namespace edm;
00124   using namespace trigger;
00125   using namespace reco;
00126 
00127   //---------- triggerResults ----------
00128   iEvent.getByLabel(triggerResultsLabel_, triggerResults_);
00129   if(!triggerResults_.isValid()) {
00130     edm::InputTag triggerResultsLabelFU(triggerResultsLabel_.label(),triggerResultsLabel_.instance(), "FU");
00131     iEvent.getByLabel(triggerResultsLabelFU,triggerResults_);
00132     if(!triggerResults_.isValid()) {
00133       edm::LogInfo("BTagHLTOfflineSource") << "TriggerResults not found, "
00134         "skipping event";
00135       return;
00136     }
00137   }
00138   
00139   int npath;
00140   if(&triggerResults_) {
00141   
00142     // Check how many HLT triggers are in triggerResults
00143     npath = triggerResults_->size();
00144     triggerNames_ = iEvent.triggerNames(*triggerResults_);
00145     
00146   } 
00147   else {
00148     
00149     edm::LogInfo("BTagHLTOfflineSource") << "TriggerResults::HLT not found, "
00150       "automatically select events";
00151     return;
00152   }
00153 
00154   //---------- triggerSummary ----------
00155   iEvent.getByLabel(triggerSummaryLabel_,triggerObj_);
00156   if(!triggerObj_.isValid()) {
00157     edm::InputTag triggerSummaryLabelFU(triggerSummaryLabel_.label(),triggerSummaryLabel_.instance(), "FU");
00158     iEvent.getByLabel(triggerSummaryLabelFU,triggerObj_);
00159     if(!triggerObj_.isValid()) {
00160       edm::LogInfo("BTagHLTOfflineSource") << "TriggerEvent not found, "
00161         "skipping event";
00162       return;
00163     }
00164   }
00165   
00166   //------------Offline Objects-------
00167 
00168   //Access the reco calo jets 
00169   edm::Handle<reco::CaloJetCollection> jetHandle;
00170   bool ValidJetColl_ = iEvent.getByLabel(caloJetsTag_, jetHandle);
00171   if(!ValidJetColl_) return;
00172   // get the selected jets
00173   selectJets(iEvent,jetHandle);
00174 
00175   //Access the reco muons
00176   edm::Handle<reco::MuonCollection> muonHandle;
00177   bool ValidMuColl_ = iEvent.getByLabel(muonTag_, muonHandle);
00178   if(!ValidMuColl_) return;
00179   // get the selected muons
00180   selectMuons(muonHandle);
00181 
00182   // Beam spot
00183   if (!iEvent.getByLabel(InputTag("offlineBeamSpot"), beamSpot_)) {
00184         edm::LogInfo("") << ">>> No beam spot found !!!";
00185   }
00186 
00187   fillMEforMonTriggerSummary();
00188   
00189   if(plotEff_)
00190     {
00191       fillMEforEffAllTrigger(iEvent); 
00192       fillMEforEffWrtMuTrigger(iEvent);
00193       fillMEforEffWrtMBTrigger(iEvent);
00194     }
00195 
00196   fillMEforTriggerNTfired();
00197 
00198 }
00199 
00200 //--------------------------------------------------------
00201 void BTagHLTOfflineSource::fillMEforMonTriggerSummary(){
00202   // Trigger summary for all paths
00203 
00204   bool muTrig = false;
00205   bool mbTrig = false;
00206 
00207   for(size_t i=0;i<MuonTrigPaths_.size();++i){
00208     if(isHLTPathAccepted(MuonTrigPaths_[i])){
00209       muTrig = true;
00210       break;
00211     } 
00212   }
00213   for(size_t i=0;i<MBTrigPaths_.size();++i){
00214     if(isHLTPathAccepted(MBTrigPaths_[i])){
00215       mbTrig = true;
00216       break;
00217     }
00218   }
00219 
00220   for(PathInfoCollection::iterator v = hltPathsAll_.begin(); v!= hltPathsAll_.end(); ++v )
00221     {
00222       bool trigFirst= false;  
00223       double binV = TriggerPosition(v->getPath());
00224       
00225       if(isHLTPathAccepted(v->getPath())) trigFirst = true;
00226       if(!trigFirst)continue;
00227       if(trigFirst)
00228         {
00229           rate_All->Fill(binV);
00230           correlation_All->Fill(binV,binV);
00231           if(muTrig){
00232             rate_AllWrtMu->Fill(binV);
00233             correlation_AllWrtMu->Fill(binV,binV);
00234           }
00235           if(mbTrig){
00236             rate_AllWrtMB->Fill(binV);
00237             correlation_AllWrtMB->Fill(binV,binV);
00238           }
00239         }
00240       for(PathInfoCollection::iterator w = v+1; w!= hltPathsAll_.end(); ++w )
00241         {
00242           bool trigSec = false; 
00243           double binW = TriggerPosition(w->getPath()); 
00244           if(isHLTPathAccepted(w->getPath()))trigSec = true;
00245           if(trigSec && trigFirst)
00246             {
00247               correlation_All->Fill(binV,binW);
00248               if(muTrig)correlation_AllWrtMu->Fill(binV,binW);
00249               if(mbTrig)correlation_AllWrtMB->Fill(binV,binW); 
00250             }
00251           if(!trigSec && trigFirst)
00252             {
00253               correlation_All->Fill(binW,binV); 
00254               if(muTrig)correlation_AllWrtMu->Fill(binW,binV);
00255               if(mbTrig)correlation_AllWrtMB->Fill(binW,binV);
00256 
00257             }
00258         }
00259     }
00260 }
00261 
00262 //--------------------------------------------------------
00263 void BTagHLTOfflineSource::fillMEforTriggerNTfired(){
00264 
00265   int npath;
00266   if(&triggerResults_) {
00267     npath = triggerResults_->size();
00268   } else {
00269     return;
00270   }
00271   for(PathInfoCollection::iterator v = hltPathsAll_.begin(); v!= hltPathsAll_.end(); ++v )
00272     {
00273       unsigned index = triggerNames_.triggerIndex(v->getPath()); 
00274       if (index < triggerNames_.size() )
00275         {
00276           v->getMEhisto_TriggerSummary()->Fill(0.);
00277 
00278           edm::InputTag l1Tag(v->getl1Path(),"",processname_);
00279           const int l1Index = triggerObj_->filterIndex(l1Tag);
00280           bool l1found = false;
00281 
00282           if ( l1Index < triggerObj_->sizeFilters() ) l1found = true;
00283           if(!l1found)v->getMEhisto_TriggerSummary()->Fill(1.);
00284           if(!l1found && !(triggerResults_->accept(index)))v->getMEhisto_TriggerSummary()->Fill(2.);
00285           if(!l1found && (triggerResults_->accept(index)))v->getMEhisto_TriggerSummary()->Fill(3.);
00286           if(l1found)v->getMEhisto_TriggerSummary()->Fill(4.);
00287           if(l1found && (triggerResults_->accept(index)))v->getMEhisto_TriggerSummary()->Fill(5.); 
00288           if(l1found && !(triggerResults_->accept(index)))v->getMEhisto_TriggerSummary()->Fill(6.);
00289 
00290           if(!(triggerResults_->accept(index)) && l1found)
00291             { 
00292               if((v->getTriggerType().compare("BTagMu_Trigger") == 0) && (SelectedCaloJetsColl_.isValid()) && SelectedCaloJets->size())
00293                 {
00294                   CaloJetCollection::const_iterator jet = SelectedCaloJets->begin();
00295                   v->getMEhisto_JetPt()->Fill(jet->pt());
00296                   v->getMEhisto_EtavsPt()->Fill(jet->eta(),jet->pt());
00297                   v->getMEhisto_PhivsPt()->Fill(jet->phi(),jet->pt());
00298                  
00299                 }// BTagMu trigger is not fired
00300 
00301             } // L1 is fired
00302         }//
00303     }// trigger not fired
00304  
00305 
00306 
00307 }
00308 
00309 //--------------------------------------------------------
00310 void BTagHLTOfflineSource::fillMEforEffAllTrigger(const Event & iEvent){
00311   
00312   int npath;
00313   if(&triggerResults_) {
00314     npath = triggerResults_->size();
00315   } 
00316   else {
00317     return;
00318   }
00319   
00320   int num = -1;
00321   int denom = -1;
00322 
00323   for(PathInfoCollection::iterator v = hltPathsEff_.begin(); v!= hltPathsEff_.end(); ++v )
00324   {
00325     num++;
00326     denom++;
00327 
00328     bool denompassed = false;
00329     bool numpassed   = false; 
00330     
00331     unsigned indexNum = triggerNames_.triggerIndex(v->getPath());
00332     unsigned indexDenom = triggerNames_.triggerIndex(v->getDenomPath());
00333     
00334     if(indexNum < triggerNames_.size() && triggerResults_->accept(indexNum))       numpassed   = true;
00335     if(indexDenom < triggerNames_.size() && triggerResults_->accept(indexDenom))   denompassed = true; 
00336     
00337     if(denompassed)
00338       { //Denominator is fired
00339         
00340         if(SelectedCaloJetsColl_.isValid() && (v->getObjectType() == trigger::TriggerBJet)) {
00341 
00342           if((v->getTriggerType().compare("BTagMu_Trigger") == 0) && SelectedCaloJets->size())
00343             {
00344               CaloJetCollection::const_iterator jet = SelectedCaloJets->begin();
00345               
00346               if (isMuonJet(*jet, SelectedMuons)){//mujet
00347                 
00348                 v->getMEhisto_DenominatorPt()->Fill(jet->pt());
00349                 
00350                 if (isBarrel(jet->eta()))  v->getMEhisto_DenominatorPtBarrel()->Fill(jet->pt());
00351                 if (isEndCap(jet->eta()))  v->getMEhisto_DenominatorPtEndcap()->Fill(jet->pt());
00352                 if (isForward(jet->eta())) v->getMEhisto_DenominatorPtForward()->Fill(jet->pt());
00353                 
00354                 v->getMEhisto_DenominatorEta()->Fill(jet->eta());
00355                 v->getMEhisto_DenominatorPhi()->Fill(jet->phi());
00356                 v->getMEhisto_DenominatorEtaPhi()->Fill(jet->eta(),jet->phi());             
00357 
00358               }//mujet
00359             }
00360           
00361         }// Jet trigger and valid jet collection
00362         
00363         if (numpassed)
00364           {//Numerator is fired
00365             
00366             if(SelectedCaloJetsColl_.isValid() && (v->getObjectType() == trigger::TriggerBJet)){
00367 
00368               if((v->getTriggerType().compare("BTagMu_Trigger") == 0) && SelectedCaloJets->size())
00369                 {
00370                   CaloJetCollection::const_iterator jet = SelectedCaloJets->begin();
00371 
00372                   if (isMuonJet(*jet, SelectedMuons)){//mujet
00373                     
00374                     v->getMEhisto_NumeratorPt()->Fill(jet->pt());
00375                     
00376                     if (isBarrel(jet->eta()))  v->getMEhisto_NumeratorPtBarrel()->Fill(jet->pt());
00377                     if (isEndCap(jet->eta()))  v->getMEhisto_NumeratorPtEndcap()->Fill(jet->pt());
00378                     if (isForward(jet->eta())) v->getMEhisto_NumeratorPtForward()->Fill(jet->pt());
00379                     
00380                     v->getMEhisto_NumeratorEta()->Fill(jet->eta());
00381                     v->getMEhisto_NumeratorPhi()->Fill(jet->phi());
00382                     v->getMEhisto_NumeratorEtaPhi()->Fill(jet->eta(),jet->phi());
00383                   }//mujet
00384                 }
00385               
00386             }// Jet trigger and valid jet collection
00387             
00388           }//Numerator is fired
00389       }//Denominator is fired
00390     
00391   }// trigger under study
00392 
00393 }
00394 
00395 //--------------------------------------------------------
00396 void BTagHLTOfflineSource::fillMEforEffWrtMuTrigger(const Event & iEvent){
00397 
00398   int npath;
00399   if(&triggerResults_) {
00400     npath = triggerResults_->size();
00401   } else {
00402     return;
00403   }
00404   bool muTrig = false;
00405   bool denompassed = false;
00406   for(size_t i=0;i<MuonTrigPaths_.size();++i){
00407     if(isHLTPathAccepted(MuonTrigPaths_[i])){
00408       muTrig = true;
00409       break;
00410     }
00411   }
00412   for(PathInfoCollection::iterator v = hltPathsEffWrtMu_.begin(); v!= hltPathsEffWrtMu_.end(); ++v )
00413   {
00414     bool numpassed   = false; 
00415     if(muTrig)denompassed = true;
00416      
00417     unsigned indexNum = triggerNames_.triggerIndex(v->getPath());
00418     if(indexNum < triggerNames_.size() && triggerResults_->accept(indexNum))numpassed   = true;
00419 
00420     if(denompassed){
00421 
00422       if(SelectedCaloJetsColl_.isValid() && (v->getObjectType() == trigger::TriggerBJet)){
00423 
00424         if((v->getTriggerType().compare("BTagMu_Trigger") == 0) && SelectedCaloJets->size())
00425           {
00426             CaloJetCollection::const_iterator jet = SelectedCaloJets->begin();
00427             
00428             if (isMuonJet(*jet, SelectedMuons)){//mujet
00429 
00430               v->getMEhisto_DenominatorPt()->Fill(jet->pt());
00431 
00432               if (isBarrel(jet->eta()))  v->getMEhisto_DenominatorPtBarrel()->Fill(jet->pt());
00433               if (isEndCap(jet->eta()))  v->getMEhisto_DenominatorPtEndcap()->Fill(jet->pt());
00434               if (isForward(jet->eta())) v->getMEhisto_DenominatorPtForward()->Fill(jet->pt());
00435               
00436               v->getMEhisto_DenominatorEta()->Fill(jet->eta());
00437               v->getMEhisto_DenominatorPhi()->Fill(jet->phi());
00438               v->getMEhisto_DenominatorEtaPhi()->Fill(jet->eta(),jet->phi());             
00439               
00440             }//mujet
00441           }
00442             
00443       }// Jet trigger and valid jet collection
00444 
00445       if (numpassed)
00446       {
00447         if(SelectedCaloJetsColl_.isValid() && (v->getObjectType() == trigger::TriggerBJet)){
00448           if((v->getTriggerType().compare("BTagMu_Trigger") == 0) && SelectedCaloJets->size())
00449           {
00450             CaloJetCollection::const_iterator jet = SelectedCaloJets->begin();
00451 
00452             if (isMuonJet(*jet, SelectedMuons)){//mujet
00453               
00454               v->getMEhisto_NumeratorPt()->Fill(jet->pt());
00455 
00456               if (isBarrel(jet->eta()))  v->getMEhisto_NumeratorPtBarrel()->Fill(jet->pt());
00457               if (isEndCap(jet->eta()))  v->getMEhisto_NumeratorPtEndcap()->Fill(jet->pt());
00458               if (isForward(jet->eta())) v->getMEhisto_NumeratorPtForward()->Fill(jet->pt());
00459 
00460               v->getMEhisto_NumeratorEta()->Fill(jet->eta());
00461               v->getMEhisto_NumeratorPhi()->Fill(jet->phi());
00462               v->getMEhisto_NumeratorEtaPhi()->Fill(jet->eta(),jet->phi());
00463             }//mujet
00464             
00465           }
00466         }// Jet trigger and valid jet collection
00467 
00468       }//Numerator is fired
00469     }//Denominator is fired
00470   }// trigger under study
00471 
00472 
00473 }
00474 
00475 //--------------------------------------------------------
00476 void BTagHLTOfflineSource::fillMEforEffWrtMBTrigger(const Event & iEvent){
00477 
00478   int npath;
00479   if(&triggerResults_) {
00480     npath = triggerResults_->size();
00481   } else {
00482     return;
00483   }
00484   bool mbTrig = false;
00485   bool denompassed = false;
00486   for(size_t i=0;i<MBTrigPaths_.size();++i){
00487     if(isHLTPathAccepted(MBTrigPaths_[i])){
00488       mbTrig = true;
00489       break;
00490     }
00491   }
00492   for(PathInfoCollection::iterator v = hltPathsEffWrtMB_.begin(); v!= hltPathsEffWrtMB_.end(); ++v )
00493   {
00494     bool numpassed   = false; 
00495     if(mbTrig)denompassed = true;
00496 
00497     unsigned indexNum = triggerNames_.triggerIndex(v->getPath());
00498     if(indexNum < triggerNames_.size() && triggerResults_->accept(indexNum))numpassed   = true;
00499 
00500     if(denompassed){
00501 
00502       if(SelectedCaloJetsColl_.isValid() && (v->getObjectType() == trigger::TriggerBJet)){
00503         if((v->getTriggerType().compare("BTagMu_Trigger") == 0) && SelectedCaloJets->size()) 
00504           {
00505             CaloJetCollection::const_iterator jet = SelectedCaloJets->begin();
00506             if (isMuonJet(*jet, SelectedMuons)){//mujet
00507 
00508               v->getMEhisto_DenominatorPt()->Fill(jet->pt());
00509 
00510               if (isBarrel(jet->eta()))  v->getMEhisto_DenominatorPtBarrel()->Fill(jet->pt());
00511               if (isEndCap(jet->eta()))  v->getMEhisto_DenominatorPtEndcap()->Fill(jet->pt());
00512               if (isForward(jet->eta())) v->getMEhisto_DenominatorPtForward()->Fill(jet->pt());
00513 
00514               v->getMEhisto_DenominatorEta()->Fill(jet->eta());
00515               v->getMEhisto_DenominatorPhi()->Fill(jet->phi());
00516               v->getMEhisto_DenominatorEtaPhi()->Fill(jet->eta(),jet->phi());             
00517             }//mujet
00518         }
00519 
00520       }// Jet trigger and valid jet collection
00521 
00522       if (numpassed)
00523       {
00524         if(SelectedCaloJetsColl_.isValid() && (v->getObjectType() == trigger::TriggerBJet)) {
00525           if((v->getTriggerType().compare("BTagMu_Trigger") == 0) && SelectedCaloJets->size())
00526             {
00527               CaloJetCollection::const_iterator jet = SelectedCaloJets->begin();
00528               if (isMuonJet(*jet, SelectedMuons)){//mujet
00529                 
00530                 v->getMEhisto_NumeratorPt()->Fill(jet->pt());
00531                 if (isBarrel(jet->eta()))  v->getMEhisto_NumeratorPtBarrel()->Fill(jet->pt());
00532                 if (isEndCap(jet->eta()))  v->getMEhisto_NumeratorPtEndcap()->Fill(jet->pt());
00533                 if (isForward(jet->eta())) v->getMEhisto_NumeratorPtForward()->Fill(jet->pt());
00534                 v->getMEhisto_NumeratorEta()->Fill(jet->eta());
00535                 v->getMEhisto_NumeratorPhi()->Fill(jet->phi());
00536                 v->getMEhisto_NumeratorEtaPhi()->Fill(jet->eta(),jet->phi());
00537 
00538               }//mujet
00539             }
00540           
00541         }// Jet trigger and valid jet collection
00542 
00543       }//Numerator is fired
00544     }//Denominator is fired
00545   }// trigger under study
00546 
00547 
00548 }
00549 
00550 // -- method called once each job just before starting event loop  --------
00551 //--------------------------------------------------------
00552 void BTagHLTOfflineSource::beginJob(){
00553  
00554 }
00555 
00556 //--------------------------------------------------------
00557 // BeginRun
00558 void BTagHLTOfflineSource::beginRun(const edm::Run& run, const edm::EventSetup& c){
00559 
00560   if(!isSetup_)
00561     { 
00562       DQMStore *dbe = 0;
00563       dbe = Service<DQMStore>().operator->();
00564       if (dbe) {
00565         dbe->setCurrentFolder(dirname_);
00566         dbe->rmdir(dirname_);
00567       }
00568       if (dbe) {
00569         dbe->setCurrentFolder(dirname_);
00570       }
00571       
00572       //--- htlConfig_
00573       bool changed(true);
00574       if (!hltConfig_.init(run, c, processname_, changed)) {
00575         LogDebug("HLTBTagDQMSource") << "HLTConfigProvider failed to initialize.";
00576       }
00577       
00578       /*
00579         Here we select the BTagMu Jets. BTagMu triggers are saved under same object type "TriggerBJet". 
00580         For the first trigger in the list, denominator trigger is dummy (empty) whereas for 
00581         other triggers denom is previous trigger of same type. e.g. DiJet20U has DiJet10U as denominator.
00582         For defining histos wrt muon trigger, denominator is always set "MuonTrigger". This string later can be checked and condition 
00583         can be applied on muon triggers.
00584       */
00585 
00586       const unsigned int n(hltConfig_.size());
00587 
00588       int btagmuJet = 0;
00589       
00590       for (unsigned int i=0; i!=n; ++i) { //Loop over paths
00591 
00592         bool denomFound = false;
00593         bool numFound = false; 
00594         bool mbFound = false;
00595         bool muFound = false; 
00596 
00597         std::string pathname = hltConfig_.triggerName(i);
00598         if(verbose_)cout << "==pathname==" << pathname << endl;
00599 
00600         std::string dpathname = MuonTrigPaths_[0];
00601         std::string l1pathname = "dummy";
00602         std::string denompathname = "";
00603         unsigned int usedPrescale = 1;
00604         unsigned int objectType = 0;
00605         std::string triggerType = "";
00606         std::string filtername("dummy");
00607         std::string Denomfiltername("denomdummy");
00608         
00609         if (pathname.find("BTagMu") != std::string::npos) {
00610           triggerType = "BTagMu_Trigger";
00611           objectType = trigger::TriggerBJet;
00612         }
00613         
00614         if( objectType == trigger::TriggerBJet  && !(pathname.find("BTagIP") != std::string::npos) )
00615           {
00616             btagmuJet++;
00617             if(btagmuJet > 1)   dpathname = dpathname = hltConfig_.triggerName(i-1);
00618             if(btagmuJet == 1)  dpathname = MuonTrigPaths_[0];
00619           }
00620         
00621         // find L1 condition for numpath with numpath object type 
00622         // find PSet for L1 global seed for numpath, 
00623         // list module labels for numpath
00624         // Checking if the trigger exist in HLT table or not
00625 
00626         for (unsigned int i=0; i!=n; ++i) {
00627           std::string HLTname = hltConfig_.triggerName(i);
00628           if(HLTname == pathname)           numFound = true;
00629           if(HLTname == dpathname)          denomFound = true;
00630           if(HLTname == MBTrigPaths_[0])    mbFound = true;
00631           if(HLTname == MuonTrigPaths_[0])  muFound = true; 
00632         }
00633  
00634         if(numFound)//check whether the trigger exists in the menu
00635           {
00636             std::vector<std::string> numpathmodules = hltConfig_.moduleLabels(pathname);
00637 
00638             for(std::vector<std::string>::iterator numpathmodule = numpathmodules.begin(); numpathmodule!= numpathmodules.end(); ++numpathmodule ) {
00639               edm::InputTag testTag(*numpathmodule,"",processname_);
00640               if ((hltConfig_.moduleType(*numpathmodule) == "HLT1CaloBJet") || (hltConfig_.moduleType(*numpathmodule) == "HLTPrescaler") ) filtername = *numpathmodule;
00641               if (hltConfig_.moduleType(*numpathmodule) == "HLTLevel1GTSeed") l1pathname = *numpathmodule;
00642               
00643             }
00644           }
00645 
00646         if(objectType != 0 && denomFound)
00647           {
00648             std::vector<std::string> numpathmodules = hltConfig_.moduleLabels(dpathname);
00649             for(std::vector<std::string>::iterator numpathmodule = numpathmodules.begin(); numpathmodule!= numpathmodules.end(); ++numpathmodule ) {
00650               edm::InputTag testTag(*numpathmodule,"",processname_);
00651               if ((hltConfig_.moduleType(*numpathmodule) == "HLT1CaloBJet") || (hltConfig_.moduleType(*numpathmodule) == "HLTPrescaler") ) Denomfiltername = *numpathmodule;
00652             }
00653           }
00654 
00655         if(objectType != 0 && numFound)
00656           {
00657             if(verbose_)
00658               cout<<"==pathname=="<<pathname<<"==denompath=="<<dpathname<<"==filtername=="<<filtername<<"==denomfiltername=="<<Denomfiltername<<"==l1pathname=="<<l1pathname<<"==objectType=="<<objectType<<endl;    
00659             
00660             if(!((pathname.find("BTagIP") != std::string::npos) || (pathname.find("Quad") != std::string::npos)))
00661               {     
00662                 hltPathsAll_.push_back(PathInfo(usedPrescale, dpathname, pathname, l1pathname, filtername, Denomfiltername, processname_, objectType, triggerType));
00663                 if(muFound)
00664                   hltPathsAllWrtMu_.push_back(PathInfo(usedPrescale, dpathname, pathname, l1pathname, filtername, Denomfiltername, processname_, objectType, triggerType));
00665                 if(muFound)
00666                   hltPathsEffWrtMu_.push_back(PathInfo(usedPrescale, dpathname, pathname, l1pathname, filtername, Denomfiltername, processname_, objectType, triggerType));
00667                 if(mbFound)
00668                   hltPathsEffWrtMB_.push_back(PathInfo(usedPrescale, dpathname, pathname, l1pathname, filtername, Denomfiltername, processname_, objectType, triggerType));
00669                 if(!nameForEff_ && denomFound) 
00670                   hltPathsEff_.push_back(PathInfo(usedPrescale, dpathname, pathname, l1pathname, filtername, Denomfiltername, processname_, objectType, triggerType));
00671               }
00672             
00673             hltPathsAllTriggerSummary_.push_back(PathInfo(usedPrescale, dpathname, pathname, l1pathname, filtername, Denomfiltername, processname_, objectType, triggerType));
00674 
00675           }
00676       } //Loop over paths
00677 
00678       //---------bool to pick trigger names pair from config file-------------
00679       if(nameForEff_)
00680         {
00681           std::string l1pathname = "dummy";
00682           std::string denompathname = "";
00683           unsigned int usedPrescale = 1;
00684           unsigned int objectType = 0;
00685           std::string triggerType = "";
00686           std::string filtername("dummy");
00687           std::string Denomfiltername("denomdummy");
00688 
00689           for (std::vector<std::pair<std::string, std::string> >::iterator custompathnamepair = custompathnamepairs_.begin(); custompathnamepair != custompathnamepairs_.end(); ++custompathnamepair)
00690             {
00691               std::string pathname  = custompathnamepair->first;
00692               std::string dpathname = custompathnamepair->second;
00693               bool numFound = false;
00694               bool denomFound = false;
00695               // Check whether the trigger exist in HLT table or not
00696               for (unsigned int i=0; i!=n; ++i) {
00697                 std::string HLTname = hltConfig_.triggerName(i);
00698                 if(HLTname == pathname)   numFound = true;
00699                 if(HLTname == dpathname)  denomFound = true;
00700               }
00701               if(numFound && denomFound)
00702                 {
00703                   if (pathname.find("BTagMu") != std::string::npos){
00704                     triggerType = "BTagMu_Trigger";
00705                     objectType = trigger::TriggerBJet;
00706                   }
00707                   std::vector<std::string> numpathmodules = hltConfig_.moduleLabels(pathname);
00708                   for(std::vector<std::string>::iterator numpathmodule = numpathmodules.begin(); numpathmodule!= numpathmodules.end(); ++numpathmodule ) {
00709                     edm::InputTag testTag(*numpathmodule,"",processname_);
00710                     if ((hltConfig_.moduleType(*numpathmodule) == "HLT1CaloBJet") || (hltConfig_.moduleType(*numpathmodule) == "HLTPrescaler") ) filtername = *numpathmodule;
00711                     if (hltConfig_.moduleType(*numpathmodule) == "HLTLevel1GTSeed")l1pathname = *numpathmodule;
00712                   }
00713 
00714                   if(objectType != 0)
00715                     {
00716                       std::vector<std::string> numpathmodules = hltConfig_.moduleLabels(dpathname);
00717                       for(std::vector<std::string>::iterator numpathmodule = numpathmodules.begin(); numpathmodule!= numpathmodules.end(); ++numpathmodule ) {
00718                         edm::InputTag testTag(*numpathmodule,"",processname_);
00719                         if ((hltConfig_.moduleType(*numpathmodule) == "HLT1CaloBJet") || (hltConfig_.moduleType(*numpathmodule) == "HLTPrescaler") ) Denomfiltername = *numpathmodule;
00720                       }
00721      
00722                       if(verbose_)
00723                         cout<<"==pathname=="<<pathname<<"==denompath=="<<dpathname<<"==filtername=="<<filtername<<"==denomfiltername=="<<Denomfiltername<<"==l1pathname=="<<l1pathname<<"==objectType=="<<objectType<<endl;
00724                       hltPathsEff_.push_back(PathInfo(usedPrescale, dpathname, pathname, l1pathname, filtername, Denomfiltername, processname_, objectType, triggerType)); 
00725 
00726                     }
00727                 }
00728             }
00729         }
00730       
00731       //-----------------------------------------------------------------
00732       //---book trigger summary histos
00733       if(!isSetup_)
00734         {
00735           std::string foldernm = "/TriggerSummary/";
00736           if (dbe)   {
00737             dbe->setCurrentFolder(dirname_ + foldernm);
00738           }
00739           int     TrigBins_ = hltPathsAllTriggerSummary_.size();
00740           double  TrigMin_  = -0.5;
00741           double  TrigMax_  = hltPathsAllTriggerSummary_.size()-0.5;
00742           
00743           std::string histonm = "BTagMu_TriggerRate";
00744           std::string histot = "BTagMu TriggerRate Summary";
00745      
00746           rate_All = dbe->book1D(histonm.c_str(),histot.c_str(),TrigBins_,TrigMin_,TrigMax_);
00747           
00748           histonm = "BTagMu_TriggerRate_Correlation";
00749           histot = "BTagMu TriggerRate Correlation Summary;y&&!x;x&&y";
00750 
00751           correlation_All = dbe->book2D(histonm.c_str(),histot.c_str(),TrigBins_,TrigMin_,TrigMax_,TrigBins_,TrigMin_,TrigMax_);
00752 
00753 
00754           histonm = "BTagMu_TriggerRate_WrtMuTrigger";
00755           histot = "BTagMu TriggerRate Summary Wrt Muon Trigger ";
00756     
00757           rate_AllWrtMu = dbe->book1D(histonm.c_str(),histot.c_str(),TrigBins_,TrigMin_,TrigMax_);
00758 
00759 
00760           histonm = "BTagMu_TriggerRate_Correlation_WrtMuTrigger";
00761           histot = "BTagMu TriggerRate Correlation Summary Wrt Muon Trigger;y&&!x;x&&y";
00762 
00763           correlation_AllWrtMu = dbe->book2D(histonm.c_str(),histot.c_str(),TrigBins_,TrigMin_,TrigMax_,TrigBins_,TrigMin_,TrigMax_);
00764 
00765           histonm = "BTagMu_TriggerRate_WrtMBTrigger";
00766           histot = "BTagMu TriggerRate Summary Wrt MB Trigger";
00767 
00768           rate_AllWrtMB = dbe->book1D(histonm.c_str(),histot.c_str(),TrigBins_,TrigMin_,TrigMax_);
00769 
00770 
00771           histonm = "BTagMu_TriggerRate_Correlation_WrtMBTrigger";
00772           histot = "BTagMu TriggerRate Correlation Wrt MB Trigger;y&&!x;x&&y";
00773 
00774           correlation_AllWrtMB = dbe->book2D(histonm.c_str(),histot.c_str(),TrigBins_,TrigMin_,TrigMax_,TrigBins_,TrigMin_,TrigMax_);
00775           isSetup_ = true;
00776 
00777         }
00778 
00779       //---Set bin label
00780       for(PathInfoCollection::iterator v = hltPathsAllTriggerSummary_.begin(); v!= hltPathsAllTriggerSummary_.end(); ++v ){
00781         
00782         std::string labelnm("dummy");
00783         labelnm = v->getPath(); 
00784         int nbins = rate_All->getTH1()->GetNbinsX();
00785 
00786         for(int ibin=1; ibin<nbins+1; ibin++)
00787           {
00788             const char * binLabel = rate_All->getTH1()->GetXaxis()->GetBinLabel(ibin);
00789             std::string binLabel_str = string(binLabel);
00790             if(binLabel_str.compare(labelnm)==0)break;
00791             if(binLabel[0]=='\0')
00792               {
00793                 rate_All->setBinLabel(ibin,labelnm);
00794                 rate_AllWrtMu->setBinLabel(ibin,labelnm);
00795                 rate_AllWrtMB->setBinLabel(ibin,labelnm);
00796                 correlation_All->setBinLabel(ibin,labelnm,1);
00797                 correlation_AllWrtMu->setBinLabel(ibin,labelnm,1);
00798                 correlation_AllWrtMB->setBinLabel(ibin,labelnm,1);
00799                 correlation_All->setBinLabel(ibin,labelnm,2);
00800                 correlation_AllWrtMu->setBinLabel(ibin,labelnm,2);
00801                 correlation_AllWrtMB->setBinLabel(ibin,labelnm,2);
00802                 break; 
00803               } 
00804           }     
00805         
00806       }
00807 
00808       //-------Now Efficiency histos--------
00809       if(plotEff_)
00810         {//plotEff_
00811           
00812           int Ptbins_      = 100;
00813           int Etabins_     = 40;
00814           int Phibins_     = 35;
00815           double PtMin_    = 0.;
00816           double PtMax_    = 200.;
00817           double EtaMin_   = -5.;
00818           double EtaMax_   =  5.;
00819           double PhiMin_   = -3.14159;
00820           double PhiMax_   =  3.14159;
00821           
00822           // Now define histos wrt lower threshold trigger
00823           std::string dirName1 = dirname_ + "/RelativeTriggerEff/";
00824           for(PathInfoCollection::iterator v = hltPathsEff_.begin(); v!= hltPathsEff_.end(); ++v ){
00825             std::string labelname("ME") ;
00826             std::string subdirName = dirName1 + v->getPath() + "_wrt_" + v->getDenomPath();
00827             dbe->setCurrentFolder(subdirName);
00828             std::string histoname(labelname+"");
00829             std::string title(labelname+"");
00830             
00831             MonitorElement *dummy;
00832             dummy =  dbe->bookFloat("dummy");   
00833             
00834             if((v->getObjectType() == trigger::TriggerBJet) && (v->getTriggerType().compare("BTagMu_Trigger") == 0))
00835               {//Loop over BTagMu trigger
00836                 
00837                 histoname = labelname + "_NumeratorPt";
00838                 title     = labelname + "NumeratorPt;Calo Pt[GeV/c]";
00839                 MonitorElement * NumeratorPt =  dbe->book1D(histoname.c_str(),title.c_str(),Ptbins_,PtMin_,PtMax_);
00840                 TH1 * h = NumeratorPt->getTH1();
00841 
00842                 
00843                 histoname = labelname + "_NumeratorPtBarrel";
00844                 title     = labelname + "NumeratorPtBarrel;Calo Pt[GeV/c] ";
00845                 MonitorElement * NumeratorPtBarrel =  dbe->book1D(histoname.c_str(),title.c_str(),Ptbins_,PtMin_,PtMax_);
00846                 h = NumeratorPtBarrel->getTH1();
00847 
00848                 
00849                 histoname = labelname + "_NumeratorPtEndcap";
00850                 title     = labelname + "NumeratorPtEndcap;Calo Pt[GeV/c]";
00851                 MonitorElement * NumeratorPtEndcap =  dbe->book1D(histoname.c_str(),title.c_str(),Ptbins_,PtMin_,PtMax_);
00852                 h = NumeratorPtEndcap->getTH1();
00853 
00854                 
00855                 histoname = labelname + "_NumeratorPtForward";
00856                 title     = labelname + "NumeratorPtForward;Calo Pt[GeV/c]";
00857                 MonitorElement * NumeratorPtForward =  dbe->book1D(histoname.c_str(),title.c_str(),Ptbins_,PtMin_,PtMax_);
00858                 h = NumeratorPtForward->getTH1();
00859 
00860                 
00861                 histoname = labelname + "_NumeratorEta";
00862                 title     = labelname + "NumeratorEta;Calo #eta ";
00863                 MonitorElement * NumeratorEta =  dbe->book1D(histoname.c_str(),title.c_str(),Etabins_,EtaMin_,EtaMax_);
00864                 h = NumeratorEta->getTH1();
00865 
00866                 
00867                 histoname = labelname + "_NumeratorPhi";
00868                 title     = labelname + "NumeratorPhi;Calo #Phi";
00869                 MonitorElement * NumeratorPhi =  dbe->book1D(histoname.c_str(),title.c_str(),Phibins_,PhiMin_,PhiMax_);
00870                 h = NumeratorPhi->getTH1();
00871 
00872                 
00873                 histoname = labelname + "_NumeratorEtaPhi";
00874                 title     = labelname + "NumeratorEtaPhi;Calo #eta;Calo #Phi";
00875                 MonitorElement * NumeratorEtaPhi =  dbe->book2D(histoname.c_str(),title.c_str(),Etabins_,EtaMin_,EtaMax_,Phibins_,PhiMin_,PhiMax_);
00876                 h = NumeratorEtaPhi->getTH1();
00877 
00878                 
00879                 histoname = labelname + "_DenominatorPt";
00880                 title     = labelname + "DenominatorPt;Calo Pt[GeV/c]";
00881                 MonitorElement * DenominatorPt =  dbe->book1D(histoname.c_str(),title.c_str(),Ptbins_,PtMin_,PtMax_);
00882                 h = DenominatorPt->getTH1();
00883 
00884                 
00885                 histoname = labelname + "_DenominatorPtBarrel";
00886                 title     = labelname + "DenominatorPtBarrel;Calo Pt[GeV/c]";
00887                 MonitorElement * DenominatorPtBarrel =  dbe->book1D(histoname.c_str(),title.c_str(),Ptbins_,PtMin_,PtMax_);
00888                 h = DenominatorPtBarrel->getTH1();
00889 
00890                 
00891                 histoname = labelname + "_DenominatorPtEndcap";
00892                 title     = labelname + "DenominatorPtEndcap;Calo Pt[GeV/c]";
00893                 MonitorElement * DenominatorPtEndcap =  dbe->book1D(histoname.c_str(),title.c_str(),Ptbins_,PtMin_,PtMax_);
00894                 h = DenominatorPtEndcap->getTH1();
00895 
00896                 
00897                 histoname = labelname + "_DenominatorPtForward";
00898                 title     = labelname + "DenominatorPtForward;Calo Pt[GeV/c] ";
00899                 MonitorElement * DenominatorPtForward =  dbe->book1D(histoname.c_str(),title.c_str(),Ptbins_,PtMin_,PtMax_);
00900                 h = DenominatorPtForward->getTH1();
00901 
00902                 
00903                 histoname = labelname + "_DenominatorEta";
00904                 title     = labelname + "DenominatorEta;Calo #eta ";
00905                 MonitorElement * DenominatorEta =  dbe->book1D(histoname.c_str(),title.c_str(),Etabins_,EtaMin_,EtaMax_);
00906                 h = DenominatorEta->getTH1();
00907 
00908                 
00909                 histoname = labelname + "_DenominatorPhi";
00910                 title     = labelname + "DenominatorPhi;Calo #Phi";
00911                 MonitorElement * DenominatorPhi =  dbe->book1D(histoname.c_str(),title.c_str(),Phibins_,PhiMin_,PhiMax_);
00912                 h = DenominatorPhi->getTH1();
00913 
00914                 
00915                 histoname = labelname + "_DenominatorEtaPhi";
00916                 title     = labelname + "DenominatorEtaPhi;Calo #eta; Calo #Phi";
00917                 MonitorElement * DenominatorEtaPhi =  dbe->book2D(histoname.c_str(),title.c_str(),Etabins_,EtaMin_,EtaMax_,Phibins_,PhiMin_,PhiMax_);
00918                 h = DenominatorEtaPhi->getTH1();
00919 
00920                 
00921                 
00922                 v->setEffHistos(  NumeratorPt,  NumeratorPtBarrel, NumeratorPtEndcap, NumeratorPtForward, NumeratorEta, NumeratorPhi, NumeratorEtaPhi,
00923                                   DenominatorPt,  DenominatorPtBarrel, DenominatorPtEndcap, DenominatorPtForward, DenominatorEta, DenominatorPhi, DenominatorEtaPhi);
00924 
00925               }// Loop over BTagMu Trigger
00926             
00927           }
00928 
00929           //------Efficiency wrt Muon trigger-----------------------
00930           std::string dirName2 = dirname_ + "/EffWrtMuonTrigger/";
00931           for(PathInfoCollection::iterator v = hltPathsEffWrtMu_.begin(); v!= hltPathsEffWrtMu_.end(); ++v ){
00932             std::string labelname("ME") ;
00933             std::string subdirName = dirName2 + v->getPath();
00934             std::string histoname(labelname+"");
00935             std::string title(labelname+"");
00936             dbe->setCurrentFolder(subdirName);
00937             
00938             MonitorElement *dummy;
00939             dummy =  dbe->bookFloat("dummy");
00940             if((v->getObjectType() == trigger::TriggerBJet) && (v->getTriggerType().compare("BTagMu_Trigger") == 0))
00941               {// Loop over BTagMu Trigger
00942 
00943                 histoname = labelname+"_NumeratorPt";
00944                 title     = labelname+"NumeratorPt;Pt[GeV/c]";
00945                 MonitorElement * NumeratorPt =  dbe->book1D(histoname.c_str(),title.c_str(),Ptbins_,PtMin_,PtMax_);
00946                 TH1 * h = NumeratorPt->getTH1();
00947 
00948                 
00949                 histoname = labelname+"_NumeratorPtBarrel";
00950                 title     = labelname+"NumeratorPtBarrel;Calo Pt[GeV/c]";
00951                 MonitorElement * NumeratorPtBarrel =  dbe->book1D(histoname.c_str(),title.c_str(),Ptbins_,PtMin_,PtMax_);
00952                 h = NumeratorPtBarrel->getTH1();
00953 
00954                 
00955                 histoname = labelname+"_NumeratorPtEndcap";
00956                 title     = labelname+"NumeratorPtEndcap;Calo Pt[GeV/c]";
00957                 MonitorElement * NumeratorPtEndcap =  dbe->book1D(histoname.c_str(),title.c_str(),Ptbins_,PtMin_,PtMax_);
00958                 h = NumeratorPtEndcap->getTH1();
00959 
00960                 
00961                 histoname = labelname+"_NumeratorPtForward";
00962                 title     = labelname+"NumeratorPtForward;Calo Pt[GeV/c]";
00963                 MonitorElement * NumeratorPtForward =  dbe->book1D(histoname.c_str(),title.c_str(),Ptbins_,PtMin_,PtMax_);
00964                 h = NumeratorPtForward->getTH1();
00965 
00966                 
00967                 histoname = labelname+"_NumeratorEta";
00968                 title     = labelname+"NumeratorEta;Calo #eta ";
00969                 MonitorElement * NumeratorEta =  dbe->book1D(histoname.c_str(),title.c_str(),Etabins_,EtaMin_,EtaMax_);
00970                 h = NumeratorEta->getTH1();
00971 
00972                 
00973                 histoname = labelname+"_NumeratorPhi";
00974                 title     = labelname+"NumeratorPhi;Calo #Phi";
00975                 MonitorElement * NumeratorPhi =  dbe->book1D(histoname.c_str(),title.c_str(),Phibins_,PhiMin_,PhiMax_);
00976                 h = NumeratorPhi->getTH1();
00977 
00978                 
00979                 histoname = labelname+"_NumeratorEtaPhi";
00980                 title     = labelname+"NumeratorEtaPhi;Calo #eta;Calo #Phi";
00981                 MonitorElement * NumeratorEtaPhi =  dbe->book2D(histoname.c_str(),title.c_str(),Etabins_,EtaMin_,EtaMax_,Phibins_,PhiMin_,PhiMax_);
00982                 h = NumeratorEtaPhi->getTH1();
00983 
00984                 
00985                 histoname = labelname+"_DenominatorPt";
00986                 title     = labelname+"DenominatorPt;Calo Pt[GeV/c]";
00987                 MonitorElement * DenominatorPt =  dbe->book1D(histoname.c_str(),title.c_str(),Ptbins_,PtMin_,PtMax_);
00988                 h = DenominatorPt->getTH1();
00989 
00990                 
00991                 histoname = labelname+"_DenominatorPtBarrel";
00992                 title     = labelname+"DenominatorPtBarrel;Calo Pt[GeV/c]";
00993                 MonitorElement * DenominatorPtBarrel =  dbe->book1D(histoname.c_str(),title.c_str(),Ptbins_,PtMin_,PtMax_);
00994                 h = DenominatorPtBarrel->getTH1();
00995 
00996                 
00997                 histoname = labelname+"_DenominatorPtEndcap";
00998                 title     = labelname+"DenominatorPtEndcap;Calo Pt[GeV/c]";
00999                 MonitorElement * DenominatorPtEndcap =  dbe->book1D(histoname.c_str(),title.c_str(),Ptbins_,PtMin_,PtMax_);
01000                 h = DenominatorPtEndcap->getTH1();
01001 
01002                 
01003                 histoname = labelname+"_DenominatorPtForward";
01004                 title     = labelname+"DenominatorPtForward;Calo Pt[GeV/c] ";
01005                 MonitorElement * DenominatorPtForward =  dbe->book1D(histoname.c_str(),title.c_str(),Ptbins_,PtMin_,PtMax_);
01006                 h = DenominatorPtForward->getTH1();
01007 
01008                 
01009                 histoname = labelname+"_DenominatorEta";
01010                 title     = labelname+"DenominatorEta;Calo #eta";
01011                 MonitorElement * DenominatorEta =  dbe->book1D(histoname.c_str(),title.c_str(),Etabins_,EtaMin_,EtaMax_);
01012                 h = DenominatorEta->getTH1();
01013 
01014                 
01015                 histoname = labelname+"_DenominatorPhi";
01016                 title     = labelname+"DenominatorPhi;Calo #Phi";
01017                 MonitorElement * DenominatorPhi =  dbe->book1D(histoname.c_str(),title.c_str(),Phibins_,PhiMin_,PhiMax_);
01018                 h = DenominatorPhi->getTH1();
01019 
01020                 
01021                 histoname = labelname+"_DenominatorEtaPhi";
01022                 title     = labelname+"DenominatorEtaPhi;Calo #eta (IC5);Calo #Phi ";
01023                 MonitorElement * DenominatorEtaPhi =  dbe->book2D(histoname.c_str(),title.c_str(),Etabins_,EtaMin_,EtaMax_,Phibins_,PhiMin_,PhiMax_);
01024                 h = DenominatorEtaPhi->getTH1();
01025 
01026                 
01027                 
01028                 v->setEffHistos(  NumeratorPt,  NumeratorPtBarrel, NumeratorPtEndcap, NumeratorPtForward, NumeratorEta, NumeratorPhi, NumeratorEtaPhi,
01029                                   DenominatorPt,  DenominatorPtBarrel, DenominatorPtEndcap, DenominatorPtForward, DenominatorEta, DenominatorPhi, DenominatorEtaPhi);
01030 
01031               }// Loop over BTagMu Trigger
01032             
01033           }
01034           
01035           //--------Efficiency  wrt MiniBias trigger---------
01036           std::string dirName3  = dirname_ + "/EffWrtMBTrigger/";
01037           for(PathInfoCollection::iterator v = hltPathsEffWrtMB_.begin(); v!= hltPathsEffWrtMB_.end(); ++v ){
01038             std::string labelname("ME") ;
01039             std::string subdirName = dirName3 + v->getPath() ;
01040             std::string histoname(labelname+"");
01041             std::string title(labelname+"");
01042             dbe->setCurrentFolder(subdirName);
01043             MonitorElement *dummy;
01044             dummy =  dbe->bookFloat("dummy");   
01045 
01046             if((v->getObjectType() == trigger::TriggerBJet) && (v->getTriggerType().compare("BTagMu_Trigger") == 0))
01047               { // Loop over BTagMu Trigger
01048                 
01049                 histoname = labelname+"_NumeratorPt";
01050                 title     = labelname+"NumeratorPt;Calo Pt[GeV/c] ";
01051                 MonitorElement * NumeratorPt =  dbe->book1D(histoname.c_str(),title.c_str(),Ptbins_,PtMin_,PtMax_);
01052                 TH1 * h = NumeratorPt->getTH1();
01053 
01054                 
01055                 histoname = labelname+"_NumeratorPtBarrel";
01056                 title     = labelname+"NumeratorPtBarrel;Calo Pt[GeV/c]";
01057                 MonitorElement * NumeratorPtBarrel =  dbe->book1D(histoname.c_str(),title.c_str(),Ptbins_,PtMin_,PtMax_);
01058                 h = NumeratorPtBarrel->getTH1();
01059 
01060                 
01061                 histoname = labelname+"_NumeratorPtEndcap";
01062                 title     = labelname+"NumeratorPtEndcap; Calo Pt[GeV/c] ";
01063                 MonitorElement * NumeratorPtEndcap =  dbe->book1D(histoname.c_str(),title.c_str(),Ptbins_,PtMin_,PtMax_);
01064                 h = NumeratorPtEndcap->getTH1();
01065 
01066                 
01067                 histoname = labelname+"_NumeratorPtForward";
01068                 title     = labelname+"NumeratorPtForward;Calo Pt[GeV/c]";
01069                 MonitorElement * NumeratorPtForward =  dbe->book1D(histoname.c_str(),title.c_str(),Ptbins_,PtMin_,PtMax_);
01070                 h = NumeratorPtForward->getTH1();
01071 
01072                 
01073                 histoname = labelname+"_NumeratorEta";
01074                 title     = labelname+"NumeratorEta;Calo #eta ";
01075                 MonitorElement * NumeratorEta =  dbe->book1D(histoname.c_str(),title.c_str(),Etabins_,EtaMin_,EtaMax_);
01076                 h = NumeratorEta->getTH1();
01077 
01078                 
01079                 histoname = labelname+"_NumeratorPhi";
01080                 title     = labelname+"NumeratorPhi;Calo #Phi";
01081                 MonitorElement * NumeratorPhi =  dbe->book1D(histoname.c_str(),title.c_str(),Phibins_,PhiMin_,PhiMax_);
01082                 h = NumeratorPhi->getTH1();
01083 
01084                 
01085                 histoname = labelname+"_NumeratorEtaPhi";
01086                 title     = labelname+"NumeratorEtaPhi;Calo #eta;Calo #Phi ";
01087                 MonitorElement * NumeratorEtaPhi =  dbe->book2D(histoname.c_str(),title.c_str(),Etabins_,EtaMin_,EtaMax_,Phibins_,PhiMin_,PhiMax_);
01088                 h = NumeratorEtaPhi->getTH1();
01089 
01090                 
01091                 histoname = labelname+"_DenominatorPt";
01092                 title     = labelname+"DenominatorPt;Calo Pt[GeV/c]";
01093                 MonitorElement * DenominatorPt =  dbe->book1D(histoname.c_str(),title.c_str(),Ptbins_,PtMin_,PtMax_);
01094                 h = DenominatorPt->getTH1();
01095 
01096                 
01097                 histoname = labelname+"_DenominatorPtBarrel";
01098                 title     = labelname+"DenominatorPtBarrel;Calo Pt[GeV/c]";
01099                 MonitorElement * DenominatorPtBarrel =  dbe->book1D(histoname.c_str(),title.c_str(),Ptbins_,PtMin_,PtMax_);
01100                 h = DenominatorPtBarrel->getTH1();
01101 
01102                 
01103                 histoname = labelname+"_DenominatorPtEndcap";
01104                 title     = labelname+"DenominatorPtEndcap;Calo Pt[GeV/c]";
01105                 MonitorElement * DenominatorPtEndcap =  dbe->book1D(histoname.c_str(),title.c_str(),Ptbins_,PtMin_,PtMax_);
01106                 h = DenominatorPtEndcap->getTH1();
01107 
01108                 
01109                 histoname = labelname+"_DenominatorPtForward";
01110                 title     = labelname+"DenominatorPtForward;Calo Pt[GeV/c]";
01111                 MonitorElement * DenominatorPtForward =  dbe->book1D(histoname.c_str(),title.c_str(),Ptbins_,PtMin_,PtMax_);
01112                 h = DenominatorPtForward->getTH1();
01113 
01114                 
01115                 histoname = labelname+"_DenominatorEta";
01116                 title     = labelname+"DenominatorEta;Calo #eta ";
01117                 MonitorElement * DenominatorEta =  dbe->book1D(histoname.c_str(),title.c_str(),Etabins_,EtaMin_,EtaMax_);
01118                 h = DenominatorEta->getTH1();
01119 
01120                 
01121                 histoname = labelname+"_DenominatorPhi";
01122                 title     = labelname+"DenominatorPhi;Calo #Phi";
01123                 MonitorElement * DenominatorPhi =  dbe->book1D(histoname.c_str(),title.c_str(),Phibins_,PhiMin_,PhiMax_);
01124                 h = DenominatorPhi->getTH1();
01125 
01126                 
01127                 histoname = labelname+"_DenominatorEtaPhi";
01128                 title     = labelname+"DenominatorEtaPhi;Calo #eta ;Calo #Phi ";
01129                 MonitorElement * DenominatorEtaPhi =  dbe->book2D(histoname.c_str(),title.c_str(),Etabins_,EtaMin_,EtaMax_,Phibins_,PhiMin_,PhiMax_);
01130                 h = DenominatorEtaPhi->getTH1();
01131 
01132                 
01133                 
01134                 v->setEffHistos(  NumeratorPt,  NumeratorPtBarrel, NumeratorPtEndcap, NumeratorPtForward, NumeratorEta, NumeratorPhi, NumeratorEtaPhi,
01135                                   DenominatorPt,  DenominatorPtBarrel, DenominatorPtEndcap, DenominatorPtForward, DenominatorEta, DenominatorPhi, DenominatorEtaPhi);
01136                 
01137               }// Loop over BTagMu Trigger
01138             
01139           }
01140           
01141         }// This is loop over all efficiency plots
01142       
01143       //--------Histos to see WHY trigger is NOT fired----------
01144       /*
01145       int Nbins_       = 10;
01146       int Nmin_        = 0;
01147       int Nmax_        = 10;
01148       */
01149       int Ptbins_      = 100;
01150       int Etabins_     = 40;
01151       int Phibins_     = 35;
01152       double PtMin_    = 0.;
01153       double PtMax_    = 200.;
01154       double EtaMin_   = -5.;
01155       double EtaMax_   =  5.;
01156       double PhiMin_   = -3.14159;
01157       double PhiMax_   =  3.14159;
01158       
01159       std::string dirName4_ = dirname_ + "/TriggerNotFired/";
01160       for(PathInfoCollection::iterator v = hltPathsAll_.begin(); v!= hltPathsAll_.end(); ++v ){
01161         
01162         MonitorElement *dummy;
01163         dummy =  dbe->bookFloat("dummy");
01164         
01165         std::string labelname("ME") ;
01166         std::string histoname(labelname+"");
01167         std::string title(labelname+"");
01168         dbe->setCurrentFolder(dirName4_ + v->getPath());
01169         
01170         histoname = labelname+"_TriggerSummary";
01171         title     = labelname+"Summary of trigger levels"; 
01172         MonitorElement * TriggerSummary = dbe->book1D(histoname.c_str(),title.c_str(),7, -0.5,6.5);
01173         
01174         std::vector<std::string> trigger;
01175         trigger.push_back("Nevt");
01176         trigger.push_back("L1 failed");
01177         trigger.push_back("L1 & HLT failed");
01178         trigger.push_back("L1 failed but not HLT");
01179         trigger.push_back("L1 passed");
01180         trigger.push_back("L1 & HLT passed");
01181         trigger.push_back("L1 passed but not HLT");
01182 
01183         for(unsigned int i =0; i < trigger.size(); i++) TriggerSummary->setBinLabel(i+1, trigger[i]);
01184         
01185         if((v->getTriggerType().compare("BTagMu_Trigger") == 0))
01186           {// BTagMu trigger
01187             
01188             histoname = labelname+"_JetPt"; 
01189             title     = labelname+"Leading jet pT;Pt[GeV/c]";
01190             MonitorElement * JetPt = dbe->book1D(histoname.c_str(),title.c_str(),Ptbins_,PtMin_,PtMax_);
01191             TH1 * h = JetPt->getTH1();
01192 
01193             
01194             histoname = labelname+"_JetEtaVsPt";
01195             title     = labelname+"Leading jet #eta vs pT;#eta;Pt[GeV/c]";
01196             MonitorElement * JetEtaVsPt = dbe->book2D(histoname.c_str(),title.c_str(),Etabins_,EtaMin_,EtaMax_,Ptbins_,PtMin_,PtMax_);
01197             h = JetEtaVsPt->getTH1();
01198 
01199             
01200             histoname = labelname+"_JetPhiVsPt";
01201             title     = labelname+"Leading jet #Phi vs pT;#Phi;Pt[GeV/c]";
01202             MonitorElement * JetPhiVsPt = dbe->book2D(histoname.c_str(),title.c_str(),Phibins_,PhiMin_,PhiMax_,Ptbins_,PtMin_,PtMax_);
01203             h = JetPhiVsPt->getTH1();
01204 
01205             
01206             v->setDgnsHistos( TriggerSummary, dummy, JetPt, JetEtaVsPt, JetPhiVsPt, dummy, dummy, dummy, dummy, dummy, dummy); 
01207 
01208           }// BTagMu trigger  
01209         
01210       }
01211       
01212     }  
01213 }
01214 
01215 //--------------------------------------------------------
01216 void BTagHLTOfflineSource::beginLuminosityBlock(const LuminosityBlock& lumiSeg, 
01217                                                 const EventSetup& context) {
01218 }
01219 //--------------------------------------------------------
01220 void BTagHLTOfflineSource::endLuminosityBlock(const LuminosityBlock& lumiSeg, 
01221                                               const EventSetup& context) {
01222 }
01223 
01224 //--------------------------------------------------------
01225 // - method called once each job just after ending the event loop  ------------
01226 void BTagHLTOfflineSource::endJob() {
01227   delete jetID;
01228 }
01229 
01230 //--------------------------------------------------------
01231 // EndRun
01232 void BTagHLTOfflineSource::endRun(const edm::Run& run, const edm::EventSetup& c){
01233   if (verbose_) std::cout << "endRun, run " << run.id() << std::endl;
01234 }
01235 
01236 //--------------------------------------------------------
01237 bool BTagHLTOfflineSource::isBarrel(double eta){
01238   bool output = false;
01239   if (fabs(eta)<=1.3) output=true;
01240   return output;
01241 }
01242 
01243 //--------------------------------------------------------
01244 bool BTagHLTOfflineSource::isEndCap(double eta){
01245   bool output = false;
01246   if (fabs(eta)<=3.0 && fabs(eta)>1.3) output=true;
01247   return output;
01248 }
01249 
01250 //--------------------------------------------------------
01251 bool BTagHLTOfflineSource::isForward(double eta){
01252   bool output = false;
01253   if (fabs(eta)>3.0) output=true;
01254   return output;
01255 }
01256 
01257 //--------------------------------------------------------
01258 bool BTagHLTOfflineSource::validPathHLT(std::string pathname){
01259   // hltConfig_ has to be defined first before calling this method
01260   bool output=false;
01261   for (unsigned int j=0; j!=hltConfig_.size(); ++j) {
01262     if (hltConfig_.triggerName(j) == pathname )
01263       output=true;
01264   }
01265   return output;
01266 }
01267 
01268 //--------------------------------------------------------
01269 bool BTagHLTOfflineSource::isHLTPathAccepted(std::string pathName){
01270   // triggerResults_, triggerNames_ has to be defined first before calling this method
01271   bool output=false;
01272   if(&triggerResults_) {
01273     unsigned index = triggerNames_.triggerIndex(pathName);
01274     if(index < triggerNames_.size() && triggerResults_->accept(index)) output = true;
01275   }
01276   return output;
01277 }
01278 
01279 //--------------------------------------------------------
01280 // This returns the position of trigger name defined in summary histograms
01281 double BTagHLTOfflineSource::TriggerPosition(std::string trigName){
01282   int nbins = rate_All->getTH1()->GetNbinsX();
01283   double binVal = -100;
01284   for(int ibin=1; ibin<nbins+1; ibin++)
01285   {
01286     const char * binLabel = rate_All->getTH1()->GetXaxis()->GetBinLabel(ibin);
01287     if(binLabel[0]=='\0')continue;
01288     //       std::string binLabel_str = string(binLabel);
01289     //       if(binLabel_str.compare(trigName)!=0)continue;
01290     if(trigName.compare(binLabel)!=0)continue;
01291 
01292     if(trigName.compare(binLabel)==0){
01293       binVal = rate_All->getTH1()->GetBinCenter(ibin);
01294       break;
01295     }
01296   }
01297   return binVal;
01298 }
01299 
01300 //--------------------------------------------------------
01301 bool BTagHLTOfflineSource::isTriggerObjectFound(std::string objectName){
01302   // processname_, triggerObj_ has to be defined before calling this method
01303   bool output=false;
01304   edm::InputTag testTag(objectName,"",processname_);
01305   const int index = triggerObj_->filterIndex(testTag);
01306   if ( index >= triggerObj_->sizeFilters() ) {    
01307     edm::LogInfo("BTagHLTOfflineSource") << "no index "<< index << " of that name ";
01308   } else {       
01309     const trigger::Keys & k = triggerObj_->filterKeys(index);
01310     if (k.size()) output=true;
01311   }
01312   return output;
01313 }
01314 
01315 //--------------------------------------------------------
01316 void BTagHLTOfflineSource::selectMuons(const edm::Handle<reco::MuonCollection> & muonHandle)
01317 {
01318   // for every event, first clear vector of selected objects
01319   SelectedMuons->clear();
01320 
01321   if(muonHandle.isValid()) { 
01322 
01323     for( reco::MuonCollection::const_iterator iter = muonHandle->begin(), iend = muonHandle->end(); iter != iend; ++iter )
01324       {
01325         
01326         if( iter->isGlobalMuon())// Global Muon
01327           {
01328             if(isVBTFMuon(*iter)) SelectedMuons->push_back(*iter);
01329           }//Global Muon
01330 
01331       } // end for
01332   
01333     edm::Handle<reco::MuonCollection> localSelMuonsHandle(SelectedMuons, muonHandle.provenance());
01334     SelectedMuonsColl_ = localSelMuonsHandle;
01335 
01336   } // end if
01337 
01338 
01339 }
01340 
01341 //--------------------------------------------------------
01342 bool BTagHLTOfflineSource::isVBTFMuon(const reco::Muon& muon)
01343 {
01344 
01345   bool quality = 1;
01346 
01347   reco::TrackRef gm = muon.globalTrack();
01348   reco::TrackRef tk = muon.innerTrack();
01349 
01350   // Muon Quality cuts same as b-tag efficiency methods
01351   // --------------------------------------------------
01352 
01353   double mupt             = muon.pt();
01354   double mueta            = muon.eta();
01355   int muonHits            = gm->hitPattern().numberOfValidMuonHits();
01356   int nMatches            = muon.numberOfMatches();
01357   int trackerHits         = tk->hitPattern().numberOfValidHits();
01358   int pixelHits           = tk->hitPattern().numberOfValidPixelHits();
01359   int outerHits           = tk->trackerExpectedHitsOuter().numberOfHits();
01360   double tknormalizedChi2 = tk->normalizedChi2(); 
01361   double gmnormalizedChi2 = gm->normalizedChi2(); 
01362 
01363   // Must have BeamSpot
01364   if(!beamSpot_.isValid()) return 0;
01365   double mudZ             = muon.vz() - beamSpot_->z0(); //pv->z();
01366   
01367   /*
01368     #pt > 5. & abs(eta) < 2.4 & isGlobalMuon() & 
01369     # globalTrack().hitPattern().numberOfValidMuonHits() > 0 
01370     #& numberOfMatches() > 1 & 
01371     #innerTrack().numberOfValidHits()> 10 
01372     #& innerTrack().hitPattern().numberOfValidPixelHits()>1 
01373     #& innerTrack().trackerExpectedHitsOuter().numberOfHits() <3 
01374     #& innerTrack().normalizedChi2() < 10 & globalTrack().normalizedChi2() < 10
01375     #& muon.vz()‐primaryVertex.z() <2 & DR(muon,jet)<0.4
01376   */
01377 
01378   if (mupt < _mupt)                           {return 0; quality=0;}
01379   if (fabs(mueta) > _mueta)                   {return 0; quality=0;}
01380   if (muonHits < _muonHits)                   {return 0; quality=0;}
01381   if (nMatches < _nMatches)                   {return 0; quality=0;}
01382   if (trackerHits < _trackerHits)             {return 0; quality=0;}
01383   if (pixelHits < _pixelHits)                 {return 0; quality=0;}
01384   if (outerHits > _outerHits)                 {return 0; quality=0;}
01385   if (tknormalizedChi2 > _tknormalizedChi2)   {return 0; quality=0;}
01386   if (gmnormalizedChi2 > _gmnormalizedChi2)   {return 0; quality=0;}
01387   if (mudZ > _mudZ)                           {return 0; quality=0;}
01388 
01389   return true;
01390 
01391 }
01392 
01393 //--------------------------------------------------------
01394 void BTagHLTOfflineSource::selectJets(const edm::Event& iEvent, const edm::Handle<reco::CaloJetCollection> & jetHandle)
01395 {
01396   // for every event, first clear vector of selected objects
01397   SelectedCaloJets->clear();
01398   
01399   if(jetHandle.isValid()) { 
01400     
01401     //    std::stable_sort( jetHandle->begin(), jetHandle->end(), JetPtSorter() );
01402     
01403     for( reco::CaloJetCollection::const_iterator iter = jetHandle->begin(), iend = jetHandle->end(); iter != iend; ++iter )
01404       {
01405         jetID->calculate(iEvent, *iter);
01406         if ( iter->pt() > _jetpt && 
01407              (iter->emEnergyFraction()>_fEMF || fabs(iter->eta()) > _jeteta) &&
01408              jetID->fHPD() < _fHPD &&
01409              iter->n90() >= _n90Hits 
01410              )
01411           { // apply jet cuts
01412             SelectedCaloJets->push_back(*iter);
01413           }
01414       } // end for
01415   
01416     edm::Handle<reco::CaloJetCollection> localSelJetsHandle(SelectedCaloJets, jetHandle.provenance());
01417     SelectedCaloJetsColl_ = localSelJetsHandle;
01418     
01419   } // end if
01420   
01421 }
01422 
01423 //--------------------------------------------------------
01424 bool BTagHLTOfflineSource::isMuonJet(const reco::CaloJet& calojet, reco::MuonCollection *SelectedMuons)
01425 {
01426   
01427   bool  isMuJet = false;
01428   
01429   if (SelectedMuons->size() != 0) 
01430     {//non empty muon collection
01431       
01432       for( reco::MuonCollection::const_iterator mu = SelectedMuons->begin(); mu != SelectedMuons->end(); ++mu )
01433         {
01434           if( (deltaR(calojet.eta(), calojet.phi(), mu->eta(), mu->phi() )) < _mujetdR )
01435             isMuJet = true;
01436         }
01437 
01438     }//non empty muon collection
01439 
01440   return isMuJet;
01441 }
01442 
01443 //--------------------------------------------------------