Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files 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 
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();
26  TMVAGlob::Initialize( );
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?
57  Int_t noVar = TMVAGlob::GetNumberOfInputVariables(dir);
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 
105 void TMVA::CorrGui_DeleteTBar()
106 {
107  TMVAGlob::DestroyCanvases();
108 
109  // delete CorrGui_Global__cbar;
110  // CorrGui_Global__cbar = 0;
111 }
112