13 void TMVA::rulevisHists(TString fin, TMVAGlob::TypeOfPlot type,
bool useTMVAStyle)
16 TMVAGlob::Initialize( useTMVAStyle );
20 TMVAGlob::OpenFile( fin );
24 TString dirname =
"Method_RuleFit";
25 UInt_t ninst = TMVAGlob::GetListOfTitles(dirname,titles);
29 TDirectory* vardir = TMVAGlob::GetInputVariablesDir( type );
30 if (vardir==0)
return;
32 TDirectory* corrdir = TMVAGlob::GetCorrelationPlotsDir( type, vardir );
33 if (corrdir==0)
return;
36 TIter keyIter(&titles);
39 while ((rfkey = TMVAGlob::NextKey(keyIter,
"TDirectory"))) {
40 rfdir = (TDirectory *)rfkey->ReadObj();
41 rulevisHists( rfdir, vardir, corrdir, type );
45 void TMVA::rulevisHists( TDirectory *rfdir, TDirectory *vardir, TDirectory *corrdir, TMVAGlob::TypeOfPlot type) {
48 if (vardir==0)
return;
49 if (corrdir==0)
return;
51 const TString rfName = rfdir->GetName();
52 const TString maintitle = rfName +
" : Rule Importance";
53 const TString rfNameOpt =
"_RF2D_";
54 const TString outfname[TMVAGlob::kNumOfMethods] = {
"rulevisHists",
55 "rulevisHists_decorr",
57 "rulevisCorr_gaussdecorr" };
59 const TString outputName = outfname[type]+
"_"+rfdir->GetName();
61 TIter rfnext(rfdir->GetListOfKeys());
67 while ((rfkey = (TKey*)rfnext())) {
69 TClass *cl = gROOT->GetClass(rfkey->GetClassName());
70 if (!cl->InheritsFrom(
"TH2F"))
continue;
71 TH2F *hrf = (TH2F*)rfkey->ReadObj();
72 TString hname= hrf->GetName();
73 if (hname.Contains(
"__RF_")){
74 Double_t valmin = hrf->GetMinimum();
75 Double_t valmax = hrf->GetMaximum();
81 if (valmax>rfmax) rfmax=valmax;
82 if (valmin<rfmin) rfmin=valmin;
88 cout <<
"ERROR: no RF plots found..." << endl;
92 const Int_t nContours = 100;
93 Double_t contourLevels[nContours];
94 Double_t dcl = (rfmax-rfmin)/Double_t(nContours-1);
96 for (Int_t i=0; i<nContours; i++) {
97 contourLevels[i] = rfmin+dcl*Double_t(i);
104 Int_t noPlots = ((vardir->GetListOfKeys())->GetEntries()) / 2;
114 xPad = 1; yPad = 1; width = 500; height = 0.7*width;
break;
116 xPad = 2; yPad = 1; width = 600; height = 0.7*width;
break;
118 xPad = 3; yPad = 1; width = 900; height = 0.4*width;
break;
120 xPad = 2; yPad = 2; width = 600; height = width;
break;
122 xPad = 3; yPad = 2; width = 800; height = 0.7*width;
break;
124 Int_t noPad = xPad * yPad ;
127 const Int_t noCanvas = 1 + (Int_t)((noPlots - 0.001)/noPad);
128 TCanvas **c =
new TCanvas*[noCanvas];
129 for (Int_t ic=0; ic<noCanvas; ic++) c[ic] = 0;
132 Int_t countCanvas = 0;
136 TIter next(vardir->GetListOfKeys());
141 while ((key = (TKey*)next())) {
144 TClass *cl = gROOT->GetClass(key->GetClassName());
145 if (!cl->InheritsFrom(
"TH1"))
continue;
146 TH1F* sig = (TH1F*)key->ReadObj();
147 TString hname= sig->GetName();
150 if (hname.Contains(
"__S")){
152 if ((c[countCanvas]==NULL) || (countPad>noPad)) {
154 sprintf( cn,
"rulehist%d_", countCanvas+1 );
156 cname += rfdir->GetName();
157 c[countCanvas] =
new TCanvas( cname, maintitle,
158 countCanvas*50+200, countCanvas*20, width, height );
160 c[countCanvas]->Divide(xPad,yPad);
165 TPad *cPad = (TPad *)(c[countCanvas]->GetPad(countPad));
166 c[countCanvas]->cd(countPad);
170 TString bgname = hname;
171 bgname.ReplaceAll(
"__S",
"__B");
172 TKey *hkey = vardir->GetKey(bgname);
173 TH1F* bgd = (TH1F*)hkey->ReadObj();
175 cout <<
"ERROR!!! couldn't find backgroung histo for" << hname << endl;
181 TString rfname = hname;
182 rfname.ReplaceAll(
"__S",
"__RF");
183 TKey *hrfkey = rfdir->GetKey(rfname);
184 TH2F *hrf = (TH2F*)hrfkey->ReadObj();
188 hrf->SetMinimum(rfmin);
189 hrf->SetMaximum(rfmax);
190 hrf->SetContour(nContours,&contourLevels[0]);
194 sig->SetFillStyle(3002);
195 sig->SetFillColor(1);
196 sig->SetLineColor(1);
197 sig->SetLineWidth(2);
199 bgd->SetFillStyle(3554);
200 bgd->SetFillColor(1);
201 bgd->SetLineColor(1);
202 bgd->SetLineWidth(2);
205 TString title(hrf->GetTitle());
206 title.ReplaceAll(
"signal",
"");
210 if (countPad==2) sc = 1.3;
211 sig->SetMaximum( TMath::Max( sig->GetMaximum(), bgd->GetMaximum() )*sc );
212 Double_t smax = sig->GetMaximum();
215 hrf->SetTitle( maintitle );
220 hrf->Draw(
"colz ah");
221 TMVAGlob::SetFrameStyle( hrf, 1.2 );
223 sig->Draw(
"same ah");
224 bgd->Draw(
"same ah");
226 hrf->GetXaxis()->SetTitle( title );
227 hrf->GetYaxis()->SetTitleOffset( 1.30 );
228 hrf->GetYaxis()->SetTitle(
"Events");
229 hrf->GetYaxis()->SetLimits(0,smax);
230 hrf->Draw(
"same axis");
232 cPad->SetRightMargin(0.13);
237 TLegend *legend=
new TLegend( cPad->GetLeftMargin(),
238 1-cPad->GetTopMargin()-.18,
239 cPad->GetLeftMargin()+.4,
240 1-cPad->GetTopMargin() );
241 legend->AddEntry(sig,
"Signal",
"F");
242 legend->AddEntry(bgd,
"Background",
"F");
243 legend->Draw(
"same");
244 legend->SetBorderSize(1);
245 legend->SetMargin( 0.3 );
246 legend->SetFillColor(19);
247 legend->SetFillStyle(1);
251 if (countPad > noPad) {
252 c[countCanvas]->Update();
253 TString fname = Form(
"plots/%s_c%i", outputName.Data(), countCanvas+1 );
254 TMVAGlob::imgconv( c[countCanvas], fname );
261 if (countPad <= noPad) {
262 c[countCanvas]->Update();
263 TString fname = Form(
"plots/%s_c%i", outputName.Data(), countCanvas+1 );
264 TMVAGlob::imgconv( c[countCanvas], fname );