From 21c6554dfb101f9cf848b8ad8c5fbaf940375603 Mon Sep 17 00:00:00 2001 From: Olivier Davignon Date: Tue, 5 Dec 2017 18:08:27 +0100 Subject: [PATCH] fix for Chiara --- .../plugins/Ntuplizer_noTagAndProbe.cc | 146 +++++++++++------- .../python/DataAnalysis_noTagAndProbe_cff.py | 7 +- .../test/test_data_noTagAndProbe.py | 5 +- 3 files changed, 93 insertions(+), 65 deletions(-) diff --git a/TauTagAndProbe/plugins/Ntuplizer_noTagAndProbe.cc b/TauTagAndProbe/plugins/Ntuplizer_noTagAndProbe.cc index 797d73c..fe92981 100644 --- a/TauTagAndProbe/plugins/Ntuplizer_noTagAndProbe.cc +++ b/TauTagAndProbe/plugins/Ntuplizer_noTagAndProbe.cc @@ -76,7 +76,8 @@ class Ntuplizer_noTagAndProbe : public edm::EDAnalyzer { virtual void endRun(edm::Run const&, edm::EventSetup const&); void Initialize(); bool hasFilters(const pat::TriggerObjectStandAlone& obj , const std::vector& filtersToLookFor); - int FillJet(const edm::View *jets, const edm::Event& event, JetCorrectionUncertainty* jecUnc); + int FillJet(const edm::View *jets, const edm::Event& event); + // int FillJet(const edm::View *jets, const edm::Event& event, JetCorrectionUncertainty* jecUnc); TTree *_tree; TTree *_triggerNamesTree; @@ -211,8 +212,8 @@ Ntuplizer_noTagAndProbe::Ntuplizer_noTagAndProbe(const edm::ParameterSet& iConfi _triggerBits (consumes (iConfig.getParameter("triggerResultsLabel"))), _L1TauTag (consumes (iConfig.getParameter("L1Tau"))), _L1EmuTauTag (consumes (iConfig.getParameter("L1EmuTau"))), -_JetTag (consumes> (iConfig.getParameter("jetCollection"))), -_l1tJetTag (consumes> (iConfig.getParameter("l1tJetCollection"))), + _JetTag (consumes> (iConfig.getParameter("jetCollection"))), + _l1tJetTag (consumes> (iConfig.getParameter("l1tJetCollection"))), _VtxTag (consumes> (iConfig.getParameter("Vertexes"))) { this -> _treeName = iConfig.getParameter("treeName"); @@ -240,6 +241,7 @@ _l1tJetTag (consumes> (iConfig.getPa this -> Initialize(); + return; } @@ -248,6 +250,7 @@ Ntuplizer_noTagAndProbe::~Ntuplizer_noTagAndProbe() void Ntuplizer_noTagAndProbe::beginRun(edm::Run const& iRun, edm::EventSetup const& iSetup) { + Bool_t changedConfig = false; if(!this -> _hltConfig.init(iRun, iSetup, this -> _processName.process(), changedConfig)){ @@ -276,6 +279,7 @@ void Ntuplizer_noTagAndProbe::beginRun(edm::Run const& iRun, edm::EventSetup con } void Ntuplizer_noTagAndProbe::Initialize() { + this -> _indexevents = 0; this -> _runNumber = 0; this -> _lumi = 0; @@ -490,52 +494,59 @@ void Ntuplizer_noTagAndProbe::analyze(const edm::Event& iEvent, const edm::Event //! TagAndProbe on HLT taus const edm::TriggerNames &names = iEvent.triggerNames(*triggerBits); - const pat::TauRef tau = (*tauHandle)[0] ; - this -> _tauTriggerBitSet.reset(); + if(tauHandle->size()>0) + { + const pat::TauRef tau = (*tauHandle)[0]; + this -> _tauTriggerBitSet.reset(); - for (pat::TriggerObjectStandAlone obj : *triggerObjects) - { - const float dR = deltaR (*tau, obj); - if ( dR < 0.5) - { - this -> _isMatched = true; - this -> _hasTriggerTauType = obj.hasTriggerObjectType(trigger::TriggerTau); - this -> _hasTriggerMuonType = obj.hasTriggerObjectType(trigger::TriggerMuon); - - obj.unpackPathNames(names); - const edm::TriggerNames::Strings& triggerNames = names.triggerNames(); - //Looking for the path - unsigned int x = 0; - bool foundTrigger = false; - for (const tParameterSet& parameter : this -> _parameters) - { - if ((parameter.hltPathIndex >= 0)&&(obj.hasPathName(triggerNames[parameter.hltPathIndex], true, false))) - { - foundTrigger = true; - //Path found, now looking for the label 1, if present in the parameter set - //std::cout << "==== FOUND PATH " << triggerNames[parameter.hltPathIndex] << " ====" << std::endl; - //Retrieving filter list for the event - const std::vector& filters = (parameter.leg1 == 15)? (parameter.hltFilters1):(parameter.hltFilters2); - if (this -> hasFilters(obj, filters)) - { - //std::cout << "#### FOUND TAU WITH HLT PATH " << x << " ####" << std::endl; - this -> _hltPt = obj.pt(); - this -> _hltEta = obj.eta(); - this -> _hltPhi = obj.phi(); - this -> _tauTriggerBitSet[x] = true; - //std::cout << this -> _tauTriggerBitSet.to_string() << std::endl; - } - } - x++; - } - if (foundTrigger) this -> _foundJet++; - } + for (pat::TriggerObjectStandAlone obj : *triggerObjects) + { + float dR = 999.; + if(tauHandle->size()>0) + { + const pat::TauRef tau = (*tauHandle)[0]; + deltaR (*tau, obj); + } + if ( dR < 0.5) + { + this -> _isMatched = true; + this -> _hasTriggerTauType = obj.hasTriggerObjectType(trigger::TriggerTau); + this -> _hasTriggerMuonType = obj.hasTriggerObjectType(trigger::TriggerMuon); + + obj.unpackPathNames(names); + const edm::TriggerNames::Strings& triggerNames = names.triggerNames(); + //Looking for the path + unsigned int x = 0; + bool foundTrigger = false; + for (const tParameterSet& parameter : this -> _parameters) + { + if ((parameter.hltPathIndex >= 0)&&(obj.hasPathName(triggerNames[parameter.hltPathIndex], true, false))) + { + foundTrigger = true; + //Path found, now looking for the label 1, if present in the parameter set + //std::cout << "==== FOUND PATH " << triggerNames[parameter.hltPathIndex] << " ====" << std::endl; + //Retrieving filter list for the event + const std::vector& filters = (parameter.leg1 == 15)? (parameter.hltFilters1):(parameter.hltFilters2); + if (this -> hasFilters(obj, filters)) + { + //std::cout << "#### FOUND TAU WITH HLT PATH " << x << " ####" << std::endl; + this -> _hltPt = obj.pt(); + this -> _hltEta = obj.eta(); + this -> _hltPhi = obj.phi(); + this -> _tauTriggerBitSet[x] = true; + //std::cout << this -> _tauTriggerBitSet.to_string() << std::endl; + } + } + x++; + } + if (foundTrigger) this -> _foundJet++; + } + } } - //! TagAndProbe on L1T taus for(BXVector::const_iterator jet = l1tJetHandle -> begin(0); jet != l1tJetHandle -> end(0) ; jet++) @@ -563,7 +574,12 @@ void Ntuplizer_noTagAndProbe::analyze(const edm::Event& iEvent, const edm::Event for (l1t::TauBxCollection::const_iterator bx0TauIt = L1TauHandle->begin(0); bx0TauIt != L1TauHandle->end(0) ; bx0TauIt++) { - const float dR = deltaR(*tau, *bx0TauIt); + float dR = 999.; + if(tauHandle->size()>0) + { + const pat::TauRef tau = (*tauHandle)[0]; + deltaR(*tau, *bx0TauIt); + } const l1t::Tau& l1tTau = *bx0TauIt; //dump check @@ -590,7 +606,12 @@ void Ntuplizer_noTagAndProbe::analyze(const edm::Event& iEvent, const edm::Event for (l1t::TauBxCollection::const_iterator bx0EmuTauIt = L1EmuTauHandle->begin(0); bx0EmuTauIt != L1EmuTauHandle->end(0) ; bx0EmuTauIt++) { - const float dR = deltaR(*tau, *bx0EmuTauIt); + float dR = 999.; + if(tauHandle->size()>0) + { + const pat::TauRef tau = (*tauHandle)[0]; + dR = deltaR(*tau, *bx0EmuTauIt); + } const l1t::Tau& l1tEmuTau = *bx0EmuTauIt; cout<<"Emul Tau, pT = "<* jets = jetHandle.product(); - edm::ESHandle JetCorParColl; - eSetup.get().get("AK4PFchs",JetCorParColl); - JetCorrectorParameters const & JetCorPar = (*JetCorParColl)["Uncertainty"]; - JetCorrectionUncertainty jecUnc (JetCorPar); - _numberOfJets = FillJet(jets,iEvent, &jecUnc); - + + //edm::ESHandle JetCorParColl; + //eSetup.get().get("AK4PFchs",JetCorParColl); + //JetCorrectorParameters const & JetCorPar = (*JetCorParColl)["Uncertainty"]; + //JetCorrectionUncertainty jecUnc (JetCorPar); + _numberOfJets = FillJet(jets,iEvent);//, &jecUnc); this -> _tree -> Fill(); @@ -664,7 +690,7 @@ bool Ntuplizer_noTagAndProbe::hasFilters(const pat::TriggerObjectStandAlone& ob return true; } -int Ntuplizer_noTagAndProbe::FillJet(const edm::View *jets, const edm::Event& event, JetCorrectionUncertainty* jecUnc){ +int Ntuplizer_noTagAndProbe::FillJet(const edm::View *jets, const edm::Event& event){//, JetCorrectionUncertainty* jecUnc){ int nJets=0; vector > softLeptInJet; // pt, idx for(edm::View::const_iterator ijet = jets->begin(); ijet!=jets->end();++ijet){ @@ -802,9 +828,9 @@ int Ntuplizer_noTagAndProbe::FillJet(const edm::View *jets, const edm: //cout << " --> sum pt, eta, phi: " << vSum.Pt() << " " << vSum.Eta() << " " << vSum.Phi() << endl; //if (abs(ijet->hadronFlavour()) == 5 ) cout << " ------------ THIS WAS A B JET ------------" << endl; //cout << "RAW pt: " << jetRawPt << " | " << jetRawPt2 << " --> " << vSum.Pt() << endl; - jecUnc->setJetEta(ijet->eta()); - jecUnc->setJetPt(ijet->pt()); // here you must use the CORRECTED jet pt - _jets_jecUnc.push_back(jecUnc->getUncertainty(true)); + //jecUnc->setJetEta(ijet->eta()); + //jecUnc->setJetPt(ijet->pt()); // here you must use the CORRECTED jet pt + //_jets_jecUnc.push_back(jecUnc->getUncertainty(true)); } return nJets; diff --git a/TauTagAndProbe/python/DataAnalysis_noTagAndProbe_cff.py b/TauTagAndProbe/python/DataAnalysis_noTagAndProbe_cff.py index bf14bcf..8db87e9 100644 --- a/TauTagAndProbe/python/DataAnalysis_noTagAndProbe_cff.py +++ b/TauTagAndProbe/python/DataAnalysis_noTagAndProbe_cff.py @@ -59,11 +59,12 @@ L2CaloJet_ForIsoPix_IsoCollection = cms.InputTag("hltL2TauPixelIsoTagProducer", "", "TEST") ) -TAndPseq = cms.Sequence( - goodTaus +#TAndPseq = cms.Sequence( +# goodTaus # genMatchedTaus -) +#) NtupleSeq = cms.Sequence( + goodTaus + Ntuplizer_noTagAndProbe ) diff --git a/TauTagAndProbe/test/test_data_noTagAndProbe.py b/TauTagAndProbe/test/test_data_noTagAndProbe.py index 6a300c8..28348c4 100644 --- a/TauTagAndProbe/test/test_data_noTagAndProbe.py +++ b/TauTagAndProbe/test/test_data_noTagAndProbe.py @@ -33,7 +33,8 @@ process.load('TauTagAndProbe.TauTagAndProbe.DataAnalysis_noTagAndProbe_cff') process.source = cms.Source("PoolSource", fileNames = cms.untracked.vstring( - '/store/data/Run2017C/SingleMuon/MINIAOD/12Sep2017-v1/00000/001BA513-7DBB-E711-B839-7CD30ACE1762.root' + '/store/data/Run2017F/SingleMuon/MINIAOD/PromptReco-v1/000/306/456/00000/2EA49EC5-EAC7-E711-A9C5-FA163E83AE5D.root' + #'/store/data/Run2017C/SingleMuon/MINIAOD/12Sep2017-v1/00000/001BA513-7DBB-E711-B839-7CD30ACE1762.root' #'/store/data/Run2017A/SingleMuon/MINIAOD/PromptReco-v2/000/296/168/00000/084C505D-784C-E711-8140-02163E019DA4.root' #'/store/data/Run2016H/SingleMuon/MINIAOD/PromptReco-v2/000/282/092/00000/DE499C8E-1B8B-E611-8C93-02163E014207.root' #'/store/data/Run2016H/SingleMuon/MINIAOD/PromptReco-v2/000/282/092/00000/ACA10D13-2D8B-E611-820E-FA163E8FD709.root' @@ -102,7 +103,7 @@ ) process.p = cms.Path( - process.TAndPseq + + #process.TAndPseq + process.NtupleSeq )