Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
deviations.cxx
Go to the documentation of this file.
1#include "TMVA/deviations.h"
2#include "TMVA/Types.h"
3#include "TH2.h"
4#include "TLine.h"
5#include "TObjString.h"
6
7
8// this macro plots the resulting MVA distributions (Signal and
9// Background overlayed) of different MVA methods run in TMVA
10// (e.g. running TMVAnalysis.C).
11
12
13// input: - Input file (result from TMVA)
14// - use of TMVA plotting TStyle
15void TMVA::deviations(TString dataset, TString fin,
16 HistType htype , Bool_t showTarget, Bool_t useTMVAStyle )
17{
18 // set style and remove existing canvas'
19 TMVAGlob::Initialize( useTMVAStyle );
21
22 // checks if file with name "fin" is already open, and if not opens one
23 TFile* file = TMVAGlob::OpenFile( fin );
24
25 // define Canvas layout here!
26 const Int_t width = 650; // size of canvas
27
28 // this defines how many canvases we need
29 TCanvas* c[100];
30
31 // counter variables
32 Int_t countCanvas = 0;
33
34 // search for the right histograms in full list of keys
35 // TList* methods = new TMap();
36
37 TIter next(file->GetDirectory(dataset.Data())->GetListOfKeys());
38 TKey *key(0);
39 while ((key = (TKey*)next())) {
40
41 if (!TString(key->GetName()).BeginsWith("Method_")) continue;
42 if (!gROOT->GetClass(key->GetClassName())->InheritsFrom("TDirectory")) continue;
43
44 TString methodName;
45 TMVAGlob::GetMethodName(methodName,key);
46 cout << "--- Plotting deviation for method: " << methodName << endl;
47
48 TDirectory* mDir = (TDirectory*)key->ReadObj();
49
50 TList* jobNames = new TList();
51
52 TIter keyIt(mDir->GetListOfKeys());
53 TKey *titkey;
54 while ((titkey = (TKey*)keyIt())) {
55
56 if (!gROOT->GetClass(titkey->GetClassName())->InheritsFrom("TDirectory")) continue;
57
58 TDirectory *titDir = (TDirectory *)titkey->ReadObj();
59
60 TObjString *jN = new TObjString( titDir->GetName() );
61 if (!jobNames->Contains( jN )) jobNames->Add( jN );
62 else delete jN;
63
64 TString methodTitle;
65 TMVAGlob::GetMethodTitle(methodTitle,titDir);
66
67 TString hname = "MVA_" + methodTitle;
68 TIter dirKeyIt( titDir->GetListOfKeys() );
69 TKey* dirKey;
70
71 Int_t countPlots = 0;
72 while ((dirKey = (TKey*)dirKeyIt())){
73 if (dirKey->ReadObj()->InheritsFrom("TH2F")) {
74 TString s(dirKey->ReadObj()->GetName());
75 if (s.Contains("_reg_") &&
76 ( (showTarget && s.Contains("_tgt")) || (!showTarget && !s.Contains("_tgt")) ) &&
77 s.Contains( (htype == kCompareType ? "train" : "test" ))) {
78 c[countCanvas] = new TCanvas( TString::Format("canvas%d", countCanvas+1),
79 TString::Format( "Regression output deviation versus %s for method: %s",
80 (showTarget ? "target" : "input variables"), methodName.Data() ),
81 countCanvas*50+100, (countCanvas+1)*20, width, (Int_t)width*0.72 );
82 c[countCanvas]->SetRightMargin(0.10); // leave space for border
83 TH1* h = (TH1*)dirKey->ReadObj();
84 h->SetTitle( TString::Format("Output deviation for method: %s (%s sample)",
85 hname.Data(), (htype == kCompareType ? "training" : "test" )) );
86 // methodName.Data(), (htype == kCompareType ? "training" : "test" )) );
87 h->Draw("colz");
88 TLine* l = new TLine( h->GetXaxis()->GetXmin(), 0, h->GetXaxis()->GetXmax(), 0 );
89 l->SetLineStyle(2);
90 l->Draw();
91
92 // update and print
93 cout << "plotting logo" << endl;
95 c[countCanvas]->Update();
96
97 TString fname = TString::Format( "%s/plots/deviation_%s_%s_%s_c%i",
98 dataset.Data(),
99 methodName.Data(),
100 (showTarget ? "target" : "vars"),
101 (htype == kCompareType ? "training" : "test" ), countPlots );
102 TMVAGlob::imgconv( c[countCanvas], fname );
103
104 countPlots++;
105 countCanvas++;
106 }
107 }
108 }
109 }
110 }
111}
112
113
114
115
#define c(i)
Definition RSha256.hxx:101
#define h(i)
Definition RSha256.hxx:106
bool Bool_t
Definition RtypesCore.h:63
int Int_t
Definition RtypesCore.h:45
Option_t Option_t width
#define gROOT
Definition TROOT.h:407
R__EXTERN TStyle * gStyle
Definition TStyle.h:436
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:119
The Canvas class.
Definition TCanvas.h:23
Bool_t Contains(const char *name) const
TDirectory * GetDirectory(const char *apath, Bool_t printError=false, const char *funcname="GetDirectory") override
Find a directory named "apath".
Describe directory structure in memory.
Definition TDirectory.h:45
virtual TList * GetListOfKeys() const
Definition TDirectory.h:223
A ROOT file is an on-disk file, usually with extension .root, that stores objects in a file-system-li...
Definition TFile.h:53
TH1 is the base class of all histogram classes in ROOT.
Definition TH1.h:59
Book space in a file, create I/O buffers, to fill them, (un)compress them.
Definition TKey.h:28
virtual const char * GetClassName() const
Definition TKey.h:75
virtual TObject * ReadObj()
To read a TObject* from the file.
Definition TKey.cxx:759
Use the TLine constructor to create a simple line.
Definition TLine.h:22
A doubly linked list.
Definition TList.h:38
void Add(TObject *obj) override
Definition TList.h:83
@ kCompareType
Definition Types.h:66
const char * GetName() const override
Returns name of object.
Definition TNamed.h:47
Collectable string class.
Definition TObjString.h:28
virtual const char * GetName() const
Returns name of object.
Definition TObject.cxx:438
virtual Bool_t InheritsFrom(const char *classname) const
Returns kTRUE if object inherits from class "classname".
Definition TObject.cxx:524
virtual void Draw(Option_t *option="")
Default Draw method for all objects.
Definition TObject.cxx:274
Basic string class.
Definition TString.h:139
const char * Data() const
Definition TString.h:376
Bool_t BeginsWith(const char *s, ECaseCompare cmp=kExact) const
Definition TString.h:623
static TString Format(const char *fmt,...)
Static method which formats a string using a printf style format descriptor and return a TString.
Definition TString.cxx:2378
void SetNumberContours(Int_t number=20)
Set the default number of contour levels when drawing 2-d plots.
Definition TStyle.cxx:1500
void Initialize(Bool_t useTMVAStyle=kTRUE)
Definition tmvaglob.cxx:176
void GetMethodTitle(TString &name, TKey *ikey)
Definition tmvaglob.cxx:348
void plot_logo(Float_t v_scale=1.0, Float_t skew=1.0)
Definition tmvaglob.cxx:270
TFile * OpenFile(const TString &fin)
Definition tmvaglob.cxx:192
void GetMethodName(TString &name, TKey *mkey)
Definition tmvaglob.cxx:342
void imgconv(TCanvas *c, const TString &fname)
Definition tmvaglob.cxx:212
void deviations(TString dataset, TString fin="TMVAReg.root", HistType htype=kMVAType, Bool_t showTarget=kTRUE, Bool_t useTMVAStyle=kTRUE)
TLine l
Definition textangle.C:4