Skip to content

Commit cd80527

Browse files
lmonetadpiparo
authored andcommitted
[tmva] Use local input files instead of downloading them from root.cern.ch for tutorials an tests
Use as input to TMVA tutorials and tests local files uploaded in github in the tutorials/machine_learning/data directory instead of getting them from root.cern.ch This is teh second commit adding the missing changes to the uncomplete commit done in master
1 parent 7bbd21c commit cd80527

19 files changed

+61
-79
lines changed

tmva/pymva/test/Classification.C

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,17 +34,13 @@ void Classification()
3434
factory->AddSpectator("spec1 := var1*2", "Spectator 1", "units", 'F');
3535
factory->AddSpectator("spec2 := var1*3", "Spectator 2", "units", 'F');
3636

37-
TFile *input(0);
38-
TString fname = "./tmva_class_example.root";
37+
TFile *input(nullptr);
38+
TString fname = gROOT->GetTutorialDir() + "/machine_learning/data/tmva_class_example.root";
3939
if (!gSystem->AccessPathName( fname )) {
4040
input = TFile::Open( fname ); // check if file in local directory exists
4141
}
42-
else {
43-
TFile::SetCacheFileDir(".");
44-
input = TFile::Open("http://root.cern/files/tmva_class_example.root", "CACHEREAD");
45-
}
4642
if (!input) {
47-
std::cout << "ERROR: could not open data file" << std::endl;
43+
std::cout << "ERROR: could not open data file " << fname << std::endl;
4844
exit(1);
4945
}
5046

