33 void TMVARegressionApplication( TString myMethodList =
"" )
40 std::map<std::string,int> Use;
67 std::cout << std::endl;
68 std::cout <<
"==> Start TMVARegressionApplication" << std::endl;
71 if (myMethodList !=
"") {
72 for (std::map<std::string,int>::iterator it = Use.begin(); it != Use.end(); it++) it->second = 0;
75 for (
UInt_t i=0; i<mlist.size(); i++) {
76 std::string regMethod(mlist[i]);
78 if (Use.find(regMethod) == Use.end()) {
79 std::cout <<
"Method \"" << regMethod <<
"\" not known in TMVA under this name. Choose among the following:" << std::endl;
80 for (std::map<std::string,int>::iterator it = Use.begin(); it != Use.end(); it++) std::cout << it->first <<
" ";
81 std::cout << std::endl;
107 TString dir =
"dataset/weights/";
108 TString prefix =
"TMVARegression";
111 for (std::map<std::string,int>::iterator it = Use.begin(); it != Use.end(); it++) {
113 TString methodName = it->first +
" method";
114 TString weightfile = dir + prefix +
"_" + TString(it->first) +
".weights.xml";
115 reader->
BookMVA( methodName, weightfile );
122 for (std::map<std::string,int>::iterator it = Use.begin(); it != Use.end(); it++) {
123 TH1*
h =
new TH1F( it->first.c_str(), TString(it->first) +
" method", 100, -100, 600 );
124 if (it->second) hists[++nhists] =
h;
133 TString fname =
"./tmva_reg_example.root";
138 input =
TFile::Open(
"http://root.cern.ch/files/tmva_reg_example.root" );
142 std::cout <<
"ERROR: could not open data file" << std::endl;
145 std::cout <<
"--- TMVARegressionApp : Using input file: " << input->GetName() << std::endl;
154 TTree* theTree = (TTree*)input->Get(
"TreeR");
155 std::cout <<
"--- Select signal sample" << std::endl;
156 theTree->SetBranchAddress(
"var1", &var1 );
157 theTree->SetBranchAddress(
"var2", &var2 );
159 std::cout <<
"--- Processing: " << theTree->GetEntries() <<
" events" << std::endl;
162 for (
Long64_t ievt=0; ievt<theTree->GetEntries();ievt++) {
164 if (ievt%1000 == 0) {
165 std::cout <<
"--- ... Processing event: " << ievt << std::endl;
168 theTree->GetEntry(ievt);
173 for (
Int_t ih=0; ih<nhists; ih++) {
174 TString title = hists[ih]->
GetTitle();
176 hists[ih]->
Fill( val );
180 std::cout <<
"--- End of event loop: "; sw.
Print();
184 TFile *target =
new TFile(
"TMVARegApp.root",
"RECREATE" );
185 for (
Int_t ih=0; ih<nhists; ih++) hists[ih]->Write();
188 std::cout <<
"--- Created root file: \"" << target->
GetName()
189 <<
"\" containing the MVA output histograms" << std::endl;
193 std::cout <<
"==> TMVARegressionApplication is done!" << std::endl << std::endl;
196 int main(
int argc,
char** argv )
200 for (
int i=1; i<argc; i++) {
201 TString regMethod(argv[i]);
202 if(regMethod==
"-b" || regMethod==
"--batch")
continue;
203 if (!methodList.IsNull()) methodList += TString(
",");
204 methodList += regMethod;
206 TMVARegressionApplication(methodList);
virtual const char * GetName() const
Returns name of object.
virtual Bool_t AccessPathName(const char *path, EAccessMode mode=kFileExists)
Returns FALSE if one can access a file using the specified access mode.
virtual Int_t Fill(Double_t x)
Increment bin with abscissa X by 1.
void Start(Bool_t reset=kTRUE)
Start the stopwatch.
void Print(Option_t *option="") const
Print the real and cpu time passed between the start and stop events.
void AddVariable(const TString &expression, Float_t *)
Add a float variable or expression to the reader.
THist< 1, float, THistStatContent, THistStatUncertainty > TH1F
const std::vector< Float_t > & EvaluateRegression(const TString &methodTag, Double_t aux=0)
evaluates MVA for given set of input variables
static TFile * Open(const char *name, Option_t *option="", const char *ftitle="", Int_t compress=1, Int_t netopt=0)
Create / open a file.
void Stop()
Stop the stopwatch.
IMethod * BookMVA(const TString &methodTag, const TString &weightfile)
read method name from weight file
R__EXTERN TSystem * gSystem
void AddSpectator(const TString &expression, Float_t *)
Add a float spectator or expression to the reader.
Abstract ClassifierFactory template that handles arbitrary types.
int main(int argc, char **argv)
virtual const char * GetTitle() const
Returns title of object.