33 void TMVARegressionApplication( TString myMethodList =
"" )
40 std::map<std::string,int> Use;
68 std::cout << std::endl;
69 std::cout <<
"==> Start TMVARegressionApplication" << std::endl;
72 if (myMethodList !=
"") {
73 for (std::map<std::string,int>::iterator it = Use.begin(); it != Use.end(); it++) it->second = 0;
76 for (
UInt_t i=0; i<mlist.size(); i++) {
77 std::string regMethod(mlist[i]);
79 if (Use.find(regMethod) == Use.end()) {
80 std::cout <<
"Method \"" << regMethod <<
"\" not known in TMVA under this name. Choose among the following:" << std::endl;
81 for (std::map<std::string,int>::iterator it = Use.begin(); it != Use.end(); it++) std::cout << it->first <<
" ";
82 std::cout << std::endl;
108 TString dir =
"dataset/weights/";
109 TString prefix =
"TMVARegression";
112 for (std::map<std::string,int>::iterator it = Use.begin(); it != Use.end(); it++) {
114 TString methodName = it->first +
" method";
115 TString weightfile = dir + prefix +
"_" + TString(it->first) +
".weights.xml";
116 reader->
BookMVA( methodName, weightfile );
123 for (std::map<std::string,int>::iterator it = Use.begin(); it != Use.end(); it++) {
124 TH1*
h =
new TH1F( it->first.c_str(), TString(it->first) +
" method", 100, -100, 600 );
125 if (it->second) hists[++nhists] =
h;
134 TString fname =
"./tmva_reg_example.root";
140 input =
TFile::Open(
"http://root.cern.ch/files/tmva_reg_example.root",
"CACHEREAD");
143 std::cout <<
"ERROR: could not open data file" << std::endl;
146 std::cout <<
"--- TMVARegressionApp : Using input file: " << input->GetName() << std::endl;
155 TTree* theTree = (TTree*)input->Get(
"TreeR");
156 std::cout <<
"--- Select signal sample" << std::endl;
157 theTree->SetBranchAddress(
"var1", &var1 );
158 theTree->SetBranchAddress(
"var2", &var2 );
160 std::cout <<
"--- Processing: " << theTree->GetEntries() <<
" events" << std::endl;
163 for (
Long64_t ievt=0; ievt<theTree->GetEntries();ievt++) {
165 if (ievt%1000 == 0) {
166 std::cout <<
"--- ... Processing event: " << ievt << std::endl;
169 theTree->GetEntry(ievt);
174 for (
Int_t ih=0; ih<nhists; ih++) {
175 TString title = hists[ih]->
GetTitle();
177 hists[ih]->
Fill( val );
181 std::cout <<
"--- End of event loop: "; sw.
Print();
185 TFile *target =
new TFile(
"TMVARegApp.root",
"RECREATE" );
186 for (
Int_t ih=0; ih<nhists; ih++) hists[ih]->Write();
189 std::cout <<
"--- Created root file: \"" << target->
GetName()
190 <<
"\" containing the MVA output histograms" << std::endl;
194 std::cout <<
"==> TMVARegressionApplication is done!" << std::endl << std::endl;
197 int main(
int argc,
char** argv )
201 for (
int i=1; i<argc; i++) {
202 TString regMethod(argv[i]);
203 if(regMethod==
"-b" || regMethod==
"--batch")
continue;
204 if (!methodList.IsNull()) methodList += TString(
",");
205 methodList += regMethod;
207 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 Bool_t SetCacheFileDir(ROOT::Internal::TStringView cacheDir, Bool_t operateDisconnected=kTRUE, Bool_t forceCacheread=kFALSE)
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.
int main(int argc, char **argv)
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.
The Reader class serves to use the MVAs in a specific analysis context.
Abstract ClassifierFactory template that handles arbitrary types.
virtual const char * GetTitle() const
Returns title of object.