00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #if defined(__CINT__) && !defined(__MAKECINT__)
00025 {
00026 Info("alice_vsd.C",
00027 "Has to be run in compiled mode ... doing this for you.");
00028 gSystem->CompileMacro("alice_vsd.C");
00029 alice_vsd();
00030 }
00031 #else
00032
00033
00034 #include <TEveManager.h>
00035 #include <TEveEventManager.h>
00036 #include <TEveVSD.h>
00037 #include <TEveVSDStructs.h>
00038
00039 #include <TEveTrack.h>
00040 #include <TEveTrackPropagator.h>
00041 #include <TEveGeoShape.h>
00042
00043 #include <TGTab.h>
00044 #include <TGButton.h>
00045
00046 #include <TFile.h>
00047 #include <TKey.h>
00048 #include <TSystem.h>
00049 #include <TPRegexp.h>
00050
00051
00052
00053
00054 #include "MultiView.C"
00055 MultiView* gMultiView = 0;
00056
00057
00058 class TVSDReader
00059 {
00060 public:
00061
00062
00063
00064
00065 TFile *fFile;
00066 TDirectory *fDirectory;
00067
00068 TObjArray *fEvDirKeys;
00069
00070 TEveVSD *fVSD;
00071
00072 Int_t fMaxEv, fCurEv;
00073
00074
00075
00076
00077
00078 TEveTrackList *fTrackList;
00079 TEvePointSet *fITSClusters;
00080 TEvePointSet *fTPCClusters;
00081 TEvePointSet *fTRDClusters;
00082 TEvePointSet *fTOFClusters;
00083
00084 public:
00085 TVSDReader(const char* file_name) :
00086 fFile(0), fDirectory(0), fEvDirKeys(0),
00087 fVSD(0),
00088
00089 fMaxEv(-1), fCurEv(-1),
00090
00091 fTrackList(0),
00092 fITSClusters(0), fTPCClusters(0), fTRDClusters(0), fTOFClusters(0)
00093 {
00094 fFile = TFile::Open(file_name);
00095 if (!fFile)
00096 {
00097 Error("VSD_Reader", "Can not open file '%s' ... terminating.",
00098 file_name);
00099 gSystem->Exit(1);
00100 }
00101
00102 fEvDirKeys = new TObjArray;
00103 TPMERegexp name_re("Event\\d+");
00104 TObjLink* lnk = fFile->GetListOfKeys()->FirstLink();
00105 while (lnk)
00106 {
00107 if (name_re.Match(lnk->GetObject()->GetName()))
00108 {
00109 fEvDirKeys->Add(lnk->GetObject());
00110 }
00111 lnk = lnk->Next();
00112 }
00113
00114 fMaxEv = fEvDirKeys->GetEntriesFast();
00115 if (fMaxEv == 0)
00116 {
00117 Error("VSD_Reader", "No events to show ... terminating.");
00118 gSystem->Exit(1);
00119 }
00120
00121 fVSD = new TEveVSD;
00122 }
00123
00124 virtual ~TVSDReader()
00125 {
00126
00127
00128 DropEvent();
00129
00130 delete fVSD;
00131 delete fEvDirKeys;
00132
00133 fFile->Close();
00134 delete fFile;
00135 }
00136
00137 void AttachEvent()
00138 {
00139
00140
00141 fVSD->LoadTrees();
00142 fVSD->SetBranchAddresses();
00143 }
00144
00145 void DropEvent()
00146 {
00147
00148
00149
00150
00151 gEve->GetViewers()->DeleteAnnotations();
00152 gEve->GetCurrentEvent()->DestroyElements();
00153
00154
00155
00156 fVSD->DeleteTrees();
00157 delete fDirectory;
00158 fDirectory = 0;
00159 }
00160
00161
00162
00163
00164
00165 void NextEvent()
00166 {
00167 GotoEvent(fCurEv + 1);
00168 }
00169
00170 void PrevEvent()
00171 {
00172 GotoEvent(fCurEv - 1);
00173 }
00174
00175 Bool_t GotoEvent(Int_t ev)
00176 {
00177 if (ev < 0 || ev >= fMaxEv)
00178 {
00179 Warning("GotoEvent", "Invalid event id %d.", ev);
00180 return kFALSE;
00181 }
00182
00183 DropEvent();
00184
00185
00186
00187 fCurEv = ev;
00188 fDirectory = (TDirectory*) ((TKey*) fEvDirKeys->At(fCurEv))->ReadObj();
00189 fVSD->SetDirectory(fDirectory);
00190
00191 AttachEvent();
00192
00193
00194
00195 LoadClusters(fITSClusters, "ITS", 0);
00196 LoadClusters(fTPCClusters, "TPC", 1);
00197 LoadClusters(fTRDClusters, "TRD", 2);
00198 LoadClusters(fTOFClusters, "TOF", 3);
00199
00200 LoadEsdTracks();
00201
00202
00203
00204 TEveElement* top = gEve->GetCurrentEvent();
00205
00206 gMultiView->DestroyEventRPhi();
00207 gMultiView->ImportEventRPhi(top);
00208
00209 gMultiView->DestroyEventRhoZ();
00210 gMultiView->ImportEventRhoZ(top);
00211
00212 gEve->Redraw3D(kFALSE, kTRUE);
00213
00214 return kTRUE;
00215 }
00216
00217
00218
00219
00220
00221
00222 void LoadClusters(TEvePointSet*& ps, const TString& det_name, Int_t det_id)
00223 {
00224 if (ps == 0)
00225 {
00226 ps = new TEvePointSet(det_name);
00227 ps->SetMainColor((Color_t)(det_id + 2));
00228 ps->SetMarkerSize(0.5);
00229 ps->SetMarkerStyle(2);
00230 ps->IncDenyDestroy();
00231 }
00232 else
00233 {
00234 ps->Reset();
00235 }
00236
00237 TEvePointSelector ss(fVSD->fTreeC, ps, "fV.fX:fV.fY:fV.fZ",
00238 TString::Format("fDetId==%d", det_id));
00239 ss.Select();
00240 ps->SetTitle(TString::Format("N=%d", ps->Size()));
00241
00242 gEve->AddElement(ps);
00243 }
00244
00245
00246
00247
00248
00249
00250 enum ESDTrackFlags
00251 {
00252 kITSin=0x0001,kITSout=0x0002,kITSrefit=0x0004,kITSpid=0x0008,
00253 kTPCin=0x0010,kTPCout=0x0020,kTPCrefit=0x0040,kTPCpid=0x0080,
00254 kTRDin=0x0100,kTRDout=0x0200,kTRDrefit=0x0400,kTRDpid=0x0800,
00255 kTOFin=0x1000,kTOFout=0x2000,kTOFrefit=0x4000,kTOFpid=0x8000,
00256 kHMPIDpid=0x20000,
00257 kEMCALmatch=0x40000,
00258 kTRDbackup=0x80000,
00259 kTRDStop=0x20000000,
00260 kESDpid=0x40000000,
00261 kTIME=0x80000000
00262 };
00263
00264 Bool_t trackIsOn(TEveTrack* t, Int_t mask)
00265 {
00266
00267
00268 return (t->GetStatus() & mask) > 0;
00269 }
00270
00271 void LoadEsdTracks()
00272 {
00273
00274
00275 if (fTrackList == 0)
00276 {
00277 fTrackList = new TEveTrackList("ESD Tracks");
00278 fTrackList->SetMainColor(6);
00279 fTrackList->SetMarkerColor(kYellow);
00280 fTrackList->SetMarkerStyle(4);
00281 fTrackList->SetMarkerSize(0.5);
00282
00283 fTrackList->IncDenyDestroy();
00284 }
00285 else
00286 {
00287 fTrackList->DestroyElements();
00288 }
00289
00290 TEveTrackPropagator* trkProp = fTrackList->GetPropagator();
00291
00292
00293 trkProp->SetMagField(0.5);
00294 trkProp->SetStepper(TEveTrackPropagator::kRungeKutta);
00295
00296 Int_t nTracks = fVSD->fTreeR->GetEntries();
00297 for (Int_t n = 0; n < nTracks; ++n)
00298 {
00299 fVSD->fTreeR->GetEntry(n);
00300
00301 TEveTrack* track = new TEveTrack(&fVSD->fR, trkProp);
00302 track->SetName(Form("ESD Track %d", fVSD->fR.fIndex));
00303 track->SetStdTitle();
00304 track->SetAttLineAttMarker(fTrackList);
00305 fTrackList->AddElement(track);
00306 }
00307
00308 fTrackList->MakeTracks();
00309
00310 gEve->AddElement(fTrackList);
00311 }
00312
00313 ClassDef(TVSDReader, 0);
00314 };
00315
00316 TVSDReader* gVSDReader = 0;
00317
00318
00319
00320 void make_gui();
00321
00322
00323 void alice_vsd(const char* vsd_file_name=
00324 "http://mtadel.home.cern.ch/mtadel/root/AliVSD.root")
00325 {
00326
00327
00328
00329
00330
00331
00332
00333
00334
00335 TFile::SetCacheFileDir(".");
00336
00337 TEveVSD::DisableTObjectStreamersForVSDStruct();
00338
00339 gVSDReader = new TVSDReader(vsd_file_name);
00340
00341 TEveManager::Create();
00342
00343 TEveGeoShape *gentle_geom = 0;
00344
00345 {
00346 TFile* geom =
00347 TFile::Open("http://mtadel.home.cern.ch/mtadel/root/alice_mini_geom.root",
00348 "CACHEREAD");
00349 if (!geom)
00350 return;
00351 TEveGeoShapeExtract* gse = (TEveGeoShapeExtract*) geom->Get("Gentle");
00352 gentle_geom = TEveGeoShape::ImportShapeExtract(gse, 0);
00353 geom->Close();
00354 delete geom;
00355 gEve->AddGlobalElement(gentle_geom);
00356 }
00357
00358
00359
00360
00361
00362 gMultiView = new MultiView;
00363 gMultiView->f3DView->GetGLViewer()->SetStyle(TGLRnrCtx::kOutline);
00364
00365 gMultiView->SetDepth(-10);
00366 gMultiView->ImportGeomRPhi(gentle_geom);
00367 gMultiView->ImportGeomRhoZ(gentle_geom);
00368 gMultiView->SetDepth(0);
00369
00370
00371
00372
00373
00374 gEve->GetViewers()->SwitchColorSet();
00375 gEve->GetDefaultGLViewer()->SetStyle(TGLRnrCtx::kOutline);
00376
00377 gEve->GetBrowser()->GetTabRight()->SetTab(1);
00378
00379 make_gui();
00380
00381 gEve->AddEvent(new TEveEventManager("Event", "ALICE VSD Event"));
00382
00383 gVSDReader->GotoEvent(0);
00384
00385 gEve->Redraw3D(kTRUE);
00386 }
00387
00388
00389
00390 void make_gui()
00391 {
00392
00393
00394 TEveBrowser* browser = gEve->GetBrowser();
00395 browser->StartEmbedding(TRootBrowser::kLeft);
00396
00397 TGMainFrame* frmMain = new TGMainFrame(gClient->GetRoot(), 1000, 600);
00398 frmMain->SetWindowName("XX GUI");
00399 frmMain->SetCleanup(kDeepCleanup);
00400
00401 TGHorizontalFrame* hf = new TGHorizontalFrame(frmMain);
00402 {
00403 TString icondir(TString::Format("%s/icons/", gSystem->Getenv("ROOTSYS")));
00404 TGPictureButton* b = 0;
00405
00406 b = new TGPictureButton(hf, gClient->GetPicture(icondir+"GoBack.gif"));
00407 hf->AddFrame(b);
00408 b->Connect("Clicked()", "TVSDReader", gVSDReader, "PrevEvent()");
00409
00410 b = new TGPictureButton(hf, gClient->GetPicture(icondir+"GoForward.gif"));
00411 hf->AddFrame(b);
00412 b->Connect("Clicked()", "TVSDReader", gVSDReader, "NextEvent()");
00413 }
00414 frmMain->AddFrame(hf);
00415
00416 frmMain->MapSubwindows();
00417 frmMain->Resize();
00418 frmMain->MapWindow();
00419
00420 browser->StopEmbedding();
00421 browser->SetTabTitle("Event Control", 0);
00422 }
00423
00424 #endif