CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
TtFullHadSignalSelMVATrainer.cc
Go to the documentation of this file.
1 #include "TMath.h"
2 #include <algorithm>
3 
6 
10 
14 
15 
17  jets_ (cfg.getParameter<edm::InputTag>("jets")),
18  whatData_ (cfg.getParameter<int>("whatData")),
19  maxEv_ (cfg.getParameter<int>("maxEv")),
20  weight_ (cfg.getParameter<double>("weight"))
21 {
22 }
23 
25 {
26 }
27 
28 void
30 {
31  //communication with CMSSW CondDB
32  mvaComputer.update<TtFullHadSignalSelMVARcd>("trainer", setup, "traintreeSaver");
33 
34  // can occur in the last iteration when the
35  // MVATrainer is about to save the result
36  if(!mvaComputer) return;
37 
38  // get the jets out of the event
40  evt.getByLabel(jets_, jets);
41 
42  //count the number of selected events
43  selEv++;
44  //skip event if enough events are already selected
45  if(selEv>maxEv_ && maxEv_!=-1) return;
46 
47  //calculation of InputVariables
48  //see TopQuarkAnalysis/TopTools/interface/TtFullHadSignalSel.h
49  // /src/TtFullHadSignalSel.cc
50  //all objects, jets, which are needed for the calculation
51  //of the input-variables have to be passed to this class
52 
54 
55  if(whatData_==-1) {
56  //your training-file contains both, signal and background events
57 
59  evt.getByLabel("genEvt", genEvt);
60 
61  bool isSignal = false;
62  if(genEvt->isTtBar()){
63  if(genEvt->isFullHadronic()) isSignal = true;
64  }
65  evaluateTtFullHadSignalSel(mvaComputer, selection, weight_, true, isSignal);
66  }
67  else {
68 
69  if(whatData_==1){
70  //your tree contains only signal events
71 
72  evaluateTtFullHadSignalSel(mvaComputer, selection, weight_, true, true);
73  }
74  else if(whatData_==0){
75  //your tree contains only background events
76 
77  evaluateTtFullHadSignalSel(mvaComputer, selection, weight_, true, false);
78  }
79  else std::cout<<"Config File Error!! Please check <whatData> in TtFullHadSignalSelMVATrainer_cfi";
80  }
81 }
82 
84  selEv = 0;
85  if(whatData_!=-1 && whatData_!=0 && whatData_!=1){
86  std::cout<<"Config File Error!! Please check <whatData> in TtFullHadSignalSelMVATrainer_cfi"<<std::endl;;
87  return;
88  }
89 }
90 
91 // implement the plugins for the trainer
92 // -> defines TtFullHadSignalSelMVAContainerSaveCondDB
93 // -> defines TtFullHadSignalSelMVASaveFile
94 // -> defines TtFullHadSignalSelMVATrainerLooper
95 MVA_TRAINER_IMPLEMENT(TtFullHadSignalSelMVA);
#define MVA_TRAINER_IMPLEMENT(N)
Definition: HelperMacros.h:40
double evaluateTtFullHadSignalSel(PhysicsTools::MVAComputerCache &mvaComputer, const TtFullHadSignalSel &sigsel, double weight=1.0, const bool training=false, const bool isSignal=false)
virtual void analyze(const edm::Event &evt, const edm::EventSetup &setup)
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:359
bool update(const Calibration::MVAComputer *computer)
tuple cout
Definition: gather_cfg.py:41
TtFullHadSignalSelMVATrainer(const edm::ParameterSet &)
PhysicsTools::MVAComputerCache mvaComputer