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