Logo ROOT  
Reference Guide
No Matches
run_alice_esd_split.C File Reference

Detailed Description

Complex example showing ALICE ESD visualization in several views.

alice_esd_split.C - a simple event-display for ALICE ESD tracks and clusters version with several windows in the same workspace

Only standard ROOT is used to process the ALICE ESD files.

No ALICE code is needed, only four simple coordinate-transformation functions declared in this macro.

A simple geometry of 10KB, extracted from the full TGeo-geometry, is used to outline the central detectors of ALICE.

All files are access from the web by using the "CACHEREAD" option.

Automatic building of ALICE ESD class declarations and dictionaries.

ALICE ESD is a TTree containing tracks and other event-related information with one entry per event. All these classes are part of the AliROOT offline framework and are not available to standard ROOT.

To be able to access the event data in a natural way, by using data-members of classes and object containers, the header files and class dictionaries are automatically generated from the TStreamerInfo classes stored in the ESD file by using the TFile::MakeProject() function. The header files and a shared library is created in the aliesd/ directory and can be loaded dynamically into the ROOT session.

See the run_alice_esd.C macro.

Creation of simple GUI for event navigation.

Most common use of the event-display is to browse through a collection of events. Thus a simple GUI allowing this is created in the function make_gui().

Eve uses the configurable ROOT-browser as its main window and so we create an extra tab in the left working area of the browser and provide backward/forward buttons.

Event-navigation functions.

As this is a simple macro, we store the information about the current event in the global variable 'Int_t esd_event_id'. The functions for event-navigation simply modify this variable and call the load_event() function which does the following:

  1. drop the old visualization objects;
  2. retrieve given event from the ESD tree;
  3. call alice_esd_read() function to create visualization objects for the new event.

Reading of ALICE data and creation of visualization objects.

This is performed in alice_esd_read() function, with the following steps:

  1. create the track container object - TEveTrackList;
  2. iterate over the ESD tracks, create TEveTrack objects and append them to the container;
  3. instruct the container to extrapolate the tracks and set their visual attributes.
