Introduction of the Copyright and cvs Log
[u/mrichter/AliRoot.git] / RALICE / AliVertex.cxx
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
16 /*
17 $Log$
18 */
19
20 #include "AliVertex.h"
21  
22 ClassImp(AliVertex) // Class implementation to enable ROOT I/O
23  
24 AliVertex::AliVertex()
25 {
26 // Default constructor
27 // All variables initialised to 0
28 // Initial maximum number of tracks is set to the default value
29 // Initial maximum number of sec. vertices is set to the default value
30  fNvmax=0;
31  fVertices=0;
32  Reset();
33  SetNtinit();
34  SetNvmax();
35 }
36 ///////////////////////////////////////////////////////////////////////////
37 AliVertex::AliVertex(Int_t n)
38 {
39 // Create a vertex to hold initially a maximum of n tracks
40 // All variables initialised to 0
41  fNvmax=0;
42  fVertices=0;
43  Reset();
44  if (n > 0)
45  {
46   SetNtinit(n);
47  }
48  else
49  {
50   cout << endl;
51   cout << " *AliVertex* Initial max. number of tracks entered : " << n << endl;
52   cout << " This is invalid. Default initial maximum will be used." << endl;
53   cout << endl;
54   SetNtinit();
55  }
56  SetNvmax();
57 }
58 ///////////////////////////////////////////////////////////////////////////
59 AliVertex::~AliVertex()
60 {
61 // Default destructor
62  if (fVertices) delete fVertices;
63  fVertices=0;
64 }
65 ///////////////////////////////////////////////////////////////////////////
66 void AliVertex::SetNvmax(Int_t n)
67 {
68 // Set the initial maximum number of (secondary) vertices
69  if (n > 0)
70  {
71   fNvmax=n;
72  }
73  else
74  {
75   fNvmax=1;
76  }
77  if (fVertices) delete fVertices;
78  fVertices=new TObjArray(fNvmax);
79 }
80 ///////////////////////////////////////////////////////////////////////////
81 void AliVertex::Reset()
82 {
83 // Reset all variables to 0
84 // The max. number of tracks is set to the initial value again
85 // The max. number of vertices is set to the default value again
86
87  AliJet::Reset();
88
89  fNvtx=0;
90  if (fNvmax>0) SetNvmax(fNvmax);
91 }
92 ///////////////////////////////////////////////////////////////////////////
93 void AliVertex::Add(AliJet& j)
94 {
95 // Add the tracks of a jet to the vertex
96  AliTrack* tj;
97  for (Int_t i=1; i<=j.GetNtracks(); i++)
98  {
99   tj=j.GetTrack(i);
100   AliJet::Add(tj);
101  }
102 }
103 ///////////////////////////////////////////////////////////////////////////
104 void AliVertex::Add(AliVertex& v)
105 {
106 // Add a (secondary) vertex to the current vertex.
107 // In case the maximum number of (secondary) vertices has been reached,
108 // the array space will be extended automatically
109 //
110 // Note : The 4-momentum of the current (primary) vertex
111 //        is updated automatically, but the track connecting
112 //        both vertices has to be entered separately by the user.
113 //
114  if (fNvtx == fNvmax) // Check if maximum vertex number is reached
115  {
116   fNvmax++;
117   fVertices->Expand(fNvmax);
118  }
119  
120  // Update 4-momentum for current vertex
121  fNvtx++;
122  fVertices->Add(&v);
123  (*(Ali4Vector*)this)+=v;
124 }
125 ///////////////////////////////////////////////////////////////////////////
126 void AliVertex::Info(TString f)
127 {
128 // Provide vertex information within the coordinate frame f
129  cout << " *AliVertex::Info* Invmass : " << GetInvmass()
130       << " Charge : " << GetCharge() << " Momentum : " << GetMomentum()
131       << " Ntracks : " << GetNtracks() << " Nvertices : " << fNvtx << endl;
132  cout << " ";
133  Ali4Vector::Info(f);
134  cout << "  Position";
135  AliPosition::Info(f); 
136
137 ///////////////////////////////////////////////////////////////////////////
138 void AliVertex::List(TString f)
139 {
140 // Provide primary track and sec. vertex information within the coordinate frame f
141
142  Info(f); // Information of the current vertex
143
144  // The tracks of this vertex
145  AliTrack* t; 
146  for (Int_t it=1; it<=GetNtracks(); it++)
147  {
148   t=GetTrack(it);
149   if (t)
150   {
151    cout << "  ---Track no. " << it << endl;
152    cout << " ";
153    t->Info(f); 
154   }
155   else
156   {
157    cout << " *AliVertex::List* Error : No track present." << endl; 
158   }
159  }
160
161  // The secondary vertices of this vertex
162  AliVertex* v; 
163  for (Int_t iv=1; iv<=GetNvertices(); iv++)
164  {
165   v=GetVertex(iv);
166   if (v)
167   {
168    cout << "  ---Level 1 sec. vertex no. " << iv << endl;
169    cout << " ";
170    v->Info(f); 
171   }
172   else
173   {
174    cout << " *AliVertex::List* Error : No sec. vertex present." << endl; 
175   }
176  }
177
178 ///////////////////////////////////////////////////////////////////////////
179 void AliVertex::ListAll(TString f)
180 {
181 // Provide complete (sec) vertex and (decay) track info within the coordinate frame f
182
183  Info(f); // Information of the current vertex
184
185  // The tracks of this vertex
186  AliTrack* t; 
187  for (Int_t it=1; it<=GetNtracks(); it++)
188  {
189   t=GetTrack(it);
190   if (t)
191   {
192    cout << "  ---Track no. " << it << endl;
193    cout << " ";
194    t->ListAll(f); 
195   }
196   else
197   {
198    cout << " *AliVertex::ListAll* Error : No track present." << endl; 
199   }
200  }
201
202  AliVertex* v=this;
203  Dump(v,1,f); // Information of all sec. vertices
204 }
205 //////////////////////////////////////////////////////////////////////////
206 void AliVertex::Dump(AliVertex* v,Int_t n,TString f)
207 {
208 // Recursively provide the info of all secondary vertices of this vertex
209  AliVertex* vs; 
210  for (Int_t iv=1; iv<=v->GetNvertices(); iv++)
211  {
212   vs=v->GetVertex(iv);
213   if (vs)
214   {
215    cout << "  ---Level " << n << " sec. vertex no. " << iv << endl;
216    cout << " ";
217    vs->Info(f); 
218
219    // The tracks of this vertex
220    AliTrack* t; 
221    for (Int_t it=1; it<=vs->GetNtracks(); it++)
222    {
223     t=vs->GetTrack(it);
224     if (t)
225     {
226      cout << "  ---Track no. " << it << endl;
227      cout << " ";
228      t->ListAll(f); 
229     }
230     else
231     {
232      cout << " *AliVertex::Dump* Error : No track present." << endl; 
233     }
234    }
235
236    // Go for next sec. vertex level of this sec. vertex recursively
237    Dump(vs,n+1,f);
238   }
239   else
240   {
241    cout << " *AliVertex::Dump* Error : No sec. vertex present." << endl; 
242   }
243  }
244
245 //////////////////////////////////////////////////////////////////////////
246 Int_t AliVertex::GetNvertices()
247 {
248 // Return the current number of (secondary) vertices
249  return fNvtx;
250 }
251 ///////////////////////////////////////////////////////////////////////////
252 AliVertex* AliVertex::GetVertex(Int_t i)
253 {
254 // Return the i-th (secondary) vertex of the current vertex
255  return (AliVertex*)fVertices->At(i-1);
256 }
257 ///////////////////////////////////////////////////////////////////////////