ROOT  6.07/01
Reference Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups 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 
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
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->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( "plots/deviation_%s_%s_%s_c%i",
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 
void imgconv(TCanvas *c, const TString &fname)
Definition: tmvaglob.cxx:212
virtual TList * GetListOfKeys() const
Definition: TDirectory.h:158
ClassImp(TSeqCollection) Int_t TSeqCollection TIter next(this)
Return index of object in collection.
Collectable string class.
Definition: TObjString.h:32
return c
R__EXTERN TStyle * gStyle
Definition: TStyle.h:423
TFile * OpenFile(const TString &fin)
Definition: tmvaglob.cxx:192
virtual TList * GetListOfKeys() const
TH1 * h
Definition: legend2.C:5
A ROOT file is a suite of consecutive data records (TKey instances) with a well defined format...
Definition: TFile.h:45
#define gROOT
Definition: TROOT.h:344
Basic string class.
Definition: TString.h:137
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:254
const char * Data() const
Definition: TString.h:349
void SetNumberContours(Int_t number=20)
Set the default number of contour levels when drawing 2-d plots.
Definition: TStyle.cxx:1119
bool BeginsWith(const std::string &theString, const std::string &theSubstring)
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:30
Double_t GetXmin() const
Definition: TAxis.h:137
A doubly linked list.
Definition: TList.h:47
std::string GetMethodName(TCppMethod_t)
Definition: Cppyy.cxx:706
void Initialize(Bool_t useTMVAStyle=kTRUE)
Definition: tmvaglob.cxx:176
virtual void Draw(Option_t *option="")
Draw this histogram with options.
Definition: TH1.cxx:2878
char * Form(const char *fmt,...)
A simple line.
Definition: TLine.h:41
TLine * l
Definition: textangle.C:4
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:51
void plot_logo(Float_t v_scale=1.0, Float_t skew=1.0)
Definition: tmvaglob.cxx:263
The Canvas class.
Definition: TCanvas.h:48
tuple file
Definition: fildir.py:20
Describe directory structure in memory.
Definition: TDirectory.h:44
Double_t GetXmax() const
Definition: TAxis.h:138
Bool_t Contains(const char *name) const
Definition: TCollection.h:84
The TH1 histogram class.
Definition: TH1.h:80
virtual void SetLineStyle(Style_t lstyle)
Definition: TAttLine.h:56
virtual void SetRightMargin(Float_t rightmargin)
Set Pad right margin in fraction of the pad width.
Definition: TAttPad.cxx:117
HistType
Definition: Types.h:71
virtual void Add(TObject *obj)
Definition: TList.h:81
virtual void SetTitle(const char *title)
Change (i.e.
Definition: TH1.cxx:6268
virtual void Update()
Update canvas pad buffers.
Definition: TCanvas.cxx:2179
void deviations(TString fin="TMVAReg.root", HistType htype=kMVAType, Bool_t showTarget=kTRUE, Bool_t useTMVAStyle=kTRUE)
Definition: deviations.cxx:16
TAxis * GetXaxis()
Definition: TH1.h:319