Hello dear ROOTforum,
I have trouble with TMVA’s macros. The tree source has branches type vector, in the part of dataloader I put this
dataloader->AddVariable( "B_J_px2", "B_J_px2", "units", 'F' );
and works fine. But in the part of Application, I stated the same variables in the part of classification (like tutorial explain)
TMVA::Reader *reader = new TMVA::Reader( "!Color:!Silent" ); // Create a set of variables and declare them to the reader // - the variable names MUST corresponds in name and type to those given in the weight file(s) used Float_t B_J_px2; ... reader->AddVariable( "B_J_px2", &B_J_px2 );... TFile* datafile = TFile::Open("Datafile.root"); std::cout << "TMVAClassificationApp :Using input file: " << datafile->GetName() <<std::endl; ` std::cout << "--- Select signal sample" << std::endl; TFile* signalfile = new TFile("MC_file.root"); //open the file TTree* signaltree = (TTree*)signalfile->Get("rootuple/ntuple"); signaltree->SetBranchAddress( "B_J_px2", &B_J_px2 );
The application macro compiles well, but when I execute it I got this:
Error in <TTree::SetBranchAddress>: The pointer type given "Float_t" (5) does not correspond to the type needed "vector<float>" by the branch: B_J_px2
I thought that the solution it could be put ‘vector’ in the part of dataloader, I mean
dataloader->AddVariable( "B_J_px2", "B_J_px2", "units", 'vector<float> type' );
but reading TMVA documentation (https://root.cern/doc/v612/classTMVA_1_1DataLoader.html#af2de13debc441fd2c4f1cd826ef175f9) I saw that not is possible.
I saw this contribution in the forum (Vector in Branch) but I can’t do that, due to I have to redeclare the variables and it isn’t allowed.
Another thing that I think it could be the solution is reading vector branches as arrays of float variables, in the SetBranchesAddress, but I don’t know if it affects the reading of weights.
Could you please help me with this? I attach the macros of classification and application and a link with the root files. TMVAClassification_Bmesonfinal.C (23.0 KB)
TMVAClassificationApplication_Bmesonfinal.C (29.3 KB)
Thanks for your attention and sorry for bothering you,