void PlotCellTree( TString fin = "weights/TMVAClassification_PDEFoam.weights_foams.root", TString cv_long, bool useTMVAStyle=kTRUE ) { // Draw the PDEFoam cell tree cout << "read file: " << fin << endl; TFile *file = TFile::Open(fin); if (useTMVAStyle) TMVAGlob::SetTMVAStyle(); // find foams TListIter foamIter(gDirectory->GetListOfKeys()); TKey *foam_key = NULL; // the foam key TCanvas *canv = NULL; // the canvas while (foam_key = (TKey*) foamIter()) { TString name(foam_key->GetName()); TString class_name(foam_key->GetClassName()); if (!class_name.Contains("PDEFoam")) continue; cout << "PDEFoam found: " << class_name << " " << name << endl; // read the foam TMVA::PDEFoam *foam = (TMVA::PDEFoam*) foam_key->ReadObj(); canv = new TCanvas(Form("canvas_%s",name.Data()), Form("%s of %s",cv_long.Data(),name.Data()), 640, 480); // get cell tree depth const UInt_t depth = foam->GetRootCell()->GetTreeDepth(); const Double_t ystep = 1.0 / depth; DrawCell(foam->GetRootCell(), foam, 0.5, 1.-0.5*ystep, 0.25, ystep); } file->Close(); }
// foam plotting macro void Plot( TString fin = "weights/TMVAClassification_PDEFoam.weights_foams.root", TMVA::ECellValue cv, TString cv_long, bool useTMVAStyle=kTRUE ) { cout << "read file: " << fin << endl; TFile *file = TFile::Open(fin); gStyle->SetNumberContours(999); if (useTMVAStyle) TMVAGlob::SetTMVAStyle(); // find foams and foam type TList foam_list; // the foams and their captions if (gDirectory->Get("SignalFoam") && gDirectory->Get("BgFoam")){ foam_list.Add(new TPair(SignalFoam, new TObjString("Signal Foam"))); foam_list.Add(new TPair(BgFoam, new TObjString("Background Foam"))); } else if (gDirectory->Get("DiscrFoam")){ foam_list.Add(new TPair(DiscrFoam, new TObjString("Discriminator Foam"))); } else if (gDirectory->Get("MultiClassFoam0")){ UInt_t cls = 0; TMVA::PDEFoam *fm = NULL; while (fm = (TMVA::PDEFoam*) gDirectory->Get(Form("MultiClassFoam%u", cls))) { foam_list.Add(new TPair(fm, new TObjString(Form("Discriminator Foam %u",cls)))); cls++; } } else if (gDirectory->Get("MonoTargetRegressionFoam")){ foam_list.Add(new TPair(MonoTargetRegressionFoam, new TObjString("MonoTargetRegression Foam"))); } else if (gDirectory->Get("MultiTargetRegressionFoam")){ foam_list.Add(new TPair(MultiTargetRegressionFoam, new TObjString("MultiTargetRegression Foam"))); } else { cout << "ERROR: no Foams found in file: " << fin << endl; return; } // loop over all foams and print out a debug message TListIter foamIter(&foam_list); TPair *fm_pair = NULL; Int_t kDim; // foam dimensions while (fm_pair = (TPair*) foamIter()) { kDim = ((TMVA::PDEFoam*) fm_pair->Key())->GetTotDim(); cout << "Foam loaded: " << ((TObjString*) fm_pair->Value())->String() << " (dimension = " << kDim << ")" << endl; } // kernel to use for the projection TMVA::PDEFoamKernelBase *kernel = new TMVA::PDEFoamKernelTrivial(); // plot foams if (kDim == 1) { Plot1DimFoams(foam_list, cv, cv_long, kernel); } else { PlotNDimFoams(foam_list, cv, cv_long, kernel); } file->Close(); }
static void oeCheckExpr(Foam expr) { int i; switch (foamTag(expr)) { case FOAM_Clos: oeCheckClos(expr->foamClos.env, expr->foamClos.prog); break; case FOAM_OCall: oeCheckClos(expr->foamOCall.env, expr->foamOCall.op); for (i=0; i<foamArgc(expr) - 3; i++) oeCheckExpr(expr->foamOCall.argv[i]); return; default: break; } foamIter(expr, arg, oeCheckExpr(*arg)); switch (foamTag(expr)) { case FOAM_Clos: break; case FOAM_Lex: oeLexRef(expr->foamLex.level); break; case FOAM_Env: oeEnvRef(expr->foamEnv.level); break; default: break; } }
local void fpPatchExpr(Foam expr, Bool envOK) { int i; switch (foamTag(expr)) { case FOAM_Clos: if (foamTag(expr->foamClos.env) == FOAM_Env) { fpPatchExpr(expr->foamClos.env, true); fpPatchExpr(expr->foamClos.prog, false); } break; case FOAM_OCall: if (foamTag(expr->foamOCall.env) == FOAM_Env) { fpPatchExpr(expr->foamOCall.env, true); fpPatchExpr(expr->foamClos.prog, false); for (i=0; i<foamArgc(expr) - 3; i++) fpPatchExpr(expr->foamClos.prog, false); } break; default: foamIter(expr, arg, fpPatchExpr(*arg, false)); } switch (foamTag(expr)) { case FOAM_Def: fpPatchDefined(expr->foamDef.lhs, expr->foamDef.rhs); break; case FOAM_Set: fpPatchDefined(expr->foamSet.lhs, expr->foamSet.rhs); break; case FOAM_Lex: /*!! Need code for computing DEnv */ if (expr->foamLex.level == 0) if (fpProg) foamProgUnsetLeaf(fpProg); break; case FOAM_Env: if (expr->foamEnv.level == 0) if (fpProg) foamProgUnsetLeaf(fpProg); break; case FOAM_RElt: fpMarkFormat(&expr->foamRElt.expr, &expr->foamRElt.format, FOAM_Rec); break; #if 0 #ifdef MarkArrayDecls case FOAM_AElt: fpMarkFormat(&expr->foamAElt.expr, &expr->foamAElt.baseType, FOAM_Arr); break; #endif #endif default: break; } #if 0 /* * There are arguments for putting 'FOAM_Glo' in here * fortunately, the only time we use globals are for * a) things like 'import from Foreign', and therefore are * initialized already * b) forcing of global initializers. In this case, we don't * care, because we won't be looking at our environment * * FOAM_Clos technically needn't be here, but unfortunately * the prog's DEnv could be wrong, and we would lose. */ switch (foamTag(expr)) { case FOAM_Env: if (envOK) break; case FOAM_Lex: if (expr->foamLex.level == 0) break; case FOAM_CEnv: #if 0 /**/ case FOAM_Clos: #endif case FOAM_EElt: if (expr->foamEElt.level < 0) bug("Really bad eelt"); case FOAM_Fluid: case FOAM_PRef: case FOAM_EInfo: foamProgUnsetNoEnvUse(fpProg); break; default: break; } #endif }