Hello,
I’m trying to apply the results of TMVA training script, but I getting the same error over and over again:
: 16-th variable of the event is NaN → return MVA value -999,
: that’s all I can do, please fix or remove this event.
This error just appears on loop with little variance. It’ll occasionally say 7-th instead of 16-th, but other than that it’s always the same. I reran the training with different signal and background files but still got the same error, and changing the file that I apply the training to doesn’t change the result. Surprisingly, running an older training-file combo that once ran successfully still gave the error. I can’t seem to find any previous mention of this error online, does anyone know what they issue may be? I’ve attached the scripts below. I replaced all of the variables that I declared with a single … to save space.
TMVA Training script:
void MVATrain(){
// Open file to store command line output
freopen("../Rankings/rankingsSM.txt","w",stdout);
// Load library, then open input and output files
TMVA::Tools::Instance();
TFile *sigFile = TFile::Open("/mnt/c/Users/uther/Dropbox/UROP_ALPs/kpietapipi-sim-sm.root");
TFile *backFile = TFile::Open("/mnt/c/Users/uther/Dropbox/UROP_ALPs/kpietapipi_500000.root");
TFile *outFile = TFile::Open("../trainingOutputFiles/TMVAOutputSM.root", "RECREATE");
// Create TMVA factory
auto factory = new TMVA::Factory("BXSignalSM", outFile,
"!V:ROC:!Correlations:!Silent:Color:!DrawProgressBar:AnalysisType=Classification");
// Get trees from files
TTree *tSig;
TTree *tBackFull;
TTree *tBack;
sigFile->GetObject("T;l", tSig);
backFile->GetObject("T;l", tBackFull);
// Disable unused branches in tree, keep needed ones
tSig->SetBranchStatus...
// Copy the background tree
tBack = tBackFull->CloneTree(tSig->GetEntries());
// Create DataLoader and add variables for cuts
TMVA::DataLoader loader("dataset");
loader.AddVariable...
// Create cuts and add tree to dataset
TCut sigCut = "iCand==0";
TCut backCut = "iCand==0";
loader.SetInputTrees(tSig, tBack, 1.0, 1.0);
loader.PrepareTrainingAndTestTree( sigCut, backCut,
"nTrain_Signal=0:nTrain_Background=0:SplitMode=Random:NormMode=NumEvents:!V");
// Book MVA methods to be run
factory->BookMethod(&loader,TMVA::Types::kMLP,"NN");//,"H:!V:NeuronType=tanh:VarTransform=N:NCycles=600:HiddenLayers=N+5:TestRate=5:!UseRegulator:TrainingMethod=BFGS:BPMode=batch");
factory->BookMethod(&loader,TMVA::Types::kBDT,"BDT");
factory->BookMethod(&loader,TMVA::Types::kLD,"LinkDis");
factory->BookMethod(&loader,TMVA::Types::kHMatrix,"LDAHMatrix");
factory->BookMethod(&loader,TMVA::Types::kFisher,"LDAFisher");
factory->BookMethod(&loader,TMVA::Types::kKNN,"KNearestN");
factory->BookMethod(&loader,TMVA::Types::kRuleFit,"PredictLearn");
factory->BookMethod(&loader,TMVA::Types::kLikelihood,"ProjectLikeliEst");
factory->BookMethod(&loader,TMVA::Types::kCuts,"RectCutOpt");
// Train, Test and Evaluate Methods
factory->TrainAllMethods();
factory->TestAllMethods();
factory->EvaluateAllMethods();
// Close output command line files
outFile->Close();
// Open and ROC curve, Draw GUI, then delete the factory
if(!gROOT->IsBatch()) TMVA::TMVAGui("/mnt/c/Users/uther/Dropbox/UROP_ALPs/Wagura/trainingOutputFiles/TMVAOutputSM.root");
delete factory;
fclose(stdout);
}
TMVA Application script:
void MVAApply(){
// Load the library
TMVA::Tools::Instance();
// Initialize the reader
TMVA::Reader *reader = new TMVA::Reader();
// Create local variables to store updated inputs
Float_t b_fd(0.);...
double db_fd(0.);...
// Add variables used to make cuts
reader->AddVariable("b_fd ...
// Book method
reader->BookMVA("NN","dataset/weights/BXSignalShort_NN.weights.xml");
// Create output histogram
TH1F *cutHisto = new TH1F( "NN-Long", "NN-Long", 100, -.5, .5);
// Open input file
//TFile *input = TFile::Open("/mnt/c/Users/uther/Dropbox/alps_kpi3pi/kpi3pi.root");
TFile *input = TFile::Open("/mnt/c/Users/uther/Dropbox/UROP_ALPS/kpietapipi.root");
// Prepare event tree
TTree* applyTree;
input->GetObject("T;78",applyTree);
applyTree->SetBranchAddress("b_fd...
// Loop over events
for (int i=0, n=applyTree->GetEntries(); i<n; i++)
{
applyTree->GetEntry(i);
// Set Values of TMVA variables
b_fd = db_fd;...
//Fill histogram
cutHisto->Fill(reader->EvaluateMVA("NN"));
}
// Write and draw the histogram, then close the file and the reader
TFile *target = new TFile("TMVAAppOmega.root", "RECREATE");
cutHisto->Write();
//cutHisto->Draw();
target->Close();
delete reader;
}
_ROOT Version: 6.22/00
_Platform: Ubuntu on WSL
Compiler: Not Provided