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
54
56
58
59 // ----------------------------------------------------------
60 // Event visualization structures
61 // ----------------------------------------------------------
62
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
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
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
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
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
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);
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
291 }
292
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
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");
329 geom->Close();
330 delete 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
350
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
bool Bool_t
Definition RtypesCore.h:63
int Int_t
Definition RtypesCore.h:45
short Color_t
Definition RtypesCore.h:85
constexpr Bool_t kFALSE
Definition RtypesCore.h:94
constexpr Bool_t kTRUE
Definition RtypesCore.h:93
#define ClassDef(name, id)
Definition Rtypes.h:342
@ kYellow
Definition Rtypes.h:66
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
void Error(const char *location, const char *msgfmt,...)
Use this function in case an error occurred.
Definition TError.cxx:185
void Warning(const char *location, const char *msgfmt,...)
Use this function in warning situations.
Definition TError.cxx:229
R__EXTERN TEveManager * gEve
#define gClient
Definition TGClient.h:157
@ kDeepCleanup
Definition TGFrame.h:42
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t mask
char * Form(const char *fmt,...)
Formats a string in a circular formatting buffer.
Definition TString.cxx:2489
R__EXTERN TSystem * gSystem
Definition TSystem.h:572
TList * GetListOfKeys() const override
Describe directory structure in memory.
Definition TDirectory.h:45
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'.
void AddElement(TEveElement *element, TEveElement *parent=nullptr)
Add an element.
void AddGlobalElement(TEveElement *element, TEveElement *parent=nullptr)
Add a global element, i.e.
TEveViewerList * GetViewers() const
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 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.
A list of tracks supporting change of common attributes and selection based on track parameters.
Definition TEveTrack.h:140
Visual representation of a track.
Definition TEveTrack.h:33
Int_t GetStatus() const
Definition TEveTrack.h:104
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
void SwitchColorSet()
Switch background color.
void DeleteAnnotations()
Delete annotations from all viewers.
A ROOT file is an on-disk file, usually with extension .root, that stores objects in a file-system-li...
Definition TFile.h:131
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:4131
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:4674
void Close(Option_t *option="") override
Close a file.
Definition TFile.cxx:955
A composite frame that layout their children in horizontal way.
Definition TGFrame.h:387
void SetStyle(Short_t st)
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 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:558
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:102
An array of TObjects.
Definition TObjArray.h:31
Wrapper for PCRE library (Perl Compatible Regular Expressions).
Definition TPRegexp.h:97
virtual Int_t Size() const
TGTab * GetTabRight() const
Basic string class.
Definition TString.h:139
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:2378
virtual const char * Getenv(const char *env)
Get environment variable.
Definition TSystem.cxx:1677
virtual void Exit(int code, Bool_t mode=kTRUE)
Exit the application.
Definition TSystem.cxx:727
const Int_t n
Definition legend1.C:16