ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/benhoob/HWW/CorrGui.C
Revision: 1.1
Committed: Mon Feb 14 12:39:14 2011 UTC (14 years, 3 months ago) by benhoob
Content type: text/plain
Branch: MAIN
CVS Tags: HEAD
Log Message:
Initial commit

File Contents

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