ROOT  6.06/09
Reference Guide
BoostControlPlots.cxx
Go to the documentation of this file.
2 #include <vector>
3 #include <string>
4 #include "TLegend.h"
5 #include "TText.h"
6 
7 
8 
9 // input: - Input file (result from TMVA),
10 // - use of TMVA plotting TStyle
11 // this macro is based on BDTControlPlots.C
12 void TMVA::BoostControlPlots( TString fin , Bool_t useTMVAStyle )
13 {
14  // set style and remove existing canvas'
15  TMVAGlob::Initialize( useTMVAStyle );
16 
17  // checks if file with name "fin" is already open, and if not opens one
18  //TFile* file =
19  TMVAGlob::OpenFile( fin );
20 
21  // get all titles of the method Boost
22  TList titles;
23  TString dirname="Method_Boost";
24  UInt_t ninst = TMVA::TMVAGlob::GetListOfTitles(dirname,titles);
25  if (ninst==0) {
26  cout << "Could not locate directory 'Method_Boost' in file " << fin << endl;
27  return;
28  }
29  // loop over all titles
30  TIter keyIter(&titles);
31  TDirectory *boostdir;
32  TKey *key;
33  while ((key = TMVAGlob::NextKey(keyIter,"TDirectory"))) {
34  boostdir = (TDirectory *)key->ReadObj();
35  boostcontrolplots( boostdir );
36  }
37 }
38 
40 
41  const Int_t nPlots = 6;
42 
43  Int_t width = 900;
44  Int_t height = 900;
45  char cn[100];
46  const TString titName = boostdir->GetName();
47  sprintf( cn, "cv_%s", titName.Data() );
48  TCanvas *c = new TCanvas( cn, Form( "%s Control Plots", titName.Data() ),
49  width, height );
50  c->Divide(2,4);
51 
52 
53  //TString hname[nPlots]={"Booster_BoostWeight","Booster_MethodWeight","Booster_ErrFraction","Booster_OrigErrFraction"};
54 
55  TString hname[nPlots]={"BoostWeight","MethodWeight","ErrFraction","SoverBtotal","SeparationGain", "SeparationGain"};
56 
57  // Note: the ROCIntegral plots are only filled for option "Boost_DetailedMonitoring=ture" currently not filled...
58  // TString hname[nPlots]={"BoostWeight","MethodWeight","ErrFraction","ROCIntegral_test"};
59 
60  for (Int_t i=0; i<nPlots; i++){
61  Int_t color = 4;
62  TH1 *h = (TH1*) boostdir->Get(hname[i]);
63  TString plotname = h->GetName();
64  h->SetMaximum(h->GetMaximum()*1.3);
65  h->SetMinimum( 0 );
66  h->SetMarkerColor(color);
67  h->SetMarkerSize( 0.7 );
68  h->SetMarkerStyle( 24 );
69  h->SetLineWidth(2);
70  h->SetLineColor(color);
71  h->Draw();
72  c->Update();
73  }
74 
75  // draw combined ROC plots
76 
77  TString hname_roctest[2] ={"ROCIntegral_test", "ROCIntegralBoosted_test"};
78  TString hname_roctrain[2]={"ROCIntegral_train", "ROCIntegralBoosted_train"};
79  TString htitle[2] = {"ROC integral of single classifier", "ROC integral of boosted method"};
80 
81  for (Int_t i=0; i<2; i++){
82  Int_t color = 4;
83  TPad * cPad = (TPad*)c->cd(nPlots+i+1);
84  TH1 *htest = (TH1*) boostdir->Get(hname_roctest[i]);
85  TH1 *htrain = (TH1*) boostdir->Get(hname_roctrain[i]);
86 
87  // check if filled
88  // Bool_t histFilled = (htest->GetMaximum() > 0 || htrain->GetMaximum() > 0);
89  Bool_t histFilled = (htest && htrain);
90 
91  if (!htest) htest = new TH1F("htest","",2,0,1);
92  if (!htrain) htrain = new TH1F("htrain","",2,0,1);
93 
94  htest->SetTitle(htitle[i]);
95  htest->SetMaximum(1.0);
96  htest->SetMinimum(0.0);
97  htest->SetMarkerColor(color);
98  htest->SetMarkerSize( 0.7 );
99  htest->SetMarkerStyle( 24 );
100  htest->SetLineWidth(2);
101  htest->SetLineColor(color);
102  htest->Draw();
103  htrain->SetMaximum(1.0);
104  htrain->SetMinimum(0.0);
105  htrain->SetMarkerColor(color-2);
106  htrain->SetMarkerSize( 0.7 );
107  htrain->SetMarkerStyle( 24 );
108  htrain->SetLineWidth(2);
109  htrain->SetLineColor(color-2);
110  htrain->Draw("same");
111 
112  if (histFilled) {
113  TLegend *legend= new TLegend( cPad->GetLeftMargin(),
114  0.2 + cPad->GetBottomMargin(),
115  cPad->GetLeftMargin() + 0.6,
116  cPad->GetBottomMargin() );
117  legend->AddEntry(htest, TString("testing sample"), "L");
118  legend->AddEntry(htrain, TString("training sample (orig. weights)"), "L");
119  legend->SetFillStyle( 1 );
120  legend->SetBorderSize(1);
121  legend->SetMargin( 0.3 );
122  legend->Draw("same");
123  }
124  else {
125  TText* t = new TText();
126  t->SetTextSize( 0.056 );
127  t->SetTextColor( 2 );
128  t->DrawTextNDC( .2, 0.6, "Use MethodBoost option: \"Boost_DetailedMonitoring\" " );
129  t->DrawTextNDC( .2, 0.51, "to fill this histograms" );
130  }
131 
132  c->Update();
133  }
134 
135  // write to file
136  TString fname = Form( "plots/%s_ControlPlots", titName.Data() );
137  TMVAGlob::imgconv( c, fname );
138 
139 }
140 
141 
virtual void SetLineWidth(Width_t lwidth)
Definition: TAttLine.h:57
void BoostControlPlots(TString fin="TMVA.root", Bool_t useTMVAStyle=kTRUE)
void imgconv(TCanvas *c, const TString &fname)
Definition: tmvaglob.cxx:212
virtual void SetMaximum(Double_t maximum=-1111)
Definition: TH1.h:394
This class displays a legend box (TPaveText) containing several legend entries.
Definition: TLegend.h:35
virtual TObject * Get(const char *namecycle)
Return pointer to object identified by namecycle.
Definition: TDirectory.cxx:727
TFile * OpenFile(const TString &fin)
Definition: tmvaglob.cxx:192
virtual void Draw(Option_t *option="")
Draw this legend with its current attributes.
Definition: TLegend.cxx:373
TH1 * h
Definition: legend2.C:5
THist< 1, float > TH1F
Definition: THist.h:315
virtual void SetMinimum(Double_t minimum=-1111)
Definition: TH1.h:395
Basic string class.
Definition: TString.h:137
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
void SetMargin(Float_t margin)
Definition: TLegend.h:80
virtual void SetFillStyle(Style_t fstyle)
Definition: TAttFill.h:52
TKey * NextKey(TIter &keyIter, TString className)
Definition: tmvaglob.cxx:357
TLegend * legend
Definition: pirndm.C:35
const char * Data() const
Definition: TString.h:349
TVirtualPad * cd(Int_t subpadnumber=0)
Set Current pad.
Definition: TPad.cxx:514
Float_t GetBottomMargin() const
Definition: TAttPad.h:53
virtual TText * DrawTextNDC(Double_t x, Double_t y, const char *text)
Draw this text with new coordinates in NDC.
Definition: TText.cxx:197
virtual void SetMarkerColor(Color_t mcolor=1)
Definition: TAttMarker.h:51
Base class for several text objects.
Definition: TText.h:42
Book space in a file, create I/O buffers, to fill them, (un)compress them.
Definition: TKey.h:30
A doubly linked list.
Definition: TList.h:47
virtual void SetLineColor(Color_t lcolor)
Definition: TAttLine.h:54
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
unsigned int UInt_t
Definition: RtypesCore.h:42
The most important graphics class in the ROOT system.
Definition: TPad.h:46
char * Form(const char *fmt,...)
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:51
virtual void SetMarkerStyle(Style_t mstyle=1)
Definition: TAttMarker.h:53
virtual void SetMarkerSize(Size_t msize=1)
Definition: TAttMarker.h:54
Float_t GetLeftMargin() const
Definition: TAttPad.h:54
The Canvas class.
Definition: TCanvas.h:48
TLegendEntry * AddEntry(const TObject *obj, const char *label="", Option_t *option="lpf")
Add a new entry to this legend.
Definition: TLegend.cxx:280
Describe directory structure in memory.
Definition: TDirectory.h:41
The TH1 histogram class.
Definition: TH1.h:80
virtual TObject * ReadObj()
To read a TObject* from the file.
Definition: TKey.cxx:727
virtual void SetTextColor(Color_t tcolor=1)
Definition: TAttText.h:57
void boostcontrolplots(TDirectory *boostdir)
virtual void SetTitle(const char *title)
Change (i.e.
Definition: TH1.cxx:6268
virtual void SetTextSize(Float_t tsize=1)
Definition: TAttText.h:60
virtual Double_t GetMaximum(Double_t maxval=FLT_MAX) const
Return maximum value smaller than maxval of bins in the range, unless the value has been overridden b...
Definition: TH1.cxx:7921
virtual void SetBorderSize(Int_t bordersize=4)
Definition: TPave.h:82
UInt_t GetListOfTitles(TDirectory *rfdir, TList &titles)
Definition: tmvaglob.cxx:634