#include <TopQuarkAnalysis/TopJetCombination/plugins/TtSemiLepJetCombMVAComputer.h>
Public Member Functions | |
TtSemiLepJetCombMVAComputer (const edm::ParameterSet &) | |
~TtSemiLepJetCombMVAComputer () | |
Private Member Functions | |
virtual void | beginJob (const edm::EventSetup &) |
virtual void | endJob () |
virtual void | produce (edm::Event &evt, const edm::EventSetup &setup) |
Private Attributes | |
edm::InputTag | jets_ |
edm::InputTag | leptons_ |
int | maxNComb_ |
int | maxNJets_ |
edm::InputTag | mets_ |
PhysicsTools::MVAComputerCache | mvaComputer |
Definition at line 23 of file TtSemiLepJetCombMVAComputer.h.
TtSemiLepJetCombMVAComputer::TtSemiLepJetCombMVAComputer | ( | const edm::ParameterSet & | cfg | ) | [explicit] |
Definition at line 11 of file TtSemiLepJetCombMVAComputer.cc.
00011 : 00012 leptons_ (cfg.getParameter<edm::InputTag>("leptons")), 00013 jets_ (cfg.getParameter<edm::InputTag>("jets")), 00014 mets_ (cfg.getParameter<edm::InputTag>("mets")), 00015 maxNJets_(cfg.getParameter<int>("maxNJets")), 00016 maxNComb_(cfg.getParameter<int>("maxNComb")) 00017 { 00018 produces< std::vector<std::vector<int> > >(); 00019 produces< std::vector<double> >("Discriminators"); 00020 produces< TString >("Method"); 00021 }
TtSemiLepJetCombMVAComputer::~TtSemiLepJetCombMVAComputer | ( | ) |
void TtSemiLepJetCombMVAComputer::beginJob | ( | const edm::EventSetup & | ) | [private, virtual] |
void TtSemiLepJetCombMVAComputer::produce | ( | edm::Event & | evt, | |
const edm::EventSetup & | setup | |||
) | [private, virtual] |
Implements edm::EDProducer.
Definition at line 28 of file TtSemiLepJetCombMVAComputer.cc.
References evaluateTtSemiLepJetComb(), edm::Event::getByLabel(), i, int, pfTauBenchmarkGeneric_cfi::jets, jets_, EgammaValidation_Zee_cff::leptons, leptons_, TtSemiLepEvtPartons::LightQ, TtSemiLepEvtPartons::LightQBar, maxNComb_, maxNJets_, CaloMET_cfi::met, mets_, mvaComputer, stdcomb::next_combination(), edm::Event::put(), PhysicsTools::MVAComputerCache::update(), and values.
00029 { 00030 std::auto_ptr< std::vector<std::vector<int> > >pOut (new std::vector<std::vector<int> >); 00031 std::auto_ptr< std::vector<double> >pOutDisc(new std::vector<double>); 00032 std::auto_ptr< TString >pOutMeth(new TString); 00033 00034 mvaComputer.update<TtSemiLepJetCombMVARcd>(setup, "ttSemiLepJetCombMVA"); 00035 00036 // read name of the processor that provides the MVA discriminator 00037 // (to be used as meta information) 00038 edm::ESHandle<PhysicsTools::Calibration::MVAComputerContainer> calibContainer; 00039 setup.get<TtSemiLepJetCombMVARcd>().get( calibContainer ); 00040 std::vector<PhysicsTools::Calibration::VarProcessor*> processors 00041 = (calibContainer->find("ttSemiLepJetCombMVA")).getProcessors(); 00042 *pOutMeth = ( processors[ processors.size()-3 ] )->getInstanceName(); 00043 evt.put(pOutMeth, "Method"); 00044 00045 // get lepton, jets and mets 00046 edm::Handle< edm::View<reco::RecoCandidate> > leptons; 00047 evt.getByLabel(leptons_, leptons); 00048 00049 edm::Handle< std::vector<pat::Jet> > jets; 00050 evt.getByLabel(jets_, jets); 00051 00052 edm::Handle< std::vector<pat::MET> > mets; 00053 evt.getByLabel(mets_, mets); 00054 00055 unsigned int nPartons = 4; 00056 00057 // skip events with no appropriate lepton candidate, 00058 // empty METs vector or less jets than partons 00059 if( leptons->empty() || mets->empty() || jets->size() < nPartons ) { 00060 std::vector<int> invalidCombi; 00061 for(unsigned int i = 0; i < nPartons; ++i) 00062 invalidCombi.push_back( -1 ); 00063 pOut->push_back( invalidCombi ); 00064 evt.put(pOut); 00065 pOutDisc->push_back( 0. ); 00066 evt.put(pOutDisc, "Discriminators"); 00067 return; 00068 } 00069 00070 const math::XYZTLorentzVector lepton = leptons->begin()->p4(); 00071 00072 const pat::MET *met = &(*mets)[0]; 00073 00074 // analyze jet combinations 00075 std::vector<int> jetIndices; 00076 for(unsigned int i=0; i<jets->size(); ++i){ 00077 if(maxNJets_ >= (int) nPartons && maxNJets_ == (int) i) break; 00078 jetIndices.push_back(i); 00079 } 00080 00081 std::vector<int> combi; 00082 for(unsigned int i=0; i<nPartons; ++i) 00083 combi.push_back(i); 00084 00085 typedef std::pair<double, std::vector<int> > discCombPair; 00086 std::list<discCombPair> discCombList; 00087 00088 do{ 00089 for(int cnt = 0; cnt < TMath::Factorial( combi.size() ); ++cnt){ 00090 // take into account indistinguishability of the two jets from the hadr. W decay, 00091 // reduces combinatorics by a factor of 2 00092 if(combi[TtSemiLepEvtPartons::LightQ] < combi[TtSemiLepEvtPartons::LightQBar]) { 00093 00094 TtSemiLepJetComb jetComb(*jets, combi, lepton, *met); 00095 00096 // feed MVA input variables into a ValueList 00097 PhysicsTools::Variable::ValueList values; 00098 evaluateTtSemiLepJetComb(values, jetComb); 00099 00100 // get discriminator from the MVAComputer 00101 double discrim = mvaComputer->eval( values ); 00102 00103 discCombList.push_back( std::make_pair(discrim, combi) ); 00104 00105 } 00106 next_permutation( combi.begin() , combi.end() ); 00107 } 00108 } 00109 while(stdcomb::next_combination( jetIndices.begin(), jetIndices.end(), combi.begin(), combi.end() )); 00110 00111 // sort results w.r.t. discriminator values 00112 discCombList.sort(); 00113 00114 // write result into the event 00115 // (starting with the JetComb having the highest discriminator value -> reverse iterator) 00116 unsigned int iDiscComb = 0; 00117 typedef std::list<discCombPair>::reverse_iterator discCombIterator; 00118 for(discCombIterator discCombPair = discCombList.rbegin(); discCombPair != discCombList.rend(); ++discCombPair) { 00119 if(maxNComb_ >= 1 && iDiscComb == (unsigned int) maxNComb_) break; 00120 pOut ->push_back( discCombPair->second ); 00121 pOutDisc->push_back( discCombPair->first ); 00122 iDiscComb++; 00123 } 00124 evt.put(pOut); 00125 evt.put(pOutDisc, "Discriminators"); 00126 }
int TtSemiLepJetCombMVAComputer::maxNComb_ [private] |
int TtSemiLepJetCombMVAComputer::maxNJets_ [private] |