00001 #include "tmvaglob.C"
00002 #include "TControlBar.h"
00003 #include <sstream>
00004 #include <string>
00005 #include <cfloat>
00006
00007
00008 typedef enum { kNEV, kDISCR, kMONO, kRMS, kRMSOVMEAN } EPlotType;
00009 typedef enum { kSEPARATE, kUNIFIED, kMONOTARGET, kMULTITARGET } EFoamType;
00010
00011 void PlotFoams( TString fin = "weights/TMVAClassification_PDEFoam.weights_foams.root",
00012 bool useTMVAStyle=kTRUE )
00013 {
00014 cout << "read file: " << fin << endl;
00015 TFile *file = TFile::Open(fin);
00016
00017
00018 TMVAGlob::Initialize( useTMVAStyle );
00019
00020
00021 TControlBar* cbar = new TControlBar( "vertical", "Choose cell value for plot:", 50, 50 );
00022 if ((gDirectory->Get("SignalFoam") && gDirectory->Get("BgFoam")) ||
00023 gDirectory->Get("MultiTargetRegressionFoam")) {
00024 TString macro = Form( "Plot(\"%s\", kNEV)", fin.Data() );
00025 cbar->AddButton( "Event density", macro, "Plot event density", "button" );
00026 } else if (gDirectory->Get("DiscrFoam")){
00027 TString macro = Form( "Plot(\"%s\", kDISCR)", fin.Data() );
00028 cbar->AddButton( "Discriminator", macro, "Plot discriminator", "button" );
00029 } else if (gDirectory->Get("MonoTargetRegressionFoam")){
00030 TString macro = Form( "Plot(\"%s\", kMONO)", fin.Data() );
00031 cbar->AddButton( "Target", macro, "Plot target", "button" );
00032 } else {
00033 cout << "Error: no foams found in file: " << fin << endl;
00034 return;
00035 }
00036
00037 TString macro_rms = Form( "Plot(\"%s\", kRMS)", fin.Data() );
00038 cbar->AddButton( "RMS", macro_rms, "Plot RMS (Variance)", "button" );
00039 TString macro_rms_ov_mean = Form( "Plot(\"%s\", kRMSOVMEAN)", fin.Data() );
00040 cbar->AddButton( "RMS over Mean", macro_rms_ov_mean, "Plot RMS over Mean", "button" );
00041
00042 cbar->Show();
00043 file->Close();
00044 }
00045
00046
00047 void Plot( TString fin = "weights/TMVAClassification_PDEFoam.weights_foams.root", EPlotType pt )
00048 {
00049 cout << "read file: " << fin << endl;
00050 TFile *file = TFile::Open(fin);
00051
00052 gStyle->SetNumberContours(999);
00053 TMVAGlob::SetTMVAStyle();
00054
00055 string cellval = "";
00056 string cellval_long = "";
00057
00058 if (pt == kNEV){
00059 cellval = "cell_value";
00060 cellval_long = "Event density";
00061 }
00062 else if (pt == kDISCR){
00063 cellval = "cell_value";
00064 cellval_long = "Discriminator";
00065 }
00066 else if (pt == kMONO){
00067 cellval = "cell_value";
00068 cellval_long = "Target";
00069 }
00070 else if (pt == kRMS){
00071 cellval = "rms";
00072 cellval_long = "RMS";
00073 }
00074 else if (pt == kRMSOVMEAN){
00075 cellval = "rms_ov_mean";
00076 cellval_long = "RMS/Mean";
00077 }
00078
00079
00080 EFoamType ft;
00081 TMVA::PDEFoam *foam = 0;
00082 TMVA::PDEFoam *foam2 = 0;
00083 string foam_capt, foam2_capt;
00084 if (gDirectory->Get("SignalFoam") && gDirectory->Get("BgFoam")){
00085 foam = SignalFoam;
00086 foam2 = BgFoam;
00087 foam_capt = "Signal Foam";
00088 foam2_capt = "Background Foam";
00089 ft = kSEPARATE;
00090 } else if (gDirectory->Get("DiscrFoam")){
00091 foam = DiscrFoam;
00092 foam_capt = "Discriminator Foam";
00093 ft = kDISCR;
00094 } else if (gDirectory->Get("MonoTargetRegressionFoam")){
00095 foam = MonoTargetRegressionFoam;
00096 foam_capt = "MonoTargetRegression Foam";
00097 ft = kMONOTARGET;
00098 } else if (gDirectory->Get("MultiTargetRegressionFoam")){
00099 foam = MultiTargetRegressionFoam;
00100 foam_capt = "MultiTargetRegression Foam";
00101 ft = kMULTITARGET;
00102 } else {
00103 cout << "ERROR: no Foams found in file: " << fin << endl;
00104 return;
00105 }
00106
00107 Int_t kDim = foam->GetTotDim();
00108 cout << foam_capt << " loaded" << endl;
00109 cout << "Dimension of foam: " << kDim << endl;
00110
00111
00112 if (kDim==1){
00113
00114 TH1D *hist1 = 0, *hist2 = 0;
00115 TCanvas *canv = new TCanvas("canv", "Foam(s)", 400, (ft==kSEPARATE) ? 800 : 400);
00116 if (ft==kSEPARATE)
00117 canv->Divide(0,2);
00118 canv->cd(1);
00119
00120 string var_name = foam->GetVariableName(0)->String();
00121 hist1 = foam->Draw1Dim(cellval.c_str(), 100);
00122 hist1->SetTitle((cellval_long+" of "+foam_capt+";"+var_name).c_str());
00123 hist1->Draw();
00124 hist1->SetDirectory(0);
00125
00126 if (ft==kSEPARATE){
00127 canv->cd(2);
00128 string var_name2 = foam2->GetVariableName(0)->String();
00129 if (ft==kSEPARATE)
00130 hist2 = foam2->Draw1Dim(cellval.c_str(), 100);
00131 hist2->SetTitle((cellval_long+" of "+foam2_capt+";"+var_name2).c_str());
00132 hist2->Draw();
00133 hist2->SetDirectory(0);
00134 }
00135
00136
00137 stringstream fname (stringstream::in | stringstream::out);
00138 fname << "plots/" << "foam_var_" << cellval << "_0";
00139 canv->Update();
00140 TMVAGlob::imgconv( canv, fname.str() );
00141 } else{
00142
00143 TCanvas* canv=0;
00144 TH2D *proj=0, *proj2=0;
00145
00146
00147 for(Int_t i=0; i<kDim; i++){
00148 for (Int_t k=i+1; k<kDim; k++){
00149
00150
00151 stringstream title (stringstream::in | stringstream::out);
00152 stringstream caption (stringstream::in | stringstream::out);
00153 title << "combined_" << i << ":" << k;
00154 caption << "Foam projections " << i << ":" << k;
00155 cout << "draw projection: " << i << ":" << k << endl;
00156
00157 stringstream title_proj1 (stringstream::in | stringstream::out);
00158 stringstream title_proj2 (stringstream::in | stringstream::out);
00159 title_proj1 << cellval_long << " of "
00160 << foam_capt << ": Projection "
00161 << foam->GetVariableName(i)->String()
00162 << ":" << foam->GetVariableName(k)->String()
00163 << ";" << foam->GetVariableName(i)->String()
00164 << ";" << foam->GetVariableName(k)->String();
00165 if (ft==kSEPARATE){
00166 title_proj2 << cellval_long << " of "
00167 << foam2_capt << ": Projection "
00168 << foam2->GetVariableName(i)->String()
00169 << ":" << foam2->GetVariableName(k)->String()
00170 << ";" << foam2->GetVariableName(i)->String()
00171 << ";" << foam2->GetVariableName(k)->String();
00172 }
00173
00174
00175 canv = new TCanvas(title.str().c_str(), caption.str().c_str(),
00176 (Int_t)(400/(1.-0.2)), (ft==kSEPARATE ? 800 : 400));
00177 if (ft==kSEPARATE){
00178 canv->Divide(0,2);
00179 canv->GetPad(1)->SetRightMargin(0.2);
00180 canv->GetPad(2)->SetRightMargin(0.2);
00181 } else {
00182 canv->SetRightMargin(0.2);
00183 }
00184 canv->cd(1);
00185
00186
00187 proj = foam->Project2(i, k, cellval.c_str(), "kNone");
00188 proj->SetTitle(title_proj1.str().c_str());
00189 if (pt==kDISCR)
00190 proj->GetZaxis()->SetRangeUser(-DBL_EPSILON, 1.+DBL_EPSILON);
00191 proj->Draw("COLZ");
00192 proj->SetDirectory(0);
00193
00194 if (ft==kSEPARATE){
00195 canv->cd(2);
00196 proj2 = foam2->Project2(i, k, cellval.c_str(), "kNone");
00197 proj2->SetTitle(title_proj2.str().c_str());
00198 proj2->Draw("COLZ");
00199 proj2->SetDirectory(0);
00200 }
00201
00202
00203 stringstream fname (stringstream::in | stringstream::out);
00204 fname << "plots/" << "foam_projection_var_" << cellval << "_" << i << ":" << k;
00205 canv->Update();
00206 TMVAGlob::imgconv( canv, fname.str() );
00207 }
00208 }
00209 }
00210
00211 file->Close();
00212 }