Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches

Detailed Description

Complex example showing ALICE VSD visualization.

alice_vsd.C - a simple event-display for ALICE

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

No ALICE code is needed – the VSD file is exported from AliRoot into VSD format – see TEveVSDStructs.h and TEveVSD.h.

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.

#include <TEveManager.h>
#include <TEveVSD.h>
#include <TEveVSDStructs.h>
#include <TEveTrack.h>
#include <TEveGeoShape.h>
#include <TGTab.h>
#include <TGButton.h>
#include <TFile.h>
#include <TKey.h>
#include <TSystem.h>
#include <TPRegexp.h>
// Include components -- compile time link :)
#include "MultiView.C"
MultiView *gMultiView = nullptr;
class TVSDReader {
public:
// ----------------------------------------------------------
// File / Event Data
// ----------------------------------------------------------
TFile *fFile;
TDirectory *fDirectory;
// ----------------------------------------------------------
// Event visualization structures
// ----------------------------------------------------------
public:
TVSDReader(const char *file_name)
: fFile(nullptr),
fDirectory(nullptr),
fEvDirKeys(nullptr),
fVSD(nullptr),
fMaxEv(-1),
fCurEv(-1),
fTrackList(nullptr),
fITSClusters(nullptr),
fTPCClusters(nullptr),
fTRDClusters(nullptr),
fTOFClusters(nullptr)
{
fFile = TFile::Open(file_name);
if (!fFile) {
Error("VSD_Reader", "Can not open file '%s' ... terminating.", file_name);
}
TPMERegexp name_re("Event\\d+");
while (lnk) {
if (name_re.Match(lnk->GetObject()->GetName())) {
fEvDirKeys->Add(lnk->GetObject());
}
lnk = lnk->Next();
}
fMaxEv = fEvDirKeys->GetEntriesFast();
if (fMaxEv == 0) {
Error("VSD_Reader", "No events to show ... terminating.");
}
fVSD = new TEveVSD;
}
virtual ~TVSDReader()
{
// Destructor.
delete fVSD;
delete fEvDirKeys;
fFile->Close();
delete fFile;
}
void AttachEvent()
{
// Attach event data from current directory.
fVSD->LoadTrees();
fVSD->SetBranchAddresses();
}
void DropEvent()
{
// Drup currently held event data, release current directory.
// Drop old visualization structures.
// Drop old event-data.
fVSD->DeleteTrees();
delete fDirectory;
fDirectory = nullptr;
}
//---------------------------------------------------------------------------
// Event navigation
//---------------------------------------------------------------------------
void NextEvent() { GotoEvent(fCurEv + 1); }
void PrevEvent() { GotoEvent(fCurEv - 1); }
Bool_t GotoEvent(Int_t ev)
{
Warning("GotoEvent", "Invalid event id %d.", ev);
return kFALSE;
}
// Connect to new event-data.
fDirectory = (TDirectory *)((TKey *)fEvDirKeys->At(fCurEv))->ReadObj();
fVSD->SetDirectory(fDirectory);
// Load event data into visualization structures.
LoadClusters(fITSClusters, "ITS", 0);
LoadClusters(fTPCClusters, "TPC", 1);
LoadClusters(fTRDClusters, "TRD", 2);
LoadClusters(fTOFClusters, "TOF", 3);
// Fill projected views.
auto top = gEve->GetCurrentEvent();
gMultiView->DestroyEventRPhi();
gMultiView->ImportEventRPhi(top);
gMultiView->DestroyEventRhoZ();
gMultiView->ImportEventRhoZ(top);
return kTRUE;
}
//---------------------------------------------------------------------------
// Cluster loading
//---------------------------------------------------------------------------
void LoadClusters(TEvePointSet *&ps, const TString &det_name, Int_t det_id)
{
if (ps == nullptr) {
ps->SetMarkerSize(0.5);
} else {
ps->Reset();
}
TEvePointSelector ss(fVSD->fTreeC, ps, "fV.fX:fV.fY:fV.fZ", TString::Format("fDetId==%d", det_id));
ss.Select();
ps->SetTitle(TString::Format("N=%d", ps->Size()));
}
//---------------------------------------------------------------------------
// Track loading
//---------------------------------------------------------------------------
kITSin = 0x0001,
kITSout = 0x0002,
kITSrefit = 0x0004,
kITSpid = 0x0008,
kTPCin = 0x0010,
kTPCout = 0x0020,
kTPCrefit = 0x0040,
kTPCpid = 0x0080,
kTRDin = 0x0100,
kTRDout = 0x0200,
kTRDrefit = 0x0400,
kTRDpid = 0x0800,
kTOFin = 0x1000,
kTOFout = 0x2000,
kTOFrefit = 0x4000,
kTOFpid = 0x8000,
kHMPIDpid = 0x20000,
kEMCALmatch = 0x40000,
kTRDbackup = 0x80000,
kTRDStop = 0x20000000,
kESDpid = 0x40000000,
kTIME = 0x80000000
};
{
// Check is track-flag specified by mask are set.
return (t->GetStatus() & mask) > 0;
}
{
// Read reconstructed tracks from current event.
if (fTrackList == nullptr) {
fTrackList = new TEveTrackList("ESD Tracks");
fTrackList->SetMainColor(6);
fTrackList->SetMarkerColor(kYellow);
fTrackList->SetMarkerStyle(4);
fTrackList->SetMarkerSize(0.5);
fTrackList->IncDenyDestroy();
} else {
fTrackList->DestroyElements();
}
auto trkProp = fTrackList->GetPropagator();
// !!!! Need to store field on file !!!!
// Can store TEveMagField ?
trkProp->SetMagField(0.5);
Int_t nTracks = fVSD->fTreeR->GetEntries();
for (Int_t n = 0; n < nTracks; ++n) {
fVSD->fTreeR->GetEntry(n);
track->SetName(Form("ESD Track %d", fVSD->fR.fIndex));
track->SetStdTitle();
track->SetAttLineAttMarker(fTrackList);
fTrackList->AddElement(track);
}
fTrackList->MakeTracks();
}
};
// Forward declaration.
void make_gui();
//______________________________________________________________________________
void alice_vsd(const char *vsd_file_name = "http://mtadel.home.cern.ch/mtadel/root/AliVSD.root")
{
// 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.
{ // Simple geometry
auto geom = TFile::Open("http://mtadel.home.cern.ch/mtadel/root/alice_mini_geom.root", "CACHEREAD");
if (!geom)
return;
auto gse = (TEveGeoShapeExtract *)geom->Get("Gentle");
geom->Close();
delete geom;
}
// Standard multi-view
//=====================
gMultiView->f3DView->GetGLViewer()->SetStyle(TGLRnrCtx::kOutline);
gMultiView->SetDepth(-10);
gMultiView->ImportGeomRPhi(gentle_geom);
gMultiView->ImportGeomRhoZ(gentle_geom);
gMultiView->SetDepth(0);
// Final stuff
//=============
gEve->AddEvent(new TEveEventManager("Event", "ALICE VSD Event"));
gVSDReader->GotoEvent(0);
gEve->Redraw3D(kTRUE); // Reset camera after the first event has been shown.
}
//______________________________________________________________________________
void make_gui()
{
// Create minimal GUI for event navigation.
auto browser = gEve->GetBrowser();
browser->StartEmbedding(TRootBrowser::kLeft);
auto frmMain = new TGMainFrame(gClient->GetRoot(), 1000, 600);
frmMain->SetWindowName("XX GUI");
frmMain->SetCleanup(kDeepCleanup);
{
TString icondir(TString::Format("%s/icons/", gSystem->Getenv("ROOTSYS")));
TGPictureButton *b = nullptr;
b = new TGPictureButton(hf, gClient->GetPicture(icondir + "GoBack.gif"));
hf->AddFrame(b);
b->Connect("Clicked()", "TVSDReader", gVSDReader, "PrevEvent()");
b = new TGPictureButton(hf, gClient->GetPicture(icondir + "GoForward.gif"));
hf->AddFrame(b);
b->Connect("Clicked()", "TVSDReader", gVSDReader, "NextEvent()");
}
frmMain->AddFrame(hf);
frmMain->MapSubwindows();
frmMain->Resize();
frmMain->MapWindow();
browser->StopEmbedding();
browser->SetTabTitle("Event Control", 0);
}
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:561
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:53
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:4088
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:4625
void Close(Option_t *option="") override
Close a file.
Definition TFile.cxx:949
A composite frame that layout their children in horizontal way.
Definition TGFrame.h:385
void SetStyle(Short_t st)
Defines top level windows that interact with the system Window Manager.
Definition TGFrame.h:397
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:1665
virtual void Exit(int code, Bool_t mode=kTRUE)
Exit the application.
Definition TSystem.cxx:716
const Int_t n
Definition legend1.C:16
Author
Matevz Tadel

Definition in file alice_vsd.C.