]> git.uio.no Git - u/mrichter/AliRoot.git/blob - EVE/alice-macros/clusters.C
d4915be38e93c2a86915062600e0e0c6a087598d
[u/mrichter/AliRoot.git] / EVE / alice-macros / clusters.C
1 #ifndef __CINT__
2 #include <TEveManager.h>
3 #include <TEvePointSet.h>
4 #include <TGeoManager.h>
5
6 #include <AliRunLoader.h>
7 #include <AliCluster.h>
8 #include <AliTracker.h>
9 #include <AliReconstruction.h>
10 #include <AliESDEvent.h>
11 #include <AliESDtrack.h>
12 #include <AliESDfriend.h>
13 #include <AliITSRecoParam.h>
14 #include <AliEveEventManager.h>
15 #endif
16
17 void clusters()
18 {
19   AliEveEventManager::AssertGeometry();
20
21   AliRunLoader *rl        = AliEveEventManager::AssertRunLoader();
22   AliESDEvent  *esd       = AliEveEventManager::AssertESD();
23   AliEveEventManager::AssertESDfriend();
24   AliEveEventManager::AssertMagField();
25
26   const char* detNames[] = { "ITS", "TPC", /*"TRD",*/ "TOF", "HMPID" };
27   const Int_t detIds[]   = {   0,     1,   /*  2,  */   3,     5   };
28   const Int_t detN       = sizeof(detNames)/sizeof(char*);
29
30   // Hack - AliReconstruction does wonders with gGeoManager.
31   TGeoManager* xxx = gGeoManager; gGeoManager = 0;
32   AliReconstruction* reco = new AliReconstruction;
33   gGeoManager = xxx;
34
35   // Hack for ITS - it requires RecoParams outside event-loop!
36   reco->SetRecoParam("ITS", AliITSRecoParam::GetLowFluxParam());
37
38   reco->ImportRunLoader(rl);
39   {
40     TString alldets;
41     for (Int_t i = 0; i < detN; ++i) {
42       alldets += detNames[i];
43       alldets += " ";
44     }
45     reco->CreateTrackers(alldets);
46   }
47
48   TObjArray* clarr = new TObjArray();
49
50   // Load clusters, fill them into clarr.
51
52   for (Int_t i = 0; i < detN; ++i)
53   {
54     Int_t det = detIds[i];
55     rl->LoadRecPoints(detNames[i]);
56
57     TTree *cTree = rl->GetTreeR(detNames[i], false);
58     if (cTree == 0)
59       continue;
60
61     AliTracker* tracker = reco->GetTracker(det);
62     if (tracker == 0) continue;
63     tracker->LoadClusters(cTree);
64     tracker->FillClusterArray(clarr);
65   }
66
67   // Loop over tracks and friends, tag used clusters.
68
69   for (Int_t n = 0; n < esd->GetNumberOfTracks(); ++n)
70   {
71     AliESDtrack* at = esd->GetTrack(n);
72
73     Int_t idx[200];
74     for (Int_t i = 0; i < detN; ++i)
75     {
76       Int_t det = detIds[i];
77       AliTracker* tracker = reco->GetTracker(det);
78       if (tracker == 0) continue;
79       Int_t nclusters = at->GetClusters(det, idx);
80       Int_t p=0;
81       for (Int_t c = 0; c < nclusters; )
82       {
83         Int_t index = idx[p++];
84         if (index < 0) continue;
85         c++;
86         AliCluster* cluster = tracker->GetCluster(index);
87         if (cluster) cluster->IncreaseClusterUsage();
88         //else printf("Zero cluster pointer for detector: %s\n",detNames[i]);
89       }
90     }
91   }
92
93   for (Int_t i = 0; i < detN; ++i)
94     rl->UnloadRecPoints(detNames[i]);
95
96   // Fill visualization structs
97
98   TEveElementList* list = new TEveElementList("Clusters");
99   gEve->AddElement(list);
100
101   TEvePointSet* shared = new TEvePointSet("Shared Clusters");
102   shared->SetMainColor(2);
103   shared->SetMarkerSize(0.4);
104   shared->SetMarkerStyle(2);
105   list->AddElement(shared);
106
107   TEvePointSet* used = new TEvePointSet("Single-used Clusters");
108   used->SetMainColor(3);
109   used->SetMarkerSize(0.4);
110   used->SetMarkerStyle(2);
111   list->AddElement(used);
112
113   TEvePointSet* nonused = new TEvePointSet("Not-used Clusters");
114   nonused->SetMainColor(4);
115   nonused->SetMarkerSize(0.4);
116   nonused->SetMarkerStyle(2);
117   list->AddElement(nonused);
118
119   // Loop over all clusters, fill appropriate container based
120   // on shared/used information.
121
122   Int_t ncl = clarr->GetEntriesFast();
123   for (Int_t i = 0; i < ncl; ++i)
124   {
125     AliCluster   *cluster = (AliCluster*) clarr->UncheckedAt(i);
126     TEvePointSet *dest    = 0;
127     if (cluster->IsClusterShared())
128       dest = shared;
129     else if (cluster->IsClusterUsed())
130       dest = used;
131     else
132       dest = nonused;
133
134     Float_t g[3]; //global coordinates
135     cluster->GetGlobalXYZ(g);
136     dest->SetNextPoint(g[0], g[1], g[2]);
137     dest->SetPointId(cluster);
138   }
139
140   delete clarr;
141
142   // ??? What to do with trackers ???
143   // I'd propose: have global reconstruction that owns them.
144   // AliEveEventManager::AssertAliReconstruction();
145   // do we have bit-field for detectors, like
146   // enum AliDetectors_e {
147   //    kITS = BIT(0),
148   //    kTPC = BIT(1),
149   //    ...
150   //    kCentralTracking = kITS | kTPC | kTRD | kTOF,
151   //    ...
152   //  };
153
154   gEve->Redraw3D();
155 }