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( Form("canvas%d", countCanvas+1),
79 Form( "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( Form("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;
94 TMVAGlob::plot_logo(1.058);
95 c[countCanvas]->Update();
96
97 TString fname = Form( "%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
int Int_t
Definition RtypesCore.h:45
bool Bool_t
Definition RtypesCore.h:63
include TDocParser_001 C image html pict1_TDocParser_001 png width
#define gROOT
Definition TROOT.h:406
char * Form(const char *fmt,...)
R__EXTERN TStyle * gStyle
Definition TStyle.h:412
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
Describe directory structure in memory.
Definition TDirectory.h:45
virtual TList * GetListOfKeys() const
Definition TDirectory.h:177
A ROOT file is a suite of consecutive data records (TKey instances) with a well defined format.
Definition TFile.h:54
TH1 is the base class of all histogram classes in ROOT.
Definition TH1.h:58
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:750
A simple line.
Definition TLine.h:22
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:359
virtual Bool_t InheritsFrom(const char *classname) const
Returns kTRUE if object inherits from class "classname".
Definition TObject.cxx:445
virtual void Draw(Option_t *option="")
Default Draw method for all objects.
Definition TObject.cxx:197
Basic string class.
Definition TString.h:136
const char * Data() const
Definition TString.h:369
Bool_t BeginsWith(const char *s, ECaseCompare cmp=kExact) const
Definition TString.h:615
void SetNumberContours(Int_t number=20)
Set the default number of contour levels when drawing 2-d plots.
Definition TStyle.cxx:1448
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