1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
18 ///////////////////////////////////////////////////////////////////////////
20 // Creation and investigation of an AliVertex.
21 // An AliVertex can be constructed by adding AliTracks and/or AliJets.
23 // Note : Also (secondary) vertices can be added to a vertex.
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().
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
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
38 // b) SetVertexCopy(1).
39 // Of every 'added' vertex a private copy will be made of which the pointer
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
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.
48 // Coding example to make 3 vertices v1, v2 and v3.
49 // ------------------------------------------------
50 // v1 contains the tracks 1,2,3 and 4
51 // v2 contains many different tracks
52 // v3 contains the jets 1 and 2
54 // AliTrack t1,t2,t3,t4;
56 // ... // code to fill the track data
61 // ... // code to fill the jet data
65 // v1.SetVertexCopy(1);
72 // Float_t r1[3]={2.4,0.1,-8.5};
73 // v1.SetPosition(r1,"car");
76 // v2.SetTrackCopy(1);
78 // AliTrack* tx=new AliTrack();
79 // for (Int_t i=0; i<10; i++)
82 // ... // code to fill the track data
88 // Float_t r2[3]={1.6,-3.2,5.7};
89 // v2.SetPosition(r2,"car");
96 // Float_t r3[3]={6.2,4.8,1.3};
97 // v3.SetPosition(r3,"car");
103 // Float_t e1=v1.GetEnergy();
104 // Ali3Vector p1=v1.Get3Momentum();
106 // v1.GetPosition(loc,"sph");
107 // AliPosition r=v2.GetPosition();
109 // Int_t nt=v2.GetNtracks();
110 // AliTrack* tv=v2.GetTrack(1); // Access track number 1 of Vertex v2
112 // Specify the vertices v2 and v3 as secondary vertices of v1
119 // Int_t nv=v1.GetNvtx();
120 // AliVertex* vx=v1.GetVertex(1); // Access 1st secondary vertex of v1
121 // Float_t e=vx->GetEnergy();
123 // Float_t M=v1.GetInvmass();
125 // Reconstruct Vertex v1 from scratch
128 // v1.SetNvmax(25); // Increase initial no. of sec. vertices
132 // Float_t pos[3]={7,9,4};
133 // v1.SetPosition(pos,"car");
135 // Note : All quantities are in GeV, GeV/c or GeV/c**2
137 //--- Author: Nick van Eijndhoven 04-apr-1998 UU-SAP Utrecht
138 //- Modified: NvE $Date$ UU-SAP Utrecht
139 ///////////////////////////////////////////////////////////////////////////
141 #include "AliVertex.h"
143 ClassImp(AliVertex) // Class implementation to enable ROOT I/O
145 AliVertex::AliVertex()
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.
163 ///////////////////////////////////////////////////////////////////////////
164 AliVertex::AliVertex(Int_t n)
166 // Create a vertex to hold initially a maximum of n tracks
167 // All variables initialised to 0
183 cout << " *AliVertex* Initial max. number of tracks entered : " << n << endl;
184 cout << " This is invalid. Default initial maximum will be used." << endl;
191 ///////////////////////////////////////////////////////////////////////////
192 AliVertex::~AliVertex()
194 // Default destructor
197 if (fVertexCopy) fVertices->Delete();
209 if (fJetCopy) fJets->Delete();
214 ///////////////////////////////////////////////////////////////////////////
215 void AliVertex::SetNvmax(Int_t n)
217 // Set the initial maximum number of (secondary) vertices
228 if (fVertexCopy) fVertices->Delete();
233 ///////////////////////////////////////////////////////////////////////////
234 void AliVertex::SetNjmax(Int_t n)
236 // Set the initial maximum number of jets
247 if (fJetCopy) fJets->Delete();
252 ///////////////////////////////////////////////////////////////////////////
253 void AliVertex::Reset()
255 // Reset all variables to 0 and reset all stored vertex and jet lists.
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 // The max. number of jets is set to the default value again
262 Double_t a[3]={0,0,0};
263 SetPosition(a,"sph");
264 SetPositionErrors(a,"car");
267 if (fNvmax>0) SetNvmax(fNvmax);
276 if (fNjmax>0) SetNjmax(fNjmax);
278 ///////////////////////////////////////////////////////////////////////////
279 void AliVertex::ResetVertices()
281 // Reset the stored vertex list and delete all connecting tracks which
282 // were generated automatically via connect=1 in AddVertex().
283 // The max. number of vertices is set to the default value again.
284 // All physics quantities are updated according to the remaining structure
285 // of connected tracks.
289 for (Int_t i=0; i<=fConnects->GetLast(); i++)
291 t=(AliTrack*)fConnects->At(i);
292 AliTrack* test=(AliTrack*)fTracks->Remove(t);
299 Double_t a[4]={0,0,0,0};
300 Ali4Vector::SetVector(a,"sph");
301 for (Int_t i=0; i<fNtrk; i++)
304 (*this)+=(Ali4Vector&)(*t);
309 if (fNvmax>0) SetNvmax(fNvmax);
317 ///////////////////////////////////////////////////////////////////////////
318 void AliVertex::AddJet(AliJet& j,Int_t tracks)
320 // Add a jet (and its tracks) to the vertex
321 // In case the maximum number of jets has been reached,
322 // the array space will be extended automatically
324 // Note : By default the tracks of the jet are added to the current (primary)
326 // The automatic addition of the tracks of the jet can be suppressed
327 // by specifying tracks=0. In this case only the AliJet object will
328 // be stored according to the mode specified by SetJetCopy().
329 // The latter will enable jet studies based on a fixed list of tracks
330 // as contained e.g. in an AliVertex or AliEvent.
331 if (!fJets) fJets=new TObjArray(fNjmax);
332 if (fNjets == fNjmax) // Check if maximum jet number is reached
335 fJets->Expand(fNjmax);
338 // Add the jet to the list
342 AliJet* jx=new AliJet(j);
350 // Add the tracks of the jet to this vertex
354 for (Int_t i=1; i<=j.GetNtracks(); i++)
361 ///////////////////////////////////////////////////////////////////////////
362 void AliVertex::AddVertex(AliVertex& v,Int_t connect)
364 // Add a (secondary) vertex to the current vertex.
365 // In case the maximum number of (secondary) vertices has been reached,
366 // the array space will be extended automatically
368 // Note : By default the 4-momentum and charge of the current (primary) vertex
369 // are updated by automatically creating the track connecting
370 // both vertices. The track parameters are taken from the
371 // 4-momentum and charge of the secondary vertex.
372 // The automatic creation of the connecting track and updating
373 // of the (primary) vertex 4-momentum and charge can be suppressed
374 // by specifying connect=0. In this case, however, the user
375 // has to introduce the connecting track lateron by hand
376 // explicitly in order to match the kinematics and charge.
378 if (!fVertices) fVertices=new TObjArray(fNvmax);
379 if (fNvtx == fNvmax) // Check if maximum vertex number is reached
382 fVertices->Expand(fNvmax);
385 // Add the linked (secondary) vertex to the list
389 AliVertex* vx=new AliVertex(v);
397 // Create connecting track and update 4-momentum and charge for current vertex
400 AliPosition r1=GetPosition();
401 AliPosition r2=v.GetPosition();
402 Float_t q=v.GetCharge();
403 Ali3Vector p=v.Get3Momentum();
404 Double_t v2=v.GetInvariant();
405 Double_t dv2=v.Ali4Vector::GetResultError();
407 AliTrack* t=new AliTrack;
408 t->SetBeginPoint(r1);
412 t->SetInvariant(v2,dv2);
416 if (!fConnects) fConnects=new TObjArray(fNvmax);
420 ///////////////////////////////////////////////////////////////////////////
421 void AliVertex::Info(TString f)
423 // Provide vertex information within the coordinate frame f
424 cout << " *AliVertex::Info* Invmass : " << GetInvmass()
425 << " Charge : " << GetCharge() << " Momentum : " << GetMomentum()
426 << " Ntracks : " << GetNtracks() << " Nvertices : " << fNvtx
427 << " Njets : " << fNjets << endl;
431 AliPosition::Info(f);
433 ///////////////////////////////////////////////////////////////////////////
434 void AliVertex::List(TString f)
436 // Provide primary track and sec. vertex information within the coordinate frame f
438 Info(f); // Information of the current vertex
440 // The tracks of this vertex
442 for (Int_t it=1; it<=GetNtracks(); it++)
447 cout << " ---Track no. " << it << endl;
453 cout << " *AliVertex::List* Error : No track present." << endl;
457 // The secondary vertices of this vertex
459 for (Int_t iv=1; iv<=GetNvertices(); iv++)
464 cout << " ---Level 1 sec. vertex no. " << iv << endl;
470 cout << " *AliVertex::List* Error : No sec. vertex present." << endl;
474 ///////////////////////////////////////////////////////////////////////////
475 void AliVertex::ListAll(TString f)
477 // Provide complete (sec) vertex and (decay) track info within the coordinate frame f
479 Info(f); // Information of the current vertex
481 // The tracks of this vertex
483 for (Int_t it=1; it<=GetNtracks(); it++)
488 cout << " ---Track no. " << it << endl;
494 cout << " *AliVertex::ListAll* Error : No track present." << endl;
499 Dump(v,1,f); // Information of all sec. vertices
501 //////////////////////////////////////////////////////////////////////////
502 void AliVertex::Dump(AliVertex* v,Int_t n,TString f)
504 // Recursively provide the info of all secondary vertices of this vertex
506 for (Int_t iv=1; iv<=v->GetNvertices(); iv++)
511 cout << " ---Level " << n << " sec. vertex no. " << iv << endl;
515 // The tracks of this vertex
517 for (Int_t it=1; it<=vs->GetNtracks(); it++)
522 cout << " ---Track no. " << it << endl;
528 cout << " *AliVertex::Dump* Error : No track present." << endl;
532 // Go for next sec. vertex level of this sec. vertex recursively
537 cout << " *AliVertex::Dump* Error : No sec. vertex present." << endl;
541 //////////////////////////////////////////////////////////////////////////
542 Int_t AliVertex::GetNvertices()
544 // Return the current number of (secondary) vertices
547 ///////////////////////////////////////////////////////////////////////////
548 AliVertex* AliVertex::GetVertex(Int_t i)
550 // Return the i-th (secondary) vertex of the current vertex
553 cout << " *AliVertex*::GetVertex* No (secondary) vertices present." << endl;
560 cout << " *AliVertex*::GetVertex* Invalid argument i : " << i
561 << " Nvtx = " << fNvtx << endl;
566 return (AliVertex*)fVertices->At(i-1);
570 ///////////////////////////////////////////////////////////////////////////
571 void AliVertex::SetVertexCopy(Int_t j)
573 // (De)activate the creation of private copies of the added vertices.
574 // j=0 ==> No private copies are made; pointers of original vertices are stored.
575 // j=1 ==> Private copies of the vertices are made and these pointers are stored.
577 // Note : Once the storage contains pointer(s) to AliVertex objects one cannot
578 // change the VertexCopy mode anymore.
579 // To change the VertexCopy mode for an existing AliVertex containing
580 // vertices one first has to invoke Reset().
589 cout << "*AliVertex::SetVertexCopy* Invalid argument : " << j << endl;
594 cout << "*AliVertex::SetVertexCopy* Storage already contained vertices."
595 << " ==> VertexCopy mode not changed." << endl;
598 ///////////////////////////////////////////////////////////////////////////
599 Int_t AliVertex::GetVertexCopy()
601 // Provide value of the VertexCopy mode.
602 // 0 ==> No private copies are made; pointers of original vertices are stored.
603 // 1 ==> Private copies of the vertices are made and these pointers are stored.
606 ///////////////////////////////////////////////////////////////////////////
607 Int_t AliVertex::GetNjets()
609 // Return the current number of jets
612 ///////////////////////////////////////////////////////////////////////////
613 AliJet* AliVertex::GetJet(Int_t i)
615 // Return the i-th jet of the current vertex
618 cout << " *AliVertex*::GetJet* No jets present." << endl;
623 if (i<=0 || i>fNjets)
625 cout << " *AliVertex*::GetJet* Invalid argument i : " << i
626 << " Njets = " << fNjets << endl;
631 return (AliJet*)fJets->At(i-1);
635 ///////////////////////////////////////////////////////////////////////////
636 void AliVertex::SetJetCopy(Int_t j)
638 // (De)activate the creation of private copies of the added jets.
639 // j=0 ==> No private copies are made; pointers of original jets are stored.
640 // j=1 ==> Private copies of the jets are made and these pointers are stored.
642 // Note : Once the storage contains pointer(s) to AliJet objects one cannot
643 // change the JetCopy mode anymore.
644 // To change the JetCopy mode for an existing AliVertex containing
645 // jets one first has to invoke Reset().
654 cout << "*AliVertex::SetJetCopy* Invalid argument : " << j << endl;
659 cout << "*AliVertex::SetJetCopy* Storage already contained jets."
660 << " ==> JetCopy mode not changed." << endl;
663 ///////////////////////////////////////////////////////////////////////////
664 Int_t AliVertex::GetJetCopy()
666 // Provide value of the JetCopy mode.
667 // 0 ==> No private copies are made; pointers of original jets are stored.
668 // 1 ==> Private copies of the jets are made and these pointers are stored.
671 ///////////////////////////////////////////////////////////////////////////