/****************************************************************************** * macro to draw parallel coordinates * * * * Author: Dr. Christian Stratowa, Vienna, Austria. * * Created: 01 Aug 2008 Last modified: 03 Aug 2008 * ******************************************************************************/ /////////////////////////// // // in new root session(s): // create file "plot.root" // > .L macroParallelCoord.C // > CreateFile("Plot4.root", 4, 10000) // > CreateFile("Plot20.root", 20, 60000) // > CreateFile("Plot100.root", 100, 60000) // // in new root session(s): // draw plot // > .L macroParallelCoord.C // > DrawParallelCoord("Plot4.root", "*", "random", 0, 0) // > DrawParallelCoord("Plot4.root", "*", "random", 0, 0, kFALSE, kTRUE) // > DrawParallelCoord("Plot4.root", "Tree2", "px:random:pz", 0, 0, kFALSE) // > DrawParallelCoord("Plot20.root") // > DrawParallelCoord("Plot100.root") // /////////////////////////// #include "TBranch.h" #include "TCanvas.h" #include "TFile.h" #include "TKey.h" #include "TLeaf.h" #include "TList.h" #include "TMath.h" #include "TParallelCoord.h" #include "TParallelCoordVar.h" #include "TParallelCoordRange.h" #include "TRandom.h" #include "TStyle.h" #include "TTree.h" #ifndef __CINT__ #include #endif #include "float.h" //______________________________________________________________________________ void CreateFile(const char *filename="Plot.root", Int_t ntrees = 4, Int_t nentries = 10000) { // Create "Plot.root" TFile f(filename, "recreate"); // Fill Trees (adopted from macro tree1.C) Float_t px, py, pz; Double_t random; Int_t ev; for (Int_t k=0; kRannor(px,py); px = 11*px; py = 13*py; pz = px*px + py*py + 300; // random = gRandom->Rndm(); random = gRandom->Gaus(1.6); ev = i; tree.Fill(); }//for_i // write tree to file tree.Write(); }//for_k }//CreateFile //______________________________________________________________________________ void DrawParallelCoord(const char *filename="Plot.root", const char *treename = "*", const char *varlist = "random", Double_t min = 0, Double_t max = 0, Bool_t gl = kTRUE, Bool_t can = kFALSE) { // Open file TFile *file = TFile::Open(filename, "READ"); if (!file) return; // Add trees to list TTree *tree = 0; TTree *treek = 0; TList *fTrees = new TList(); if (strcmp(treename,"*") == 0) { TKey *key = 0; TIter next(file->GetListOfKeys()); while ((key = (TKey*)next())) { tree = (TTree*)file->Get(key->GetName()); fTrees->Add(tree); }//while tree = (TTree*)(fTrees->At(0)); for (Int_t k=1; kGetSize(); k++) { treek = (TTree*)(fTrees->At(k)); tree->AddFriend(treek->GetName(), file->GetName()); }//for_k } else { tree = (TTree*)file->Get(treename); fTrees->Add(tree); }//if Int_t numtrees = fTrees->GetSize(); Int_t nentries = (Int_t)(tree->GetEntries()); // New canvas TCanvas *fCanvas = new TCanvas("test", "test", 10, 10, 800, 600); TParallelCoord* para = new TParallelCoord(tree, nentries); // Add variables TString tname, varname; if (strcmp(treename,"*") == 0) { for (Int_t k=0; kAt(k)); varname = treek->GetName(); varname += "."; varname += varlist; para->AddVariable(varname); }//for_k } else { char *name = new char[strlen(varlist) + 1]; char *dname = name; name = strtok(strcpy(name, varlist), ":"); while(name) { para->AddVariable(name); name = strtok(0, ":"); if (name == 0) break; }//while delete [] dname; }//if para->SetGlobalScale(gl); para->SetDotsSpacing(5); //no para->SetCandleChart(can); if (can) para->SetCandleChart(can); // Set axis range if (min < max){ para->SetGlobalMin(min); para->SetGlobalMax(max); }//if para->Draw(); if(fTrees) {delete fTrees; fTrees = 0;} }//DrawParallelCoord