15 void TMVA::rulevisCorr( TString fin , TMVAGlob::TypeOfPlot type ,
bool )
22 TFile *file = TMVAGlob::OpenFile( fin );
34 TString dirname=
"Method_RuleFit";
35 UInt_t ninst = TMVAGlob::GetListOfTitles(dirname,titles);
38 TDirectory* dir = (TDirectory*)file->Get(dirname );
41 TIter next(dir->GetListOfKeys());
43 while ((key = (TKey*)next())) {
45 if (!gROOT->GetClass(key->GetClassName())->InheritsFrom(
"TDirectory"))
continue;
47 TDirectory* rfdir = (TDirectory*)key->ReadObj();
48 TDirectory* vardir = rfdir;
49 TDirectory* corrdir = rfdir;
52 TIter keyIter(&titles);
56 rulevisCorr( rfdir, vardir, corrdir, type );
61 void TMVA::rulevisCorr( TDirectory *rfdir, TDirectory *vardir, TDirectory *corrdir, TMVAGlob::TypeOfPlot type) {
64 if (vardir==0)
return;
65 if (corrdir==0)
return;
67 const TString rfName = rfdir->GetName();
68 const TString maintitle = rfName +
" : Rule Importance, 2D";
69 const TString rfNameOpt =
"_RF2D_";
70 const TString outfname[TMVAGlob::kNumOfMethods] = {
"rulevisCorr",
73 "rulevisCorr_gaussdecorr" };
74 const TString outputName = outfname[type]+
"_"+rfdir->GetName();
76 TIter rfnext(rfdir->GetListOfKeys());
83 while ((rfkey = TMVAGlob::NextKey(rfnext,
"TH2F"))) {
84 hrf = (TH2F *)rfkey->ReadObj();
85 TString hname= hrf->GetName();
86 if (hname.Contains(rfNameOpt)){
87 Double_t valmin = hrf->GetMinimum();
88 Double_t valmax = hrf->GetMaximum();
93 if (valmax>rfmax) rfmax = valmax;
94 if (valmin<rfmin) rfmin = valmin;
101 cout <<
"ERROR: no RF2D plots found..." << endl;
104 Double_t minrange = rfmin;
105 Double_t maxrange = rfmax;
106 Double_t targetrange = maxrange - minrange;
108 const Int_t nContours = 100;
109 Double_t contourLevels[nContours];
110 Double_t dcl = targetrange/Double_t(nContours-1);
112 for (Int_t i=0; i<nContours; i++) {
113 contourLevels[i] = rfmin+dcl*Double_t(i);
120 Int_t noVars = ((vardir->GetListOfKeys())->GetEntries()) / 2;
121 Int_t noPlots = (noVars*(noVars+1)/2) - noVars;
132 xPad = 1; yPad = 1; width = 500; height = 0.7*width;
break;
134 xPad = 2; yPad = 1; width = 600; height = 0.7*width;
break;
136 xPad = 3; yPad = 1; width = 900; height = 0.4*width;
break;
138 xPad = 2; yPad = 2; width = 600; height = width;
break;
140 xPad = 3; yPad = 2; width = 800; height = 0.7*width;
break;
142 Int_t noPad = xPad * yPad ;
145 const Int_t noCanvas = 1 + (Int_t)((noPlots - 0.001)/noPad);
146 TCanvas **c =
new TCanvas*[noCanvas];
147 for (Int_t ic=0; ic<noCanvas; ic++) c[ic] = 0;
150 Int_t countCanvas = 0;
154 TIter next(corrdir->GetListOfKeys());
160 while ((key = (TKey*)next())) {
163 TClass *cl = gROOT->GetClass(key->GetClassName());
164 if (!cl->InheritsFrom(
"TH2"))
continue;
165 TH2F* sig = (TH2F*)key->ReadObj();
166 TString hname= sig->GetName();
168 if (hname.Contains(
"_sig_")){
171 if ((c[countCanvas]==NULL) || (countPad>noPad)) {
173 sprintf( cn,
"rulecorr%d_", countCanvas+1 );
175 cname += rfdir->GetName();
176 c[countCanvas] =
new TCanvas( cname, maintitle,
177 countCanvas*50+200, countCanvas*20, width, height );
179 c[countCanvas]->Divide(xPad,yPad);
183 TPad *cPad = (TPad *)(c[countCanvas]->GetPad(countPad));
184 c[countCanvas]->cd(countPad);
188 TString bgname = hname;
189 bgname.ReplaceAll(
"_sig_",
"_bgd_");
190 TKey* hkey = corrdir->GetKey(bgname);
191 TH2F* bgd = (TH2F*)hkey->ReadObj();
193 cout <<
"ERROR!!! couldn't find background histo for" << hname << endl;
197 sig->Rebin2D(rebin,rebin);
198 bgd->Rebin2D(rebin,rebin);
200 TString rfname = hname;
201 rfname.ReplaceAll(
"_sig_",rfNameOpt);
202 TKey *hrfkey = rfdir->GetKey(rfname);
203 TH2F* hrf2 = (TH2F*)hrfkey->ReadObj();
211 hrf2->SetMinimum(minrange);
212 hrf2->SetMaximum(maxrange);
213 hrf2->SetContour(nContours,&contourLevels[0]);
217 sig->SetFillColor(1);
218 sig->SetLineColor(1);
220 bgd->SetFillColor(15);
221 bgd->SetLineColor(15);
224 TString title(hrf2->GetTitle());
225 title.ReplaceAll(
"signal",
"");
227 hrf2->SetTitle( maintitle );
230 hrf2->SetTitle(
"" );
232 TMVAGlob::SetFrameStyle( hrf2, 1.2 );
235 hrf2->Draw(
"colz ah");
237 if (countPad==2) sc = 1.3;
238 sig->SetMaximum( TMath::Max( sig->GetMaximum(), bgd->GetMaximum() )*sc );
239 Double_t smax = sig->GetMaximum();
241 sig->Scale(1.0/smax);
243 sig->Draw(
"same cont3");
244 TMVAGlob::SetFrameStyle( sig, 1.2 );
246 bgd->Scale(1.0/smax);
248 bgd->Draw(
"same cont3");
249 TMVAGlob::SetFrameStyle( bgd, 1.2 );
251 sig->GetYaxis()->SetTitleOffset( 1.30 );
255 sig->Draw(
"sameaxis");
257 cPad->SetRightMargin(0.13);
262 TLegend *legend=
new TLegend( cPad->GetLeftMargin(),
263 1-cPad->GetTopMargin()-.18,
264 cPad->GetLeftMargin()+.4,
265 1-cPad->GetTopMargin() );
266 legend->AddEntry(sig,
"Signal",
"F");
267 legend->AddEntry(bgd,
"Background",
"F");
268 legend->Draw(
"same");
269 legend->SetBorderSize(1);
270 legend->SetMargin( 0.3 );
271 legend->SetFillColor(19);
272 legend->SetFillStyle(3001);
276 if (countPad > noPad) {
277 c[countCanvas]->Update();
278 TString fname = Form(
"plots/%s_c%i", outputName.Data(), countCanvas+1 );
279 TMVAGlob::imgconv( c[countCanvas], fname );
286 if (countPad <= noPad) {
287 c[countCanvas]->Update();
288 TString fname = Form(
"plots/%s_c%i", outfname[type].Data(), countCanvas+1 );
289 TMVAGlob::imgconv( c[countCanvas], fname );