Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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
14void 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 TString::Format( " Target: %s ", Var[ic].ReplaceAll("_target","").Data()) :
87 TString::Format( " Variable: %s ", Var[ic].Data())),
88 TString::Format( "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 // set the style
93 cbar->SetTextColor("blue");
94
95 // there seems to be a bug in ROOT: font jumps back to default after pressing on >2 different buttons
96 // cbar->SetFont("-adobe-helvetica-bold-r-*-*-12-*-*-*-*-*-iso8859-1");
97
98 // draw
99 cbar->Show();
100
101 gROOT->SaveContext();
102
103}
104
106{
108
109 // delete CorrGui_Global__cbar;
110 // CorrGui_Global__cbar = 0;
111}
112
bool Bool_t
Definition RtypesCore.h:63
int Int_t
Definition RtypesCore.h:45
#define gDirectory
Definition TDirectory.h:384
#define gROOT
Definition TROOT.h:406
static char * Format(const char *format, va_list ap)
Format a string in a circular formatting buffer (using a printf style format descriptor).
Definition TString.cxx:2442
const char * extension
Definition civetweb.c:8026
TClass instances represent classes, structs and namespaces in the ROOT type system.
Definition TClass.h:81
Bool_t InheritsFrom(const char *cl) const override
Return kTRUE if this class inherits from a class with name "classname".
Definition TClass.cxx:4874
static TClass * GetClass(const char *name, Bool_t load=kTRUE, Bool_t silent=kFALSE)
Static method returning pointer to TClass of the specified class name.
Definition TClass.cxx:2968
A Control Bar is a fully user configurable tool which provides fast access to frequently used operati...
Definition TControlBar.h:26
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.:
TDirectory * GetDirectory(const char *apath, Bool_t printError=false, const char *funcname="GetDirectory") override
Find a directory named "apath".
Describe directory structure in memory.
Definition TDirectory.h:45
virtual TObject * Get(const char *namecycle)
Return pointer to object identified by namecycle.
virtual Bool_t cd()
Change current directory to "this" directory.
virtual TList * GetListOfKeys() const
Definition TDirectory.h:223
A ROOT file is an on-disk file, usually with extension .root, that stores objects in a file-system-li...
Definition TFile.h:53
TH1 is the base class of all histogram classes in ROOT.
Definition TH1.h:59
Book space in a file, create I/O buffers, to fill them, (un)compress them.
Definition TKey.h:28
virtual const char * GetClassName() const
Definition TKey.h:75
virtual TObject * ReadObj()
To read a TObject* from the file.
Definition TKey.cxx:758
const char * GetName() const override
Returns name of object.
Definition TNamed.h:47
Basic string class.
Definition TString.h:139
TString & ReplaceAll(const TString &s1, const TString &s2)
Definition TString.h:704
static TString Format(const char *fmt,...)
Static method which formats a string using a printf style format descriptor and return a TString.
Definition TString.cxx:2378
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
Definition TString.h:632
double Var(const RVec< T > &v)
Get the variance of the elements of an RVec.
Definition RVec.hxx:2065
void ReplaceAll(std::string &str, const std::string &from, const std::string &to, bool recurse=false)
void Initialize(Bool_t useTMVAStyle=kTRUE)
Definition tmvaglob.cxx:176
Int_t GetNumberOfInputVariables(TDirectory *dir)
Definition tmvaglob.cxx:420
void DestroyCanvases()
Definition tmvaglob.cxx:166
TFile * OpenFile(const TString &fin)
Definition tmvaglob.cxx:192
void CorrGui_DeleteTBar()
void CorrGui(TString dataset, TString fin="TMVA.root", TString dirName="InputVariables_Id", TString title="TMVA Input Variable", Bool_t isRegression=kFALSE)