Introduce GetLifetime(Int_T kf) method until functionality provided by
[u/mrichter/AliRoot.git] / RALICE / AliVertex.cxx
CommitLineData
4c039060 1/**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3 * *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
6 * *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
15
f531a546 16// $Id$
4c039060 17
959fbac5 18///////////////////////////////////////////////////////////////////////////
19// Class AliVertex
20// Creation and investigation of an AliVertex.
21// An AliVertex can be constructed by adding AliTracks and/or AliJets.
22//
23// Note : Also (secondary) vertices can be added to a vertex.
24//
f34f4acb 25// To provide maximal flexibility to the user, two modes of vertex storage
26// are provided by means of the memberfunction SetVertexCopy().
27// The same holds for the storage of jets via SetJetCopy().
28//
29// a) SetVertexCopy(0) (which is the default).
30// Only the pointers of the 'added' vertices are stored.
31// This mode is typically used by making vertex studies based on a fixed list
32// of vertices which stays under user control or is contained for instance
33// in an AliEvent.
34// In this way the AliVertex just represents a 'logical structure' for the
35// physics analysis which can be embedded in e.g. an AliEvent or AliVertex.
36// Modifications made to the original vertices also affect the AliVertex objects
37// which are stored.
38// b) SetVertexCopy(1).
39// Of every 'added' vertex a private copy will be made of which the pointer
40// will be stored.
41// In this way the AliVertex represents an entity on its own and modifications
42// made to the original vertices do not affect the AliVertex objects which are
43// stored.
44// This mode will allow 'adding' many different AliVertex objects by
45// creating only one AliVertex instance in the main programme and using the
46// AliVertex::Reset() and AliVertex::AddTrack and parameter setting memberfunctions.
47//
959fbac5 48// Coding example to make 3 vertices v1, v2 and v3.
49// ------------------------------------------------
50// v1 contains the tracks 1,2,3 and 4
f34f4acb 51// v2 contains many different tracks
959fbac5 52// v3 contains the jets 1 and 2
53//
f34f4acb 54// AliTrack t1,t2,t3,t4;
959fbac5 55// ...
56// ... // code to fill the track data
57// ...
58//
59// AliJet j1,j2;
60// ...
61// ... // code to fill the jet data
62// ...
63//
f34f4acb 64// AliVertex v1;
65// v1.SetVertexCopy(1);
959fbac5 66//
f531a546 67// v1.AddTrack(t1);
68// v1.AddTrack(t2);
69// v1.AddTrack(t3);
70// v1.AddTrack(t4);
959fbac5 71//
72// Float_t r1[3]={2.4,0.1,-8.5};
73// v1.SetPosition(r1,"car");
74//
f34f4acb 75// AliVertex v2;
76// v2.SetTrackCopy(1);
77//
78// AliTrack* tx=new AliTrack();
79// for (Int_t i=0; i<10; i++)
80// {
81// ...
82// ... // code to fill the track data
83// ...
84// v2.AddTrack(tx);
85// tx->Reset();
86// }
959fbac5 87//
88// Float_t r2[3]={1.6,-3.2,5.7};
89// v2.SetPosition(r2,"car");
90//
91// AliVertex v3;
92//
f531a546 93// v3.AddJet(j1);
94// v3.AddJet(j2);
959fbac5 95//
96// Float_t r3[3]={6.2,4.8,1.3};
97// v3.SetPosition(r3,"car");
98//
99// v1.Info("sph");
100// v2.ListAll();
101// v3.List("cyl");
102//
103// Float_t e1=v1.GetEnergy();
104// Ali3Vector p1=v1.Get3Momentum();
105// Float_t loc[3];
106// v1.GetPosition(loc,"sph");
107// AliPosition r=v2.GetPosition();
108// r.Info();
109// Int_t nt=v2.GetNtracks();
110// AliTrack* tv=v2.GetTrack(1); // Access track number 1 of Vertex v2
111//
112// Specify the vertices v2 and v3 as secondary vertices of v1
113//
f531a546 114// v1.AddVertex(v2);
115// v1.AddVertex(v3);
959fbac5 116//
117// v1.List();
118//
119// Int_t nv=v1.GetNvtx();
120// AliVertex* vx=v1.GetVertex(1); // Access 1st secondary vertex of v1
121// Float_t e=vx->GetEnergy();
122//
123// Float_t M=v1.GetInvmass();
124//
125// Reconstruct Vertex v1 from scratch
126//
127// v1.Reset();
128// v1.SetNvmax(25); // Increase initial no. of sec. vertices
f531a546 129// v1.AddTrack(t3);
f34f4acb 130// v1.AddTrack(t4);
f531a546 131// v1.AddJet(j2);
959fbac5 132// Float_t pos[3]={7,9,4};
133// v1.SetPosition(pos,"car");
134//
135// Note : All quantities are in GeV, GeV/c or GeV/c**2
136//
137//--- Author: Nick van Eijndhoven 04-apr-1998 UU-SAP Utrecht
f531a546 138//- Modified: NvE $Date$ UU-SAP Utrecht
959fbac5 139///////////////////////////////////////////////////////////////////////////
140
d88f97cc 141#include "AliVertex.h"
142
143ClassImp(AliVertex) // Class implementation to enable ROOT I/O
144
145AliVertex::AliVertex()
146{
959fbac5 147// Default constructor.
148// All variables initialised to 0.
149// Initial maximum number of tracks is set to the default value.
150// Initial maximum number of sec. vertices is set to the default value.
d88f97cc 151 fNvmax=0;
152 fVertices=0;
29beb80d 153 fConnects=0;
f34f4acb 154 fVertexCopy=0;
155 fNjmax=0;
156 fJets=0;
157 fJetCopy=0;
d88f97cc 158 Reset();
159 SetNtinit();
160 SetNvmax();
f34f4acb 161 SetNjmax();
d88f97cc 162}
163///////////////////////////////////////////////////////////////////////////
164AliVertex::AliVertex(Int_t n)
165{
166// Create a vertex to hold initially a maximum of n tracks
167// All variables initialised to 0
168 fNvmax=0;
169 fVertices=0;
29beb80d 170 fConnects=0;
f34f4acb 171 fVertexCopy=0;
172 fNjmax=0;
173 fJets=0;
174 fJetCopy=0;
d88f97cc 175 Reset();
176 if (n > 0)
177 {
178 SetNtinit(n);
179 }
180 else
181 {
182 cout << endl;
183 cout << " *AliVertex* Initial max. number of tracks entered : " << n << endl;
184 cout << " This is invalid. Default initial maximum will be used." << endl;
185 cout << endl;
186 SetNtinit();
187 }
188 SetNvmax();
f34f4acb 189 SetNjmax();
d88f97cc 190}
191///////////////////////////////////////////////////////////////////////////
192AliVertex::~AliVertex()
193{
194// Default destructor
f34f4acb 195 if (fVertices)
196 {
197 if (fVertexCopy) fVertices->Delete();
198 delete fVertices;
199 fVertices=0;
200 }
29beb80d 201 if (fConnects)
202 {
203 fConnects->Delete();
204 delete fConnects;
205 fConnects=0;
206 }
f34f4acb 207 if (fJets)
208 {
209 if (fJetCopy) fJets->Delete();
210 delete fJets;
211 fJets=0;
212 }
d88f97cc 213}
214///////////////////////////////////////////////////////////////////////////
215void AliVertex::SetNvmax(Int_t n)
216{
217// Set the initial maximum number of (secondary) vertices
218 if (n > 0)
219 {
220 fNvmax=n;
221 }
222 else
223 {
224 fNvmax=1;
225 }
f34f4acb 226 if (fVertices)
227 {
228 if (fVertexCopy) fVertices->Delete();
229 delete fVertices;
230 fVertices=0;
231 }
232}
233///////////////////////////////////////////////////////////////////////////
234void AliVertex::SetNjmax(Int_t n)
235{
236// Set the initial maximum number of jets
237 if (n > 0)
238 {
239 fNjmax=n;
240 }
241 else
242 {
243 fNjmax=1;
244 }
245 if (fJets)
246 {
247 if (fJetCopy) fJets->Delete();
248 delete fJets;
249 fJets=0;
250 }
d88f97cc 251}
252///////////////////////////////////////////////////////////////////////////
253void AliVertex::Reset()
254{
255// Reset all variables to 0
256// The max. number of tracks is set to the initial value again
257// The max. number of vertices is set to the default value again
258
259 AliJet::Reset();
260
f531a546 261 Double_t a[3]={0,0,0};
262 SetPosition(a,"sph");
263 SetPositionErrors(a,"car");
264
d88f97cc 265 fNvtx=0;
266 if (fNvmax>0) SetNvmax(fNvmax);
29beb80d 267 if (fConnects)
268 {
269 fConnects->Delete();
270 delete fConnects;
271 fConnects=0;
272 }
f34f4acb 273
274 fNjets=0;
275 if (fNjmax>0) SetNjmax(fNjmax);
d88f97cc 276}
277///////////////////////////////////////////////////////////////////////////
f34f4acb 278void AliVertex::AddJet(AliJet& j,Int_t tracks)
d88f97cc 279{
f34f4acb 280// Add a jet (and its tracks) to the vertex
281// In case the maximum number of jets has been reached,
282// the array space will be extended automatically
283//
284// Note : By default the tracks of the jet are added to the current (primary)
285// vertex.
286// The automatic addition of the tracks of the jet can be suppressed
287// by specifying tracks=0. In this case only the AliJet object will
288// be stored according to the mode specified by SetJetCopy().
289// The latter will enable jet studies based on a fixed list of tracks
290// as contained e.g. in an AliVertex or AliEvent.
291 if (!fJets) fJets=new TObjArray(fNjmax);
292 if (fNjets == fNjmax) // Check if maximum jet number is reached
d88f97cc 293 {
f34f4acb 294 fNjmax++;
295 fJets->Expand(fNjmax);
296 }
297
298 // Add the jet to the list
299 fNjets++;
300 if (fJetCopy)
301 {
302 AliJet* jx=new AliJet(j);
303 fJets->Add(jx);
304 }
305 else
306 {
307 fJets->Add(&j);
308 }
309
310 // Add the tracks of the jet to this vertex
311 if (tracks)
312 {
313 AliTrack* tj;
314 for (Int_t i=1; i<=j.GetNtracks(); i++)
315 {
316 tj=j.GetTrack(i);
317 AddTrack(tj);
318 }
d88f97cc 319 }
320}
321///////////////////////////////////////////////////////////////////////////
f531a546 322void AliVertex::AddVertex(AliVertex& v,Int_t connect)
d88f97cc 323{
324// Add a (secondary) vertex to the current vertex.
325// In case the maximum number of (secondary) vertices has been reached,
326// the array space will be extended automatically
327//
29beb80d 328// Note : By default the 4-momentum and charge of the current (primary) vertex
329// are updated by automatically creating the track connecting
330// both vertices. The track parameters are taken from the
331// 4-momentum and charge of the secondary vertex.
332// The automatic creation of the connecting track and updating
333// of the (primary) vertex 4-momentum and charge can be suppressed
334// by specifying connect=0. In this case, however, the user
335// has to introduce the connecting track lateron by hand
336// explicitly in order to match the kinematics and charge.
d88f97cc 337//
f34f4acb 338 if (!fVertices) fVertices=new TObjArray(fNvmax);
d88f97cc 339 if (fNvtx == fNvmax) // Check if maximum vertex number is reached
340 {
341 fNvmax++;
342 fVertices->Expand(fNvmax);
343 }
29beb80d 344
345 // Add the linked (secondary) vertex to the list
d88f97cc 346 fNvtx++;
f34f4acb 347 if (fVertexCopy)
348 {
349 AliVertex* vx=new AliVertex(v);
350 fVertices->Add(vx);
351 }
352 else
353 {
354 fVertices->Add(&v);
355 }
29beb80d 356
357 // Create connecting track and update 4-momentum and charge for current vertex
358 if (connect)
359 {
360 AliPosition r1=GetPosition();
361 AliPosition r2=v.GetPosition();
362 Float_t q=v.GetCharge();
363 Ali3Vector p=v.Get3Momentum();
364 Double_t v2=v.GetInvariant();
365 Double_t dv2=v.Ali4Vector::GetResultError();
366
367 AliTrack* t=new AliTrack;
368 t->SetBeginPoint(r1);
369 t->SetEndPoint(r2);
370 t->SetCharge(q);
371 t->Set3Momentum(p);
372 t->SetInvariant(v2,dv2);
373
f34f4acb 374 AddTrack(t);
29beb80d 375
376 if (!fConnects) fConnects=new TObjArray(fNvmax);
377 fConnects->Add(t);
378 }
d88f97cc 379}
380///////////////////////////////////////////////////////////////////////////
381void AliVertex::Info(TString f)
382{
383// Provide vertex information within the coordinate frame f
384 cout << " *AliVertex::Info* Invmass : " << GetInvmass()
385 << " Charge : " << GetCharge() << " Momentum : " << GetMomentum()
f34f4acb 386 << " Ntracks : " << GetNtracks() << " Nvertices : " << fNvtx
387 << " Njets : " << fNjets << endl;
d88f97cc 388 cout << " ";
389 Ali4Vector::Info(f);
390 cout << " Position";
391 AliPosition::Info(f);
392}
393///////////////////////////////////////////////////////////////////////////
394void AliVertex::List(TString f)
395{
396// Provide primary track and sec. vertex information within the coordinate frame f
397
398 Info(f); // Information of the current vertex
399
400 // The tracks of this vertex
401 AliTrack* t;
402 for (Int_t it=1; it<=GetNtracks(); it++)
403 {
404 t=GetTrack(it);
405 if (t)
406 {
407 cout << " ---Track no. " << it << endl;
408 cout << " ";
409 t->Info(f);
410 }
411 else
412 {
413 cout << " *AliVertex::List* Error : No track present." << endl;
414 }
415 }
416
417 // The secondary vertices of this vertex
418 AliVertex* v;
419 for (Int_t iv=1; iv<=GetNvertices(); iv++)
420 {
421 v=GetVertex(iv);
422 if (v)
423 {
424 cout << " ---Level 1 sec. vertex no. " << iv << endl;
425 cout << " ";
426 v->Info(f);
427 }
428 else
429 {
430 cout << " *AliVertex::List* Error : No sec. vertex present." << endl;
431 }
432 }
433}
434///////////////////////////////////////////////////////////////////////////
435void AliVertex::ListAll(TString f)
436{
437// Provide complete (sec) vertex and (decay) track info within the coordinate frame f
438
439 Info(f); // Information of the current vertex
440
441 // The tracks of this vertex
442 AliTrack* t;
443 for (Int_t it=1; it<=GetNtracks(); it++)
444 {
445 t=GetTrack(it);
446 if (t)
447 {
448 cout << " ---Track no. " << it << endl;
449 cout << " ";
450 t->ListAll(f);
451 }
452 else
453 {
454 cout << " *AliVertex::ListAll* Error : No track present." << endl;
455 }
456 }
457
458 AliVertex* v=this;
459 Dump(v,1,f); // Information of all sec. vertices
460}
461//////////////////////////////////////////////////////////////////////////
462void AliVertex::Dump(AliVertex* v,Int_t n,TString f)
463{
464// Recursively provide the info of all secondary vertices of this vertex
465 AliVertex* vs;
466 for (Int_t iv=1; iv<=v->GetNvertices(); iv++)
467 {
468 vs=v->GetVertex(iv);
469 if (vs)
470 {
471 cout << " ---Level " << n << " sec. vertex no. " << iv << endl;
472 cout << " ";
473 vs->Info(f);
474
475 // The tracks of this vertex
476 AliTrack* t;
477 for (Int_t it=1; it<=vs->GetNtracks(); it++)
478 {
479 t=vs->GetTrack(it);
480 if (t)
481 {
482 cout << " ---Track no. " << it << endl;
483 cout << " ";
484 t->ListAll(f);
485 }
486 else
487 {
488 cout << " *AliVertex::Dump* Error : No track present." << endl;
489 }
490 }
491
492 // Go for next sec. vertex level of this sec. vertex recursively
493 Dump(vs,n+1,f);
494 }
495 else
496 {
497 cout << " *AliVertex::Dump* Error : No sec. vertex present." << endl;
498 }
499 }
500}
501//////////////////////////////////////////////////////////////////////////
502Int_t AliVertex::GetNvertices()
503{
504// Return the current number of (secondary) vertices
505 return fNvtx;
506}
507///////////////////////////////////////////////////////////////////////////
508AliVertex* AliVertex::GetVertex(Int_t i)
509{
510// Return the i-th (secondary) vertex of the current vertex
f34f4acb 511 if (!fVertices)
512 {
513 cout << " *AliVertex*::GetVertex* No (secondary) vertices present." << endl;
514 return 0;
515 }
516 else
517 {
518 if (i<=0 || i>fNvtx)
519 {
520 cout << " *AliVertex*::GetVertex* Invalid argument i : " << i
521 << " Nvtx = " << fNvtx << endl;
522 return 0;
523 }
524 else
525 {
526 return (AliVertex*)fVertices->At(i-1);
527 }
528 }
529}
530///////////////////////////////////////////////////////////////////////////
531void AliVertex::SetVertexCopy(Int_t j)
532{
533// (De)activate the creation of private copies of the added vertices.
534// j=0 ==> No private copies are made; pointers of original vertices are stored.
535// j=1 ==> Private copies of the vertices are made and these pointers are stored.
536//
537// Note : Once the storage contains pointer(s) to AliVertex objects one cannot
538// change the VertexCopy mode anymore.
539// To change the VertexCopy mode for an existing AliVertex containing
540// vertices one first has to invoke Reset().
541 if (!fVertices)
542 {
543 if (j==0 || j==1)
544 {
545 fVertexCopy=j;
546 }
547 else
548 {
549 cout << "*AliVertex::SetVertexCopy* Invalid argument : " << j << endl;
550 }
551 }
552 else
553 {
554 cout << "*AliVertex::SetVertexCopy* Storage already contained vertices."
555 << " ==> VertexCopy mode not changed." << endl;
556 }
557}
558///////////////////////////////////////////////////////////////////////////
559Int_t AliVertex::GetVertexCopy()
560{
561// Provide value of the VertexCopy mode.
562// 0 ==> No private copies are made; pointers of original vertices are stored.
563// 1 ==> Private copies of the vertices are made and these pointers are stored.
564 return fVertexCopy;
565}
566///////////////////////////////////////////////////////////////////////////
567Int_t AliVertex::GetNjets()
568{
569// Return the current number of jets
570 return fNjets;
571}
572///////////////////////////////////////////////////////////////////////////
573AliJet* AliVertex::GetJet(Int_t i)
574{
575// Return the i-th jet of the current vertex
576 if (!fJets)
577 {
578 cout << " *AliVertex*::GetJet* No jets present." << endl;
579 return 0;
580 }
581 else
582 {
583 if (i<=0 || i>fNjets)
584 {
585 cout << " *AliVertex*::GetJet* Invalid argument i : " << i
586 << " Njets = " << fNjets << endl;
587 return 0;
588 }
589 else
590 {
591 return (AliJet*)fJets->At(i-1);
592 }
593 }
594}
595///////////////////////////////////////////////////////////////////////////
596void AliVertex::SetJetCopy(Int_t j)
597{
598// (De)activate the creation of private copies of the added jets.
599// j=0 ==> No private copies are made; pointers of original jets are stored.
600// j=1 ==> Private copies of the jets are made and these pointers are stored.
601//
602// Note : Once the storage contains pointer(s) to AliJet objects one cannot
603// change the JetCopy mode anymore.
604// To change the JetCopy mode for an existing AliVertex containing
605// jets one first has to invoke Reset().
606 if (!fJets)
607 {
608 if (j==0 || j==1)
609 {
610 fJetCopy=j;
611 }
612 else
613 {
614 cout << "*AliVertex::SetJetCopy* Invalid argument : " << j << endl;
615 }
616 }
617 else
618 {
619 cout << "*AliVertex::SetJetCopy* Storage already contained jets."
620 << " ==> JetCopy mode not changed." << endl;
621 }
622}
623///////////////////////////////////////////////////////////////////////////
624Int_t AliVertex::GetJetCopy()
625{
626// Provide value of the JetCopy mode.
627// 0 ==> No private copies are made; pointers of original jets are stored.
628// 1 ==> Private copies of the jets are made and these pointers are stored.
629 return fJetCopy;
d88f97cc 630}
631///////////////////////////////////////////////////////////////////////////