Failed to call "kCuts" methods from pyroot using TMVA

when I used TMVA with pyroot, I can not successfully call kCuts in TMVA method. the error message is following:

TFHandler_Factory : Variable Mean RMS [ Min Max ]
: -----------------------------------------------------------
: pt_b1b2: 134.63 90.575 [ 0.18029 1241.2 ]
: -----------------------------------------------------------
: Ranking input variables (method unspecific)…
IdTransformation : Ranking result (top variable is best ranked)
: --------------------------------
: Rank : Variable : Separation
: --------------------------------
: 1 : pt_b1b2 : 3.203e-01
: --------------------------------
Factory : Train method: kCuts for Classification
:
: Dataset[DYBDTTraining] : Base Directory for kCuts not set yet → check if already there…
: Dataset[DYBDTTraining] : Base Directory for Cuts not set yet → check if already there…
: Dataset[DYBDTTraining] : Base Directory for kCuts does not exist yet–> created it
: Dataset[DYBDTTraining] : Return from MethodBaseDir() after creating base directory
: Dataset[DYBDTTraining] : Base Directory for Cuts does not exist yet–> created it
: Dataset[DYBDTTraining] : Base Directory for Cuts existed, return it…
: Begin training
: maximum lower than minimum

I could use Macro to book kCuts in TMVA with same setting and dataset, and the results make sense for me.

The following is the pyroot code to call “kCuts” with MVAmethods = [“kCuts”] and options = {“kCuts” : “!H:Debug:FitMethod=MC:EffSel:SampleSize=20000:VarProp=FSmart”}. i tried to use one dimensional input and multiple dimensional inputs, and none of them could work. I even tried to define the cutrange by adding “CutRangeMin[0]=0:CutRangeMax[1]=1200” to book method options and it still did not work.

dataloader.PrepareTrainingAndTestTree(R.TCut(trainCut), traintestOptions)
for MVAmethod in MVAmethods:
     option = ""
     if options is not None:
         option = options[MVAmethod]
     print("method ", MVAmethod, " TMVA type ", getattr(R.TMVA.Types, MVAmethod)," option ",option)
     factory.BookMethod(dataloader, getattr(R.TMVA.Types, MVAmethod), MVAmethod, option)

As for other MVA methods in TMVA, i could use them in pyroot without any issue.

Does anyone have an explanation or see something similar.
Cheers,
Tao

Hi,

@sitong or @moneta might be able to help.

Hi,

I found this thread while searching for the same error, and wanted to share that I found a solution in the root_numpy documentation, root_numpy.tmva.add_classification_events — root_numpy 4.7.3.dev0 documentation. The documentation states:

When using MethodCuts, the first event added must be a signal event, otherwise TMVA will fail with <FATAL> Interval : maximum lower than minimum .

In my case, I found that the signal tree must be loaded before the background tree:

Works:

dataloader.AddSignalTree(tree_mc, 1.0)
dataloader.AddBackgroundTree(tree_data, 1.0)

Does not work:

dataloader.AddBackgroundTree(tree_data, 1.0)
dataloader.AddSignalTree(tree_mc, 1.0)

Perhaps the developers could comment on this (presumably unexpected) behavior?

Cheers,

David

1 Like

Hi David,
thank you for taking the time to come back and post a solution!

I guess @moneta can comment whether that should be a jira ticket.
Cheers,
Enrico