CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch9/src/TopQuarkAnalysis/TopEventSelection/plugins/TtFullHadSignalSelMVATrainer.cc

Go to the documentation of this file.
00001 #include "TMath.h"
00002 #include <algorithm>
00003 
00004 #include "PhysicsTools/JetMCUtils/interface/combination.h"
00005 #include "PhysicsTools/MVATrainer/interface/HelperMacros.h"
00006 
00007 #include "AnalysisDataFormats/TopObjects/interface/TtEvent.h"
00008 #include "TopQuarkAnalysis/TopEventSelection/plugins/TtFullHadSignalSelMVATrainer.h"
00009 #include "TopQuarkAnalysis/TopEventSelection/interface/TtFullHadSignalSelEval.h"
00010 
00011 #include "DataFormats/PatCandidates/interface/Jet.h"
00012 #include "DataFormats/PatCandidates/interface/Flags.h"
00013 #include "DataFormats/RecoCandidate/interface/RecoCandidate.h"
00014 
00015 
00016 TtFullHadSignalSelMVATrainer::TtFullHadSignalSelMVATrainer(const edm::ParameterSet& cfg):
00017   jets_      (cfg.getParameter<edm::InputTag>("jets")),
00018   whatData_  (cfg.getParameter<int>("whatData")),
00019   maxEv_     (cfg.getParameter<int>("maxEv")),
00020   weight_    (cfg.getParameter<double>("weight"))
00021 {
00022 }
00023 
00024 TtFullHadSignalSelMVATrainer::~TtFullHadSignalSelMVATrainer()
00025 {
00026 }
00027 
00028 void
00029 TtFullHadSignalSelMVATrainer::analyze(const edm::Event& evt, const edm::EventSetup& setup)
00030 {
00031   //communication with CMSSW CondDB
00032   mvaComputer.update<TtFullHadSignalSelMVARcd>("trainer", setup, "traintreeSaver");
00033 
00034   // can occur in the last iteration when the 
00035   // MVATrainer is about to save the result
00036   if(!mvaComputer) return;
00037 
00038   // get the jets out of the event
00039   edm::Handle< std::vector<pat::Jet> > jets;
00040   evt.getByLabel(jets_, jets);
00041 
00042   //count the number of selected events
00043   selEv++;
00044   //skip event if enough events are already selected
00045   if(selEv>maxEv_ && maxEv_!=-1) return;
00046 
00047   //calculation of InputVariables
00048   //see TopQuarkAnalysis/TopTools/interface/TtFullHadSignalSel.h
00049   //                             /src/TtFullHadSignalSel.cc
00050   //all objects, jets, which are needed for the calculation
00051   //of the input-variables have to be passed to this class
00052 
00053   TtFullHadSignalSel selection(*jets);
00054 
00055   if(whatData_==-1) {
00056     //your training-file contains both, signal and background events
00057 
00058     edm::Handle<TtGenEvent> genEvt;
00059     evt.getByLabel("genEvt", genEvt);
00060     
00061     bool isSignal = false;
00062     if(genEvt->isTtBar()){
00063       if(genEvt->isFullHadronic()) isSignal = true;
00064     }
00065     evaluateTtFullHadSignalSel(mvaComputer, selection, weight_, true, isSignal);
00066   }
00067   else {
00068    
00069     if(whatData_==1){
00070       //your tree contains only signal events
00071 
00072       evaluateTtFullHadSignalSel(mvaComputer, selection, weight_, true, true);
00073     }
00074     else if(whatData_==0){
00075       //your tree contains only background events
00076 
00077       evaluateTtFullHadSignalSel(mvaComputer, selection, weight_, true, false);
00078     }
00079     else std::cout<<"Config File Error!! Please check <whatData> in TtFullHadSignalSelMVATrainer_cfi";
00080   }
00081 }
00082 
00083 void TtFullHadSignalSelMVATrainer::beginJob(){
00084   selEv = 0;
00085   if(whatData_!=-1 && whatData_!=0 && whatData_!=1){
00086     std::cout<<"Config File Error!! Please check <whatData> in TtFullHadSignalSelMVATrainer_cfi"<<std::endl;;
00087     return;
00088   }
00089 }
00090 
00091 // implement the plugins for the trainer
00092 // -> defines TtFullHadSignalSelMVAContainerSaveCondDB
00093 // -> defines TtFullHadSignalSelMVASaveFile
00094 // -> defines TtFullHadSignalSelMVATrainerLooper
00095 MVA_TRAINER_IMPLEMENT(TtFullHadSignalSelMVA);