8 void TMVA::plot_training_history(TString dataset, TFile* , TDirectory* BinDir)
11 Bool_t __PLOT_LOGO__ = kTRUE;
12 Bool_t __SAVE_IMAGE__ = kTRUE;
21 TCanvas* c =
new TCanvas(
"c",
"the canvas", 200, 0, 650, 500 );
28 Float_t x0L = 0.107, y0H = 0.899;
29 Float_t dxL = 0.457-x0L, dyH = 0.22;
31 TLegend *legend =
new TLegend( x0L, y0H-dyH, x0L+dxL, y0H );
33 legend->SetHeader(
"MVA Method:" );
34 legend->SetMargin( 0.4 );
36 TString xtit =
"Training Step";
39 TString ftit =
"Training History";
41 TString hNameRef =
"";
45 UInt_t xnm = TMVAGlob::GetListOfMethods( xmethods ,BinDir);
47 cout <<
"ups .. no methods found in to plot training history for ... give up" << endl;
50 TIter xnext(&xmethods);
53 while ((xkey = (TKey*)xnext())) {
54 TDirectory * mDir = (TDirectory*)xkey->ReadObj();
56 UInt_t ninst = TMVAGlob::GetListOfTitles(mDir,titles);
57 if (ninst==0) cout <<
"hmm... sorry, but this printout was supposed to be only to keep the compiler quite.. never supposed to happen :(" << endl;
58 TIter nextTitle(&titles);
61 while ((titkey = TMVAGlob::NextKey(nextTitle,
"TDirectory"))) {
62 titDir = (TDirectory *)titkey->ReadObj();
64 TMVAGlob::GetMethodTitle(methodTitle,titDir);
65 TIter nextKey( titDir->GetListOfKeys() );
67 while ((hkey2 = TMVAGlob::NextKey(nextKey,
"TH1"))) {
68 TH1 *h = (TH1*)hkey2->ReadObj();
69 TString hname = h->GetName();
70 if (hname.Contains( hNameRef ) && hname.BeginsWith(
"TrainingHistory_" )) {
72 if (h->GetMaximum() > y2) y2 = h->GetMaximum()*1.1;
73 if (h->GetMinimum() < y1) y1 = h->GetMinimum();
74 if (h->GetBinLowEdge(0) < x1 ) x1 = h->GetBinLowEdge(0);
75 if (h->GetBinLowEdge(h->GetNbinsX()+1 ) > x2 ) x2 = h->GetBinLowEdge(h->GetNbinsX()+1 );
84 if(gROOT->FindObject(
"frame")!=0) gROOT->FindObject(
"frame")->Delete();
85 TH2F* frame =
new TH2F(
"frame", ftit, 500, x1, x2, 500, y1, y2 );
86 frame->GetXaxis()->SetTitle( xtit );
87 frame->GetYaxis()->SetTitle( ytit );
88 TMVAGlob::SetFrameStyle( frame, 1.0 );
98 UInt_t nm = TMVAGlob::GetListOfMethods( methods,BinDir );
100 cout <<
"ups .. no methods found in to plot ROC curve for ... give up" << endl;
104 TIter next(&methods);
107 while ((key = (TKey*)next())) {
108 TDirectory * mDir = (TDirectory*)key->ReadObj();
110 UInt_t ninst = TMVAGlob::GetListOfTitles(mDir,titles);
111 if (ninst==0) cout <<
"hmm... sorry, but this printout was supposed to be only to keep the compiler quite.. never supposed to happen :(" << endl;
112 TIter nextTitle(&titles);
115 while ((titkey = TMVAGlob::NextKey(nextTitle,
"TDirectory"))) {
116 titDir = (TDirectory *)titkey->ReadObj();
118 TMVAGlob::GetMethodTitle(methodTitle,titDir);
119 TIter nextKey( titDir->GetListOfKeys() );
121 while ((hkey2 = TMVAGlob::NextKey(nextKey,
"TH1"))) {
122 TH1 *h = (TH1*)hkey2->ReadObj();
123 TString hname = h->GetName();
124 if (hname.Contains( hNameRef ) && hname.BeginsWith(
"TrainingHistory_" )) {
126 h->SetLineColor(color);
127 color++;
if (color == 5 || color == 10 || color == 11) color++;
136 while (hists.GetSize()) {
137 TListIter hIt(&hists);
139 Double_t largestInt=-1;
140 TH1* histWithLargestInt(0);
141 while ((hist = (TH1*)hIt())!=0) {
142 Double_t integral = hist->Integral(1,hist->FindBin(0.9999));
143 if (integral>largestInt) {
144 largestInt = integral;
145 histWithLargestInt = hist;
148 if (histWithLargestInt == 0) {
149 cout <<
"ERROR - unknown hist \"histWithLargestInt\" --> serious problem in ROOT file" << endl;
152 legend->AddEntry(histWithLargestInt,TString(histWithLargestInt->GetTitle()).ReplaceAll(
"MVA_",
""),
"l");
153 hists.Remove(histWithLargestInt);
158 dyH *= (Float_t(TMath::Min(10,nmva) - 3.0)/4.0);
159 legend->SetY2( y0H + dyH);
162 frame->Draw(
"sameaxis");
163 legend->Draw(
"same");
167 if (__PLOT_LOGO__) TMVAGlob::plot_logo();
173 TString fname = dataset+
"/plots/" + hNameRef;
174 if (TString(BinDir->GetName()).Contains(
"multicut")){
175 TString fprepend(BinDir->GetName());
176 fprepend.ReplaceAll(
"multicutMVA_",
"");
177 fname = dataset+
"plots/" + fprepend +
"_" + hNameRef;
179 if (__SAVE_IMAGE__) TMVAGlob::imgconv( c, fname );
184 void TMVA::training_history(TString dataset, TString fin , Bool_t useTMVAStyle )
188 TMVAGlob::Initialize( useTMVAStyle );
191 TFile* file = TMVAGlob::OpenFile( fin );
193 plot_training_history(dataset, file, file->GetDirectory(dataset.Data()));