Logo ROOT   6.07/09
Reference Guide
alice_vsd.C
Go to the documentation of this file.
1 /// \file
2 /// \ingroup tutorial_eve
3 /// Complex example showing ALICE VSD visualization.
4 ///
5 /// alice_vsd.C - a simple event-display for ALICE
6 ///
7 /// Only standard ROOT is used to process the ALICE VSD files.
8 ///
9 /// No ALICE code is needed -- the VSD file is exported from AliRoot into
10 /// VSD format -- see TEveVSDStructs.h and TEveVSD.h.
11 ///
12 /// A simple geometry of 10KB, extracted from the full TGeo-geometry, is
13 /// used to outline the central detectors of ALICE.
14 ///
15 /// All files are access from the web by using the "CACHEREAD" option.
16 ///
17 /// \image html eve_alice_vsd.png
18 /// \macro_code
19 ///
20 /// \author Matevz Tadel
21 
22 
23 #include <TEveManager.h>
24 #include <TEveEventManager.h>
25 #include <TEveVSD.h>
26 #include <TEveVSDStructs.h>
27 
28 #include <TEveTrack.h>
29 #include <TEveTrackPropagator.h>
30 #include <TEveGeoShape.h>
31 
32 #include <TGTab.h>
33 #include <TGButton.h>
34 
35 #include <TFile.h>
36 #include <TKey.h>
37 #include <TSystem.h>
38 #include <TPRegexp.h>
39 
40 
41 // Include componets -- compile time link :)
42 
43 #include "MultiView.C"
44 MultiView* gMultiView = 0;
45 
46 
47 class TVSDReader
48 {
49 public:
50  // ----------------------------------------------------------
51  // File / Event Data
52  // ----------------------------------------------------------
53 
54  TFile *fFile;
55  TDirectory *fDirectory;
56 
57  TObjArray *fEvDirKeys;
58 
59  TEveVSD *fVSD;
60 
61  Int_t fMaxEv, fCurEv;
62 
63  // ----------------------------------------------------------
64  // Event visualization structures
65  // ----------------------------------------------------------
66 
67  TEveTrackList *fTrackList;
68  TEvePointSet *fITSClusters;
69  TEvePointSet *fTPCClusters;
70  TEvePointSet *fTRDClusters;
71  TEvePointSet *fTOFClusters;
72 
73 public:
74  TVSDReader(const char* file_name) :
75  fFile(0), fDirectory(0), fEvDirKeys(0),
76  fVSD(0),
77 
78  fMaxEv(-1), fCurEv(-1),
79 
80  fTrackList(0),
81  fITSClusters(0), fTPCClusters(0), fTRDClusters(0), fTOFClusters(0)
82  {
83  fFile = TFile::Open(file_name);
84  if (!fFile)
85  {
86  Error("VSD_Reader", "Can not open file '%s' ... terminating.",
87  file_name);
88  gSystem->Exit(1);
89  }
90 
91  fEvDirKeys = new TObjArray;
92  TPMERegexp name_re("Event\\d+");
93  TObjLink* lnk = fFile->GetListOfKeys()->FirstLink();
94  while (lnk)
95  {
96  if (name_re.Match(lnk->GetObject()->GetName()))
97  {
98  fEvDirKeys->Add(lnk->GetObject());
99  }
100  lnk = lnk->Next();
101  }
102 
103  fMaxEv = fEvDirKeys->GetEntriesFast();
104  if (fMaxEv == 0)
105  {
106  Error("VSD_Reader", "No events to show ... terminating.");
107  gSystem->Exit(1);
108  }
109 
110  fVSD = new TEveVSD;
111  }
112 
113  virtual ~TVSDReader()
114  {
115  // Destructor.
116 
117  DropEvent();
118 
119  delete fVSD;
120  delete fEvDirKeys;
121 
122  fFile->Close();
123  delete fFile;
124  }
125 
126  void AttachEvent()
127  {
128  // Attach event data from current directory.
129 
130  fVSD->LoadTrees();
131  fVSD->SetBranchAddresses();
132  }
133 
134  void DropEvent()
135  {
136  // Drup currently held event data, release current directory.
137 
138  // Drop old visualization structures.
139 
142 
143  // Drop old event-data.
144 
145  fVSD->DeleteTrees();
146  delete fDirectory;
147  fDirectory = 0;
148  }
149 
150  //---------------------------------------------------------------------------
151  // Event navigation
152  //---------------------------------------------------------------------------
153 
154  void NextEvent()
155  {
156  GotoEvent(fCurEv + 1);
157  }
158 
159  void PrevEvent()
160  {
161  GotoEvent(fCurEv - 1);
162  }
163 
164  Bool_t GotoEvent(Int_t ev)
165  {
166  if (ev < 0 || ev >= fMaxEv)
167  {
168  Warning("GotoEvent", "Invalid event id %d.", ev);
169  return kFALSE;
170  }
171 
172  DropEvent();
173 
174  // Connect to new event-data.
175 
176  fCurEv = ev;
177  fDirectory = (TDirectory*) ((TKey*) fEvDirKeys->At(fCurEv))->ReadObj();
178  fVSD->SetDirectory(fDirectory);
179 
180  AttachEvent();
181 
182  // Load event data into visualization structures.
183 
184  LoadClusters(fITSClusters, "ITS", 0);
185  LoadClusters(fTPCClusters, "TPC", 1);
186  LoadClusters(fTRDClusters, "TRD", 2);
187  LoadClusters(fTOFClusters, "TOF", 3);
188 
189  LoadEsdTracks();
190 
191  // Fill projected views.
192 
193  TEveElement* top = gEve->GetCurrentEvent();
194 
195  gMultiView->DestroyEventRPhi();
196  gMultiView->ImportEventRPhi(top);
197 
198  gMultiView->DestroyEventRhoZ();
199  gMultiView->ImportEventRhoZ(top);
200 
202 
203  return kTRUE;
204  }
205 
206 
207  //---------------------------------------------------------------------------
208  // Cluster loading
209  //---------------------------------------------------------------------------
210 
211  void LoadClusters(TEvePointSet*& ps, const TString& det_name, Int_t det_id)
212  {
213  if (ps == 0)
214  {
215  ps = new TEvePointSet(det_name);
216  ps->SetMainColor((Color_t)(det_id + 2));
217  ps->SetMarkerSize(0.5);
218  ps->SetMarkerStyle(2);
219  ps->IncDenyDestroy();
220  }
221  else
222  {
223  ps->Reset();
224  }
225 
226  TEvePointSelector ss(fVSD->fTreeC, ps, "fV.fX:fV.fY:fV.fZ",
227  TString::Format("fDetId==%d", det_id));
228  ss.Select();
229  ps->SetTitle(TString::Format("N=%d", ps->Size()));
230 
231  gEve->AddElement(ps);
232  }
233 
234 
235  //---------------------------------------------------------------------------
236  // Track loading
237  //---------------------------------------------------------------------------
238 
239  enum ESDTrackFlags
240  {
241  kITSin=0x0001,kITSout=0x0002,kITSrefit=0x0004,kITSpid=0x0008,
242  kTPCin=0x0010,kTPCout=0x0020,kTPCrefit=0x0040,kTPCpid=0x0080,
243  kTRDin=0x0100,kTRDout=0x0200,kTRDrefit=0x0400,kTRDpid=0x0800,
244  kTOFin=0x1000,kTOFout=0x2000,kTOFrefit=0x4000,kTOFpid=0x8000,
245  kHMPIDpid=0x20000,
246  kEMCALmatch=0x40000,
247  kTRDbackup=0x80000,
248  kTRDStop=0x20000000,
249  kESDpid=0x40000000,
250  kTIME=0x80000000
251  };
252 
253  Bool_t trackIsOn(TEveTrack* t, Int_t mask)
254  {
255  // Check is track-flag specified by mask are set.
256 
257  return (t->GetStatus() & mask) > 0;
258  }
259 
260  void LoadEsdTracks()
261  {
262  // Read reconstructed tracks from current event.
263 
264  if (fTrackList == 0)
265  {
266  fTrackList = new TEveTrackList("ESD Tracks");
267  fTrackList->SetMainColor(6);
268  fTrackList->SetMarkerColor(kYellow);
269  fTrackList->SetMarkerStyle(4);
270  fTrackList->SetMarkerSize(0.5);
271 
272  fTrackList->IncDenyDestroy();
273  }
274  else
275  {
276  fTrackList->DestroyElements();
277  }
278 
279  TEveTrackPropagator* trkProp = fTrackList->GetPropagator();
280  // !!!! Need to store field on file !!!!
281  // Can store TEveMagField ?
282  trkProp->SetMagField(0.5);
284 
285  Int_t nTracks = fVSD->fTreeR->GetEntries();
286  for (Int_t n = 0; n < nTracks; ++n)
287  {
288  fVSD->fTreeR->GetEntry(n);
289 
290  TEveTrack* track = new TEveTrack(&fVSD->fR, trkProp);
291  track->SetName(Form("ESD Track %d", fVSD->fR.fIndex));
292  track->SetStdTitle();
293  track->SetAttLineAttMarker(fTrackList);
294  fTrackList->AddElement(track);
295  }
296 
297  fTrackList->MakeTracks();
298 
299  gEve->AddElement(fTrackList);
300  }
301 
302  ClassDef(TVSDReader, 0);
303 };
304 
305 TVSDReader* gVSDReader = 0;
306 
307 
308 // Forward declaration.
309 void make_gui();
310 
311 //______________________________________________________________________________
312 void alice_vsd(const char* vsd_file_name=
313  "http://mtadel.home.cern.ch/mtadel/root/AliVSD.root")
314 {
315  // Main function, initializes the application.
316  //
317  // 1. Load the auto-generated library holding ESD classes and
318  // ESD dictionaries.
319  // 2. Open ESD data-files.
320  // 3. Load cartoon geometry.
321  // 4. Spawn simple GUI.
322  // 5. Load first event.
323 
325 
327 
328  gVSDReader = new TVSDReader(vsd_file_name);
329 
331 
332  TEveGeoShape *gentle_geom = 0;
333 
334  { // Simple geometry
335  TFile* geom =
336  TFile::Open("http://mtadel.home.cern.ch/mtadel/root/alice_mini_geom.root",
337  "CACHEREAD");
338  if (!geom)
339  return;
340  TEveGeoShapeExtract* gse = (TEveGeoShapeExtract*) geom->Get("Gentle");
341  gentle_geom = TEveGeoShape::ImportShapeExtract(gse, 0);
342  geom->Close();
343  delete geom;
344  gEve->AddGlobalElement(gentle_geom);
345  }
346 
347 
348  // Standard multi-view
349  //=====================
350 
351  gMultiView = new MultiView;
352  gMultiView->f3DView->GetGLViewer()->SetStyle(TGLRnrCtx::kOutline);
353 
354  gMultiView->SetDepth(-10);
355  gMultiView->ImportGeomRPhi(gentle_geom);
356  gMultiView->ImportGeomRhoZ(gentle_geom);
357  gMultiView->SetDepth(0);
358 
359 
360  // Final stuff
361  //=============
362 
365 
366  gEve->GetBrowser()->GetTabRight()->SetTab(1);
367 
368  make_gui();
369 
370  gEve->AddEvent(new TEveEventManager("Event", "ALICE VSD Event"));
371 
372  gVSDReader->GotoEvent(0);
373 
374  gEve->Redraw3D(kTRUE); // Reset camera after the first event has been shown.
375 }
376 
377 
378 //______________________________________________________________________________
379 void make_gui()
380 {
381  // Create minimal GUI for event navigation.
382 
383  TEveBrowser* browser = gEve->GetBrowser();
385 
386  TGMainFrame* frmMain = new TGMainFrame(gClient->GetRoot(), 1000, 600);
387  frmMain->SetWindowName("XX GUI");
388  frmMain->SetCleanup(kDeepCleanup);
389 
390  TGHorizontalFrame* hf = new TGHorizontalFrame(frmMain);
391  {
392  TString icondir(TString::Format("%s/icons/", gSystem->Getenv("ROOTSYS")));
393  TGPictureButton* b = 0;
394 
395  b = new TGPictureButton(hf, gClient->GetPicture(icondir+"GoBack.gif"));
396  hf->AddFrame(b);
397  b->Connect("Clicked()", "TVSDReader", gVSDReader, "PrevEvent()");
398 
399  b = new TGPictureButton(hf, gClient->GetPicture(icondir+"GoForward.gif"));
400  hf->AddFrame(b);
401  b->Connect("Clicked()", "TVSDReader", gVSDReader, "NextEvent()");
402  }
403  frmMain->AddFrame(hf);
404 
405  frmMain->MapSubwindows();
406  frmMain->Resize();
407  frmMain->MapWindow();
408 
409  browser->StopEmbedding();
410  browser->SetTabTitle("Event Control", 0);
411 }
412 
413 #endif
virtual void SetDirectory(TDirectory *dir)
Set directory in which the trees are (or will be) created.
Definition: TEveVSD.cxx:64
TEveViewerList * GetViewers() const
Definition: TEveManager.h:145
virtual void Resize(UInt_t w=0, UInt_t h=0)
Resize the frame.
Definition: TGFrame.cxx:587
An array of TObjects.
Definition: TObjArray.h:39
Base class for event management and navigation.
static void DisableTObjectStreamersForVSDStruct()
Disable TObject streamers for those VSD structs that inherit from TObject directly.
Definition: TEveVSD.cxx:204
virtual void StartEmbedding(Int_t pos=kRight, Int_t subpos=-1)
Start embedding external frame in the tab "pos" and tab element "subpos".
Globally positioned TGeoShape with rendering attributes and an optional list of daughter shape-extrac...
virtual void DeleteTrees()
Delete internal trees.
Definition: TEveVSD.cxx:88
virtual void SetName(const char *name)
Change (i.e.
void SetWindowName(const char *name=0)
Set window name. This is typically done via the window manager.
Definition: TGFrame.cxx:1746
virtual TList * GetListOfKeys() const
virtual Int_t Size() const
Definition: TPolyMarker3D.h:81
A ROOT file is a suite of consecutive data records (TKey instances) with a well defined format...
Definition: TFile.h:50
void AddGlobalElement(TEveElement *element, TEveElement *parent=0)
Add a global element, i.e.
virtual TObject * Get(const char *namecycle)
Return pointer to object identified by namecycle.
void IncDenyDestroy()
Increases the deny-destroy count of the element.
Specialization of TRootBrowser for Eve.
Definition: TEveBrowser.h:128
virtual Int_t GetEntry(Long64_t entry=0, Int_t getall=0)
Read all branches of entry and return total number of bytes read.
Definition: TTree.cxx:5210
Basic string class.
Definition: TString.h:137
#define gClient
Definition: TGClient.h:174
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
const Bool_t kFALSE
Definition: Rtypes.h:92
virtual void SetMarkerStyle(Style_t mstyle=1)
Set marker style, propagate to projecteds.
void Redraw3D(Bool_t resetCameras=kFALSE, Bool_t dropLogicals=kFALSE)
Definition: TEveManager.h:168
virtual void SetMarkerColor(Color_t c)
Set marker color for the list and the elements.
Definition: TEveTrack.cxx:931
TEveRecTrack fR
Definition: TEveVSD.h:44
Definition: Rtypes.h:61
Int_t GetEntriesFast() const
Definition: TObjArray.h:66
virtual void SetTitle(const char *t)
Definition: TEvePointSet.h:69
void SwitchColorSet()
Switch background color.
Definition: TEveViewer.cxx:658
TEveEventManager * GetCurrentEvent() const
Definition: TEveManager.h:149
virtual void LoadTrees()
Load internal trees from directory.
Definition: TEveVSD.cxx:149
void AddElement(TEveElement *element, TEveElement *parent=0)
Add an element.
static TFile * Open(const char *name, Option_t *option="", const char *ftitle="", Int_t compress=1, Int_t netopt=0)
Create / open a file.
Definition: TFile.cxx:3871
void SetStepper(EStepper_e s)
TTree * fTreeR
Clusters.
Definition: TEveVSD.h:35
#define ClassDef(name, id)
Definition: Rtypes.h:254
static TString Format(const char *fmt,...)
Static method which formats a string using a printf style format descriptor and return a TString...
Definition: TString.cxx:2335
virtual void SetMarkerStyle(Style_t s)
Set marker style for the list and the elements.
Definition: TEveTrack.cxx:899
Multi-view (3d, rphi, rhoz) service class using EVE Window Manager.
A list of tracks supporting change of common attributes and selection based on track parameters...
Definition: TEveTrack.h:137
virtual const char * Getenv(const char *env)
Get environment variable.
Definition: TSystem.cxx:1627
virtual void SetMainColor(Color_t c)
Set main (line) color for the list and the elements.
Definition: TEveTrack.cxx:803
static TEveManager * Create(Bool_t map_window=kTRUE, Option_t *opt="FIV")
If global TEveManager* gEve is not set initialize it.
Book space in a file, create I/O buffers, to fill them, (un)compress them.
Definition: TKey.h:30
virtual void SetMarkerSize(Size_t msize=1)
Set marker size, propagate to projecteds.
virtual void DestroyElements()
Destroy all children of this element.
void Error(const char *location, const char *msgfmt,...)
short Color_t
Definition: RtypesCore.h:79
virtual void SetBranchAddresses()
Set branche addresses of internal trees.
Definition: TEveVSD.cxx:122
TGListTreeItem * AddEvent(TEveEventManager *event)
Add a new event and make it the current event.
Bool_t Connect(const char *signal, const char *receiver_class, void *receiver, const char *slot)
Non-static method is used to connect from the signal of this object to the receiver slot...
Definition: TQObject.cxx:1137
R__EXTERN TSystem * gSystem
Definition: TSystem.h:549
void SetTabTitle(const char *title, Int_t pos=kRight, Int_t subpos=-1)
Set text "title" of Tab "subpos" in TGTab "pos".
R__EXTERN TEveManager * gEve
Definition: TEveManager.h:243
Int_t GetStatus() const
Definition: TEveTrack.h:104
virtual Bool_t SetTab(Int_t tabIndex, Bool_t emit=kTRUE)
Brings the composite frame with the index tabIndex to the front and generate the following event if t...
Definition: TGTab.cxx:507
char * Form(const char *fmt,...)
TEvePointSet is a render-element holding a collection of 3D points with optional per-point TRef and a...
Definition: TEvePointSet.h:31
TEveTrackPropagator * GetPropagator()
Definition: TEveTrack.h:175
virtual void AddElement(TEveElement *el)
Add el to the list of children.
virtual TObjLink * FirstLink() const
Definition: TList.h:101
Holding structure for a number of track rendering parameters.
Visual representation of a track.
Definition: TEveTrack.h:32
void Warning(const char *location, const char *msgfmt,...)
virtual void SetMainColor(Color_t color)
Set main color of the element.
void DeleteAnnotations()
Delete annotations from all viewers.
Definition: TEveViewer.cxx:475
virtual const char * GetName() const
Returns name of object.
Definition: TObject.cxx:416
virtual void SetCleanup(Int_t mode=kLocalCleanup)
Turn on automatic cleanup of child frames in dtor.
Definition: TGFrame.cxx:1054
virtual void SetMarkerSize(Size_t s)
Set marker size for the list and the elements.
Definition: TEveTrack.cxx:963
Describe directory structure in memory.
Definition: TDirectory.h:44
TEveBrowser * GetBrowser() const
Definition: TEveManager.h:137
TGLViewer * GetDefaultGLViewer() const
Get TGLViewer of the default TEveViewer.
virtual void StopEmbedding(const char *name=0)
Definition: TRootBrowser.h:156
virtual void AddFrame(TGFrame *f, TGLayoutHints *l=0)
Add frame to the composite frame using the specified layout hints.
Definition: TGFrame.cxx:1099
virtual void MapSubwindows()
Map all sub windows that are part of the composite frame.
Definition: TGFrame.cxx:1146
void Reset(Int_t n_points=0, Int_t n_int_ids=0)
Drop all data and set-up the data structures to recive new data.
Visualization Summary Data - a collection of trees holding standard event data in experiment independ...
Definition: TEveVSD.h:19
void SetMagField(Double_t bX, Double_t bY, Double_t bZ)
Set constant magnetic field and rebuild tracks.
static Bool_t SetCacheFileDir(const char *cacheDir, Bool_t operateDisconnected=kTRUE, Bool_t forceCacheread=kFALSE)
Sets the directory where to locally stage/cache remote files.
Definition: TFile.cxx:4391
Wrapper for PCRE library (Perl Compatible Regular Expressions).
Definition: TPRegexp.h:103
virtual void MapWindow()
Definition: TGFrame.h:267
Wrapper for TGeoShape with absolute positioning and color attributes allowing display of extracted TG...
Definition: TEveGeoShape.h:23
virtual void Exit(int code, Bool_t mode=kTRUE)
Exit the application.
Definition: TSystem.cxx:721
you should not use this method at all Int_t Int_t Double_t Double_t Double_t Int_t Double_t Double_t Double_t Double_t b
Definition: TRolke.cxx:630
void MakeTracks(Bool_t recurse=kTRUE)
Regenerate the visual representations of tracks.
Definition: TEveTrack.cxx:637
virtual void SetStdTitle()
Set standard track title based on most data-member values.
Definition: TEveTrack.cxx:266
void Add(TObject *obj)
Definition: TObjArray.h:75
virtual Long64_t GetEntries() const
Definition: TTree.h:392
void SetAttLineAttMarker(TEveTrackList *tl)
Set line and marker attributes from TEveTrackList.
Definition: TEveTrack.cxx:320
TTree * fTreeC
Hits.
Definition: TEveVSD.h:34
TObject * At(Int_t idx) const
Definition: TObjArray.h:167
const Bool_t kTRUE
Definition: Rtypes.h:91
static TEveGeoShape * ImportShapeExtract(TEveGeoShapeExtract *gse, TEveElement *parent=0)
Import a shape extract &#39;gse&#39; under element &#39;parent&#39;.
Base class for TEveUtil visualization elements, providing hierarchy management, rendering control and...
Definition: TEveElement.h:33
TGTab * GetTabRight() const
Definition: TRootBrowser.h:145
const Int_t n
Definition: legend1.C:16
void SetStyle(Short_t st)
TEvePointSelector is a sub-class of TSelectorDraw for direct extraction of point-like data from a Tre...
Definition: TEveTreeTools.h:66
virtual void Close(Option_t *option="")
Close a file.
Definition: TFile.cxx:904