30std::vector<TControlBar*> TMVA::BDT_Global__cbar;
59 fMethName( methName ),
99 fInput->
Connect(
"ValueSet(Long_t)",
"TMVA::StatDialogBDT",
this,
"SetItree()");
115 if(!fWfile.EndsWith(
".xml") ){
116 std::ifstream fin( fWfile );
118 cout <<
"*** ERROR: Weight file: " << fWfile <<
" does not exist" << endl;
126 while (!
dummy.Contains(
"NTrees")) {
131 cout <<
"*** Huge problem: could not locate term \"NTrees\" in BDT weight file: "
133 cout <<
"==> panic abort (please contact the TMVA authors)" << endl;
139 fNtrees =
dummy.ReplaceAll(
"\"",
"").Atoi();
148 if(nodeName==
"Weights") {
155 cout <<
"--- Found " << fNtrees <<
" decision trees in weight file" << endl;
169 if (xsize>0.15) xsize=0.1;
170 if (
n->GetLeft() != NULL){
176 if (
n->GetRight() != NULL){
195 sprintf( buffer,
"N=%f",
n->GetNEvents() );
196 if (
n->GetNEvents()>0) t->
AddText(buffer);
197 sprintf( buffer,
"S/(S+B)=%4.3f",
n->GetPurity() );
200 if (
n->GetNodeType() == 0){
201 if (
n->GetCutType()){
214 cout <<
"--- Reading Tree " << itree <<
" from weight file: " << fWfile << endl;
216 if(!fWfile.EndsWith(
".xml") ){
217 std::ifstream fin( fWfile );
219 cout <<
"*** ERROR: Weight file: " << fWfile <<
" does not exist" << endl;
227 if (itree >= fNtrees) {
228 cout <<
"*** ERROR: requested decision tree: " << itree
229 <<
", but number of trained trees only: " << fNtrees << endl;
241 fin >>
dummy >> nVars;
246 vars[nVars]=
"FisherCrit";
250 sprintf(buffer,
"Tree %d",itree);
252 while (!
dummy.Contains(buffer)) {
253 fin.getline(
line,256);
262 if (itree >= fNtrees) {
263 cout <<
"*** ERROR: requested decision tree: " << itree
264 <<
", but number of trained trees only: " << fNtrees << endl;
275 if(nodeName==
"Variables"){
279 for (
Int_t i = 0; i < nVars; i++){
283 vars[nVars]=
"FisherCrit";
285 if(nodeName==
"Weights")
break;
303 UInt_t depth =
d->GetTotalTreeDepth();
306 cout <<
"--- Tree depth: " << depth << endl;
318 Int_t MyPalette[100];
319 for (
int i=0;i<100;i++) MyPalette[i] = fColorOffset+i;
326 TString cbuffer =
Form(
"Reading weight file: %s", fWfile.Data() );
327 TString tbuffer =
Form(
"Decision Tree no.: %d", itree );
328 if (!fCanvas) fCanvas =
new TCanvas(
"c1", cbuffer, 200, 0, 1000, 600 );
329 else fCanvas->Clear();
350 signalleaf->
AddText(
"Pure Signal Nodes");
354 ydown = ydown - ystep/2.5 -dy;
355 yup = yup - ystep/2.5 -dy;
361 backgroundleaf->
AddText(
"Pure Backgr. Nodes");
363 backgroundleaf->
Draw();
367 TString fname = fDataset+
Form(
"/plots/%s_%i", fMethName.Data(), itree );
368 cout <<
"--- Creating image: " << fname << endl;
390 cout <<
"*** Error in macro \"BDT.C\": cannot find directory \"Method_BDT\" in file: " << fin << endl;
397 std::vector<TString> methname;
398 std::vector<TString> path;
399 std::vector<TString> wfile;
400 while ((key = (
TKey*)next())) {
403 cout <<
"*** Error in macro \"BDT.C\": cannot find sub-directory: " << key->
GetName()
404 <<
" in directory: " << dir->
GetName() << endl;
411 if (!strPath || !strWFile) {
412 cout <<
"*** Error in macro \"BDT.C\": could not find TObjStrings \"TrainingPath\" and/or \"WeightFileName\" *** " << endl;
413 cout <<
"*** Maybe you are using TMVA >= 3.8.15 with an older training target file ? *** " << endl;
417 methname.push_back( key->GetName() );
419 wfile .push_back( strWFile->
GetString() );
424 BDT_Global__cbar.push_back(cbar);
426 for (
UInt_t im=0; im<path.size(); im++) {
428 if (fname[fname.
Length()-1] !=
'/') fname +=
"/";
430 TString macro =
Form(
"TMVA::BDT(\"%s\",0,\"%s\",\"%s\")",dataset.
Data(), fname.
Data(), methname[im].Data() );
431 cbar->
AddButton( fname, macro,
"Plot decision trees from this weight file",
"button" );
435#if ROOT_VERSION_CODE < ROOT_VERSION(5,19,0)
436 cbar->
AddButton(
"Close",
Form(
"BDT_DeleteTBar(%i)", BDT_Global__cbar.size()-1),
"Close this control bar",
"button" );
453 delete BDT_Global__cbar[i];
454 BDT_Global__cbar[i] = 0;
465 wfile = dataset+
"/weights/TMVAnalysis_test_BDT.weights.txt";
468 std::ifstream fin( wfile );
470 cout <<
"*** ERROR: Weight file: " << wfile <<
" does not exist" << endl;
474 std::cout <<
"test1";
478 StatDialogBDT* gGui =
new StatDialogBDT(dataset,
gClient->GetRoot(), wfile, methName, itree );
480 gGui->DrawTree(itree );
static RooMathCoreReg dummy
char * Form(const char *fmt,...)
virtual void SetFillColor(Color_t fcolor)
Set the fill area color.
virtual void SetFillStyle(Style_t fstyle)
Set the fill area style.
virtual void SetLineWidth(Width_t lwidth)
Set the line width.
virtual void SetTextColor(Color_t tcolor=1)
Set the text color.
static Int_t GetColor(const char *hexcolor)
Static method returning color number for color specified by hex color string of form: "#rrggbb",...
static Int_t CreateGradientColorTable(UInt_t Number, Double_t *Stops, Double_t *Red, Double_t *Green, Double_t *Blue, UInt_t NColors, Float_t alpha=1.)
Static function creating a color table with several connected linear gradients.
A Control Bar is a fully user configurable tool which provides fast access to frequently used operati...
void Show()
Show control bar.
void AddButton(TControlBarButton *button)
Add button.
void SetTextColor(const char *colorName)
Sets text color for control bar buttons, e.g.
Describe directory structure in memory.
virtual TDirectory * GetDirectory(const char *namecycle, Bool_t printError=false, const char *funcname="GetDirectory")
Find a directory using apath.
virtual TObject * Get(const char *namecycle)
Return pointer to object identified by namecycle.
virtual TList * GetListOfKeys() const
A ROOT file is a suite of consecutive data records (TKey instances) with a well defined format.
virtual void AddFrame(TGFrame *f, TGLayoutHints *l=0)
Add frame to the composite frame using the specified layout hints.
virtual TGDimension GetDefaultSize() const
std::cout << fWidth << "x" << fHeight << std::endl;
virtual void MapSubwindows()
Map all sub windows that are part of the composite frame.
virtual void Resize(UInt_t w=0, UInt_t h=0)
Resize the frame.
void SetWMPosition(Int_t x, Int_t y)
Give the window manager a window position hint.
void SetWindowName(const char *name=0)
Set window name. This is typically done via the window manager.
virtual void SetLimits(ELimit limits=TGNumberFormat::kNELNoLimits, Double_t min=0, Double_t max=1)
virtual Double_t GetNumber() const
Book space in a file, create I/O buffers, to fill them, (un)compress them.
Implementation of a Decision Tree.
TGTextButton * fDrawButton
TMVA::DecisionTree * ReadTree(TString *&vars, Int_t itree)
void DrawTree(Int_t itree)
TGHorizontalFrame * fButtons
StatDialogBDT(TString dataset, const TGWindow *p, TString wfile, TString methName="BDT", Int_t itree=0)
void DrawNode(TMVA::DecisionTreeNode *n, Double_t x, Double_t y, Double_t xscale, Double_t yscale, TString *vars)
recursively puts an entries in the histogram for the node and its daughters
static StatDialogBDT * fThis
TGTextButton * fCloseButton
virtual const char * GetName() const
Returns name of object.
Collectable string class.
const TString & GetString() const
virtual void Draw(Option_t *option="")
Default Draw method for all objects.
A Pave (see TPave) with text, lines or/and boxes inside.
virtual TText * AddText(Double_t x1, Double_t y1, const char *label)
Add a new Text line to this pavetext at given coordinates.
virtual void Draw(Option_t *option="")
Draw this pavetext with its current attributes.
virtual void SetBorderSize(Int_t bordersize=4)
Bool_t Connect(const char *signal, const char *receiver_class, void *receiver, const char *slot)
Non-static method is used to connect from the signal of this object to the receiver slot.
Bool_t EndsWith(const char *pat, ECaseCompare cmp=kExact) const
Return true if string ends with the specified string.
const char * Data() const
TStyle objects may be created to define special styles.
void SetCanvasColor(Color_t color=19)
void SetPalette(Int_t ncolors=kBird, Int_t *colors=0, Float_t alpha=1.)
See TColor::SetPalette.
Color_t GetCanvasColor() const
XMLNodePointer_t GetChild(XMLNodePointer_t xmlnode, Bool_t realnode=kTRUE)
returns first child of xmlnode
XMLNodePointer_t DocGetRootElement(XMLDocPointer_t xmldoc)
returns root node of document
XMLDocPointer_t ParseFile(const char *filename, Int_t maxbuf=100000)
Parses content of file and tries to produce xml structures.
XMLNodePointer_t GetNext(XMLNodePointer_t xmlnode, Bool_t realnode=kTRUE)
return next to xmlnode node if realnode==kTRUE, any special nodes in between will be skipped
void Initialize(Bool_t useTMVAStyle=kTRUE)
TFile * OpenFile(const TString &fin)
void imgconv(TCanvas *c, const TString &fname)
void BDT_DeleteTBar(int i)
void BDT(TString dataset, const TString &fin="TMVA.root")