00001
00002 #ifndef TMVA_TMVAGLOB
00003 #define TMVA_TMVAGLOB
00004
00005 #include <iostream>
00006 #include <vector>
00007
00008 #include "TPad.h"
00009 #include "TCanvas.h"
00010 #include "TColor.h"
00011 #include "TSystem.h"
00012 #include "TImage.h"
00013 #include "TKey.h"
00014 #include "TH1.h"
00015 #include "TROOT.h"
00016 #include "TStyle.h"
00017 #include "TFile.h"
00018 #include "TDirectory.h"
00019 #include "TObjArray.h"
00020
00021
00022 #include "RVersion.h"
00023
00024 using std::cout;
00025 using std::endl;
00026
00027 namespace TMVAGlob {
00028
00029
00030 static Bool_t UsePaperStyle = 0;
00031
00032
00033 enum TypeOfPlot { kId = 0,
00034 kNorm,
00035 kDecorrelated,
00036 kPCA,
00037 kGaussDecorr,
00038 kNumOfMethods };
00039
00040 static Int_t c_Canvas = TColor::GetColor( "#f0f0f0" );
00041 static Int_t c_FrameFill = TColor::GetColor( "#fffffd" );
00042 static Int_t c_TitleBox = TColor::GetColor( "#5D6B7D" );
00043 static Int_t c_TitleBorder = TColor::GetColor( "#7D8B9D" );
00044 static Int_t c_TitleText = TColor::GetColor( "#FFFFFF" );
00045 static Int_t c_SignalLine = TColor::GetColor( "#0000ee" );
00046 static Int_t c_SignalFill = TColor::GetColor( "#7d99d1" );
00047 static Int_t c_BackgroundLine = TColor::GetColor( "#ff0000" );
00048 static Int_t c_BackgroundFill = TColor::GetColor( "#ff0000" );
00049 static Int_t c_NovelBlue = TColor::GetColor( "#2244a5" );
00050
00051
00052 void SetSignalAndBackgroundStyle( TH1* sig, TH1* bkg, TH1* all = 0 )
00053 {
00054
00055
00056
00057 Int_t FillColor__S = c_SignalFill;
00058 Int_t FillStyle__S = 1001;
00059 Int_t LineColor__S = c_SignalLine;
00060 Int_t LineWidth__S = 2;
00061
00062
00063
00064 Int_t FillColor__B = c_BackgroundFill;
00065 Int_t FillStyle__B = 3554;
00066 Int_t LineColor__B = c_BackgroundLine;
00067 Int_t LineWidth__B = 2;
00068
00069 if (sig != NULL) {
00070 sig->SetLineColor( LineColor__S );
00071 sig->SetLineWidth( LineWidth__S );
00072 sig->SetFillStyle( FillStyle__S );
00073 sig->SetFillColor( FillColor__S );
00074 }
00075
00076 if (bkg != NULL) {
00077 bkg->SetLineColor( LineColor__B );
00078 bkg->SetLineWidth( LineWidth__B );
00079 bkg->SetFillStyle( FillStyle__B );
00080 bkg->SetFillColor( FillColor__B );
00081 }
00082
00083 if (all != NULL) {
00084 all->SetLineColor( LineColor__S );
00085 all->SetLineWidth( LineWidth__S );
00086 all->SetFillStyle( FillStyle__S );
00087 all->SetFillColor( FillColor__S );
00088 }
00089 }
00090
00091 void SetMultiClassStyle( TObjArray* hists )
00092 {
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108 Int_t FillColors[10] = {38,2,3,6,7,8,9,11};
00109 Int_t LineColors[10] = {4,2,3,6,7,8,9,11};
00110 Int_t FillStyles[5] = {1001,3554,3003,3545,0};
00111
00112 for(Int_t i=0; i<hists->GetEntriesFast(); ++i){
00113 ((TH1*)(*hists)[i])->SetFillColor(FillColors[i%10]);
00114 ((TH1*)(*hists)[i])->SetFillStyle(FillStyles[i%5]);
00115 ((TH1*)(*hists)[i])->SetLineColor(LineColors[i%10]);
00116 ((TH1*)(*hists)[i])->SetLineWidth(2);
00117 }
00118 }
00119
00120
00121 void SetFrameStyle( TH1* frame, Float_t scale = 1.0 )
00122 {
00123 frame->SetLabelOffset( 0.012, "X" );
00124 frame->SetLabelOffset( 0.012, "Y" );
00125 frame->GetXaxis()->SetTitleOffset( 1.25 );
00126 frame->GetYaxis()->SetTitleOffset( 1.22 );
00127 frame->GetXaxis()->SetTitleSize( 0.045*scale );
00128 frame->GetYaxis()->SetTitleSize( 0.045*scale );
00129 Float_t labelSize = 0.04*scale;
00130 frame->GetXaxis()->SetLabelSize( labelSize );
00131 frame->GetYaxis()->SetLabelSize( labelSize );
00132
00133
00134 gPad->SetTicks();
00135 gPad->SetLeftMargin ( 0.108*scale );
00136 gPad->SetRightMargin ( 0.050*scale );
00137 gPad->SetBottomMargin( 0.120*scale );
00138 }
00139
00140 void SetTMVAStyle() {
00141
00142 TStyle *TMVAStyle = gROOT->GetStyle("TMVA");
00143 if(TMVAStyle!=0) {
00144 gROOT->SetStyle("TMVA");
00145 return;
00146 }
00147
00148 TMVAStyle = new TStyle(*gROOT->GetStyle("Plain"));
00149 TMVAStyle->SetName("TMVA");
00150 TMVAStyle->SetTitle("TMVA style based on \"Plain\" with modifications defined in tmvaglob.C");
00151 gROOT->GetListOfStyles()->Add(TMVAStyle);
00152 gROOT->SetStyle("TMVA");
00153
00154 TMVAStyle->SetLineStyleString( 5, "[52 12]" );
00155 TMVAStyle->SetLineStyleString( 6, "[22 12]" );
00156 TMVAStyle->SetLineStyleString( 7, "[22 10 7 10]" );
00157
00158
00159 TMVAStyle->SetPalette((UsePaperStyle ? 18 : 1),0);
00160
00161
00162 TMVAStyle->SetFrameBorderMode(0);
00163 TMVAStyle->SetCanvasBorderMode(0);
00164 TMVAStyle->SetPadBorderMode(0);
00165 TMVAStyle->SetPadColor(0);
00166 TMVAStyle->SetFillStyle(0);
00167
00168 TMVAStyle->SetLegendBorderSize(0);
00169
00170
00171
00172
00173
00174
00175 TMVAStyle->SetTitleFillColor( c_TitleBox );
00176 TMVAStyle->SetTitleTextColor( c_TitleText );
00177 TMVAStyle->SetTitleBorderSize( 1 );
00178 TMVAStyle->SetLineColor( c_TitleBorder );
00179 if (!UsePaperStyle) {
00180 TMVAStyle->SetFrameFillColor( c_FrameFill );
00181 TMVAStyle->SetCanvasColor( c_Canvas );
00182 }
00183
00184
00185 TMVAStyle->SetPaperSize(20,26);
00186 TMVAStyle->SetPadTopMargin(0.10);
00187 TMVAStyle->SetPadRightMargin(0.05);
00188 TMVAStyle->SetPadBottomMargin(0.11);
00189 TMVAStyle->SetPadLeftMargin(0.12);
00190
00191
00192 TMVAStyle->SetMarkerStyle(21);
00193 TMVAStyle->SetMarkerSize(0.3);
00194 TMVAStyle->SetHistLineWidth(2);
00195 TMVAStyle->SetLineStyleString(2,"[12 12]");
00196
00197
00198 TMVAStyle->SetOptTitle(1);
00199 TMVAStyle->SetTitleH(0.052);
00200
00201 TMVAStyle->SetOptStat(0);
00202 TMVAStyle->SetOptFit(0);
00203
00204
00205 TMVAStyle->SetPadTickX(1);
00206 TMVAStyle->SetPadTickY(1);
00207
00208 }
00209
00210 void DestroyCanvases()
00211 {
00212
00213 TList* loc = (TList*)gROOT->GetListOfCanvases();
00214 TListIter itc(loc);
00215 TObject *o(0);
00216 while ((o = itc())) delete o;
00217 }
00218
00219
00220 void Initialize( Bool_t useTMVAStyle = kTRUE )
00221 {
00222
00223 DestroyCanvases();
00224
00225
00226 if (!useTMVAStyle) {
00227 gROOT->SetStyle("Plain");
00228 gStyle->SetOptStat(0);
00229 return;
00230 }
00231
00232 SetTMVAStyle();
00233 }
00234
00235
00236 TFile* OpenFile( const TString& fin )
00237 {
00238 TFile* file = gDirectory->GetFile();
00239 if (file==0 || fin != file->GetName()) {
00240 if (file != 0) {
00241 gROOT->cd();
00242 file->Close();
00243 }
00244 cout << "--- Opening root file " << fin << " in read mode" << endl;
00245 file = TFile::Open( fin, "READ" );
00246 }
00247 else {
00248 file = gDirectory->GetFile();
00249 }
00250
00251 file->cd();
00252 return file;
00253 }
00254
00255
00256 void imgconv( TCanvas* c, const TString & fname )
00257 {
00258
00259 if (NULL == c) {
00260 cout << "*** Error in TMVAGlob::imgconv: canvas is NULL" << endl;
00261 }
00262 else {
00263
00264 TString f = fname;
00265 TString dir = f.Remove( f.Last( '/' ), f.Length() - f.Last( '/' ) );
00266 gSystem->mkdir( dir );
00267
00268 TString pngName = fname + ".png";
00269 TString gifName = fname + ".gif";
00270 TString epsName = fname + ".eps";
00271 c->cd();
00272
00273
00274 if (UsePaperStyle) {
00275 c->Print(epsName);
00276 }
00277 else {
00278 cout << "--- --------------------------------------------------------------------" << endl;
00279 cout << "--- If you want to save the image as eps, gif or png, please comment out " << endl;
00280 cout << "--- the corresponding lines (line no. 239-241) in tmvaglob.C" << endl;
00281 cout << "--- --------------------------------------------------------------------" << endl;
00282 c->Print(epsName);
00283 c->Print(pngName);
00284
00285 }
00286 }
00287 }
00288
00289 TImage * findImage(const char * imageName)
00290 {
00291
00292 TString macroPath(gROOT->GetMacroPath());
00293 Ssiz_t curIndex(0);
00294 TImage *img(0);
00295 while(1) {
00296 Ssiz_t pathStart = curIndex;
00297 curIndex = macroPath.Index(":",curIndex);
00298 Ssiz_t pathEnd = (curIndex==-1)?macroPath.Length():curIndex;
00299 TString path(macroPath(pathStart,pathEnd-pathStart));
00300
00301 gSystem->ExpandPathName(path);
00302 const char* fullName = Form("%s/%s", path.Data(), imageName);
00303
00304 Bool_t fileFound = ! gSystem->AccessPathName(fullName);
00305
00306 if(fileFound) {
00307 img = TImage::Open(fullName);
00308 break;
00309 }
00310 if(curIndex==-1) break;
00311 curIndex++;
00312 }
00313 return img;
00314 }
00315
00316 void plot_logo( Float_t v_scale = 1.0, Float_t skew = 1.0 )
00317 {
00318
00319 TImage *img = findImage("tmva_logo.gif");
00320 if (!img) {
00321 cout << "+++ Could not open image tmva_logo.gif" << endl;
00322 return;
00323 }
00324
00325 img->SetConstRatio(kFALSE);
00326 UInt_t h_ = img->GetHeight();
00327 UInt_t w_ = img->GetWidth();
00328
00329 Float_t r = w_/h_;
00330 gPad->Update();
00331 Float_t rpad = Double_t(gPad->VtoAbsPixel(0) - gPad->VtoAbsPixel(1))/(gPad->UtoAbsPixel(1) - gPad->UtoAbsPixel(0));
00332 r *= rpad;
00333
00334 Float_t d = 0.055;
00335
00336 Float_t x1R = 1 - gStyle->GetPadRightMargin();
00337 Float_t y1B = 1 - gStyle->GetPadTopMargin()+.01;
00338
00339 Float_t x1L = x1R - d*r/skew;
00340 Float_t y1T = y1B + d*v_scale*skew;
00341 if (y1T>0.99) y1T = 0.99;
00342
00343 TPad *p1 = new TPad("imgpad", "imgpad", x1L, y1B, x1R, y1T );
00344 p1->SetRightMargin(0);
00345 p1->SetBottomMargin(0);
00346 p1->SetLeftMargin(0);
00347 p1->SetTopMargin(0);
00348 p1->Draw();
00349
00350 Int_t xSizeInPixel = p1->UtoAbsPixel(1) - p1->UtoAbsPixel(0);
00351 Int_t ySizeInPixel = p1->VtoAbsPixel(0) - p1->VtoAbsPixel(1);
00352 if (xSizeInPixel<=25 || ySizeInPixel<=25) {
00353 delete p1;
00354 return;
00355 }
00356
00357 p1->cd();
00358 img->Draw();
00359 }
00360
00361 void NormalizeHist( TH1* h )
00362 {
00363 if (h==0) return;
00364 if (h->GetSumw2N() == 0) h->Sumw2();
00365 if(h->GetSumOfWeights()!=0) {
00366 Float_t dx = (h->GetXaxis()->GetXmax() - h->GetXaxis()->GetXmin())/h->GetNbinsX();
00367 h->Scale( 1.0/h->GetSumOfWeights()/dx );
00368 }
00369 }
00370 void NormalizeHists( TH1* sig, TH1* bkg = 0 )
00371 {
00372 if (sig->GetSumw2N() == 0) sig->Sumw2();
00373 if (bkg && bkg->GetSumw2N() == 0) bkg->Sumw2();
00374
00375 if(sig->GetSumOfWeights()!=0) {
00376 Float_t dx = (sig->GetXaxis()->GetXmax() - sig->GetXaxis()->GetXmin())/sig->GetNbinsX();
00377 sig->Scale( 1.0/sig->GetSumOfWeights()/dx );
00378 }
00379 if (bkg != 0 && bkg->GetSumOfWeights()!=0) {
00380 Float_t dx = (bkg->GetXaxis()->GetXmax() - bkg->GetXaxis()->GetXmin())/bkg->GetNbinsX();
00381 bkg->Scale( 1.0/bkg->GetSumOfWeights()/dx );
00382 }
00383 }
00384
00385
00386
00387
00388 void GetMethodName( TString & name, TKey * mkey ) {
00389 if (mkey==0) return;
00390 name = mkey->GetName();
00391 name.ReplaceAll("Method_","");
00392 }
00393
00394 void GetMethodTitle( TString & name, TKey * ikey ) {
00395 if (ikey==0) return;
00396 name = ikey->GetName();
00397 }
00398
00399 void GetMethodName( TString & name, TDirectory * mdir ) {
00400 if (mdir==0) return;
00401 name = mdir->GetName();
00402 name.ReplaceAll("Method_","");
00403 }
00404
00405 void GetMethodTitle( TString & name, TDirectory * idir ) {
00406 if (idir==0) return;
00407 name = idir->GetName();
00408 }
00409
00410 TKey *NextKey( TIter & keyIter, TString className) {
00411 TKey *key=(TKey *)keyIter.Next();
00412 TKey *rkey=0;
00413 Bool_t loop=(key!=0);
00414
00415 while (loop) {
00416 TClass *cl = gROOT->GetClass(key->GetClassName());
00417 if (cl->InheritsFrom(className.Data())) {
00418 loop = kFALSE;
00419 rkey = key;
00420 } else {
00421 key = (TKey *)keyIter.Next();
00422 if (key==0) loop = kFALSE;
00423 }
00424 }
00425 return rkey;
00426 }
00427
00428 UInt_t GetListOfKeys( TList& keys, TString inherits, TDirectory *dir=0 )
00429 {
00430
00431
00432 if (dir==0) dir = gDirectory;
00433 TIter mnext(dir->GetListOfKeys());
00434 TKey *mkey;
00435 keys.Clear();
00436 keys.SetOwner(kFALSE);
00437 UInt_t ni=0;
00438 while ((mkey = (TKey*)mnext())) {
00439
00440 TClass *cl = gROOT->GetClass(mkey->GetClassName());
00441 if (cl->InheritsFrom(inherits)) {
00442 keys.Add(mkey);
00443 ni++;
00444 }
00445 }
00446 return ni;
00447 }
00448
00449 Int_t GetNumberOfTargets( TDirectory *dir )
00450 {
00451 TIter next(dir->GetListOfKeys());
00452 TKey* key = 0;
00453 Int_t noTrgts = 0;
00454
00455 while ((key = (TKey*)next())) {
00456 if (key->GetCycle() != 1) continue;
00457 if (TString(key->GetName()).Contains("__Regression_target")) noTrgts++;
00458 }
00459 return noTrgts;
00460 }
00461
00462 Int_t GetNumberOfInputVariables( TDirectory *dir )
00463 {
00464 TIter next(dir->GetListOfKeys());
00465 TKey* key = 0;
00466 Int_t noVars = 0;
00467
00468 while ((key = (TKey*)next())) {
00469 if (key->GetCycle() != 1) continue;
00470
00471
00472 if (TString(key->GetName()).Contains("__Signal") || (TString(key->GetName()).Contains("__Regression") && !(TString(key->GetName()).Contains("__Regression_target")))) noVars++;
00473 }
00474
00475 return noVars;
00476 }
00477
00478 std::vector<TString> GetInputVariableNames(TDirectory *dir )
00479 {
00480 TIter next(dir->GetListOfKeys());
00481 TKey* key = 0;
00482
00483 std::vector<TString> names;
00484
00485 while ((key = (TKey*)next())) {
00486 if (key->GetCycle() != 1) continue;
00487 TClass *cl = gROOT->GetClass(key->GetClassName());
00488 if (!cl->InheritsFrom("TH1")) continue;
00489 TString name(key->GetName());
00490 Int_t pos = name.First("__");
00491 name.Remove(pos);
00492 Bool_t hasname = false;
00493 std::vector<TString>::const_iterator iter = names.begin();
00494 while(iter != names.end()){
00495 if(name.CompareTo(*iter)==0)
00496 hasname=true;
00497 iter++;
00498 }
00499 if(!hasname)
00500 names.push_back(name);
00501 }
00502 return names;
00503 }
00504
00505 Int_t GetNumberOfInputVariablesMultiClass( TDirectory *dir ){
00506 std::vector<TString> names(GetInputVariableNames(dir));
00507 return names.end() - names.begin();
00508 }
00509
00510 std::vector<TString> GetClassNames(TDirectory *dir )
00511 {
00512
00513 TIter next(dir->GetListOfKeys());
00514 TKey* key = 0;
00515
00516 std::vector<TString> names;
00517
00518 while ((key = (TKey*)next())) {
00519 if (key->GetCycle() != 1) continue;
00520 TClass *cl = gROOT->GetClass(key->GetClassName());
00521 if (!cl->InheritsFrom("TH1")) continue;
00522 TString name(key->GetName());
00523 name.ReplaceAll("_Deco","");
00524 name.ReplaceAll("_Gauss","");
00525 name.ReplaceAll("_PCA","");
00526 name.ReplaceAll("_Id","");
00527 name.ReplaceAll("_vs_","");
00528 char c = '_';
00529 Int_t pos = name.Last(c);
00530 name.Remove(0,pos+1);
00531
00532
00533
00534
00535
00536
00537
00538
00539
00540
00541
00542
00543
00544
00545 Bool_t hasname = false;
00546 std::vector<TString>::const_iterator iter = names.begin();
00547 while(iter != names.end()){
00548 if(name.CompareTo(*iter)==0)
00549 hasname=true;
00550 iter++;
00551 }
00552 if(!hasname)
00553 names.push_back(name);
00554 }
00555 return names;
00556 }
00557
00558
00559 TKey* FindMethod( TString name, TDirectory *dir=0 )
00560 {
00561
00562 if (dir==0) dir = gDirectory;
00563 TIter mnext(dir->GetListOfKeys());
00564 TKey *mkey;
00565 TKey *retkey=0;
00566 Bool_t loop=kTRUE;
00567 while (loop) {
00568 mkey = (TKey*)mnext();
00569 if (mkey==0) {
00570 loop = kFALSE;
00571 }
00572 else {
00573 TString clname = mkey->GetClassName();
00574 TClass *cl = gROOT->GetClass(clname);
00575 if (cl->InheritsFrom("TDirectory")) {
00576 TString mname = mkey->GetName();
00577 TString tname = "Method_"+name;
00578 if (mname==tname) {
00579 loop = kFALSE;
00580 retkey = mkey;
00581 }
00582 }
00583 }
00584 }
00585 return retkey;
00586 }
00587
00588 Bool_t ExistMethodName( TString name, TDirectory *dir=0 )
00589 {
00590
00591 if (dir==0) dir = gDirectory;
00592 TIter mnext(dir->GetListOfKeys());
00593 TKey *mkey;
00594 Bool_t loop=kTRUE;
00595 while (loop) {
00596 mkey = (TKey*)mnext();
00597 if (mkey==0) {
00598 loop = kFALSE;
00599 }
00600 else {
00601 TString clname = mkey->GetClassName();
00602 TString keyname = mkey->GetName();
00603 TClass *cl = gROOT->GetClass(clname);
00604 if (keyname.Contains("Method") && cl->InheritsFrom("TDirectory")) {
00605
00606 TDirectory* d_ = (TDirectory*)dir->Get( keyname );
00607 if (!d_) {
00608 cout << "HUUUGE TROUBLES IN TMVAGlob::ExistMethodName() --> contact authors" << endl;
00609 return kFALSE;
00610 }
00611
00612 TIter mnext_(d_->GetListOfKeys());
00613 TKey *mkey_;
00614 while ((mkey_ = (TKey*)mnext_())) {
00615 TString clname_ = mkey_->GetClassName();
00616 TClass *cl_ = gROOT->GetClass(clname_);
00617 if (cl_->InheritsFrom("TDirectory")) {
00618 TString mname = mkey_->GetName();
00619 if (mname==name) {
00620 return kTRUE;
00621 }
00622 }
00623 }
00624 }
00625 }
00626 }
00627 return kFALSE;
00628 }
00629
00630 UInt_t GetListOfMethods( TList & methods, TDirectory *dir=0 )
00631 {
00632
00633
00634 if (dir==0) dir = gDirectory;
00635 TIter mnext(dir->GetListOfKeys());
00636 TKey *mkey;
00637 methods.Clear();
00638 methods.SetOwner(kFALSE);
00639 UInt_t ni=0;
00640 while ((mkey = (TKey*)mnext())) {
00641
00642 TString name = mkey->GetClassName();
00643 TClass *cl = gROOT->GetClass(name);
00644 if (cl->InheritsFrom("TDirectory")) {
00645 if (TString(mkey->GetName()).BeginsWith("Method_")) {
00646 methods.Add(mkey);
00647 ni++;
00648 }
00649 }
00650 }
00651 cout << "--- Found " << ni << " classifier types" << endl;
00652 return ni;
00653 }
00654
00655 UInt_t GetListOfJobs( TFile* file, TList& jobdirs)
00656 {
00657
00658
00659 TIter next(file->GetListOfKeys());
00660 TKey *key(0);
00661 while ((key = (TKey*)next())) {
00662
00663 if (TString(key->GetName()).BeginsWith("Method_")) {
00664 if (gROOT->GetClass(key->GetClassName())->InheritsFrom("TDirectory")) {
00665
00666 TDirectory* mDir = (TDirectory*)key->ReadObj();
00667
00668 TIter keyIt(mDir->GetListOfKeys());
00669 TKey *jobkey;
00670 while ((jobkey = (TKey*)keyIt())) {
00671 if (!gROOT->GetClass(jobkey->GetClassName())->InheritsFrom("TDirectory")) continue;
00672
00673 TDirectory *jobDir = (TDirectory *)jobkey->ReadObj();
00674 cout << "jobdir name " << jobDir->GetName() << endl;
00675 jobdirs.Add(jobDir);
00676 }
00677 }
00678 }
00679 }
00680 return jobdirs.GetSize();
00681 }
00682
00683 UInt_t GetListOfTitles( TDirectory *rfdir, TList & titles )
00684 {
00685
00686 UInt_t ni=0;
00687 if (rfdir==0) return 0;
00688 TList *keys = rfdir->GetListOfKeys();
00689 if (keys==0) {
00690 cout << "+++ Directory '" << rfdir->GetName() << "' contains no keys" << endl;
00691 return 0;
00692 }
00693
00694 TIter rfnext(rfdir->GetListOfKeys());
00695 TKey *rfkey;
00696 titles.Clear();
00697 titles.SetOwner(kFALSE);
00698 while ((rfkey = (TKey*)rfnext())) {
00699
00700 TClass *cl = gROOT->GetClass(rfkey->GetClassName());
00701 if (cl->InheritsFrom("TDirectory")) {
00702 titles.Add(rfkey);
00703 ni++;
00704 }
00705 }
00706 cout << "--- Found " << ni << " instance(s) of the method " << rfdir->GetName() << endl;
00707 return ni;
00708 }
00709
00710 UInt_t GetListOfTitles( TString & methodName, TList & titles, TDirectory *dir=0 )
00711 {
00712
00713
00714
00715 UInt_t ni=0;
00716 if (dir==0) dir = gDirectory;
00717 TDirectory* rfdir = (TDirectory*)dir->Get( methodName );
00718 if (rfdir==0) {
00719 cout << "+++ Could not locate directory '" << methodName << endl;
00720 return 0;
00721 }
00722
00723 return GetListOfTitles( rfdir, titles );
00724
00725 TList *keys = rfdir->GetListOfKeys();
00726 if (keys==0) {
00727 cout << "+++ Directory '" << methodName << "' contains no keys" << endl;
00728 return 0;
00729 }
00730
00731 TIter rfnext(rfdir->GetListOfKeys());
00732 TKey *rfkey;
00733 titles.Clear();
00734 titles.SetOwner(kFALSE);
00735 while ((rfkey = (TKey*)rfnext())) {
00736
00737 TClass *cl = gROOT->GetClass(rfkey->GetClassName());
00738 if (cl->InheritsFrom("TDirectory")) {
00739 titles.Add(rfkey);
00740 ni++;
00741 }
00742 }
00743 cout << "--- Found " << ni << " instance(s) of the method " << methodName << endl;
00744 return ni;
00745 }
00746
00747 TDirectory *GetInputVariablesDir( TMVAGlob::TypeOfPlot type, TDirectory *dir=0 )
00748 {
00749
00750 const TString directories[TMVAGlob::kNumOfMethods] = { "InputVariables_Id",
00751 "InputVariables_Deco",
00752 "InputVariables_PCA",
00753 "InputVariables_Gauss_Deco" };
00754 if (dir==0) dir = gDirectory;
00755
00756
00757 dir = (TDirectory*)gDirectory->Get( directories[type] );
00758 if (dir==0) {
00759 cout << "+++ Could not locate input variable directory '" << directories[type] << endl;
00760 return 0;
00761 }
00762 return dir;
00763 }
00764
00765 TDirectory *GetCorrelationPlotsDir( TMVAGlob::TypeOfPlot type, TDirectory *dir=0 )
00766 {
00767
00768 if (dir==0) dir = GetInputVariablesDir( type, 0 );
00769 if (dir==0) return 0;
00770
00771 TDirectory* corrdir = (TDirectory*)dir->Get( "CorrelationPlots" );
00772 if (corrdir==0) {
00773 cout << "+++ Could not find CorrelationPlots directory 'CorrelationPlots'" << endl;
00774 return 0;
00775 }
00776 return corrdir;
00777 }
00778
00779 }
00780
00781 #endif