Logo ROOT   6.14/05
Reference Guide
correlations.cxx
Go to the documentation of this file.
1 #include "TMVA/correlations.h"
2 #include "TMVA/Config.h"
3 
4 
5 #include "TH1.h"
6 #include "TH2.h"
7 #include "TPaletteAxis.h"
8 
9 // this macro plots the correlation matrix of the various input
10 // variables used in TMVA (e.g. running TMVAnalysis.C). Signal and
11 // Background are plotted separately
12 
13 // input: - Input file (result from TMVA),
14 // - use of colors or grey scale
15 // - use of TMVA plotting TStyle
16 void TMVA::correlations(TString dataset, TString fin , Bool_t isRegression ,
17  Bool_t /* greyScale */ , Bool_t useTMVAStyle )
18 {
19 
20  // set style and remove existing canvas'
21  TMVAGlob::Initialize( useTMVAStyle );
22 
23  // checks if file with name "fin" is already open, and if not opens one
24  TFile* file = TMVAGlob::OpenFile( fin );
25 
26  // signal and background or regression problem
27  Int_t ncls = (isRegression ? 1 : 2 );
28  TString hName[2] = { "CorrelationMatrixS", "CorrelationMatrixB" };
29  if (isRegression) hName[0]= "CorrelationMatrix";
30  const Int_t width = 600;
31  for (Int_t ic=0; ic<ncls; ic++) {
32 
33  TH2* h2 = dynamic_cast<TH2*> (file->GetDirectory(dataset.Data())->Get( hName[ic] ));
34  if(!h2) {
35  cout << "Did not find histogram " << hName[ic] << " in " << fin << endl;
36  continue;
37  }
38 
39  TCanvas* c = new TCanvas( hName[ic],
40  Form("Correlations between MVA input variables (%s)",
41  (isRegression ? "" : (ic==0 ? "signal" : "background"))),
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 
56  gStyle->SetPaintTextFormat( "3g" );
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 += hName[ic];
87  TMVAGlob::imgconv( c, fname );
88  }
89 }
void imgconv(TCanvas *c, const TString &fname)
Definition: tmvaglob.cxx:212
virtual void LabelsOption(Option_t *option="h", Option_t *axis="X")
Set option(s) to draw axis with labels.
Definition: TH1.cxx:5085
float Float_t
Definition: RtypesCore.h:53
image html pict1_TGaxis_012 png width
Define new text attributes for the label number "labNum".
Definition: TGaxis.cxx:2551
R__EXTERN TStyle * gStyle
Definition: TStyle.h:406
TFile * OpenFile(const TString &fin)
Definition: tmvaglob.cxx:192
Config & gConfig()
A ROOT file is a suite of consecutive data records (TKey instances) with a well defined format...
Definition: TFile.h:47
Basic string class.
Definition: TString.h:131
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
virtual void SetTopMargin(Float_t topmargin)
Set Pad top margin in fraction of the pad height.
Definition: TAttPad.cxx:130
virtual TObject * FindObject(const char *name) const
Delete a TObjLink object.
Definition: TList.cxx:574
virtual void AppendPad(Option_t *option="")
Append graphics object to current pad.
Definition: TObject.cxx:105
virtual void SetGrid(Int_t valuex=1, Int_t valuey=1)
Definition: TPad.h:327
virtual void SetMarkerColor(Color_t mcolor=1)
Set the marker color.
Definition: TAttMarker.h:38
Base class for several text objects.
Definition: TText.h:23
virtual void SetNDC(Bool_t isNDC=kTRUE)
Set NDC mode on if isNDC = kTRUE, off otherwise.
Definition: TText.cxx:814
void correlations(TString dataset, TString fin="TMVA.root", Bool_t isRegression=kFALSE, Bool_t greyScale=kFALSE, Bool_t useTMVAStyle=kTRUE)
Double_t GetX1NDC() const
Definition: TPave.h:56
virtual void SetBottomMargin(Float_t bottommargin)
Set Pad bottom margin in fraction of the pad height.
Definition: TAttPad.cxx:100
Service class for 2-Dim histogram classes.
Definition: TH2.h:30
void Initialize(Bool_t useTMVAStyle=kTRUE)
Definition: tmvaglob.cxx:176
virtual void Draw(Option_t *option="")
Draw this histogram with options.
Definition: TH1.cxx:2974
virtual void SetX1NDC(Double_t x1)
Definition: TPave.h:75
char * Form(const char *fmt,...)
TAxis * GetYaxis()
Definition: TH1.h:316
virtual TDirectory * GetDirectory(const char *apath, Bool_t printError=false, const char *funcname="GetDirectory")
Find a directory named "apath".
virtual void SetLabelSize(Float_t size=0.04)
Set size of axis labels The size is expressed in per cent of the pad width.
Definition: TAttAxis.cxx:204
virtual void SetMarkerSize(Size_t msize=1)
Set the marker size.
Definition: TAttMarker.h:41
The Canvas class.
Definition: TCanvas.h:31
virtual void SetTicks(Int_t valuex=1, Int_t valuey=1)
Definition: TPad.h:347
virtual void SetRightMargin(Float_t rightmargin)
Set Pad right margin in fraction of the pad width.
Definition: TAttPad.cxx:120
Definition: file.py:1
#define c(i)
Definition: RSha256.hxx:101
void SetPaintTextFormat(const char *format="g")
Definition: TStyle.h:363
virtual void SetTextSize(Float_t tsize=1)
Set the text size.
Definition: TAttText.h:46
virtual void Update()
Update canvas pad buffers.
Definition: TCanvas.cxx:2248
TList * GetListOfFunctions() const
Definition: TH1.h:238
The palette painting class.
Definition: TPaletteAxis.h:29
void SetPalette(Int_t ncolors=kBird, Int_t *colors=0, Float_t alpha=1.)
See TColor::SetPalette.
Definition: TStyle.cxx:1637
TAxis * GetXaxis()
Get the behaviour adopted by the object about the statoverflows. See EStatOverflows for more informat...
Definition: TH1.h:315
virtual void SetLabelSize(Float_t labelsize)
Definition: TPaletteAxis.h:62
virtual void SetLabelOffset(Float_t offset=0.005, Option_t *axis="X")
Set offset between axis and axis&#39; labels.
Definition: Haxis.cxx:267
virtual void SetLeftMargin(Float_t leftmargin)
Set Pad left margin in fraction of the pad width.
Definition: TAttPad.cxx:110
const char * Data() const
Definition: TString.h:364