ROOT  6.07/01
Reference Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 
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 
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 = (TFile*)gROOT->GetListOfFiles()->FindObject(fin);
40  if (!file || !file->IsOpen()) {
41  file = new TFile(fin);
42  }
43 
44  gDirectory->pwd();
45  TDirectory* dir = (TDirectory*)gDirectory->Get( dirName );
46  if (!dir) {
47  cout << "Could not locate directory '" << dirName << "' in file: " << fin << endl;
48  cout << " Try again .. " <<endl;
49  gDirectory->cd("/");
50  gDirectory->pwd();
51  dir = (TDirectory*)gDirectory->Get( dirName );
52  if (!dir) {
53  cout << "Nope ..Could not locate directory '" << dirName << "' in file: " << fin << endl;
54  return;
55  }
56  }
57  dir->cd();
58 
59  // how many variables are in the directory?
61  cout << "found number of variables='" << noVar<< endl;
62  std::vector<TString> Var(noVar);
63 
64  TIter next(dir->GetListOfKeys());
65  Int_t it=0;
66 
67  TKey *key;
68  while ( (key = (TKey*)next()) ) {
69 
70  // make sure, that we only look at histograms
71  TClass *cl = gROOT->GetClass(key->GetClassName());
72  if (cl->InheritsFrom("TH1")) {
73  TH1 *sig = (TH1*)key->ReadObj();
74  TString hname = sig->GetName();
75  // check for all signal histograms
76  if (hname.Contains("__Signal") || (hname.Contains("__Regression") && !hname.Contains("__Regression_target"))) { // found a new signal plot
77  hname.ReplaceAll(extension,"");
78  hname.ReplaceAll("__Signal","");
79  hname.ReplaceAll("__Regression","");
80  Var[it] = hname;
81  ++it;
82  }
83  }
84  }
85  cout << "found histos for "<< it <<" variables='" << endl;
86 
87  for (Int_t ic=0;ic<it;ic++) {
88  cbar->AddButton( (Var[ic].Contains("_target") ?
89  Form( " Target: %s ", Var[ic].ReplaceAll("_target","").Data()) :
90  Form( " Variable: %s ", Var[ic].Data())),
91  Form( "TMVA::correlationscatters(\"%s\",\"%s\",\"%s\",\"%s\",%i)",
92  fin.Data(), Var[ic].Data(), dirName.Data(), title.Data(), (Int_t)isRegression ),
93  buttonType );
94  }
95 
96  // *** problems with this button below ROOT 5.19 ***
97 #if ROOT_VERSION_CODE < ROOT_VERSION(5,19,0)
98  cbar->AddButton( "Close", "CorrGui_DeleteTBar()", "Close this control bar", "button" );
99 #endif
100  // **********************************************
101 
102  // set the style
103  cbar->SetTextColor("blue");
104 
105  // there seems to be a bug in ROOT: font jumps back to default after pressing on >2 different buttons
106  // cbar->SetFont("-adobe-helvetica-bold-r-*-*-12-*-*-*-*-*-iso8859-1");
107 
108  // draw
109  cbar->Show();
110 
111  gROOT->SaveContext();
112 
113 }
114 
116 {
118 
119  // delete CorrGui_Global__cbar;
120  // CorrGui_Global__cbar = 0;
121 }
122 
void Show()
Show control bar.
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:37
void SetTextColor(const char *colorName)
Sets text color for control bar buttons, e.g.
virtual TList * GetListOfKeys() const
Definition: TDirectory.h:158
Int_t GetNumberOfInputVariables(TDirectory *dir)
Definition: tmvaglob.cxx:413
ClassImp(TSeqCollection) Int_t TSeqCollection TIter next(this)
Return index of object in collection.
TString & ReplaceAll(const TString &s1, const TString &s2)
Definition: TString.h:635
A ROOT file is a suite of consecutive data records (TKey instances) with a well defined format...
Definition: TFile.h:45
#define gROOT
Definition: TROOT.h:344
Basic string class.
Definition: TString.h:137
virtual const char * GetClassName() const
Definition: TKey.h:77
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
const char * Data() const
Definition: TString.h:349
virtual Bool_t IsOpen() const
Returns kTRUE in case file is open and kFALSE if file is not open.
Definition: TFile.cxx:1373
std::vector< std::vector< double > > Data
Book space in a file, create I/O buffers, to fill them, (un)compress them.
Definition: TKey.h:30
void CorrGui(TString fin="TMVA.root", TString dirName="InputVariables_Id", TString title="TMVA Input Variable", Bool_t isRegression=kFALSE)
Definition: CorrGui.cxx:14
void CorrGui_DeleteTBar()
Definition: CorrGui.cxx:115
TString dirName
Definition: demos.C:9
void Initialize(Bool_t useTMVAStyle=kTRUE)
Definition: tmvaglob.cxx:176
TPaveLabel title(3, 27.1, 15, 28.7,"ROOT Environment and Tools")
char * Form(const char *fmt,...)
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:51
The ROOT global object gROOT contains a list of all defined classes.
Definition: TClass.h:81
const char * extension
Definition: civetweb.c:2467
tuple file
Definition: fildir.py:20
Describe directory structure in memory.
Definition: TDirectory.h:44
void dir(char *path=0)
Definition: rootalias.C:30
The TH1 histogram class.
Definition: TH1.h:80
virtual TObject * ReadObj()
To read a TObject* from the file.
Definition: TKey.cxx:727
virtual Bool_t cd(const char *path=0)
Change current directory to "this" directory.
Definition: TDirectory.cxx:433
void ReplaceAll(std::string &str, const std::string &from, const std::string &to, bool recurse=false)
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
Definition: TString.h:567
#define gDirectory
Definition: TDirectory.h:221
Bool_t InheritsFrom(const char *cl) const
Return kTRUE if this class inherits from a class with name "classname".
Definition: TClass.cxx:4498
void DestroyCanvases()
Definition: tmvaglob.cxx:166