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