Dataloader says tree has 0 events


ROOT Version: 6.24
Platform: VSCode
Compiler: macOS C++ Compiler


Hi,

I’m trying to practice the basics of Root. I followed along with the TMVAClassification tutorial, and I got that to work. Now, I’m trying to use my own data to create a ML model. But I keep getting this error:

DataSetInfo : [dataset] : Added class “Signal”
: Add Tree signalTree of type Signal with 0 events
<FATAL> : Encountered empty TTree or TChain of class Signal

This is confusing me because this is the code responsible:

auto fileName = "./student-mat-signal.csv";
auto rdf = ROOT::RDF::MakeCsvDataFrame(fileName, true, ',');
TTree *signalTree = new TTree("signalTree","Signals");
rdf.Snapshot("signalTree", "signalMathScores.root");
.
.
.
TMVA::DataLoader *dataloader=new TMVA::DataLoader("dataset");

dataloader->AddVariable( "G1" );
dataloader->AddVariable( "G3" );

Double_t signalWeight = 1.0;
dataloader->AddSignalTree(signalTree, signalWeight );

The signalMathScores.root file that gets created isn’t empty, so I don’t understand why the dataloader says there’s 0 events. Any ideas on what the problem could be?

Hello,

I think the problem is here:

TTree *signalTree = new TTree("signalTree","Signals");
rdf.Snapshot("signalTree", "signalMathScores.root");

You are creating an in-memory tree and also snapshotting the contents of the CSV file into a tree in a ROOT file. But I guess what you want TMVA to use is the tree you snapshot.

So what you can do here is remove the line TTree *signalTree = new TTree("signalTree","Signals"); and instead, after the snapshot, you open the signalMathScores.root file and you read the tree from that file. See this link for information on how to read objects stored in ROOT files.

1 Like

That worked! Thank you!