Logo ROOT   6.12/07
Reference Guide
CorrGui.cxx
Go to the documentation of this file.
1 #include "TMVA/CorrGui.h"
2 #include "TMVA/Config.h"
3 ///////////
4 //New Gui for easier plotting of scatter corelations
5 // L. Ancu 04/04/07
6 ////////////
7 #include <iostream>
8 
9 #include "TControlBar.h"
10 
11 
12 //static TControlBar* CorrGui_Global__cbar = 0;
13 
14 void TMVA::CorrGui(TString dataset, TString fin, TString dirName , TString title ,
15  Bool_t isRegression )
16 {
17  // Use this script in order to run the various individual macros
18  // that plot the output of TMVA (e.g. running TMVAnalysis.C),
19  // stored in the file "TMVA.root"
20  // for further documentation, look in the individual macros
21 
22  cout << "--- Open CorrGui for input file: " << fin << " and type: " << dirName << endl;
23 
24  // destroy all open cavases
25  // TMVAGlob::DestroyCanvases();
27 
28  TString extension = dirName;
29  extension.ReplaceAll( "InputVariables", "" );
30 
31  // create the control bar
32  TControlBar* cbar = new TControlBar( "vertical", title, 50, 50 );
33  // CorrGui_Global__cbar = cbar;
34 
35  const char* buttonType = "button";
36 
37  // configure buttons
38  // checks if file with name "fin" is already open, and if not opens one
39  TFile* file = TMVAGlob::OpenFile( fin );
40 
41  gDirectory->pwd();
42  TDirectory* dir = (TDirectory*)file->GetDirectory(dataset)->Get(dirName );
43  if (!dir) {
44  cout << "Could not locate directory '" << dirName << "' in file: " << fin << endl;
45  cout << " Try again .. " <<endl;
46  gDirectory->cd("/");
47  gDirectory->pwd();
48  dir = (TDirectory*)gDirectory->Get( dirName );
49  if (!dir) {
50  cout << "Nope ..Could not locate directory '" << dirName << "' in file: " << fin << endl;
51  return;
52  }
53  }
54  dir->cd();
55 
56  // how many variables are in the directory?
58  cout << "found number of variables='" << noVar<< endl;
59  std::vector<TString> Var(noVar);
60 
61  TIter next(dir->GetListOfKeys());
62  Int_t it=0;
63 
64  TKey *key;
65  while ( (key = (TKey*)next()) ) {
66 
67  // make sure, that we only look at histograms
68  TClass *cl = gROOT->GetClass(key->GetClassName());
69  if (cl->InheritsFrom("TH1")) {
70  TH1 *sig = (TH1*)key->ReadObj();
71  TString hname = sig->GetName();
72  // check for all signal histograms
73  if (hname.Contains("__Signal") || (hname.Contains("__Regression") && !hname.Contains("__Regression_target"))) { // found a new signal plot
74  hname.ReplaceAll(extension,"");
75  hname.ReplaceAll("__Signal","");
76  hname.ReplaceAll("__Regression","");
77  Var[it] = hname;
78  ++it;
79  }
80  }
81  }
82  cout << "found histos for "<< it <<" variables='" << endl;
83 
84  for (Int_t ic=0;ic<it;ic++) {
85  cbar->AddButton( (Var[ic].Contains("_target") ?
86  Form( " Target: %s ", Var[ic].ReplaceAll("_target","").Data()) :
87  Form( " Variable: %s ", Var[ic].Data())),
88  Form( "TMVA::correlationscatters(\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",%i)",dataset.Data(),fin.Data(), Var[ic].Data(), dirName.Data(), title.Data(), (Int_t)isRegression ),
89  buttonType );
90  }
91 
92  // *** problems with this button below ROOT 5.19 ***
93 #if ROOT_VERSION_CODE < ROOT_VERSION(5,19,0)
94  cbar->AddButton( "Close", "CorrGui_DeleteTBar()", "Close this control bar", "button" );
95 #endif
96  // **********************************************
97 
98  // set the style
99  cbar->SetTextColor("blue");
100 
101  // there seems to be a bug in ROOT: font jumps back to default after pressing on >2 different buttons
102  // cbar->SetFont("-adobe-helvetica-bold-r-*-*-12-*-*-*-*-*-iso8859-1");
103 
104  // draw
105  cbar->Show();
106 
107  gROOT->SaveContext();
108 
109 }
110 
112 {
114 
115  // delete CorrGui_Global__cbar;
116  // CorrGui_Global__cbar = 0;
117 }
118 
void Show()
Show control bar.
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:47
void AddButton(TControlBarButton *button)
Add button.
A Control Bar is a fully user configurable tool which provides fast access to frequently used operati...
Definition: TControlBar.h:22
virtual TList * GetListOfKeys() const
Definition: TDirectory.h:150
void SetTextColor(const char *colorName)
Sets text color for control bar buttons, e.g.
Int_t GetNumberOfInputVariables(TDirectory *dir)
Definition: tmvaglob.cxx:413
virtual TObject * Get(const char *namecycle)
Return pointer to object identified by namecycle.
Definition: TDirectory.cxx:805
TString & ReplaceAll(const TString &s1, const TString &s2)
Definition: TString.h:638
TFile * OpenFile(const TString &fin)
Definition: tmvaglob.cxx:192
virtual const char * GetClassName() const
Definition: TKey.h:71
A ROOT file is a suite of consecutive data records (TKey instances) with a well defined format...
Definition: TFile.h:46
#define gROOT
Definition: TROOT.h:402
Basic string class.
Definition: TString.h:125
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
Book space in a file, create I/O buffers, to fill them, (un)compress them.
Definition: TKey.h:24
void CorrGui(TString dataset, TString fin="TMVA.root", TString dirName="InputVariables_Id", TString title="TMVA Input Variable", Bool_t isRegression=kFALSE)
void CorrGui_DeleteTBar()
void Initialize(Bool_t useTMVAStyle=kTRUE)
Definition: tmvaglob.cxx:176
char * Form(const char *fmt,...)
The ROOT global object gROOT contains a list of all defined classes.
Definition: TClass.h:75
Bool_t InheritsFrom(const char *cl) const
Return kTRUE if this class inherits from a class with name "classname".
Definition: TClass.cxx:4688
virtual TDirectory * GetDirectory(const char *apath, Bool_t printError=false, const char *funcname="GetDirectory")
Find a directory named "apath".
const char * extension
Definition: civetweb.c:5005
Describe directory structure in memory.
Definition: TDirectory.h:34
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
Definition: TString.h:570
The TH1 histogram class.
Definition: TH1.h:56
virtual TObject * ReadObj()
To read a TObject* from the file.
Definition: TKey.cxx:722
virtual Bool_t cd(const char *path=0)
Change current directory to "this" directory.
Definition: TDirectory.cxx:497
Definition: file.py:1
#define gDirectory
Definition: TDirectory.h:213
void DestroyCanvases()
Definition: tmvaglob.cxx:166
const char * Data() const
Definition: TString.h:345