Logo ROOT   6.14/05
Reference Guide
deviations.cxx
Go to the documentation of this file.
1 #include "TMVA/deviations.h"
2 #include "TMVA/Types.h"
3 #include "TLegend.h"
4 #include "TText.h"
5 #include "TH2.h"
6 #include "TLine.h"
7 
8 
9 // this macro plots the resulting MVA distributions (Signal and
10 // Background overlayed) of different MVA methods run in TMVA
11 // (e.g. running TMVAnalysis.C).
12 
13 
14 // input: - Input file (result from TMVA)
15 // - use of TMVA plotting TStyle
16 void TMVA::deviations(TString dataset, TString fin,
17  HistType htype , Bool_t showTarget, Bool_t useTMVAStyle )
18 {
19  // set style and remove existing canvas'
20  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  // define Canvas layout here!
27  const Int_t width = 650; // size of canvas
28 
29  // this defines how many canvases we need
30  TCanvas* c[100];
31 
32  // counter variables
33  Int_t countCanvas = 0;
34 
35  // search for the right histograms in full list of keys
36  // TList* methods = new TMap();
37 
38  TIter next(file->GetDirectory(dataset.Data())->GetListOfKeys());
39  TKey *key(0);
40  while ((key = (TKey*)next())) {
41 
42  if (!TString(key->GetName()).BeginsWith("Method_")) continue;
43  if (!gROOT->GetClass(key->GetClassName())->InheritsFrom("TDirectory")) continue;
44 
45  TString methodName;
46  TMVAGlob::GetMethodName(methodName,key);
47  cout << "--- Plotting deviation for method: " << methodName << endl;
48 
49  TDirectory* mDir = (TDirectory*)key->ReadObj();
50 
51  TList* jobNames = new TList();
52 
53  TIter keyIt(mDir->GetListOfKeys());
54  TKey *titkey;
55  while ((titkey = (TKey*)keyIt())) {
56 
57  if (!gROOT->GetClass(titkey->GetClassName())->InheritsFrom("TDirectory")) continue;
58 
59  TDirectory *titDir = (TDirectory *)titkey->ReadObj();
60 
61  TObjString *jN = new TObjString( titDir->GetName() );
62  if (!jobNames->Contains( jN )) jobNames->Add( jN );
63  else delete jN;
64 
65  TString methodTitle;
66  TMVAGlob::GetMethodTitle(methodTitle,titDir);
67 
68  TString hname = "MVA_" + methodTitle;
69  TIter dirKeyIt( titDir->GetListOfKeys() );
70  TKey* dirKey;
71 
72  Int_t countPlots = 0;
73  while ((dirKey = (TKey*)dirKeyIt())){
74  if (dirKey->ReadObj()->InheritsFrom("TH2F")) {
75  TString s(dirKey->ReadObj()->GetName());
76  if (s.Contains("_reg_") &&
77  ( (showTarget && s.Contains("_tgt")) || (!showTarget && !s.Contains("_tgt")) ) &&
78  s.Contains( (htype == kCompareType ? "train" : "test" ))) {
79  c[countCanvas] = new TCanvas( Form("canvas%d", countCanvas+1),
80  Form( "Regression output deviation versus %s for method: %s",
81  (showTarget ? "target" : "input variables"), methodName.Data() ),
82  countCanvas*50+100, (countCanvas+1)*20, width, (Int_t)width*0.72 );
83  c[countCanvas]->SetRightMargin(0.10); // leave space for border
84  TH1* h = (TH1*)dirKey->ReadObj();
85  h->SetTitle( Form("Output deviation for method: %s (%s sample)",
86  hname.Data(), (htype == kCompareType ? "training" : "test" )) );
87  // methodName.Data(), (htype == kCompareType ? "training" : "test" )) );
88  h->Draw("colz");
89  TLine* l = new TLine( h->GetXaxis()->GetXmin(), 0, h->GetXaxis()->GetXmax(), 0 );
90  l->SetLineStyle(2);
91  l->Draw();
92 
93  // update and print
94  cout << "plotting logo" << endl;
95  TMVAGlob::plot_logo(1.058);
96  c[countCanvas]->Update();
97 
98  TString fname = Form( "%s/plots/deviation_%s_%s_%s_c%i",
99  dataset.Data(),
100  methodName.Data(),
101  (showTarget ? "target" : "vars"),
102  (htype == kCompareType ? "training" : "test" ), countPlots );
103  TMVAGlob::imgconv( c[countCanvas], fname );
104 
105  countPlots++;
106  countCanvas++;
107  }
108  }
109  }
110  }
111  }
112 }
113 
114 
115 
116 
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:47
void imgconv(TCanvas *c, const TString &fname)
Definition: tmvaglob.cxx:212
virtual TList * GetListOfKeys() const
Definition: TDirectory.h:150
Collectable string class.
Definition: TObjString.h:28
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
A ROOT file is a suite of consecutive data records (TKey instances) with a well defined format...
Definition: TFile.h:47
#define gROOT
Definition: TROOT.h:410
UInt_t GetListOfKeys(TList &keys, TString inherits, TDirectory *dir=0)
Definition: tmvaglob.cxx:375
Basic string class.
Definition: TString.h:131
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
virtual void Draw(Option_t *option="")
Default Draw method for all objects.
Definition: TObject.cxx:195
Bool_t Contains(const char *name) const
Definition: TCollection.h:169
void SetNumberContours(Int_t number=20)
Set the default number of contour levels when drawing 2-d plots.
Definition: TStyle.cxx:1306
Double_t GetXmin() const
Definition: TAxis.h:133
void GetMethodTitle(TString &name, TKey *ikey)
Definition: tmvaglob.cxx:341
Book space in a file, create I/O buffers, to fill them, (un)compress them.
Definition: TKey.h:24
A doubly linked list.
Definition: TList.h:44
std::string GetMethodName(TCppMethod_t)
Definition: Cppyy.cxx:733
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
char * Form(const char *fmt,...)
A simple line.
Definition: TLine.h:23
void plot_logo(Float_t v_scale=1.0, Float_t skew=1.0)
Definition: tmvaglob.cxx:263
virtual TDirectory * GetDirectory(const char *apath, Bool_t printError=false, const char *funcname="GetDirectory")
Find a directory named "apath".
#define h(i)
Definition: RSha256.hxx:106
The Canvas class.
Definition: TCanvas.h:31
Describe directory structure in memory.
Definition: TDirectory.h:34
The TH1 histogram class.
Definition: TH1.h:56
static constexpr double s
void deviations(TString dataset, TString fin="TMVAReg.root", HistType htype=kMVAType, Bool_t showTarget=kTRUE, Bool_t useTMVAStyle=kTRUE)
virtual void SetLineStyle(Style_t lstyle)
Set the line style.
Definition: TAttLine.h:42
virtual void SetRightMargin(Float_t rightmargin)
Set Pad right margin in fraction of the pad width.
Definition: TAttPad.cxx:120
virtual void Add(TObject *obj)
Definition: TList.h:87
auto * l
Definition: textangle.C:4
Definition: file.py:1
#define c(i)
Definition: RSha256.hxx:101
virtual void SetTitle(const char *title)
See GetStatOverflows for more information.
Definition: TH1.cxx:6192
virtual void Update()
Update canvas pad buffers.
Definition: TCanvas.cxx:2248
Double_t GetXmax() const
Definition: TAxis.h:134
TAxis * GetXaxis()
Get the behaviour adopted by the object about the statoverflows. See EStatOverflows for more informat...
Definition: TH1.h:315
const char * Data() const
Definition: TString.h:364