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
85class AliExternalTrackParam;
86
87void make_gui();
88void load_event();
89
90void alice_esd_read();
91TEveTrack* esd_make_track(TEveTrackPropagator* trkProp, Int_t index,
92 AliESDtrack* at,
93 AliExternalTrackParam* tp=0);
94Bool_t trackIsOn(AliESDtrack* t, Int_t mask);
95void trackGetPos(AliExternalTrackParam* tp, Double_t r[3]);
96void trackGetMomentum(AliExternalTrackParam* tp, Double_t p[3]);
97Double_t trackGetP(AliExternalTrackParam* tp);
98
99
100// Configuration and global variables.
101
102const char* esd_file_name = "http://root.cern.ch/files/alice_ESDs.root";
103// Temporarily disable reading of ESD friend.
104// There seems to be no way to get it working without AliRoot.
105// const char* esd_friends_file_name =
106// "http://root.cern.ch/files/alice_ESDfriends.root";
107const char* esd_friends_file_name = nullptr;
108
109const char* esd_geom_file_name =
110 "http://root.cern.ch/files/alice_ESDgeometry.root";
111
112// For testing
113// const char* esd_file_name = "AliESDs.root";
114// const char* esd_friends_file_name = "AliESDfriends.root";
115
116TFile *esd_file = nullptr;
117TFile *esd_friends_file = nullptr;
118
119TTree *esd_tree = nullptr;
120
121AliESDEvent *esd = nullptr;
122TList *esd_objs = nullptr;
123AliESDfriend *esd_friend = nullptr;
124
125Int_t esd_event_id = 0; // Current event id.
126
127TEveTrackList *gTrackList = nullptr;
128
129TEveGeoShape *gGeomGentle = nullptr;
130
131// Implemented in MultiView.C
132MultiView *gMultiView = nullptr;
133
134/******************************************************************************/
135// Initialization and steering functions
136/******************************************************************************/
137
138//______________________________________________________________________________
139void run_alice_esd()
140{
141 // Main function, initializes the application.
142 //
143 // 1. Load the auto-generated library holding ESD classes and
144 // ESD dictionaries.
145 // 2. Open ESD data-files.
146 // 3. Load cartoon geometry.
147 // 4. Spawn simple GUI.
148 // 5. Load first event.
149
150 const TString weh("alice_esd()");
151
153
154 printf("*** Opening ESD ***\n");
155 esd_file = TFile::Open(esd_file_name, "CACHEREAD");
156 if (!esd_file)
157 return;
158
159 esd_tree = (TTree*) esd_file->Get("esdTree");
160 esd = (AliESDEvent*) esd_tree->GetUserInfo()->FindObject("AliESDEvent");
161 esd_objs = esd->fESDObjects;
162
163 if (esd_friends_file_name != 0)
164 {
165 printf("*** Opening ESD-friends ***\n");
166 esd_friends_file = TFile::Open(esd_friends_file_name, "CACHEREAD");
167 if (!esd_friends_file)
168 return;
169
170 esd_tree->SetBranchStatus ("ESDfriend*", 1);
171 }
172
173 // Set the branch addresses.
174 {
175 TIter next(esd_objs);
176 TObject *el;
177 while ((el = (TNamed*)next()))
178 {
179 TString bname(el->GetName());
180 if (bname == "AliESDfriend")
181 {
182 // AliESDfriend needs special treatment.
183 TBranch *br = esd_tree->GetBranch("ESDfriend.");
184 br->SetAddress(esd_objs->GetObjectRef(el));
185 }
186 else
187 {
188 TBranch *br = esd_tree->GetBranch(bname);
189 if (br)
190 {
191 br->SetAddress(esd_objs->GetObjectRef(el));
192 }
193 else
194 {
195 br = esd_tree->GetBranch(bname + ".");
196 if (br)
197 {
198 br->SetAddress(esd_objs->GetObjectRef(el));
199 }
200 else
201 {
202 Warning("AliESDEvent::ReadFromTree() "
203 "No Branch found with Name '%s' or '%s.'.",
204 bname.Data(),bname.Data());
205 }
206 }
207 }
208 }
209 }
210
211
213
214 { // Simple geometry
215 TFile* geom = TFile::Open(esd_geom_file_name, "CACHEREAD");
216 if (!geom)
217 return;
218 TEveGeoShapeExtract* gse = (TEveGeoShapeExtract*) geom->Get("Gentle");
219 gGeomGentle = TEveGeoShape::ImportShapeExtract(gse, 0);
220 geom->Close();
221 delete geom;
222 gEve->AddGlobalElement(gGeomGentle);
223 }
224
225
226 // Standard multi-view
227 //=====================
228
229 gMultiView = new MultiView;
230
231 gMultiView->ImportGeomRPhi(gGeomGentle);
232 gMultiView->ImportGeomRhoZ(gGeomGentle);
233
234
235 // HTML summary view
236 //===================
237
238 fgHtmlSummary = new HtmlSummary("Alice Event Display Summary Table");
240 fgHtml = new TGHtml(0, 100, 100);
241 TEveWindowFrame *wf = slot->MakeFrame(fgHtml);
242 fgHtml->MapSubwindows();
243 wf->SetElementName("Summary");
244
245
246 // Final stuff
247 //=============
248
250
251 make_gui();
252
253 load_event();
254
255 gEve->Redraw3D(kTRUE); // Reset camera after the first event has been shown.
256}
257
258//______________________________________________________________________________
259void load_event()
260{
261 // Load event specified in global esd_event_id.
262 // The contents of previous event are removed.
263
264 printf("Loading event %d.\n", esd_event_id);
265
267
268 if (gTrackList)
269 gTrackList->DestroyElements();
270
271 esd_tree->GetEntry(esd_event_id);
272 // esd_tree->Show();
273
274 alice_esd_read();
275
277
278 gMultiView->DestroyEventRPhi();
279 gMultiView->ImportEventRPhi(top);
280
281 gMultiView->DestroyEventRhoZ();
282 gMultiView->ImportEventRhoZ(top);
283
284 update_html_summary();
285
287}
288
289
290/******************************************************************************/
291// GUI
292/******************************************************************************/
293
294//______________________________________________________________________________
295//
296// EvNavHandler class is needed to connect GUI signals.
297
298class EvNavHandler
299{
300public:
301 void Fwd()
302 {
303 if (esd_event_id < esd_tree->GetEntries() - 1) {
304 ++esd_event_id;
305 load_event();
306 } else {
307 printf("Already at last event.\n");
308 }
309 }
310 void Bck()
311 {
312 if (esd_event_id > 0) {
313 --esd_event_id;
314 load_event();
315 } else {
316 printf("Already at first event.\n");
317 }
318 }
319};
320
321//______________________________________________________________________________
322void make_gui()
323{
324 // Create minimal GUI for event navigation.
325
326 TEveBrowser* browser = gEve->GetBrowser();
328
329 TGMainFrame* frmMain = new TGMainFrame(gClient->GetRoot(), 1000, 600);
330 frmMain->SetWindowName("XX GUI");
331 frmMain->SetCleanup(kDeepCleanup);
332
333 TGHorizontalFrame* hf = new TGHorizontalFrame(frmMain);
334 {
335
336 TString icondir( Form("%s/icons/", gSystem->Getenv("ROOTSYS")) );
337 TGPictureButton* b = 0;
338 EvNavHandler *fh = new EvNavHandler;
339
340 b = new TGPictureButton(hf, gClient->GetPicture(icondir+"GoBack.gif"));
341 hf->AddFrame(b);
342 b->Connect("Clicked()", "EvNavHandler", fh, "Bck()");
343
344 b = new TGPictureButton(hf, gClient->GetPicture(icondir+"GoForward.gif"));
345 hf->AddFrame(b);
346 b->Connect("Clicked()", "EvNavHandler", fh, "Fwd()");
347 }
348 frmMain->AddFrame(hf);
349
350 frmMain->MapSubwindows();
351 frmMain->Resize();
352 frmMain->MapWindow();
353
354 browser->StopEmbedding();
355 browser->SetTabTitle("Event Control", 0);
356}
357
358
359/******************************************************************************/
360// Code for reading AliESD and creating visualization objects
361/******************************************************************************/
362
363enum ESDTrackFlags {
364 kITSin=0x0001,kITSout=0x0002,kITSrefit=0x0004,kITSpid=0x0008,
365 kTPCin=0x0010,kTPCout=0x0020,kTPCrefit=0x0040,kTPCpid=0x0080,
366 kTRDin=0x0100,kTRDout=0x0200,kTRDrefit=0x0400,kTRDpid=0x0800,
367 kTOFin=0x1000,kTOFout=0x2000,kTOFrefit=0x4000,kTOFpid=0x8000,
368 kHMPIDpid=0x20000,
369 kEMCALmatch=0x40000,
370 kTRDbackup=0x80000,
371 kTRDStop=0x20000000,
372 kESDpid=0x40000000,
373 kTIME=0x80000000
374};
375
376//______________________________________________________________________________
377void alice_esd_read()
378{
379 // Read tracks and associated clusters from current event.
380
381 AliESDRun *esdrun = (AliESDRun*) esd_objs->FindObject("AliESDRun");
382 TClonesArray *tracks = (TClonesArray*) esd_objs->FindObject("Tracks");
383
384 // This needs further investigation. Clusters not shown.
385 // esd_friend = (AliESDfriend*) esd_objs->FindObject("AliESDfriend");
386 // printf("Friend %p, n_tracks:%d\n",
387 // esd_friend,
388 // esd_friend->fTracks.GetEntries());
389
390 if (gTrackList == 0)
391 {
392 gTrackList = new TEveTrackList("ESD Tracks");
393 gTrackList->SetMainColor(6);
394 gTrackList->SetMarkerColor(kYellow);
395 gTrackList->SetMarkerStyle(4);
396 gTrackList->SetMarkerSize(0.5);
397
398 gEve->AddElement(gTrackList);
399 }
400
401 TEveTrackPropagator* trkProp = gTrackList->GetPropagator();
402 trkProp->SetMagField( 0.1 * esdrun->fMagneticField ); // kGaus to Tesla
403
404 for (Int_t n=0; n<tracks->GetEntriesFast(); ++n)
405 {
406 AliESDtrack* at = (AliESDtrack*) tracks->At(n);
407
408 // If ITS refit failed, take track parameters at inner TPC radius.
409 AliExternalTrackParam* tp = at;
410 if (! trackIsOn(at, kITSrefit)) {
411 tp = at->fIp;
412 }
413
414 TEveTrack* track = esd_make_track(trkProp, n, at, tp);
415 track->SetAttLineAttMarker(gTrackList);
416 gTrackList->AddElement(track);
417
418 // This needs further investigation. Clusters not shown.
419 // if (frnd)
420 // {
421 // AliESDfriendTrack* ft = (AliESDfriendTrack*) frnd->fTracks->At(n);
422 // printf("%d friend = %p\n", ft);
423 // }
424 }
425
426 gTrackList->MakeTracks();
427}
428
429//______________________________________________________________________________
430TEveTrack* esd_make_track(TEveTrackPropagator* trkProp,
431 Int_t index,
432 AliESDtrack* at,
433 AliExternalTrackParam* tp)
434{
435 // Helper function creating TEveTrack from AliESDtrack.
436 //
437 // Optionally specific track-parameters (e.g. at TPC entry point)
438 // can be specified via the tp argument.
439
440 Double_t pbuf[3], vbuf[3];
441 TEveRecTrack rt;
442
443 if (tp == 0) tp = at;
444
445 rt.fLabel = at->fLabel;
446 rt.fIndex = index;
447 rt.fStatus = (Int_t) at->fFlags;
448 rt.fSign = (tp->fP[4] > 0) ? 1 : -1;
449
450 trackGetPos(tp, vbuf); rt.fV.Set(vbuf);
451 trackGetMomentum(tp, pbuf); rt.fP.Set(pbuf);
452
453 Double_t ep = trackGetP(at);
454 Double_t mc = 0.138; // at->GetMass(); - Complicated function, requiring PID.
455
456 rt.fBeta = ep/TMath::Sqrt(ep*ep + mc*mc);
457
458 TEveTrack* track = new TEveTrack(&rt, trkProp);
459 track->SetName(Form("TEveTrack %d", rt.fIndex));
460 track->SetStdTitle();
461
462 return track;
463}
464
465//______________________________________________________________________________
466Bool_t trackIsOn(AliESDtrack* t, Int_t mask)
467{
468 // Check is track-flag specified by mask are set.
469
470 return (t->fFlags & mask) > 0;
471}
472
473//______________________________________________________________________________
474void trackGetPos(AliExternalTrackParam* tp, Double_t r[3])
475{
476 // Get global position of starting point of tp.
477
478 r[0] = tp->fX; r[1] = tp->fP[0]; r[2] = tp->fP[1];
479
480 Double_t cs=TMath::Cos(tp->fAlpha), sn=TMath::Sin(tp->fAlpha), x=r[0];
481 r[0] = x*cs - r[1]*sn; r[1] = x*sn + r[1]*cs;
482}
483
484//______________________________________________________________________________
485void trackGetMomentum(AliExternalTrackParam* tp, Double_t p[3])
486{
487 // Return global momentum vector of starting point of tp.
488
489 p[0] = tp->fP[4]; p[1] = tp->fP[2]; p[2] = tp->fP[3];
490
491 Double_t pt=1./TMath::Abs(p[0]);
492 Double_t cs=TMath::Cos(tp->fAlpha), sn=TMath::Sin(tp->fAlpha);
493 Double_t r=TMath::Sqrt(1 - p[1]*p[1]);
494 p[0]=pt*(r*cs - p[1]*sn); p[1]=pt*(p[1]*cs + r*sn); p[2]=pt*p[2];
495}
496
497//______________________________________________________________________________
498Double_t trackGetP(AliExternalTrackParam* tp)
499{
500 // Return magnitude of momentum of tp.
501
502 return TMath::Sqrt(1.+ tp->fP[3]*tp->fP[3])/TMath::Abs(tp->fP[4]);
503}
Multi-view (3d, rphi, rhoz) service class using EVE Window Manager.
ROOT::R::TRInterface & r
Definition Object.C:4
#define b(i)
Definition RSha256.hxx:100
int Int_t
Definition RtypesCore.h:45
const Bool_t kFALSE
Definition RtypesCore.h:101
bool Bool_t
Definition RtypesCore.h:63
double Double_t
Definition RtypesCore.h:59
const Bool_t kTRUE
Definition RtypesCore.h:100
@ kYellow
Definition Rtypes.h:66
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:157
@ kDeepCleanup
Definition TGFrame.h:42
char * Form(const char *fmt,...)
R__EXTERN TSystem * gSystem
Definition TSystem.h:559
Html table and event summary for alice_esd.C.
A TTree is a list of TBranches.
Definition TBranch.h:89
virtual void SetAddress(void *add)
Set address of this branch.
Definition TBranch.cxx:2620
An array of clone (identical) objects.
TObject * Get(const char *namecycle) override
Return pointer to object identified by namecycle.
Specialization of TRootBrowser for Eve.
virtual void SetElementName(const char *name)
Virtual function for setting of name of an element.
Base class for TEveUtil visualization elements, providing hierarchy management, rendering control and...
Definition TEveElement.h:36
virtual void AddElement(TEveElement *el)
Add el to the list of children.
virtual void DestroyElements()
Destroy all children of this element.
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.
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
TEveVectorT< TT > fP
TEveVectorT< TT > fV
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.
Holding structure for a number of track rendering parameters.
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.
virtual void SetStdTitle()
Set standard track title based on most data-member values.
void Set(const Float_t *v)
Definition TEveVector.h:82
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=0)
Create a new tab in a given tab-widget and populate it with a default window-slot.
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:326
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:4025
void Close(Option_t *option="") override
Close a file.
Definition TFile.cxx:899
virtual void AddFrame(TGFrame *f, TGLayoutHints *l=0)
Add frame to the composite frame using the specified layout hints.
Definition TGFrame.cxx:1117
virtual void SetCleanup(Int_t mode=kLocalCleanup)
Turn on automatic cleanup of child frames in dtor.
Definition TGFrame.cxx:1072
virtual void MapSubwindows()
Map all sub windows that are part of the composite frame.
Definition TGFrame.cxx:1164
virtual void Resize(UInt_t w=0, UInt_t h=0)
Resize the frame.
Definition TGFrame.cxx:605
virtual void MapWindow()
map window
Definition TGFrame.h:204
A composite frame that layout their children in horizontal way.
Definition TGFrame.h:386
The ROOT HTML widget.
Definition TGHtml.h:873
Defines top level windows that interact with the system Window Manager.
Definition TGFrame.h:398
void SetWindowName(const char *name=0)
Set window name. This is typically done via the window manager.
Definition TGFrame.cxx:1788
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
virtual TObject ** GetObjectRef(const TObject *obj) const
Return address of pointer to obj.
Definition TList.cxx:671
virtual TObject * FindObject(const char *name) const
Find an object in this list using its name.
Definition TList.cxx:578
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
virtual const char * GetName() const
Returns name of object.
Definition TObject.cxx:429
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".
void SetTabTitle(const char *title, Int_t pos=kRight, Int_t subpos=-1)
Set text "title" of Tab "subpos" in TGTab "pos".
void StopEmbedding(const char *name=nullptr) override
TGTab * GetTabRight() const
Basic string class.
Definition TString.h:136
virtual const char * Getenv(const char *env)
Get environment variable.
Definition TSystem.cxx:1663
A TTree represents a columnar dataset.
Definition TTree.h:79
virtual TBranch * GetBranch(const char *name)
Return pointer to the branch with the given name in this tree or its friends.
Definition TTree.cxx:5279
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:5622
virtual TList * GetUserInfo()
Return a pointer to the list containing user objects associated to this tree.
Definition TTree.cxx:6340
virtual void SetBranchStatus(const char *bname, Bool_t status=1, UInt_t *found=0)
Set branch status to Process or DoNotProcess.
Definition TTree.cxx:8505
TPaveText * pt
Double_t x[n]
Definition legend1.C:17
const Int_t n
Definition legend1.C:16
Double_t Sqrt(Double_t x)
Definition TMath.h:641
Double_t Cos(Double_t)
Definition TMath.h:593
Double_t Sin(Double_t)
Definition TMath.h:589
Short_t Abs(Short_t d)
Definition TMathBase.h:120
void tracks()
Definition tracks.C:49