#include "aliesd/AliESDEvent.h"
#include "aliesd/AliESDRun.h"
#include "aliesd/AliESDtrack.h"
TEveGeoShape *gGeoShape;
class AliESDEvent;
class AliESDfriend;
class AliESDtrack;
class AliExternalTrackParam;
void make_gui();
void load_event();
void update_projections();
void alice_esd_read();
TEveTrack* esd_make_track(TEveTrackPropagator* trkProp, Int_t index, AliESDtrack* at,
AliExternalTrackParam* tp=0);
Bool_t trackIsOn(AliESDtrack* t, Int_t mask);
void trackGetPos(AliExternalTrackParam* tp, Double_t r[3]);
void trackGetMomentum(AliExternalTrackParam* tp, Double_t p[3]);
Double_t trackGetP(AliExternalTrackParam* tp);
// Configuration and global variables.
const char* esd_file_name = "http://root.cern.ch/files/alice_ESDs.root";
const char* esd_friends_file_name = "http://root.cern.ch/files/alice_ESDfriends.root";
const char* esd_geom_file_name = "http://root.cern.ch/files/alice_ESDgeometry.root";
TFile *esd_file = nullptr;
TFile *esd_friends_file = nullptr;
TTree *esd_tree = nullptr;
AliESDEvent *esd = nullptr;
AliESDfriend *esd_friend = nullptr;
Int_t esd_event_id = 0; // Current event id.
TEveTrackList *track_list = nullptr;
TGTextEntry *gTextEntry = nullptr;
TGHProgressBar *gProgress = nullptr;
// Initialization and steering functions
void run_alice_esd_split(Bool_t auto_size=kFALSE)
// Main function, initializes the application.
// 1. Load the auto-generated library holding ESD classes and ESD dictionaries.
// 2. Open ESD data-files.
// 3. Load cartoon geometry.
// 4. Spawn simple GUI.
// 5. Load first event.
printf("*** Opening ESD ***\n");
esd_file = TFile::Open(esd_file_name, "CACHEREAD");
if (!esd_file)
printf("*** Opening ESD-friends ***\n");
esd_friends_file = TFile::Open(esd_friends_file_name, "CACHEREAD");
if (!esd_friends_file)
esd_tree = (TTree*) esd_file->Get("esdTree");
esd = (AliESDEvent*) esd_tree->GetUserInfo()->FindObject("AliESDEvent");
// Set the branch addresses.
TIter next(esd->fESDObjects);
TObject *el;
while ((el=(TNamed*)next()))
TString bname(el->GetName());
// AliESDfriend needs some '.' magick.
esd_tree->SetBranchAddress("ESDfriend.", esd->fESDObjects->GetObjectRef(el));
esd_tree->SetBranchAddress(bname, esd->fESDObjects->GetObjectRef(el));
// Adapt the main frame to the screen size...
if (auto_size)
Int_t qq;
UInt_t ww, hh;
gVirtualX->GetWindowSize(gVirtualX->GetDefaultRootWindow(), qq, qq, ww, hh);
Float_t screen_ratio = (Float_t)ww/(Float_t)hh;
if (screen_ratio > 1.5) {
gEve->GetBrowser()->MoveResize(100, 50, ww - 300, hh - 100);
} else {
gEve->GetBrowser()->Move(50, 50);
{ // Simple geometry
TFile* geom = TFile::Open(esd_geom_file_name, "CACHEREAD");
if (!geom)
TEveGeoShapeExtract* gse = (TEveGeoShapeExtract*) geom->Get("Gentle");
gGeoShape = TEveGeoShape::ImportShapeExtract(gse, 0);
delete geom;
// import the geometry in the projection managers
if (gRPhiMgr) {
gEve->GetScenes()->FindChild("R-Phi Projection")->AddElement(a);
if (gRhoZMgr) {
gEve->GetScenes()->FindChild("Rho-Z Projection")->AddElement(a);
gEve->Redraw3D(kTRUE); // Reset camera after the first event has been shown.
void load_event()
// Load event specified in global esd_event_id.
// The contents of previous event are removed.
printf("Loading event %d.\n", esd_event_id);
gTextEntry->SetText(Form("Loading event %d...",esd_event_id));
if (track_list)
gTextEntry->SetText(Form("Event %d loaded",esd_event_id));
void update_projections()
// cleanup then import geometry and event
// in the projection managers
if (gRPhiMgr && top) {
if (gRhoZMgr && top) {
// GUI
// EvNavHandler class is needed to connect GUI signals.
class EvNavHandler
void Fwd()
if (esd_event_id < esd_tree->GetEntries() - 1) {
} else {
gTextEntry->SetText("Already at last event");
printf("Already at last event.\n");
void Bck()
if (esd_event_id > 0) {
} else {
gTextEntry->SetText("Already at first event");
printf("Already at first event.\n");
void make_gui()
// Create minimal GUI for event navigation.
gROOT->ProcessLine(".L SplitGLView.C+");
TEveBrowser* browser = gEve->GetBrowser();
browser->ExecPlugin("SplitGLView", 0, "new SplitGLView(gClient->GetRoot(), 600, 450, kTRUE)");
TGMainFrame* frmMain = new TGMainFrame(gClient->GetRoot(), 1000, 600);
frmMain->SetWindowName("XX GUI");
TString icondir( Form("%s/icons/", gSystem->Getenv("ROOTSYS")) );
EvNavHandler *fh = new EvNavHandler;
b = new TGPictureButton(hf, gClient->GetPicture(icondir + "GoBack.gif"));
hf->AddFrame(b, new TGLayoutHints(kLHintsLeft | kLHintsCenterY, 10, 2, 10, 10));
b->Connect("Clicked()", "EvNavHandler", fh, "Bck()");
b = new TGPictureButton(hf, gClient->GetPicture(icondir + "GoForward.gif"));
hf->AddFrame(b, new TGLayoutHints(kLHintsLeft | kLHintsCenterY, 2, 10, 10, 10));
b->Connect("Clicked()", "EvNavHandler", fh, "Fwd()");
gTextEntry = new TGTextEntry(hf);
kLHintsExpandX, 2, 10, 10, 10));
frmMain->AddFrame(hf, new TGLayoutHints(kLHintsTop | kLHintsExpandX,0,0,20,0));
gProgress = new TGHProgressBar(frmMain, TGProgressBar::kFancy, 100);
gProgress->ShowPosition(kTRUE, kFALSE, "%.0f tracks");
frmMain->AddFrame(gProgress, new TGLayoutHints(kLHintsExpandX, 10, 10, 5, 5));
browser->SetTabTitle("Event Control", 0);
// Code for reading AliESD and creating visualization objects
enum ESDTrackFlags {
void alice_esd_read()
// Read tracks and associated clusters from current event.
AliESDRun *esdrun = (AliESDRun*) esd->fESDObjects->FindObject("AliESDRun");
TClonesArray *tracks = (TClonesArray*) esd->fESDObjects->FindObject("Tracks");
// This needs further investigation. Clusters not shown.
// AliESDfriend *frnd = (AliESDfriend*) esd->fESDObjects->FindObject("AliESDfriend");
// printf("Friend %p, n_tracks:%d\n", frnd, frnd->fTracks.GetEntries());
if (track_list == 0) {
track_list = new TEveTrackList("ESD Tracks");
TEveTrackPropagator* trkProp = track_list->GetPropagator();
trkProp->SetMagField( 0.1 * esdrun->fMagneticField ); // kGaus to Tesla
for (Int_t n=0; n<tracks->GetEntriesFast(); ++n)
AliESDtrack* at = (AliESDtrack*) tracks->At(n);
// If ITS refit failed, take track parameters at inner TPC radius.
AliExternalTrackParam* tp = at;
if (! trackIsOn(at, kITSrefit)) {
tp = at->fIp;
TEveTrack* track = esd_make_track(trkProp, n, at, tp);
// This needs further investigation. Clusters not shown.
// if (frnd)
// {
// AliESDfriendTrack* ft = (AliESDfriendTrack*) frnd->fTracks->At(n);
// printf("%d friend = %p\n", ft);
// }
TEveTrack* esd_make_track(TEveTrackPropagator* trkProp,
AliESDtrack* at,
AliExternalTrackParam* tp)
// Helper function creating TEveTrack from AliESDtrack.
// Optionally specific track-parameters (e.g. at TPC entry point)
// can be specified via the tp argument.
Double_t pbuf[3], vbuf[3];
if (tp == 0) tp = at;
rt.fLabel = at->fLabel;
rt.fIndex = index;
rt.fStatus = (Int_t) at->fFlags;
rt.fSign = (tp->fP[4] > 0) ? 1 : -1;
trackGetPos(tp, vbuf); rt.fV.Set(vbuf);
trackGetMomentum(tp, pbuf); rt.fP.Set(pbuf);
Double_t ep = trackGetP(at);
Double_t mc = 0.138; // at->GetMass(); - Complicated function, requiring PID.
rt.fBeta = ep/TMath::Sqrt(ep*ep + mc*mc);
TEveTrack* track = new TEveTrack(&rt, trkProp);
track->SetName(Form("TEveTrack %d", rt.fIndex));
return track;
Bool_t trackIsOn(AliESDtrack* t, Int_t mask)
// Check is track-flag specified by mask are set.
return (t->fFlags & mask) > 0;
void trackGetPos(AliExternalTrackParam* tp, Double_t r[3])
// Get global position of starting point of tp.
r[0] = tp->fX; r[1] = tp->fP[0]; r[2] = tp->fP[1];
Double_t cs=TMath::Cos(tp->fAlpha), sn=TMath::Sin(tp->fAlpha), x=r[0];
r[0] = x*cs - r[1]*sn; r[1] = x*sn + r[1]*cs;
void trackGetMomentum(AliExternalTrackParam* tp, Double_t p[3])
// Return global momentum vector of starting point of tp.
p[0] = tp->fP[4]; p[1] = tp->fP[2]; p[2] = tp->fP[3];
Double_t cs=TMath::Cos(tp->fAlpha), sn=TMath::Sin(tp->fAlpha);
Double_t r=TMath::Sqrt(1 - p[1]*p[1]);
p[0]=pt*(r*cs - p[1]*sn); p[1]=pt*(p[1]*cs + r*sn); p[2]=pt*p[2];
Double_t trackGetP(AliExternalTrackParam* tp)
// Return magnitude of momentum of tp.
return TMath::Sqrt(1.+ tp->fP[3]*tp->fP[3])/TMath::Abs(tp->fP[4]);
#define R__EXTERN
Definition DllImport.h:27
ULong_t Pixel_t
Pixel value.
Definition GuiTypes.h:40
#define b(i)
Definition RSha256.hxx:100
#define a(i)
Definition RSha256.hxx:99
bool Bool_t
Definition RtypesCore.h:63
int Int_t
Definition RtypesCore.h:45
unsigned int UInt_t
Definition RtypesCore.h:46
float Float_t
Definition RtypesCore.h:57
constexpr Bool_t kFALSE
Definition RtypesCore.h:101
double Double_t
Definition RtypesCore.h:59
constexpr Bool_t kTRUE
Definition RtypesCore.h:100
@ kYellow
Definition Rtypes.h:66
R__EXTERN TEveManager * gEve
#define gClient
Definition TGClient.h:157
@ kDeepCleanup
Definition TGFrame.h:42
@ kLHintsLeft
Definition TGLayout.h:24
@ kLHintsCenterY
Definition TGLayout.h:28
@ kLHintsTop
Definition TGLayout.h:27
@ kLHintsExpandX
Definition TGLayout.h:30
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
#define gROOT
Definition TROOT.h:407
char * Form(const char *fmt,...)
Formats a string in a circular formatting buffer.
Definition TString.cxx:2467
R__EXTERN TSystem * gSystem
Definition TSystem.h:560
#define gVirtualX
Definition TVirtualX.h:338
An array of clone (identical) objects.
TObject * Get(const char *namecycle) override
Return pointer to object identified by namecycle.
Specialization of TRootBrowser for Eve.
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.
TEveElement * FindChild(const TString &name, const TClass *cls=nullptr)
Find the first child with given name.
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=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.
TEveSceneList * GetScenes() 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
Axes for non-linear projections.
Manager class for steering of projections and managing projected objects.
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
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
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
A ROOT file is composed of a header, followed by consecutive data records (TKey instances) with a wel...
Definition TFile.h:53
static Bool_t SetCacheFileDir(ROOT::Internal::TStringView cacheDir, Bool_t operateDisconnected=kTRUE, Bool_t forceCacheread=kFALSE)
Definition TFile.h:332
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:4075
void Close(Option_t *option="") override
Close a file.
Definition TFile.cxx:936
virtual void AddFrame(TGFrame *f, TGLayoutHints *l=nullptr)
Add frame to the composite frame using the specified layout hints.
Definition TGFrame.cxx:1117
void MapSubwindows() override
Map all sub windows that are part of the composite frame.
Definition TGFrame.cxx:1164
void SetCleanup(Int_t mode=kLocalCleanup) override
Turn on automatic cleanup of child frames in dtor.
Definition TGFrame.cxx:1072
void MoveResize(Int_t x, Int_t y, UInt_t w=0, UInt_t h=0) override
Move and/or resize the frame.
Definition TGFrame.cxx:629
void Resize(UInt_t w=0, UInt_t h=0) override
Resize the frame.
Definition TGFrame.cxx:605
void MapWindow() override
map window
Definition TGFrame.h:204
void Move(Int_t x, Int_t y) override
Move frame.
Definition TGFrame.cxx:593
void ShowPosition(Bool_t set=kTRUE, Bool_t percent=kTRUE, const char *format="%.2f")
Show postion text, either in percent or formatted according format.
A composite frame that layout their children in horizontal way.
Definition TGFrame.h:385
This class describes layout hints used by the layout classes.
Definition TGLayout.h:50
Defines top level windows that interact with the system Window Manager.
Definition TGFrame.h:397
void SetWindowName(const char *name=nullptr) override
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
void Increment(Float_t inc)
Increment progress position.
virtual void SetBarColor(Pixel_t color)
Set progress bar color.
void SetMax(Float_t max)
virtual void Reset()
Reset progress bar (i.e. set pos to 0).
A TGTextEntry is a one line text input widget.
Definition TGTextEntry.h:24
void SetEnabled(Bool_t flag=kTRUE)
virtual void SetTextColor(Pixel_t color, Bool_t local=kTRUE)
Changes text color.
virtual void SetText(const char *text, Bool_t emit=kTRUE)
Sets text entry to text, clears the selection and moves the cursor to the end of the line.
TObject * FindObject(const char *name) const override
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
TObject * FindObject(const char *name) const override
Find an object in this collection using its name.
Mother of all ROOT objects.
Definition TObject.h:41
virtual const char * GetName() const
Returns name of object.
Definition TObject.cxx:439
SCoord_t fX
Definition TPoint.h:35
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".
Longptr_t ExecPlugin(const char *name=nullptr, const char *fname=nullptr, const char *cmd=nullptr, Int_t pos=kRight, Int_t subpos=-1) override
Execute a macro and embed the created frame in the tab "pos" and tab element "subpos".
void StopEmbedding(const char *name=nullptr) override
virtual void ShowCloseTab(Bool_t show)
Basic string class.
Definition TString.h:139
virtual const char * Getenv(const char *env)
Get environment variable.
Definition TSystem.cxx:1650
virtual Bool_t ProcessEvents()
Process pending events (GUI, timers, sockets).
Definition TSystem.cxx:403
A TTree represents a columnar dataset.
Definition TTree.h:79
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:5635
virtual Int_t SetBranchAddress(const char *bname, void *add, TBranch **ptr=nullptr)
Change branch address, dealing with clone trees properly.
Definition TTree.cxx:8377
virtual TList * GetUserInfo()
Return a pointer to the list containing user objects associated to this tree.
Definition TTree.cxx:6353
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:662
Double_t Cos(Double_t)
Returns the cosine of an angle of x radians.
Definition TMath.h:594
Double_t Sin(Double_t)
Returns the sine of an angle of x radians.
Definition TMath.h:588
Short_t Abs(Short_t d)
Returns the absolute value of parameter Short_t d.
Definition TMathBase.h:123
void tracks()
Definition tracks.C:49
Bertrand Bellenot

Definition in file run_alice_esd_split.C.