Logo ROOT  
Reference Guide
tvdemo.C
Go to the documentation of this file.
1void open_session(void *p = 0) {
2//=========Macro generated by ROOT version3.00/00
3//=========for tree "T" (Wed Feb 21 14:16:23 2001)
4//===This macro can be opened from a TreeViewer session after loading
5//===the corresponding tree
6 TTreeViewer *treeview = (TTreeViewer *) p;
7 if (!treeview) treeview = new TTreeViewer();
8 TTree *tv_tree = (TTree*)gROOT->FindObject("T");
9 TFile *tv_file = (TFile*)gROOT->GetListOfFiles()->FindObject("Event.root");
10 if (!tv_tree) {
11 if (!tv_file) tv_file = new TFile("$ROOTSYS/test/Event.root");
12 if (tv_file) tv_tree = (TTree*)tv_file->Get("T");
13 if(!tv_tree) {
14 printf("Tree not found\n");
15 return;
16 }
17 }
18
19 treeview->SetTreeName("T");
20 treeview->SetNexpressions(10);
21// Set expressions on axis and cut
22 TTVLVEntry *item;
23// X expression
24 item = treeview->ExpressionItem(0);
25 item->SetExpression("fTemperature", "fTemperature");
26// Y expression
27 item = treeview->ExpressionItem(1);
28 item->SetExpression("", "-empty-");
29// Z expression
30 item = treeview->ExpressionItem(2);
31 item->SetExpression("", "-empty-");
32// Cut expression
33 item = treeview->ExpressionItem(3);
34 item->SetExpression("", "-empty-");
35// Scan list
36 item = treeview->ExpressionItem(4);
37 item->SetExpression("", "Scan box");
38// User defined expressions
39 item = treeview->ExpressionItem(5);
40 item->SetExpression("sqrt(fTracks.fPx*fTracks.fPx+fTracks.fPy*fTracks.fPy)", "~Pt", kFALSE);
41 item = treeview->ExpressionItem(6);
42 item->SetExpression("fTracks.fPx>0", "~Cut1", kTRUE);
43 item = treeview->ExpressionItem(7);
44 item->SetExpression("", "-empty-", kFALSE);
45 item = treeview->ExpressionItem(8);
46 item->SetExpression("", "-empty-", kFALSE);
47 item = treeview->ExpressionItem(9);
48 item->SetExpression("", "-empty-", kFALSE);
49 item = treeview->ExpressionItem(10);
50 item->SetExpression("", "-empty-", kFALSE);
51 item = treeview->ExpressionItem(11);
52 item->SetExpression("", "-empty-", kFALSE);
53 item = treeview->ExpressionItem(12);
54 item->SetExpression("", "-empty-", kFALSE);
55 item = treeview->ExpressionItem(13);
56 item->SetExpression("", "-empty-", kFALSE);
57 item = treeview->ExpressionItem(14);
58 item->SetExpression("", "-empty-", kFALSE);
59//--- session object
60 auto tv_session = new TTVSession(treeview);
61 treeview->SetSession(tv_session);
62//--- tree viewer record
63 auto tv_record = tv_session->AddRecord(kTRUE);
64 tv_session->SetRecordName("Temperature");
65 tv_record->fX = "fTemperature";
66 tv_record->fY = "";
67 tv_record->fZ = "";
68 tv_record->fCut = "";
69 tv_record->fXAlias = "fTemperature";
70 tv_record->fYAlias = "-empty-";
71 tv_record->fZAlias = "-empty-";
72 tv_record->fCutAlias = "-empty-";
73 tv_record->fOption = "lego1";
74 tv_record->fScanRedirected = kFALSE;
75 tv_record->fCutEnabled = kTRUE;
76//--- tree viewer record
77 tv_record = tv_session->AddRecord(kTRUE);
78 tv_session->SetRecordName("Py versus Px");
79 tv_record->fX = "fTracks.fPx";
80 tv_record->fY = "fTracks.fPy";
81 tv_record->fZ = "";
82 tv_record->fCut = "";
83 tv_record->fXAlias = "fTracks.fPx";
84 tv_record->fYAlias = "fTracks.fPy";
85 tv_record->fZAlias = "-empty-";
86 tv_record->fCutAlias = "-empty-";
87 tv_record->fOption = "lego";
88 tv_record->fScanRedirected = kFALSE;
89 tv_record->fCutEnabled = kTRUE;
90//--- tree viewer record
91 tv_record = tv_session->AddRecord(kTRUE);
92 tv_session->SetRecordName("Transverse momentum");
93 tv_record->fX = "sqrt(fTracks.fPx*fTracks.fPx+fTracks.fPy*fTracks.fPy)";
94 tv_record->fY = "";
95 tv_record->fZ = "";
96 tv_record->fCut = "fTracks.fPx>0";
97 tv_record->fXAlias = "~Pt";
98 tv_record->fYAlias = "-empty-";
99 tv_record->fZAlias = "-empty-";
100 tv_record->fCutAlias = "~Cut1";
101 tv_record->fOption = "";
102 tv_record->fScanRedirected = kFALSE;
103 tv_record->fCutEnabled = kTRUE;
104//--- tree viewer record
105 tv_record = tv_session->AddRecord(kTRUE);
106 tv_session->SetRecordName("Surface plot of Py vs. Px");
107 tv_record->fX = "fTracks.fPx";
108 tv_record->fY = "fTracks.fPy";
109 tv_record->fZ = "";
110 tv_record->fCut = "";
111 tv_record->fXAlias = "fTracks.fPx";
112 tv_record->fYAlias = "fTracks.fPy";
113 tv_record->fZAlias = "-empty-";
114 tv_record->fCutAlias = "-empty-";
115 tv_record->fOption = "SURF";
116 tv_record->fScanRedirected = kFALSE;
117 tv_record->fCutEnabled = kTRUE;
118//--- Show first record
119 tv_session->Show(tv_session->First());
120}
121
122void tvdemo() {
123 printf("This demo show how to handle TTreeViewer sessions\n");
124 printf("Compile class Event from test directory before running this\n");
125 printf("- use arrow buttons from bottom to cycle records ...\n");
126 printf("- make new expressions and drag them to X, Y, Z or Cut items ...\n");
127 printf("- use the Draw button to check your current selection ...\n");
128 printf("- click the record button once you are happy with this ...\n");
129 printf("- open the TV context menu (right-click on the right panel)...\n");
130 printf(" Use : RemoveLastRecord() - to remove last record :-)\n");
131 printf(" SetRecordName() - to name current record\n");
132 printf(" UpdateRecord() - if you want to change a record from the list\n");
133 printf(" with your new X, Y, Z, Cut configuration.\n");
134 printf(" Best luck !\n");
135
136 open_session();
137}
const Bool_t kFALSE
Definition: RtypesCore.h:101
const Bool_t kTRUE
Definition: RtypesCore.h:100
winID h TVirtualViewer3D TVirtualGLPainter p
#define gROOT
Definition: TROOT.h:404
TObject * Get(const char *namecycle) override
Return pointer to object identified by namecycle.
A ROOT file is a suite of consecutive data records (TKey instances) with a well defined format.
Definition: TFile.h:54
This class represent entries that goes into the TreeViewer listview container.
void SetExpression(const char *name, const char *alias, Bool_t cutType=kFALSE)
Set the true name, alias and type of the expression, then refresh it.
I/O classes for TreeViewer session handling.
Definition: TTVSession.h:75
A graphic user interface designed to handle ROOT trees and to take advantage of TTree class features.
Definition: TTreeViewer.h:54
void SetNexpressions(Int_t expr)
void SetSession(TTVSession *session)
TTVLVEntry * ExpressionItem(Int_t index)
void SetTreeName(const char *treeName)
A TTree represents a columnar dataset.
Definition: TTree.h:79
void tvdemo()
Definition: tvdemo.C:122
void open_session(void *p=0)
Definition: tvdemo.C:1