Logo ROOT  
Reference Guide
Loading...
Searching...
No Matches
correlations.cxx
Go to the documentation of this file.
1#include "TMVA/correlations.h"
2#include "TMVA/Config.h"
3
4
5#include "TH2.h"
6#include "TPaletteAxis.h"
7
8// this macro plots the correlation matrix of the various input
9// variables used in TMVA (e.g. running TMVAnalysis.C). Signal and
10// Background are plotted separately
11
12// input: - Input file (result from TMVA),
13// - use of colors or grey scale
14// - use of TMVA plotting TStyle
15void TMVA::correlations(TString dataset, TString fin , Bool_t isRegression ,
16 Bool_t /* greyScale */ , Bool_t useTMVAStyle )
17{
18
19 // set style and remove existing canvas'
20 TMVAGlob::Initialize( useTMVAStyle );
21
22 // checks if file with name "fin" is already open, and if not opens one
23 TFile* file = TMVAGlob::OpenFile( fin );
24
25 // signal and background or regression problem
26 Int_t ncls = (isRegression ? 1 : 2 );
27 TString hName[2] = { "CorrelationMatrixS", "CorrelationMatrixB" };
28 if (isRegression) hName[0]= "CorrelationMatrix";
29 const Int_t width = 600;
30 for (Int_t ic=0; ic<ncls; ic++) {
31
32 TH2* h2 = dynamic_cast<TH2*> (file->GetDirectory(dataset.Data())->Get( hName[ic] ));
33 if(!h2) {
34 cout << "Did not find histogram " << hName[ic] << " in " << fin << endl;
35 continue;
36 }
37
38 TCanvas* c = new TCanvas( hName[ic],
39 TString::Format("Correlations between MVA input variables (%s)",
40 (isRegression ? "" : (ic==0 ? "signal" : "background"))),
41 ic*(width+5)+200, 0, width, width );
42 Float_t newMargin1 = 0.13;
43 Float_t newMargin2 = 0.15;
44 if (gConfig().fVariablePlotting.fUsePaperStyle) newMargin2 = 0.13;
45
46 c->SetGrid();
47 c->SetTicks();
48 c->SetLeftMargin ( newMargin2 );
49 c->SetBottomMargin( newMargin2 );
50 c->SetRightMargin ( newMargin1 );
51 c->SetTopMargin ( newMargin1 );
52 gStyle->SetPalette( 1, 0 );
53
54
55 gStyle->SetPaintTextFormat( "3g" );
56
57 h2->SetMarkerSize( 1.5 );
58 h2->SetMarkerColor( 0 );
59 Float_t labelSize = 0.040;
60 h2->GetXaxis()->SetLabelSize( labelSize );
61 h2->GetYaxis()->SetLabelSize( labelSize );
62 h2->LabelsOption( "d" );
63 h2->SetLabelOffset( 0.011 );// label offset on x axis
64
65 h2->Draw("colz"); // color pads
66 c->Update();
67
68 // modify properties of paletteAxis
69 TPaletteAxis* paletteAxis = (TPaletteAxis*)h2->GetListOfFunctions()->FindObject( "palette" );
70 paletteAxis->SetLabelSize( 0.03 );
71 paletteAxis->SetX1NDC( paletteAxis->GetX1NDC() + 0.02 );
72
73 h2->Draw("textsame"); // add text
74
75 // add comment
76 TText* t = new TText( 0.53, 0.88, "Linear correlation coefficients in %" );
77 t->SetNDC();
78 t->SetTextSize( 0.026 );
79 t->AppendPad();
80
81 // TMVAGlob::plot_logo( );
82 c->Update();
83
84 TString fname = dataset+"/plots/";
85 fname += hName[ic];
86 TMVAGlob::imgconv( c, fname );
87 }
88}
#define c(i)
Definition RSha256.hxx:101
int Int_t
Signed integer 4 bytes (int).
Definition RtypesCore.h:59
bool Bool_t
Boolean (0=false, 1=true) (bool).
Definition RtypesCore.h:77
float Float_t
Float 4 bytes (float).
Definition RtypesCore.h:71
externTStyle * gStyle
Definition TStyle.h:442
virtual void SetLabelSize(Float_t size=0.04)
Set size of axis labels.
Definition TAttAxis.cxx:184
virtual void SetMarkerColor(Color_t mcolor=1)
Set the marker color.
Definition TAttMarker.h:41
virtual void SetMarkerSize(Size_t msize=1)
Set the marker size.
Definition TAttMarker.h:48
virtual void SetTextSize(Float_t tsize=1)
Set the text size.
Definition TAttText.h:53
TDirectory * GetDirectory(const char *apath, Bool_t printError=false, const char *funcname="GetDirectory") override
Find a directory using apath.
virtual TObject * Get(const char *namecycle)
Return pointer to object identified by namecycle.
virtual void SetLabelOffset(Float_t offset=0.005, Option_t *axis="X")
Set offset between axis and axis' labels.
Definition Haxis.cxx:267
virtual void LabelsOption(Option_t *option="h", Option_t *axis="X")
Sort bins with labels or set option(s) to draw axis with labels.
Definition TH1.cxx:5464
TAxis * GetXaxis()
Definition TH1.h:571
TAxis * GetYaxis()
Definition TH1.h:572
void Draw(Option_t *option="") override
Draw this histogram with options.
Definition TH1.cxx:3097
TList * GetListOfFunctions() const
Definition TH1.h:488
TObject * FindObject(const char *name) const override
Find an object in this list using its name.
Definition TList.cxx:708
virtual void AppendPad(Option_t *option="")
Append graphics object to current pad.
Definition TObject.cxx:204
virtual void SetLabelSize(Float_t size=0.035)
Double_t GetX1NDC() const
Definition TPave.h:61
virtual void SetX1NDC(Double_t x1)
Definition TPave.h:84
Basic string class.
Definition TString.h:138
const char * Data() const
Definition TString.h:384
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:2385
virtual void SetNDC(Bool_t isNDC=kTRUE)
void Initialize(Bool_t useTMVAStyle=kTRUE)
Definition tmvaglob.cxx:176
TFile * OpenFile(const TString &fin)
Definition tmvaglob.cxx:192
void imgconv(TCanvas *c, const TString &fname)
Definition tmvaglob.cxx:212
Config & gConfig()
void correlations(TString dataset, TString fin="TMVA.root", Bool_t isRegression=kFALSE, Bool_t greyScale=kFALSE, Bool_t useTMVAStyle=kTRUE)