]> git.uio.no Git - u/mrichter/AliRoot.git/blob - RALICE/AliVertex.cxx
8ee85692029d9a2fea94cac72c848f75e271a2ab
[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 // Coding example to make 3 vertices v1, v2 and v3.
52 // ------------------------------------------------
53 // v1 contains the tracks 1,2,3 and 4
54 // v2 contains many different tracks
55 // v3 contains the jets 1 and 2
56 //
57 //        AliTrack t1,t2,t3,t4;
58 //         ...
59 //         ... // code to fill the track data
60 //         ...
61 //
62 //        AliJet j1,j2;
63 //         ...
64 //         ... // code to fill the jet data
65 //         ...
66 //
67 //        AliVertex v1;
68 //        v1.SetVertexCopy(1);
69 //
70 //        v1.AddTrack(t1);
71 //        v1.AddTrack(t2);
72 //        v1.AddTrack(t3);
73 //        v1.AddTrack(t4);
74 //
75 //        Float_t r1[3]={2.4,0.1,-8.5};
76 //        v1.SetPosition(r1,"car");
77 //
78 //        AliVertex v2;
79 //        v2.SetTrackCopy(1);
80 //
81 //        AliTrack* tx=new AliTrack();
82 //        for (Int_t i=0; i<10; i++)
83 //        {
84 //         ...
85 //         ... // code to fill the track data
86 //         ...
87 //         v2.AddTrack(tx);
88 //         tx->Reset(); 
89 //        }
90 //
91 //        Float_t r2[3]={1.6,-3.2,5.7};
92 //        v2.SetPosition(r2,"car");
93 //
94 //        AliVertex v3;
95 //
96 //        v3.AddJet(j1);
97 //        v3.AddJet(j2);
98 //
99 //        Float_t r3[3]={6.2,4.8,1.3};
100 //        v3.SetPosition(r3,"car");
101 //
102 //        v1.Info("sph");
103 //        v2.ListAll();
104 //        v3.List("cyl");
105 //
106 //        Float_t e1=v1.GetEnergy();
107 //        Ali3Vector p1=v1.Get3Momentum();
108 //        Float_t loc[3];
109 //        v1.GetPosition(loc,"sph");
110 //        AliPosition r=v2.GetPosition();
111 //        r.Info(); 
112 //        Int_t nt=v2.GetNtracks();
113 //        AliTrack* tv=v2.GetTrack(1); // Access track number 1 of Vertex v2
114 //
115 // Specify the vertices v2 and v3 as secondary vertices of v1
116 //
117 //        v1.AddVertex(v2);
118 //        v1.AddVertex(v3);
119 //
120 //        v1.List();
121 //
122 //        Int_t nv=v1.GetNvtx();
123 //        AliVertex* vx=v1.GetVertex(1); // Access 1st secondary vertex of v1
124 //        Float_t e=vx->GetEnergy();
125 //
126 //        Float_t M=v1.GetInvmass(); 
127 //
128 // Reconstruct Vertex v1 from scratch
129 //
130 //        v1.Reset();
131 //        v1.SetNvmax(25); // Increase initial no. of sec. vertices
132 //        v1.AddTrack(t3);
133 //        v1.AddTrack(t4);
134 //        v1.AddJet(j2);
135 //        Float_t pos[3]={7,9,4};
136 //        v1.SetPosition(pos,"car");
137 //
138 // Note : All quantities are in GeV, GeV/c or GeV/c**2
139 //
140 //--- Author: Nick van Eijndhoven 04-apr-1998 UU-SAP Utrecht
141 //- Modified: NvE $Date$ UU-SAP Utrecht
142 ///////////////////////////////////////////////////////////////////////////
143
144 #include "AliVertex.h"
145  
146 ClassImp(AliVertex) // Class implementation to enable ROOT I/O
147  
148 AliVertex::AliVertex()
149 {
150 // Default constructor.
151 // All variables initialised to 0.
152 // Initial maximum number of tracks is set to the default value.
153 // Initial maximum number of sec. vertices is set to the default value.
154  fNvmax=0;
155  fVertices=0;
156  fConnects=0;
157  fVertexCopy=0;
158  fNjmax=0;
159  fJets=0;
160  fJetCopy=0;
161  Reset();
162  SetNtinit();
163  SetNvmax();
164  SetNjmax();
165 }
166 ///////////////////////////////////////////////////////////////////////////
167 AliVertex::AliVertex(Int_t n)
168 {
169 // Create a vertex to hold initially a maximum of n tracks
170 // All variables initialised to 0
171  fNvmax=0;
172  fVertices=0;
173  fConnects=0;
174  fVertexCopy=0;
175  fNjmax=0;
176  fJets=0;
177  fJetCopy=0;
178  Reset();
179  if (n > 0)
180  {
181   SetNtinit(n);
182  }
183  else
184  {
185   cout << endl;
186   cout << " *AliVertex* Initial max. number of tracks entered : " << n << endl;
187   cout << " This is invalid. Default initial maximum will be used." << endl;
188   cout << endl;
189   SetNtinit();
190  }
191  SetNvmax();
192  SetNjmax();
193 }
194 ///////////////////////////////////////////////////////////////////////////
195 AliVertex::~AliVertex()
196 {
197 // Default destructor
198  if (fVertices)
199  {
200   if (fVertexCopy) fVertices->Delete();
201   delete fVertices;
202   fVertices=0;
203  }
204  if (fConnects)
205  {
206   fConnects->Delete();
207   delete fConnects;
208   fConnects=0;
209  }
210  if (fJets)
211  {
212   if (fJetCopy) fJets->Delete();
213   delete fJets;
214   fJets=0;
215  }
216 }
217 ///////////////////////////////////////////////////////////////////////////
218 void AliVertex::SetNvmax(Int_t n)
219 {
220 // Set the initial maximum number of (secondary) vertices
221  if (n > 0)
222  {
223   fNvmax=n;
224  }
225  else
226  {
227   fNvmax=1;
228  }
229  if (fVertices)
230  {
231   if (fVertexCopy) fVertices->Delete();
232   delete fVertices;
233   fVertices=0;
234  }
235 }
236 ///////////////////////////////////////////////////////////////////////////
237 void AliVertex::SetNjmax(Int_t n)
238 {
239 // Set the initial maximum number of jets
240  if (n > 0)
241  {
242   fNjmax=n;
243  }
244  else
245  {
246   fNjmax=1;
247  }
248  if (fJets)
249  {
250   if (fJetCopy) fJets->Delete();
251   delete fJets;
252   fJets=0;
253  }
254 }
255 ///////////////////////////////////////////////////////////////////////////
256 void AliVertex::Reset()
257 {
258 // Reset all variables to 0 and reset all stored vertex and jet lists.
259 // The max. number of tracks is set to the initial value again
260 // The max. number of vertices is set to the default value again
261 // The max. number of jets is set to the default value again
262
263  AliJet::Reset();
264
265  Double_t a[3]={0,0,0};
266  SetPosition(a,"sph");
267  SetPositionErrors(a,"car");
268
269  fNvtx=0;
270  if (fNvmax>0) SetNvmax(fNvmax);
271  if (fConnects)
272  {
273   fConnects->Delete();
274   delete fConnects;
275   fConnects=0;
276  }
277
278  fNjets=0;
279  if (fNjmax>0) SetNjmax(fNjmax);
280 }
281 ///////////////////////////////////////////////////////////////////////////
282 void AliVertex::ResetVertices()
283 {
284 // Reset the stored vertex list and delete all connecting tracks which
285 // were generated automatically via connect=1 in AddVertex().
286 // The max. number of vertices is set to the default value again.
287 // All physics quantities are updated according to the removal of the
288 // connecting tracks.
289  AliTrack* t;
290  if (fConnects)
291  {
292   for (Int_t i=0; i<=fConnects->GetLast(); i++)
293   {
294    t=(AliTrack*)fConnects->At(i);
295    AliTrack* test=(AliTrack*)fTracks->Remove(t);
296    if (test)
297    {
298     fNtrk--;
299     (Ali4Vector&)(*this)-=(Ali4Vector&)(*t);
300     fQ-=t->GetCharge();
301    }
302   }
303   fTracks->Compress();
304  }
305
306  fNvtx=0;
307  if (fNvmax>0) SetNvmax(fNvmax);
308  if (fConnects)
309  {
310   fConnects->Delete();
311   delete fConnects;
312   fConnects=0;
313  }
314 }
315 ///////////////////////////////////////////////////////////////////////////
316 void AliVertex::AddJet(AliJet& j,Int_t tracks)
317 {
318 // Add a jet (and its tracks) to the vertex
319 // In case the maximum number of jets has been reached,
320 // the array space will be extended automatically
321 //
322 // Note : By default the tracks of the jet are added to the current (primary)
323 //        vertex.
324 //        The automatic addition of the tracks of the jet can be suppressed
325 //        by specifying tracks=0. In this case only the AliJet object will
326 //        be stored according to the mode specified by SetJetCopy().
327 //        The latter will enable jet studies based on a fixed list of tracks
328 //        as contained e.g. in an AliVertex or AliEvent. 
329  if (!fJets) fJets=new TObjArray(fNjmax);
330  if (fNjets == fNjmax) // Check if maximum jet number is reached
331  {
332   fNjmax++;
333   fJets->Expand(fNjmax);
334  }
335
336  // Add the jet to the list 
337  fNjets++;
338  if (fJetCopy)
339  {
340   fJets->Add(j.Clone());
341  }
342  else
343  {
344   fJets->Add(&j);
345  }
346
347  // Add the tracks of the jet to this vertex
348  if (tracks)
349  {
350   AliTrack* tj;
351   for (Int_t i=1; i<=j.GetNtracks(); i++)
352   {
353    tj=j.GetTrack(i);
354    AddTrack(tj);
355   }
356  }
357 }
358 ///////////////////////////////////////////////////////////////////////////
359 void AliVertex::AddVertex(AliVertex& v,Int_t connect)
360 {
361 // Add a (secondary) vertex to the current vertex.
362 // In case the maximum number of (secondary) vertices has been reached,
363 // the array space will be extended automatically
364 //
365 // Note : By default the 4-momentum and charge of the current (primary) vertex
366 //        are updated by automatically creating the track connecting
367 //        both vertices. The track parameters are taken from the
368 //        4-momentum and charge of the secondary vertex.
369 //        The automatic creation of the connecting track and updating
370 //        of the (primary) vertex 4-momentum and charge can be suppressed
371 //        by specifying connect=0. In this case, however, the user
372 //        has to introduce the connecting track lateron by hand
373 //        explicitly in order to match the kinematics and charge.
374 //
375  if (!fVertices) fVertices=new TObjArray(fNvmax);
376  if (fNvtx == fNvmax) // Check if maximum vertex number is reached
377  {
378   fNvmax++;
379   fVertices->Expand(fNvmax);
380  }
381
382  // Add the linked (secondary) vertex to the list 
383  fNvtx++;
384  if (fVertexCopy)
385  {
386   fVertices->Add(v.Clone());
387  }
388  else
389  {
390   fVertices->Add(&v);
391  }
392
393  // Create connecting track and update 4-momentum and charge for current vertex
394  if (connect)
395  {
396   AliPosition r1=GetPosition();
397   AliPosition r2=v.GetPosition();
398   Float_t q=v.GetCharge();
399   Ali3Vector p=v.Get3Momentum();
400   Double_t v2=v.GetInvariant();
401   Double_t dv2=v.Ali4Vector::GetResultError();
402
403   AliTrack* t=new AliTrack();
404   t->SetBeginPoint(r1);
405   t->SetEndPoint(r2);
406   t->SetCharge(q);
407   t->Set3Momentum(p);
408   t->SetInvariant(v2,dv2);
409
410   AddTrack(t);
411
412   if (!fConnects) fConnects=new TObjArray(fNvmax);
413   fConnects->Add(t);
414  }
415 }
416 ///////////////////////////////////////////////////////////////////////////
417 void AliVertex::Info(TString f)
418 {
419 // Provide vertex information within the coordinate frame f
420  cout << " *AliVertex::Info* Id : " << fUserId << " Invmass : " << GetInvmass()
421       << " Charge : " << GetCharge() << " Momentum : " << GetMomentum()
422       << " Ntracks : " << GetNtracks() << " Nvertices : " << fNvtx 
423       << " Njets : " << fNjets << endl;
424  cout << " ";
425  Ali4Vector::Info(f);
426  cout << "  Position";
427  AliPosition::Info(f); 
428
429 ///////////////////////////////////////////////////////////////////////////
430 void AliVertex::List(TString f)
431 {
432 // Provide primary track and sec. vertex information within the coordinate frame f
433
434  Info(f); // Information of the current vertex
435
436  // The tracks of this vertex
437  AliTrack* t; 
438  for (Int_t it=1; it<=GetNtracks(); it++)
439  {
440   t=GetTrack(it);
441   if (t)
442   {
443    cout << "  ---Track no. " << it << endl;
444    cout << " ";
445    t->Info(f); 
446   }
447   else
448   {
449    cout << " *AliVertex::List* Error : No track present." << endl; 
450   }
451  }
452
453  // The secondary vertices of this vertex
454  AliVertex* v; 
455  for (Int_t iv=1; iv<=GetNvertices(); iv++)
456  {
457   v=GetVertex(iv);
458   if (v)
459   {
460    cout << "  ---Level 1 sec. vertex no. " << iv << endl;
461    cout << " ";
462    v->Info(f); 
463   }
464   else
465   {
466    cout << " *AliVertex::List* Error : No sec. vertex present." << endl; 
467   }
468  }
469
470 ///////////////////////////////////////////////////////////////////////////
471 void AliVertex::ListAll(TString f)
472 {
473 // Provide complete (sec) vertex and (decay) track info within the coordinate frame f
474
475  Info(f); // Information of the current vertex
476
477  // The tracks of this vertex
478  AliTrack* t; 
479  for (Int_t it=1; it<=GetNtracks(); it++)
480  {
481   t=GetTrack(it);
482   if (t)
483   {
484    cout << "  ---Track no. " << it << endl;
485    cout << " ";
486    t->ListAll(f); 
487   }
488   else
489   {
490    cout << " *AliVertex::ListAll* Error : No track present." << endl; 
491   }
492  }
493
494  AliVertex* v=this;
495  Dump(v,1,f); // Information of all sec. vertices
496 }
497 //////////////////////////////////////////////////////////////////////////
498 void AliVertex::Dump(AliVertex* v,Int_t n,TString f)
499 {
500 // Recursively provide the info of all secondary vertices of this vertex
501  AliVertex* vs; 
502  for (Int_t iv=1; iv<=v->GetNvertices(); iv++)
503  {
504   vs=v->GetVertex(iv);
505   if (vs)
506   {
507    cout << "  ---Level " << n << " sec. vertex no. " << iv << endl;
508    cout << " ";
509    vs->Info(f); 
510
511    // The tracks of this vertex
512    AliTrack* t; 
513    for (Int_t it=1; it<=vs->GetNtracks(); it++)
514    {
515     t=vs->GetTrack(it);
516     if (t)
517     {
518      cout << "  ---Track no. " << it << endl;
519      cout << " ";
520      t->ListAll(f); 
521     }
522     else
523     {
524      cout << " *AliVertex::Dump* Error : No track present." << endl; 
525     }
526    }
527
528    // Go for next sec. vertex level of this sec. vertex recursively
529    Dump(vs,n+1,f);
530   }
531   else
532   {
533    cout << " *AliVertex::Dump* Error : No sec. vertex present." << endl; 
534   }
535  }
536
537 //////////////////////////////////////////////////////////////////////////
538 Int_t AliVertex::GetNvertices()
539 {
540 // Return the current number of (secondary) vertices
541  return fNvtx;
542 }
543 ///////////////////////////////////////////////////////////////////////////
544 AliVertex* AliVertex::GetVertex(Int_t i)
545 {
546 // Return the i-th (secondary) vertex of the current vertex
547  if (!fVertices)
548  {
549   cout << " *AliVertex*::GetVertex* No (secondary) vertices present." << endl;
550   return 0;
551  }
552  else
553  {
554   if (i<=0 || i>fNvtx)
555   {
556    cout << " *AliVertex*::GetVertex* Invalid argument i : " << i
557         << " Nvtx = " << fNvtx << endl;
558    return 0;
559   }
560   else
561   {
562    return (AliVertex*)fVertices->At(i-1);
563   }
564  }
565 }
566 ///////////////////////////////////////////////////////////////////////////
567 AliVertex* AliVertex::GetIdVertex(Int_t id)
568 {
569 // Return the (sec.) vertex with user identifier "id"
570  AliVertex* vx=0;
571  AliVertex* v=0;
572  if (!fVertices)
573  {
574   cout << " *AliVertex*::GetIdVertex* No (secondary) vertices present." << endl;
575   return 0;
576  }
577  else
578  {
579   for (Int_t i=0; i<fNvtx; i++)
580   {
581    vx=(AliVertex*)fVertices->At(i);
582    if (id == vx->GetId()) v=vx;
583   }
584   return v;
585  }
586 }
587 ///////////////////////////////////////////////////////////////////////////
588 void AliVertex::SetVertexCopy(Int_t j)
589 {
590 // (De)activate the creation of private copies of the added vertices.
591 // j=0 ==> No private copies are made; pointers of original vertices are stored.
592 // j=1 ==> Private copies of the vertices are made and these pointers are stored.
593 //
594 // Note : Once the storage contains pointer(s) to AliVertex objects one cannot
595 //        change the VertexCopy mode anymore.
596 //        To change the VertexCopy mode for an existing AliVertex containing
597 //        vertices one first has to invoke Reset().
598  if (!fVertices)
599  {
600   if (j==0 || j==1)
601   {
602    fVertexCopy=j;
603   }
604   else
605   {
606    cout << "*AliVertex::SetVertexCopy* Invalid argument : " << j << endl;
607   }
608  }
609  else
610  {
611   cout << "*AliVertex::SetVertexCopy* Storage already contained vertices."
612        << "  ==> VertexCopy mode not changed." << endl; 
613  }
614 }
615 ///////////////////////////////////////////////////////////////////////////
616 Int_t AliVertex::GetVertexCopy()
617 {
618 // Provide value of the VertexCopy mode.
619 // 0 ==> No private copies are made; pointers of original vertices are stored.
620 // 1 ==> Private copies of the vertices are made and these pointers are stored.
621  return fVertexCopy;
622 }
623 ///////////////////////////////////////////////////////////////////////////
624 Int_t AliVertex::GetNjets()
625 {
626 // Return the current number of jets
627  return fNjets;
628 }
629 ///////////////////////////////////////////////////////////////////////////
630 AliJet* AliVertex::GetJet(Int_t i)
631 {
632 // Return the i-th jet of the current vertex
633  if (!fJets)
634  {
635   cout << " *AliVertex*::GetJet* No jets present." << endl;
636   return 0;
637  }
638  else
639  {
640   if (i<=0 || i>fNjets)
641   {
642    cout << " *AliVertex*::GetJet* Invalid argument i : " << i
643         << " Njets = " << fNjets << endl;
644    return 0;
645   }
646   else
647   {
648    return (AliJet*)fJets->At(i-1);
649   }
650  }
651 }
652 ///////////////////////////////////////////////////////////////////////////
653 AliJet* AliVertex::GetIdJet(Int_t id)
654 {
655 // Return the jet with user identifier "id"
656  AliJet* jx=0;
657  AliJet* j=0;
658  if (!fJets)
659  {
660   cout << " *AliVertex*::GetIdJet* No jets present." << endl;
661   return 0;
662  }
663  else
664  {
665   for (Int_t i=0; i<fNjets; i++)
666   {
667    jx=(AliJet*)fJets->At(i);
668    if (id == jx->GetId()) j=jx;
669   }
670   return j;
671  }
672 }
673 ///////////////////////////////////////////////////////////////////////////
674 void AliVertex::SetJetCopy(Int_t j)
675 {
676 // (De)activate the creation of private copies of the added jets.
677 // j=0 ==> No private copies are made; pointers of original jets are stored.
678 // j=1 ==> Private copies of the jets are made and these pointers are stored.
679 //
680 // Note : Once the storage contains pointer(s) to AliJet objects one cannot
681 //        change the JetCopy mode anymore.
682 //        To change the JetCopy mode for an existing AliVertex containing
683 //        jets one first has to invoke Reset().
684  if (!fJets)
685  {
686   if (j==0 || j==1)
687   {
688    fJetCopy=j;
689   }
690   else
691   {
692    cout << "*AliVertex::SetJetCopy* Invalid argument : " << j << endl;
693   }
694  }
695  else
696  {
697   cout << "*AliVertex::SetJetCopy* Storage already contained jets."
698        << "  ==> JetCopy mode not changed." << endl; 
699  }
700 }
701 ///////////////////////////////////////////////////////////////////////////
702 Int_t AliVertex::GetJetCopy()
703 {
704 // Provide value of the JetCopy mode.
705 // 0 ==> No private copies are made; pointers of original jets are stored.
706 // 1 ==> Private copies of the jets are made and these pointers are stored.
707  return fJetCopy;
708 }
709 ///////////////////////////////////////////////////////////////////////////