Convert format of TMVA weight file from xml to root

Dear Expert,

Is it possible to convert the BDT training output model.xml into some weight file in root format? Since I found that in some case, only weight file in root format is used to configure a BDT.

And it is configured as follows:

//________________________________________________________________________________
MVAUtils::BDT* tauRecTools::configureMVABDT( std::map<TString, float*> &availableVars, const TString& weightFile){
	TFile* fBDT = TFile::Open( weightFile );
	if(!fBDT){
		std::cerr << "ERROR Cannot find tau input BDT file: " << weightFile << std::endl;
		return 0;
	}
	TTree* tBDT = dynamic_cast<TTree*> (fBDT->Get("BDT"));
	if(!tBDT){
		delete fBDT;
		std::cerr << "ERROR Cannot find tau input BDT tree" << std::endl;
		return 0;
	}    

	std::cout << "tauRecTools::configureMVABDT opened file: " << weightFile << std::endl;

	std::vector<float*> vars;

	//parsing of variables done here from TNamed object
	TNamed* n_varList = dynamic_cast<TNamed*> (fBDT->Get("varList"));
	if(!n_varList) {
		std::cerr << "ERROR no Variable List in file : " << weightFile << std::endl;
		delete fBDT;
		return 0;
	}
	std::vector<TString> varList_ar = 	tauRecTools::parseStringMVAUtilsBDT(n_varList->GetTitle());
	for(const TString& str : varList_ar){
		if(str.Length()==0) continue;
		std::map<TString, float*>::iterator itr = availableVars.find(str);
		if(itr==availableVars.end()){
			std::cerr << "ERROR Variable : " << str << " is not available" << std::endl;
			delete fBDT;
			delete n_varList;
			return 0;
		}
		vars.push_back( itr->second );
	}
	
	MVAUtils::BDT* reader = new MVAUtils::BDT(tBDT);
  	reader->SetPointers( vars );
  	
  	delete n_varList;
  	delete fBDT;
  	return reader;

}

Thanks a lot!

Cheers,
Bowen

Hi,

This code snippet is not part of TMVA/ROOT. TMVA currently only supports outputting weight files in xml format.

There is probably a function in your framework that can do this, you would have to check with the maintainers/documentation of that framework.

Cheers,
Kim

Hi Kim,

Thanks for your reply! It’s good to know the problem is not with TMVA. I’ll ask the maintainer on how it works.

Cheers,
Bowen

1 Like