The following is my code for a BDT using TMVA. I need it to write the BDT response to a file, but that just is not happening… I suspect I’m not using the dataloader correctly, but I have messed with things with no success for a few days now. Any help would be appreciated.
signal_file=TFile('signal.root') #signal
background_file=TFile('background.root') #background
tree_s=signal_file.Get('microtuple')
tree_b=background_file.Get('microtuple')
# why not writing to file?
out_file=TFile('alllcuts_BDT.root', 'RECREATE')
factory = TMVA.Factory("TMVAClassification",out_file,"V:!Silent:Color:Transformations=I:DrawProgressBar:AnalysisType=Classification");
dataloader = TMVA.DataLoader()
dataloader.AddVariable('jj_mass', 'F')
dataloader.AddVariable('met_et', 'F')
dataloader.AddSignalTree(tree_s)
dataloader.AddBackgroundTree(tree_b)
# additional cuts
signal_cut=TCut('jj_mass>1000000 && met_et>150000')
background_cut=TCut('jj_mass>1000000 && met_et>150000')
dataloader.PrepareTrainingAndTestTree(signal_cut, background_cut, ':'.join(['nTrain_Signal=0', 'nTrain_Background=0',
'SplitMode=Random', 'NormMode=NumEvents', '!V']))
method = factory.BookMethod(dataloader, TMVA.Types.kBDT, 'BDTG', ':'.join(['!H', '!V', 'NTrees=850',
'MaxDepth=3', 'BoostType=Grad', 'Shrinkage=1.0',
'SeparationType=GiniIndex', 'nCuts=20', 'PruneMethod=NoPruning']))
factory.TrainAllMethods()
factory.TestAllMethods()
factory.EvaluateAllMethods()
print('done')