Logo ROOT   6.16/01
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
16void 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;
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
#define c(i)
Definition: RSha256.hxx:101
#define h(i)
Definition: RSha256.hxx:106
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
include TDocParser_001 C image html pict1_TDocParser_001 png width
Definition: TDocParser.cxx:121
#define gROOT
Definition: TROOT.h:410
char * Form(const char *fmt,...)
R__EXTERN TStyle * gStyle
Definition: TStyle.h:406
The Canvas class.
Definition: TCanvas.h:31
Bool_t Contains(const char *name) const
Definition: TCollection.h:169
Describe directory structure in memory.
Definition: TDirectory.h:34
virtual TList * GetListOfKeys() const
Definition: TDirectory.h:150
A ROOT file is a suite of consecutive data records (TKey instances) with a well defined format.
Definition: TFile.h:48
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:24
virtual const char * GetClassName() const
Definition: TKey.h:71
virtual TObject * ReadObj()
To read a TObject* from the file.
Definition: TKey.cxx:722
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:1306
std::string GetMethodName(TCppMethod_t)
Definition: Cppyy.cxx:750
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 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