Loading [MathJax]/extensions/tex2jax.js
Logo ROOT  
Reference Guide
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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#include "TObjString.h"
8
9
10// this macro plots the resulting MVA distributions (Signal and
11// Background overlayed) of different MVA methods run in TMVA
12// (e.g. running TMVAnalysis.C).
13
14
15// input: - Input file (result from TMVA)
16// - use of TMVA plotting TStyle
17void TMVA::deviations(TString dataset, TString fin,
18 HistType htype , Bool_t showTarget, Bool_t useTMVAStyle )
19{
20 // set style and remove existing canvas'
21 TMVAGlob::Initialize( useTMVAStyle );
23
24 // checks if file with name "fin" is already open, and if not opens one
25 TFile* file = TMVAGlob::OpenFile( fin );
26
27 // define Canvas layout here!
28 const Int_t width = 650; // size of canvas
29
30 // this defines how many canvases we need
31 TCanvas* c[100];
32
33 // counter variables
34 Int_t countCanvas = 0;
35
36 // search for the right histograms in full list of keys
37 // TList* methods = new TMap();
38
39 TIter next(file->GetDirectory(dataset.Data())->GetListOfKeys());
40 TKey *key(0);
41 while ((key = (TKey*)next())) {
42
43 if (!TString(key->GetName()).BeginsWith("Method_")) continue;
44 if (!gROOT->GetClass(key->GetClassName())->InheritsFrom("TDirectory")) continue;
45
46 TString methodName;
47 TMVAGlob::GetMethodName(methodName,key);
48 cout << "--- Plotting deviation for method: " << methodName << endl;
49
50 TDirectory* mDir = (TDirectory*)key->ReadObj();
51
52 TList* jobNames = new TList();
53
54 TIter keyIt(mDir->GetListOfKeys());
55 TKey *titkey;
56 while ((titkey = (TKey*)keyIt())) {
57
58 if (!gROOT->GetClass(titkey->GetClassName())->InheritsFrom("TDirectory")) continue;
59
60 TDirectory *titDir = (TDirectory *)titkey->ReadObj();
61
62 TObjString *jN = new TObjString( titDir->GetName() );
63 if (!jobNames->Contains( jN )) jobNames->Add( jN );
64 else delete jN;
65
66 TString methodTitle;
67 TMVAGlob::GetMethodTitle(methodTitle,titDir);
68
69 TString hname = "MVA_" + methodTitle;
70 TIter dirKeyIt( titDir->GetListOfKeys() );
71 TKey* dirKey;
72
73 Int_t countPlots = 0;
74 while ((dirKey = (TKey*)dirKeyIt())){
75 if (dirKey->ReadObj()->InheritsFrom("TH2F")) {
76 TString s(dirKey->ReadObj()->GetName());
77 if (s.Contains("_reg_") &&
78 ( (showTarget && s.Contains("_tgt")) || (!showTarget && !s.Contains("_tgt")) ) &&
79 s.Contains( (htype == kCompareType ? "train" : "test" ))) {
80 c[countCanvas] = new TCanvas( Form("canvas%d", countCanvas+1),
81 Form( "Regression output deviation versus %s for method: %s",
82 (showTarget ? "target" : "input variables"), methodName.Data() ),
83 countCanvas*50+100, (countCanvas+1)*20, width, (Int_t)width*0.72 );
84 c[countCanvas]->SetRightMargin(0.10); // leave space for border
85 TH1* h = (TH1*)dirKey->ReadObj();
86 h->SetTitle( Form("Output deviation for method: %s (%s sample)",
87 hname.Data(), (htype == kCompareType ? "training" : "test" )) );
88 // methodName.Data(), (htype == kCompareType ? "training" : "test" )) );
89 h->Draw("colz");
90 TLine* l = new TLine( h->GetXaxis()->GetXmin(), 0, h->GetXaxis()->GetXmax(), 0 );
91 l->SetLineStyle(2);
92 l->Draw();
93
94 // update and print
95 cout << "plotting logo" << endl;
97 c[countCanvas]->Update();
98
99 TString fname = Form( "%s/plots/deviation_%s_%s_%s_c%i",
100 dataset.Data(),
101 methodName.Data(),
102 (showTarget ? "target" : "vars"),
103 (htype == kCompareType ? "training" : "test" ), countPlots );
104 TMVAGlob::imgconv( c[countCanvas], fname );
105
106 countPlots++;
107 countCanvas++;
108 }
109 }
110 }
111 }
112 }
113}
114
115
116
117
#define c(i)
Definition: RSha256.hxx:101
#define h(i)
Definition: RSha256.hxx:106
int Int_t
Definition: RtypesCore.h:43
bool Bool_t
Definition: RtypesCore.h:61
include TDocParser_001 C image html pict1_TDocParser_001 png width
Definition: TDocParser.cxx:121
#define gROOT
Definition: TROOT.h:406
char * Form(const char *fmt,...)
R__EXTERN TStyle * gStyle
Definition: TStyle.h:410
The Canvas class.
Definition: TCanvas.h:27
Bool_t Contains(const char *name) const
Definition: TCollection.h:169
Describe directory structure in memory.
Definition: TDirectory.h:40
virtual TList * GetListOfKeys() const
Definition: TDirectory.h:166
A ROOT file is a suite of consecutive data records (TKey instances) with a well defined format.
Definition: TFile.h:53
The TH1 histogram class.
Definition: TH1.h:56
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:76
virtual TObject * ReadObj()
To read a TObject* from the file.
Definition: TKey.cxx:738
A simple line.
Definition: TLine.h:23
A doubly linked list.
Definition: TList.h:44
virtual void Add(TObject *obj)
Definition: TList.h:87
virtual const char * GetName() const
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:357
virtual Bool_t InheritsFrom(const char *classname) const
Returns kTRUE if object inherits from class "classname".
Definition: TObject.cxx:443
Basic string class.
Definition: TString.h:131
const char * Data() const
Definition: TString.h:364
Bool_t BeginsWith(const char *s, ECaseCompare cmp=kExact) const
Definition: TString.h:610
void SetNumberContours(Int_t number=20)
Set the default number of contour levels when drawing 2-d plots.
Definition: TStyle.cxx:1449
static constexpr double s
void Initialize(Bool_t useTMVAStyle=kTRUE)
Definition: tmvaglob.cxx:176
void GetMethodTitle(TString &name, TKey *ikey)
Definition: tmvaglob.cxx:341
void plot_logo(Float_t v_scale=1.0, Float_t skew=1.0)
Definition: tmvaglob.cxx:263
TFile * OpenFile(const TString &fin)
Definition: tmvaglob.cxx:192
void GetMethodName(TString &name, TKey *mkey)
Definition: tmvaglob.cxx:335
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)
Definition: file.py:1
auto * l
Definition: textangle.C:4