Handle missing rec-point tree in a uniform way: return null pointer to TEvePointSet.
[u/mrichter/AliRoot.git] / EVE / alice-macros / tpc_clusters.C
CommitLineData
d810d0de 1// $Id$
2// Main authors: Matevz Tadel & Alja Mrak-Tadel: 2006, 2007
3
4/**************************************************************************
5 * Copyright(c) 1998-2008, ALICE Experiment at CERN, all rights reserved. *
6 * See http://aliceinfo.cern.ch/Offline/AliRoot/License.html for *
51346b82 7 * full copyright notice. *
d810d0de 8 **************************************************************************/
cb4245bb 9
32e219c2 10#ifdef __CINT__
ae1afd97 11
84aff7a4 12class TEveElement;
13class TEvePointSet;
32e219c2 14
15#else
16
84aff7a4 17#include <TEveManager.h>
18#include <TEvePointSet.h>
ea5d9491 19#include <EveBase/AliEveEventManager.h>
32e219c2 20
21#include <AliRunLoader.h>
22#include <AliCluster.h>
23#include <TPC/AliTPCClustersRow.h>
24
25#endif
26
84aff7a4 27TEvePointSet* tpc_clusters(TEveElement* cont=0, Float_t maxR=270)
ae1afd97 28{
29 const Int_t kMaxCl=100*160;
30
d810d0de 31 AliEveEventManager::AssertGeometry();
ae1afd97 32
d810d0de 33 AliRunLoader* rl = AliEveEventManager::AssertRunLoader();
ae1afd97 34 rl->LoadRecPoints("TPC");
35
787c89c5 36 TTree *cTree = rl->GetTreeR("TPC", false);
37 if (cTree == 0)
38 return 0;
39
40 AliTPCClustersRow *clrow = new AliTPCClustersRow();
ae1afd97 41 clrow->SetClass("AliTPCclusterMI");
42 clrow->SetArray(kMaxCl);
32e219c2 43 cTree->SetBranchAddress("Segment", &clrow);
ae1afd97 44
787c89c5 45 TEvePointSet* clusters = new TEvePointSet(kMaxCl);
46 clusters->SetOwnIds(kTRUE);
47
48
ae1afd97 49 Float_t maxRsqr = maxR*maxR;
ae1afd97 50 Int_t nentr=(Int_t)cTree->GetEntries();
0abe4b3a 51 for (Int_t i=0; i<nentr; i++)
52 {
ae1afd97 53 if (!cTree->GetEvent(i)) continue;
54
0abe4b3a 55 TClonesArray *cl = clrow->GetArray();
56 Int_t ncl = cl->GetEntriesFast();
ae1afd97 57
0abe4b3a 58 while (ncl--)
59 {
60 AliCluster *c = (AliCluster*) cl->UncheckedAt(ncl);
ae1afd97 61 Float_t g[3]; //global coordinates
62 c->GetGlobalXYZ(g);
63 if (g[0]*g[0]+g[1]*g[1] < maxRsqr)
64 {
65 clusters->SetNextPoint(g[0], g[1], g[2]);
66 AliCluster *atp = new AliCluster(*c);
67 clusters->SetPointId(atp);
68 }
69 }
70 cl->Clear();
71 }
72
73 delete clrow;
74
0abe4b3a 75 if (clusters->Size() == 0 && gEve->GetKeepEmptyCont() == kFALSE)
76 {
8ebd7df4 77 Warning("tpc_clusters.C", "No TPC clusters");
ae1afd97 78 delete clusters;
79 return 0;
80 }
81
82 clusters->SetMarkerStyle(2);
83 clusters->SetMarkerSize(0.2);
84 clusters->SetMarkerColor(4);
85
86 char form[1000];
87 sprintf(form,"TPC Clusters");
88 clusters->SetName(form);
89
90 char tip[1000];
91 sprintf(tip,"N=%d", clusters->Size());
92 clusters->SetTitle(tip);
84aff7a4 93 gEve->AddElement(clusters, cont);
94 gEve->Redraw3D();
ae1afd97 95
96 return clusters;
97}