25std::vector<TControlBar*> TMVA::BDT_Global__cbar;
54 fMethName( methName ),
94 fInput->
Connect(
"ValueSet(Long_t)",
"TMVA::StatDialogBDT",
this,
"SetItree()");
110 if(!fWfile.EndsWith(
".xml") ){
111 std::ifstream fin( fWfile );
113 cout <<
"*** ERROR: Weight file: " << fWfile <<
" does not exist" << endl;
126 cout <<
"*** Huge problem: could not locate term \"NTrees\" in BDT weight file: "
128 cout <<
"==> panic abort (please contact the TMVA authors)" << endl;
143 if(nodeName==
"Weights") {
150 cout <<
"--- Found " << fNtrees <<
" decision trees in weight file" << endl;
164 if (xsize>0.15) xsize=0.1;
165 if (
n->GetLeft() != NULL){
171 if (
n->GetRight() != NULL){
190 sprintf( buffer,
"N=%f",
n->GetNEvents() );
191 if (
n->GetNEvents()>0) t->
AddText(buffer);
192 sprintf( buffer,
"S/(S+B)=%4.3f",
n->GetPurity() );
195 if (
n->GetNodeType() == 0){
196 if (
n->GetCutType()){
209 cout <<
"--- Reading Tree " << itree <<
" from weight file: " << fWfile << endl;
211 if(!fWfile.EndsWith(
".xml") ){
212 std::ifstream fin( fWfile );
214 cout <<
"*** ERROR: Weight file: " << fWfile <<
" does not exist" << endl;
222 if (itree >= fNtrees) {
223 cout <<
"*** ERROR: requested decision tree: " << itree
224 <<
", but number of trained trees only: " << fNtrees << endl;
231 while (!dummy.
Contains(
"#VAR")) fin >> dummy;
232 fin >> dummy >> dummy >> dummy;
236 fin >> dummy >> nVars;
240 for (
Int_t i = 0; i < nVars; i++) fin >> vars[i] >> dummy >> dummy >> dummy >> dummy;
241 vars[nVars]=
"FisherCrit";
245 sprintf(buffer,
"Tree %d",itree);
248 fin.getline(
line,256);
257 if (itree >= fNtrees) {
258 cout <<
"*** ERROR: requested decision tree: " << itree
259 <<
", but number of trained trees only: " << fNtrees << endl;
270 if(nodeName==
"Variables"){
274 for (
Int_t i = 0; i < nVars; i++){
278 vars[nVars]=
"FisherCrit";
280 if(nodeName==
"Weights")
break;
298 UInt_t depth =
d->GetTotalTreeDepth();
301 cout <<
"--- Tree depth: " << depth << endl;
313 Int_t MyPalette[100];
314 for (
int i=0;i<100;i++) MyPalette[i] = fColorOffset+i;
321 TString cbuffer =
Form(
"Reading weight file: %s", fWfile.Data() );
322 TString tbuffer =
Form(
"Decision Tree no.: %d", itree );
323 if (!fCanvas) fCanvas =
new TCanvas(
"c1", cbuffer, 200, 0, 1000, 600 );
324 else fCanvas->Clear();
345 signalleaf->
AddText(
"Pure Signal Nodes");
349 ydown = ydown - ystep/2.5 -dy;
350 yup = yup - ystep/2.5 -dy;
356 backgroundleaf->
AddText(
"Pure Backgr. Nodes");
358 backgroundleaf->
Draw();
362 TString fname = fDataset+
Form(
"/plots/%s_%i", fMethName.Data(), itree );
363 cout <<
"--- Creating image: " << fname << endl;
385 cout <<
"*** Error in macro \"BDT.C\": cannot find directory \"Method_BDT\" in file: " << fin << endl;
392 std::vector<TString> methname;
393 std::vector<TString> path;
394 std::vector<TString> wfile;
395 while ((key = (
TKey*)next())) {
398 cout <<
"*** Error in macro \"BDT.C\": cannot find sub-directory: " << key->
GetName()
399 <<
" in directory: " << dir->
GetName() << endl;
406 if (!strPath || !strWFile) {
407 cout <<
"*** Error in macro \"BDT.C\": could not find TObjStrings \"TrainingPath\" and/or \"WeightFileName\" *** " << endl;
408 cout <<
"*** Maybe you are using TMVA >= 3.8.15 with an older training target file ? *** " << endl;
412 methname.push_back( key->GetName() );
414 wfile .push_back( strWFile->
GetString() );
419 BDT_Global__cbar.push_back(cbar);
421 for (
UInt_t im=0; im<path.size(); im++) {
423 if (fname[fname.
Length()-1] !=
'/') fname +=
"/";
425 TString macro =
Form(
"TMVA::BDT(\"%s\",0,\"%s\",\"%s\")",dataset.
Data(), fname.
Data(), methname[im].Data() );
426 cbar->
AddButton( fname, macro,
"Plot decision trees from this weight file",
"button" );
442 delete BDT_Global__cbar[i];
443 BDT_Global__cbar[i] = 0;
454 wfile = dataset+
"/weights/TMVAnalysis_test_BDT.weights.txt";
457 std::ifstream fin( wfile );
459 cout <<
"*** ERROR: Weight file: " << wfile <<
" does not exist" << endl;
463 std::cout <<
"test1";
467 StatDialogBDT* gGui =
new StatDialogBDT(dataset,
gClient->GetRoot(), wfile, methName, itree );
469 gGui->DrawTree(itree );
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.
virtual void MapWindow()
map window
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.
static void SetIsTraining(bool on)
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.
Int_t Atoi() const
Return integer value of string.
Bool_t EndsWith(const char *pat, ECaseCompare cmp=kExact) const
Return true if string ends with the specified string.
const char * Data() const
TString & ReplaceAll(const TString &s1, const TString &s2)
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) 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")