Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
correlationsMultiClass.cxx
Go to the documentation of this file.
2#include "TH2.h"
3#include "TPaletteAxis.h"
4#include "TMVA/Config.h"
5
6
7// this macro plots the correlation matrix of the various input
8// variables used in TMVA (e.g. running TMVAnalysis.C). Signal and
9// Background are plotted separately
10
11// input: - Input file (result from TMVA),
12// - use of colors or grey scale
13// - use of TMVA plotting TStyle
14void TMVA::correlationsMultiClass(TString dataset, TString fin , Bool_t /* isRegression */ ,
15 Bool_t /* greyScale */ , Bool_t useTMVAStyle )
16{
17
18 // set style and remove existing canvas'
19 TMVAGlob::Initialize( useTMVAStyle );
20
21 // checks if file with name "fin" is already open, and if not opens one
22 TFile* file = TMVAGlob::OpenFile( fin );
23 TDirectory* vardir = (TDirectory*)file->GetDirectory(dataset.Data())->Get( "InputVariables_Id" );
24 std::vector<TString> classnames(TMVAGlob::GetClassNames(vardir));
25 // signal and background or regression problem
26 Int_t ncls = classnames.end() - classnames.begin();
27 std::vector<TString> hnames(classnames);
28
29 const Int_t width = 600;
30 for (Int_t ic=0; ic<ncls; ic++) {
31 hnames[ic] = TString("CorrelationMatrix")+ hnames[ic];
32 TH2* h2 = (TH2*)file->GetDirectory(dataset.Data())->Get( hnames[ic] );
33 cout << "Looking for histo " << hnames[ic] << " in " << fin << endl;
34 if(!h2) {
35 cout << "Did not find histogram " << hnames[ic] << " in " << fin << endl;
36 continue;
37 }
38
39 TCanvas* c = new TCanvas( hnames[ic],
40 TString::Format("Correlations between MVA input variables (%s)",
41 classnames[ic].Data()),
42 ic*(width+5)+200, 0, width, width );
43 Float_t newMargin1 = 0.13;
44 Float_t newMargin2 = 0.15;
45 if (gConfig().fVariablePlotting.fUsePaperStyle) newMargin2 = 0.13;
46
47 c->SetGrid();
48 c->SetTicks();
49 c->SetLeftMargin ( newMargin2 );
50 c->SetBottomMargin( newMargin2 );
51 c->SetRightMargin ( newMargin1 );
52 c->SetTopMargin ( newMargin1 );
53 gStyle->SetPalette( 1, 0 );
54
55
57
58 h2->SetMarkerSize( 1.5 );
59 h2->SetMarkerColor( 0 );
60 Float_t labelSize = 0.040;
61 h2->GetXaxis()->SetLabelSize( labelSize );
62 h2->GetYaxis()->SetLabelSize( labelSize );
63 h2->LabelsOption( "d" );
64 h2->SetLabelOffset( 0.011 );// label offset on x axis
65
66 h2->Draw("colz"); // color pads
67 c->Update();
68
69 // modify properties of paletteAxis
70 TPaletteAxis* paletteAxis = (TPaletteAxis*)h2->GetListOfFunctions()->FindObject( "palette" );
71 paletteAxis->SetLabelSize( 0.03 );
72 paletteAxis->SetX1NDC( paletteAxis->GetX1NDC() + 0.02 );
73
74 h2->Draw("textsame"); // add text
75
76 // add comment
77 TText* t = new TText( 0.53, 0.88, "Linear correlation coefficients in %" );
78 t->SetNDC();
79 t->SetTextSize( 0.026 );
80 t->AppendPad();
81
82 // TMVAGlob::plot_logo( );
83 c->Update();
84
85 TString fname = dataset+"/plots/";
86 fname += hnames[ic];
87 TMVAGlob::imgconv( c, fname );
88 }
89}
#define c(i)
Definition RSha256.hxx:101
bool Bool_t
Definition RtypesCore.h:63
int Int_t
Definition RtypesCore.h:45
float Float_t
Definition RtypesCore.h:57
Option_t Option_t width
R__EXTERN TStyle * gStyle
Definition TStyle.h:433
virtual void SetTextSize(Float_t tsize=1)
Set the text size.
Definition TAttText.h:47
The Canvas class.
Definition TCanvas.h:23
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
A ROOT file is an on-disk file, usually with extension .root, that stores objects in a file-system-li...
Definition TFile.h:53
Service class for 2-D histogram classes.
Definition TH2.h:30
virtual void AppendPad(Option_t *option="")
Append graphics object to current pad.
Definition TObject.cxx:184
The palette painting class.
virtual void SetLabelSize(Float_t size=0.035)
Double_t GetX1NDC() const
Definition TPave.h:59
virtual void SetX1NDC(Double_t x1)
Definition TPave.h:82
Basic string class.
Definition TString.h:139
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
void SetPaintTextFormat(const char *format="g")
Definition TStyle.h:383
void SetPalette(Int_t ncolors=kBird, Int_t *colors=nullptr, Float_t alpha=1.)
See TColor::SetPalette.
Definition TStyle.cxx:1884
Base class for several text objects.
Definition TText.h:22
virtual void SetNDC(Bool_t isNDC=kTRUE)
Set NDC mode on if isNDC = kTRUE, off otherwise.
Definition TText.cxx:823
void Initialize(Bool_t useTMVAStyle=kTRUE)
Definition tmvaglob.cxx:176
TFile * OpenFile(const TString &fin)
Definition tmvaglob.cxx:192
std::vector< TString > GetClassNames(TDirectory *dir)
Definition tmvaglob.cxx:469
void imgconv(TCanvas *c, const TString &fname)
Definition tmvaglob.cxx:212
Config & gConfig()
void correlationsMultiClass(TString dataset, TString fin="TMVA.root", Bool_t isRegression=kFALSE, Bool_t greyScale=kFALSE, Bool_t useTMVAStyle=kTRUE)