Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
run_alice_esd.C
Go to the documentation of this file.
1/// \file
2/// \ingroup tutorial_eve
3/// Complex example showing ALICE ESD track visualization.
4///
5/// alice_esd.C - a simple event-display for ALICE ESD tracks and clusters
6///
7///
8/// Only standard ROOT is used to process the ALICE ESD files.
9///
10/// No ALICE code is needed, only four simple coordinate-transformation
11/// functions declared in this macro.
12///
13/// A simple geometry of 10KB, extracted from the full TGeo-geometry, is
14/// used to outline the central detectors of ALICE.
15///
16/// All files are access from the web by using the "CACHEREAD" option.
17///
18///
19/// ### Automatic building of ALICE ESD class declarations and dictionaries.
20///
21/// ALICE ESD is a TTree containing tracks and other event-related
22/// information with one entry per event. All these classes are part of
23/// the AliROOT offline framework and are not available to standard
24/// ROOT.
25///
26/// To be able to access the event data in a natural way, by using
27/// data-members of classes and object containers, the header files and
28/// class dictionaries are automatically generated from the
29/// TStreamerInfo classes stored in the ESD file by using the
30/// TFile::MakeProject() function. The header files and a shared library
31/// is created in the aliesd/ directory and can be loaded dynamically
32/// into the ROOT session.
33///
34/// See the run_alice_esd.C macro.
35///
36///
37/// ### Creation of simple GUI for event navigation.
38///
39/// Most common use of the event-display is to browse through a
40/// collection of events. Thus a simple GUI allowing this is created in
41/// the function make_gui().
42///
43/// Eve uses the configurable ROOT-browser as its main window and so we
44/// create an extra tab in the left working area of the browser and
45/// provide backward/forward buttons.
46///
47///
48/// ### Event-navigation functions.
49///
50/// As this is a simple macro, we store the information about the
51/// current event in the global variable 'Int_t esd_event_id'. The
52/// functions for event-navigation simply modify this variable and call
53/// the load_event() function which does the following:
54/// 1. drop the old visualization objects;
55/// 2. retrieve given event from the ESD tree;
56/// 3. call alice_esd_read() function to create visualization objects
57/// for the new event.
58///
59///
60/// ### Reading of ALICE data and creation of visualization objects.
61///
62/// This is performed in alice_esd_read() function, with the following
63/// steps:
64/// 1. create the track container object - TEveTrackList;
65/// 2. iterate over the ESD tracks, create TEveTrack objects and append
66/// them to the container;
67/// 3. instruct the container to extrapolate the tracks and set their
68/// visual attributes.
69///
70/// \image html eve_alice_esd.png
71/// \macro_code
72///
73/// \author Matevz Tadel
74
75#include "MultiView.C"
77
78// Forward declarations.
79
80#include "aliesd/AliESDEvent.h"
81#include "aliesd/AliESDfriend.h"
82#include "aliesd/AliESDtrack.h"
83#include "aliesd/AliESDRun.h"
84
86
87void make_gui();
88void load_event();
89
90void alice_esd_read();
96
97// Configuration and global variables.
98
99const char *esd_file_name = "http://root.cern.ch/files/alice_ESDs.root";
100// Temporarily disable reading of ESD friend.
101// There seems to be no way to get it working without AliRoot.
102// const char* esd_friends_file_name =
103// "http://root.cern.ch/files/alice_ESDfriends.root";
104const char *esd_friends_file_name = nullptr;
105
106const char *esd_geom_file_name = "http://root.cern.ch/files/alice_ESDgeometry.root";
107
108// For testing
109// const char* esd_file_name = "AliESDs.root";
110// const char* esd_friends_file_name = "AliESDfriends.root";
111
112TFile *esd_file = nullptr;
113TFile *esd_friends_file = nullptr;
114
115TTree *esd_tree = nullptr;
116
117AliESDEvent *esd = nullptr;
118TList *esd_objs = nullptr;
119AliESDfriend *esd_friend = nullptr;
120
121Int_t esd_event_id = 0; // Current event id.
122
123TEveTrackList *gTrackList = nullptr;
124
125TEveGeoShape *gGeomGentle = nullptr;
126
127// Implemented in MultiView.C
128MultiView *gMultiView = nullptr;
129
130/******************************************************************************/
131// Initialization and steering functions
132/******************************************************************************/
133
134//______________________________________________________________________________
135void run_alice_esd()
136{
137 // Main function, initializes the application.
138 //
139 // 1. Load the auto-generated library holding ESD classes and
140 // ESD dictionaries.
141 // 2. Open ESD data-files.
142 // 3. Load cartoon geometry.
143 // 4. Spawn simple GUI.
144 // 5. Load first event.
145
146 const TString weh("alice_esd()");
147
149
150 printf("*** Opening ESD ***\n");
151 esd_file = TFile::Open(esd_file_name, "CACHEREAD");
152 if (!esd_file)
153 return;
154
155 esd_tree = (TTree *)esd_file->Get("esdTree");
156 esd = (AliESDEvent *)esd_tree->GetUserInfo()->FindObject("AliESDEvent");
157 esd_objs = esd->fESDObjects;
158
159 if (esd_friends_file_name != 0) {
160 printf("*** Opening ESD-friends ***\n");
162 if (!esd_friends_file)
163 return;
164
165 esd_tree->SetBranchStatus("ESDfriend*", 1);
166 }
167
168 // Set the branch addresses.
169 {
170 TIter next(esd_objs);
171 TObject *el;
172 while ((el = (TNamed *)next())) {
173 TString bname(el->GetName());
174 if (bname == "AliESDfriend") {
175 // AliESDfriend needs special treatment.
176 TBranch *br = esd_tree->GetBranch("ESDfriend.");
177 br->SetAddress(esd_objs->GetObjectRef(el));
178 } else {
179 TBranch *br = esd_tree->GetBranch(bname);
180 if (br) {
181 br->SetAddress(esd_objs->GetObjectRef(el));
182 } else {
183 br = esd_tree->GetBranch(bname + ".");
184 if (br) {
185 br->SetAddress(esd_objs->GetObjectRef(el));
186 } else {
187 Warning("AliESDEvent::ReadFromTree() "
188 "No Branch found with Name '%s' or '%s.'.",
189 bname.Data(), bname.Data());
190 }
191 }
192 }
193 }
194 }
195
197
198 { // Simple geometry
199 TFile *geom = TFile::Open(esd_geom_file_name, "CACHEREAD");
200 if (!geom)
201 return;
202 TEveGeoShapeExtract *gse = (TEveGeoShapeExtract *)geom->Get("Gentle");
204 geom->Close();
205 delete geom;
207 }
208
209 // Standard multi-view
210 //=====================
211
212 gMultiView = new MultiView;
213
214 gMultiView->ImportGeomRPhi(gGeomGentle);
215 gMultiView->ImportGeomRhoZ(gGeomGentle);
216
217 // HTML summary view
218 //===================
219
220 fgHtmlSummary = new HtmlSummary("Alice Event Display Summary Table");
222 fgHtml = new TGHtml(0, 100, 100);
223 TEveWindowFrame *wf = slot->MakeFrame(fgHtml);
224 fgHtml->MapSubwindows();
225 wf->SetElementName("Summary");
226
227 // Final stuff
228 //=============
229
231
232 make_gui();
233
234 load_event();
235
236 gEve->Redraw3D(kTRUE); // Reset camera after the first event has been shown.
237}
238
239//______________________________________________________________________________
240void load_event()
241{
242 // Load event specified in global esd_event_id.
243 // The contents of previous event are removed.
244
245 printf("Loading event %d.\n", esd_event_id);
246
248
249 if (gTrackList)
250 gTrackList->DestroyElements();
251
252 esd_tree->GetEntry(esd_event_id);
253 // esd_tree->Show();
254
256
258
259 gMultiView->DestroyEventRPhi();
260 gMultiView->ImportEventRPhi(top);
261
262 gMultiView->DestroyEventRhoZ();
263 gMultiView->ImportEventRhoZ(top);
264
266
268}
269
270/******************************************************************************/
271// GUI
272/******************************************************************************/
273
274//______________________________________________________________________________
275//
276// EvNavHandler class is needed to connect GUI signals.
277
278class EvNavHandler {
279public:
280 void Fwd()
281 {
282 if (esd_event_id < esd_tree->GetEntries() - 1) {
283 ++esd_event_id;
284 load_event();
285 } else {
286 printf("Already at last event.\n");
287 }
288 }
289 void Bck()
290 {
291 if (esd_event_id > 0) {
292 --esd_event_id;
293 load_event();
294 } else {
295 printf("Already at first event.\n");
296 }
297 }
298};
299
300//______________________________________________________________________________
301void make_gui()
302{
303 // Create minimal GUI for event navigation.
304
306 browser->StartEmbedding(TRootBrowser::kLeft);
307
308 TGMainFrame *frmMain = new TGMainFrame(gClient->GetRoot(), 1000, 600);
309 frmMain->SetWindowName("XX GUI");
310 frmMain->SetCleanup(kDeepCleanup);
311
313 {
314
315 TString icondir(Form("%s/icons/", gSystem->Getenv("ROOTSYS")));
316 TGPictureButton *b = 0;
317 EvNavHandler *fh = new EvNavHandler;
318
319 b = new TGPictureButton(hf, gClient->GetPicture(icondir + "GoBack.gif"));
320 hf->AddFrame(b);
321 b->Connect("Clicked()", "EvNavHandler", fh, "Bck()");
322
323 b = new TGPictureButton(hf, gClient->GetPicture(icondir + "GoForward.gif"));
324 hf->AddFrame(b);
325 b->Connect("Clicked()", "EvNavHandler", fh, "Fwd()");
326 }
327 frmMain->AddFrame(hf);
328
329 frmMain->MapSubwindows();
330 frmMain->Resize();
331 frmMain->MapWindow();
332
333 browser->StopEmbedding();
334 browser->SetTabTitle("Event Control", 0);
335}
336
337/******************************************************************************/
338// Code for reading AliESD and creating visualization objects
339/******************************************************************************/
340
341enum ESDTrackFlags {
342 kITSin = 0x0001,
343 kITSout = 0x0002,
344 kITSrefit = 0x0004,
345 kITSpid = 0x0008,
346 kTPCin = 0x0010,
347 kTPCout = 0x0020,
348 kTPCrefit = 0x0040,
349 kTPCpid = 0x0080,
350 kTRDin = 0x0100,
351 kTRDout = 0x0200,
352 kTRDrefit = 0x0400,
353 kTRDpid = 0x0800,
354 kTOFin = 0x1000,
355 kTOFout = 0x2000,
356 kTOFrefit = 0x4000,
357 kTOFpid = 0x8000,
358 kHMPIDpid = 0x20000,
359 kEMCALmatch = 0x40000,
360 kTRDbackup = 0x80000,
361 kTRDStop = 0x20000000,
362 kESDpid = 0x40000000,
363 kTIME = 0x80000000
364};
365
366//______________________________________________________________________________
367void alice_esd_read()
368{
369 // Read tracks and associated clusters from current event.
370
371 AliESDRun *esdrun = (AliESDRun *)esd_objs->FindObject("AliESDRun");
372 TClonesArray *tracks = (TClonesArray *)esd_objs->FindObject("Tracks");
373
374 // This needs further investigation. Clusters not shown.
375 // esd_friend = (AliESDfriend*) esd_objs->FindObject("AliESDfriend");
376 // printf("Friend %p, n_tracks:%d\n",
377 // esd_friend,
378 // esd_friend->fTracks.GetEntries());
379
380 if (gTrackList == 0) {
381 gTrackList = new TEveTrackList("ESD Tracks");
382 gTrackList->SetMainColor(6);
383 gTrackList->SetMarkerColor(kYellow);
384 gTrackList->SetMarkerStyle(4);
385 gTrackList->SetMarkerSize(0.5);
386
388 }
389
390 TEveTrackPropagator *trkProp = gTrackList->GetPropagator();
391 trkProp->SetMagField(0.1 * esdrun->fMagneticField); // kGaus to Tesla
392
393 for (Int_t n = 0; n < tracks->GetEntriesFast(); ++n) {
394 AliESDtrack *at = (AliESDtrack *)tracks->At(n);
395
396 // If ITS refit failed, take track parameters at inner TPC radius.
398 if (!trackIsOn(at, kITSrefit)) {
399 tp = at->fIp;
400 }
401
403 track->SetAttLineAttMarker(gTrackList);
404 gTrackList->AddElement(track);
405
406 // This needs further investigation. Clusters not shown.
407 // if (frnd)
408 // {
409 // AliESDfriendTrack* ft = (AliESDfriendTrack*) frnd->fTracks->At(n);
410 // printf("%d friend = %p\n", ft);
411 // }
412 }
413
414 gTrackList->MakeTracks();
415}
416
417//______________________________________________________________________________
419{
420 // Helper function creating TEveTrack from AliESDtrack.
421 //
422 // Optionally specific track-parameters (e.g. at TPC entry point)
423 // can be specified via the tp argument.
424
425 Double_t pbuf[3], vbuf[3];
427
428 if (tp == 0)
429 tp = at;
430
431 rt.fLabel = at->fLabel;
432 rt.fIndex = index;
433 rt.fStatus = (Int_t)at->fFlags;
434 rt.fSign = (tp->fP[4] > 0) ? 1 : -1;
435
437 rt.fV.Set(vbuf);
439 rt.fP.Set(pbuf);
440
441 Double_t ep = trackGetP(at);
442 Double_t mc = 0.138; // at->GetMass(); - Complicated function, requiring PID.
443
444 rt.fBeta = ep / TMath::Sqrt(ep * ep + mc * mc);
445
447 track->SetName(Form("TEveTrack %d", rt.fIndex));
448 track->SetStdTitle();
449
450 return track;
451}
452
453//______________________________________________________________________________
455{
456 // Check is track-flag specified by mask are set.
457
458 return (t->fFlags & mask) > 0;
459}
460
461//______________________________________________________________________________
463{
464 // Get global position of starting point of tp.
465
466 r[0] = tp->fX;
467 r[1] = tp->fP[0];
468 r[2] = tp->fP[1];
469
470 Double_t cs = TMath::Cos(tp->fAlpha), sn = TMath::Sin(tp->fAlpha), x = r[0];
471 r[0] = x * cs - r[1] * sn;
472 r[1] = x * sn + r[1] * cs;
473}
474
475//______________________________________________________________________________
477{
478 // Return global momentum vector of starting point of tp.
479
480 p[0] = tp->fP[4];
481 p[1] = tp->fP[2];
482 p[2] = tp->fP[3];
483
484 Double_t pt = 1. / TMath::Abs(p[0]);
485 Double_t cs = TMath::Cos(tp->fAlpha), sn = TMath::Sin(tp->fAlpha);
486 Double_t r = TMath::Sqrt(1 - p[1] * p[1]);
487 p[0] = pt * (r * cs - p[1] * sn);
488 p[1] = pt * (p[1] * cs + r * sn);
489 p[2] = pt * p[2];
490}
491
492//______________________________________________________________________________
494{
495 // Return magnitude of momentum of tp.
496
497 return TMath::Sqrt(1. + tp->fP[3] * tp->fP[3]) / TMath::Abs(tp->fP[4]);
498}
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
constexpr Bool_t kFALSE
Definition RtypesCore.h:94
double Double_t
Definition RtypesCore.h:59
constexpr Bool_t kTRUE
Definition RtypesCore.h:93
@ 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 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
winID h TVirtualViewer3D TVirtualGLPainter p
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
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 r
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t index
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
Html table and event summary for alice_esd.C.
A TTree is a list of TBranches.
Definition TBranch.h:93
An array of clone (identical) objects.
Specialization of TRootBrowser for Eve.
Base class for TEveUtil visualization elements, providing hierarchy management, rendering control and...
Definition TEveElement.h:36
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
TEveBrowser * GetBrowser() const
static TEveManager * Create(Bool_t map_window=kTRUE, Option_t *opt="FIV")
If global TEveManager* gEve is not set initialize it.
void Redraw3D(Bool_t resetCameras=kFALSE, Bool_t dropLogicals=kFALSE)
TEveEventManager * GetCurrentEvent() const
A list of tracks supporting change of common attributes and selection based on track parameters.
Definition TEveTrack.h:140
Holding structure for a number of track rendering parameters.
Visual representation of a track.
Definition TEveTrack.h:33
void DeleteAnnotations()
Delete annotations from all viewers.
Encapsulates TGFrame into an eve-window.
Definition TEveWindow.h:336
static TEveWindowSlot * CreateWindowInTab(TGTab *tab, TEveWindow *eve_parent=nullptr)
Create a new tab in a given tab-widget and populate it with a default window-slot.
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
A composite frame that layout their children in horizontal way.
Definition TGFrame.h:387
The ROOT HTML widget.
Definition TGHtml.h:873
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
A doubly linked list.
Definition TList.h:38
The TNamed class is the base class for all named ROOT classes.
Definition TNamed.h:29
Mother of all ROOT objects.
Definition TObject.h:41
TGTab * GetTabRight() const
Basic string class.
Definition TString.h:139
virtual const char * Getenv(const char *env)
Get environment variable.
Definition TSystem.cxx:1677
A TTree represents a columnar dataset.
Definition TTree.h:84
TPaveText * pt
Double_t x[n]
Definition legend1.C:17
const Int_t n
Definition legend1.C:16
Double_t Sqrt(Double_t x)
Returns the square root of x.
Definition TMath.h:666
Double_t Cos(Double_t)
Returns the cosine of an angle of x radians.
Definition TMath.h:598
Double_t Sin(Double_t)
Returns the sine of an angle of x radians.
Definition TMath.h:592
Short_t Abs(Short_t d)
Returns the absolute value of parameter Short_t d.
Definition TMathBase.h:123
void tracks()
Definition tracks.C:48