ROOT  6.07/01
Reference Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 #if defined(__CINT__) && !defined(__MAKECINT__)
23 {
24  Info("alice_vsd.C",
25  "Has to be run in compiled mode ... doing this for you.");
26  gSystem->CompileMacro("alice_vsd.C");
27  alice_vsd();
28 }
29 #else
30 
31 
32 #include <TEveManager.h>
33 #include <TEveEventManager.h>
34 #include <TEveVSD.h>
35 #include <TEveVSDStructs.h>
36 
37 #include <TEveTrack.h>
38 #include <TEveTrackPropagator.h>
39 #include <TEveGeoShape.h>
40 
41 #include <TGTab.h>
42 #include <TGButton.h>
43 
44 #include <TFile.h>
45 #include <TKey.h>
46 #include <TSystem.h>
47 #include <TPRegexp.h>
48 
49 
50 // Include componets -- compile time link :)
51 
52 #include "MultiView.C"
53 MultiView* gMultiView = 0;
54 
55 
56 class TVSDReader
57 {
58 public:
59  // ----------------------------------------------------------
60  // File / Event Data
61  // ----------------------------------------------------------
62 
63  TFile *fFile;
64  TDirectory *fDirectory;
65 
66  TObjArray *fEvDirKeys;
67 
68  TEveVSD *fVSD;
69 
70  Int_t fMaxEv, fCurEv;
71 
72  // ----------------------------------------------------------
73  // Event visualization structures
74  // ----------------------------------------------------------
75 
76  TEveTrackList *fTrackList;
77  TEvePointSet *fITSClusters;
78  TEvePointSet *fTPCClusters;
79  TEvePointSet *fTRDClusters;
80  TEvePointSet *fTOFClusters;
81 
82 public:
83  TVSDReader(const char* file_name) :
84  fFile(0), fDirectory(0), fEvDirKeys(0),
85  fVSD(0),
86 
87  fMaxEv(-1), fCurEv(-1),
88 
89  fTrackList(0),
90  fITSClusters(0), fTPCClusters(0), fTRDClusters(0), fTOFClusters(0)
91  {
92  fFile = TFile::Open(file_name);
93  if (!fFile)
94  {
95  Error("VSD_Reader", "Can not open file '%s' ... terminating.",
96  file_name);
97  gSystem->Exit(1);
98  }
99 
100  fEvDirKeys = new TObjArray;
101  TPMERegexp name_re("Event\\d+");
102  TObjLink* lnk = fFile->GetListOfKeys()->FirstLink();
103  while (lnk)
104  {
105  if (name_re.Match(lnk->GetObject()->GetName()))
106  {
107  fEvDirKeys->Add(lnk->GetObject());
108  }
109  lnk = lnk->Next();
110  }
111 
112  fMaxEv = fEvDirKeys->GetEntriesFast();
113  if (fMaxEv == 0)
114  {
115  Error("VSD_Reader", "No events to show ... terminating.");
116  gSystem->Exit(1);
117  }
118 
119  fVSD = new TEveVSD;
120  }
121 
122  virtual ~TVSDReader()
123  {
124  // Destructor.
125 
126  DropEvent();
127 
128  delete fVSD;
129  delete fEvDirKeys;
130 
131  fFile->Close();
132  delete fFile;
133  }
134 
135  void AttachEvent()
136  {
137  // Attach event data from current directory.
138 
139  fVSD->LoadTrees();
140  fVSD->SetBranchAddresses();
141  }
142 
143  void DropEvent()
144  {
145  // Drup currently held event data, release current directory.
146 
147  // Drop old visualization structures.
148 
151 
152  // Drop old event-data.
153 
154  fVSD->DeleteTrees();
155  delete fDirectory;
156  fDirectory = 0;
157  }
158 
159  //---------------------------------------------------------------------------
160  // Event navigation
161  //---------------------------------------------------------------------------
162 
163  void NextEvent()
164  {
165  GotoEvent(fCurEv + 1);
166  }
167 
168  void PrevEvent()
169  {
170  GotoEvent(fCurEv - 1);
171  }
172 
173  Bool_t GotoEvent(Int_t ev)
174  {
175  if (ev < 0 || ev >= fMaxEv)
176  {
177  Warning("GotoEvent", "Invalid event id %d.", ev);
178  return kFALSE;
179  }
180 
181  DropEvent();
182 
183  // Connect to new event-data.
184 
185  fCurEv = ev;
186  fDirectory = (TDirectory*) ((TKey*) fEvDirKeys->At(fCurEv))->ReadObj();
187  fVSD->SetDirectory(fDirectory);
188 
189  AttachEvent();
190 
191  // Load event data into visualization structures.
192 
193  LoadClusters(fITSClusters, "ITS", 0);
194  LoadClusters(fTPCClusters, "TPC", 1);
195  LoadClusters(fTRDClusters, "TRD", 2);
196  LoadClusters(fTOFClusters, "TOF", 3);
197 
198  LoadEsdTracks();
199 
200  // Fill projected views.
201 
202  TEveElement* top = gEve->GetCurrentEvent();
203 
204  gMultiView->DestroyEventRPhi();
205  gMultiView->ImportEventRPhi(top);
206 
207  gMultiView->DestroyEventRhoZ();
208  gMultiView->ImportEventRhoZ(top);
209 
211 
212  return kTRUE;
213  }
214 
215 
216  //---------------------------------------------------------------------------
217  // Cluster loading
218  //---------------------------------------------------------------------------
219 
220  void LoadClusters(TEvePointSet*& ps, const TString& det_name, Int_t det_id)
221  {
222  if (ps == 0)
223  {
224  ps = new TEvePointSet(det_name);
225  ps->SetMainColor((Color_t)(det_id + 2));
226  ps->SetMarkerSize(0.5);
227  ps->SetMarkerStyle(2);
228  ps->IncDenyDestroy();
229  }
230  else
231  {
232  ps->Reset();
233  }
234 
235  TEvePointSelector ss(fVSD->fTreeC, ps, "fV.fX:fV.fY:fV.fZ",
236  TString::Format("fDetId==%d", det_id));
237  ss.Select();
238  ps->SetTitle(TString::Format("N=%d", ps->Size()));
239 
240  gEve->AddElement(ps);
241  }
242 
243 
244  //---------------------------------------------------------------------------
245  // Track loading
246  //---------------------------------------------------------------------------
247 
248  enum ESDTrackFlags
249  {
250  kITSin=0x0001,kITSout=0x0002,kITSrefit=0x0004,kITSpid=0x0008,
251  kTPCin=0x0010,kTPCout=0x0020,kTPCrefit=0x0040,kTPCpid=0x0080,
252  kTRDin=0x0100,kTRDout=0x0200,kTRDrefit=0x0400,kTRDpid=0x0800,
253  kTOFin=0x1000,kTOFout=0x2000,kTOFrefit=0x4000,kTOFpid=0x8000,
254  kHMPIDpid=0x20000,
255  kEMCALmatch=0x40000,
256  kTRDbackup=0x80000,
257  kTRDStop=0x20000000,
258  kESDpid=0x40000000,
259  kTIME=0x80000000
260  };
261 
262  Bool_t trackIsOn(TEveTrack* t, Int_t mask)
263  {
264  // Check is track-flag specified by mask are set.
265 
266  return (t->GetStatus() & mask) > 0;
267  }
268 
269  void LoadEsdTracks()
270  {
271  // Read reconstructed tracks from current event.
272 
273  if (fTrackList == 0)
274  {
275  fTrackList = new TEveTrackList("ESD Tracks");
276  fTrackList->SetMainColor(6);
277  fTrackList->SetMarkerColor(kYellow);
278  fTrackList->SetMarkerStyle(4);
279  fTrackList->SetMarkerSize(0.5);
280 
281  fTrackList->IncDenyDestroy();
282  }
283  else
284  {
285  fTrackList->DestroyElements();
286  }
287 
288  TEveTrackPropagator* trkProp = fTrackList->GetPropagator();
289  // !!!! Need to store field on file !!!!
290  // Can store TEveMagField ?
291  trkProp->SetMagField(0.5);
293 
294  Int_t nTracks = fVSD->fTreeR->GetEntries();
295  for (Int_t n = 0; n < nTracks; ++n)
296  {
297  fVSD->fTreeR->GetEntry(n);
298 
299  TEveTrack* track = new TEveTrack(&fVSD->fR, trkProp);
300  track->SetName(Form("ESD Track %d", fVSD->fR.fIndex));
301  track->SetStdTitle();
302  track->SetAttLineAttMarker(fTrackList);
303  fTrackList->AddElement(track);
304  }
305 
306  fTrackList->MakeTracks();
307 
308  gEve->AddElement(fTrackList);
309  }
310 
311  ClassDef(TVSDReader, 0);
312 };
313 
314 TVSDReader* gVSDReader = 0;
315 
316 
317 // Forward declaration.
318 void make_gui();
319 
320 //______________________________________________________________________________
321 void alice_vsd(const char* vsd_file_name=
322  "http://mtadel.home.cern.ch/mtadel/root/AliVSD.root")
323 {
324  // Main function, initializes the application.
325  //
326  // 1. Load the auto-generated library holding ESD classes and
327  // ESD dictionaries.
328  // 2. Open ESD data-files.
329  // 3. Load cartoon geometry.
330  // 4. Spawn simple GUI.
331  // 5. Load first event.
332 
334 
336 
337  gVSDReader = new TVSDReader(vsd_file_name);
338 
340 
341  TEveGeoShape *gentle_geom = 0;
342 
343  { // Simple geometry
344  TFile* geom =
345  TFile::Open("http://mtadel.home.cern.ch/mtadel/root/alice_mini_geom.root",
346  "CACHEREAD");
347  if (!geom)
348  return;
349  TEveGeoShapeExtract* gse = (TEveGeoShapeExtract*) geom->Get("Gentle");
350  gentle_geom = TEveGeoShape::ImportShapeExtract(gse, 0);
351  geom->Close();
352  delete geom;
353  gEve->AddGlobalElement(gentle_geom);
354  }
355 
356 
357  // Standard multi-view
358  //=====================
359 
360  gMultiView = new MultiView;
361  gMultiView->f3DView->GetGLViewer()->SetStyle(TGLRnrCtx::kOutline);
362 
363  gMultiView->SetDepth(-10);
364  gMultiView->ImportGeomRPhi(gentle_geom);
365  gMultiView->ImportGeomRhoZ(gentle_geom);
366  gMultiView->SetDepth(0);
367 
368 
369  // Final stuff
370  //=============
371 
374 
375  gEve->GetBrowser()->GetTabRight()->SetTab(1);
376 
377  make_gui();
378 
379  gEve->AddEvent(new TEveEventManager("Event", "ALICE VSD Event"));
380 
381  gVSDReader->GotoEvent(0);
382 
383  gEve->Redraw3D(kTRUE); // Reset camera after the first event has been shown.
384 }
385 
386 
387 //______________________________________________________________________________
388 void make_gui()
389 {
390  // Create minimal GUI for event navigation.
391 
392  TEveBrowser* browser = gEve->GetBrowser();
394 
395  TGMainFrame* frmMain = new TGMainFrame(gClient->GetRoot(), 1000, 600);
396  frmMain->SetWindowName("XX GUI");
397  frmMain->SetCleanup(kDeepCleanup);
398 
399  TGHorizontalFrame* hf = new TGHorizontalFrame(frmMain);
400  {
401  TString icondir(TString::Format("%s/icons/", gSystem->Getenv("ROOTSYS")));
402  TGPictureButton* b = 0;
403 
404  b = new TGPictureButton(hf, gClient->GetPicture(icondir+"GoBack.gif"));
405  hf->AddFrame(b);
406  b->Connect("Clicked()", "TVSDReader", gVSDReader, "PrevEvent()");
407 
408  b = new TGPictureButton(hf, gClient->GetPicture(icondir+"GoForward.gif"));
409  hf->AddFrame(b);
410  b->Connect("Clicked()", "TVSDReader", gVSDReader, "NextEvent()");
411  }
412  frmMain->AddFrame(hf);
413 
414  frmMain->MapSubwindows();
415  frmMain->Resize();
416  frmMain->MapWindow();
417 
418  browser->StopEmbedding();
419  browser->SetTabTitle("Event Control", 0);
420 }
421 
422 #endif
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
TServerSocket * ss
Definition: hserv2.C:30
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 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 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:45
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
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
Definition: Rtypes.h:61
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
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:3851
void SetStepper(EStepper_e s)
#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:2321
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 int CompileMacro(const char *filename, Option_t *opt="", const char *library_name="", const char *build_dir="", UInt_t dirmode=0)
This method compiles and loads a shared library containing the code from the file "filename"...
Definition: TSystem.cxx:2736
virtual const char * Getenv(const char *env)
Get environment variable.
Definition: TSystem.cxx:1575
void Info(const char *location, const char *msgfmt,...)
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
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:1135
virtual Int_t Select(Int_t interest=kRead, Long_t timeout=-1)
Waits for this socket to change status.
Definition: TSocket.cxx:441
R__EXTERN TSystem * gSystem
Definition: TSystem.h:545
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
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:415
virtual void SetCleanup(Int_t mode=kLocalCleanup)
Turn on automatic cleanup of child frames in dtor.
Definition: TGFrame.cxx:1054
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:4371
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:720
virtual void SetStdTitle()
Set standard track title based on most data-member values.
Definition: TEveTrack.cxx:266
void SetAttLineAttMarker(TEveTrackList *tl)
Set line and marker attributes from TEveTrackList.
Definition: TEveTrack.cxx:320
const Bool_t kTRUE
Definition: Rtypes.h:91
static TEveGeoShape * ImportShapeExtract(TEveGeoShapeExtract *gse, TEveElement *parent=0)
Import a shape extract 'gse' under element 'parent'.
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:898