ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/benhoob/HWW/tmvaglob.C
Revision: 1.1
Committed: Mon Feb 14 12:37:23 2011 UTC (14 years, 3 months ago) by benhoob
Content type: text/plain
Branch: MAIN
CVS Tags: HEAD
Log Message:
Initial commit

File Contents

# User Rev Content
1 benhoob 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     // else {
287     // cout << "--- --------------------------------------------------------------------" << endl;
288     // cout << "--- Currently not printing files by default, see " << endl;
289     // cout << "--- the corresponding lines (line no. 239-241) in tmvaglob.C" << endl;
290     // cout << "--- --------------------------------------------------------------------" << endl;
291     // }
292     }
293     }
294    
295     TImage * findImage(const char * imageName)
296     {
297     // looks for the image in macropath
298     TString macroPath(gROOT->GetMacroPath()); // look for the image in here
299     Ssiz_t curIndex(0);
300     TImage *img(0);
301     while(1) {
302     Ssiz_t pathStart = curIndex;
303     curIndex = macroPath.Index(":",curIndex);
304     Ssiz_t pathEnd = (curIndex==-1)?macroPath.Length():curIndex;
305     TString path(macroPath(pathStart,pathEnd-pathStart));
306    
307     gSystem->ExpandPathName(path);
308     const char* fullName = Form("%s/%s", path.Data(), imageName);
309    
310     Bool_t fileFound = ! gSystem->AccessPathName(fullName);
311    
312     if(fileFound) {
313     img = TImage::Open(fullName);
314     break;
315     }
316     if(curIndex==-1) break;
317     curIndex++;
318     }
319     return img;
320     }
321    
322     void plot_logo( Float_t v_scale = 1.0, Float_t skew = 1.0 )
323     {
324    
325     TImage *img = findImage("tmva_logo.gif");
326     if (!img) {
327     cout << "+++ Could not open image tmva_logo.gif" << endl;
328     return;
329     }
330    
331     img->SetConstRatio(kFALSE);
332     UInt_t h_ = img->GetHeight();
333     UInt_t w_ = img->GetWidth();
334    
335     Float_t r = w_/h_;
336     gPad->Update();
337     Float_t rpad = Double_t(gPad->VtoAbsPixel(0) - gPad->VtoAbsPixel(1))/(gPad->UtoAbsPixel(1) - gPad->UtoAbsPixel(0));
338     r *= rpad;
339    
340     Float_t d = 0.055;
341     // absolute coordinates
342     Float_t x1R = 1 - gStyle->GetPadRightMargin();
343     Float_t y1B = 1 - gStyle->GetPadTopMargin()+.01; // we like the logo to sit a bit above the histo
344    
345     Float_t x1L = x1R - d*r/skew;
346     Float_t y1T = y1B + d*v_scale*skew;
347     if (y1T>0.99) y1T = 0.99;
348    
349     TPad *p1 = new TPad("imgpad", "imgpad", x1L, y1B, x1R, y1T );
350     p1->SetRightMargin(0);
351     p1->SetBottomMargin(0);
352     p1->SetLeftMargin(0);
353     p1->SetTopMargin(0);
354     p1->Draw();
355    
356     Int_t xSizeInPixel = p1->UtoAbsPixel(1) - p1->UtoAbsPixel(0);
357     Int_t ySizeInPixel = p1->VtoAbsPixel(0) - p1->VtoAbsPixel(1);
358     if (xSizeInPixel<=25 || ySizeInPixel<=25) {
359     delete p1;
360     return; // ROOT doesn't draw smaller than this
361     }
362    
363     p1->cd();
364     img->Draw();
365     }
366    
367     void NormalizeHist( TH1* h )
368     {
369     if (h==0) return;
370     if (h->GetSumw2N() == 0) h->Sumw2();
371     if(h->GetSumOfWeights()!=0) {
372     Float_t dx = (h->GetXaxis()->GetXmax() - h->GetXaxis()->GetXmin())/h->GetNbinsX();
373     h->Scale( 1.0/h->GetSumOfWeights()/dx );
374     }
375     }
376     void NormalizeHists( TH1* sig, TH1* bkg = 0 )
377     {
378     if (sig->GetSumw2N() == 0) sig->Sumw2();
379     if (bkg && bkg->GetSumw2N() == 0) bkg->Sumw2();
380    
381     if(sig->GetSumOfWeights()!=0) {
382     Float_t dx = (sig->GetXaxis()->GetXmax() - sig->GetXaxis()->GetXmin())/sig->GetNbinsX();
383     sig->Scale( 1.0/sig->GetSumOfWeights()/dx );
384     }
385     if (bkg != 0 && bkg->GetSumOfWeights()!=0) {
386     Float_t dx = (bkg->GetXaxis()->GetXmax() - bkg->GetXaxis()->GetXmin())/bkg->GetNbinsX();
387     bkg->Scale( 1.0/bkg->GetSumOfWeights()/dx );
388     }
389     }
390    
391     // the following are tools to help handling different methods and titles
392    
393    
394     void GetMethodName( TString & name, TKey * mkey ) {
395     if (mkey==0) return;
396     name = mkey->GetName();
397     name.ReplaceAll("Method_","");
398     }
399    
400     void GetMethodTitle( TString & name, TKey * ikey ) {
401     if (ikey==0) return;
402     name = ikey->GetName();
403     }
404    
405     void GetMethodName( TString & name, TDirectory * mdir ) {
406     if (mdir==0) return;
407     name = mdir->GetName();
408     name.ReplaceAll("Method_","");
409     }
410    
411     void GetMethodTitle( TString & name, TDirectory * idir ) {
412     if (idir==0) return;
413     name = idir->GetName();
414     }
415    
416     TKey *NextKey( TIter & keyIter, TString className) {
417     TKey *key=(TKey *)keyIter.Next();
418     TKey *rkey=0;
419     Bool_t loop=(key!=0);
420     //
421     while (loop) {
422     TClass *cl = gROOT->GetClass(key->GetClassName());
423     if (cl->InheritsFrom(className.Data())) {
424     loop = kFALSE;
425     rkey = key;
426     } else {
427     key = (TKey *)keyIter.Next();
428     if (key==0) loop = kFALSE;
429     }
430     }
431     return rkey;
432     }
433    
434     UInt_t GetListOfKeys( TList& keys, TString inherits, TDirectory *dir=0 )
435     {
436     // get a list of keys with a given inheritance
437     // the list contains TKey objects
438     if (dir==0) dir = gDirectory;
439     TIter mnext(dir->GetListOfKeys());
440     TKey *mkey;
441     keys.Clear();
442     keys.SetOwner(kFALSE);
443     UInt_t ni=0;
444     while ((mkey = (TKey*)mnext())) {
445     // make sure, that we only look at TDirectory with name Method_<xxx>
446     TClass *cl = gROOT->GetClass(mkey->GetClassName());
447     if (cl->InheritsFrom(inherits)) {
448     keys.Add(mkey);
449     ni++;
450     }
451     }
452     return ni;
453     }
454    
455     Int_t GetNumberOfTargets( TDirectory *dir )
456     {
457     TIter next(dir->GetListOfKeys());
458     TKey* key = 0;
459     Int_t noTrgts = 0;
460    
461     while ((key = (TKey*)next())) {
462     if (key->GetCycle() != 1) continue;
463     if (TString(key->GetName()).Contains("__Regression_target")) noTrgts++;
464     }
465     return noTrgts;
466     }
467    
468     Int_t GetNumberOfInputVariables( TDirectory *dir )
469     {
470     TIter next(dir->GetListOfKeys());
471     TKey* key = 0;
472     Int_t noVars = 0;
473    
474     while ((key = (TKey*)next())) {
475     if (key->GetCycle() != 1) continue;
476    
477     // count number of variables (signal is sufficient), exclude target(s)
478     if (TString(key->GetName()).Contains("__Signal") || (TString(key->GetName()).Contains("__Regression") && !(TString(key->GetName()).Contains("__Regression_target")))) noVars++;
479     }
480    
481     return noVars;
482     }
483    
484     std::vector<TString> GetInputVariableNames(TDirectory *dir )
485     {
486     TIter next(dir->GetListOfKeys());
487     TKey* key = 0;
488     //set<std::string> varnames;
489     std::vector<TString> names;
490    
491     while ((key = (TKey*)next())) {
492     if (key->GetCycle() != 1) continue;
493     TClass *cl = gROOT->GetClass(key->GetClassName());
494     if (!cl->InheritsFrom("TH1")) continue;
495     TString name(key->GetName());
496     Int_t pos = name.First("__");
497     name.Remove(pos);
498     Bool_t hasname = false;
499     std::vector<TString>::const_iterator iter = names.begin();
500     while(iter != names.end()){
501     if(name.CompareTo(*iter)==0)
502     hasname=true;
503     iter++;
504     }
505     if(!hasname)
506     names.push_back(name);
507     }
508     return names;
509     }
510    
511     Int_t GetNumberOfInputVariablesMultiClass( TDirectory *dir ){
512     std::vector<TString> names(GetInputVariableNames(dir));
513     return names.end() - names.begin();
514     }
515    
516     std::vector<TString> GetClassNames(TDirectory *dir )
517     {
518    
519     TIter next(dir->GetListOfKeys());
520     TKey* key = 0;
521     //set<std::string> varnames;
522     std::vector<TString> names;
523    
524     while ((key = (TKey*)next())) {
525     if (key->GetCycle() != 1) continue;
526     TClass *cl = gROOT->GetClass(key->GetClassName());
527     if (!cl->InheritsFrom("TH1")) continue;
528     TString name(key->GetName());
529     name.ReplaceAll("_Deco","");
530     name.ReplaceAll("_Gauss","");
531     name.ReplaceAll("_PCA","");
532     name.ReplaceAll("_Id","");
533     name.ReplaceAll("_vs_","");
534     char c = '_';
535     Int_t pos = name.Last(c);
536     name.Remove(0,pos+1);
537    
538     /*Int_t pos = name.First("__");
539     name.Remove(0,pos+2);
540     char c = '_';
541     pos = name.Last(c);
542     name.Remove(pos);
543     if(name.Contains("Gauss")){
544     pos = name.Last(c);
545     name.Remove(pos);
546     }
547     pos = name.Last(c);
548     if(pos!=-1)
549     name.Remove(0,pos+1);
550     */
551     Bool_t hasname = false;
552     std::vector<TString>::const_iterator iter = names.begin();
553     while(iter != names.end()){
554     if(name.CompareTo(*iter)==0)
555     hasname=true;
556     iter++;
557     }
558     if(!hasname)
559     names.push_back(name);
560     }
561     return names;
562     }
563    
564    
565     TKey* FindMethod( TString name, TDirectory *dir=0 )
566     {
567     // find the key for a method
568     if (dir==0) dir = gDirectory;
569     TIter mnext(dir->GetListOfKeys());
570     TKey *mkey;
571     TKey *retkey=0;
572     Bool_t loop=kTRUE;
573     while (loop) {
574     mkey = (TKey*)mnext();
575     if (mkey==0) {
576     loop = kFALSE;
577     }
578     else {
579     TString clname = mkey->GetClassName();
580     TClass *cl = gROOT->GetClass(clname);
581     if (cl->InheritsFrom("TDirectory")) {
582     TString mname = mkey->GetName(); // method name
583     TString tname = "Method_"+name; // target name
584     if (mname==tname) { // target found!
585     loop = kFALSE;
586     retkey = mkey;
587     }
588     }
589     }
590     }
591     return retkey;
592     }
593    
594     Bool_t ExistMethodName( TString name, TDirectory *dir=0 )
595     {
596     // find the key for a method
597     if (dir==0) dir = gDirectory;
598     TIter mnext(dir->GetListOfKeys());
599     TKey *mkey;
600     Bool_t loop=kTRUE;
601     while (loop) {
602     mkey = (TKey*)mnext();
603     if (mkey==0) {
604     loop = kFALSE;
605     }
606     else {
607     TString clname = mkey->GetClassName();
608     TString keyname = mkey->GetName();
609     TClass *cl = gROOT->GetClass(clname);
610     if (keyname.Contains("Method") && cl->InheritsFrom("TDirectory")) {
611    
612     TDirectory* d_ = (TDirectory*)dir->Get( keyname );
613     if (!d_) {
614     cout << "HUUUGE TROUBLES IN TMVAGlob::ExistMethodName() --> contact authors" << endl;
615     return kFALSE;
616     }
617    
618     TIter mnext_(d_->GetListOfKeys());
619     TKey *mkey_;
620     while ((mkey_ = (TKey*)mnext_())) {
621     TString clname_ = mkey_->GetClassName();
622     TClass *cl_ = gROOT->GetClass(clname_);
623     if (cl_->InheritsFrom("TDirectory")) {
624     TString mname = mkey_->GetName(); // method name
625     if (mname==name) { // target found!
626     return kTRUE;
627     }
628     }
629     }
630     }
631     }
632     }
633     return kFALSE;
634     }
635    
636     UInt_t GetListOfMethods( TList & methods, TDirectory *dir=0 )
637     {
638     // get a list of methods
639     // the list contains TKey objects
640     if (dir==0) dir = gDirectory;
641     TIter mnext(dir->GetListOfKeys());
642     TKey *mkey;
643     methods.Clear();
644     methods.SetOwner(kFALSE);
645     UInt_t ni=0;
646     while ((mkey = (TKey*)mnext())) {
647     // make sure, that we only look at TDirectory with name Method_<xxx>
648     TString name = mkey->GetClassName();
649     TClass *cl = gROOT->GetClass(name);
650     if (cl->InheritsFrom("TDirectory")) {
651     if (TString(mkey->GetName()).BeginsWith("Method_")) {
652     methods.Add(mkey);
653     ni++;
654     }
655     }
656     }
657     cout << "--- Found " << ni << " classifier types" << endl;
658     return ni;
659     }
660    
661     UInt_t GetListOfJobs( TFile* file, TList& jobdirs)
662     {
663     // get a list of all jobs in all method directories
664     // based on ideas by Peter and Joerg found in macro deviations.C
665     TIter next(file->GetListOfKeys());
666     TKey *key(0);
667     while ((key = (TKey*)next())) {
668    
669     if (TString(key->GetName()).BeginsWith("Method_")) {
670     if (gROOT->GetClass(key->GetClassName())->InheritsFrom("TDirectory")) {
671    
672     TDirectory* mDir = (TDirectory*)key->ReadObj();
673    
674     TIter keyIt(mDir->GetListOfKeys());
675     TKey *jobkey;
676     while ((jobkey = (TKey*)keyIt())) {
677     if (!gROOT->GetClass(jobkey->GetClassName())->InheritsFrom("TDirectory")) continue;
678    
679     TDirectory *jobDir = (TDirectory *)jobkey->ReadObj();
680     cout << "jobdir name " << jobDir->GetName() << endl;
681     jobdirs.Add(jobDir);
682     }
683     }
684     }
685     }
686     return jobdirs.GetSize();
687     }
688    
689     UInt_t GetListOfTitles( TDirectory *rfdir, TList & titles )
690     {
691     // get a list of titles (i.e TDirectory) given a method dir
692     UInt_t ni=0;
693     if (rfdir==0) return 0;
694     TList *keys = rfdir->GetListOfKeys();
695     if (keys==0) {
696     cout << "+++ Directory '" << rfdir->GetName() << "' contains no keys" << endl;
697     return 0;
698     }
699     //
700     TIter rfnext(rfdir->GetListOfKeys());
701     TKey *rfkey;
702     titles.Clear();
703     titles.SetOwner(kFALSE);
704     while ((rfkey = (TKey*)rfnext())) {
705     // make sure, that we only look at histograms
706     TClass *cl = gROOT->GetClass(rfkey->GetClassName());
707     if (cl->InheritsFrom("TDirectory")) {
708     titles.Add(rfkey);
709     ni++;
710     }
711     }
712     cout << "--- Found " << ni << " instance(s) of the method " << rfdir->GetName() << endl;
713     return ni;
714     }
715    
716     UInt_t GetListOfTitles( TString & methodName, TList & titles, TDirectory *dir=0 )
717     {
718     // get the list of all titles for a given method
719     // if the input dir is 0, gDirectory is used
720     // returns a list of keys
721     UInt_t ni=0;
722     if (dir==0) dir = gDirectory;
723     TDirectory* rfdir = (TDirectory*)dir->Get( methodName );
724     if (rfdir==0) {
725     cout << "+++ Could not locate directory '" << methodName << endl;
726     return 0;
727     }
728    
729     return GetListOfTitles( rfdir, titles );
730    
731     TList *keys = rfdir->GetListOfKeys();
732     if (keys==0) {
733     cout << "+++ Directory '" << methodName << "' contains no keys" << endl;
734     return 0;
735     }
736     //
737     TIter rfnext(rfdir->GetListOfKeys());
738     TKey *rfkey;
739     titles.Clear();
740     titles.SetOwner(kFALSE);
741     while ((rfkey = (TKey*)rfnext())) {
742     // make sure, that we only look at histograms
743     TClass *cl = gROOT->GetClass(rfkey->GetClassName());
744     if (cl->InheritsFrom("TDirectory")) {
745     titles.Add(rfkey);
746     ni++;
747     }
748     }
749     cout << "--- Found " << ni << " instance(s) of the method " << methodName << endl;
750     return ni;
751     }
752    
753     TDirectory *GetInputVariablesDir( TMVAGlob::TypeOfPlot type, TDirectory *dir=0 )
754     {
755     // get the InputVariables directory
756     const TString directories[TMVAGlob::kNumOfMethods] = { "InputVariables_Id",
757     "InputVariables_Deco",
758     "InputVariables_PCA",
759     "InputVariables_Gauss_Deco" };
760     if (dir==0) dir = gDirectory;
761    
762     // get top dir containing all hists of the variables
763     dir = (TDirectory*)gDirectory->Get( directories[type] );
764     if (dir==0) {
765     cout << "+++ Could not locate input variable directory '" << directories[type] << endl;
766     return 0;
767     }
768     return dir;
769     }
770    
771     TDirectory *GetCorrelationPlotsDir( TMVAGlob::TypeOfPlot type, TDirectory *dir=0 )
772     {
773     // get the CorrelationPlots directory
774     if (dir==0) dir = GetInputVariablesDir( type, 0 );
775     if (dir==0) return 0;
776     //
777     TDirectory* corrdir = (TDirectory*)dir->Get( "CorrelationPlots" );
778     if (corrdir==0) {
779     cout << "+++ Could not find CorrelationPlots directory 'CorrelationPlots'" << endl;
780     return 0;
781     }
782     return corrdir;
783     }
784    
785     }
786    
787     #endif