ROOT  6.07/01
Reference Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
correlationscatters.cxx
Go to the documentation of this file.
2 #include "TMVA/Config.h"
3 
4 
5 
6 // this macro plots the correlations (as scatter plots) of
7 // the various input variable combinations used in TMVA (e.g. running
8 // TMVAnalysis.C). Signal and Background are plotted separately
9 
10 // input: - Input file (result from TMVA),
11 // - normal/decorrelated/PCA
12 // - use of TMVA plotting TStyle
14  TString dirName_, TString /*title */ ,
15  Bool_t isRegression ,
16  Bool_t useTMVAStyle )
17 {
18  // set style and remove existing canvas'
19  TMVAGlob::Initialize( useTMVAStyle );
20 
21  TString extension = dirName_;
22  extension.ReplaceAll( "InputVariables", "" );
23  extension.ReplaceAll( " ", "" );
24  if (extension == "") extension = "_Id"; // use 'Id' for 'idendtity transform'
25 
26  var.ReplaceAll( extension, "" );
27  cout << "Called macro \"correlationscatters\" for variable: \"" << var
28  << "\", transformation type \"" << dirName_
29  << "\" (extension: \"" << extension << "\")" << endl;
30 
31  // checks if file with name "fin" is already open, and if not opens one
32  //TFile* file =
33  TMVAGlob::OpenFile( fin );
34 
35  TString dirName = dirName_ + "/CorrelationPlots";
36 
37  // find out number of input variables
38  TDirectory* vardir = (TDirectory*)gDirectory->Get( "InputVariables_Id" );
39  if (!vardir) {
40  cout << "ERROR: no such directory: \"InputVariables\"" << endl;
41  return;
42  }
43  Int_t noVars = TMVAGlob::GetNumberOfInputVariables( vardir ); // subtraction of target(s) no longer necessary
44 
45  TDirectory* dir = (TDirectory*)gDirectory->Get( dirName );
46  if (dir==0) {
47  cout << "No information about " << extension << " available in " << fin << endl;
48  return;
49  }
50  dir->cd();
51 
52  TListIter keyIt(dir->GetListOfKeys());
53  Int_t noPlots = noVars - 1;
54 
55  cout << "noPlots: " << noPlots << " --> noVars: " << noVars << endl;
56  if (noVars != Int_t(noVars)) {
57  cout << "*** Warning: problem in inferred number of variables ... not an integer *** " << endl;
58  }
59 
60  // define Canvas layout here!
61  // default setting
62  Int_t xPad; // no of plots in x
63  Int_t yPad; // no of plots in y
64  Int_t width; // size of canvas
65  Int_t height;
66  switch (noPlots) {
67  case 1:
68  xPad = 1; yPad = 1; width = 400; height = width; break;
69  case 2:
70  xPad = 2; yPad = 1; width = 700; height = 0.55*width; break;
71  case 3:
72  xPad = 3; yPad = 1; width = 800; height = 0.4*width; break;
73  case 4:
74  xPad = 2; yPad = 2; width = 600; height = width; break;
75  default:
76  xPad = 3; yPad = 2; width = 800; height = 0.55*width; break;
77  }
78  Int_t noPadPerCanv = xPad * yPad ;
79 
80  // counter variables
81  Int_t countCanvas = 0;
82 
83  // loop over all objects in "input_variables" directory
84  TString thename[2] = { "_Signal", "_Background" };
85  if (isRegression) thename[0] = "_Regression";
86  for (UInt_t itype = 0; itype < 2; itype++) {
87 
88  TIter next(gDirectory->GetListOfKeys());
89  TKey * key = 0;
90  TCanvas* canv = 0;
91 
92  Int_t countPad = 0;
93 
94  while ( (key = (TKey*)next()) ) {
95 
96  if (key->GetCycle() != 1) continue;
97 
98  // make sure, that we only look at histograms
99  TClass *cl = gROOT->GetClass(key->GetClassName());
100  if (!cl->InheritsFrom("TH1")) continue;
101  TH1 *scat = (TH1*)key->ReadObj();
102  TString hname = scat->GetName();
103 
104  // check for all signal histograms
105  if (! (hname.EndsWith( thename[itype] + extension ) &&
106  hname.Contains( TString("_") + var + "_" ) && hname.BeginsWith("scat_")) ) {
107  scat->Delete();
108  continue;
109  }
110 
111  // found a new signal plot
112 
113  // create new canvas
114  if (countPad%noPadPerCanv==0) {
115  ++countCanvas;
116  TString ext = extension; ext.Remove( 0, 1 );
117  canv = new TCanvas( Form("canvas%d", countCanvas),
118  Form("Correlation profiles for '%s'-transformed %s variables",
119  ext.Data(), (isRegression ? "" : (itype==0) ? "signal" : "background")),
120  countCanvas*50+200, countCanvas*20, width, height );
121  canv->Divide(xPad,yPad);
122  }
123 
124  if (!canv) continue;
125 
126  canv->cd(countPad++%noPadPerCanv+1);
127 
128  // find the corredponding backgrouns histo
129  TString bgname = hname;
130  bgname.ReplaceAll("scat_","prof_");
131  TH1 *prof = (TH1*)gDirectory->Get(bgname);
132  if (prof == NULL) {
133  cout << "ERROR!!! couldn't find background histo for" << hname << endl;
134  //exit(1);
135  return;
136  }
137  // this is set but not stored during plot creation in MVA_Factory
139 
140  // chop off "signal"
141  TMVAGlob::SetFrameStyle( scat, 1.2 );
142 
143  // normalise both signal and background
144  scat->Scale( 1.0/scat->GetSumOfWeights() );
145 
146  // finally plot and overlay
147  scat->SetMarkerColor( 4);
148  scat->Draw("col");
149  prof->SetMarkerColor( gConfig().fVariablePlotting.fUsePaperStyle ? 1 : 2 );
150  prof->SetMarkerSize( 0.2 );
151  prof->SetLineColor( gConfig().fVariablePlotting.fUsePaperStyle ? 1 : 2 );
152  prof->SetLineWidth( gConfig().fVariablePlotting.fUsePaperStyle ? 2 : 1 );
153  prof->SetFillStyle( 3002 );
154  prof->SetFillColor( 46 );
155  prof->Draw("samee1");
156  // redraw axes
157  scat->Draw("sameaxis");
158 
159  // save canvas to file
160  if (countPad%noPadPerCanv==0) {
161  canv->Update();
162 
163  TString fname = Form( "plots/correlationscatter_%s_%s_c%i",var.Data(), extension.Data(), countCanvas );
165  TMVAGlob::imgconv( canv, fname );
166  }
167  }
168  if (countPad%noPadPerCanv!=0) {
169  canv->Update();
170 
171  TString fname = Form( "plots/correlationscatter_%s_%s_c%i",var.Data(), extension.Data(), countCanvas );
173  TMVAGlob::imgconv( canv, fname );
174  }
175  }
176 }
virtual void SetLineWidth(Width_t lwidth)
Definition: TAttLine.h:57
virtual void Scale(Double_t c1=1, Option_t *option="")
Multiply this histogram by a constant c1.
Definition: TH1.cxx:6174
void imgconv(TCanvas *c, const TString &fname)
Definition: tmvaglob.cxx:212
virtual TList * GetListOfKeys() const
Definition: TDirectory.h:158
Int_t GetNumberOfInputVariables(TDirectory *dir)
Definition: tmvaglob.cxx:413
ClassImp(TSeqCollection) Int_t TSeqCollection TIter next(this)
Return index of object in collection.
TString & ReplaceAll(const TString &s1, const TString &s2)
Definition: TString.h:635
TFile * OpenFile(const TString &fin)
Definition: tmvaglob.cxx:192
Config & gConfig()
TVirtualPad * cd(Int_t subpadnumber=0)
Set current canvas & pad.
Definition: TCanvas.cxx:659
void SetSignalAndBackgroundStyle(TH1 *sig, TH1 *bkg, TH1 *all=0)
Definition: tmvaglob.cxx:8
#define gROOT
Definition: TROOT.h:344
void SetFrameStyle(TH1 *frame, Float_t scale=1.0)
Definition: tmvaglob.cxx:77
Basic string class.
Definition: TString.h:137
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
virtual void SetFillStyle(Style_t fstyle)
Definition: TAttFill.h:52
Bool_t BeginsWith(const char *s, ECaseCompare cmp=kExact) const
Definition: TString.h:558
Iterator of linked list.
Definition: TList.h:187
const char * Data() const
Definition: TString.h:349
virtual void SetMarkerColor(Color_t mcolor=1)
Definition: TAttMarker.h:51
Book space in a file, create I/O buffers, to fill them, (un)compress them.
Definition: TKey.h:30
virtual void SetLineColor(Color_t lcolor)
Definition: TAttLine.h:54
virtual void Delete(Option_t *option="")
Delete this object.
Definition: TObject.cxx:228
Bool_t EndsWith(const char *pat, ECaseCompare cmp=kExact) const
Return true if string ends with the specified string.
Definition: TString.cxx:2207
TString dirName
Definition: demos.C:9
void Initialize(Bool_t useTMVAStyle=kTRUE)
Definition: tmvaglob.cxx:176
virtual void Draw(Option_t *option="")
Draw this histogram with options.
Definition: TH1.cxx:2878
virtual void SetFillColor(Color_t fcolor)
Definition: TAttFill.h:50
unsigned int UInt_t
Definition: RtypesCore.h:42
char * Form(const char *fmt,...)
virtual Double_t GetSumOfWeights() const
Return the sum of weights excluding under/overflows.
Definition: TH1.cxx:7354
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:51
The ROOT global object gROOT contains a list of all defined classes.
Definition: TClass.h:81
void plot_logo(Float_t v_scale=1.0, Float_t skew=1.0)
Definition: tmvaglob.cxx:263
virtual void SetMarkerSize(Size_t msize=1)
Definition: TAttMarker.h:54
const char * extension
Definition: civetweb.c:2467
TString & Remove(Ssiz_t pos)
Definition: TString.h:616
The Canvas class.
Definition: TCanvas.h:48
void correlationscatters(TString fin, TString var="var3", TString dirName_="InputVariables_Id", TString title="TMVA Input Variable", Bool_t isRegression=kFALSE, Bool_t useTMVAStyle=kTRUE)
Describe directory structure in memory.
Definition: TDirectory.h:44
void dir(char *path=0)
Definition: rootalias.C:30
The TH1 histogram class.
Definition: TH1.h:80
virtual Bool_t cd(const char *path=0)
Change current directory to "this" directory.
Definition: TDirectory.cxx:433
virtual void Divide(Int_t nx=1, Int_t ny=1, Float_t xmargin=0.01, Float_t ymargin=0.01, Int_t color=0)
Automatic pad generation by division.
Definition: TPad.cxx:1073
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
Definition: TString.h:567
#define NULL
Definition: Rtypes.h:82
#define gDirectory
Definition: TDirectory.h:221
Bool_t InheritsFrom(const char *cl) const
Return kTRUE if this class inherits from a class with name "classname".
Definition: TClass.cxx:4498
virtual void Update()
Update canvas pad buffers.
Definition: TCanvas.cxx:2179