Logo ROOT  
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
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 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 // 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
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
#define gDirectory
Definition: TDirectory.h:223
#define gROOT
Definition: TROOT.h:415
char * Form(const char *fmt,...)
const char * extension
Definition: civetweb.c:7793
TClass instances represent classes, structs and namespaces in the ROOT type system.
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:4708
A Control Bar is a fully user configurable tool which provides fast access to frequently used operati...
Definition: TControlBar.h:22
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.
Definition: TDirectory.h:34
virtual TList * GetListOfKeys() const
Definition: TDirectory.h:160
virtual Bool_t cd(const char *path=nullptr)
Change current directory to "this" directory.
Definition: TDirectory.cxx:497
A ROOT file is a suite of consecutive data records (TKey instances) with a well defined format.
Definition: TFile.h:48
The TH1 histogram class.
Definition: TH1.h:56
Book space in a file, create I/O buffers, to fill them, (un)compress them.
Definition: TKey.h:24
virtual const char * GetClassName() const
Definition: TKey.h:72
virtual TObject * ReadObj()
To read a TObject* from the file.
Definition: TKey.cxx:729
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:47
Basic string class.
Definition: TString.h:131
TString & ReplaceAll(const TString &s1, const TString &s2)
Definition: TString.h:687
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
Definition: TString.h:619
double Var(const RVec< T > &v)
Get the variance of the elements of an RVec.
Definition: RVec.hxx:861
void Initialize(Bool_t useTMVAStyle=kTRUE)
Definition: tmvaglob.cxx:176
Int_t GetNumberOfInputVariables(TDirectory *dir)
Definition: tmvaglob.cxx:413
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)
Definition: file.py:1