CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/HLTriggerOffline/Tau/src/L1TauAnalyzer.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Package:    L1TauAnalyzer
00004 // Class:      L1TauAnalyzer
00005 // 
00013 //
00014 // Original Author:  Chi Nhan Nguyen
00015 //         Created:  Fri Feb 22 09:20:55 CST 2008
00016 // $Id: L1TauAnalyzer.cc,v 1.6 2010/05/03 15:38:25 nuno Exp $
00017 //
00018 //
00019 
00020 #include "HLTriggerOffline/Tau/interface/L1TauAnalyzer.h"
00021 
00022 
00023 //
00024 // constructors and destructor
00025 //
00026 L1TauAnalyzer::L1TauAnalyzer(const edm::ParameterSet& iConfig)
00027 
00028 {
00029   _GenParticleSource = iConfig.getParameter<edm::InputTag>("GenParticleSource");
00030   _PFTauSource = iConfig.getParameter<edm::InputTag>("PFTauSource");
00031   _PFTauDiscriminatorSource = iConfig.getParameter<edm::InputTag>("PFTauDiscriminatorSource");
00032 
00033   _L1extraTauJetSource = iConfig.getParameter<edm::InputTag>("L1extraTauJetSource");
00034   _L1extraCenJetSource = iConfig.getParameter<edm::InputTag>("L1extraCenJetSource");
00035   _L1extraForJetSource = iConfig.getParameter<edm::InputTag>("L1extraForJetSource");
00036   _L1extraMuonSource = iConfig.getParameter<edm::InputTag>("L1extraMuonSource");
00037   _L1extraMETSource = iConfig.getParameter<edm::InputTag>("L1extraMETSource");
00038   _L1extraNonIsoEgammaSource = iConfig.getParameter<edm::InputTag>("L1extraNonIsoEgammaSource");
00039   _L1extraIsoEgammaSource = iConfig.getParameter<edm::InputTag>("L1extraIsoEgammaSource");
00040 
00041   _DoMCMatching = iConfig.getParameter<bool>("DoMCMatching");
00042   _DoPFTauMatching = iConfig.getParameter<bool>("DoPFTauMatching");
00043 
00044   _L1MCTauMinDeltaR = iConfig.getParameter<double>("L1MCTauMinDeltaR");
00045   _MCTauHadMinEt = iConfig.getParameter<double>("MCTauHadMinEt");
00046   _MCTauHadMaxAbsEta = iConfig.getParameter<double>("MCTauHadMaxAbsEta");
00047 
00048   _PFMCTauMinDeltaR = iConfig.getParameter<double>("PFMCTauMinDeltaR");
00049   _PFTauMinEt = iConfig.getParameter<double>("PFTauMinEt");
00050   _PFTauMaxAbsEta = iConfig.getParameter<double>("PFTauMaxAbsEta");
00051 
00052   _SingleTauThreshold = iConfig.getParameter<double>("SingleTauThreshold");
00053   _DoubleTauThreshold = iConfig.getParameter<double>("DoubleTauThreshold");
00054   _SingleTauMETThresholds = iConfig.getParameter< std::vector<double> >("SingleTauMETThresholds");
00055   _MuTauThresholds = iConfig.getParameter< std::vector<double> >("MuTauThresholds");
00056   _IsoEgTauThresholds = iConfig.getParameter< std::vector<double> >("IsoEgTauThresholds");
00057 
00058   _L1GtReadoutRecord = iConfig.getParameter<edm::InputTag>("L1GtReadoutRecord");
00059   _L1GtObjectMap = iConfig.getParameter<edm::InputTag>("L1GtObjectMap");
00060   
00061   _L1SingleTauName = iConfig.getParameter<std::string>("L1SingleTauName");
00062   _L1DoubleTauName = iConfig.getParameter<std::string>("L1DoubleTauName");
00063   _L1TauMETName = iConfig.getParameter<std::string>("L1TauMETName");
00064   _L1MuonTauName = iConfig.getParameter<std::string>("L1MuonTauName");
00065   _L1IsoEgTauName = iConfig.getParameter<std::string>("L1IsoEGTauName");
00066 
00067   _BosonPID = iConfig.getParameter<int>("BosonPID");
00068 }
00069 
00070 
00071 L1TauAnalyzer::~L1TauAnalyzer()
00072 {
00073  
00074    // do anything here that needs to be done at desctruction time
00075    // (e.g. close files, deallocate resources etc.)
00076 
00077 }
00078 
00079 
00080 //
00081 // member functions
00082 //
00083 
00084 // ------------ method called to for each event  ------------
00085 void
00086 L1TauAnalyzer::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup)
00087 {
00088    using namespace edm;
00089 
00090    _nEvents++;
00091 
00092   // get object
00093    getL1extraObjects(iEvent,iSetup);
00094    if (_DoMCMatching)
00095      getGenObjects(iEvent,iSetup);
00096    if (_DoPFTauMatching)
00097      getPFTauObjects(iEvent,iSetup);
00098 
00099    evalL1Decisions(iEvent);
00100    evalL1extraDecisions();
00101    
00102    // fill simple histograms
00103    fillL1Histograms();
00104    if (_DoMCMatching)
00105      fillGenHistograms();
00106    if (_DoPFTauMatching)
00107      fillPFTauHistograms();
00108 
00109    if (_DoMCMatching)
00110      calcL1MCTauMatching();
00111    if (_DoMCMatching && _DoPFTauMatching)
00112      calcL1MCPFTauMatching();
00113 
00114 }
00115 
00116 
00117 // ------------ method called once each job just before starting event loop  ------------
00118 void 
00119 L1TauAnalyzer::beginJob()
00120 {
00121   edm::Service<TFileService> fs;
00122   TFileDirectory dir = fs->mkdir("histos");
00123 
00124   //
00125   h_L1TauEt = dir.make<TH1F>("L1TauEt","L1TauEt",50,0.,100.);
00126   h_L1TauEt->Sumw2();
00127   h_L1TauEta = dir.make<TH1F>("L1TauEta","L1TauEt",60,-4.,4.);
00128   h_L1TauEta->Sumw2();
00129   h_L1TauPhi = dir.make<TH1F>("L1TauPhi","L1TauPhi",50,-3.2,3.2);
00130   h_L1TauPhi->Sumw2();
00131 
00132   h_L1Tau1Et = dir.make<TH1F>("L1Tau1Et","L1Tau1Et",50,0.,100.);
00133   h_L1Tau1Et->Sumw2();
00134   h_L1Tau1Eta = dir.make<TH1F>("L1Tau1Eta","L1Tau1Et",60,-4.,4.);
00135   h_L1Tau1Eta->Sumw2();
00136   h_L1Tau1Phi = dir.make<TH1F>("L1Tau1Phi","L1Tau1Phi",50,-3.2,3.2);
00137   h_L1Tau1Phi->Sumw2();
00138 
00139   h_L1Tau2Et = dir.make<TH1F>("L1Tau2Et","L1Tau2Et",50,0.,100.);
00140   h_L1Tau2Et->Sumw2();
00141   h_L1Tau2Eta = dir.make<TH1F>("L1Tau2Eta","L1Tau2Et",60,-4.,4.);
00142   h_L1Tau2Eta->Sumw2();
00143   h_L1Tau2Phi = dir.make<TH1F>("L1Tau2Phi","L1Tau2Phi",50,-3.2,3.2);
00144   h_L1Tau2Phi->Sumw2();
00145 
00146   //
00147   h_GenTauHadEt = dir.make<TH1F>("GenTauHadEt","GenTauHadEt",50,0.,100.);
00148   h_GenTauHadEt->Sumw2();
00149   h_GenTauHadEta = dir.make<TH1F>("GenTauHadEta","GenTauHadEt",60,-4.,4.);
00150   h_GenTauHadEta->Sumw2();
00151   h_GenTauHadPhi = dir.make<TH1F>("GenTauHadPhi","GenTauHadPhi",50,-3.2,3.2);
00152   h_GenTauHadPhi->Sumw2();
00153 
00154   //
00155   h_PFTauEt = dir.make<TH1F>("PFTauEt","PFTauEt",50,0.,100.);
00156   h_PFTauEt->Sumw2();
00157   h_PFTauEta = dir.make<TH1F>("PFTauEta","PFTauEt",60,-4.,4.);
00158   h_PFTauEta->Sumw2();
00159   h_PFTauPhi = dir.make<TH1F>("PFTauPhi","PFTauPhi",50,-3.2,3.2);
00160   h_PFTauPhi->Sumw2();
00161 
00162   // L1 response
00163   h_L1MCTauDeltaR = dir.make<TH1F>("L1MCTauDeltaR","L1MCTauDeltaR",60,0.,6.);
00164   h_L1MCTauDeltaR->Sumw2();
00165   h_L1minusMCTauEt = dir.make<TH1F>("L1minusMCTauEt","L1minusMCTauEt",50,-50.,50.);
00166   h_L1minusMCTauEt->Sumw2();
00167   h_L1minusMCoverMCTauEt = dir.make<TH1F>("L1minusMCoverMCTauEt","L1minusMCoverMCTauEt",40,-1.2,1.2);
00168   h_L1minusMCoverMCTauEt->Sumw2();
00169  
00170   // MC matching efficiencies
00171   h_MCTauHadEt = dir.make<TH1F>("MCTauHadEt","MCTauHadEt",50,0.,100.);
00172   h_MCTauHadEt->Sumw2();
00173   h_MCTauHadEta = dir.make<TH1F>("MCTauHadEta","MCTauHadEt",60,-4.,4.);
00174   h_MCTauHadEta->Sumw2();
00175   h_MCTauHadPhi = dir.make<TH1F>("MCTauHadPhi","MCTauHadPhi",50,-3.2,3.2);
00176   h_MCTauHadPhi->Sumw2();
00177 
00178   h_L1MCMatchedTauEt = dir.make<TH1F>("L1MCMatchedTauEt","L1MCMatchedTauEt",50,0.,100.);
00179   h_L1MCMatchedTauEt->Sumw2();
00180   h_L1MCMatchedTauEta = dir.make<TH1F>("L1MCMatchedTauEta","L1MCMatchedTauEt",60,-4.,4.);
00181   h_L1MCMatchedTauEta->Sumw2();
00182   h_L1MCMatchedTauPhi = dir.make<TH1F>("L1MCMatchedTauPhi","L1MCMatchedTauPhi",50,-3.2,3.2);
00183   h_L1MCMatchedTauPhi->Sumw2();
00184 
00185   h_EffMCTauEt = dir.make<TH1F>("EffMCTauEt","EffMCTauEt",50,0.,100.);
00186   h_EffMCTauEt->Sumw2();
00187   h_EffMCTauEta = dir.make<TH1F>("EffMCTauEta","EffMCTauEt",60,-4.,4.);
00188   h_EffMCTauEta->Sumw2();
00189   h_EffMCTauPhi = dir.make<TH1F>("EffMCTauPhi","EffMCTauPhi",50,-3.2,3.2);
00190   h_EffMCTauPhi->Sumw2();
00191 
00192   // PFTau-MC matching efficiencies
00193   h_MCPFTauHadEt = dir.make<TH1F>("MCPFTauHadEt","MCPFTauHadEt",50,0.,100.);
00194   h_MCPFTauHadEt->Sumw2();
00195   h_MCPFTauHadEta = dir.make<TH1F>("MCPFTauHadEta","MCPFTauHadEt",60,-4.,4.);
00196   h_MCPFTauHadEta->Sumw2();
00197   h_MCPFTauHadPhi = dir.make<TH1F>("MCPFTauHadPhi","MCPFTauHadPhi",50,-3.2,3.2);
00198   h_MCPFTauHadPhi->Sumw2();
00199 
00200   h_L1MCPFMatchedTauEt = dir.make<TH1F>("L1MCPFMatchedTauEt","L1MCPFMatchedTauEt",50,0.,100.);
00201   h_L1MCPFMatchedTauEt->Sumw2();
00202   h_L1MCPFMatchedTauEta = dir.make<TH1F>("L1MCPFMatchedTauEta","L1MCPFMatchedTauEt",60,-4.,4.);
00203   h_L1MCPFMatchedTauEta->Sumw2();
00204   h_L1MCPFMatchedTauPhi = dir.make<TH1F>("L1MCPFMatchedTauPhi","L1MCPFMatchedTauPhi",50,-3.2,3.2);
00205   h_L1MCPFMatchedTauPhi->Sumw2();
00206 
00207   h_EffMCPFTauEt = dir.make<TH1F>("EffMCPFTauEt","EffMCPFTauEt",50,0.,100.);
00208   h_EffMCPFTauEt->Sumw2();
00209   h_EffMCPFTauEta = dir.make<TH1F>("EffMCPFTauEta","EffMCPFTauEt",60,-4.,4.);
00210   h_EffMCPFTauEta->Sumw2();
00211   h_EffMCPFTauPhi = dir.make<TH1F>("EffMCPFTauPhi","EffMCPFTauPhi",50,-3.2,3.2);
00212   h_EffMCPFTauPhi->Sumw2();
00213 
00214   h_PFMCTauDeltaR = dir.make<TH1F>("PFMCTauDeltaR","PFMCTauDeltaR",60,0.,6.);
00215   h_PFMCTauDeltaR->Sumw2();
00216 
00217 
00218   h_L1SingleTauEffEt = dir.make<TH1F>("L1SingleTauEffEt","L1SingleTauEffEt",
00219                                              50,0.,100.);
00220   h_L1SingleTauEffEt->Sumw2();
00221   h_L1DoubleTauEffEt = dir.make<TH1F>("L1DoubleTauEffEt","L1DoubleTauEffEt",
00222                                              40,0.,80.);
00223   h_L1DoubleTauEffEt->Sumw2();
00224   h_L1SingleTauEffMCMatchEt = dir.make<TH1F>("L1SingleTauEffMCMatchEt","L1SingleTauEffMCMatchEt",
00225                                              50,0.,100.);
00226   h_L1SingleTauEffMCMatchEt->Sumw2();
00227   h_L1DoubleTauEffMCMatchEt = dir.make<TH1F>("L1DoubleTauEffMCMatchEt","L1DoubleTauEffMCMatchEt",
00228                                              40,0.,80.);
00229   h_L1DoubleTauEffMCMatchEt->Sumw2();
00230   h_L1SingleTauEffPFMCMatchEt = dir.make<TH1F>("L1SingleTauEffPFMCMatchEt","L1SingleTauEffPFMCMatchEt",
00231                                              50,0.,100.);
00232   h_L1SingleTauEffPFMCMatchEt->Sumw2();
00233   h_L1DoubleTauEffPFMCMatchEt = dir.make<TH1F>("L1DoubleTauEffPFMCMatchEt","L1DoubleTauEffPFMCMatchEt",
00234                                              40,0.,80.);
00235   h_L1DoubleTauEffPFMCMatchEt->Sumw2();
00236 
00237   // Init counters for event based efficiencies
00238   _nEvents = 0; // all events processed
00239 
00240   _nEventsGenTauHad = 0; 
00241   _nEventsDoubleGenTauHads = 0; 
00242   _nEventsGenTauMuonTauHad = 0; 
00243   _nEventsGenTauElecTauHad = 0;   
00244 
00245   _nfidEventsGenTauHad = 0; 
00246   _nfidEventsDoubleGenTauHads = 0; 
00247   _nfidEventsGenTauMuonTauHad = 0; 
00248   _nfidEventsGenTauElecTauHad = 0;   
00249 
00250   _nEventsPFMatchGenTauHad = 0; 
00251   _nEventsPFMatchDoubleGenTauHads = 0; 
00252   _nEventsPFMatchGenTauMuonTauHad = 0; 
00253   _nEventsPFMatchGenTauElecTauHad = 0;   
00254 
00255   _nEventsL1SingleTauPassed = 0;
00256   _nEventsL1SingleTauPassedMCMatched = 0;
00257   _nEventsL1SingleTauPassedPFMCMatched = 0;
00258 
00259   _nEventsL1DoubleTauPassed = 0;
00260   _nEventsL1DoubleTauPassedMCMatched = 0;
00261   _nEventsL1DoubleTauPassedPFMCMatched = 0;
00262 
00263   _nEventsL1SingleTauMETPassed = 0;
00264   _nEventsL1SingleTauMETPassedMCMatched = 0;
00265   _nEventsL1SingleTauMETPassedPFMCMatched = 0;
00266 
00267   _nEventsL1MuonTauPassed = 0;
00268   _nEventsL1MuonTauPassedMCMatched = 0;
00269   _nEventsL1MuonTauPassedPFMCMatched = 0;
00270 
00271   _nEventsL1IsoEgTauPassed = 0;
00272   _nEventsL1IsoEgTauPassedMCMatched = 0;
00273   _nEventsL1IsoEgTauPassedPFMCMatched = 0;
00274 
00275   // from GT bit info
00276   _nEventsL1GTSingleTauPassed = 0;
00277   _nEventsL1GTDoubleTauPassed = 0;
00278   _nEventsL1GTSingleTauMETPassed = 0;
00279   _nEventsL1GTMuonTauPassed = 0;
00280   _nEventsL1GTIsoEgTauPassed = 0;
00281 
00282 }
00283 
00284 // ------------ method called once each job just after ending the event loop  ------------
00285 void 
00286 L1TauAnalyzer::endJob() {
00287 
00288   // MC matching efficiencies
00289   h_EffMCTauEt->Divide(h_MCTauHadEt);
00290   h_EffMCTauEta->Divide(h_MCTauHadEta);
00291   h_EffMCTauPhi->Divide(h_MCTauHadPhi);
00292 
00293   // MC-PFTau matching efficiencies
00294   h_EffMCPFTauEt->Divide(h_MCPFTauHadEt);
00295   h_EffMCPFTauEta->Divide(h_MCPFTauHadEta);
00296   h_EffMCPFTauPhi->Divide(h_MCPFTauHadPhi);
00297 
00298   //
00299   convertToIntegratedEff(h_L1SingleTauEffEt,(double)_nEvents);
00300   convertToIntegratedEff(h_L1DoubleTauEffEt,(double)_nEvents);
00301   convertToIntegratedEff(h_L1SingleTauEffMCMatchEt,(double)_nfidEventsGenTauHad);
00302   convertToIntegratedEff(h_L1DoubleTauEffMCMatchEt,(double)_nfidEventsDoubleGenTauHads);
00303   convertToIntegratedEff(h_L1SingleTauEffPFMCMatchEt,(double)_nEventsPFMatchGenTauHad);
00304   convertToIntegratedEff(h_L1DoubleTauEffPFMCMatchEt,(double)_nEventsPFMatchDoubleGenTauHads);
00305 
00306   //printTrigReport();
00307 }
00308 
00309 void
00310 L1TauAnalyzer::getL1extraObjects(const edm::Event& iEvent, const edm::EventSetup& iSetup)
00311 {
00312   using namespace edm;
00313   using namespace l1extra;
00314 
00315   //
00316   _L1Taus.clear();
00317   Handle<L1JetParticleCollection> l1TauHandle;
00318   iEvent.getByLabel(_L1extraTauJetSource,l1TauHandle);
00319   for( L1JetParticleCollection::const_iterator itr = l1TauHandle->begin() ;
00320        itr != l1TauHandle->end() ; ++itr ) {
00321     TLorentzVector p(itr->px(),itr->py(),itr->pz(),itr->energy());
00322     _L1Taus.push_back(p);
00323   }
00324 
00325   //
00326   _L1CenJets.clear();
00327   Handle<L1JetParticleCollection> l1CenJetHandle;
00328   iEvent.getByLabel(_L1extraCenJetSource,l1CenJetHandle);
00329   for( L1JetParticleCollection::const_iterator itr = l1CenJetHandle->begin() ;
00330        itr != l1CenJetHandle->end() ; ++itr ) {
00331     TLorentzVector p(itr->px(),itr->py(),itr->pz(),itr->energy());
00332     _L1CenJets.push_back(p);
00333   }
00334 
00335   //
00336   _L1ForJets.clear();
00337   Handle<L1JetParticleCollection> l1ForJetHandle;
00338   iEvent.getByLabel(_L1extraForJetSource,l1ForJetHandle);
00339   for( L1JetParticleCollection::const_iterator itr = l1ForJetHandle->begin() ;
00340        itr != l1ForJetHandle->end() ; ++itr ) {
00341     TLorentzVector p(itr->px(),itr->py(),itr->pz(),itr->energy());
00342     _L1ForJets.push_back(p);
00343   }
00344 
00345   //
00346   _L1IsoEgammas.clear();
00347   Handle<L1EmParticleCollection> l1IsoEgammaHandle;
00348   iEvent.getByLabel(_L1extraIsoEgammaSource,l1IsoEgammaHandle);
00349   for( L1EmParticleCollection::const_iterator itr = l1IsoEgammaHandle->begin() ;
00350        itr != l1IsoEgammaHandle->end() ; ++itr ) {
00351     TLorentzVector p(itr->px(),itr->py(),itr->pz(),itr->energy());
00352     _L1IsoEgammas.push_back(p);
00353   }
00354 
00355   //
00356   _L1NonIsoEgammas.clear();
00357   Handle<L1EmParticleCollection> l1NonIsoEgammaHandle;
00358   iEvent.getByLabel(_L1extraNonIsoEgammaSource,l1NonIsoEgammaHandle);
00359   for( L1EmParticleCollection::const_iterator itr = l1NonIsoEgammaHandle->begin() ;
00360        itr != l1NonIsoEgammaHandle->end() ; ++itr ) {
00361     TLorentzVector p(itr->px(),itr->py(),itr->pz(),itr->energy());
00362     _L1NonIsoEgammas.push_back(p);
00363   }
00364 
00365   //
00366   _L1Muons.clear();
00367   _L1MuQuals.clear();
00368   Handle<L1MuonParticleCollection> l1MuonHandle;
00369   iEvent.getByLabel(_L1extraMuonSource,l1MuonHandle);
00370   for( L1MuonParticleCollection::const_iterator itr = l1MuonHandle->begin() ;
00371        itr != l1MuonHandle->end() ; ++itr ) {
00372     TLorentzVector p(itr->px(),itr->py(),itr->pz(),itr->energy());
00373     _L1Muons.push_back(p);
00374     L1MuGMTExtendedCand gmtCand = itr->gmtMuonCand();
00375     _L1MuQuals.push_back(gmtCand.quality());// Muon quality as defined in the GT
00376   }
00377 
00378   //
00379   _L1METs.clear();
00380   Handle<L1EtMissParticleCollection> l1MetHandle;
00381   iEvent.getByLabel(_L1extraMETSource,l1MetHandle);
00382   for( L1EtMissParticleCollection::const_iterator itr = l1MetHandle->begin() ;
00383        itr != l1MetHandle->end() ; ++itr ) {
00384     TLorentzVector p(itr->px(),itr->py(),itr->pz(),itr->energy());
00385     _L1METs.push_back(p);
00386   }
00387 
00388 }
00389 
00390 void
00391 L1TauAnalyzer::getPFTauObjects(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
00392   using namespace edm;
00393   using namespace reco;
00394 
00395   _PFTaus.clear();
00396   Handle<PFTauCollection> thePFTauHandle; 
00397   iEvent.getByLabel(_PFTauSource,thePFTauHandle); 
00398   Handle<PFTauDiscriminatorByIsolation> thePFTauDiscriminatorByIsolation; 
00399   iEvent.getByLabel(_PFTauDiscriminatorSource,thePFTauDiscriminatorByIsolation); 
00400   for (PFTauCollection::size_type iPFTau=0;iPFTau<thePFTauHandle->size();iPFTau++) { 
00401     PFTauRef thePFTau(thePFTauHandle,iPFTau); 
00402     if ((*thePFTauDiscriminatorByIsolation)[thePFTau] == 1) {
00403       TLorentzVector pftau((*thePFTau).px(),(*thePFTau).py(),(*thePFTau).pz(),(*thePFTau).energy());
00404       _PFTaus.push_back(pftau);
00405     }
00406   }
00407 }
00408 
00409 void
00410 L1TauAnalyzer::getGenObjects(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
00411   using namespace edm;
00412   using namespace HepMC;
00413 
00415   // MC Truth based on RecoTauTag/HLTAnalyzers/src/TauJetMCFilter.cc
00416   Handle<HepMCProduct> evt;
00417   iEvent.getByLabel(_GenParticleSource, evt);
00418   GenEvent * generated_event = new GenEvent(*(evt->GetEvent()));
00419 
00420   //init
00421   _GenTauHads.clear();
00422   _GenTauMuons.clear();
00423   _GenTauElecs.clear();
00424 
00425   int nTauHads = 0; int nTauMuons = 0;int nTauElecs = 0; //
00426   int nfidTauHads = 0; int nfidTauMuons = 0;int nfidTauElecs = 0; // count in fiducial region
00427   TLorentzVector taunu,tauelec,taumuon;
00428   GenEvent::particle_iterator p;
00429 
00430   for (p = generated_event->particles_begin(); p != generated_event->particles_end(); ++p) {
00431     if(abs((*p)->pdg_id()) == _BosonPID && (*p)->end_vertex()) {
00432       HepMC::GenVertex::particle_iterator z = (*p)->end_vertex()->particles_begin(HepMC::descendants);
00433       for(; z != (*p)->end_vertex()->particles_end(HepMC::descendants); z++) {
00434         if(abs((*z)->pdg_id()) == 15 && (*z)->status()==2) { 
00435           bool lept_decay = false;
00436           TLorentzVector tau((*z)->momentum().px(),(*z)->momentum().py(),(*z)->momentum().pz(),(*z)->momentum().e());
00437           HepMC::GenVertex::particle_iterator t = (*z)->end_vertex()->particles_begin(HepMC::descendants);
00438           for(; t != (*z)->end_vertex()->particles_end(HepMC::descendants); t++) {
00439             if(abs((*t)->pdg_id()) == 11 || abs((*t)->pdg_id()) == 13) lept_decay=true;
00440             if(abs((*t)->pdg_id()) == 11) {
00441               tauelec.SetPxPyPzE((*t)->momentum().px(),(*t)->momentum().py(),(*t)->momentum().pz(),(*t)->momentum().e());
00442               _GenTauElecs.push_back(tauelec);
00443               nTauElecs++;
00444               if (tauelec.Et()>=_MCTauHadMinEt && tauelec.Eta()<=_MCTauHadMaxAbsEta )
00445                 nfidTauElecs++;
00446             }
00447             if(abs((*t)->pdg_id()) == 13) {
00448               taumuon.SetPxPyPzE((*t)->momentum().px(),(*t)->momentum().py(),(*t)->momentum().pz(),(*t)->momentum().e());
00449               _GenTauMuons.push_back(taumuon);
00450               nTauMuons++;
00451               if (taumuon.Et()>=_MCTauHadMinEt && taumuon.Eta()<=_MCTauHadMaxAbsEta )
00452                 nfidTauMuons++;
00453             }
00454             if(abs((*t)->pdg_id()) == 16)
00455               taunu.SetPxPyPzE((*t)->momentum().px(),(*t)->momentum().py(),(*t)->momentum().pz(),(*t)->momentum().e()); 
00456           }
00457           if(lept_decay==false) {
00458             TLorentzVector jetMom=tau-taunu;
00459             _GenTauHads.push_back(jetMom);
00460             nTauHads++;
00461             if (jetMom.Et()>=_MCTauHadMinEt && jetMom.Eta()<=_MCTauHadMaxAbsEta )
00462               nfidTauHads++;
00463           }
00464         }    
00465       }
00466     }
00467   }
00468   delete generated_event;
00469 
00470   // Counters
00471   if (nTauHads >= 1) _nEventsGenTauHad++; 
00472   if (nTauHads >= 2) _nEventsDoubleGenTauHads++; 
00473   if (nTauHads >= 1 && nTauMuons >= 1) _nEventsGenTauMuonTauHad++; 
00474   if (nTauHads >= 1 && nTauElecs >= 1) _nEventsGenTauElecTauHad++; 
00475 
00477   if (nfidTauHads >= 1) _nfidEventsGenTauHad++; 
00478   if (nfidTauHads >= 2) _nfidEventsDoubleGenTauHads++; 
00479   if (nfidTauHads >= 1 && nfidTauMuons >= 1) _nfidEventsGenTauMuonTauHad++; 
00480   if (nfidTauHads >= 1 && nfidTauElecs >= 1) _nfidEventsGenTauElecTauHad++; 
00481 
00482 }
00483 
00484 
00485 void
00486 L1TauAnalyzer::fillL1Histograms() {
00487   for (int i=0; i<(int)_L1Taus.size(); i++) {
00488     h_L1TauEt->Fill(_L1Taus[i].Et());
00489     h_L1TauEta->Fill(_L1Taus[i].Eta());
00490     h_L1TauPhi->Fill(_L1Taus[i].Phi());
00491     if (i==0) {
00492       h_L1Tau1Et->Fill(_L1Taus[i].Et());
00493       h_L1Tau1Eta->Fill(_L1Taus[i].Eta());
00494       h_L1Tau1Phi->Fill(_L1Taus[i].Phi());
00495     }
00496     if (i==1) {
00497       h_L1Tau2Et->Fill(_L1Taus[i].Et());
00498       h_L1Tau2Eta->Fill(_L1Taus[i].Eta());
00499       h_L1Tau2Phi->Fill(_L1Taus[i].Phi());
00500     }    
00501   }
00502 
00503 }
00504 
00505 void
00506 L1TauAnalyzer::fillGenHistograms() {
00507   for (int i=0; i<(int)_GenTauHads.size(); i++) {
00508     h_GenTauHadEt->Fill(_GenTauHads[i].Et());
00509     h_GenTauHadEta->Fill(_GenTauHads[i].Eta());
00510     h_GenTauHadPhi->Fill(_GenTauHads[i].Phi());
00511   }  
00512   // Denominators for MC matching efficiencies
00513   for (int i=0; i<(int)_GenTauHads.size(); i++) {
00514     if (std::abs(_GenTauHads[i].Eta())<=_MCTauHadMaxAbsEta)
00515       h_MCTauHadEt->Fill(_GenTauHads[i].Et());
00516     if (_GenTauHads[i].Et()>=_MCTauHadMinEt)
00517       h_MCTauHadEta->Fill(_GenTauHads[i].Eta());
00518     if (_GenTauHads[i].Et()>=_MCTauHadMinEt && std::abs(_GenTauHads[i].Eta())<=_MCTauHadMaxAbsEta)
00519       h_MCTauHadPhi->Fill(_GenTauHads[i].Phi());
00520   }
00521 }
00522 
00523 void
00524 L1TauAnalyzer::fillPFTauHistograms() {
00525   for (int i=0; i<(int)_PFTaus.size(); i++) {
00526     h_PFTauEt->Fill(_PFTaus[i].Et());
00527     h_PFTauEta->Fill(_PFTaus[i].Eta());
00528     h_PFTauPhi->Fill(_PFTaus[i].Phi());
00529   }
00530 }
00531 
00532 
00533 
00534 void
00535 L1TauAnalyzer::evalL1Decisions(const edm::Event& iEvent) {
00536   using namespace edm;
00537   using namespace std;
00538 
00539   Handle<L1GlobalTriggerReadoutRecord> l1GtRR;
00540   iEvent.getByLabel(_L1GtReadoutRecord,l1GtRR);
00541   Handle<L1GlobalTriggerObjectMapRecord> l1GtOMRec;
00542   iEvent.getByLabel(_L1GtObjectMap,l1GtOMRec);
00543 
00544   L1GlobalTriggerReadoutRecord L1GTRR = *l1GtRR.product();              
00545   L1GlobalTriggerObjectMapRecord L1GTOMRec = *l1GtOMRec.product();
00546 
00547   DecisionWord gtDecisionWord = L1GTRR.decisionWord();
00548   string l1BitName;
00549   int l1Accept;
00550   // get ObjectMaps from ObjectMapRecord
00551   const vector<L1GlobalTriggerObjectMap>& objMapVec =  L1GTOMRec.gtObjectMap();
00552   for (vector<L1GlobalTriggerObjectMap>::const_iterator itMap = objMapVec.begin();
00553        itMap != objMapVec.end(); ++itMap) {
00554     int iBit = (*itMap).algoBitNumber();
00555     l1BitName = string( (*itMap).algoName() );
00556     l1Accept = gtDecisionWord[iBit];
00557     //cout<<l1BitName<<" "<<l1Accept<<endl;
00558     if (l1BitName.compare(_L1SingleTauName)==0) {
00559       //cout<<l1BitName<<" "<<l1Accept<<endl;
00560       if (l1Accept) _nEventsL1GTSingleTauPassed++;
00561     }
00562     if (l1BitName.compare(_L1DoubleTauName)==0) {
00563       if (l1Accept) _nEventsL1GTDoubleTauPassed++;
00564     }
00565     if (l1BitName.compare(_L1TauMETName)==0) {
00566       if (l1Accept) _nEventsL1GTSingleTauMETPassed++;
00567     }
00568     if (l1BitName.compare(_L1MuonTauName)==0) {
00569       if (l1Accept) _nEventsL1GTMuonTauPassed++;
00570     }
00571     if (l1BitName.compare(_L1IsoEgTauName)==0) {
00572       if (l1Accept) _nEventsL1GTIsoEgTauPassed++;
00573     }
00574   }
00575 }
00576 
00577 void
00578 L1TauAnalyzer::evalL1extraDecisions() {
00579   bool singleTauPassed = false;
00580   bool doubleTauPassed = false;
00581   bool muTauPassed = false;
00582   bool isoEgTauPassed = false;
00583   bool singleTauMETPassed = false;
00584   
00585   int nL1Taus = _L1Taus.size();
00586   int nL1Muons = _L1Muons.size();
00587   int nL1IsoEgammas = _L1IsoEgammas.size();
00588 
00589 
00590   if (nL1Taus>=1) {
00591     h_L1SingleTauEffEt->Fill(_L1Taus[0].Et());
00592     if (_L1Taus[0].Et()>=_SingleTauThreshold)
00593       singleTauPassed = true;
00594   }
00595   if (nL1Taus>=2 ) {
00596     h_L1DoubleTauEffEt->Fill(_L1Taus[1].Et());
00597     if (_L1Taus[1].Et()>=_DoubleTauThreshold)
00598       doubleTauPassed = true;
00599   }
00600 
00601   if (nL1Taus>=1 && _L1Taus[0].Et()>=_SingleTauMETThresholds[0] &&
00602       _L1METs[0].Et()>=_SingleTauMETThresholds[1])
00603     singleTauMETPassed = true;
00604 
00605   if (nL1Taus>=1 && _L1Taus[0].Et()>=_MuTauThresholds[1] &&
00606       nL1Muons>=1 && _L1Muons[0].Pt()>=_MuTauThresholds[0]) {
00607     //if ( _L1MuQuals[0]==4 || _L1MuQuals[0]==5 || _L1MuQuals[0]==6 || _L1MuQuals[0]==7 ) {
00608     //if ( _L1MuQuals[0]==3 || _L1MuQuals[0]==5 || _L1MuQuals[0]==6 || _L1MuQuals[0]==7 ) {
00609     if ( _L1MuQuals[0]>=0) {
00610       muTauPassed = true;
00611     }
00612   }
00613     
00614   for (int i=0;i<nL1Taus;i++) {
00615     for (int j=0;j<nL1IsoEgammas;j++) {
00616       if (_L1Taus[i].Et()>=_IsoEgTauThresholds[1] &&
00617           _L1IsoEgammas[j].Et()>=_IsoEgTauThresholds[0]) {
00618         //double deltaR = ROOT::Math::VectorUtil::DeltaR(_L1Taus[i],_GenTauHads[j]);
00619         double deltaPhi = ROOT::Math::VectorUtil::DeltaPhi(_L1Taus[i],_L1IsoEgammas[j]);
00620         double deltaEta = std::abs(_L1Taus[i].Eta()-_L1IsoEgammas[j].Eta());
00621         // Non-collinearity check
00622         if (deltaPhi>0.348 && deltaEta>0.348) {
00623           isoEgTauPassed = true;
00624           break;
00625         }
00626       }
00627     }
00628   }
00629 
00630   if (singleTauPassed) _nEventsL1SingleTauPassed++;
00631   if (doubleTauPassed) _nEventsL1DoubleTauPassed++;
00632   if (singleTauMETPassed) _nEventsL1SingleTauMETPassed++;
00633   if (muTauPassed) _nEventsL1MuonTauPassed++;
00634   if (isoEgTauPassed) _nEventsL1IsoEgTauPassed++;
00635 }
00636 
00637 
00638 void
00639 L1TauAnalyzer::calcL1MCTauMatching() {
00640   bool singleTauPassed = false;
00641   bool doubleTauPassed = false;
00642   bool muTauPassed = false;
00643   bool isoEgTauPassed = false;
00644   bool singleTauMETPassed = false;
00645 
00646   bool singleMatch = false; // for doubletau match
00647   bool doubleMatch = false; 
00648   int iSingle = -1;
00649   int iDouble = -1;
00650 
00651   for (unsigned int i = 0; i<_L1Taus.size();i++) {
00652     for (unsigned int j = 0; j<_GenTauHads.size();j++) {
00653       double deltaR = ROOT::Math::VectorUtil::DeltaR(_L1Taus[i],_GenTauHads[j]);
00654       h_L1MCTauDeltaR->Fill(deltaR);
00655       if (deltaR < _L1MCTauMinDeltaR) {
00656         if (_GenTauHads[j].Et()>=_MCTauHadMinEt) {
00657           //if (std::abs(_GenTauHads[j].Eta())<=_MCTauHadMaxAbsEta) {
00658           h_L1minusMCTauEt->Fill(_L1Taus[i].Et() - _GenTauHads[j].Et());
00659           h_L1minusMCoverMCTauEt->Fill( (_L1Taus[i].Et() - _GenTauHads[j].Et()) / _GenTauHads[j].Et());
00660           // For event efficiencies     
00661           if (singleMatch) {
00662             doubleMatch = true;
00663             iDouble = i;
00664           }
00665           singleMatch = true;
00666           if (singleMatch && !doubleMatch)
00667             iSingle = i;
00668         }       
00669         // Numerators for MC matching efficiencies
00670         if (std::abs(_GenTauHads[j].Eta())<=_MCTauHadMaxAbsEta) {       
00671           h_L1MCMatchedTauEt->Fill(_GenTauHads[j].Et());
00672           h_EffMCTauEt->Fill(_GenTauHads[j].Et());
00673         }
00674         if (_GenTauHads[j].Et()>=_MCTauHadMinEt) {
00675           h_L1MCMatchedTauEta->Fill(_GenTauHads[j].Eta());
00676           h_EffMCTauEta->Fill(_GenTauHads[j].Eta());
00677         }
00678         if (_GenTauHads[j].Et()>=_MCTauHadMinEt && std::abs(_GenTauHads[j].Eta())<=_MCTauHadMaxAbsEta) {
00679           h_L1MCMatchedTauPhi->Fill(_GenTauHads[j].Phi());
00680           h_EffMCTauPhi->Fill(_GenTauHads[j].Phi());
00681         }
00682         //break;
00683       }           
00684     }
00685   }
00686   if (singleMatch && iSingle>=0) {
00687     h_L1SingleTauEffMCMatchEt->Fill(_L1Taus[iSingle].Et());
00688     if (_L1Taus[iSingle].Et()>=_SingleTauThreshold)
00689       singleTauPassed = true;
00690 
00691     /*
00692     // Ask for only one L1Tau to be matched with PFTau!!!
00693     if (_L1Taus.size()>=2) {
00694       h_L1DoubleTauEffPFMCMatchEt->Fill(_L1Taus[1].Et());
00695       if (_L1Taus[1].Et()>=_DoubleTauThreshold)
00696         doubleTauPassed = true;
00697     }
00698     */
00699     
00700     if (_L1Taus[iSingle].Et()>=_SingleTauMETThresholds[0] &&
00701         _L1METs[0].Et()>=_SingleTauMETThresholds[1])
00702       singleTauMETPassed = true;
00703     
00704     if (_L1Taus[iSingle].Et()>=_MuTauThresholds[1]) {
00705       for (int i=0;i<(int)_L1Muons.size();i++) {
00706         if (_L1Muons[i].Pt()>=_MuTauThresholds[0]) {
00707           //if ( _L1MuQuals[0]==4 || _L1MuQuals[0]==5 || _L1MuQuals[0]==6 || _L1MuQuals[0]==7 ) {
00708           //if ( _L1MuQuals[0]==3 || _L1MuQuals[0]==5 || _L1MuQuals[0]==6 || _L1MuQuals[0]==7 ) {
00709           if ( _L1MuQuals[i]>=0) {
00710             for (int j=0;j<(int)_GenTauMuons.size();j++) {
00711               double deltaR = ROOT::Math::VectorUtil::DeltaR(_GenTauMuons[j],_L1Muons[i]);
00712               if (deltaR<0.3) {
00713                 muTauPassed = true;
00714               }
00715             }
00716           }
00717         }
00718       }
00719     }
00720     
00721     for (int j=0;j<(int)_L1IsoEgammas.size();j++) {
00722       if (_L1Taus[iSingle].Et()>=_IsoEgTauThresholds[1] &&
00723           _L1IsoEgammas[j].Et()>=_IsoEgTauThresholds[0]) {
00724         double deltaPhi = ROOT::Math::VectorUtil::DeltaPhi(_L1Taus[iSingle],_L1IsoEgammas[j]);
00725         double deltaEta = std::abs(_L1Taus[iSingle].Eta()-_L1IsoEgammas[j].Eta());
00726         // Non-collinearity check
00727         if (deltaPhi>0.348 && deltaEta>0.348) {
00728           for (int k=0;k<(int)_GenTauElecs.size();k++) {
00729             double deltaR = ROOT::Math::VectorUtil::DeltaR(_GenTauElecs[k],_L1IsoEgammas[j]);
00730             if (deltaR<0.3) {
00731               isoEgTauPassed = true;
00732               break;
00733             }
00734           }
00735         }
00736       }
00737     }
00738   }
00739 
00740   if (doubleMatch && iDouble>=0) {
00741     h_L1DoubleTauEffMCMatchEt->Fill(_L1Taus[iDouble].Et());
00742     if (_L1Taus[iDouble].Et()>=_DoubleTauThreshold)
00743       doubleTauPassed = true;
00744     for (int j=0;j<(int)_L1IsoEgammas.size();j++) {
00745       if (_L1Taus[iDouble].Et()>=_IsoEgTauThresholds[1] &&
00746           _L1IsoEgammas[j].Et()>=_IsoEgTauThresholds[0]) {
00747         double deltaPhi = ROOT::Math::VectorUtil::DeltaPhi(_L1Taus[iDouble],_L1IsoEgammas[j]);
00748         double deltaEta = std::abs(_L1Taus[iDouble].Eta()-_L1IsoEgammas[j].Eta());
00749         // Non-collinearity check
00750         if (deltaPhi>0.348 && deltaEta>0.348) {
00751           for (int k=0;k<(int)_GenTauElecs.size();k++) {
00752             double deltaR = ROOT::Math::VectorUtil::DeltaR(_GenTauElecs[k],_L1IsoEgammas[j]);
00753             if (deltaR<0.3) {
00754               isoEgTauPassed = true;
00755               break;
00756             }
00757           }
00758         }
00759       }
00760     }
00761   }
00762   
00763   if (singleTauPassed) _nEventsL1SingleTauPassedMCMatched++;
00764   if (doubleTauPassed) _nEventsL1DoubleTauPassedMCMatched++;
00765   if (singleTauMETPassed) _nEventsL1SingleTauMETPassedMCMatched++;
00766   if (muTauPassed) _nEventsL1MuonTauPassedMCMatched++;
00767   if (isoEgTauPassed) _nEventsL1IsoEgTauPassedMCMatched++;
00768 
00769 }
00770 
00771 void
00772 L1TauAnalyzer::calcL1MCPFTauMatching() {
00773   bool singleTauPassed = false;
00774   bool doubleTauPassed = false;
00775   bool muTauPassed = false;
00776   bool isoEgTauPassed = false;
00777   bool singleTauMETPassed = false;
00778 
00779   bool singleMatch = false; // for doubletau match
00780   bool doubleMatch = false; 
00781   int iSingle = -1;
00782   int iDouble = -1;
00783   
00784   int nPFMatchGenTauHad = 0;
00785   
00786   std::vector<TLorentzVector> PFMatchedGenTauHads;
00787   PFMatchedGenTauHads.clear();// store PFTau matched gentaus
00788   for (unsigned int j = 0; j<_GenTauHads.size();j++) {
00789     for (unsigned int k = 0; k<_PFTaus.size();k++) {
00790       double deltaR = ROOT::Math::VectorUtil::DeltaR(_PFTaus[k],_GenTauHads[j]);
00791       h_PFMCTauDeltaR->Fill(deltaR);      
00792       if (_PFTaus[k].Et()>=_PFTauMinEt && _PFTaus[k].Eta()<=_PFTauMaxAbsEta) {
00793         if (deltaR < _PFMCTauMinDeltaR) {
00794           // Denominators for PF-MC matching efficiencies
00795           if (std::abs(_GenTauHads[j].Eta())<=_MCTauHadMaxAbsEta)
00796             h_MCPFTauHadEt->Fill(_GenTauHads[j].Et());
00797           if (_GenTauHads[j].Et()>=_MCTauHadMinEt)
00798             h_MCPFTauHadEta->Fill(_GenTauHads[j].Eta());
00799           if (_GenTauHads[j].Et()>=_MCTauHadMinEt &&
00800               std::abs(_GenTauHads[j].Eta())<=_MCTauHadMaxAbsEta) {
00801             h_MCPFTauHadPhi->Fill(_GenTauHads[j].Phi());
00802             nPFMatchGenTauHad++; // For denominator
00803             PFMatchedGenTauHads.push_back(_GenTauHads[j]);// store PFTau matched gentaus
00804           }
00805           break;
00806         }
00807       }
00808     }
00809   }
00810   // now loop over only PFTau matched gentaus
00811   for (unsigned int i = 0; i<_L1Taus.size();i++) {
00812     for (unsigned int j = 0; j<PFMatchedGenTauHads.size();j++) {
00813       double deltaR = ROOT::Math::VectorUtil::DeltaR(_L1Taus[i],PFMatchedGenTauHads[j]);
00814       if (deltaR < _L1MCTauMinDeltaR) {
00815         // For event efficiencies       
00816         if (singleMatch) {
00817           doubleMatch = true;
00818           iDouble = i;
00819         }
00820         singleMatch = true;
00821         if (singleMatch && !doubleMatch)
00822           iSingle = i;
00823         
00824         // Numerators for PF-MC matching efficiencies
00825         h_L1MCPFMatchedTauEt->Fill(PFMatchedGenTauHads[j].Et());
00826         h_EffMCPFTauEt->Fill(PFMatchedGenTauHads[j].Et());
00827         h_L1MCPFMatchedTauEta->Fill(PFMatchedGenTauHads[j].Eta());
00828         h_EffMCPFTauEta->Fill(PFMatchedGenTauHads[j].Eta());
00829         h_L1MCPFMatchedTauPhi->Fill(PFMatchedGenTauHads[j].Phi());
00830         h_EffMCPFTauPhi->Fill(PFMatchedGenTauHads[j].Phi());
00831       }
00832       //break;
00833     }
00834   }
00835 
00836   if (singleMatch && iSingle>=0) {
00837     h_L1SingleTauEffPFMCMatchEt->Fill(_L1Taus[iSingle].Et());
00838     if (_L1Taus[iSingle].Et()>=_SingleTauThreshold)
00839       singleTauPassed = true;
00840 
00841     /*
00842     // Ask for only one L1Tau to be matched with PFTau!!!
00843     if (_L1Taus.size()>=2) {
00844       h_L1DoubleTauEffPFMCMatchEt->Fill(_L1Taus[1].Et());
00845       if (_L1Taus[1].Et()>=_DoubleTauThreshold)
00846         doubleTauPassed = true;
00847     }
00848     */
00849     
00850     if (_L1Taus[iSingle].Et()>=_SingleTauMETThresholds[0] &&
00851         _L1METs[0].Et()>=_SingleTauMETThresholds[1])
00852       singleTauMETPassed = true;
00853 
00854     if (_L1Taus[iSingle].Et()>=_MuTauThresholds[1]) {
00855       for (int i=0;i<(int)_L1Muons.size();i++) {
00856         if (_L1Muons[i].Pt()>=_MuTauThresholds[0]) {
00857           //if ( _L1MuQuals[0]==4 || _L1MuQuals[0]==5 || _L1MuQuals[0]==6 || _L1MuQuals[0]==7 ) {
00858           //if ( _L1MuQuals[0]==3 || _L1MuQuals[0]==5 || _L1MuQuals[0]==6 || _L1MuQuals[0]==7 ) {
00859           if ( _L1MuQuals[i]>=0) {
00860             for (int j=0;j<(int)_GenTauMuons.size();j++) {
00861               double deltaR = ROOT::Math::VectorUtil::DeltaR(_GenTauMuons[j],_L1Muons[i]);
00862               if (deltaR<0.3) {
00863                 muTauPassed = true;
00864               }
00865             }
00866           }
00867         }
00868       }
00869     }
00870     for (int j=0;j<(int)_L1IsoEgammas.size();j++) {
00871       if (_L1Taus[iSingle].Et()>=_IsoEgTauThresholds[1] &&
00872           _L1IsoEgammas[j].Et()>=_IsoEgTauThresholds[0]) {
00873         double deltaPhi = ROOT::Math::VectorUtil::DeltaPhi(_L1Taus[iSingle],_L1IsoEgammas[j]);
00874         double deltaEta = std::abs(_L1Taus[iSingle].Eta()-_L1IsoEgammas[j].Eta());
00875         // Non-collinearity check
00876         if (deltaPhi>0.348 && deltaEta>0.348) {
00877           for (int k=0;k<(int)_GenTauElecs.size();k++) {
00878             double deltaR = ROOT::Math::VectorUtil::DeltaR(_GenTauElecs[k],_L1IsoEgammas[j]);
00879             if (deltaR<0.3) {
00880               isoEgTauPassed = true;
00881               break;
00882             }
00883           }
00884         }
00885       }
00886     }
00887   }
00888   if (doubleMatch && iDouble>=0) {
00889     h_L1DoubleTauEffPFMCMatchEt->Fill(_L1Taus[iDouble].Et());
00890     if (_L1Taus[iDouble].Et()>=_DoubleTauThreshold)
00891       doubleTauPassed = true;
00892 
00893     for (int j=0;j<(int)_L1IsoEgammas.size();j++) {
00894       if (_L1Taus[iDouble].Et()>=_IsoEgTauThresholds[1] &&
00895           _L1IsoEgammas[j].Et()>=_IsoEgTauThresholds[0]) {
00896         double deltaPhi = ROOT::Math::VectorUtil::DeltaPhi(_L1Taus[iDouble],_L1IsoEgammas[j]);
00897         double deltaEta = std::abs(_L1Taus[iDouble].Eta()-_L1IsoEgammas[j].Eta());
00898         // Non-collinearity check
00899         if (deltaPhi>0.348 && deltaEta>0.348) {
00900           for (int k=0;k<(int)_GenTauElecs.size();k++) {
00901             double deltaR = ROOT::Math::VectorUtil::DeltaR(_GenTauElecs[k],_L1IsoEgammas[j]);
00902             if (deltaR<0.3) {
00903               isoEgTauPassed = true;
00904               break;
00905             }
00906           }
00907         }
00908       }
00909     }
00910   }
00911   
00912   int nfidMCGenTauMuon = 0;
00913   int nfidMCGenTauElec = 0;
00914   for (int i = 0; i<(int)_GenTauMuons.size();i++) {
00915     if (_GenTauMuons[i].Et()>=_MCTauHadMinEt && _GenTauMuons[i].Eta()<=_MCTauHadMaxAbsEta ) {
00916       nfidMCGenTauMuon++;
00917     }
00918   }
00919   for (int i = 0; i<(int)_GenTauElecs.size();i++) {
00920     if (_GenTauElecs[i].Et()>=_MCTauHadMinEt && _GenTauElecs[i].Eta()<=_MCTauHadMaxAbsEta ) {
00921       nfidMCGenTauElec++;
00922     }
00923   }
00924  
00925   if (nPFMatchGenTauHad>=1) _nEventsPFMatchGenTauHad++; 
00926   if (nPFMatchGenTauHad>=2) _nEventsPFMatchDoubleGenTauHads++; 
00927 
00928   if (nPFMatchGenTauHad>=1 && nfidMCGenTauMuon>=1) _nEventsPFMatchGenTauMuonTauHad++; 
00929   if (nPFMatchGenTauHad>=1 && nfidMCGenTauElec>=1) _nEventsPFMatchGenTauElecTauHad++; 
00930 
00931   if (singleTauPassed) _nEventsL1SingleTauPassedPFMCMatched++;
00932   if (doubleTauPassed) _nEventsL1DoubleTauPassedPFMCMatched++;
00933   if (singleTauMETPassed) _nEventsL1SingleTauMETPassedPFMCMatched++;
00934   if (muTauPassed) _nEventsL1MuonTauPassedPFMCMatched++;
00935   if (isoEgTauPassed) _nEventsL1IsoEgTauPassedPFMCMatched++;
00936 
00937 }
00938 
00939 void
00940 L1TauAnalyzer::convertToIntegratedEff(TH1* histo, double nGenerated)
00941 {
00942   // Convert the histogram to efficiency
00943   // Assuming that the histogram is incremented with weight=1 for each event
00944   // this function integrates the histogram contents above every bin and stores it
00945   // in that bin.  The result is plot of integral rate versus threshold plot.
00946   int nbins = histo->GetNbinsX();
00947   double integral = histo->GetBinContent(nbins+1);  // Initialize to overflow
00948   if (nGenerated<=0)  {
00949     std::cerr << "***** L1TauAnalyzer::convertToIntegratedEff() Error: nGenerated = " << nGenerated << std::endl;
00950     nGenerated=1;
00951   }
00952   for(int i = nbins; i >= 1; i--)
00953     {
00954       double thisBin = histo->GetBinContent(i);
00955       integral += thisBin;
00956       double integralEff;
00957       double integralError;
00958       integralEff = (integral / nGenerated);
00959       histo->SetBinContent(i, integralEff);
00960       // error
00961       integralError = (sqrt(integral) / nGenerated);
00962       histo->SetBinError(i, integralError);
00963     }
00964 }
00965 
00966 void
00967 L1TauAnalyzer::printTrigReport() {
00968   using namespace std;
00969    
00970   cout<<"****************************************"<<endl;    
00971   cout<<"* L1extra Efficiency Report"<<endl;    
00972   cout<<"****************************************"<<endl;    
00973   cout<<"Total number of Events: "<<_nEvents<<endl;    
00974   cout<<"---------------------------------------------------------------------------------------------"<<endl;
00975   cout<<"                 #PassL1  GlobEff  GlEff/BR(fid.)  MCMatchEff  PFMCMatchEff  BR(fid.)    BR"<<endl;    
00976   cout<<"---------------------------------------------------------------------------------------------"<<endl;
00977   cout<<"  SingleTau ("<<_SingleTauThreshold<<"): "
00978       <<setw(6)<<_nEventsL1SingleTauPassed<<"  "
00979       <<setprecision(2)<<setw(7)<<(double)_nEventsL1SingleTauPassed/(double)_nEvents<<"  "
00980       <<setprecision(2)<<setw(13)<<(double)_nEventsL1SingleTauPassed/(double)_nfidEventsGenTauHad<<"  "
00981       <<setprecision(2)<<setw(10)<<(double)_nEventsL1SingleTauPassedMCMatched/(double)_nfidEventsGenTauHad<<"  "
00982       <<setprecision(2)<<setw(12)<<(double)_nEventsL1SingleTauPassedPFMCMatched/(double)_nEventsPFMatchGenTauHad<<"  "
00983       <<setprecision(2)<<setw(8)<<(double)_nfidEventsGenTauHad/(double)_nEvents<<"  "
00984       <<setprecision(2)<<setw(7)<<(double)_nEventsGenTauHad/(double)_nEvents<<"  "
00985       <<endl;
00986   cout<<"  DoubleTau ("<<_DoubleTauThreshold<<"): "
00987       <<setw(6)<<_nEventsL1DoubleTauPassed<<"  "
00988       <<setprecision(2)<<setw(7)<<(double)_nEventsL1DoubleTauPassed/(double)_nEvents<<"  "
00989       <<setprecision(2)<<setw(13)<<(double)_nEventsL1DoubleTauPassed/(double)_nfidEventsDoubleGenTauHads<<"  "
00990       <<setprecision(2)<<setw(10)<<(double)_nEventsL1DoubleTauPassedMCMatched/(double)_nfidEventsDoubleGenTauHads<<"  "
00991       <<setprecision(2)<<setw(12)<<(double)_nEventsL1DoubleTauPassedPFMCMatched/(double)_nEventsPFMatchDoubleGenTauHads<<"  "
00992       <<setprecision(2)<<setw(8)<<(double)_nfidEventsDoubleGenTauHads/(double)_nEvents<<"  "
00993       <<setprecision(2)<<setw(7)<<(double)_nEventsDoubleGenTauHads/(double)_nEvents<<"  "
00994       <<endl;
00995   cout<<"  TauMET ("<<_SingleTauMETThresholds[0]<<","<<_SingleTauMETThresholds[1]<<"): "
00996       <<setw(6)<<_nEventsL1SingleTauMETPassed<<"  "
00997       <<setprecision(2)<<setw(7)<<(double)_nEventsL1SingleTauMETPassed/(double)_nEvents<<"  "
00998       <<setprecision(2)<<setw(13)<<(double)_nEventsL1SingleTauMETPassed/(double)_nfidEventsGenTauHad<<"  "
00999       <<setprecision(2)<<setw(10)<<(double)_nEventsL1SingleTauMETPassedMCMatched/(double)_nfidEventsGenTauHad<<"  "
01000       <<setprecision(2)<<setw(12)<<(double)_nEventsL1SingleTauMETPassedPFMCMatched/(double)_nEventsPFMatchGenTauHad<<"  "
01001       <<setprecision(2)<<setw(8)<<(double)_nfidEventsGenTauHad/(double)_nEvents<<"  "
01002       <<setprecision(2)<<setw(7)<<(double)_nEventsGenTauHad/(double)_nEvents<<"  "
01003       <<endl;
01004   cout<<"    MuTau ("<<_MuTauThresholds[0]<<","<<_MuTauThresholds[1]<<"): "
01005       <<setw(6)<<_nEventsL1MuonTauPassed<<"  "
01006       <<setprecision(2)<<setw(7)<<(double)_nEventsL1MuonTauPassed/(double)_nEvents<<"  "
01007       <<setprecision(2)<<setw(13)<<(double)_nEventsL1MuonTauPassed/(double)_nfidEventsGenTauMuonTauHad<<"  "
01008       <<setprecision(2)<<setw(10)<<(double)_nEventsL1MuonTauPassedMCMatched/(double)_nfidEventsGenTauMuonTauHad<<"  "
01009       <<setprecision(2)<<setw(12)<<(double)_nEventsL1MuonTauPassedPFMCMatched/(double)_nEventsPFMatchGenTauMuonTauHad<<"  "
01010       <<setprecision(2)<<setw(8)<<(double)_nfidEventsGenTauMuonTauHad/(double)_nEvents<<"  "
01011       <<setprecision(2)<<setw(7)<<(double)_nEventsGenTauMuonTauHad/(double)_nEvents<<"  "
01012       <<endl;
01013   cout<<"IsoEgTau ("<<_IsoEgTauThresholds[0]<<","<<_IsoEgTauThresholds[1]<<"): "
01014       <<setw(6)<<_nEventsL1IsoEgTauPassed<<"  "
01015       <<setprecision(2)<<setw(7)<<(double)_nEventsL1IsoEgTauPassed/(double)_nEvents<<"  "
01016       <<setprecision(2)<<setw(13)<<(double)_nEventsL1IsoEgTauPassed/(double)_nfidEventsGenTauElecTauHad<<"  "
01017       <<setprecision(2)<<setw(10)<<(double)_nEventsL1IsoEgTauPassedMCMatched/(double)_nfidEventsGenTauElecTauHad<<"  "
01018       <<setprecision(2)<<setw(12)<<(double)_nEventsL1IsoEgTauPassedPFMCMatched/(double)_nEventsPFMatchGenTauElecTauHad<<"  "
01019       <<setprecision(2)<<setw(8)<<(double)_nfidEventsGenTauElecTauHad/(double)_nEvents<<"  "
01020       <<setprecision(2)<<setw(7)<<(double)_nEventsGenTauElecTauHad/(double)_nEvents<<"  "
01021       <<endl;
01022   
01023   cout<<endl;
01024 
01025   cout<<"****************************************"<<endl;    
01026   cout<<"* L1 GT Efficiency Report"<<endl;    
01027   cout<<"****************************************"<<endl;    
01028   cout<<"Total number of Events: "<<_nEvents<<endl;    
01029   cout<<"---------------------------------------------------------------------------------------"<<endl;
01030   cout<<"                       #PassL1  GlobEff  GlobEff/BR(fid.)  BR(fid.)    BR"<<endl;    
01031   cout<<"---------------------------------------------------------------------------------------"<<endl;
01032   cout<<setw(20)<<_L1SingleTauName<<": "
01033       <<setw(7)<<_nEventsL1GTSingleTauPassed<<"  "
01034       <<setprecision(2)<<setw(7)<<setw(7)<<(double)_nEventsL1GTSingleTauPassed/(double)_nEvents<<"  "
01035       <<setprecision(2)<<setw(16)<<(double)_nEventsL1GTSingleTauPassed/(double)_nfidEventsGenTauHad<<"  "
01036       <<setprecision(2)<<setw(8)<<(double)_nfidEventsGenTauHad/(double)_nEvents<<"  "
01037       <<setprecision(2)<<setw(7)<<(double)_nEventsGenTauHad/(double)_nEvents<<"  "
01038       <<endl;
01039   cout<<setw(20)<<_L1DoubleTauName<<": "
01040       <<setw(7)<<_nEventsL1GTDoubleTauPassed<<"  "
01041       <<setprecision(2)<<setw(7)<<(double)_nEventsL1GTDoubleTauPassed/(double)_nEvents<<"  "
01042       <<setprecision(2)<<setw(16)<<(double)_nEventsL1GTDoubleTauPassed/(double)_nfidEventsDoubleGenTauHads<<"  "
01043       <<setprecision(2)<<setw(8)<<(double)_nfidEventsDoubleGenTauHads/(double)_nEvents<<"  "
01044       <<setprecision(2)<<setw(7)<<(double)_nEventsDoubleGenTauHads/(double)_nEvents<<"  "
01045       <<endl;
01046   cout<<setw(20)<<_L1TauMETName<<": "
01047       <<setw(7)<<_nEventsL1GTSingleTauMETPassed<<"  "
01048       <<setprecision(2)<<setw(7)<<(double)_nEventsL1GTSingleTauMETPassed/(double)_nEvents<<"  "
01049       <<setprecision(2)<<setw(16)<<(double)_nEventsL1GTSingleTauMETPassed/(double)_nfidEventsGenTauHad<<"  "
01050       <<setprecision(2)<<setw(8)<<(double)_nfidEventsGenTauHad/(double)_nEvents<<"  "
01051       <<setprecision(2)<<setw(7)<<(double)_nEventsGenTauHad/(double)_nEvents<<"  "
01052       <<endl;
01053   cout<<setw(20)<<_L1MuonTauName<<": "
01054       <<setw(7)<<_nEventsL1GTMuonTauPassed<<"  "
01055       <<setprecision(2)<<setw(7)<<(double)_nEventsL1GTMuonTauPassed/(double)_nEvents<<"  "
01056       <<setprecision(2)<<setw(16)<<(double)_nEventsL1GTMuonTauPassed/(double)_nfidEventsGenTauMuonTauHad<<"  "
01057       <<setprecision(2)<<setw(8)<<(double)_nfidEventsGenTauMuonTauHad/(double)_nEvents<<"  "
01058       <<setprecision(2)<<setw(7)<<(double)_nEventsGenTauMuonTauHad/(double)_nEvents<<"  "
01059       <<endl;
01060   cout<<setw(20)<<_L1IsoEgTauName<<": "
01061       <<setw(7)<<_nEventsL1GTIsoEgTauPassed<<"  "
01062       <<setprecision(2)<<setw(7)<<(double)_nEventsL1GTIsoEgTauPassed/(double)_nEvents<<"  "
01063       <<setprecision(2)<<setw(16)<<(double)_nEventsL1GTIsoEgTauPassed/(double)_nfidEventsGenTauElecTauHad<<"  "
01064       <<setprecision(2)<<setw(8)<<(double)_nfidEventsGenTauElecTauHad/(double)_nEvents<<"  "
01065       <<setprecision(2)<<setw(7)<<(double)_nEventsGenTauElecTauHad/(double)_nEvents<<"  "
01066       <<endl;
01067   
01068   cout<<endl;
01069 
01070 }
01071 
01072 //define this as a plug-in
01073 //DEFINE_FWK_MODULE(L1TauAnalyzer);