Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files 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
16 void 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 );
21  gStyle->SetNumberContours(999);
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;
95  TMVAGlob::plot_logo(1.058);
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