]> git.uio.no Git - u/mrichter/AliRoot.git/blob - RALICE/AliVertex.cxx
05-dec-2003 NvE Memberfunction SetStable introduced in AliCollider for the user's...
[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 // $Id$
17
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 //
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 //
37 //    Note :
38 //    Modifications made to the original vertices also affect the AliVertex objects
39 //    which are stored.
40 // 
41 // b) SetVertexCopy(1).
42 //    Of every 'added' vertex a private copy will be made of which the pointer
43 //    will be stored.
44 //    In this way the AliVertex represents an entity on its own and modifications
45 //    made to the original vertices do not affect the AliVertex objects which are
46 //    stored. 
47 //    This mode will allow 'adding' many different AliVertex objects by
48 //    creating only one AliVertex instance in the main programme and using the
49 //    AliVertex::Reset, AliVertex::AddTrack and parameter setting memberfunctions.
50 //
51 // See also the documentation provided for the memberfunction SetOwner(). 
52 //
53 // Coding example to make 3 vertices v1, v2 and v3.
54 // ------------------------------------------------
55 // v1 contains the tracks 1,2,3 and 4
56 // v2 contains many different tracks
57 // v3 contains the jets 1 and 2
58 //
59 //        AliTrack t1,t2,t3,t4;
60 //         ...
61 //         ... // code to fill the track data
62 //         ...
63 //
64 //        AliJet j1,j2;
65 //         ...
66 //         ... // code to fill the jet data
67 //         ...
68 //
69 //        AliVertex v1;
70 //        v1.SetVertexCopy(1);
71 //
72 //        v1.AddTrack(t1);
73 //        v1.AddTrack(t2);
74 //        v1.AddTrack(t3);
75 //        v1.AddTrack(t4);
76 //
77 //        Float_t r1[3]={2.4,0.1,-8.5};
78 //        v1.SetPosition(r1,"car");
79 //
80 //        AliVertex v2;
81 //        v2.SetTrackCopy(1);
82 //
83 //        AliTrack* tx=new AliTrack();
84 //        for (Int_t i=0; i<10; i++)
85 //        {
86 //         ...
87 //         ... // code to fill the track data
88 //         ...
89 //         v2.AddTrack(tx);
90 //         tx->Reset(); 
91 //        }
92 //
93 //        Float_t r2[3]={1.6,-3.2,5.7};
94 //        v2.SetPosition(r2,"car");
95 //
96 //        AliVertex v3;
97 //
98 //        v3.AddJet(j1);
99 //        v3.AddJet(j2);
100 //
101 //        Float_t r3[3]={6.2,4.8,1.3};
102 //        v3.SetPosition(r3,"car");
103 //
104 //        v1.Data("sph");
105 //        v2.ListAll();
106 //        v3.List("cyl");
107 //
108 //        Float_t e1=v1.GetEnergy();
109 //        Ali3Vector p1=v1.Get3Momentum();
110 //        Float_t loc[3];
111 //        v1.GetPosition(loc,"sph");
112 //        AliPosition r=v2.GetPosition();
113 //        r.Data(); 
114 //        Int_t nt=v2.GetNtracks();
115 //        AliTrack* tv=v2.GetTrack(1); // Access track number 1 of Vertex v2
116 //
117 // Specify the vertices v2 and v3 as secondary vertices of v1
118 //
119 //        v1.AddVertex(v2);
120 //        v1.AddVertex(v3);
121 //
122 //        v1.List();
123 //
124 //        Int_t nv=v1.GetNvtx();
125 //        AliVertex* vx=v1.GetVertex(1); // Access 1st secondary vertex of v1
126 //        Float_t e=vx->GetEnergy();
127 //
128 //        Float_t M=v1.GetInvmass(); 
129 //
130 // Reconstruct Vertex v1 from scratch
131 //
132 //        v1.Reset();
133 //        v1.SetNvmax(25); // Increase initial no. of sec. vertices
134 //        v1.AddTrack(t3);
135 //        v1.AddTrack(t4);
136 //        v1.AddJet(j2);
137 //        Float_t pos[3]={7,9,4};
138 //        v1.SetPosition(pos,"car");
139 //
140 // Note : All quantities are in GeV, GeV/c or GeV/c**2
141 //
142 //--- Author: Nick van Eijndhoven 04-apr-1998 UU-SAP Utrecht
143 //- Modified: NvE $Date$ UU-SAP Utrecht
144 ///////////////////////////////////////////////////////////////////////////
145
146 #include "AliVertex.h"
147 #include "Riostream.h"
148  
149 ClassImp(AliVertex) // Class implementation to enable ROOT I/O
150  
151 AliVertex::AliVertex() : AliJet(),AliPosition()
152 {
153 // Default constructor.
154 // All variables initialised to 0.
155 // Initial maximum number of tracks is set to the default value.
156 // Initial maximum number of sec. vertices is set to the default value.
157  Init();
158  Reset();
159  SetNvmax();
160  SetNjmax();
161 }
162 ///////////////////////////////////////////////////////////////////////////
163 void AliVertex::Init()
164 {
165 // Initialisation of pointers etc...
166  fNvmax=0;
167  fVertices=0;
168  fConnects=0;
169  fVertexCopy=0;
170  fNjmax=0;
171  fJets=0;
172  fJetTracks=0;
173  fJetCopy=0;
174  fLines=0;
175 }
176 ///////////////////////////////////////////////////////////////////////////
177 AliVertex::AliVertex(Int_t n) : AliJet(n),AliPosition()
178 {
179 // Create a vertex to hold initially a maximum of n tracks
180 // All variables initialised to 0
181  if (n<=0)
182  {
183   cout << " *** This AliJet initialisation was invoked via the AliVertex ctor." << endl;
184  }
185  Init();
186  Reset();
187  SetNvmax();
188  SetNjmax();
189 }
190 ///////////////////////////////////////////////////////////////////////////
191 AliVertex::~AliVertex()
192 {
193 // Default destructor
194  if (fVertices)
195  {
196   delete fVertices;
197   fVertices=0;
198  }
199  if (fConnects)
200  {
201   delete fConnects;
202   fConnects=0;
203  }
204  if (fJets)
205  {
206   delete fJets;
207   fJets=0;
208  }
209  if (fJetTracks)
210  {
211   delete fJetTracks;
212   fJetTracks=0;
213  }
214  if (fLines)
215  {
216   delete fLines;
217   fLines=0;
218  }
219 }
220 ///////////////////////////////////////////////////////////////////////////
221 void AliVertex::SetOwner(Bool_t own)
222 {
223 // Set ownership of all added objects. 
224 // The default parameter is own=kTRUE.
225 //
226 // Invokation of this memberfunction also sets all the copy modes
227 // (e.g. TrackCopy & co.) according to the value of own.
228 //
229 // This function (with own=kTRUE) is particularly useful when reading data
230 // from a tree/file, since Reset() will then actually remove all the
231 // added objects from memory irrespective of the copy mode settings
232 // during the tree/file creation process. In this way it provides a nice way
233 // of preventing possible memory leaks in the reading/analysis process.
234 //
235 // In addition this memberfunction can also be used as a shortcut to set all
236 // copy modes in one go during a tree/file creation process.
237 // However, in this case the user has to take care to only set/change the
238 // ownership (and copy mode) for empty objects (e.g. newly created objects
239 // or after invokation of the Reset() memberfunction) otherwise it will
240 // very likely result in inconsistent destructor behaviour.
241
242  Int_t mode=1;
243  if (!own) mode=0;
244  if (fVertices) fVertices->SetOwner(own);
245  fVertexCopy=mode;
246  if (fJets) fJets->SetOwner(own);
247  fJetCopy=mode;
248
249  AliJet::SetOwner(own);
250 }
251 ///////////////////////////////////////////////////////////////////////////
252 AliVertex::AliVertex(AliVertex& v) : AliJet(v.fNtinit),AliPosition(v)
253 {
254 // Copy constructor
255  Init();
256  fNvtx=0;
257  fNjets=0;
258  SetNvmax(v.fNvmax);
259  SetNjmax(v.fNjmax);
260  SetTrackCopy(v.GetTrackCopy());
261  SetVertexCopy(v.GetVertexCopy());
262  SetJetCopy(v.GetJetCopy());
263  SetId(v.GetId());
264
265  // Copy all tracks except the ones coming from jets
266  AliTrack* tx=0;
267  Int_t jetflag=0,connect=0;
268  AliTrack* tx2=0;
269  for (Int_t it=1; it<=v.GetNtracks(); it++)
270  {
271   tx=v.GetTrack(it);
272   if (tx)
273   {
274    jetflag=v.IsJetTrack(tx);
275    connect=v.IsConnectTrack(tx);
276
277    if (!jetflag && !connect) AddTrack(tx);
278
279    if (connect)
280    {
281     if (!fConnects)
282     {
283      fConnects=new TObjArray(fNvmax);
284      if (!fTrackCopy) fConnects->SetOwner();
285     }
286     tx2=new AliTrack(*tx);
287     fConnects->Add(tx2);
288     AddTrack(tx2,0);
289    } 
290   }
291  }
292
293  // Copy all the (secondary) vertices without re-creating connecting tracks
294  // The connecting tracks have already been copied above
295  AliVertex* vx=0;
296  for (Int_t iv=1; iv<=v.GetNvertices(); iv++)
297  {
298   vx=v.GetVertex(iv);
299   if (vx) AddVertex(vx,0); 
300  }
301
302  // Copy all the jets including the jet tracks for these jets for which
303  // this was also the case in the original vertex
304  AliJet* jx=0;
305  for (Int_t ij=1; ij<=v.GetNjets(); ij++)
306  {
307   jx=v.GetJet(ij);
308   if (jx)
309   {
310    jetflag=0;
311    if (jx->GetNtracks())
312    {
313     tx=jx->GetTrack(1);
314     if (tx)
315     {
316      jetflag=v.IsJetTrack(tx);
317     }
318    }
319    AddJet(jx,jetflag);
320   } 
321  }
322 }
323 ///////////////////////////////////////////////////////////////////////////
324 void AliVertex::SetNvmax(Int_t n)
325 {
326 // Set the initial maximum number of (secondary) vertices
327  if (n > 0)
328  {
329   fNvmax=n;
330  }
331  else
332  {
333   fNvmax=1;
334  }
335  if (fVertices)
336  {
337   delete fVertices;
338   fVertices=0;
339  }
340 }
341 ///////////////////////////////////////////////////////////////////////////
342 void AliVertex::SetNjmax(Int_t n)
343 {
344 // Set the initial maximum number of jets
345  if (n > 0)
346  {
347   fNjmax=n;
348  }
349  else
350  {
351   fNjmax=1;
352  }
353  if (fJets)
354  {
355   delete fJets;
356   fJets=0;
357  }
358 }
359 ///////////////////////////////////////////////////////////////////////////
360 void AliVertex::Reset()
361 {
362 // Reset all variables to 0 and reset all stored vertex and jet lists.
363 // The max. number of tracks is set to the initial value again
364 // The max. number of vertices is set to the default value again
365 // The max. number of jets is set to the default value again
366
367  AliJet::Reset();
368
369  Double_t a[3]={0,0,0};
370  SetPosition(a,"sph");
371  SetPositionErrors(a,"car");
372
373  fNvtx=0;
374  if (fNvmax>0) SetNvmax(fNvmax);
375  if (fConnects)
376  {
377   delete fConnects;
378   fConnects=0;
379  }
380
381  fNjets=0;
382  if (fNjmax>0) SetNjmax(fNjmax);
383  if (fJetTracks)
384  {
385   delete fJetTracks;
386   fJetTracks=0;
387  }
388  
389  if (fLines)
390  {
391   delete fLines;
392   fLines=0;
393  }
394 }
395 ///////////////////////////////////////////////////////////////////////////
396 void AliVertex::ResetVertices()
397 {
398 // Reset the stored vertex list and delete all connecting tracks which
399 // were generated automatically via connect=1 in AddVertex().
400 // The max. number of vertices is set to the default value again.
401 // All physics quantities are updated according to the removal of the
402 // connecting tracks.
403  AliTrack* t;
404  if (fConnects)
405  {
406   for (Int_t i=0; i<=fConnects->GetLast(); i++)
407   {
408    t=(AliTrack*)fConnects->At(i);
409    AliTrack* test=(AliTrack*)fTracks->Remove(t);
410    if (test)
411    {
412     fNtrk--;
413     (Ali4Vector&)(*this)-=(Ali4Vector&)(*t);
414     fQ-=t->GetCharge();
415     if (fTrackCopy) delete t;
416    }
417   }
418   fTracks->Compress();
419  }
420
421  fNvtx=0;
422  if (fNvmax>0) SetNvmax(fNvmax);
423  if (fConnects)
424  {
425   delete fConnects;
426   fConnects=0;
427  }
428 }
429 ///////////////////////////////////////////////////////////////////////////
430 void AliVertex::AddJet(AliJet& j,Int_t tracks)
431 {
432 // Add a jet (and its tracks) to the vertex
433 // In case the maximum number of jets has been reached,
434 // the array space will be extended automatically
435 //
436 // Note : By default the tracks of the jet are added to the current (primary)
437 //        vertex.
438 //        The automatic addition of the tracks of the jet can be suppressed
439 //        by specifying tracks=0. In this case only the AliJet object will
440 //        be stored according to the mode specified by SetJetCopy().
441 //        The latter will enable jet studies based on a fixed list of tracks
442 //        as contained e.g. in an AliVertex or AliEvent. 
443 //
444 // In case a private copy is made, this is performed via the Clone() memberfunction.
445 // All AliJet and derived classes have the default TObject::Clone() memberfunction.
446 // However, derived classes generally contain an internal data structure which may
447 // include pointers to other objects. Therefore it is recommended to provide
448 // for all derived classes a specific copy constructor and override the default Clone()
449 // memberfunction using this copy constructor.
450 // An example for this may be seen from AliJet.   
451
452  if (!fJets)
453  {
454   fJets=new TObjArray(fNjmax);
455   if (fJetCopy) fJets->SetOwner();
456  }
457  if (fNjets == fNjmax) // Check if maximum jet number is reached
458  {
459   fNjmax++;
460   fJets->Expand(fNjmax);
461  }
462
463  // Add the jet to the list 
464  AliJet* jx=&j;
465  if (fJetCopy) jx=(AliJet*)j.Clone();
466
467  if (jx)
468  {
469   fNjets++;
470   fJets->Add(jx); 
471  }
472
473  // Add the tracks of the jet to this vertex
474  if (tracks)
475  {
476   if (!fJetTracks)
477   {
478    fJetTracks=new TObjArray();
479   }
480   Int_t copy=1-(jx->GetTrackCopy());
481   AliTrack* tj;
482   for (Int_t i=1; i<=jx->GetNtracks(); i++)
483   {
484    tj=jx->GetTrack(i);
485    if (tj)
486    {
487     AddTrack(tj,copy);
488     fJetTracks->Add(tj);
489    }
490   }
491  }
492 }
493 ///////////////////////////////////////////////////////////////////////////
494 void AliVertex::AddVertex(AliVertex& v,Int_t connect)
495 {
496 // Add a (secondary) vertex to the current vertex.
497 // In case the maximum number of (secondary) vertices has been reached,
498 // the array space will be extended automatically
499 //
500 // Note : By default the 4-momentum and charge of the current (primary) vertex
501 //        are updated by automatically creating the track connecting
502 //        both vertices. The track parameters are taken from the
503 //        4-momentum and charge of the secondary vertex.
504 //        The automatic creation of the connecting track and updating
505 //        of the (primary) vertex 4-momentum and charge can be suppressed
506 //        by specifying connect=0. In this case, however, the user
507 //        has to introduce the connecting track lateron by hand
508 //        explicitly in order to match the kinematics and charge.
509 //
510 // In case a private copy is made, this is performed via the Clone() memberfunction.
511 // All AliVertex and derived classes have the default TObject::Clone() memberfunction.
512 // However, derived classes generally contain an internal data structure which may
513 // include pointers to other objects. Therefore it is recommended to provide
514 // for all derived classes a specific copy constructor and override the default Clone()
515 // memberfunction using this copy constructor.
516 // An example for this may be seen from AliVertex.   
517
518  if (!fVertices)
519  {
520   fVertices=new TObjArray(fNvmax);
521   if (fVertexCopy) fVertices->SetOwner();
522  }
523  if (fNvtx == fNvmax) // Check if maximum vertex number is reached
524  {
525   fNvmax++;
526   fVertices->Expand(fNvmax);
527  }
528
529  // Add the linked (secondary) vertex to the list 
530  AliVertex* vx=&v;
531  if (fVertexCopy) vx=(AliVertex*)v.Clone();
532
533  if (vx)
534  {
535   fNvtx++;
536   fVertices->Add(vx);
537  } 
538
539  // Create connecting track and update 4-momentum and charge for current vertex
540  if (connect)
541  {
542   AliTrack* t=new AliTrack();
543   t->SetBeginPoint(GetPosition());
544   t->SetEndPoint(v.GetPosition());
545   t->SetCharge(v.GetCharge());
546   t->Set4Momentum((Ali4Vector&)v);
547
548   AddTrack(t,0);
549
550   if (!fConnects)
551   {
552    fConnects=new TObjArray(fNvmax);
553    if (!fTrackCopy) fConnects->SetOwner();
554   }
555   fConnects->Add(t);
556  }
557 }
558 ///////////////////////////////////////////////////////////////////////////
559 void AliVertex::Data(TString f)
560 {
561 // Provide vertex information within the coordinate frame f
562  cout << " *AliVertex::Data* Name : " << GetName() << " Title : " << GetTitle() << endl;
563  cout << " Id : " << fUserId << " Invmass : " << GetInvmass()
564       << " Charge : " << GetCharge() << " Momentum : " << GetMomentum()
565       << " Ntracks : " << GetNtracks() << " Nvertices : " << fNvtx 
566       << " Njets : " << fNjets << endl;
567  cout << " ";
568  Ali4Vector::Data(f);
569  cout << "  Position";
570  AliPosition::Data(f); 
571
572 ///////////////////////////////////////////////////////////////////////////
573 void AliVertex::List(TString f)
574 {
575 // Provide primary track and sec. vertex information within the coordinate frame f
576
577  Data(f); // Information of the current vertex
578
579  // The tracks of this vertex
580  AliTrack* t; 
581  for (Int_t it=1; it<=GetNtracks(); it++)
582  {
583   t=GetTrack(it);
584   if (t)
585   {
586    cout << "  ---Track no. " << it << endl;
587    cout << " ";
588    t->Data(f); 
589   }
590   else
591   {
592    cout << " *AliVertex::List* Error : No track present." << endl; 
593   }
594  }
595
596  // The secondary vertices of this vertex
597  AliVertex* v; 
598  for (Int_t iv=1; iv<=GetNvertices(); iv++)
599  {
600   v=GetVertex(iv);
601   if (v)
602   {
603    cout << "  ---Level 1 sec. vertex no. " << iv << endl;
604    cout << " ";
605    v->Data(f); 
606   }
607   else
608   {
609    cout << " *AliVertex::List* Error : No sec. vertex present." << endl; 
610   }
611  }
612
613 ///////////////////////////////////////////////////////////////////////////
614 void AliVertex::ListAll(TString f)
615 {
616 // Provide complete (sec) vertex and (decay) track info within the coordinate frame f
617
618  Data(f); // Information of the current vertex
619
620  // The tracks of this vertex
621  AliTrack* t; 
622  for (Int_t it=1; it<=GetNtracks(); it++)
623  {
624   t=GetTrack(it);
625   if (t)
626   {
627    cout << "  ---Track no. " << it << endl;
628    cout << " ";
629    t->ListAll(f); 
630   }
631   else
632   {
633    cout << " *AliVertex::ListAll* Error : No track present." << endl; 
634   }
635  }
636
637  AliVertex* v=this;
638  Dumps(v,1,f); // Information of all sec. vertices
639 }
640 //////////////////////////////////////////////////////////////////////////
641 void AliVertex::Dumps(AliVertex* v,Int_t n,TString f)
642 {
643 // Recursively provide the info of all secondary vertices of this vertex
644  AliVertex* vs; 
645  for (Int_t iv=1; iv<=v->GetNvertices(); iv++)
646  {
647   vs=v->GetVertex(iv);
648   if (vs)
649   {
650    cout << "  ---Level " << n << " sec. vertex no. " << iv << endl;
651    cout << " ";
652    vs->Data(f); 
653
654    // The tracks of this vertex
655    AliTrack* t; 
656    for (Int_t it=1; it<=vs->GetNtracks(); it++)
657    {
658     t=vs->GetTrack(it);
659     if (t)
660     {
661      cout << "  ---Track no. " << it << endl;
662      cout << " ";
663      t->ListAll(f); 
664     }
665     else
666     {
667      cout << " *AliVertex::Dumps* Error : No track present." << endl; 
668     }
669    }
670
671    // Go for next sec. vertex level of this sec. vertex recursively
672    Dumps(vs,n+1,f);
673   }
674   else
675   {
676    cout << " *AliVertex::Dumps* Error : No sec. vertex present." << endl; 
677   }
678  }
679
680 //////////////////////////////////////////////////////////////////////////
681 Int_t AliVertex::GetNvertices()
682 {
683 // Return the current number of (secondary) vertices
684  return fNvtx;
685 }
686 ///////////////////////////////////////////////////////////////////////////
687 AliVertex* AliVertex::GetVertex(Int_t i)
688 {
689 // Return the i-th (secondary) vertex of the current vertex
690  if (!fVertices)
691  {
692   cout << " *AliVertex*::GetVertex* No (secondary) vertices present." << endl;
693   return 0;
694  }
695  else
696  {
697   if (i<=0 || i>fNvtx)
698   {
699    cout << " *AliVertex*::GetVertex* Invalid argument i : " << i
700         << " Nvtx = " << fNvtx << endl;
701    return 0;
702   }
703   else
704   {
705    return (AliVertex*)fVertices->At(i-1);
706   }
707  }
708 }
709 ///////////////////////////////////////////////////////////////////////////
710 AliVertex* AliVertex::GetIdVertex(Int_t id)
711 {
712 // Return the (sec.) vertex with user identifier "id"
713  AliVertex* vx=0;
714  AliVertex* v=0;
715  if (!fVertices)
716  {
717   cout << " *AliVertex*::GetIdVertex* No (secondary) vertices present." << endl;
718   return 0;
719  }
720  else
721  {
722   for (Int_t i=0; i<fNvtx; i++)
723   {
724    vx=(AliVertex*)fVertices->At(i);
725    if (id == vx->GetId()) v=vx;
726   }
727   return v;
728  }
729 }
730 ///////////////////////////////////////////////////////////////////////////
731 void AliVertex::SetVertexCopy(Int_t j)
732 {
733 // (De)activate the creation of private copies of the added vertices.
734 // j=0 ==> No private copies are made; pointers of original vertices are stored.
735 // j=1 ==> Private copies of the vertices are made and these pointers are stored.
736 //
737 // Note : Once the storage contains pointer(s) to AliVertex objects one cannot
738 //        change the VertexCopy mode anymore.
739 //        To change the VertexCopy mode for an existing AliVertex containing
740 //        vertices one first has to invoke Reset().
741  if (!fVertices)
742  {
743   if (j==0 || j==1)
744   {
745    fVertexCopy=j;
746   }
747   else
748   {
749    cout << "*AliVertex::SetVertexCopy* Invalid argument : " << j << endl;
750   }
751  }
752  else
753  {
754   cout << "*AliVertex::SetVertexCopy* Storage already contained vertices."
755        << "  ==> VertexCopy mode not changed." << endl; 
756  }
757 }
758 ///////////////////////////////////////////////////////////////////////////
759 Int_t AliVertex::GetVertexCopy()
760 {
761 // Provide value of the VertexCopy mode.
762 // 0 ==> No private copies are made; pointers of original vertices are stored.
763 // 1 ==> Private copies of the vertices are made and these pointers are stored.
764  return fVertexCopy;
765 }
766 ///////////////////////////////////////////////////////////////////////////
767 Int_t AliVertex::GetNjets()
768 {
769 // Return the current number of jets
770  return fNjets;
771 }
772 ///////////////////////////////////////////////////////////////////////////
773 AliJet* AliVertex::GetJet(Int_t i)
774 {
775 // Return the i-th jet of the current vertex
776  if (!fJets)
777  {
778   cout << " *AliVertex*::GetJet* No jets present." << endl;
779   return 0;
780  }
781  else
782  {
783   if (i<=0 || i>fNjets)
784   {
785    cout << " *AliVertex*::GetJet* Invalid argument i : " << i
786         << " Njets = " << fNjets << endl;
787    return 0;
788   }
789   else
790   {
791    return (AliJet*)fJets->At(i-1);
792   }
793  }
794 }
795 ///////////////////////////////////////////////////////////////////////////
796 AliJet* AliVertex::GetIdJet(Int_t id)
797 {
798 // Return the jet with user identifier "id"
799  AliJet* jx=0;
800  AliJet* j=0;
801  if (!fJets)
802  {
803   cout << " *AliVertex*::GetIdJet* No jets present." << endl;
804   return 0;
805  }
806  else
807  {
808   for (Int_t i=0; i<fNjets; i++)
809   {
810    jx=(AliJet*)fJets->At(i);
811    if (id == jx->GetId()) j=jx;
812   }
813   return j;
814  }
815 }
816 ///////////////////////////////////////////////////////////////////////////
817 void AliVertex::SetJetCopy(Int_t j)
818 {
819 // (De)activate the creation of private copies of the added jets.
820 // j=0 ==> No private copies are made; pointers of original jets are stored.
821 // j=1 ==> Private copies of the jets are made and these pointers are stored.
822 //
823 // Note : Once the storage contains pointer(s) to AliJet objects one cannot
824 //        change the JetCopy mode anymore.
825 //        To change the JetCopy mode for an existing AliVertex containing
826 //        jets one first has to invoke Reset().
827  if (!fJets)
828  {
829   if (j==0 || j==1)
830   {
831    fJetCopy=j;
832   }
833   else
834   {
835    cout << "*AliVertex::SetJetCopy* Invalid argument : " << j << endl;
836   }
837  }
838  else
839  {
840   cout << "*AliVertex::SetJetCopy* Storage already contained jets."
841        << "  ==> JetCopy mode not changed." << endl; 
842  }
843 }
844 ///////////////////////////////////////////////////////////////////////////
845 Int_t AliVertex::GetJetCopy()
846 {
847 // Provide value of the JetCopy mode.
848 // 0 ==> No private copies are made; pointers of original jets are stored.
849 // 1 ==> Private copies of the jets are made and these pointers are stored.
850  return fJetCopy;
851 }
852 ///////////////////////////////////////////////////////////////////////////
853 Int_t AliVertex::IsConnectTrack(AliTrack* t)
854 {
855 // Indicate whether a track from the tracklist was created via the
856 // connection of a (secondary) vertex or not.
857 // In case the track was the result of (secondary) vertex addition the
858 // return value is 1, otherwise the value 0 will be returned.
859  Int_t connect=0;
860  if (fConnects)
861  {
862   if (fConnects->FindObject(t)) connect=1;
863  }
864  return connect;
865 }
866 ///////////////////////////////////////////////////////////////////////////
867 Int_t AliVertex::IsJetTrack(AliTrack* t)
868 {
869 // Indicate whether a track from the tracklist was created via the
870 // addition of a jet or not.
871 // In case the track was the result of jet addition the return value is 1,
872 // otherwise the value 0 will be returned.
873  Int_t jetflag=0;
874  if (fJetTracks)
875  {
876   if (fJetTracks->FindObject(t)) jetflag=1;
877  }
878  return jetflag;
879 }
880 ///////////////////////////////////////////////////////////////////////////
881 void AliVertex::Draw(Int_t secs,Int_t cons,Int_t jets)
882 {
883 // 3-Dimensional visualisation of an AliVertex with its attributes.
884 // The displayed tracklength is proportional to the momentum of the track.
885 //
886 // Color conventions :
887 // -------------------
888 // positive track : red
889 // neutral  track : green
890 // negative track : blue
891 // jet-track      : magenta (if explicit marking selected)
892 //
893 // secs = 1 --> Draw secondary vertices. (Default)
894 //        0 --> Don't draw secondary vertices.
895 //
896 // cons = 1 --> Draw (auto generated) connecting tracks. (Default) 
897 //        0 --> Don't draw (auto generated) connecting tracks.
898 //                  
899 // jets = 1 --> Mark tracks belonging to jets.
900 //        0 --> Don't mark jet-tracks. (Default)
901 //
902 // Notes :
903 // -------
904 // Auto generated connecting tracks will be drawn as thin lines.
905 // Tracks belonging to jets will be marked as somewhat thinner magenta lines.
906 // This memberfunction is used recursively.
907 //
908  Double_t vec[3]={0,0,0};
909  AliTrack* tx=0;
910  AliVertex* vx=0;
911  AliPosition* r=0;
912  Ali3Vector p;
913  Float_t charge;
914
915  AliPosition dummy;
916
917  if (fLines) delete fLines;
918  fLines=new TObjArray();
919  fLines->SetOwner();
920
921  Int_t ntk=GetNtracks();
922  for (Int_t jtk=1; jtk<=ntk; jtk++)
923  {
924   tx=GetTrack(jtk);
925
926   if (!tx) continue;
927
928   charge=tx->GetCharge();
929
930   TPolyLine3D* line=new TPolyLine3D();
931   fLines->Add(line);
932
933   if (IsConnectTrack(tx))
934   {
935    if (cons==1)
936    {
937     r=tx->GetBeginPoint();
938     if (!r) r=&dummy;
939     r->GetPosition(vec,"car");
940     line->SetNextPoint(vec[0],vec[1],vec[2]);
941     r=tx->GetEndPoint();
942     if (!r) r=&dummy;
943     r->GetPosition(vec,"car");
944     line->SetNextPoint(vec[0],vec[1],vec[2]);
945     line->SetLineWidth(1);
946    }
947   }
948   else
949   {
950    r=tx->GetClosestPoint();
951    if (!r) r=&dummy;
952    r->GetPosition(vec,"car");
953    line->SetNextPoint(vec[0],vec[1],vec[2]);
954    p=tx->Get3Momentum();
955    p=p+(*r);
956    p.GetVector(vec,"car");
957    line->SetNextPoint(vec[0],vec[1],vec[2]);
958    line->SetLineWidth(3);
959   }
960
961   line->SetLineColor(kGreen);              // Neutral track
962   if (charge>0) line->SetLineColor(kRed);  // Positive track
963   if (charge<0) line->SetLineColor(kBlue); // Negative track
964  
965   // Mark tracks belonging to jets
966   if (IsJetTrack(tx))
967   {
968    if (jets==1)
969    {
970     line->SetLineWidth(2);
971     line->SetLineColor(kMagenta);
972    }
973   }
974     
975   line->Draw();
976  }
977
978  // Go for secondary vertices if selected
979  if (secs==1)
980  {
981   Int_t nvtx=GetNvertices();
982   for (Int_t jvtx=1; jvtx<=nvtx; jvtx++)
983   {
984    vx=GetVertex(jvtx);
985    if (vx) vx->Draw(secs,cons,jets);
986   }
987  }
988 }
989 ///////////////////////////////////////////////////////////////////////////
990 TObject* AliVertex::Clone(char* name)
991 {
992 // Make a deep copy of the current object and provide the pointer to the copy.
993 // This memberfunction enables automatic creation of new objects of the
994 // correct type depending on the object type, a feature which may be very useful
995 // for containers when adding objects in case the container owns the objects.
996 // This feature allows e.g. AliEvent to store either AliVertex objects or
997 // objects derived from AliVertex via the AddVertex memberfunction, provided
998 // these derived classes also have a proper Clone memberfunction. 
999
1000  AliVertex* vtx=new AliVertex(*this);
1001  if (name)
1002  {
1003   if (strlen(name)) vtx->SetName(name);
1004  }
1005  return vtx;
1006 }
1007 ///////////////////////////////////////////////////////////////////////////