1 |
benhoob |
1.1 |
#include "tmvaglob.C"
|
2 |
|
|
|
3 |
|
|
// this macro plots the correlation matrix of the various input
|
4 |
|
|
// variables used in TMVA (e.g. running TMVAnalysis.C). Signal and
|
5 |
|
|
// Background are plotted separately
|
6 |
|
|
|
7 |
|
|
// input: - Input file (result from TMVA),
|
8 |
|
|
// - use of colors or grey scale
|
9 |
|
|
// - use of TMVA plotting TStyle
|
10 |
|
|
void correlations( TString fin = "TMVA.root", Bool_t isRegression = kFALSE,
|
11 |
|
|
Bool_t greyScale = kFALSE, Bool_t useTMVAStyle = kTRUE )
|
12 |
|
|
{
|
13 |
|
|
|
14 |
|
|
// set style and remove existing canvas'
|
15 |
|
|
TMVAGlob::Initialize( useTMVAStyle );
|
16 |
|
|
|
17 |
|
|
// checks if file with name "fin" is already open, and if not opens one
|
18 |
|
|
TFile* file = TMVAGlob::OpenFile( fin );
|
19 |
|
|
|
20 |
|
|
// signal and background or regression problem
|
21 |
|
|
Int_t ncls = (isRegression ? 1 : 2 );
|
22 |
|
|
TString hName[2] = { "CorrelationMatrixS", "CorrelationMatrixB" };
|
23 |
|
|
if (isRegression) hName[0]= "CorrelationMatrix";
|
24 |
|
|
const Int_t width = 600;
|
25 |
|
|
for (Int_t ic=0; ic<ncls; ic++) {
|
26 |
|
|
|
27 |
|
|
TH2* h2 = file->Get( hName[ic] );
|
28 |
|
|
if(!h2) {
|
29 |
|
|
cout << "Did not find histogram " << hName[ic] << " in " << fin << endl;
|
30 |
|
|
continue;
|
31 |
|
|
}
|
32 |
|
|
|
33 |
|
|
TCanvas* c = new TCanvas( hName[ic],
|
34 |
|
|
Form("Correlations between MVA input variables (%s)",
|
35 |
|
|
(isRegression ? "" : (ic==0 ? "signal" : "background"))),
|
36 |
|
|
ic*(width+5)+200, 0, width, width );
|
37 |
|
|
Float_t newMargin1 = 0.13;
|
38 |
|
|
Float_t newMargin2 = 0.15;
|
39 |
|
|
if (TMVAGlob::UsePaperStyle) newMargin2 = 0.13;
|
40 |
|
|
|
41 |
|
|
c->SetGrid();
|
42 |
|
|
c->SetTicks();
|
43 |
|
|
c->SetLeftMargin ( newMargin2 );
|
44 |
|
|
c->SetBottomMargin( newMargin2 );
|
45 |
|
|
c->SetRightMargin ( newMargin1 );
|
46 |
|
|
c->SetTopMargin ( newMargin1 );
|
47 |
|
|
gStyle->SetPalette( 1, 0 );
|
48 |
|
|
|
49 |
|
|
|
50 |
|
|
gStyle->SetPaintTextFormat( "3g" );
|
51 |
|
|
|
52 |
|
|
h2->SetMarkerSize( 1.5 );
|
53 |
|
|
h2->SetMarkerColor( 0 );
|
54 |
|
|
Float_t labelSize = 0.040;
|
55 |
|
|
h2->GetXaxis()->SetLabelSize( labelSize );
|
56 |
|
|
h2->GetYaxis()->SetLabelSize( labelSize );
|
57 |
|
|
h2->LabelsOption( "d" );
|
58 |
|
|
h2->SetLabelOffset( 0.011 );// label offset on x axis
|
59 |
|
|
|
60 |
|
|
h2->Draw("colz"); // color pads
|
61 |
|
|
c->Update();
|
62 |
|
|
|
63 |
|
|
// modify properties of paletteAxis
|
64 |
|
|
TPaletteAxis* paletteAxis = (TPaletteAxis*)h2->GetListOfFunctions()->FindObject( "palette" );
|
65 |
|
|
paletteAxis->SetLabelSize( 0.03 );
|
66 |
|
|
paletteAxis->SetX1NDC( paletteAxis->GetX1NDC() + 0.02 );
|
67 |
|
|
|
68 |
|
|
h2->Draw("textsame"); // add text
|
69 |
|
|
|
70 |
|
|
// add comment
|
71 |
|
|
TText* t = new TText( 0.53, 0.88, "Linear correlation coefficients in %" );
|
72 |
|
|
t->SetNDC();
|
73 |
|
|
t->SetTextSize( 0.026 );
|
74 |
|
|
t->AppendPad();
|
75 |
|
|
|
76 |
|
|
// TMVAGlob::plot_logo( );
|
77 |
|
|
c->Update();
|
78 |
|
|
|
79 |
|
|
TString fname = "plots/";
|
80 |
|
|
fname += hName[ic];
|
81 |
|
|
TMVAGlob::imgconv( c, fname );
|
82 |
|
|
}
|
83 |
|
|
}
|