tmva/pymva/test/testPyAdaBoostClassification.C

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include "TFile.h"
55
#include "TTree.h"
66
#include "TSystem.h"
7+
#include "TROOT.h"
78
#include "TMVA/Factory.h"
89
#include "TMVA/Reader.h"
910
#include "TMVA/DataLoader.h"
@@ -12,12 +13,12 @@
1213
int testPyAdaBoostClassification(){
1314
// Get data file
1415
std::cout << "Get test data..." << std::endl;
15-
TString fname = "./tmva_class_example.root";
16-
if (gSystem->AccessPathName(fname)) {
17-
// file does not exist in local directory
18-
gSystem->Exec("curl -L -O http://root.cern/files/tmva_class_example.root");
19-
}
16+
TString fname = gROOT->GetTutorialDir() + "/machine_learning/data/tmva_class_example.root";
2017
TFile *input = TFile::Open(fname);
18+
if (!input) {
19+
std::cout << "ERROR: could not open data file " << fname << std::endl;
20+
return 1;
21+
}
2122

2223
// Setup PyMVA and factory
2324
std::cout << "Setup TMVA..." << std::endl;

tmva/pymva/test/testPyGTBClassification.C

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include "TFile.h"
55
#include "TTree.h"
66
#include "TSystem.h"
7+
#include "TROOT.h"
78
#include "TMVA/Factory.h"
89
#include "TMVA/Reader.h"
910
#include "TMVA/DataLoader.h"
@@ -12,12 +13,12 @@
1213
int testPyGTBClassification(){
1314
// Get data file
1415
std::cout << "Get test data..." << std::endl;
15-
TString fname = "./tmva_class_example.root";
16-
if (gSystem->AccessPathName(fname)) {
17-
// file does not exist in local directory
18-
gSystem->Exec("curl -L -O http://root.cern/files/tmva_class_example.root");
19-
}
16+
TString fname = gROOT->GetTutorialDir() + "/machine_learning/data/tmva_class_example.root";
2017
TFile *input = TFile::Open(fname);
18+
if (!input) {
19+
std::cout << "ERROR: could not open data file " << fname << std::endl;
20+
return 1;
21+
}
2122

2223
// Setup PyMVA and factory
2324
std::cout << "Setup TMVA..." << std::endl;

tmva/pymva/test/testPyKerasClassification.C

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include "TFile.h"
55
#include "TTree.h"
66
#include "TSystem.h"
7+
#include "TROOT.h"
78
#include "TMVA/Factory.h"
89
#include "TMVA/Reader.h"
910
#include "TMVA/DataLoader.h"
@@ -24,12 +25,12 @@ int testPyKerasClassification(){
2425

2526
// Get data file
2627
std::cout << "Get test data..." << std::endl;
27-
TString fname = "./tmva_class_example.root";
28-
if (gSystem->AccessPathName(fname)) {
29-
// file does not exist in local directory
30-
gSystem->Exec("curl -L -O http://root.cern/files/tmva_class_example.root");
31-
}
28+
TString fname = gROOT->GetTutorialDir() + "/machine_learning/data/tmva_class_example.root";
3229
TFile *input = TFile::Open(fname);
30+
if (!input) {
31+
std::cout << "ERROR: could not open data file " << fname << std::endl;
32+
return 1;
33+
}
3334

3435
// Build model from python file
3536
if (gSystem->AccessPathName("kerasModelClassification.h5")) {

tmva/pymva/test/testPyKerasRegression.C

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include "TFile.h"
55
#include "TTree.h"
66
#include "TSystem.h"
7+
#include "TROOT.h"
78
#include "TMVA/Factory.h"
89
#include "TMVA/Reader.h"
910
#include "TMVA/DataLoader.h"
@@ -23,12 +24,12 @@ model.save(\"kerasModelRegression.h5\")\n";
2324
int testPyKerasRegression(){
2425
// Get data file
2526
std::cout << "Get test data..." << std::endl;
26-
TString fname = "./tmva_reg_example.root";
27-
if (gSystem->AccessPathName(fname)) {
28-
// file does not exist in local directory
29-
gSystem->Exec("curl -L -O http://root.cern/files/tmva_reg_example.root");
30-
}
27+
TString fname = gROOT->GetTutorialDir() + "/machine_learning/data/tmva_reg_example.root";
3128
TFile *input = TFile::Open(fname);
29+
if (!input) {
30+
std::cout << "ERROR: could not open data file " << fname << std::endl;
31+
return 1;
32+
}
3233

3334
// Build model from python file
3435
std::cout << "Generate keras model..." << std::endl;

tmva/pymva/test/testPyRandomForestClassification.C

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include "TFile.h"
55
#include "TTree.h"
66
#include "TSystem.h"
7+
#include "TROOT.h"
78
#include "TMVA/Factory.h"
89
#include "TMVA/Reader.h"
910
#include "TMVA/DataLoader.h"
@@ -12,12 +13,12 @@
1213
int testPyRandomForestClassification(){
1314
// Get data file
1415
std::cout << "Get test data..." << std::endl;
15-
TString fname = "./tmva_class_example.root";
16-
if (gSystem->AccessPathName(fname)) {
17-
// file does not exist in local directory
18-
gSystem->Exec("curl -L -O http://root.cern/files/tmva_class_example.root");
19-
}
16+
TString fname = gROOT->GetTutorialDir() + "/machine_learning/data/tmva_class_example.root";
2017
TFile *input = TFile::Open(fname);
18+
if (!input) {
19+
std::cout << "ERROR: could not open data file " << fname << std::endl;
20+
return 1;
21+
}
2122

2223
// Setup PyMVA and factory
2324
std::cout << "Setup TMVA..." << std::endl;

tmva/rmva/test/Classification.C

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,16 +39,12 @@ void Classification()
3939
dataloader->AddSpectator("spec2 := var1*3", "Spectator 2", "units", 'F');
4040

4141
TFile *input(0);
42-
TString fname = "./tmva_class_example.root";
42+
TString fname = gROOT->GetTutorialDir() + "/machine_learning/data/tmva_class_example.root";
4343
if (!gSystem->AccessPathName( fname )) {
4444
input = TFile::Open( fname ); // check if file in local directory exists
4545
}
46-
else {
47-
TFile::SetCacheFileDir(".");
48-
input = TFile::Open("http://root.cern/files/tmva_class_example.root", "CACHEREAD");
49-
}
5046
if (!input) {
51-
std::cout << "ERROR: could not open data file" << std::endl;
47+
std::cout << "ERROR: could not open data file " << fname << std::endl;
5248
exit(1);
5349
}
5450

tmva/tmva/inc/TMVA/Classification.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,9 @@ void classification(UInt_t jobs = 2)
5757
TMVA::Tools::Instance();
5858
5959
TFile *input(0);
60-
TString fname = "./tmva_class_example.root";
60+
TString fname = gROOT->GetTutorialDir() + "/machine_learning/data/tmva_class_example.root";
6161
if (!gSystem->AccessPathName(fname)) {
6262
input = TFile::Open(fname); // check if file in local directory exists
63-
} else {
64-
TFile::SetCacheFileDir(".");
65-
input = TFile::Open("http://root.cern/files/tmva_class_example.root", "CACHEREAD");
6663
}
6764
if (!input) {
6865
std::cout << "ERROR: could not open data file" << std::endl;

tmva/tmva/test/rreader.cxx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ void TrainClassificationModel()
3535
output, "Silent:!V:!DrawProgressBar:AnalysisType=Classification");
3636

3737
// Open trees with signal and background events
38-
const std::string filename = "http://root.cern/files/tmva_class_example.root";
38+
const std::string filename = filenameClassification;
3939
std::unique_ptr<TFile> data{TFile::Open(filename.c_str())};
4040
auto signal = (TTree *)data->Get("TreeS");
4141
auto background = (TTree *)data->Get("TreeB");
@@ -58,7 +58,7 @@ void TrainClassificationModel()
5858

5959
// Regression
6060
static const std::string modelRegression = "RReaderRegression/weights/RReaderRegression_BDTG.weights.xml";
61-
static const std::string filenameRegression = "http://root.cern/files/tmva_reg_example.root";
61+
static const std::string filenameRegression = std::string(gROOT->GetTutorialDir()) + "/machine_learning/data/tmva_reg_example.root";
6262
static const std::vector<std::string> variablesRegression = {"var1", "var2"};
6363

6464
void TrainRegressionModel()
@@ -77,7 +77,7 @@ void TrainRegressionModel()
7777
output, "Silent:!V:!DrawProgressBar:AnalysisType=Regression");
7878

7979
// Open trees with signal and background events
80-
const std::string filename = "http://root.cern/files/tmva_reg_example.root";
80+
const std::string filename = filenameRegression;
8181
std::unique_ptr<TFile> data{TFile::Open(filename.c_str())};
8282
auto tree = (TTree *)data->Get("TreeR");
8383

@@ -97,7 +97,7 @@ void TrainRegressionModel()
9797

9898
// Multiclass
9999
static const std::string modelMulticlass = "RReaderMulticlass/weights/RReaderMulticlass_BDT.weights.xml";
100-
static const std::string filenameMulticlass = "http://root.cern/files/tmva_multiclass_example.root";
100+
static const std::string filenameMulticlass = std::string(gROOT->GetTutorialDir()) + "/machine_learning/data/tmva_multiclass_example.root";
101101
static const std::vector<std::string> variablesMulticlass = variablesClassification;
102102

103103
void TrainMulticlassModel()
@@ -116,7 +116,7 @@ void TrainMulticlassModel()
116116
output, "Silent:!V:!DrawProgressBar:AnalysisType=Multiclass");
117117

118118
// Open trees with signal and background events
119-
const std::string filename = "http://root.cern/files/tmva_multiclass_example.root";
119+
const std::string filename = filenameMulticlass;
120120
std::unique_ptr<TFile> data{TFile::Open(filename.c_str())};
121121
auto signal = (TTree *)data->Get("TreeS");
122122
auto background0 = (TTree *)data->Get("TreeB0");

tutorials/machine_learning/RBatchGenerator_NumPy.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import ROOT
1212

1313
tree_name = "sig_tree"
14-
file_name = "http://root.cern/files/Higgs_data.root"
14+
file_name = str(ROOT.gROOT.GetTutorialDir()) + "/machine_learning/data/Higgs_data.root"
1515

1616
batch_size = 128
1717
chunk_size = 5_000

0 commit comments

Comments
 (0)