Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
RMethodBase.cxx
Go to the documentation of this file.
1 // @(#)root/tmva/rmva $Id$
2 // Author: Omar Zapata,Lorenzo Moneta, Sergei Gleyzer 2015
3 
4 
5 /**********************************************************************************
6  * Project: TMVA - a Root-integrated toolkit for multivariate data analysis *
7  * Package: TMVA *
8  * Class : RMethodBase *
9  * *
10  * Description: *
11  * Virtual base class for all MVA method based on ROOTR *
12  * *
13  **********************************************************************************/
14 
15 #include<TMVA/RMethodBase.h>
16 #include <TMVA/DataSetInfo.h>
17 #include<TApplication.h>
18 using namespace TMVA;
19 
20 ClassImp(RMethodBase);
21 
22 //_______________________________________________________________________
23 RMethodBase::RMethodBase(const TString &jobName,
24  Types::EMVA methodType,
25  const TString &methodTitle,
26  DataSetInfo &dsi,
27  const TString &theOption , ROOT::R::TRInterface &_r): MethodBase(jobName, methodType, methodTitle, dsi, theOption),
28  r(_r)
29 {
30  LoadData();
31 }
32 
33 //_______________________________________________________________________
34 RMethodBase::RMethodBase(Types::EMVA methodType,
35  DataSetInfo &dsi,
36  const TString &weightFile,ROOT::R::TRInterface &_r): MethodBase(methodType, dsi, weightFile),
37  r(_r)
38 {
39  LoadData();
40 }
41 
42 //_______________________________________________________________________
43 void RMethodBase::LoadData()
44 {
45  ///////////////////////////
46  //Loading Training Data //
47  ///////////////////////////
48  const UInt_t nvar = DataInfo().GetNVariables();
49 
50  const UInt_t ntrains = Data()->GetNTrainingEvents();
51 
52  //array of columns for every var to create a dataframe for training
53  std::vector<std::vector<Float_t> > fArrayTrain(nvar);
54 // Data()->SetCurrentEvent(1);
55 // Data()->SetCurrentType(Types::ETreeType::kTraining);
56 
57  fWeightTrain.ResizeTo(ntrains);
58  for (UInt_t j = 0; j < ntrains; j++) {
59  const Event *ev = Data()->GetEvent(j, Types::ETreeType::kTraining);
60 // const Event *ev=Data()->GetEvent( j );
61  //creating array with class type(signal or background) for factor required
62  if (ev->GetClass() == Types::kSignal) fFactorTrain.push_back("signal");
63  else fFactorTrain.push_back("background");
64 
65  fWeightTrain[j] = ev->GetWeight();
66 
67  //filling vector of columns for training
68  for (UInt_t i = 0; i < nvar; i++) {
69  fArrayTrain[i].push_back(ev->GetValue(i));
70  }
71 
72  }
73  for (UInt_t i = 0; i < nvar; i++) {
74  fDfTrain[DataInfo().GetListOfVariables()[i].Data()] = fArrayTrain[i];
75  }
76  ////////////////////////
77  //Loading Test Data //
78  ////////////////////////
79 
80  const UInt_t ntests = Data()->GetNTestEvents();
81  const UInt_t nspectators = DataInfo().GetNSpectators(kTRUE);
82 
83  //array of columns for every var to create a dataframe for testing
84  std::vector<std::vector<Float_t> > fArrayTest(nvar);
85  //array of columns for every spectator to create a dataframe for testing
86  std::vector<std::vector<Float_t> > fArraySpectators(nvar);
87  fWeightTest.ResizeTo(ntests);
88 // Data()->SetCurrentType(Types::ETreeType::kTesting);
89  for (UInt_t j = 0; j < ntests; j++) {
90  const Event *ev = Data()->GetEvent(j, Types::ETreeType::kTesting);
91 // const Event *ev=Data()->GetEvent(j);
92  //creating array with class type(signal or background) for factor required
93  if (ev->GetClass() == Types::kSignal) fFactorTest.push_back("signal");
94  else fFactorTest.push_back("background");
95 
96  fWeightTest[j] = ev->GetWeight();
97 
98  for (UInt_t i = 0; i < nvar; i++) {
99  fArrayTest[i].push_back(ev->GetValue(i));
100  }
101  for (UInt_t i = 0; i < nspectators; i++) {
102  fArraySpectators[i].push_back(ev->GetSpectator(i));
103  }
104  }
105  for (UInt_t i = 0; i < nvar; i++) {
106  fDfTest[DataInfo().GetListOfVariables()[i].Data()] = fArrayTest[i];
107  }
108  for (UInt_t i = 0; i < nspectators; i++) {
109  fDfSpectators[DataInfo().GetSpectatorInfo(i).GetLabel().Data()] = fArraySpectators[i];
110  }
111 
112 }