8 void TMVA::plot_efficiencies(TString dataset, TFile* , Int_t type , TDirectory* BinDir)
15 Bool_t __PLOT_LOGO__ = kTRUE;
16 Bool_t __SAVE_IMAGE__ = kTRUE;
30 }
else if (type == 3) {
38 TCanvas* c =
new TCanvas(
"c",
"the canvas", 200, 0, 650, 500 );
45 Float_t x0L = 0.107, y0H = 0.899;
46 Float_t dxL = 0.457-x0L, dyH = 0.22;
49 y0H = 1 - y0H + dyH + 0.07;
51 TLegend *legend =
new TLegend( x0L, y0H-dyH, x0L+dxL, y0H );
53 legend->SetHeader(
"MVA Method:" );
54 legend->SetMargin( 0.4 );
56 TString xtit =
"Signal efficiency";
57 TString ytit =
"Background efficiency";
58 if (type == 2) ytit =
"Background rejection";
59 if (type == 3) ytit =
"1/(Background eff.)";
60 TString ftit = ytit +
" versus " + xtit;
62 TString hNameRef =
"effBvsS";
63 if (type == 2) hNameRef =
"rejBvsS";
64 if (type == 3) hNameRef =
"invBeffvsSeff";
67 if (TString(BinDir->GetName()).Contains(
"multicut")){
69 ftit += (BinDir->GetTitle());
74 UInt_t xnm = TMVAGlob::GetListOfMethods( xmethods ,BinDir);
76 cout <<
"ups .. no methods found in to plot ROC curve for ... give up" << endl;
79 TIter xnext(&xmethods);
82 while ((xkey = (TKey*)xnext())) {
83 TDirectory * mDir = (TDirectory*)xkey->ReadObj();
85 UInt_t ninst = TMVAGlob::GetListOfTitles(mDir,titles);
86 if (ninst==0) cout <<
"hmm... sorry, but this printout was supposed to be only to keep the compiler quite.. never supposed to happen :(" << endl;
87 TIter nextTitle(&titles);
90 while ((titkey = TMVAGlob::NextKey(nextTitle,
"TDirectory"))) {
91 titDir = (TDirectory *)titkey->ReadObj();
93 TMVAGlob::GetMethodTitle(methodTitle,titDir);
94 TIter nextKey( titDir->GetListOfKeys() );
96 while ((hkey2 = TMVAGlob::NextKey(nextKey,
"TH1"))) {
97 TH1 *h = (TH1*)hkey2->ReadObj();
98 TString hname = h->GetName();
99 if (hname.Contains( hNameRef ) && hname.BeginsWith(
"MVA_" )) {
100 if (type==3 && h->GetMaximum() > y2) y2 = h->GetMaximum()*1.1;
108 if(gROOT->FindObject(
"frame")!=0) gROOT->FindObject(
"frame")->Delete();
109 TH2F* frame =
new TH2F(
"frame", ftit, 500, x1, x2, 500, y1, y2 );
110 frame->GetXaxis()->SetTitle( xtit );
111 frame->GetYaxis()->SetTitle( ytit );
112 TMVAGlob::SetFrameStyle( frame, 1.0 );
122 UInt_t nm = TMVAGlob::GetListOfMethods( methods,BinDir );
124 cout <<
"ups .. no methods found in to plot ROC curve for ... give up" << endl;
128 TIter next(&methods);
131 while ((key = (TKey*)next())) {
132 TDirectory * mDir = (TDirectory*)key->ReadObj();
134 UInt_t ninst = TMVAGlob::GetListOfTitles(mDir,titles);
135 if (ninst==0) cout <<
"hmm... sorry, but this printout was supposed to be only to keep the compiler quite.. never supposed to happen :(" << endl;
136 TIter nextTitle(&titles);
139 while ((titkey = TMVAGlob::NextKey(nextTitle,
"TDirectory"))) {
140 titDir = (TDirectory *)titkey->ReadObj();
142 TMVAGlob::GetMethodTitle(methodTitle,titDir);
143 TIter nextKey( titDir->GetListOfKeys() );
145 while ((hkey2 = TMVAGlob::NextKey(nextKey,
"TH1"))) {
146 TH1 *h = (TH1*)hkey2->ReadObj();
147 TString hname = h->GetName();
148 if (hname.Contains( hNameRef ) && hname.BeginsWith(
"MVA_" )) {
150 h->SetLineColor(color);
151 color++;
if (color == 5 || color == 10 || color == 11) color++;
160 while (hists.GetSize()) {
161 TListIter hIt(&hists);
163 Double_t largestInt=-1;
164 TH1* histWithLargestInt(0);
165 while ((hist = (TH1*)hIt())!=0) {
166 Double_t integral = hist->Integral(1,hist->FindBin(0.9999));
167 if (integral>largestInt) {
168 largestInt = integral;
169 histWithLargestInt = hist;
172 if (histWithLargestInt == 0) {
173 cout <<
"ERROR - unknown hist \"histWithLargestInt\" --> serious problem in ROOT file" << endl;
176 legend->AddEntry(histWithLargestInt,TString(histWithLargestInt->GetTitle()).ReplaceAll(
"MVA_",
""),
"l");
177 hists.Remove(histWithLargestInt);
183 dyH *= (1.0 + Float_t(nmva - 3.0)/4.0);
184 legend->SetY1( y0H - dyH );
187 dyH *= (Float_t(TMath::Min(10,nmva) - 3.0)/4.0);
188 legend->SetY2( y0H + dyH);
192 frame->Draw(
"sameaxis");
193 legend->Draw(
"same");
197 if (__PLOT_LOGO__) TMVAGlob::plot_logo();
203 TString fname = dataset+
"/plots/" + hNameRef;
204 if (TString(BinDir->GetName()).Contains(
"multicut")){
205 TString fprepend(BinDir->GetName());
206 fprepend.ReplaceAll(
"multicutMVA_",
"");
207 fname = dataset+
"plots/" + fprepend +
"_" + hNameRef;
209 if (__SAVE_IMAGE__) TMVAGlob::imgconv( c, fname );
214 void TMVA::efficiencies(TString dataset, TString fin , Int_t type , Bool_t useTMVAStyle )
220 TMVAGlob::Initialize( useTMVAStyle );
223 TFile* file = TMVAGlob::OpenFile( fin );
225 plot_efficiencies(dataset, file, type, file->GetDirectory(dataset.Data()));