30std::vector<TControlBar*> TMVA::BDT_Global__cbar;
60 fMethName( methName ),
100 fInput->
Connect(
"ValueSet(Long_t)",
"TMVA::StatDialogBDT",
this,
"SetItree()");
116 if(!fWfile.EndsWith(
".xml") ){
117 std::ifstream fin( fWfile );
119 cout <<
"*** ERROR: Weight file: " << fWfile <<
" does not exist" << endl;
127 while (!
dummy.Contains(
"NTrees")) {
132 cout <<
"*** Huge problem: could not locate term \"NTrees\" in BDT weight file: "
134 cout <<
"==> panic abort (please contact the TMVA authors)" << endl;
140 fNtrees =
dummy.ReplaceAll(
"\"",
"").Atoi();
149 if(nodeName==
"Weights") {
156 cout <<
"--- Found " << fNtrees <<
" decision trees in weight file" << endl;
170 if (xsize>0.15) xsize=0.1;
171 if (
n->GetLeft() != NULL){
177 if (
n->GetRight() != NULL){
196 sprintf( buffer,
"N=%f",
n->GetNEvents() );
197 if (
n->GetNEvents()>0) t->
AddText(buffer);
198 sprintf( buffer,
"S/(S+B)=%4.3f",
n->GetPurity() );
201 if (
n->GetNodeType() == 0){
202 if (
n->GetCutType()){
215 cout <<
"--- Reading Tree " << itree <<
" from weight file: " << fWfile << endl;
217 if(!fWfile.EndsWith(
".xml") ){
218 std::ifstream fin( fWfile );
220 cout <<
"*** ERROR: Weight file: " << fWfile <<
" does not exist" << endl;
228 if (itree >= fNtrees) {
229 cout <<
"*** ERROR: requested decision tree: " << itree
230 <<
", but number of trained trees only: " << fNtrees << endl;
242 fin >>
dummy >> nVars;
247 vars[nVars]=
"FisherCrit";
251 sprintf(buffer,
"Tree %d",itree);
253 while (!
dummy.Contains(buffer)) {
254 fin.getline(
line,256);
263 if (itree >= fNtrees) {
264 cout <<
"*** ERROR: requested decision tree: " << itree
265 <<
", but number of trained trees only: " << fNtrees << endl;
276 if(nodeName==
"Variables"){
280 for (
Int_t i = 0; i < nVars; i++){
284 vars[nVars]=
"FisherCrit";
286 if(nodeName==
"Weights")
break;
304 UInt_t depth =
d->GetTotalTreeDepth();
307 cout <<
"--- Tree depth: " << depth << endl;
319 Int_t MyPalette[100];
320 for (
int i=0;i<100;i++) MyPalette[i] = fColorOffset+i;
327 TString cbuffer =
Form(
"Reading weight file: %s", fWfile.Data() );
328 TString tbuffer =
Form(
"Decision Tree no.: %d", itree );
329 if (!fCanvas) fCanvas =
new TCanvas(
"c1", cbuffer, 200, 0, 1000, 600 );
330 else fCanvas->Clear();
351 signalleaf->
AddText(
"Pure Signal Nodes");
355 ydown = ydown - ystep/2.5 -dy;
356 yup = yup - ystep/2.5 -dy;
362 backgroundleaf->
AddText(
"Pure Backgr. Nodes");
364 backgroundleaf->
Draw();
368 TString fname = fDataset+
Form(
"/plots/%s_%i", fMethName.Data(), itree );
369 cout <<
"--- Creating image: " << fname << endl;
391 cout <<
"*** Error in macro \"BDT.C\": cannot find directory \"Method_BDT\" in file: " << fin << endl;
398 std::vector<TString> methname;
399 std::vector<TString> path;
400 std::vector<TString> wfile;
401 while ((key = (
TKey*)next())) {
404 cout <<
"*** Error in macro \"BDT.C\": cannot find sub-directory: " << key->
GetName()
405 <<
" in directory: " << dir->
GetName() << endl;
412 if (!strPath || !strWFile) {
413 cout <<
"*** Error in macro \"BDT.C\": could not find TObjStrings \"TrainingPath\" and/or \"WeightFileName\" *** " << endl;
414 cout <<
"*** Maybe you are using TMVA >= 3.8.15 with an older training target file ? *** " << endl;
418 methname.push_back( key->GetName() );
420 wfile .push_back( strWFile->
GetString() );
425 BDT_Global__cbar.push_back(cbar);
427 for (
UInt_t im=0; im<path.size(); im++) {
429 if (fname[fname.
Length()-1] !=
'/') fname +=
"/";
431 TString macro =
Form(
"TMVA::BDT(\"%s\",0,\"%s\",\"%s\")",dataset.
Data(), fname.
Data(), methname[im].Data() );
432 cbar->
AddButton( fname, macro,
"Plot decision trees from this weight file",
"button" );
448 delete BDT_Global__cbar[i];
449 BDT_Global__cbar[i] = 0;
460 wfile = dataset+
"/weights/TMVAnalysis_test_BDT.weights.txt";
463 std::ifstream fin( wfile );
465 cout <<
"*** ERROR: Weight file: " << wfile <<
" does not exist" << endl;
469 std::cout <<
"test1";
473 StatDialogBDT* gGui =
new StatDialogBDT(dataset,
gClient->GetRoot(), wfile, methName, itree );
475 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")