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.
38 // Modifications made to the original vertices also affect the AliVertex objects
41 // b) SetVertexCopy(1).
42 // Of every 'added' vertex a private copy will be made of which the pointer
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
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.
51 // See also the documentation provided for the memberfunction SetOwner().
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
59 // AliTrack t1,t2,t3,t4;
61 // ... // code to fill the track data
66 // ... // code to fill the jet data
70 // v1.SetVertexCopy(1);
77 // Float_t r1[3]={2.4,0.1,-8.5};
78 // v1.SetPosition(r1,"car");
81 // v2.SetTrackCopy(1);
83 // AliTrack* tx=new AliTrack();
84 // for (Int_t i=0; i<10; i++)
87 // ... // code to fill the track data
93 // Float_t r2[3]={1.6,-3.2,5.7};
94 // v2.SetPosition(r2,"car");
101 // Float_t r3[3]={6.2,4.8,1.3};
102 // v3.SetPosition(r3,"car");
108 // Float_t e1=v1.GetEnergy();
109 // Ali3Vector p1=v1.Get3Momentum();
111 // v1.GetPosition(loc,"sph");
112 // AliPosition r=v2.GetPosition();
114 // Int_t nt=v2.GetNtracks();
115 // AliTrack* tv=v2.GetTrack(1); // Access track number 1 of Vertex v2
117 // Specify the vertices v2 and v3 as secondary vertices of v1
124 // Int_t nv=v1.GetNvtx();
125 // AliVertex* vx=v1.GetVertex(1); // Access 1st secondary vertex of v1
126 // Float_t e=vx->GetEnergy();
128 // Float_t M=v1.GetInvmass();
130 // Reconstruct Vertex v1 from scratch
133 // v1.SetNvmax(25); // Increase initial no. of sec. vertices
137 // Float_t pos[3]={7,9,4};
138 // v1.SetPosition(pos,"car");
140 // Note : All quantities are in GeV, GeV/c or GeV/c**2
142 //--- Author: Nick van Eijndhoven 04-apr-1998 UU-SAP Utrecht
143 //- Modified: NvE $Date$ UU-SAP Utrecht
144 ///////////////////////////////////////////////////////////////////////////
146 #include "AliVertex.h"
147 #include "Riostream.h"
149 ClassImp(AliVertex) // Class implementation to enable ROOT I/O
151 AliVertex::AliVertex() : AliJet(),AliPosition()
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.
162 ///////////////////////////////////////////////////////////////////////////
163 void AliVertex::Init()
165 // Initialisation of pointers etc...
176 ///////////////////////////////////////////////////////////////////////////
177 AliVertex::AliVertex(Int_t n) : AliJet(n),AliPosition()
179 // Create a vertex to hold initially a maximum of n tracks
180 // All variables initialised to 0
183 cout << " *** This AliJet initialisation was invoked via the AliVertex ctor." << endl;
190 ///////////////////////////////////////////////////////////////////////////
191 AliVertex::~AliVertex()
193 // Default destructor
220 ///////////////////////////////////////////////////////////////////////////
221 void AliVertex::SetOwner(Bool_t own)
223 // Set ownership of all added objects.
224 // The default parameter is own=kTRUE.
226 // Invokation of this memberfunction also sets all the copy modes
227 // (e.g. TrackCopy & co.) according to the value of own.
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.
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.
244 if (fVertices) fVertices->SetOwner(own);
246 if (fJets) fJets->SetOwner(own);
249 AliJet::SetOwner(own);
251 ///////////////////////////////////////////////////////////////////////////
252 AliVertex::AliVertex(AliVertex& v) : AliJet(v.fNtinit),AliPosition(v)
260 SetTrackCopy(v.GetTrackCopy());
261 SetVertexCopy(v.GetVertexCopy());
262 SetJetCopy(v.GetJetCopy());
265 // Copy all tracks except the ones coming from jets
267 Int_t jetflag=0,connect=0;
269 for (Int_t it=1; it<=v.GetNtracks(); it++)
274 jetflag=v.IsJetTrack(tx);
275 connect=v.IsConnectTrack(tx);
277 if (!jetflag && !connect) AddTrack(tx);
283 fConnects=new TObjArray(fNvmax);
284 if (!fTrackCopy) fConnects->SetOwner();
286 tx2=new AliTrack(*tx);
293 // Copy all the (secondary) vertices without re-creating connecting tracks
294 // The connecting tracks have already been copied above
296 for (Int_t iv=1; iv<=v.GetNvertices(); iv++)
299 if (vx) AddVertex(vx,0);
302 // Copy all the jets including the jet tracks for these jets for which
303 // this was also the case in the original vertex
305 for (Int_t ij=1; ij<=v.GetNjets(); ij++)
311 if (jx->GetNtracks())
316 jetflag=v.IsJetTrack(tx);
323 ///////////////////////////////////////////////////////////////////////////
324 void AliVertex::SetNvmax(Int_t n)
326 // Set the initial maximum number of (secondary) vertices
341 ///////////////////////////////////////////////////////////////////////////
342 void AliVertex::SetNjmax(Int_t n)
344 // Set the initial maximum number of jets
359 ///////////////////////////////////////////////////////////////////////////
360 void AliVertex::Reset()
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
369 Double_t a[3]={0,0,0};
370 SetPosition(a,"sph");
371 SetPositionErrors(a,"car");
374 if (fNvmax>0) SetNvmax(fNvmax);
382 if (fNjmax>0) SetNjmax(fNjmax);
395 ///////////////////////////////////////////////////////////////////////////
396 void AliVertex::ResetVertices()
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.
406 for (Int_t i=0; i<=fConnects->GetLast(); i++)
408 t=(AliTrack*)fConnects->At(i);
409 AliTrack* test=(AliTrack*)fTracks->Remove(t);
413 (Ali4Vector&)(*this)-=(Ali4Vector&)(*t);
415 if (fTrackCopy) delete t;
422 if (fNvmax>0) SetNvmax(fNvmax);
429 ///////////////////////////////////////////////////////////////////////////
430 void AliVertex::AddJet(AliJet& j,Int_t tracks)
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
436 // Note : By default the tracks of the jet are added to the current (primary)
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.
445 fJets=new TObjArray(fNjmax);
446 if (fJetCopy) fJets->SetOwner();
448 if (fNjets == fNjmax) // Check if maximum jet number is reached
451 fJets->Expand(fNjmax);
454 // Add the jet to the list
456 if (fJetCopy) jx=new AliJet(j);
464 // Add the tracks of the jet to this vertex
469 fJetTracks=new TObjArray();
471 Int_t copy=1-(jx->GetTrackCopy());
473 for (Int_t i=1; i<=jx->GetNtracks(); i++)
484 ///////////////////////////////////////////////////////////////////////////
485 void AliVertex::AddVertex(AliVertex& v,Int_t connect)
487 // Add a (secondary) vertex to the current vertex.
488 // In case the maximum number of (secondary) vertices has been reached,
489 // the array space will be extended automatically
491 // Note : By default the 4-momentum and charge of the current (primary) vertex
492 // are updated by automatically creating the track connecting
493 // both vertices. The track parameters are taken from the
494 // 4-momentum and charge of the secondary vertex.
495 // The automatic creation of the connecting track and updating
496 // of the (primary) vertex 4-momentum and charge can be suppressed
497 // by specifying connect=0. In this case, however, the user
498 // has to introduce the connecting track lateron by hand
499 // explicitly in order to match the kinematics and charge.
503 fVertices=new TObjArray(fNvmax);
504 if (fVertexCopy) fVertices->SetOwner();
506 if (fNvtx == fNvmax) // Check if maximum vertex number is reached
509 fVertices->Expand(fNvmax);
512 // Add the linked (secondary) vertex to the list
514 if (fVertexCopy) vx=new AliVertex(v);
522 // Create connecting track and update 4-momentum and charge for current vertex
525 AliTrack* t=new AliTrack();
526 t->SetBeginPoint(GetPosition());
527 t->SetEndPoint(v.GetPosition());
528 t->SetCharge(v.GetCharge());
529 t->Set4Momentum((Ali4Vector&)v);
535 fConnects=new TObjArray(fNvmax);
536 if (!fTrackCopy) fConnects->SetOwner();
541 ///////////////////////////////////////////////////////////////////////////
542 void AliVertex::Data(TString f)
544 // Provide vertex information within the coordinate frame f
545 cout << " *AliVertex::Data* Name : " << GetName() << " Title : " << GetTitle() << endl;
546 cout << " Id : " << fUserId << " Invmass : " << GetInvmass()
547 << " Charge : " << GetCharge() << " Momentum : " << GetMomentum()
548 << " Ntracks : " << GetNtracks() << " Nvertices : " << fNvtx
549 << " Njets : " << fNjets << endl;
553 AliPosition::Data(f);
555 ///////////////////////////////////////////////////////////////////////////
556 void AliVertex::List(TString f)
558 // Provide primary track and sec. vertex information within the coordinate frame f
560 Data(f); // Information of the current vertex
562 // The tracks of this vertex
564 for (Int_t it=1; it<=GetNtracks(); it++)
569 cout << " ---Track no. " << it << endl;
575 cout << " *AliVertex::List* Error : No track present." << endl;
579 // The secondary vertices of this vertex
581 for (Int_t iv=1; iv<=GetNvertices(); iv++)
586 cout << " ---Level 1 sec. vertex no. " << iv << endl;
592 cout << " *AliVertex::List* Error : No sec. vertex present." << endl;
596 ///////////////////////////////////////////////////////////////////////////
597 void AliVertex::ListAll(TString f)
599 // Provide complete (sec) vertex and (decay) track info within the coordinate frame f
601 Data(f); // Information of the current vertex
603 // The tracks of this vertex
605 for (Int_t it=1; it<=GetNtracks(); it++)
610 cout << " ---Track no. " << it << endl;
616 cout << " *AliVertex::ListAll* Error : No track present." << endl;
621 Dumps(v,1,f); // Information of all sec. vertices
623 //////////////////////////////////////////////////////////////////////////
624 void AliVertex::Dumps(AliVertex* v,Int_t n,TString f)
626 // Recursively provide the info of all secondary vertices of this vertex
628 for (Int_t iv=1; iv<=v->GetNvertices(); iv++)
633 cout << " ---Level " << n << " sec. vertex no. " << iv << endl;
637 // The tracks of this vertex
639 for (Int_t it=1; it<=vs->GetNtracks(); it++)
644 cout << " ---Track no. " << it << endl;
650 cout << " *AliVertex::Dumps* Error : No track present." << endl;
654 // Go for next sec. vertex level of this sec. vertex recursively
659 cout << " *AliVertex::Dumps* Error : No sec. vertex present." << endl;
663 //////////////////////////////////////////////////////////////////////////
664 Int_t AliVertex::GetNvertices()
666 // Return the current number of (secondary) vertices
669 ///////////////////////////////////////////////////////////////////////////
670 AliVertex* AliVertex::GetVertex(Int_t i)
672 // Return the i-th (secondary) vertex of the current vertex
675 cout << " *AliVertex*::GetVertex* No (secondary) vertices present." << endl;
682 cout << " *AliVertex*::GetVertex* Invalid argument i : " << i
683 << " Nvtx = " << fNvtx << endl;
688 return (AliVertex*)fVertices->At(i-1);
692 ///////////////////////////////////////////////////////////////////////////
693 AliVertex* AliVertex::GetIdVertex(Int_t id)
695 // Return the (sec.) vertex with user identifier "id"
700 cout << " *AliVertex*::GetIdVertex* No (secondary) vertices present." << endl;
705 for (Int_t i=0; i<fNvtx; i++)
707 vx=(AliVertex*)fVertices->At(i);
708 if (id == vx->GetId()) v=vx;
713 ///////////////////////////////////////////////////////////////////////////
714 void AliVertex::SetVertexCopy(Int_t j)
716 // (De)activate the creation of private copies of the added vertices.
717 // j=0 ==> No private copies are made; pointers of original vertices are stored.
718 // j=1 ==> Private copies of the vertices are made and these pointers are stored.
720 // Note : Once the storage contains pointer(s) to AliVertex objects one cannot
721 // change the VertexCopy mode anymore.
722 // To change the VertexCopy mode for an existing AliVertex containing
723 // vertices one first has to invoke Reset().
732 cout << "*AliVertex::SetVertexCopy* Invalid argument : " << j << endl;
737 cout << "*AliVertex::SetVertexCopy* Storage already contained vertices."
738 << " ==> VertexCopy mode not changed." << endl;
741 ///////////////////////////////////////////////////////////////////////////
742 Int_t AliVertex::GetVertexCopy()
744 // Provide value of the VertexCopy mode.
745 // 0 ==> No private copies are made; pointers of original vertices are stored.
746 // 1 ==> Private copies of the vertices are made and these pointers are stored.
749 ///////////////////////////////////////////////////////////////////////////
750 Int_t AliVertex::GetNjets()
752 // Return the current number of jets
755 ///////////////////////////////////////////////////////////////////////////
756 AliJet* AliVertex::GetJet(Int_t i)
758 // Return the i-th jet of the current vertex
761 cout << " *AliVertex*::GetJet* No jets present." << endl;
766 if (i<=0 || i>fNjets)
768 cout << " *AliVertex*::GetJet* Invalid argument i : " << i
769 << " Njets = " << fNjets << endl;
774 return (AliJet*)fJets->At(i-1);
778 ///////////////////////////////////////////////////////////////////////////
779 AliJet* AliVertex::GetIdJet(Int_t id)
781 // Return the jet with user identifier "id"
786 cout << " *AliVertex*::GetIdJet* No jets present." << endl;
791 for (Int_t i=0; i<fNjets; i++)
793 jx=(AliJet*)fJets->At(i);
794 if (id == jx->GetId()) j=jx;
799 ///////////////////////////////////////////////////////////////////////////
800 void AliVertex::SetJetCopy(Int_t j)
802 // (De)activate the creation of private copies of the added jets.
803 // j=0 ==> No private copies are made; pointers of original jets are stored.
804 // j=1 ==> Private copies of the jets are made and these pointers are stored.
806 // Note : Once the storage contains pointer(s) to AliJet objects one cannot
807 // change the JetCopy mode anymore.
808 // To change the JetCopy mode for an existing AliVertex containing
809 // jets one first has to invoke Reset().
818 cout << "*AliVertex::SetJetCopy* Invalid argument : " << j << endl;
823 cout << "*AliVertex::SetJetCopy* Storage already contained jets."
824 << " ==> JetCopy mode not changed." << endl;
827 ///////////////////////////////////////////////////////////////////////////
828 Int_t AliVertex::GetJetCopy()
830 // Provide value of the JetCopy mode.
831 // 0 ==> No private copies are made; pointers of original jets are stored.
832 // 1 ==> Private copies of the jets are made and these pointers are stored.
835 ///////////////////////////////////////////////////////////////////////////
836 Int_t AliVertex::IsConnectTrack(AliTrack* t)
838 // Indicate whether a track from the tracklist was created via the
839 // connection of a (secondary) vertex or not.
840 // In case the track was the result of (secondary) vertex addition the
841 // return value is 1, otherwise the value 0 will be returned.
845 if (fConnects->FindObject(t)) connect=1;
849 ///////////////////////////////////////////////////////////////////////////
850 Int_t AliVertex::IsJetTrack(AliTrack* t)
852 // Indicate whether a track from the tracklist was created via the
853 // addition of a jet or not.
854 // In case the track was the result of jet addition the return value is 1,
855 // otherwise the value 0 will be returned.
859 if (fJetTracks->FindObject(t)) jetflag=1;
863 ///////////////////////////////////////////////////////////////////////////
864 void AliVertex::Draw(Int_t secs,Int_t cons,Int_t jets)
866 // 3-Dimensional visualisation of an AliVertex with its attributes.
867 // The displayed tracklength is proportional to the momentum of the track.
869 // Color conventions :
870 // -------------------
871 // positive track : red
872 // neutral track : green
873 // negative track : blue
874 // jet-track : magenta (if explicit marking selected)
876 // secs = 1 --> Draw secondary vertices. (Default)
877 // 0 --> Don't draw secondary vertices.
879 // cons = 1 --> Draw (auto generated) connecting tracks. (Default)
880 // 0 --> Don't draw (auto generated) connecting tracks.
882 // jets = 1 --> Mark tracks belonging to jets.
883 // 0 --> Don't mark jet-tracks. (Default)
887 // Auto generated connecting tracks will be drawn as thin lines.
888 // Tracks belonging to jets will be marked as somewhat thinner magenta lines.
889 // This memberfunction is used recursively.
891 Double_t vec[3]={0,0,0};
900 if (fLines) delete fLines;
901 fLines=new TObjArray();
904 Int_t ntk=GetNtracks();
905 for (Int_t jtk=1; jtk<=ntk; jtk++)
911 charge=tx->GetCharge();
913 TPolyLine3D* line=new TPolyLine3D();
916 if (IsConnectTrack(tx))
920 r=tx->GetBeginPoint();
922 r->GetPosition(vec,"car");
923 line->SetNextPoint(vec[0],vec[1],vec[2]);
926 r->GetPosition(vec,"car");
927 line->SetNextPoint(vec[0],vec[1],vec[2]);
928 line->SetLineWidth(1);
933 r=tx->GetClosestPoint();
935 r->GetPosition(vec,"car");
936 line->SetNextPoint(vec[0],vec[1],vec[2]);
937 p=tx->Get3Momentum();
939 p.GetVector(vec,"car");
940 line->SetNextPoint(vec[0],vec[1],vec[2]);
941 line->SetLineWidth(3);
944 line->SetLineColor(kGreen); // Neutral track
945 if (charge>0) line->SetLineColor(kRed); // Positive track
946 if (charge<0) line->SetLineColor(kBlue); // Negative track
948 // Mark tracks belonging to jets
953 line->SetLineWidth(2);
954 line->SetLineColor(kMagenta);
961 // Go for secondary vertices if selected
964 Int_t nvtx=GetNvertices();
965 for (Int_t jvtx=1; jvtx<=nvtx; jvtx++)
968 if (vx) vx->Draw(secs,cons,jets);
972 ///////////////////////////////////////////////////////////////////////////