TMVA::Reader::AddVariable: How to cast Double_t type variable to Float_t

Dear Experts,

While evaluating the MVA response through TMVA::Reader::AddVariable. I faced the problem of the method AddVariable only accepting Float_t variables (or Int_t), but not Double_t. I can import variables of type double from my nTuple to train an MVA method with the TMVA::DataLoader but cannot through ‘TMVA::Reader::AddVariable’ because of the reason as stated.
train.C (2.4 KB)

Along with the MVA response, I am also want to save the probability and rarity distribution. The macro apply.C is used to save their distribution. see
apply.C (3.8 KB)

The data coming from a TTree, which I did not create that already has Double_t branches, so to use them, the only way was casting to Float_t.

Kindly please suggest how to cast the Double_t type variables to Float_t type or some other solution which can take Double_t type variables.

Please find the attached sample for the signal and background used for training.
sig_train.root (2.3 MB)
bkg_train.root (2.3 MB)

Thank you.

Hi,

You can use an input double from the Tree, but you need to pass a float pointer in Reader::AddVariable. Like in this example (here the input Tree is having an integer and a float is used in AddVariable):

You pass a double pointer in Tree::SetBranchAddress as following:

double xd; 
float xf;
tree->SetBranchAddress("variable",&xd);
reader->AddVariable("variable",&xf); 

and in the event loop you do:

tree->GetEntry(ievt);
xf = xd; 
reader->EvaluateMVA("MyBDT");

Cheers

Lorenzo

Thank you for your suggestions. I have implemented it in my code, and it works.