16 void TMVA::mvasMulticlass(TString dataset, TString fin , HistType htype , Bool_t useTMVAStyle )
19 TMVAGlob::Initialize( useTMVAStyle );
22 const Bool_t Save_Images = kTRUE;
25 TFile *file = TMVAGlob::OpenFile(fin);
28 TIter keys_dir = file->GetDirectory(dataset.Data())->GetListOfKeys();
30 TDirectory *tempdir = 0;
31 while ((key = (TKey *)keys_dir())) {
32 TString name = key->GetName();
33 if (name.BeginsWith(
"InputVariables_")) {
34 tempdir = (TDirectory *)(file->GetDirectory(dataset.Data())->Get(name));
38 std::vector<TString> classnames(TMVAGlob::GetClassNames(tempdir));
44 const Int_t width = 600;
50 Int_t countCanvas = 0;
53 TIter next(file->GetDirectory(dataset.Data())->GetListOfKeys());
55 while ((key = (TKey*)next())) {
57 if (!TString(key->GetName()).BeginsWith(
"Method_"))
continue;
58 if (!gROOT->GetClass(key->GetClassName())->InheritsFrom(
"TDirectory"))
continue;
61 TMVAGlob::GetMethodName(methodName,key);
63 TDirectory* mDir = (TDirectory*)key->ReadObj();
65 TIter keyIt(mDir->GetListOfKeys());
67 while ((titkey = (TKey*)keyIt())) {
69 if (!gROOT->GetClass(titkey->GetClassName())->InheritsFrom(
"TDirectory"))
continue;
71 TDirectory *titDir = (TDirectory *)titkey->ReadObj();
73 TMVAGlob::GetMethodTitle(methodTitle,titDir);
75 cout <<
"--- Found directory for method: " << methodName <<
"::" << methodTitle << endl;
76 TString hname =
"MVA_" + methodTitle;
77 for(UInt_t icls = 0; icls < classnames.size(); ++icls){
80 std::vector<TString>::iterator classiter = classnames.begin();
81 for(; classiter!=classnames.end(); ++classiter){
82 TString name(hname+
"_Test_"+ classnames.at(icls)
83 +
"_prob_for_" + *classiter);
84 TH1 *hist = (TH1*)titDir->Get(name);
86 cout <<
":\t mva distribution not available (this is normal for Cut classifier)" << endl;
94 ((TH1*)hists.First())->SetTitle( Form(
"TMVA response for classifier: %s", methodTitle.Data() ));
98 TString ctitle = ((htype == kMVAType) ?
99 Form(
"TMVA response for class %s %s", classnames.at(icls).Data(),methodTitle.Data()) :
100 Form(
"TMVA comparison for class %s %s", classnames.at(icls).Data(),methodTitle.Data())) ;
102 c =
new TCanvas( Form(
"canvas%d", countCanvas+1), ctitle,
103 countCanvas*50+200, countCanvas*20, width, (Int_t)width*0.78 );
107 TMVAGlob::SetMultiClassStyle( &hists );
110 Float_t histmax = -1;
111 for(Int_t i=0; i<hists.GetEntriesFast(); ++i){
112 TMVAGlob::NormalizeHist((TH1*)hists[i] );
113 if(((TH1*)hists[i])->GetMaximum() > histmax)
114 histmax = ((TH1*)hists[i])->GetMaximum();
121 Float_t maxMult = (htype == kCompareType) ? 1.3 : 1.2;
122 Float_t ymax = histmax*maxMult;
125 TString hFrameName(TString(
"frame") + methodTitle);
126 TObject *o = gROOT->FindObject(hFrameName);
128 TH2F* frame =
new TH2F( hFrameName, ((TH1*)hists.First())->GetTitle(),
129 nb, xmin, xmax, nb, ymin, ymax );
130 frame->GetXaxis()->SetTitle( methodTitle +
" response for "+classnames.at(icls));
131 frame->GetYaxis()->SetTitle(
"(1/N) dN^{ }/^{ }dx");
132 TMVAGlob::SetFrameStyle( frame );
137 c->GetPad(0)->SetLeftMargin( 0.105 );
138 frame->GetYaxis()->SetTitleOffset( 1.2 );
141 TLegend *legend=
new TLegend( c->GetLeftMargin(), 1 - c->GetTopMargin() - 0.12,
142 c->GetLeftMargin() + (htype == kCompareType ? 0.40 : 0.3), 1 - c->GetTopMargin() );
143 legend->SetFillStyle( 1 );
144 classiter = classnames.begin();
146 for(Int_t i=0; i<hists.GetEntriesFast(); ++i, ++classiter){
147 legend->AddEntry(((TH1*)hists[i]),*classiter,
"F");
150 legend->SetBorderSize(1);
151 legend->SetMargin( 0.3 );
152 legend->Draw(
"same");
155 for(Int_t i=0; i<hists.GetEntriesFast(); ++i){
157 ((TH1*)hists[i])->Draw(
"histsame");
158 TString ytit = TString(
"(1/N) ") + ((TH1*)hists[i])->GetYaxis()->GetTitle();
159 ((TH1*)hists[i])->GetYaxis()->SetTitle( ytit );
164 if (htype == kCompareType) {
168 classiter = classnames.begin();
169 for(; classiter!=classnames.end(); ++classiter){
170 TString name(hname+
"_Train_"+ classnames.at(icls)
171 +
"_prob_for_" + *classiter);
172 TH1 *hist = (TH1*)titDir->Get(name);
174 cout <<
":\t comparison histogram for overtraining check not available!" << endl;
180 TLegend *legend2=
new TLegend( 1 - c->GetRightMargin() - 0.42, 1 - c->GetTopMargin() - 0.12,
181 1 - c->GetRightMargin(), 1 - c->GetTopMargin() );
182 legend2->SetFillStyle( 1 );
183 legend2->SetBorderSize(1);
185 classiter = classnames.begin();
186 for(Int_t i=0; i<othists.GetEntriesFast(); ++i, ++classiter){
187 legend2->AddEntry(((TH1*)othists[i]),*classiter+
" (training sample)",
"P");
189 legend2->SetMargin( 0.1 );
190 legend2->Draw(
"same");
193 for(Int_t i=0; i<othists.GetEntriesFast(); ++i){
194 TMVAGlob::NormalizeHist((TH1*)othists[i] );
195 if(((TH1*)othists[i])->GetMaximum() > histmax)
196 histmax = ((TH1*)othists[i])->GetMaximum();
199 TMVAGlob::SetMultiClassStyle( &othists );
200 for(Int_t i=0; i<othists.GetEntriesFast(); ++i){
201 Int_t col = ((TH1*)hists[i])->GetLineColor();
202 ((TH1*)othists[i])->SetMarkerSize( 0.7 );
203 ((TH1*)othists[i])->SetMarkerStyle( 20 );
204 ((TH1*)othists[i])->SetMarkerColor( col );
205 ((TH1*)othists[i])->SetLineWidth( 1 );
206 ((TH1*)othists[i])->Draw(
"e1same");
209 ymax = histmax*maxMult;
210 frame->GetYaxis()->SetLimits( 0, ymax );
213 TMVAGlob::SetMultiClassStyle( &othists );
214 for(Int_t i=0; i<hists.GetEntriesFast(); ++i){
215 ((TH1*)hists[i])->SetLineWidth( 1 );
221 cout <<
"--- Perform Kolmogorov-Smirnov tests" << endl;
222 cout <<
"--- Goodness of consistency for class " << classnames.at(icls)<< endl;
224 for(Int_t j=0; j<othists.GetEntriesFast(); ++j){
225 Float_t kol = ((TH1*)hists[j])->KolmogorovTest(((TH1*)othists[j]),
"X");
226 cout << classnames.at(j) <<
": " << kol << endl;
239 frame->Draw(
"sameaxis");
259 TMVAGlob::plot_logo(1.058);
261 if (htype == kMVAType) TMVAGlob::imgconv( c, Form(
"%s/plots/mva_%s_%s",dataset.Data(),classnames.at(icls).Data(), methodTitle.Data()) );
262 else if (htype == kCompareType) TMVAGlob::imgconv( c, Form(
"%s/plots/overtrain_%s_%s",dataset.Data(),classnames.at(icls).Data(), methodTitle.Data()) );