16 void TMVA::paracoor(TString dataset, TString fin , Bool_t useTMVAStyle )
19 TMVAGlob::Initialize( useTMVAStyle );
22 TFile* file = TMVAGlob::OpenFile( fin );
23 TTree* tree = (TTree*)file->GetDirectory(dataset.Data())->Get(
"TestTree");
25 cout <<
"--- No TestTree saved in ROOT file. Parallel coordinates will not be plotted" << endl;
30 TObjArray* leafList = tree->GetListOfLeaves();
33 for (Int_t iar=0; iar<leafList->GetSize(); iar++) {
34 TLeaf* leaf = (TLeaf*)leafList->At(iar);
36 TString leafName = leaf->GetName();
37 if (leafName !=
"type" && leafName !=
"weight" && leafName !=
"boostweight" &&
38 leafName !=
"class" && leafName !=
"className" && leafName !=
"classID" &&
39 !leafName.Contains(
"prob_")) {
41 if (TMVAGlob::ExistMethodName( leafName,file->GetDirectory(dataset.Data()) )) {
42 mvas.push_back( leafName );
45 vars.push_back( leafName );
51 cout <<
"--- Found: " << vars.size() <<
" variables" << endl;
52 cout <<
"--- Found: " << mvas.size() <<
" MVA(s)" << endl;
55 TString type[2] = {
"Signal",
"Background" };
56 for (UInt_t imva=0; imva<mvas.size(); imva++) {
57 cout <<
"--- Plotting parallel coordinates for : " << mvas[imva] <<
" & input variables" << endl;
59 for (Int_t itype=0; itype<2; itype++) {
62 TString varstr = mvas[imva] +
":";
63 for (UInt_t ivar=0; ivar<vars.size(); ivar++) varstr += vars[ivar] +
":";
64 varstr.Resize( varstr.Last(
':' ) );
67 TString mvashort = mvas[imva]; mvashort.ReplaceAll(
"MVA_",
"");
68 auto c1 =
new TCanvas( Form(
"c1_%i_%s",itype,mvashort.Data() ),
69 Form(
"Parallel coordinate representation for %s and input variables (%s events)",
70 mvashort.Data(), type[itype].Data() ),
71 50*(itype), 50*(itype), 750, 500 );
72 tree->Draw( varstr.Data(), Form(
"classID==%i",1-itype) ,
"para" );
74 gStyle->SetOptTitle(0);
76 TParallelCoord* para = (TParallelCoord*)gPad->GetListOfPrimitives()->FindObject(
"ParaCoord" );
77 TParallelCoordVar* mvavar = (TParallelCoordVar*)para->GetVarList()->FindObject( mvas[imva] );
78 Double_t minrange = tree->GetMinimum( mvavar->GetName() );
79 Double_t maxrange = tree->GetMaximum( mvavar->GetName() );
80 Double_t width = 0.2*(maxrange - minrange);
81 Double_t x1 = minrange, x2 = x1 + width;
82 TParallelCoordRange* parrange =
new TParallelCoordRange( mvavar, x1, x2 );
83 parrange->SetLineColor(4);
84 mvavar->AddRange( parrange );
86 para->AddSelection(
"-1");
88 for (Int_t ivar=1; ivar<TMath::Min(Int_t(vars.size()) + 1,3); ivar++) {
89 TParallelCoordVar* var = (TParallelCoordVar*)para->GetVarList()->FindObject( vars[ivar] );
90 minrange = tree->GetMinimum( var->GetName() );
91 maxrange = tree->GetMaximum( var->GetName() );
92 width = 0.2*(maxrange - minrange);
95 case 0: { x1 = minrange; x2 = x1 + width;
break; }
96 case 1: { x1 = 0.5*(maxrange + minrange - width)*0.02; x2 = x1 + width*0.02;
break; }
97 case 2: { x1 = maxrange - width; x2 = x1 + width;
break; }
100 parrange =
new TParallelCoordRange( var, x1, x2 );
101 parrange->SetLineColor( ivar == 0 ? 2 : ivar == 1 ? 5 : 6 );
102 var->AddRange( parrange );
104 para->AddSelection( Form(
"%i",ivar) );
109 TString fname = Form(
"%s/plots/paracoor_c%i_%s",dataset.Data(), imva, itype == 0 ?
"S" :
"B" );
110 TMVAGlob::imgconv( c1, fname );