8 void TMVA::TMVAGlob::SetSignalAndBackgroundStyle( TH1* sig, TH1* bkg, TH1* all )
13 Int_t FillColor__S = getSignalFill();
14 Int_t FillStyle__S = 1001;
15 Int_t LineColor__S = getSignalLine();
16 Int_t LineWidth__S = 2;
20 Int_t FillColor__B = getBackgroundFill();
21 Int_t FillStyle__B = 3554;
22 Int_t LineColor__B = getBackgroundLine();
23 Int_t LineWidth__B = 2;
26 sig->SetLineColor( LineColor__S );
27 sig->SetLineWidth( LineWidth__S );
28 sig->SetFillStyle( FillStyle__S );
29 sig->SetFillColor( FillColor__S );
33 bkg->SetLineColor( LineColor__B );
34 bkg->SetLineWidth( LineWidth__B );
35 bkg->SetFillStyle( FillStyle__B );
36 bkg->SetFillColor( FillColor__B );
40 all->SetLineColor( LineColor__S );
41 all->SetLineWidth( LineWidth__S );
42 all->SetFillStyle( FillStyle__S );
43 all->SetFillColor( FillColor__S );
47 void TMVA::TMVAGlob::SetMultiClassStyle( TObjArray* hists )
64 Int_t FillColors[10] = {38,2,3,6,7,8,9,11};
65 Int_t LineColors[10] = {4,2,3,6,7,8,9,11};
66 Int_t FillStyles[5] = {1001,3554,3003,3545,0};
68 for(Int_t i=0; i<hists->GetEntriesFast(); ++i){
69 ((TH1*)(*hists)[i])->SetFillColor(FillColors[i%10]);
70 ((TH1*)(*hists)[i])->SetFillStyle(FillStyles[i%5]);
71 ((TH1*)(*hists)[i])->SetLineColor(LineColors[i%10]);
72 ((TH1*)(*hists)[i])->SetLineWidth(2);
77 void TMVA::TMVAGlob::SetFrameStyle( TH1* frame, Float_t scale )
79 frame->SetLabelOffset( 0.012,
"X" );
80 frame->SetLabelOffset( 0.012,
"Y" );
81 frame->GetXaxis()->SetTitleOffset( 1.25 );
82 frame->GetYaxis()->SetTitleOffset( 1.22 );
83 frame->GetXaxis()->SetTitleSize( 0.045*scale );
84 frame->GetYaxis()->SetTitleSize( 0.045*scale );
85 Float_t labelSize = 0.04*scale;
86 frame->GetXaxis()->SetLabelSize( labelSize );
87 frame->GetYaxis()->SetLabelSize( labelSize );
91 gPad->SetLeftMargin ( 0.108*scale );
92 gPad->SetRightMargin ( 0.050*scale );
93 gPad->SetBottomMargin( 0.120*scale );
96 void TMVA::TMVAGlob::SetTMVAStyle() {
98 TStyle *TMVAStyle = gROOT->GetStyle(
"TMVA");
100 gROOT->SetStyle(
"TMVA");
104 TMVAStyle =
new TStyle(*gROOT->GetStyle(
"Plain"));
105 TMVAStyle->SetName(
"TMVA");
106 TMVAStyle->SetTitle(
"TMVA style based on \"Plain\" with modifications defined in tmvaglob.C");
107 gROOT->GetListOfStyles()->Add(TMVAStyle);
108 gROOT->SetStyle(
"TMVA");
110 TMVAStyle->SetLineStyleString( 5,
"[52 12]" );
111 TMVAStyle->SetLineStyleString( 6,
"[22 12]" );
112 TMVAStyle->SetLineStyleString( 7,
"[22 10 7 10]" );
115 TMVAStyle->SetPalette((gConfig().fVariablePlotting.fUsePaperStyle ? 18 : 1),0);
118 TMVAStyle->SetFrameBorderMode(0);
119 TMVAStyle->SetCanvasBorderMode(0);
120 TMVAStyle->SetPadBorderMode(0);
121 TMVAStyle->SetPadColor(0);
122 TMVAStyle->SetFillStyle(0);
124 TMVAStyle->SetLegendBorderSize(0);
131 TMVAStyle->SetTitleFillColor( getTitleBox() );
132 TMVAStyle->SetTitleTextColor( getTitleText() );
133 TMVAStyle->SetTitleBorderSize( 1 );
134 TMVAStyle->SetLineColor( getTitleBorder() );
135 if (!gConfig().fVariablePlotting.fUsePaperStyle) {
136 TMVAStyle->SetFrameFillColor( getFrameFill() );
137 TMVAStyle->SetCanvasColor( getCanvas() );
141 TMVAStyle->SetPaperSize(20,26);
142 TMVAStyle->SetPadTopMargin(0.10);
143 TMVAStyle->SetPadRightMargin(0.05);
144 TMVAStyle->SetPadBottomMargin(0.11);
145 TMVAStyle->SetPadLeftMargin(0.12);
148 TMVAStyle->SetMarkerStyle(21);
149 TMVAStyle->SetMarkerSize(0.3);
150 TMVAStyle->SetHistLineWidth(2);
151 TMVAStyle->SetLineStyleString(2,
"[12 12]");
154 TMVAStyle->SetOptTitle(1);
155 TMVAStyle->SetTitleH(0.052);
157 TMVAStyle->SetOptStat(0);
158 TMVAStyle->SetOptFit(0);
161 TMVAStyle->SetPadTickX(1);
162 TMVAStyle->SetPadTickY(1);
166 void TMVA::TMVAGlob::DestroyCanvases()
169 TList* loc = (TList*)gROOT->GetListOfCanvases();
172 while ((o = itc()))
delete o;
176 void TMVA::TMVAGlob::Initialize( Bool_t useTMVAStyle )
183 gROOT->SetStyle(
"Plain");
184 gStyle->SetOptStat(0);
192 TFile* TMVA::TMVAGlob::OpenFile(
const TString& fin )
194 TFile* file = gDirectory->GetFile();
195 if (file==0 || fin != file->GetName()) {
200 cout <<
"--- Opening root file " << fin <<
" in read mode" << endl;
201 file = TFile::Open( fin,
"READ" );
204 file = gDirectory->GetFile();
212 void TMVA::TMVAGlob::imgconv( TCanvas* c,
const TString & fname )
216 cout <<
"*** Error in TMVAGlob::imgconv: canvas is NULL" << endl;
221 TString dir = f.Remove( f.Last(
'/' ), f.Length() - f.Last(
'/' ) );
222 gSystem->mkdir( dir );
224 TString pngName = fname +
".png";
225 TString gifName = fname +
".gif";
226 TString epsName = fname +
".eps";
230 if (gConfig().fVariablePlotting.fUsePaperStyle) {
234 cout <<
"--- --------------------------------------------------------------------" << endl;
235 cout <<
"--- If you want to save the image as eps, gif or png, please comment out " << endl;
236 cout <<
"--- the corresponding lines (line no. 239-241) in tmvaglob.C" << endl;
237 cout <<
"--- --------------------------------------------------------------------" << endl;
245 TImage * TMVA::TMVAGlob::findImage(
const char * imageName)
249 TString tutorialPath = getenv (
"ROOTSYS");
250 tutorialPath+=
"/tutorials/tmva";
252 TString fullName = Form(
"%s/%s", tutorialPath.Data(), imageName);
253 Bool_t fileFound = ! gSystem->AccessPathName(fullName);
256 img = TImage::Open(fullName);
258 cout <<
"+++ Could not open image: " << fullName << endl;
263 void TMVA::TMVAGlob::plot_logo( Float_t v_scale, Float_t skew )
266 TImage *img = findImage(
"tmva_logo.gif");
268 cout <<
"+++ Could not open image tmva_logo.gif" << endl;
272 img->SetConstRatio(kFALSE);
273 UInt_t h_ = img->GetHeight();
274 UInt_t w_ = img->GetWidth();
278 Float_t rpad = Double_t(gPad->VtoAbsPixel(0) - gPad->VtoAbsPixel(1))/(gPad->UtoAbsPixel(1) - gPad->UtoAbsPixel(0));
283 Float_t x1R = 1 - gStyle->GetPadRightMargin();
284 Float_t y1B = 1 - gStyle->GetPadTopMargin()+.01;
286 Float_t x1L = x1R - d*r/skew;
287 Float_t y1T = y1B + d*v_scale*skew;
288 if (y1T>0.99) y1T = 0.99;
290 TPad *p1 =
new TPad(
"imgpad",
"imgpad", x1L, y1B, x1R, y1T );
291 p1->SetRightMargin(0);
292 p1->SetBottomMargin(0);
293 p1->SetLeftMargin(0);
297 Int_t xSizeInPixel = p1->UtoAbsPixel(1) - p1->UtoAbsPixel(0);
298 Int_t ySizeInPixel = p1->VtoAbsPixel(0) - p1->VtoAbsPixel(1);
299 if (xSizeInPixel<=25 || ySizeInPixel<=25) {
308 void TMVA::TMVAGlob::NormalizeHist( TH1* h )
311 if (h->GetSumw2N() == 0) h->Sumw2();
312 if(h->GetSumOfWeights()!=0) {
313 Float_t dx = (h->GetXaxis()->GetXmax() - h->GetXaxis()->GetXmin())/h->GetNbinsX();
314 h->Scale( 1.0/h->GetSumOfWeights()/dx );
317 void TMVA::TMVAGlob::NormalizeHists( TH1* sig, TH1* bkg )
319 if (sig->GetSumw2N() == 0) sig->Sumw2();
320 if (bkg && bkg->GetSumw2N() == 0) bkg->Sumw2();
322 if(sig->GetSumOfWeights()!=0) {
323 Float_t dx = (sig->GetXaxis()->GetXmax() - sig->GetXaxis()->GetXmin())/sig->GetNbinsX();
324 sig->Scale( 1.0/sig->GetSumOfWeights()/dx );
326 if (bkg != 0 && bkg->GetSumOfWeights()!=0) {
327 Float_t dx = (bkg->GetXaxis()->GetXmax() - bkg->GetXaxis()->GetXmin())/bkg->GetNbinsX();
328 bkg->Scale( 1.0/bkg->GetSumOfWeights()/dx );
335 void TMVA::TMVAGlob::GetMethodName( TString & name, TKey * mkey ) {
337 name = mkey->GetName();
338 name.ReplaceAll(
"Method_",
"");
341 void TMVA::TMVAGlob::GetMethodTitle( TString & name, TKey * ikey ) {
343 name = ikey->GetName();
346 void TMVA::TMVAGlob::GetMethodName( TString & name, TDirectory * mdir ) {
348 name = mdir->GetName();
349 name.ReplaceAll(
"Method_",
"");
352 void TMVA::TMVAGlob::GetMethodTitle( TString & name, TDirectory * idir ) {
354 name = idir->GetName();
357 TKey *TMVA::TMVAGlob::NextKey( TIter & keyIter, TString className) {
358 TKey *key=(TKey *)keyIter.Next();
360 Bool_t loop=(key!=0);
363 TClass *cl = gROOT->GetClass(key->GetClassName());
364 if (cl->InheritsFrom(className.Data())) {
368 key = (TKey *)keyIter.Next();
369 if (key==0) loop = kFALSE;
375 UInt_t TMVA::TMVAGlob::GetListOfKeys( TList& keys, TString inherits, TDirectory *dir )
379 if (dir==0) dir = gDirectory;
380 TIter mnext(dir->GetListOfKeys());
383 keys.SetOwner(kFALSE);
385 while ((mkey = (TKey*)mnext())) {
387 TClass *cl = gROOT->GetClass(mkey->GetClassName());
388 if (cl->InheritsFrom(inherits)) {
396 Int_t TMVA::TMVAGlob::GetNumberOfTargets( TDirectory *dir )
399 cout <<
"tmvaglob::GetNumberOfTargets is called with *dir==NULL :( " << endl;
402 TIter next(dir->GetListOfKeys());
406 while ((key = (TKey*)next())) {
407 if (key->GetCycle() != 1)
continue;
408 if (TString(key->GetName()).Contains(
"__Regression_target")) noTrgts++;
413 Int_t TMVA::TMVAGlob::GetNumberOfInputVariables( TDirectory *dir )
415 TIter next(dir->GetListOfKeys());
419 while ((key = (TKey*)next())) {
420 if (key->GetCycle() != 1)
continue;
423 if (TString(key->GetName()).Contains(
"__Signal") || (TString(key->GetName()).Contains(
"__Regression") && !(TString(key->GetName()).Contains(
"__Regression_target")))) noVars++;
429 std::vector<TString> TMVA::TMVAGlob::GetInputVariableNames(TDirectory *dir)
431 TIter next(dir->GetListOfKeys());
433 std::vector<TString> names;
435 while ((key = (TKey*)next())) {
436 if (key->GetCycle() != 1)
continue;
437 TClass *cl = gROOT->GetClass(key->GetClassName());
438 if (!cl->InheritsFrom(
"TH1"))
continue;
439 TString name(key->GetName());
440 Int_t pos = name.Index(
"__");
444 Bool_t hasname =
false;
445 std::vector<TString>::const_iterator iter = names.begin();
446 while(iter != names.end()){
447 if(name.CompareTo(*iter)==0)
452 names.push_back(name);
457 Int_t TMVA::TMVAGlob::GetNumberOfInputVariablesMultiClass( TDirectory *dir ){
458 std::vector<TString> names(GetInputVariableNames(dir));
459 return names.end() - names.begin();
462 std::vector<TString> TMVA::TMVAGlob::GetClassNames(TDirectory *dir )
465 TIter next(dir->GetListOfKeys());
468 std::vector<TString> names;
470 while ((key = (TKey*)next())) {
471 if (key->GetCycle() != 1)
continue;
472 TClass *cl = gROOT->GetClass(key->GetClassName());
473 if (!cl->InheritsFrom(
"TH1"))
continue;
474 TString name(key->GetName());
475 Int_t pos = name.Index(
"__");
478 name.ReplaceAll(
"_Deco",
"");
479 name.ReplaceAll(
"_Gauss",
"");
480 name.ReplaceAll(
"_PCA",
"");
481 name.ReplaceAll(
"_Id",
"");
482 name.ReplaceAll(
"_vs_",
"");
483 name.Remove(0, pos + 2);
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)
506 names.push_back(name);
512 TKey* TMVA::TMVAGlob::FindMethod( TString name, TDirectory *dir )
515 if (dir==0) dir = gDirectory;
516 TIter mnext(dir->GetListOfKeys());
521 mkey = (TKey*)mnext();
526 TString clname = mkey->GetClassName();
527 TClass *cl = gROOT->GetClass(clname);
528 if (cl->InheritsFrom(
"TDirectory")) {
529 TString mname = mkey->GetName();
530 TString tname =
"Method_"+name;
541 Bool_t TMVA::TMVAGlob::ExistMethodName( TString name, TDirectory *dir )
544 if (dir==0) dir = gDirectory;
545 TIter mnext(dir->GetListOfKeys());
549 mkey = (TKey*)mnext();
554 TString clname = mkey->GetClassName();
555 TString keyname = mkey->GetName();
556 TClass *cl = gROOT->GetClass(clname);
557 if (keyname.Contains(
"Method") && cl->InheritsFrom(
"TDirectory")) {
559 TDirectory* d_ = (TDirectory*)dir->Get( keyname );
561 cout <<
"HUUUGE TROUBLES IN TMVAGlob::ExistMethodName() --> contact authors" << endl;
565 TIter mnext_(d_->GetListOfKeys());
567 while ((mkey_ = (TKey*)mnext_())) {
568 TString clname_ = mkey_->GetClassName();
569 TClass *cl_ = gROOT->GetClass(clname_);
570 if (cl_->InheritsFrom(
"TDirectory")) {
571 TString mname = mkey_->GetName();
583 UInt_t TMVA::TMVAGlob::GetListOfMethods( TList & methods, TDirectory *dir )
587 if (dir==0) dir = gDirectory;
588 TIter mnext(dir->GetListOfKeys());
591 methods.SetOwner(kFALSE);
593 while ((mkey = (TKey*)mnext())) {
595 TString name = mkey->GetClassName();
596 TClass *cl = gROOT->GetClass(name);
597 if (cl->InheritsFrom(
"TDirectory")) {
598 if (TString(mkey->GetName()).BeginsWith(
"Method_")) {
604 cout <<
"--- Found " << ni <<
" classifier types" << endl;
608 UInt_t TMVA::TMVAGlob::GetListOfJobs( TFile* file, TList& jobdirs)
612 TIter next(file->GetListOfKeys());
614 while ((key = (TKey*)next())) {
616 if (TString(key->GetName()).BeginsWith(
"Method_")) {
617 if (gROOT->GetClass(key->GetClassName())->InheritsFrom(
"TDirectory")) {
619 TDirectory* mDir = (TDirectory*)key->ReadObj();
621 TIter keyIt(mDir->GetListOfKeys());
623 while ((jobkey = (TKey*)keyIt())) {
624 if (!gROOT->GetClass(jobkey->GetClassName())->InheritsFrom(
"TDirectory"))
continue;
626 TDirectory *jobDir = (TDirectory *)jobkey->ReadObj();
627 cout <<
"jobdir name " << jobDir->GetName() << endl;
633 return jobdirs.GetSize();
636 UInt_t TMVA::TMVAGlob::GetListOfTitles( TDirectory *rfdir, TList & titles )
640 if (rfdir==0)
return 0;
641 TList *keys = rfdir->GetListOfKeys();
643 cout <<
"+++ Directory '" << rfdir->GetName() <<
"' contains no keys" << endl;
647 TIter rfnext(rfdir->GetListOfKeys());
650 titles.SetOwner(kFALSE);
651 while ((rfkey = (TKey*)rfnext())) {
653 TClass *cl = gROOT->GetClass(rfkey->GetClassName());
654 if (cl->InheritsFrom(
"TDirectory")) {
659 cout <<
"--- Found " << ni <<
" instance(s) of the method " << rfdir->GetName() << endl;
663 UInt_t TMVA::TMVAGlob::GetListOfTitles( TString & methodName, TList & titles, TDirectory *dir )
669 if (dir==0) dir = gDirectory;
670 TDirectory* rfdir = (TDirectory*)dir->Get( methodName );
672 cout <<
"+++ Could not locate directory '" << methodName << endl;
676 return GetListOfTitles( rfdir, titles );
678 TList *keys = rfdir->GetListOfKeys();
680 cout <<
"+++ Directory '" << methodName <<
"' contains no keys" << endl;
684 TIter rfnext(rfdir->GetListOfKeys());
687 titles.SetOwner(kFALSE);
688 while ((rfkey = (TKey*)rfnext())) {
690 TClass *cl = gROOT->GetClass(rfkey->GetClassName());
691 if (cl->InheritsFrom(
"TDirectory")) {
696 cout <<
"--- Found " << ni <<
" instance(s) of the method " << methodName << endl;
700 TDirectory *TMVA::TMVAGlob::GetInputVariablesDir( TMVAGlob::TypeOfPlot type, TDirectory *dir )
703 const TString directories[TMVAGlob::kNumOfMethods] = {
"InputVariables_Id",
704 "InputVariables_Deco",
705 "InputVariables_PCA",
706 "InputVariables_Gauss_Deco" };
707 if (dir==0) dir = gDirectory;
710 dir = (TDirectory*)gDirectory->Get( directories[type] );
712 cout <<
"+++ Could not locate input variable directory '" << directories[type] << endl;
718 TDirectory *TMVA::TMVAGlob::GetCorrelationPlotsDir( TMVAGlob::TypeOfPlot type, TDirectory *dir )
721 if (dir==0) dir = GetInputVariablesDir( type, 0 );
722 if (dir==0)
return 0;
724 TDirectory* corrdir = (TDirectory*)dir->Get(
"CorrelationPlots" );
726 cout <<
"+++ Could not find CorrelationPlots directory 'CorrelationPlots'" << endl;