-
Notifications
You must be signed in to change notification settings - Fork 0
/
CorrGui.C
executable file
·112 lines (88 loc) · 3.62 KB
/
CorrGui.C
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
///////////
//New Gui for easier plotting of scatter corelations
// L. Ancu 04/04/07
////////////
#include <iostream>
#include "TControlBar.h"
#include "tmvaglob.C"
static TControlBar* CorrGui_Global__cbar = 0;
void CorrGui( TString fin = "TMVA.root", TString dirName = "InputVariables_Id", TString title = "TMVA Input Variable",
Bool_t isRegression = kFALSE )
{
// Use this script in order to run the various individual macros
// that plot the output of TMVA (e.g. running TMVAnalysis.C),
// stored in the file "TMVA.root"
// for further documentation, look in the individual macros
cout << "--- Open CorrGui for input file: " << fin << " and type: " << dirName << endl;
// destroy all open cavases
TMVAGlob::DestroyCanvases();
TString extension = dirName;
extension.ReplaceAll( "InputVariables", "" );
// create the control bar
TControlBar* cbar = new TControlBar( "vertical", title, 50, 50 );
CorrGui_Global__cbar = cbar;
const char* buttonType = "button";
const char* scriptpath = "./";
// configure buttons
// checks if file with name "fin" is already open, and if not opens one
TFile *file = (TFile*)gROOT->GetListOfFiles()->FindObject(fin);
if (!file || !file->IsOpen()) {
file = new TFile(fin);
}
TDirectory* dir = (TDirectory*)gDirectory->Get( dirName );
if (!dir) {
cout << "Could not locate directory '" << dirName << "' in file: " << fin << endl;
return;
}
dir->cd();
// how many variables are in the directory?
Int_t noVar = TMVAGlob::GetNumberOfInputVariables(dir);
cout << "found number of variables='" << noVar<< endl;
TString Var[noVar];
TIter next(dir->GetListOfKeys());
Int_t it=0;
TKey *key;
while ((key = (TKey*)next())) {
// make sure, that we only look at histograms
TClass *cl = gROOT->GetClass(key->GetClassName());
if (cl->InheritsFrom("TH1")) {
TH1 *sig = (TH1*)key->ReadObj();
TString hname = sig->GetName();
// check for all signal histograms
if (hname.Contains("__Signal") || (hname.Contains("__Regression") && !hname.Contains("__Regression_target"))) { // found a new signal plot
hname.ReplaceAll(extension,"");
hname.ReplaceAll("__Signal","");
hname.ReplaceAll("__Regression","");
Var[it] = hname;
++it;
}
}
}
cout << "found histos for "<< it <<" variables='" << endl;
for (Int_t ic=0;ic<it;ic++) {
cbar->AddButton( (Var[ic].Contains("_target") ?
Form( " Target: %s ", Var[ic].ReplaceAll("_target","").Data()) :
Form( " Variable: %s ", Var[ic].Data())),
Form( ".x %s/correlationscatters.C\(\"%s\",\"%s\",\"%s\",\"%s\",%i)",
scriptpath, fin.Data(), Var[ic].Data(), dirName.Data(), title.Data(), (Int_t)isRegression ),
buttonType );
}
// *** problems with this button below ROOT 5.19 ***
#if ROOT_VERSION_CODE < ROOT_VERSION(5,19,0)
cbar->AddButton( "Close", "CorrGui_DeleteTBar()", "Close this control bar", "button" );
#endif
// **********************************************
// set the style
cbar->SetTextColor("blue");
// there seems to be a bug in ROOT: font jumps back to default after pressing on >2 different buttons
// cbar->SetFont("-adobe-helvetica-bold-r-*-*-12-*-*-*-*-*-iso8859-1");
// draw
cbar->Show();
gROOT->SaveContext();
}
void CorrGui_DeleteTBar()
{
TMVAGlob::DestroyCanvases();
delete CorrGui_Global__cbar;
CorrGui_Global__cbar = 0;
}