Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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 components -- compile time link :)
42
43#include "MultiView.C"
44MultiView* gMultiView = 0;
45
46
47class TVSDReader
48{
49public:
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
73public:
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 if (name_re.Match(lnk->GetObject()->GetName()))
96 {
97 fEvDirKeys->Add(lnk->GetObject());
98 }
99 lnk = lnk->Next();
100 }
101
102 fMaxEv = fEvDirKeys->GetEntriesFast();
103 if (fMaxEv == 0) {
104 Error("VSD_Reader", "No events to show ... terminating.");
105 gSystem->Exit(1);
106 }
107
108 fVSD = new TEveVSD;
109 }
110
111 virtual ~TVSDReader()
112 {
113 // Destructor.
114
115 DropEvent();
116
117 delete fVSD;
118 delete fEvDirKeys;
119
120 fFile->Close();
121 delete fFile;
122 }
123
124 void AttachEvent()
125 {
126 // Attach event data from current directory.
127
128 fVSD->LoadTrees();
129 fVSD->SetBranchAddresses();
130 }
131
132 void DropEvent()
133 {
134 // Drup currently held event data, release current directory.
135
136 // Drop old visualization structures.
137
140
141 // Drop old event-data.
142
143 fVSD->DeleteTrees();
144 delete fDirectory;
145 fDirectory = 0;
146 }
147
148 //---------------------------------------------------------------------------
149 // Event navigation
150 //---------------------------------------------------------------------------
151
152 void NextEvent()
153 {
154 GotoEvent(fCurEv + 1);
155 }
156
157 void PrevEvent()
158 {
159 GotoEvent(fCurEv - 1);
160 }
161
162 Bool_t GotoEvent(Int_t ev)
163 {
164 if (ev < 0 || ev >= fMaxEv)
165 {
166 Warning("GotoEvent", "Invalid event id %d.", ev);
167 return kFALSE;
168 }
169
170 DropEvent();
171
172 // Connect to new event-data.
173
174 fCurEv = ev;
175 fDirectory = (TDirectory*) ((TKey*) fEvDirKeys->At(fCurEv))->ReadObj();
176 fVSD->SetDirectory(fDirectory);
177
178 AttachEvent();
179
180 // Load event data into visualization structures.
181
182 LoadClusters(fITSClusters, "ITS", 0);
183 LoadClusters(fTPCClusters, "TPC", 1);
184 LoadClusters(fTRDClusters, "TRD", 2);
185 LoadClusters(fTOFClusters, "TOF", 3);
186
187 LoadEsdTracks();
188
189 // Fill projected views.
190
191 auto top = gEve->GetCurrentEvent();
192
193 gMultiView->DestroyEventRPhi();
194 gMultiView->ImportEventRPhi(top);
195
196 gMultiView->DestroyEventRhoZ();
197 gMultiView->ImportEventRhoZ(top);
198
200
201 return kTRUE;
202 }
203
204
205 //---------------------------------------------------------------------------
206 // Cluster loading
207 //---------------------------------------------------------------------------
208
209 void LoadClusters(TEvePointSet*& ps, const TString& det_name, Int_t det_id)
210 {
211 if (ps == 0) {
212 ps = new TEvePointSet(det_name);
213 ps->SetMainColor((Color_t)(det_id + 2));
214 ps->SetMarkerSize(0.5);
215 ps->SetMarkerStyle(2);
216 ps->IncDenyDestroy();
217 } else {
218 ps->Reset();
219 }
220
221 TEvePointSelector ss(fVSD->fTreeC, ps, "fV.fX:fV.fY:fV.fZ",
222 TString::Format("fDetId==%d", det_id));
223 ss.Select();
224 ps->SetTitle(TString::Format("N=%d", ps->Size()));
225
226 gEve->AddElement(ps);
227 }
228
229
230 //---------------------------------------------------------------------------
231 // Track loading
232 //---------------------------------------------------------------------------
233
234 enum ESDTrackFlags
235 {
236 kITSin=0x0001,kITSout=0x0002,kITSrefit=0x0004,kITSpid=0x0008,
237 kTPCin=0x0010,kTPCout=0x0020,kTPCrefit=0x0040,kTPCpid=0x0080,
238 kTRDin=0x0100,kTRDout=0x0200,kTRDrefit=0x0400,kTRDpid=0x0800,
239 kTOFin=0x1000,kTOFout=0x2000,kTOFrefit=0x4000,kTOFpid=0x8000,
240 kHMPIDpid=0x20000,
241 kEMCALmatch=0x40000,
242 kTRDbackup=0x80000,
243 kTRDStop=0x20000000,
244 kESDpid=0x40000000,
245 kTIME=0x80000000
246 };
247
248 Bool_t trackIsOn(TEveTrack* t, Int_t mask)
249 {
250 // Check is track-flag specified by mask are set.
251
252 return (t->GetStatus() & mask) > 0;
253 }
254
255 void LoadEsdTracks()
256 {
257 // Read reconstructed tracks from current event.
258
259 if (fTrackList == 0) {
260 fTrackList = new TEveTrackList("ESD Tracks");
261 fTrackList->SetMainColor(6);
262 fTrackList->SetMarkerColor(kYellow);
263 fTrackList->SetMarkerStyle(4);
264 fTrackList->SetMarkerSize(0.5);
265
266 fTrackList->IncDenyDestroy();
267 } else {
268 fTrackList->DestroyElements();
269 }
270
271 auto trkProp = fTrackList->GetPropagator();
272 // !!!! Need to store field on file !!!!
273 // Can store TEveMagField ?
274 trkProp->SetMagField(0.5);
275 trkProp->SetStepper(TEveTrackPropagator::kRungeKutta);
276
277 Int_t nTracks = fVSD->fTreeR->GetEntries();
278 for (Int_t n = 0; n < nTracks; ++n) {
279 fVSD->fTreeR->GetEntry(n);
280
281 TEveTrack* track = new TEveTrack(&fVSD->fR, trkProp);
282 track->SetName(Form("ESD Track %d", fVSD->fR.fIndex));
283 track->SetStdTitle();
284 track->SetAttLineAttMarker(fTrackList);
285 fTrackList->AddElement(track);
286 }
287
288 fTrackList->MakeTracks();
289
290 gEve->AddElement(fTrackList);
291 }
292
293 ClassDef(TVSDReader, 0);
294};
295
296TVSDReader* gVSDReader = 0;
297
298
299// Forward declaration.
300void make_gui();
301
302//______________________________________________________________________________
303void alice_vsd(const char* vsd_file_name=
304 "http://mtadel.home.cern.ch/mtadel/root/AliVSD.root")
305{
306 // Main function, initializes the application.
307 //
308 // 1. Load the auto-generated library holding ESD classes and
309 // ESD dictionaries.
310 // 2. Open ESD data-files.
311 // 3. Load cartoon geometry.
312 // 4. Spawn simple GUI.
313 // 5. Load first event.
314
316
318
319 gVSDReader = new TVSDReader(vsd_file_name);
320
322
323 TEveGeoShape *gentle_geom = 0;
324
325 { // Simple geometry
326 auto geom =
327 TFile::Open("http://mtadel.home.cern.ch/mtadel/root/alice_mini_geom.root",
328 "CACHEREAD");
329 if (!geom)
330 return;
331 auto gse = (TEveGeoShapeExtract*) geom->Get("Gentle");
332 gentle_geom = TEveGeoShape::ImportShapeExtract(gse, 0);
333 geom->Close();
334 delete geom;
335 gEve->AddGlobalElement(gentle_geom);
336 }
337
338
339 // Standard multi-view
340 //=====================
341
342 gMultiView = new MultiView;
343 gMultiView->f3DView->GetGLViewer()->SetStyle(TGLRnrCtx::kOutline);
344
345 gMultiView->SetDepth(-10);
346 gMultiView->ImportGeomRPhi(gentle_geom);
347 gMultiView->ImportGeomRhoZ(gentle_geom);
348 gMultiView->SetDepth(0);
349
350
351 // Final stuff
352 //=============
353
356
358
359 make_gui();
360
361 gEve->AddEvent(new TEveEventManager("Event", "ALICE VSD Event"));
362
363 gVSDReader->GotoEvent(0);
364
365 gEve->Redraw3D(kTRUE); // Reset camera after the first event has been shown.
366}
367
368
369//______________________________________________________________________________
370void make_gui()
371{
372 // Create minimal GUI for event navigation.
373
374 auto browser = gEve->GetBrowser();
376
377 auto frmMain = new TGMainFrame(gClient->GetRoot(), 1000, 600);
378 frmMain->SetWindowName("XX GUI");
379 frmMain->SetCleanup(kDeepCleanup);
380
381 auto hf = new TGHorizontalFrame(frmMain);
382 {
383 TString icondir(TString::Format("%s/icons/", gSystem->Getenv("ROOTSYS")));
384 TGPictureButton* b = 0;
385
386 b = new TGPictureButton(hf, gClient->GetPicture(icondir+"GoBack.gif"));
387 hf->AddFrame(b);
388 b->Connect("Clicked()", "TVSDReader", gVSDReader, "PrevEvent()");
389
390 b = new TGPictureButton(hf, gClient->GetPicture(icondir+"GoForward.gif"));
391 hf->AddFrame(b);
392 b->Connect("Clicked()", "TVSDReader", gVSDReader, "NextEvent()");
393 }
394 frmMain->AddFrame(hf);
395
396 frmMain->MapSubwindows();
397 frmMain->Resize();
398 frmMain->MapWindow();
399
400 browser->StopEmbedding();
401 browser->SetTabTitle("Event Control", 0);
402}
403
Multi-view (3d, rphi, rhoz) service class using EVE Window Manager.
#define b(i)
Definition RSha256.hxx:100
int Int_t
Definition RtypesCore.h:45
const Bool_t kFALSE
Definition RtypesCore.h:92
bool Bool_t
Definition RtypesCore.h:63
short Color_t
Definition RtypesCore.h:83
const Bool_t kTRUE
Definition RtypesCore.h:91
#define ClassDef(name, id)
Definition Rtypes.h:325
@ kYellow
Definition Rtypes.h:66
void Error(const char *location, const char *msgfmt,...)
Use this function in case an error occurred.
Definition TError.cxx:187
void Warning(const char *location, const char *msgfmt,...)
Use this function in warning situations.
Definition TError.cxx:231
R__EXTERN TEveManager * gEve
#define gClient
Definition TGClient.h:166
@ kDeepCleanup
Definition TGFrame.h:50
char * Form(const char *fmt,...)
R__EXTERN TSystem * gSystem
Definition TSystem.h:559
TList * GetListOfKeys() const override
Describe directory structure in memory.
Definition TDirectory.h:45
virtual void AddElement(TEveElement *el)
Add el to the list of children.
virtual void SetMainColor(Color_t color)
Set main color of the element.
void IncDenyDestroy()
Increases the deny-destroy count of the element.
virtual void DestroyElements()
Destroy all children of this element.
Base class for event management and navigation.
Globally positioned TGeoShape with rendering attributes and an optional list of daughter shape-extrac...
Wrapper for TGeoShape with absolute positioning and color attributes allowing display of extracted TG...
static TEveGeoShape * ImportShapeExtract(TEveGeoShapeExtract *gse, TEveElement *parent=0)
Import a shape extract 'gse' under element 'parent'.
TEveViewerList * GetViewers() const
void AddElement(TEveElement *element, TEveElement *parent=0)
Add an element.
void AddGlobalElement(TEveElement *element, TEveElement *parent=0)
Add a global element, i.e.
TGLViewer * GetDefaultGLViewer() const
Get TGLViewer of the default TEveViewer.
TEveBrowser * GetBrowser() const
static TEveManager * Create(Bool_t map_window=kTRUE, Option_t *opt="FIV")
If global TEveManager* gEve is not set initialize it.
TGListTreeItem * AddEvent(TEveEventManager *event)
Add a new event and make it the current event.
void Redraw3D(Bool_t resetCameras=kFALSE, Bool_t dropLogicals=kFALSE)
TEveEventManager * GetCurrentEvent() const
TEvePointSelector is a sub-class of TSelectorDraw for direct extraction of point-like data from a Tre...
TEvePointSet is a render-element holding a collection of 3D points with optional per-point TRef and a...
virtual void SetMarkerStyle(Style_t mstyle=1)
Set marker style, propagate to projecteds.
virtual void SetTitle(const char *t)
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.
virtual void SetMarkerSize(Size_t msize=1)
Set marker size, propagate to projecteds.
A list of tracks supporting change of common attributes and selection based on track parameters.
Definition TEveTrack.h:140
virtual void SetMarkerStyle(Style_t s)
Set marker style for the list and the elements.
virtual void SetMarkerColor(Color_t c)
Set marker color for the list and the elements.
void MakeTracks(Bool_t recurse=kTRUE)
Regenerate the visual representations of tracks.
virtual void SetMainColor(Color_t c)
Set main (line) color for the list and the elements.
TEveTrackPropagator * GetPropagator()
Definition TEveTrack.h:175
virtual void SetMarkerSize(Size_t s)
Set marker size for the list and the elements.
void SetMagField(Double_t bX, Double_t bY, Double_t bZ)
Set constant magnetic field and rebuild tracks.
Visual representation of a track.
Definition TEveTrack.h:33
void SetAttLineAttMarker(TEveTrackList *tl)
Set line and marker attributes from TEveTrackList.
Int_t GetStatus() const
Definition TEveTrack.h:104
virtual void SetStdTitle()
Set standard track title based on most data-member values.
Visualization Summary Data - a collection of trees holding standard event data in experiment independ...
Definition TEveVSD.h:20
static void DisableTObjectStreamersForVSDStruct()
Disable TObject streamers for those VSD structs that inherit from TObject directly.
Definition TEveVSD.cxx:203
TEveRecTrack fR
Definition TEveVSD.h:44
virtual void SetBranchAddresses()
Set branche addresses of internal trees.
Definition TEveVSD.cxx:121
virtual void DeleteTrees()
Delete internal trees.
Definition TEveVSD.cxx:87
virtual void SetDirectory(TDirectory *dir)
Set directory in which the trees are (or will be) created.
Definition TEveVSD.cxx:63
TTree * fTreeC
Hits.
Definition TEveVSD.h:34
virtual void LoadTrees()
Load internal trees from directory.
Definition TEveVSD.cxx:148
TTree * fTreeR
Clusters.
Definition TEveVSD.h:35
void SwitchColorSet()
Switch background color.
void DeleteAnnotations()
Delete annotations from all viewers.
A ROOT file is a suite of consecutive data records (TKey instances) with a well defined format.
Definition TFile.h:54
static Bool_t SetCacheFileDir(ROOT::Internal::TStringView cacheDir, Bool_t operateDisconnected=kTRUE, Bool_t forceCacheread=kFALSE)
Definition TFile.h:324
static TFile * Open(const char *name, Option_t *option="", const char *ftitle="", Int_t compress=ROOT::RCompressionSetting::EDefaults::kUseCompiledDefault, Int_t netopt=0)
Create / open a file.
Definition TFile.cxx:3997
void Close(Option_t *option="") override
Close a file.
Definition TFile.cxx:879
void SetStyle(Short_t st)
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:509
Book space in a file, create I/O buffers, to fill them, (un)compress them.
Definition TKey.h:28
virtual TObjLink * FirstLink() const
Definition TList.h:108
An array of TObjects.
Definition TObjArray.h:37
Int_t GetEntriesFast() const
Definition TObjArray.h:64
void Add(TObject *obj)
Definition TObjArray.h:74
TObject * At(Int_t idx) const
Definition TObjArray.h:166
virtual const char * GetName() const
Returns name of object.
Definition TObject.cxx:359
Wrapper for PCRE library (Perl Compatible Regular Expressions).
Definition TPRegexp.h:97
virtual Int_t Size() const
virtual void SetName(const char *name)
Change (i.e.
void StartEmbedding(Int_t pos=kRight, Int_t subpos=-1) override
Start embedding external frame in the tab "pos" and tab element "subpos".
TGTab * GetTabRight() const
Basic string class.
Definition TString.h:136
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:2331
virtual const char * Getenv(const char *env)
Get environment variable.
Definition TSystem.cxx:1661
virtual void Exit(int code, Bool_t mode=kTRUE)
Exit the application.
Definition TSystem.cxx:717
virtual Long64_t GetEntries() const
Definition TTree.h:460
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:5618
const Int_t n
Definition legend1.C:16