1 |
yangyong |
1.1 |
// global TMVA style settings
|
2 |
|
|
#ifndef TMVA_TMVAGLOB
|
3 |
|
|
#define TMVA_TMVAGLOB
|
4 |
|
|
|
5 |
|
|
#include <iostream>
|
6 |
|
|
#include <vector>
|
7 |
|
|
|
8 |
|
|
#include "TPad.h"
|
9 |
|
|
#include "TCanvas.h"
|
10 |
|
|
#include "TColor.h"
|
11 |
|
|
#include "TSystem.h"
|
12 |
|
|
#include "TImage.h"
|
13 |
|
|
#include "TKey.h"
|
14 |
|
|
#include "TH1.h"
|
15 |
|
|
#include "TROOT.h"
|
16 |
|
|
#include "TStyle.h"
|
17 |
|
|
#include "TFile.h"
|
18 |
|
|
#include "TDirectory.h"
|
19 |
|
|
#include "TObjArray.h"
|
20 |
|
|
|
21 |
|
|
|
22 |
|
|
#include "RVersion.h"
|
23 |
|
|
|
24 |
|
|
using std::cout;
|
25 |
|
|
using std::endl;
|
26 |
|
|
|
27 |
|
|
namespace TMVAGlob {
|
28 |
|
|
|
29 |
|
|
// --------- S t y l e ---------------------------
|
30 |
|
|
static Bool_t UsePaperStyle = 0;
|
31 |
|
|
// -----------------------------------------------
|
32 |
|
|
|
33 |
|
|
enum TypeOfPlot { kId = 0,
|
34 |
|
|
kNorm,
|
35 |
|
|
kDecorrelated,
|
36 |
|
|
kPCA,
|
37 |
|
|
kGaussDecorr,
|
38 |
|
|
kNumOfMethods };
|
39 |
|
|
|
40 |
|
|
static Int_t c_Canvas = TColor::GetColor( "#f0f0f0" );
|
41 |
|
|
static Int_t c_FrameFill = TColor::GetColor( "#fffffd" );
|
42 |
|
|
static Int_t c_TitleBox = TColor::GetColor( "#5D6B7D" );
|
43 |
|
|
static Int_t c_TitleBorder = TColor::GetColor( "#7D8B9D" );
|
44 |
|
|
static Int_t c_TitleText = TColor::GetColor( "#FFFFFF" );
|
45 |
|
|
static Int_t c_SignalLine = TColor::GetColor( "#0000ee" );
|
46 |
|
|
static Int_t c_SignalFill = TColor::GetColor( "#7d99d1" );
|
47 |
|
|
static Int_t c_BackgroundLine = TColor::GetColor( "#ff0000" );
|
48 |
|
|
static Int_t c_BackgroundFill = TColor::GetColor( "#ff0000" );
|
49 |
|
|
static Int_t c_NovelBlue = TColor::GetColor( "#2244a5" );
|
50 |
|
|
|
51 |
|
|
// set the style
|
52 |
|
|
void SetSignalAndBackgroundStyle( TH1* sig, TH1* bkg, TH1* all = 0 )
|
53 |
|
|
{
|
54 |
|
|
//signal
|
55 |
|
|
// const Int_t FillColor__S = 38 + 150; // change of Color Scheme in ROOT-5.16.
|
56 |
|
|
// convince yourself with gROOT->GetListOfColors()->Print()
|
57 |
|
|
Int_t FillColor__S = c_SignalFill;
|
58 |
|
|
Int_t FillStyle__S = 1001;
|
59 |
|
|
Int_t LineColor__S = c_SignalLine;
|
60 |
|
|
Int_t LineWidth__S = 2;
|
61 |
|
|
|
62 |
|
|
// background
|
63 |
|
|
//Int_t icolor = UsePaperStyle ? 2 + 100 : 2;
|
64 |
|
|
Int_t FillColor__B = c_BackgroundFill;
|
65 |
|
|
Int_t FillStyle__B = 3554;
|
66 |
|
|
Int_t LineColor__B = c_BackgroundLine;
|
67 |
|
|
Int_t LineWidth__B = 2;
|
68 |
|
|
|
69 |
|
|
if (sig != NULL) {
|
70 |
|
|
sig->SetLineColor( LineColor__S );
|
71 |
|
|
sig->SetLineWidth( LineWidth__S );
|
72 |
|
|
sig->SetFillStyle( FillStyle__S );
|
73 |
|
|
sig->SetFillColor( FillColor__S );
|
74 |
|
|
}
|
75 |
|
|
|
76 |
|
|
if (bkg != NULL) {
|
77 |
|
|
bkg->SetLineColor( LineColor__B );
|
78 |
|
|
bkg->SetLineWidth( LineWidth__B );
|
79 |
|
|
bkg->SetFillStyle( FillStyle__B );
|
80 |
|
|
bkg->SetFillColor( FillColor__B );
|
81 |
|
|
}
|
82 |
|
|
|
83 |
|
|
if (all != NULL) {
|
84 |
|
|
all->SetLineColor( LineColor__S );
|
85 |
|
|
all->SetLineWidth( LineWidth__S );
|
86 |
|
|
all->SetFillStyle( FillStyle__S );
|
87 |
|
|
all->SetFillColor( FillColor__S );
|
88 |
|
|
}
|
89 |
|
|
}
|
90 |
|
|
|
91 |
|
|
void SetMultiClassStyle( TObjArray* hists )
|
92 |
|
|
{
|
93 |
|
|
//signal
|
94 |
|
|
// const Int_t FillColor__S = 38 + 150; // change of Color Scheme in ROOT-5.16.
|
95 |
|
|
// convince yourself with gROOT->GetListOfColors()->Print()
|
96 |
|
|
//Int_t FillColor__S = c_SignalFill;
|
97 |
|
|
//Int_t FillStyle__S = 1001;
|
98 |
|
|
//Int_t LineColor__S = c_SignalLine;
|
99 |
|
|
//Int_t LineWidth__S = 2;
|
100 |
|
|
|
101 |
|
|
// background
|
102 |
|
|
//Int_t icolor = UsePaperStyle ? 2 + 100 : 2;
|
103 |
|
|
//Int_t FillColor__B = c_BackgroundFill;
|
104 |
|
|
//Int_t FillStyle__B = 3554;
|
105 |
|
|
//Int_t LineColor__B = c_BackgroundLine;
|
106 |
|
|
//Int_t LineWidth__B = 2;
|
107 |
|
|
|
108 |
|
|
Int_t FillColors[10] = {38,2,3,6,7,8,9,11};
|
109 |
|
|
Int_t LineColors[10] = {4,2,3,6,7,8,9,11};
|
110 |
|
|
Int_t FillStyles[5] = {1001,3554,3003,3545,0};
|
111 |
|
|
|
112 |
|
|
for(Int_t i=0; i<hists->GetEntriesFast(); ++i){
|
113 |
|
|
((TH1*)(*hists)[i])->SetFillColor(FillColors[i%10]);
|
114 |
|
|
((TH1*)(*hists)[i])->SetFillStyle(FillStyles[i%5]);
|
115 |
|
|
((TH1*)(*hists)[i])->SetLineColor(LineColors[i%10]);
|
116 |
|
|
((TH1*)(*hists)[i])->SetLineWidth(2);
|
117 |
|
|
}
|
118 |
|
|
}
|
119 |
|
|
|
120 |
|
|
// set frame styles
|
121 |
|
|
void SetFrameStyle( TH1* frame, Float_t scale = 1.0 )
|
122 |
|
|
{
|
123 |
|
|
frame->SetLabelOffset( 0.012, "X" );// label offset on x axis
|
124 |
|
|
frame->SetLabelOffset( 0.012, "Y" );// label offset on x axis
|
125 |
|
|
frame->GetXaxis()->SetTitleOffset( 1.25 );
|
126 |
|
|
frame->GetYaxis()->SetTitleOffset( 1.22 );
|
127 |
|
|
frame->GetXaxis()->SetTitleSize( 0.045*scale );
|
128 |
|
|
frame->GetYaxis()->SetTitleSize( 0.045*scale );
|
129 |
|
|
Float_t labelSize = 0.04*scale;
|
130 |
|
|
frame->GetXaxis()->SetLabelSize( labelSize );
|
131 |
|
|
frame->GetYaxis()->SetLabelSize( labelSize );
|
132 |
|
|
|
133 |
|
|
// global style settings
|
134 |
|
|
gPad->SetTicks();
|
135 |
|
|
gPad->SetLeftMargin ( 0.108*scale );
|
136 |
|
|
gPad->SetRightMargin ( 0.050*scale );
|
137 |
|
|
gPad->SetBottomMargin( 0.120*scale );
|
138 |
|
|
}
|
139 |
|
|
|
140 |
|
|
void SetTMVAStyle() {
|
141 |
|
|
|
142 |
|
|
TStyle *TMVAStyle = gROOT->GetStyle("TMVA");
|
143 |
|
|
if(TMVAStyle!=0) {
|
144 |
|
|
gROOT->SetStyle("TMVA");
|
145 |
|
|
return;
|
146 |
|
|
}
|
147 |
|
|
|
148 |
|
|
TMVAStyle = new TStyle(*gROOT->GetStyle("Plain")); // our style is based on Plain
|
149 |
|
|
TMVAStyle->SetName("TMVA");
|
150 |
|
|
TMVAStyle->SetTitle("TMVA style based on \"Plain\" with modifications defined in tmvaglob.C");
|
151 |
|
|
gROOT->GetListOfStyles()->Add(TMVAStyle);
|
152 |
|
|
gROOT->SetStyle("TMVA");
|
153 |
|
|
|
154 |
|
|
TMVAStyle->SetLineStyleString( 5, "[52 12]" );
|
155 |
|
|
TMVAStyle->SetLineStyleString( 6, "[22 12]" );
|
156 |
|
|
TMVAStyle->SetLineStyleString( 7, "[22 10 7 10]" );
|
157 |
|
|
|
158 |
|
|
// the pretty color palette of old
|
159 |
|
|
TMVAStyle->SetPalette((UsePaperStyle ? 18 : 1),0);
|
160 |
|
|
|
161 |
|
|
// use plain black on white colors
|
162 |
|
|
TMVAStyle->SetFrameBorderMode(0);
|
163 |
|
|
TMVAStyle->SetCanvasBorderMode(0);
|
164 |
|
|
TMVAStyle->SetPadBorderMode(0);
|
165 |
|
|
TMVAStyle->SetPadColor(0);
|
166 |
|
|
TMVAStyle->SetFillStyle(0);
|
167 |
|
|
|
168 |
|
|
TMVAStyle->SetLegendBorderSize(0);
|
169 |
|
|
|
170 |
|
|
// title properties
|
171 |
|
|
// TMVAStyle->SetTitleW(.4);
|
172 |
|
|
// TMVAStyle->SetTitleH(.10);
|
173 |
|
|
// MVAStyle->SetTitleX(.5);
|
174 |
|
|
// TMVAStyle->SetTitleY(.9);
|
175 |
|
|
TMVAStyle->SetTitleFillColor( c_TitleBox );
|
176 |
|
|
TMVAStyle->SetTitleTextColor( c_TitleText );
|
177 |
|
|
TMVAStyle->SetTitleBorderSize( 1 );
|
178 |
|
|
TMVAStyle->SetLineColor( c_TitleBorder );
|
179 |
|
|
if (!UsePaperStyle) {
|
180 |
|
|
TMVAStyle->SetFrameFillColor( c_FrameFill );
|
181 |
|
|
TMVAStyle->SetCanvasColor( c_Canvas );
|
182 |
|
|
}
|
183 |
|
|
|
184 |
|
|
// set the paper & margin sizes
|
185 |
|
|
TMVAStyle->SetPaperSize(20,26);
|
186 |
|
|
TMVAStyle->SetPadTopMargin(0.10);
|
187 |
|
|
TMVAStyle->SetPadRightMargin(0.05);
|
188 |
|
|
TMVAStyle->SetPadBottomMargin(0.11);
|
189 |
|
|
TMVAStyle->SetPadLeftMargin(0.12);
|
190 |
|
|
|
191 |
|
|
// use bold lines and markers
|
192 |
|
|
TMVAStyle->SetMarkerStyle(21);
|
193 |
|
|
TMVAStyle->SetMarkerSize(0.3);
|
194 |
|
|
TMVAStyle->SetHistLineWidth(2);
|
195 |
|
|
TMVAStyle->SetLineStyleString(2,"[12 12]"); // postscript dashes
|
196 |
|
|
|
197 |
|
|
// do not display any of the standard histogram decorations
|
198 |
|
|
TMVAStyle->SetOptTitle(1);
|
199 |
|
|
TMVAStyle->SetTitleH(0.052);
|
200 |
|
|
|
201 |
|
|
TMVAStyle->SetOptStat(0);
|
202 |
|
|
TMVAStyle->SetOptFit(0);
|
203 |
|
|
|
204 |
|
|
// put tick marks on top and RHS of plots
|
205 |
|
|
TMVAStyle->SetPadTickX(1);
|
206 |
|
|
TMVAStyle->SetPadTickY(1);
|
207 |
|
|
|
208 |
|
|
}
|
209 |
|
|
|
210 |
|
|
void DestroyCanvases()
|
211 |
|
|
{
|
212 |
|
|
|
213 |
|
|
TList* loc = (TList*)gROOT->GetListOfCanvases();
|
214 |
|
|
TListIter itc(loc);
|
215 |
|
|
TObject *o(0);
|
216 |
|
|
while ((o = itc())) delete o;
|
217 |
|
|
}
|
218 |
|
|
|
219 |
|
|
// set style and remove existing canvas'
|
220 |
|
|
void Initialize( Bool_t useTMVAStyle = kTRUE )
|
221 |
|
|
{
|
222 |
|
|
// destroy canvas'
|
223 |
|
|
DestroyCanvases();
|
224 |
|
|
|
225 |
|
|
// set style
|
226 |
|
|
if (!useTMVAStyle) {
|
227 |
|
|
gROOT->SetStyle("Plain");
|
228 |
|
|
gStyle->SetOptStat(0);
|
229 |
|
|
return;
|
230 |
|
|
}
|
231 |
|
|
|
232 |
|
|
SetTMVAStyle();
|
233 |
|
|
}
|
234 |
|
|
|
235 |
|
|
// checks if file with name "fin" is already open, and if not opens one
|
236 |
|
|
TFile* OpenFile( const TString& fin )
|
237 |
|
|
{
|
238 |
|
|
TFile* file = gDirectory->GetFile();
|
239 |
|
|
if (file==0 || fin != file->GetName()) {
|
240 |
|
|
if (file != 0) {
|
241 |
|
|
gROOT->cd();
|
242 |
|
|
file->Close();
|
243 |
|
|
}
|
244 |
|
|
cout << "--- Opening root file " << fin << " in read mode" << endl;
|
245 |
|
|
file = TFile::Open( fin, "READ" );
|
246 |
|
|
}
|
247 |
|
|
else {
|
248 |
|
|
file = gDirectory->GetFile();
|
249 |
|
|
}
|
250 |
|
|
|
251 |
|
|
file->cd();
|
252 |
|
|
return file;
|
253 |
|
|
}
|
254 |
|
|
|
255 |
|
|
// used to create output file for canvas
|
256 |
|
|
void imgconv( TCanvas* c, const TString & fname )
|
257 |
|
|
{
|
258 |
|
|
// return;
|
259 |
|
|
if (NULL == c) {
|
260 |
|
|
cout << "*** Error in TMVAGlob::imgconv: canvas is NULL" << endl;
|
261 |
|
|
}
|
262 |
|
|
else {
|
263 |
|
|
// create directory if not existing
|
264 |
|
|
TString f = fname;
|
265 |
|
|
TString dir = f.Remove( f.Last( '/' ), f.Length() - f.Last( '/' ) );
|
266 |
|
|
gSystem->mkdir( dir );
|
267 |
|
|
|
268 |
|
|
TString pngName = fname + ".png";
|
269 |
|
|
TString gifName = fname + ".gif";
|
270 |
|
|
TString epsName = fname + ".eps";
|
271 |
|
|
c->cd();
|
272 |
|
|
|
273 |
|
|
// create eps (other option: c->Print( epsName ))
|
274 |
|
|
if (UsePaperStyle) {
|
275 |
|
|
c->Print(epsName);
|
276 |
|
|
}
|
277 |
|
|
else {
|
278 |
|
|
cout << "--- --------------------------------------------------------------------" << endl;
|
279 |
|
|
cout << "--- If you want to save the image as eps, gif or png, please comment out " << endl;
|
280 |
|
|
cout << "--- the corresponding lines (line no. 239-241) in tmvaglob.C" << endl;
|
281 |
|
|
cout << "--- --------------------------------------------------------------------" << endl;
|
282 |
|
|
c->Print(epsName);
|
283 |
|
|
c->Print(pngName);
|
284 |
|
|
// c->Print(gifName);
|
285 |
|
|
}
|
286 |
|
|
}
|
287 |
|
|
}
|
288 |
|
|
|
289 |
|
|
TImage * findImage(const char * imageName)
|
290 |
|
|
{
|
291 |
|
|
// looks for the image in macropath
|
292 |
|
|
TString macroPath(gROOT->GetMacroPath()); // look for the image in here
|
293 |
|
|
Ssiz_t curIndex(0);
|
294 |
|
|
TImage *img(0);
|
295 |
|
|
while(1) {
|
296 |
|
|
Ssiz_t pathStart = curIndex;
|
297 |
|
|
curIndex = macroPath.Index(":",curIndex);
|
298 |
|
|
Ssiz_t pathEnd = (curIndex==-1)?macroPath.Length():curIndex;
|
299 |
|
|
TString path(macroPath(pathStart,pathEnd-pathStart));
|
300 |
|
|
|
301 |
|
|
gSystem->ExpandPathName(path);
|
302 |
|
|
const char* fullName = Form("%s/%s", path.Data(), imageName);
|
303 |
|
|
|
304 |
|
|
Bool_t fileFound = ! gSystem->AccessPathName(fullName);
|
305 |
|
|
|
306 |
|
|
if(fileFound) {
|
307 |
|
|
img = TImage::Open(fullName);
|
308 |
|
|
break;
|
309 |
|
|
}
|
310 |
|
|
if(curIndex==-1) break;
|
311 |
|
|
curIndex++;
|
312 |
|
|
}
|
313 |
|
|
return img;
|
314 |
|
|
}
|
315 |
|
|
|
316 |
|
|
void plot_logo( Float_t v_scale = 1.0, Float_t skew = 1.0 )
|
317 |
|
|
{
|
318 |
|
|
|
319 |
|
|
TImage *img = findImage("tmva_logo.gif");
|
320 |
|
|
if (!img) {
|
321 |
|
|
cout << "+++ Could not open image tmva_logo.gif" << endl;
|
322 |
|
|
return;
|
323 |
|
|
}
|
324 |
|
|
|
325 |
|
|
img->SetConstRatio(kFALSE);
|
326 |
|
|
UInt_t h_ = img->GetHeight();
|
327 |
|
|
UInt_t w_ = img->GetWidth();
|
328 |
|
|
|
329 |
|
|
Float_t r = w_/h_;
|
330 |
|
|
gPad->Update();
|
331 |
|
|
Float_t rpad = Double_t(gPad->VtoAbsPixel(0) - gPad->VtoAbsPixel(1))/(gPad->UtoAbsPixel(1) - gPad->UtoAbsPixel(0));
|
332 |
|
|
r *= rpad;
|
333 |
|
|
|
334 |
|
|
Float_t d = 0.055;
|
335 |
|
|
// absolute coordinates
|
336 |
|
|
Float_t x1R = 1 - gStyle->GetPadRightMargin();
|
337 |
|
|
Float_t y1B = 1 - gStyle->GetPadTopMargin()+.01; // we like the logo to sit a bit above the histo
|
338 |
|
|
|
339 |
|
|
Float_t x1L = x1R - d*r/skew;
|
340 |
|
|
Float_t y1T = y1B + d*v_scale*skew;
|
341 |
|
|
if (y1T>0.99) y1T = 0.99;
|
342 |
|
|
|
343 |
|
|
TPad *p1 = new TPad("imgpad", "imgpad", x1L, y1B, x1R, y1T );
|
344 |
|
|
p1->SetRightMargin(0);
|
345 |
|
|
p1->SetBottomMargin(0);
|
346 |
|
|
p1->SetLeftMargin(0);
|
347 |
|
|
p1->SetTopMargin(0);
|
348 |
|
|
p1->Draw();
|
349 |
|
|
|
350 |
|
|
Int_t xSizeInPixel = p1->UtoAbsPixel(1) - p1->UtoAbsPixel(0);
|
351 |
|
|
Int_t ySizeInPixel = p1->VtoAbsPixel(0) - p1->VtoAbsPixel(1);
|
352 |
|
|
if (xSizeInPixel<=25 || ySizeInPixel<=25) {
|
353 |
|
|
delete p1;
|
354 |
|
|
return; // ROOT doesn't draw smaller than this
|
355 |
|
|
}
|
356 |
|
|
|
357 |
|
|
p1->cd();
|
358 |
|
|
img->Draw();
|
359 |
|
|
}
|
360 |
|
|
|
361 |
|
|
void NormalizeHist( TH1* h )
|
362 |
|
|
{
|
363 |
|
|
if (h==0) return;
|
364 |
|
|
if (h->GetSumw2N() == 0) h->Sumw2();
|
365 |
|
|
if(h->GetSumOfWeights()!=0) {
|
366 |
|
|
Float_t dx = (h->GetXaxis()->GetXmax() - h->GetXaxis()->GetXmin())/h->GetNbinsX();
|
367 |
|
|
h->Scale( 1.0/h->GetSumOfWeights()/dx );
|
368 |
|
|
}
|
369 |
|
|
}
|
370 |
|
|
void NormalizeHists( TH1* sig, TH1* bkg = 0 )
|
371 |
|
|
{
|
372 |
|
|
if (sig->GetSumw2N() == 0) sig->Sumw2();
|
373 |
|
|
if (bkg && bkg->GetSumw2N() == 0) bkg->Sumw2();
|
374 |
|
|
|
375 |
|
|
if(sig->GetSumOfWeights()!=0) {
|
376 |
|
|
Float_t dx = (sig->GetXaxis()->GetXmax() - sig->GetXaxis()->GetXmin())/sig->GetNbinsX();
|
377 |
|
|
sig->Scale( 1.0/sig->GetSumOfWeights()/dx );
|
378 |
|
|
}
|
379 |
|
|
if (bkg != 0 && bkg->GetSumOfWeights()!=0) {
|
380 |
|
|
Float_t dx = (bkg->GetXaxis()->GetXmax() - bkg->GetXaxis()->GetXmin())/bkg->GetNbinsX();
|
381 |
|
|
bkg->Scale( 1.0/bkg->GetSumOfWeights()/dx );
|
382 |
|
|
}
|
383 |
|
|
}
|
384 |
|
|
|
385 |
|
|
// the following are tools to help handling different methods and titles
|
386 |
|
|
|
387 |
|
|
|
388 |
|
|
void GetMethodName( TString & name, TKey * mkey ) {
|
389 |
|
|
if (mkey==0) return;
|
390 |
|
|
name = mkey->GetName();
|
391 |
|
|
name.ReplaceAll("Method_","");
|
392 |
|
|
}
|
393 |
|
|
|
394 |
|
|
void GetMethodTitle( TString & name, TKey * ikey ) {
|
395 |
|
|
if (ikey==0) return;
|
396 |
|
|
name = ikey->GetName();
|
397 |
|
|
}
|
398 |
|
|
|
399 |
|
|
void GetMethodName( TString & name, TDirectory * mdir ) {
|
400 |
|
|
if (mdir==0) return;
|
401 |
|
|
name = mdir->GetName();
|
402 |
|
|
name.ReplaceAll("Method_","");
|
403 |
|
|
}
|
404 |
|
|
|
405 |
|
|
void GetMethodTitle( TString & name, TDirectory * idir ) {
|
406 |
|
|
if (idir==0) return;
|
407 |
|
|
name = idir->GetName();
|
408 |
|
|
}
|
409 |
|
|
|
410 |
|
|
TKey *NextKey( TIter & keyIter, TString className) {
|
411 |
|
|
TKey *key=(TKey *)keyIter.Next();
|
412 |
|
|
TKey *rkey=0;
|
413 |
|
|
Bool_t loop=(key!=0);
|
414 |
|
|
//
|
415 |
|
|
while (loop) {
|
416 |
|
|
TClass *cl = gROOT->GetClass(key->GetClassName());
|
417 |
|
|
if (cl->InheritsFrom(className.Data())) {
|
418 |
|
|
loop = kFALSE;
|
419 |
|
|
rkey = key;
|
420 |
|
|
} else {
|
421 |
|
|
key = (TKey *)keyIter.Next();
|
422 |
|
|
if (key==0) loop = kFALSE;
|
423 |
|
|
}
|
424 |
|
|
}
|
425 |
|
|
return rkey;
|
426 |
|
|
}
|
427 |
|
|
|
428 |
|
|
UInt_t GetListOfKeys( TList& keys, TString inherits, TDirectory *dir=0 )
|
429 |
|
|
{
|
430 |
|
|
// get a list of keys with a given inheritance
|
431 |
|
|
// the list contains TKey objects
|
432 |
|
|
if (dir==0) dir = gDirectory;
|
433 |
|
|
TIter mnext(dir->GetListOfKeys());
|
434 |
|
|
TKey *mkey;
|
435 |
|
|
keys.Clear();
|
436 |
|
|
keys.SetOwner(kFALSE);
|
437 |
|
|
UInt_t ni=0;
|
438 |
|
|
while ((mkey = (TKey*)mnext())) {
|
439 |
|
|
// make sure, that we only look at TDirectory with name Method_<xxx>
|
440 |
|
|
TClass *cl = gROOT->GetClass(mkey->GetClassName());
|
441 |
|
|
if (cl->InheritsFrom(inherits)) {
|
442 |
|
|
keys.Add(mkey);
|
443 |
|
|
ni++;
|
444 |
|
|
}
|
445 |
|
|
}
|
446 |
|
|
return ni;
|
447 |
|
|
}
|
448 |
|
|
|
449 |
|
|
Int_t GetNumberOfTargets( TDirectory *dir )
|
450 |
|
|
{
|
451 |
|
|
TIter next(dir->GetListOfKeys());
|
452 |
|
|
TKey* key = 0;
|
453 |
|
|
Int_t noTrgts = 0;
|
454 |
|
|
|
455 |
|
|
while ((key = (TKey*)next())) {
|
456 |
|
|
if (key->GetCycle() != 1) continue;
|
457 |
|
|
if (TString(key->GetName()).Contains("__Regression_target")) noTrgts++;
|
458 |
|
|
}
|
459 |
|
|
return noTrgts;
|
460 |
|
|
}
|
461 |
|
|
|
462 |
|
|
Int_t GetNumberOfInputVariables( TDirectory *dir )
|
463 |
|
|
{
|
464 |
|
|
TIter next(dir->GetListOfKeys());
|
465 |
|
|
TKey* key = 0;
|
466 |
|
|
Int_t noVars = 0;
|
467 |
|
|
|
468 |
|
|
while ((key = (TKey*)next())) {
|
469 |
|
|
if (key->GetCycle() != 1) continue;
|
470 |
|
|
|
471 |
|
|
// count number of variables (signal is sufficient), exclude target(s)
|
472 |
|
|
if (TString(key->GetName()).Contains("__Signal") || (TString(key->GetName()).Contains("__Regression") && !(TString(key->GetName()).Contains("__Regression_target")))) noVars++;
|
473 |
|
|
}
|
474 |
|
|
|
475 |
|
|
return noVars;
|
476 |
|
|
}
|
477 |
|
|
|
478 |
|
|
std::vector<TString> GetInputVariableNames(TDirectory *dir )
|
479 |
|
|
{
|
480 |
|
|
TIter next(dir->GetListOfKeys());
|
481 |
|
|
TKey* key = 0;
|
482 |
|
|
//set<std::string> varnames;
|
483 |
|
|
std::vector<TString> names;
|
484 |
|
|
|
485 |
|
|
while ((key = (TKey*)next())) {
|
486 |
|
|
if (key->GetCycle() != 1) continue;
|
487 |
|
|
TClass *cl = gROOT->GetClass(key->GetClassName());
|
488 |
|
|
if (!cl->InheritsFrom("TH1")) continue;
|
489 |
|
|
TString name(key->GetName());
|
490 |
|
|
Int_t pos = name.First("__");
|
491 |
|
|
name.Remove(pos);
|
492 |
|
|
Bool_t hasname = false;
|
493 |
|
|
std::vector<TString>::const_iterator iter = names.begin();
|
494 |
|
|
while(iter != names.end()){
|
495 |
|
|
if(name.CompareTo(*iter)==0)
|
496 |
|
|
hasname=true;
|
497 |
|
|
iter++;
|
498 |
|
|
}
|
499 |
|
|
if(!hasname)
|
500 |
|
|
names.push_back(name);
|
501 |
|
|
}
|
502 |
|
|
return names;
|
503 |
|
|
}
|
504 |
|
|
|
505 |
|
|
Int_t GetNumberOfInputVariablesMultiClass( TDirectory *dir ){
|
506 |
|
|
std::vector<TString> names(GetInputVariableNames(dir));
|
507 |
|
|
return names.end() - names.begin();
|
508 |
|
|
}
|
509 |
|
|
|
510 |
|
|
std::vector<TString> GetClassNames(TDirectory *dir )
|
511 |
|
|
{
|
512 |
|
|
|
513 |
|
|
TIter next(dir->GetListOfKeys());
|
514 |
|
|
TKey* key = 0;
|
515 |
|
|
//set<std::string> varnames;
|
516 |
|
|
std::vector<TString> names;
|
517 |
|
|
|
518 |
|
|
while ((key = (TKey*)next())) {
|
519 |
|
|
if (key->GetCycle() != 1) continue;
|
520 |
|
|
TClass *cl = gROOT->GetClass(key->GetClassName());
|
521 |
|
|
if (!cl->InheritsFrom("TH1")) continue;
|
522 |
|
|
TString name(key->GetName());
|
523 |
|
|
name.ReplaceAll("_Deco","");
|
524 |
|
|
name.ReplaceAll("_Gauss","");
|
525 |
|
|
name.ReplaceAll("_PCA","");
|
526 |
|
|
name.ReplaceAll("_Id","");
|
527 |
|
|
name.ReplaceAll("_vs_","");
|
528 |
|
|
char c = '_';
|
529 |
|
|
Int_t pos = name.Last(c);
|
530 |
|
|
name.Remove(0,pos+1);
|
531 |
|
|
|
532 |
|
|
/*Int_t pos = name.First("__");
|
533 |
|
|
name.Remove(0,pos+2);
|
534 |
|
|
char c = '_';
|
535 |
|
|
pos = name.Last(c);
|
536 |
|
|
name.Remove(pos);
|
537 |
|
|
if(name.Contains("Gauss")){
|
538 |
|
|
pos = name.Last(c);
|
539 |
|
|
name.Remove(pos);
|
540 |
|
|
}
|
541 |
|
|
pos = name.Last(c);
|
542 |
|
|
if(pos!=-1)
|
543 |
|
|
name.Remove(0,pos+1);
|
544 |
|
|
*/
|
545 |
|
|
Bool_t hasname = false;
|
546 |
|
|
std::vector<TString>::const_iterator iter = names.begin();
|
547 |
|
|
while(iter != names.end()){
|
548 |
|
|
if(name.CompareTo(*iter)==0)
|
549 |
|
|
hasname=true;
|
550 |
|
|
iter++;
|
551 |
|
|
}
|
552 |
|
|
if(!hasname)
|
553 |
|
|
names.push_back(name);
|
554 |
|
|
}
|
555 |
|
|
return names;
|
556 |
|
|
}
|
557 |
|
|
|
558 |
|
|
|
559 |
|
|
TKey* FindMethod( TString name, TDirectory *dir=0 )
|
560 |
|
|
{
|
561 |
|
|
// find the key for a method
|
562 |
|
|
if (dir==0) dir = gDirectory;
|
563 |
|
|
TIter mnext(dir->GetListOfKeys());
|
564 |
|
|
TKey *mkey;
|
565 |
|
|
TKey *retkey=0;
|
566 |
|
|
Bool_t loop=kTRUE;
|
567 |
|
|
while (loop) {
|
568 |
|
|
mkey = (TKey*)mnext();
|
569 |
|
|
if (mkey==0) {
|
570 |
|
|
loop = kFALSE;
|
571 |
|
|
}
|
572 |
|
|
else {
|
573 |
|
|
TString clname = mkey->GetClassName();
|
574 |
|
|
TClass *cl = gROOT->GetClass(clname);
|
575 |
|
|
if (cl->InheritsFrom("TDirectory")) {
|
576 |
|
|
TString mname = mkey->GetName(); // method name
|
577 |
|
|
TString tname = "Method_"+name; // target name
|
578 |
|
|
if (mname==tname) { // target found!
|
579 |
|
|
loop = kFALSE;
|
580 |
|
|
retkey = mkey;
|
581 |
|
|
}
|
582 |
|
|
}
|
583 |
|
|
}
|
584 |
|
|
}
|
585 |
|
|
return retkey;
|
586 |
|
|
}
|
587 |
|
|
|
588 |
|
|
Bool_t ExistMethodName( TString name, TDirectory *dir=0 )
|
589 |
|
|
{
|
590 |
|
|
// find the key for a method
|
591 |
|
|
if (dir==0) dir = gDirectory;
|
592 |
|
|
TIter mnext(dir->GetListOfKeys());
|
593 |
|
|
TKey *mkey;
|
594 |
|
|
Bool_t loop=kTRUE;
|
595 |
|
|
while (loop) {
|
596 |
|
|
mkey = (TKey*)mnext();
|
597 |
|
|
if (mkey==0) {
|
598 |
|
|
loop = kFALSE;
|
599 |
|
|
}
|
600 |
|
|
else {
|
601 |
|
|
TString clname = mkey->GetClassName();
|
602 |
|
|
TString keyname = mkey->GetName();
|
603 |
|
|
TClass *cl = gROOT->GetClass(clname);
|
604 |
|
|
if (keyname.Contains("Method") && cl->InheritsFrom("TDirectory")) {
|
605 |
|
|
|
606 |
|
|
TDirectory* d_ = (TDirectory*)dir->Get( keyname );
|
607 |
|
|
if (!d_) {
|
608 |
|
|
cout << "HUUUGE TROUBLES IN TMVAGlob::ExistMethodName() --> contact authors" << endl;
|
609 |
|
|
return kFALSE;
|
610 |
|
|
}
|
611 |
|
|
|
612 |
|
|
TIter mnext_(d_->GetListOfKeys());
|
613 |
|
|
TKey *mkey_;
|
614 |
|
|
while ((mkey_ = (TKey*)mnext_())) {
|
615 |
|
|
TString clname_ = mkey_->GetClassName();
|
616 |
|
|
TClass *cl_ = gROOT->GetClass(clname_);
|
617 |
|
|
if (cl_->InheritsFrom("TDirectory")) {
|
618 |
|
|
TString mname = mkey_->GetName(); // method name
|
619 |
|
|
if (mname==name) { // target found!
|
620 |
|
|
return kTRUE;
|
621 |
|
|
}
|
622 |
|
|
}
|
623 |
|
|
}
|
624 |
|
|
}
|
625 |
|
|
}
|
626 |
|
|
}
|
627 |
|
|
return kFALSE;
|
628 |
|
|
}
|
629 |
|
|
|
630 |
|
|
UInt_t GetListOfMethods( TList & methods, TDirectory *dir=0 )
|
631 |
|
|
{
|
632 |
|
|
// get a list of methods
|
633 |
|
|
// the list contains TKey objects
|
634 |
|
|
if (dir==0) dir = gDirectory;
|
635 |
|
|
TIter mnext(dir->GetListOfKeys());
|
636 |
|
|
TKey *mkey;
|
637 |
|
|
methods.Clear();
|
638 |
|
|
methods.SetOwner(kFALSE);
|
639 |
|
|
UInt_t ni=0;
|
640 |
|
|
while ((mkey = (TKey*)mnext())) {
|
641 |
|
|
// make sure, that we only look at TDirectory with name Method_<xxx>
|
642 |
|
|
TString name = mkey->GetClassName();
|
643 |
|
|
TClass *cl = gROOT->GetClass(name);
|
644 |
|
|
if (cl->InheritsFrom("TDirectory")) {
|
645 |
|
|
if (TString(mkey->GetName()).BeginsWith("Method_")) {
|
646 |
|
|
methods.Add(mkey);
|
647 |
|
|
ni++;
|
648 |
|
|
}
|
649 |
|
|
}
|
650 |
|
|
}
|
651 |
|
|
cout << "--- Found " << ni << " classifier types" << endl;
|
652 |
|
|
return ni;
|
653 |
|
|
}
|
654 |
|
|
|
655 |
|
|
UInt_t GetListOfJobs( TFile* file, TList& jobdirs)
|
656 |
|
|
{
|
657 |
|
|
// get a list of all jobs in all method directories
|
658 |
|
|
// based on ideas by Peter and Joerg found in macro deviations.C
|
659 |
|
|
TIter next(file->GetListOfKeys());
|
660 |
|
|
TKey *key(0);
|
661 |
|
|
while ((key = (TKey*)next())) {
|
662 |
|
|
|
663 |
|
|
if (TString(key->GetName()).BeginsWith("Method_")) {
|
664 |
|
|
if (gROOT->GetClass(key->GetClassName())->InheritsFrom("TDirectory")) {
|
665 |
|
|
|
666 |
|
|
TDirectory* mDir = (TDirectory*)key->ReadObj();
|
667 |
|
|
|
668 |
|
|
TIter keyIt(mDir->GetListOfKeys());
|
669 |
|
|
TKey *jobkey;
|
670 |
|
|
while ((jobkey = (TKey*)keyIt())) {
|
671 |
|
|
if (!gROOT->GetClass(jobkey->GetClassName())->InheritsFrom("TDirectory")) continue;
|
672 |
|
|
|
673 |
|
|
TDirectory *jobDir = (TDirectory *)jobkey->ReadObj();
|
674 |
|
|
cout << "jobdir name " << jobDir->GetName() << endl;
|
675 |
|
|
jobdirs.Add(jobDir);
|
676 |
|
|
}
|
677 |
|
|
}
|
678 |
|
|
}
|
679 |
|
|
}
|
680 |
|
|
return jobdirs.GetSize();
|
681 |
|
|
}
|
682 |
|
|
|
683 |
|
|
UInt_t GetListOfTitles( TDirectory *rfdir, TList & titles )
|
684 |
|
|
{
|
685 |
|
|
// get a list of titles (i.e TDirectory) given a method dir
|
686 |
|
|
UInt_t ni=0;
|
687 |
|
|
if (rfdir==0) return 0;
|
688 |
|
|
TList *keys = rfdir->GetListOfKeys();
|
689 |
|
|
if (keys==0) {
|
690 |
|
|
cout << "+++ Directory '" << rfdir->GetName() << "' contains no keys" << endl;
|
691 |
|
|
return 0;
|
692 |
|
|
}
|
693 |
|
|
//
|
694 |
|
|
TIter rfnext(rfdir->GetListOfKeys());
|
695 |
|
|
TKey *rfkey;
|
696 |
|
|
titles.Clear();
|
697 |
|
|
titles.SetOwner(kFALSE);
|
698 |
|
|
while ((rfkey = (TKey*)rfnext())) {
|
699 |
|
|
// make sure, that we only look at histograms
|
700 |
|
|
TClass *cl = gROOT->GetClass(rfkey->GetClassName());
|
701 |
|
|
if (cl->InheritsFrom("TDirectory")) {
|
702 |
|
|
titles.Add(rfkey);
|
703 |
|
|
ni++;
|
704 |
|
|
}
|
705 |
|
|
}
|
706 |
|
|
cout << "--- Found " << ni << " instance(s) of the method " << rfdir->GetName() << endl;
|
707 |
|
|
return ni;
|
708 |
|
|
}
|
709 |
|
|
|
710 |
|
|
UInt_t GetListOfTitles( TString & methodName, TList & titles, TDirectory *dir=0 )
|
711 |
|
|
{
|
712 |
|
|
// get the list of all titles for a given method
|
713 |
|
|
// if the input dir is 0, gDirectory is used
|
714 |
|
|
// returns a list of keys
|
715 |
|
|
UInt_t ni=0;
|
716 |
|
|
if (dir==0) dir = gDirectory;
|
717 |
|
|
TDirectory* rfdir = (TDirectory*)dir->Get( methodName );
|
718 |
|
|
if (rfdir==0) {
|
719 |
|
|
cout << "+++ Could not locate directory '" << methodName << endl;
|
720 |
|
|
return 0;
|
721 |
|
|
}
|
722 |
|
|
|
723 |
|
|
return GetListOfTitles( rfdir, titles );
|
724 |
|
|
|
725 |
|
|
TList *keys = rfdir->GetListOfKeys();
|
726 |
|
|
if (keys==0) {
|
727 |
|
|
cout << "+++ Directory '" << methodName << "' contains no keys" << endl;
|
728 |
|
|
return 0;
|
729 |
|
|
}
|
730 |
|
|
//
|
731 |
|
|
TIter rfnext(rfdir->GetListOfKeys());
|
732 |
|
|
TKey *rfkey;
|
733 |
|
|
titles.Clear();
|
734 |
|
|
titles.SetOwner(kFALSE);
|
735 |
|
|
while ((rfkey = (TKey*)rfnext())) {
|
736 |
|
|
// make sure, that we only look at histograms
|
737 |
|
|
TClass *cl = gROOT->GetClass(rfkey->GetClassName());
|
738 |
|
|
if (cl->InheritsFrom("TDirectory")) {
|
739 |
|
|
titles.Add(rfkey);
|
740 |
|
|
ni++;
|
741 |
|
|
}
|
742 |
|
|
}
|
743 |
|
|
cout << "--- Found " << ni << " instance(s) of the method " << methodName << endl;
|
744 |
|
|
return ni;
|
745 |
|
|
}
|
746 |
|
|
|
747 |
|
|
TDirectory *GetInputVariablesDir( TMVAGlob::TypeOfPlot type, TDirectory *dir=0 )
|
748 |
|
|
{
|
749 |
|
|
// get the InputVariables directory
|
750 |
|
|
const TString directories[TMVAGlob::kNumOfMethods] = { "InputVariables_Id",
|
751 |
|
|
"InputVariables_Deco",
|
752 |
|
|
"InputVariables_PCA",
|
753 |
|
|
"InputVariables_Gauss_Deco" };
|
754 |
|
|
if (dir==0) dir = gDirectory;
|
755 |
|
|
|
756 |
|
|
// get top dir containing all hists of the variables
|
757 |
|
|
dir = (TDirectory*)gDirectory->Get( directories[type] );
|
758 |
|
|
if (dir==0) {
|
759 |
|
|
cout << "+++ Could not locate input variable directory '" << directories[type] << endl;
|
760 |
|
|
return 0;
|
761 |
|
|
}
|
762 |
|
|
return dir;
|
763 |
|
|
}
|
764 |
|
|
|
765 |
|
|
TDirectory *GetCorrelationPlotsDir( TMVAGlob::TypeOfPlot type, TDirectory *dir=0 )
|
766 |
|
|
{
|
767 |
|
|
// get the CorrelationPlots directory
|
768 |
|
|
if (dir==0) dir = GetInputVariablesDir( type, 0 );
|
769 |
|
|
if (dir==0) return 0;
|
770 |
|
|
//
|
771 |
|
|
TDirectory* corrdir = (TDirectory*)dir->Get( "CorrelationPlots" );
|
772 |
|
|
if (corrdir==0) {
|
773 |
|
|
cout << "+++ Could not find CorrelationPlots directory 'CorrelationPlots'" << endl;
|
774 |
|
|
return 0;
|
775 |
|
|
}
|
776 |
|
|
return corrdir;
|
777 |
|
|
}
|
778 |
|
|
|
779 |
|
|
}
|
780 |
|
|
|
781 |
|
|
#endif
|