00001 #include "PhysicsTools/JetMCUtils/interface/combination.h"
00002
00003 #include "DataFormats/PatCandidates/interface/Jet.h"
00004 #include "DataFormats/RecoCandidate/interface/RecoCandidate.h"
00005 #include "AnalysisDataFormats/TopObjects/interface/TtGenEvent.h"
00006 #include "TopQuarkAnalysis/TopJetCombination/interface/TtSemiLepJetCombEval.h"
00007 #include "TopQuarkAnalysis/TopJetCombination/plugins/TtSemiLepJetCombMVAComputer.h"
00008
00009 #include "TString.h"
00010
00011 TtSemiLepJetCombMVAComputer::TtSemiLepJetCombMVAComputer(const edm::ParameterSet& cfg):
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 }
00022
00023 TtSemiLepJetCombMVAComputer::~TtSemiLepJetCombMVAComputer()
00024 {
00025 }
00026
00027 void
00028 TtSemiLepJetCombMVAComputer::produce(edm::Event& evt, const edm::EventSetup& setup)
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
00037
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
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
00058
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
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
00091
00092 if(combi[TtSemiLepEvtPartons::LightQ] < combi[TtSemiLepEvtPartons::LightQBar]) {
00093
00094 TtSemiLepJetComb jetComb(*jets, combi, lepton, *met);
00095
00096
00097 PhysicsTools::Variable::ValueList values;
00098 evaluateTtSemiLepJetComb(values, jetComb);
00099
00100
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
00112 discCombList.sort();
00113
00114
00115
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 }
00127
00128 void
00129 TtSemiLepJetCombMVAComputer::beginJob(const edm::EventSetup&)
00130 {
00131 }
00132
00133 void
00134 TtSemiLepJetCombMVAComputer::endJob()
00135 {
00136 }
00137
00138
00139
00140
00141 MVA_COMPUTER_CONTAINER_IMPLEMENT(TtSemiLepJetCombMVA);