# Convert format of TMVA weight file from xml to root

**URL:** <https://root-forum.cern.ch/t/convert-format-of-tmva-weight-file-from-xml-to-root/30047>\
**Category:** TMVA\
**Created:** [July 31, 2018, 1:02pm UTC](https://root-forum.cern.ch/t/convert-format-of-tmva-weight-file-from-xml-to-root/30047 "2018-07-31T13:02:03Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![zhangb](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/z/87869e/32.png) [@zhangb](https://root-forum.cern.ch/u/zhangb)\
**Post date:** [July 31, 2018, 1:02pm UTC](https://root-forum.cern.ch/t/convert-format-of-tmva-weight-file-from-xml-to-root/30047/1 "2018-07-31T13:02:03Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![kialbert](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/kialbert/32/16537_2.png) [@kialbert](https://root-forum.cern.ch/u/kialbert)\
**Post date:** [July 31, 2018, 1:06pm UTC](https://root-forum.cern.ch/t/convert-format-of-tmva-weight-file-from-xml-to-root/30047/2 "2018-07-31T13:06:07Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![zhangb](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/z/87869e/32.png) [@zhangb](https://root-forum.cern.ch/u/zhangb)\
**Post date:** [July 31, 2018, 1:21pm UTC](https://root-forum.cern.ch/t/convert-format-of-tmva-weight-file-from-xml-to-root/30047/3 "2018-07-31T13:21:53Z")

</div>

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
