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#include <TEveManager.h>
23#include <TEveEventManager.h>
24#include <TEveVSD.h>
25#include <TEveVSDStructs.h>
26
27#include <TEveTrack.h>
28#include <TEveTrackPropagator.h>
29#include <TEveGeoShape.h>
30
31#include <TGTab.h>
32#include <TGButton.h>
33
34#include <TFile.h>
35#include <TKey.h>
36#include <TSystem.h>
37#include <TPRegexp.h>
38
39// Include components -- compile time link :)
40
41#include "MultiView.C"
42MultiView *gMultiView = nullptr;
43
44class TVSDReader {
45public:
46 // ----------------------------------------------------------
47 // File / Event Data
48 // ----------------------------------------------------------
49
50 TFile *fFile;
51 TDirectory *fDirectory;
52
53 TObjArray *fEvDirKeys;
54
55 TEveVSD *fVSD;
56
57 Int_t fMaxEv, fCurEv;
58
59 // ----------------------------------------------------------
60 // Event visualization structures
61 // ----------------------------------------------------------
62
63 TEveTrackList *fTrackList;
64 TEvePointSet *fITSClusters;
65 TEvePointSet *fTPCClusters;
66 TEvePointSet *fTRDClusters;
67 TEvePointSet *fTOFClusters;
68
69public:
70 TVSDReader(const char *file_name)
71 : fFile(nullptr),
72 fDirectory(nullptr),
73 fEvDirKeys(nullptr),
74 fVSD(nullptr),
75
76 fMaxEv(-1),
77 fCurEv(-1),
78
79 fTrackList(nullptr),
80 fITSClusters(nullptr),
81 fTPCClusters(nullptr),
82 fTRDClusters(nullptr),
83 fTOFClusters(nullptr)
84 {
85 fFile = TFile::Open(file_name);
86 if (!fFile) {
87 Error("VSD_Reader", "Can not open file '%s' ... terminating.", 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 fEvDirKeys->Add(lnk->GetObject());
97 }
98 lnk = lnk->Next();
99 }
100
101 fMaxEv = fEvDirKeys->GetEntriesFast();
102 if (fMaxEv == 0) {
103 Error("VSD_Reader", "No events to show ... terminating.");
104 gSystem->Exit(1);
105 }
106
107 fVSD = new TEveVSD;
108 }
109
110 virtual ~TVSDReader()
111 {
112 // Destructor.
113
114 DropEvent();
115
116 delete fVSD;
117 delete fEvDirKeys;
118
119 fFile->Close();
120 delete fFile;
121 }
122
123 void AttachEvent()
124 {
125 // Attach event data from current directory.
126
127 fVSD->LoadTrees();
128 fVSD->SetBranchAddresses();
129 }
130
131 void DropEvent()
132 {
133 // Drup currently held event data, release current directory.
134
135 // Drop old visualization structures.
136
137 gEve->GetViewers()->DeleteAnnotations();
138 gEve->GetCurrentEvent()->DestroyElements();
139
140 // Drop old event-data.
141
142 fVSD->DeleteTrees();
143 delete fDirectory;
144 fDirectory = nullptr;
145 }
146
147 //---------------------------------------------------------------------------
148 // Event navigation
149 //---------------------------------------------------------------------------
150
151 void NextEvent() { GotoEvent(fCurEv + 1); }
152
153 void PrevEvent() { GotoEvent(fCurEv - 1); }
154
155 Bool_t GotoEvent(Int_t ev)
156 {
157 if (ev < 0 || ev >= fMaxEv) {
158 Warning("GotoEvent", "Invalid event id %d.", ev);
159 return kFALSE;
160 }
161
162 DropEvent();
163
164 // Connect to new event-data.
165
166 fCurEv = ev;
167 fDirectory = (TDirectory *)((TKey *)fEvDirKeys->At(fCurEv))->ReadObj();
168 fVSD->SetDirectory(fDirectory);
169
170 AttachEvent();
171
172 // Load event data into visualization structures.
173
174 LoadClusters(fITSClusters, "ITS", 0);
175 LoadClusters(fTPCClusters, "TPC", 1);
176 LoadClusters(fTRDClusters, "TRD", 2);
177 LoadClusters(fTOFClusters, "TOF", 3);
178
179 LoadEsdTracks();
180
181 // Fill projected views.
182
183 auto top = gEve->GetCurrentEvent();
184
185 gMultiView->DestroyEventRPhi();
186 gMultiView->ImportEventRPhi(top);
187
188 gMultiView->DestroyEventRhoZ();
189 gMultiView->ImportEventRhoZ(top);
190
191 gEve->Redraw3D(kFALSE, kTRUE);
192
193 return kTRUE;
194 }
195
196 //---------------------------------------------------------------------------
197 // Cluster loading
198 //---------------------------------------------------------------------------
199
200 void LoadClusters(TEvePointSet *&ps, const TString &det_name, Int_t det_id)
201 {
202 if (ps == nullptr) {
203 ps = new TEvePointSet(det_name);
204 ps->SetMainColor((Color_t)(det_id + 2));
205 ps->SetMarkerSize(0.5);
206 ps->SetMarkerStyle(2);
207 ps->IncDenyDestroy();
208 } else {
209 ps->Reset();
210 }
211
212 TEvePointSelector ss(fVSD->fTreeC, ps, "fV.fX:fV.fY:fV.fZ", TString::Format("fDetId==%d", det_id));
213 ss.Select();
214 ps->SetTitle(TString::Format("N=%d", ps->Size()));
215
216 gEve->AddElement(ps);
217 }
218
219 //---------------------------------------------------------------------------
220 // Track loading
221 //---------------------------------------------------------------------------
222
223 enum ESDTrackFlags {
224 kITSin = 0x0001,
225 kITSout = 0x0002,
226 kITSrefit = 0x0004,
227 kITSpid = 0x0008,
228 kTPCin = 0x0010,
229 kTPCout = 0x0020,
230 kTPCrefit = 0x0040,
231 kTPCpid = 0x0080,
232 kTRDin = 0x0100,
233 kTRDout = 0x0200,
234 kTRDrefit = 0x0400,
235 kTRDpid = 0x0800,
236 kTOFin = 0x1000,
237 kTOFout = 0x2000,
238 kTOFrefit = 0x4000,
239 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 == nullptr) {
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 = nullptr;
297
298// Forward declaration.
299void make_gui();
300
301//______________________________________________________________________________
302void alice_vsd(const char *vsd_file_name = "http://mtadel.home.cern.ch/mtadel/root/AliVSD.root")
303{
304 // Main function, initializes the application.
305 //
306 // 1. Load the auto-generated library holding ESD classes and
307 // ESD dictionaries.
308 // 2. Open ESD data-files.
309 // 3. Load cartoon geometry.
310 // 4. Spawn simple GUI.
311 // 5. Load first event.
312
314
316
317 gVSDReader = new TVSDReader(vsd_file_name);
318
320
321 TEveGeoShape *gentle_geom = nullptr;
322
323 { // Simple geometry
324 auto geom = TFile::Open("http://mtadel.home.cern.ch/mtadel/root/alice_mini_geom.root", "CACHEREAD");
325 if (!geom)
326 return;
327 auto gse = (TEveGeoShapeExtract *)geom->Get("Gentle");
328 gentle_geom = TEveGeoShape::ImportShapeExtract(gse, nullptr);
329 geom->Close();
330 delete geom;
331 gEve->AddGlobalElement(gentle_geom);
332 }
333
334 // Standard multi-view
335 //=====================
336
337 gMultiView = new MultiView;
338 gMultiView->f3DView->GetGLViewer()->SetStyle(TGLRnrCtx::kOutline);
339
340 gMultiView->SetDepth(-10);
341 gMultiView->ImportGeomRPhi(gentle_geom);
342 gMultiView->ImportGeomRhoZ(gentle_geom);
343 gMultiView->SetDepth(0);
344
345 // Final stuff
346 //=============
347
348 gEve->GetViewers()->SwitchColorSet();
349 gEve->GetDefaultGLViewer()->SetStyle(TGLRnrCtx::kOutline);
350
351 gEve->GetBrowser()->GetTabRight()->SetTab(1);
352
353 make_gui();
354
355 gEve->AddEvent(new TEveEventManager("Event", "ALICE VSD Event"));
356
357 gVSDReader->GotoEvent(0);
358
359 gEve->Redraw3D(kTRUE); // Reset camera after the first event has been shown.
360}
361
362//______________________________________________________________________________
363void make_gui()
364{
365 // Create minimal GUI for event navigation.
366
367 auto browser = gEve->GetBrowser();
368 browser->StartEmbedding(TRootBrowser::kLeft);
369
370 auto frmMain = new TGMainFrame(gClient->GetRoot(), 1000, 600);
371 frmMain->SetWindowName("XX GUI");
372 frmMain->SetCleanup(kDeepCleanup);
373
374 auto hf = new TGHorizontalFrame(frmMain);
375 {
376 TString icondir(TString::Format("%s/icons/", gSystem->Getenv("ROOTSYS")));
377 TGPictureButton *b = nullptr;
378
379 b = new TGPictureButton(hf, gClient->GetPicture(icondir + "GoBack.gif"));
380 hf->AddFrame(b);
381 b->Connect("Clicked()", "TVSDReader", gVSDReader, "PrevEvent()");
382
383 b = new TGPictureButton(hf, gClient->GetPicture(icondir + "GoForward.gif"));
384 hf->AddFrame(b);
385 b->Connect("Clicked()", "TVSDReader", gVSDReader, "NextEvent()");
386 }
387 frmMain->AddFrame(hf);
388
389 frmMain->MapSubwindows();
390 frmMain->Resize();
391 frmMain->MapWindow();
392
393 browser->StopEmbedding();
394 browser->SetTabTitle("Event Control", 0);
395}
Multi-view (3d, rphi, rhoz) service class using EVE Window Manager.
#define b(i)
Definition RSha256.hxx:100
int Int_t
Signed integer 4 bytes (int).
Definition RtypesCore.h:59
bool Bool_t
Boolean (0=false, 1=true) (bool).
Definition RtypesCore.h:77
constexpr Bool_t kFALSE
Definition RtypesCore.h:108
short Color_t
Color number (short).
Definition RtypesCore.h:99
constexpr Bool_t kTRUE
Definition RtypesCore.h:107
#define ClassDef(name, id)
Definition Rtypes.h:344
@ kYellow
Definition Rtypes.h:67
Error("WriteTObject","The current directory (%s) is not associated with a file. The object (%s) has not been written.", GetName(), objname)
void Warning(const char *location, const char *msgfmt,...)
Use this function in warning situations.
Definition TError.cxx:252
externTEveManager * gEve
#define gClient
Definition TGClient.h:157
@ kDeepCleanup
Definition TGFrame.h:42
char * Form(const char *fmt,...)
Formats a string in a circular formatting buffer.
Definition TString.cxx:2496
externTSystem * gSystem
Definition TSystem.h:582
TList * GetListOfKeys() const override
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=nullptr)
Import a shape extract 'gse' under element 'parent'.
static TEveManager * Create(Bool_t map_window=kTRUE, Option_t *opt="FIV")
If global TEveManager* gEve is not set initialize it.
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.
void SetMarkerStyle(Style_t mstyle=1) override
Set marker style, propagate to projecteds.
void SetMarkerSize(Size_t msize=1) override
Set marker size, propagate to projecteds.
void SetMarkerStyle(Style_t s) override
Set marker style for the list and the elements.
void SetMarkerColor(Color_t c) override
Set marker color for the list and the elements.
void SetMainColor(Color_t c) override
Set main (line) color for the list and the elements.
void SetMarkerSize(Size_t s) override
Set marker size for the list and the elements.
void MakeTracks(Bool_t recurse=kTRUE)
Regenerate the visual representations of tracks.
TEveTrackPropagator * GetPropagator()
Definition TEveTrack.h:175
void SetMagField(Double_t bX, Double_t bY, Double_t bZ)
Set constant magnetic field and rebuild tracks.
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.
static void DisableTObjectStreamersForVSDStruct()
Disable TObject streamers for those VSD structs that inherit from TObject directly.
Definition TEveVSD.cxx:202
TEveRecTrack fR
Definition TEveVSD.h:44
virtual void SetBranchAddresses()
Set branche addresses of internal trees.
Definition TEveVSD.cxx:120
virtual void DeleteTrees()
Delete internal trees.
Definition TEveVSD.cxx:86
virtual void SetDirectory(TDirectory *dir)
Set directory in which the trees are (or will be) created.
Definition TEveVSD.cxx:62
TTree * fTreeC
! Clusters.
Definition TEveVSD.h:34
virtual void LoadTrees()
Load internal trees from directory.
Definition TEveVSD.cxx:147
TTree * fTreeR
! Reconstructed tracks.
Definition TEveVSD.h:35
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:3787
static Bool_t SetCacheFileDir(std::string_view cacheDir, Bool_t operateDisconnected=kTRUE, Bool_t forceCacheread=kFALSE)
Sets the directory where to locally stage/cache remote files.
Definition TFile.cxx:4328
void Close(Option_t *option="") override
Close a file.
Definition TFile.cxx:981
A composite frame that layout their children in horizontal way.
Definition TGFrame.h:387
Defines top level windows that interact with the system Window Manager.
Definition TGFrame.h:399
Yield an action as soon as it is clicked.
Definition TGButton.h:228
virtual TObjLink * FirstLink() const
Definition TList.h:107
Int_t GetEntriesFast() const
Definition TObjArray.h:58
TObject * At(Int_t idx) const override
Definition TObjArray.h:170
void Add(TObject *obj) override
Definition TObjArray.h:68
virtual const char * GetName() const
Returns name of object.
Definition TObject.cxx:462
virtual Int_t Size() const
virtual void SetName(const char *name)
Change (i.e.
Basic string class.
Definition TString.h:138
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:2385
virtual Int_t GetEntry(Long64_t entry, Int_t getall=0)
Read all branches of entry and return total number of bytes read.
Definition TTree.cxx:5718
virtual Long64_t GetEntries() const
Definition TTree.h:510
const Int_t n
Definition legend1.C:16