]> git.uio.no Git - u/mrichter/AliRoot.git/blob - EVE/alice-macros/primary_vertex.C
68932613936e1659f5ec1a99087b9e6691a30573
[u/mrichter/AliRoot.git] / EVE / alice-macros / primary_vertex.C
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          *
7  * full copyright notice.                                                 *
8  **************************************************************************/
9
10 #if !defined(__CINT__) || defined(__MAKECINT__)
11 #include <TEveManager.h>
12 #include <TEveCompound.h>
13 #include <TEveStraightLineSet.h>
14
15 #include <EveBase/AliEveEventManager.h>
16
17 #include <AliESDEvent.h>
18 #include <AliESDVertex.h>
19
20 #endif
21
22 //==============================================================================
23 // Utilities
24 //==============================================================================
25
26 TEveCompound* assert_vertex_parent(const TString& name, Color_t col)
27 {
28   // !!! TEveCompound should have viz-db support ... add in root, then fix here,
29   // that is, remove the color var and pass viz-db tag.
30
31   TEveCompound* parent = dynamic_cast<TEveCompound*>
32     (AliEveEventManager::GetCurrent()->FindChild(name));
33   if (parent == 0)
34   {
35     parent = new TEveCompound(name);
36     parent->OpenCompound();
37     parent->SetMainColor(col);
38     AliEveEventManager::GetMaster()->AddElement(parent);
39   }
40   return parent;
41 }
42
43
44 //==============================================================================
45 // Functions to make a cross / ellipse / box
46 //==============================================================================
47
48 TEveStraightLineSet*
49 make_vertex_cross(const AliESDVertex* v, Bool_t use_sigma, Float_t fx, Float_t fy, Float_t fz)
50 {
51   Double_t x[3], e[3];
52   v->GetXYZ(x); v->GetSigmaXYZ(e);
53
54   TEveStraightLineSet* ls = new TEveStraightLineSet("Cross");
55   TString title;
56   if (use_sigma)
57   {
58     e[0] *= fx; e[1] *= fy; e[2] *= fz;
59     title += Form("+- %.1f*sigma_x, %.1f*sigma_y, %.1f*sigma_z", fx, fy, fz);
60   }
61   else
62   {
63     e[0] = fx; e[1] = fy; e[2] = fz;
64     title += Form("+- %.1f cm x %.1f cm x %.1f cm", fx, fy, fz);
65   }
66   title += Form("\nx=%.5f, y=%.5f, z=%.5f\nsx=%.5f, sy=%.5f, sz=%.5f",
67                 x[0], x[1], x[2], e[0], e[1], e[2]);
68   ls->SetTitle(title);
69
70   ls->AddLine(e[0], 0,    0,   -e[0], 0,    0);
71   ls->AddLine(0,    e[1], 0,    0,   -e[1], 0);
72   ls->AddLine(0,    0,    e[2], 0,    0,   -e[2]);
73
74   ls->RefMainTrans().SetPos(x);
75   return ls;
76 }
77
78 TEveStraightLineSet*
79 make_vertex_ellipse(const AliESDVertex* v, Bool_t use_sigma, Float_t fx, Float_t fy, Float_t fz)
80 {
81   Double_t x[3], e[3];
82   v->GetXYZ(x); v->GetSigmaXYZ(e);
83
84   TEveStraightLineSet* ls = new TEveStraightLineSet("Ellipse");
85   TString title;
86   if (use_sigma)
87   {
88     e[0] *= fx; e[1] *= fy; e[2] *= fz;
89     title += Form("+- %.1f*sigma_x, %.1f*sigma_y, %.1f sigma_z", fx, fy, fz);
90   }
91   else
92   {
93     e[0] = fx; e[1] = fy; e[2] = fz;
94     title += Form("+- %.1f cm x %.1f cm x %.1f cm", fx, fy, fz);
95   }
96   title += Form("\nx=%.5f, y=%.5f, z=%.5f\nsx=%.5f, sy=%.5f, sz=%.5f",
97                 x[0], x[1], x[2], e[0], e[1], e[2]);
98   ls->SetTitle(title);
99
100   const Int_t   N = 32;
101   const Float_t S = 2*TMath::Pi()/N;
102
103   Float_t a = e[0], b = e[1];
104   for (Int_t i = 0; i<N; i++)
105     ls->AddLine(a*TMath::Cos(i*S)  , b*TMath::Sin(i*S)  , 0,
106                 a*TMath::Cos(i*S+S), b*TMath::Sin(i*S+S), 0);
107
108   a = e[0]; b = e[2];
109   for (Int_t i = 0; i<N; i++)
110     ls->AddLine(a*TMath::Cos(i*S)  , 0, b*TMath::Sin(i*S),
111                 a*TMath::Cos(i*S+S), 0, b*TMath::Sin(i*S+S));
112
113   a = e[1]; b = e[2];
114   for (Int_t i = 0; i<N; i++)
115     ls->AddLine(0, a*TMath::Cos(i*S)  ,  b*TMath::Sin(i*S),
116                 0, a*TMath::Cos(i*S+S),  b*TMath::Sin(i*S+S));
117
118   ls->RefMainTrans().SetPos(x);
119   return ls;
120 }
121
122 TEveStraightLineSet*
123 make_vertex_box(const AliESDVertex* v, Bool_t use_sigma, Float_t fx, Float_t fy, Float_t fz)
124 {
125   Double_t x[3], e[3];
126   v->GetXYZ(x); v->GetSigmaXYZ(e);
127
128   TEveStraightLineSet* ls = new TEveStraightLineSet("Box");
129   TString title;
130   if (use_sigma)
131   {
132     e[0] *= fx; e[1] *= fy; e[2] *= fz;
133     title += Form("+- %.1f*sigma_x, %.1f*sigma_y, %.1f*sigma_z", fx, fy, fz);
134   }
135   else
136   {
137     e[0] = fx; e[1] = fy; e[2] = fz;
138     title += Form("+- %.1f cm x %.1f cm x %.1f cm", fx, fy, fz);
139   }
140   title += Form("\nx=%.5f, y=%.5f, z=%.5f\nsx=%.5f, sy=%.5f, sz=%.5f",
141                 x[0], x[1], x[2], e[0], e[1], e[2]);
142   ls->SetTitle(title);
143
144   // pos z
145   ls->AddLine( e[0],  e[1],  e[2],  e[0], -e[1],  e[2]);
146   ls->AddLine( e[0], -e[1],  e[2], -e[0], -e[1],  e[2]);
147   ls->AddLine(-e[0], -e[1],  e[2], -e[0],  e[1],  e[2]);
148   ls->AddLine(-e[0],  e[1],  e[2],  e[0],  e[1],  e[2]);
149   // lines along z
150   ls->AddLine( e[0],  e[1],  e[2],  e[0],  e[1], -e[2]);
151   ls->AddLine( e[0], -e[1],  e[2],  e[0], -e[1], -e[2]);
152   ls->AddLine(-e[0], -e[1],  e[2], -e[0], -e[1], -e[2]);
153   ls->AddLine(-e[0],  e[1],  e[2], -e[0],  e[1], -e[2]);
154   // neg z
155   ls->AddLine( e[0],  e[1], -e[2],  e[0], -e[1], -e[2]);
156   ls->AddLine( e[0], -e[1], -e[2], -e[0], -e[1], -e[2]);
157   ls->AddLine(-e[0], -e[1], -e[2], -e[0],  e[1], -e[2]);
158   ls->AddLine(-e[0],  e[1], -e[2],  e[0],  e[1], -e[2]);
159
160   ls->RefMainTrans().SetPos(x);
161   return ls;
162 }
163
164
165 //==============================================================================
166 // Element making functions
167 //==============================================================================
168
169 TEveStraightLineSet*
170 primary_vertex(Bool_t use_sigma=kTRUE, Float_t fx=1, Float_t fy=1, Float_t fz=1)
171 {
172   AliESDEvent  *esd = AliEveEventManager::AssertESD();
173   const AliESDVertex *pv  = esd->GetPrimaryVertex();
174   if ( ! pv->GetStatus()) {
175     Info("primary_vertex", "Primary vertex not available.");
176     return 0;
177   }
178
179   TEveStraightLineSet* ls = make_vertex_cross(pv, use_sigma, fx, fy, fz);
180   ls->ApplyVizTag("PVTX");
181   assert_vertex_parent("Primary Vertex", 7)->AddElement(ls);
182   gEve->Redraw3D();
183   return ls;
184 }
185
186 TEveStraightLineSet*
187 primary_vertex_spd(Bool_t use_sigma=kTRUE, Float_t fx=1, Float_t fy=1, Float_t fz=1)
188 {
189   AliESDEvent  *esd  = AliEveEventManager::AssertESD();
190   const AliESDVertex *spdv = esd->GetPrimaryVertexSPD();
191   if ( ! spdv->GetStatus()) {
192     Info("primary_vertex_spd", "Primary vertex SPD not available.");
193     return 0;
194   }
195
196   TEveStraightLineSet* ls = make_vertex_cross(spdv, use_sigma, fx, fy, fz);
197   ls->ApplyVizTag("PVTX SPD");
198   assert_vertex_parent("Primary Vertex SPD", 6)->AddElement(ls);
199   gEve->Redraw3D();
200   return ls;
201 }
202
203 TEveStraightLineSet*
204 primary_vertex_tpc(Bool_t use_sigma=kTRUE, Float_t fx=1, Float_t fy=1, Float_t fz=1)
205 {
206   AliESDEvent  *esd  = AliEveEventManager::AssertESD();
207   const AliESDVertex *tpcv = esd->GetPrimaryVertexTPC();
208   if ( ! tpcv->GetStatus()) {
209     Info("primary_vertex_tpc", "Primary vertex TPC not available.");
210     return 0;
211   }
212
213   TEveStraightLineSet* ls = make_vertex_cross(tpcv, use_sigma, fx, fy, fz);
214   ls->ApplyVizTag("PVTX TPC");
215   assert_vertex_parent("Primary Vertex TPC", 5)->AddElement(ls);
216   gEve->Redraw3D();
217   return ls;
218 }
219
220 //------------------------------------------------------------------------------
221 // Ellipse
222 //------------------------------------------------------------------------------
223
224 TEveStraightLineSet*
225 primary_vertex_ellipse(Bool_t use_sigma=kTRUE, Float_t fx=30, Float_t fy=30, Float_t fz=10)
226 {
227   AliESDEvent  *esd = AliEveEventManager::AssertESD();
228   const AliESDVertex *pv  = esd->GetPrimaryVertex();
229   if ( ! pv->GetStatus()) {
230     Info("primary_vertex_ellipse", "Primary vertex not available.");
231     return 0;
232   }
233
234   TEveStraightLineSet* ls = make_vertex_ellipse(pv, use_sigma, fx, fy, fz);
235   ls->ApplyVizTag("PVTX Ellipse");
236   assert_vertex_parent("Primary Vertex", 7)->AddElement(ls);
237   gEve->Redraw3D();
238   return ls;
239 }
240
241 TEveStraightLineSet*
242 primary_vertex_ellipse_spd(Bool_t use_sigma=kTRUE, Float_t fx=30, Float_t fy=30, Float_t fz=10)
243 {
244   AliESDEvent  *esd  = AliEveEventManager::AssertESD();
245   const AliESDVertex *spdv = esd->GetPrimaryVertexSPD();
246   if ( ! spdv->GetStatus()) {
247     Info("primary_vertex_ellipse_spd", "Primary vertex SPD not available.");
248     return 0;
249   }
250
251   TEveStraightLineSet* ls = make_vertex_ellipse(spdv, use_sigma, fx, fy, fz);
252   ls->ApplyVizTag("PVTX Ellipse SPD");
253   assert_vertex_parent("Primary Vertex SPD", 6)->AddElement(ls);
254   gEve->Redraw3D();
255   return ls;
256 }
257
258 TEveStraightLineSet*
259 primary_vertex_ellipse_tpc(Bool_t use_sigma=kTRUE, Float_t fx=30, Float_t fy=30, Float_t fz=10)
260 {
261   AliESDEvent  *esd  = AliEveEventManager::AssertESD();
262   const AliESDVertex *tpcv = esd->GetPrimaryVertexTPC();
263   if ( ! tpcv->GetStatus()) {
264     Info("primary_vertex_ellipse_tpc", "Primary vertex TPC not available.");
265     return 0;
266   }
267
268   TEveStraightLineSet* ls = make_vertex_ellipse(tpcv, use_sigma, fx, fy, fz);
269   ls->ApplyVizTag("PVTX Ellipse TPC");
270   assert_vertex_parent("Primary Vertex TPC", 5)->AddElement(ls);
271   gEve->Redraw3D();
272   return ls;
273 }
274
275 //------------------------------------------------------------------------------
276 // Box
277 //------------------------------------------------------------------------------
278
279 TEveStraightLineSet*
280 primary_vertex_box(Bool_t use_sigma=kTRUE, Float_t fx=30, Float_t fy=30, Float_t fz=10)
281 {
282   AliESDEvent  *esd = AliEveEventManager::AssertESD();
283   const AliESDVertex *pv  = esd->GetPrimaryVertex();
284   if ( ! pv->GetStatus()) {
285     Info("primary_vertex_box", "Primary vertex not available.");
286     return 0;
287   }
288
289   TEveStraightLineSet* ls = make_vertex_box(pv, use_sigma, fx, fy, fz);
290   ls->ApplyVizTag("PVTX Box");
291   assert_vertex_parent("Primary Vertex", 7)->AddElement(ls);
292   gEve->Redraw3D();
293   return ls;
294 }
295
296 TEveStraightLineSet*
297 primary_vertex_box_spd(Bool_t use_sigma=kTRUE, Float_t fx=30, Float_t fy=30, Float_t fz=10)
298 {
299   AliESDEvent  *esd  = AliEveEventManager::AssertESD();
300   const AliESDVertex *spdv = esd->GetPrimaryVertexSPD();
301   if ( ! spdv->GetStatus()) {
302     Info("primary_vertex_box_spd", "Primary vertex SPD not available.");
303     return 0;
304   }
305
306   TEveStraightLineSet* ls = make_vertex_box(spdv, use_sigma, fx, fy, fz);
307   ls->ApplyVizTag("PVTX Box SPD");
308   assert_vertex_parent("Primary Vertex SPD", 6)->AddElement(ls);
309   gEve->Redraw3D();
310   return ls;
311 }
312
313 TEveStraightLineSet*
314 primary_vertex_box_tpc(Bool_t use_sigma=kTRUE, Float_t fx=30, Float_t fy=30, Float_t fz=10)
315 {
316   AliESDEvent  *esd  = AliEveEventManager::AssertESD();
317   const AliESDVertex *tpcv = esd->GetPrimaryVertexTPC();
318   if ( ! tpcv->GetStatus()) {
319     Info("primary_vertex_box_tpc", "Primary vertex TPC not available.");
320     return 0;
321   }
322
323   TEveStraightLineSet* ls = make_vertex_box(tpcv, use_sigma, fx, fy, fz);
324   ls->ApplyVizTag("PVTX Box TPC");
325   assert_vertex_parent("Primary Vertex TPC", 5)->AddElement(ls);
326   gEve->Redraw3D();
327   return ls;
328 }