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"
148 ClassImp(AliVertex) // Class implementation to enable ROOT I/O
150 AliVertex::AliVertex()
152 // Default constructor.
153 // All variables initialised to 0.
154 // Initial maximum number of tracks is set to the default value.
155 // Initial maximum number of sec. vertices is set to the default value.
162 ///////////////////////////////////////////////////////////////////////////
163 void AliVertex::Init()
165 // Initialisation of pointers etc...
177 ///////////////////////////////////////////////////////////////////////////
178 AliVertex::AliVertex(Int_t n)
180 // Create a vertex to hold initially a maximum of n tracks
181 // All variables initialised to 0
191 cout << " *AliVertex* Initial max. number of tracks entered : " << n << endl;
192 cout << " This is invalid. Default initial maximum will be used." << endl;
199 ///////////////////////////////////////////////////////////////////////////
200 AliVertex::~AliVertex()
202 // Default destructor
229 ///////////////////////////////////////////////////////////////////////////
230 void AliVertex::SetOwner(Bool_t own)
232 // Set ownership of all added objects.
233 // The default parameter is own=kTRUE.
235 // Invokation of this memberfunction also sets all the copy modes
236 // (e.g. TrackCopy & co.) according to the value of own.
238 // This function (with own=kTRUE) is particularly useful when reading data
239 // from a tree/file, since Reset() will then actually remove all the
240 // added objects from memory irrespective of the copy mode settings
241 // during the tree/file creation process. In this way it provides a nice way
242 // of preventing possible memory leaks in the reading/analysis process.
244 // In addition this memberfunction can also be used as a shortcut to set all
245 // copy modes in one go during a tree/file creation process.
246 // However, in this case the user has to take care to only set/change the
247 // ownership (and copy mode) for empty objects (e.g. newly created objects
248 // or after invokation of the Reset() memberfunction) otherwise it will
249 // very likely result in inconsistent destructor behaviour.
253 if (fVertices) fVertices->SetOwner(own);
255 if (fJets) fJets->SetOwner(own);
258 AliJet::SetOwner(own);
260 ///////////////////////////////////////////////////////////////////////////
261 AliVertex::AliVertex(AliVertex& v)
269 SetTrackCopy(v.GetTrackCopy());
270 SetVertexCopy(v.GetVertexCopy());
271 SetJetCopy(v.GetJetCopy());
273 SetPosition(v.GetPosition());
275 // Copy all tracks except the ones coming from jets
277 Int_t jetflag=0,connect=0;
279 for (Int_t it=1; it<=v.GetNtracks(); it++)
284 jetflag=v.IsJetTrack(tx);
285 connect=v.IsConnectTrack(tx);
287 if (!jetflag && !connect) AddTrack(tx);
293 fConnects=new TObjArray(fNvmax);
294 if (!fTrackCopy) fConnects->SetOwner();
296 tx2=new AliTrack(*tx);
303 // Copy all the (secondary) vertices without re-creating connecting tracks
304 // The connecting tracks have already been copied above
306 for (Int_t iv=1; iv<=v.GetNvertices(); iv++)
309 if (vx) AddVertex(vx,0);
312 // Copy all the jets including the jet tracks for these jets for which
313 // this was also the case in the original vertex
315 for (Int_t ij=1; ij<=v.GetNjets(); ij++)
321 if (jx->GetNtracks())
326 jetflag=v.IsJetTrack(tx);
333 ///////////////////////////////////////////////////////////////////////////
334 void AliVertex::SetNvmax(Int_t n)
336 // Set the initial maximum number of (secondary) vertices
351 ///////////////////////////////////////////////////////////////////////////
352 void AliVertex::SetNjmax(Int_t n)
354 // Set the initial maximum number of jets
369 ///////////////////////////////////////////////////////////////////////////
370 void AliVertex::Reset()
372 // Reset all variables to 0 and reset all stored vertex and jet lists.
373 // The max. number of tracks is set to the initial value again
374 // The max. number of vertices is set to the default value again
375 // The max. number of jets is set to the default value again
379 Double_t a[3]={0,0,0};
380 SetPosition(a,"sph");
381 SetPositionErrors(a,"car");
384 if (fNvmax>0) SetNvmax(fNvmax);
392 if (fNjmax>0) SetNjmax(fNjmax);
405 ///////////////////////////////////////////////////////////////////////////
406 void AliVertex::ResetVertices()
408 // Reset the stored vertex list and delete all connecting tracks which
409 // were generated automatically via connect=1 in AddVertex().
410 // The max. number of vertices is set to the default value again.
411 // All physics quantities are updated according to the removal of the
412 // connecting tracks.
416 for (Int_t i=0; i<=fConnects->GetLast(); i++)
418 t=(AliTrack*)fConnects->At(i);
419 AliTrack* test=(AliTrack*)fTracks->Remove(t);
423 (Ali4Vector&)(*this)-=(Ali4Vector&)(*t);
425 if (fTrackCopy) delete t;
432 if (fNvmax>0) SetNvmax(fNvmax);
439 ///////////////////////////////////////////////////////////////////////////
440 void AliVertex::AddJet(AliJet& j,Int_t tracks)
442 // Add a jet (and its tracks) to the vertex
443 // In case the maximum number of jets has been reached,
444 // the array space will be extended automatically
446 // Note : By default the tracks of the jet are added to the current (primary)
448 // The automatic addition of the tracks of the jet can be suppressed
449 // by specifying tracks=0. In this case only the AliJet object will
450 // be stored according to the mode specified by SetJetCopy().
451 // The latter will enable jet studies based on a fixed list of tracks
452 // as contained e.g. in an AliVertex or AliEvent.
455 fJets=new TObjArray(fNjmax);
456 if (fJetCopy) fJets->SetOwner();
458 if (fNjets == fNjmax) // Check if maximum jet number is reached
461 fJets->Expand(fNjmax);
464 // Add the jet to the list
466 if (fJetCopy) jx=new AliJet(j);
474 // Add the tracks of the jet to this vertex
479 fJetTracks=new TObjArray();
481 Int_t copy=1-(jx->GetTrackCopy());
483 for (Int_t i=1; i<=jx->GetNtracks(); i++)
494 ///////////////////////////////////////////////////////////////////////////
495 void AliVertex::AddVertex(AliVertex& v,Int_t connect)
497 // Add a (secondary) vertex to the current vertex.
498 // In case the maximum number of (secondary) vertices has been reached,
499 // the array space will be extended automatically
501 // Note : By default the 4-momentum and charge of the current (primary) vertex
502 // are updated by automatically creating the track connecting
503 // both vertices. The track parameters are taken from the
504 // 4-momentum and charge of the secondary vertex.
505 // The automatic creation of the connecting track and updating
506 // of the (primary) vertex 4-momentum and charge can be suppressed
507 // by specifying connect=0. In this case, however, the user
508 // has to introduce the connecting track lateron by hand
509 // explicitly in order to match the kinematics and charge.
513 fVertices=new TObjArray(fNvmax);
514 if (fVertexCopy) fVertices->SetOwner();
516 if (fNvtx == fNvmax) // Check if maximum vertex number is reached
519 fVertices->Expand(fNvmax);
522 // Add the linked (secondary) vertex to the list
524 if (fVertexCopy) vx=new AliVertex(v);
532 // Create connecting track and update 4-momentum and charge for current vertex
535 AliTrack* t=new AliTrack();
536 t->SetBeginPoint(GetPosition());
537 t->SetEndPoint(v.GetPosition());
538 t->SetCharge(v.GetCharge());
539 t->Set4Momentum((Ali4Vector&)v);
545 fConnects=new TObjArray(fNvmax);
546 if (!fTrackCopy) fConnects->SetOwner();
551 ///////////////////////////////////////////////////////////////////////////
552 void AliVertex::Data(TString f)
554 // Provide vertex information within the coordinate frame f
555 cout << " *AliVertex::Data* Id : " << fUserId << " Invmass : " << GetInvmass()
556 << " Charge : " << GetCharge() << " Momentum : " << GetMomentum()
557 << " Ntracks : " << GetNtracks() << " Nvertices : " << fNvtx
558 << " Njets : " << fNjets << endl;
562 AliPosition::Data(f);
564 ///////////////////////////////////////////////////////////////////////////
565 void AliVertex::List(TString f)
567 // Provide primary track and sec. vertex information within the coordinate frame f
569 Data(f); // Information of the current vertex
571 // The tracks of this vertex
573 for (Int_t it=1; it<=GetNtracks(); it++)
578 cout << " ---Track no. " << it << endl;
584 cout << " *AliVertex::List* Error : No track present." << endl;
588 // The secondary vertices of this vertex
590 for (Int_t iv=1; iv<=GetNvertices(); iv++)
595 cout << " ---Level 1 sec. vertex no. " << iv << endl;
601 cout << " *AliVertex::List* Error : No sec. vertex present." << endl;
605 ///////////////////////////////////////////////////////////////////////////
606 void AliVertex::ListAll(TString f)
608 // Provide complete (sec) vertex and (decay) track info within the coordinate frame f
610 Data(f); // Information of the current vertex
612 // The tracks of this vertex
614 for (Int_t it=1; it<=GetNtracks(); it++)
619 cout << " ---Track no. " << it << endl;
625 cout << " *AliVertex::ListAll* Error : No track present." << endl;
630 Dump(v,1,f); // Information of all sec. vertices
632 //////////////////////////////////////////////////////////////////////////
633 void AliVertex::Dump(AliVertex* v,Int_t n,TString f)
635 // Recursively provide the info of all secondary vertices of this vertex
637 for (Int_t iv=1; iv<=v->GetNvertices(); iv++)
642 cout << " ---Level " << n << " sec. vertex no. " << iv << endl;
646 // The tracks of this vertex
648 for (Int_t it=1; it<=vs->GetNtracks(); it++)
653 cout << " ---Track no. " << it << endl;
659 cout << " *AliVertex::Dump* Error : No track present." << endl;
663 // Go for next sec. vertex level of this sec. vertex recursively
668 cout << " *AliVertex::Dump* Error : No sec. vertex present." << endl;
672 //////////////////////////////////////////////////////////////////////////
673 Int_t AliVertex::GetNvertices()
675 // Return the current number of (secondary) vertices
678 ///////////////////////////////////////////////////////////////////////////
679 AliVertex* AliVertex::GetVertex(Int_t i)
681 // Return the i-th (secondary) vertex of the current vertex
684 cout << " *AliVertex*::GetVertex* No (secondary) vertices present." << endl;
691 cout << " *AliVertex*::GetVertex* Invalid argument i : " << i
692 << " Nvtx = " << fNvtx << endl;
697 return (AliVertex*)fVertices->At(i-1);
701 ///////////////////////////////////////////////////////////////////////////
702 AliVertex* AliVertex::GetIdVertex(Int_t id)
704 // Return the (sec.) vertex with user identifier "id"
709 cout << " *AliVertex*::GetIdVertex* No (secondary) vertices present." << endl;
714 for (Int_t i=0; i<fNvtx; i++)
716 vx=(AliVertex*)fVertices->At(i);
717 if (id == vx->GetId()) v=vx;
722 ///////////////////////////////////////////////////////////////////////////
723 void AliVertex::SetVertexCopy(Int_t j)
725 // (De)activate the creation of private copies of the added vertices.
726 // j=0 ==> No private copies are made; pointers of original vertices are stored.
727 // j=1 ==> Private copies of the vertices are made and these pointers are stored.
729 // Note : Once the storage contains pointer(s) to AliVertex objects one cannot
730 // change the VertexCopy mode anymore.
731 // To change the VertexCopy mode for an existing AliVertex containing
732 // vertices one first has to invoke Reset().
741 cout << "*AliVertex::SetVertexCopy* Invalid argument : " << j << endl;
746 cout << "*AliVertex::SetVertexCopy* Storage already contained vertices."
747 << " ==> VertexCopy mode not changed." << endl;
750 ///////////////////////////////////////////////////////////////////////////
751 Int_t AliVertex::GetVertexCopy()
753 // Provide value of the VertexCopy mode.
754 // 0 ==> No private copies are made; pointers of original vertices are stored.
755 // 1 ==> Private copies of the vertices are made and these pointers are stored.
758 ///////////////////////////////////////////////////////////////////////////
759 Int_t AliVertex::GetNjets()
761 // Return the current number of jets
764 ///////////////////////////////////////////////////////////////////////////
765 AliJet* AliVertex::GetJet(Int_t i)
767 // Return the i-th jet of the current vertex
770 cout << " *AliVertex*::GetJet* No jets present." << endl;
775 if (i<=0 || i>fNjets)
777 cout << " *AliVertex*::GetJet* Invalid argument i : " << i
778 << " Njets = " << fNjets << endl;
783 return (AliJet*)fJets->At(i-1);
787 ///////////////////////////////////////////////////////////////////////////
788 AliJet* AliVertex::GetIdJet(Int_t id)
790 // Return the jet with user identifier "id"
795 cout << " *AliVertex*::GetIdJet* No jets present." << endl;
800 for (Int_t i=0; i<fNjets; i++)
802 jx=(AliJet*)fJets->At(i);
803 if (id == jx->GetId()) j=jx;
808 ///////////////////////////////////////////////////////////////////////////
809 void AliVertex::SetJetCopy(Int_t j)
811 // (De)activate the creation of private copies of the added jets.
812 // j=0 ==> No private copies are made; pointers of original jets are stored.
813 // j=1 ==> Private copies of the jets are made and these pointers are stored.
815 // Note : Once the storage contains pointer(s) to AliJet objects one cannot
816 // change the JetCopy mode anymore.
817 // To change the JetCopy mode for an existing AliVertex containing
818 // jets one first has to invoke Reset().
827 cout << "*AliVertex::SetJetCopy* Invalid argument : " << j << endl;
832 cout << "*AliVertex::SetJetCopy* Storage already contained jets."
833 << " ==> JetCopy mode not changed." << endl;
836 ///////////////////////////////////////////////////////////////////////////
837 Int_t AliVertex::GetJetCopy()
839 // Provide value of the JetCopy mode.
840 // 0 ==> No private copies are made; pointers of original jets are stored.
841 // 1 ==> Private copies of the jets are made and these pointers are stored.
844 ///////////////////////////////////////////////////////////////////////////
845 Int_t AliVertex::IsConnectTrack(AliTrack* t)
847 // Indicate whether a track from the tracklist was created via the
848 // connection of a (secondary) vertex or not.
849 // In case the track was the result of (secondary) vertex addition the
850 // return value is 1, otherwise the value 0 will be returned.
854 if (fConnects->FindObject(t)) connect=1;
858 ///////////////////////////////////////////////////////////////////////////
859 Int_t AliVertex::IsJetTrack(AliTrack* t)
861 // Indicate whether a track from the tracklist was created via the
862 // addition of a jet or not.
863 // In case the track was the result of jet addition the return value is 1,
864 // otherwise the value 0 will be returned.
868 if (fJetTracks->FindObject(t)) jetflag=1;
872 ///////////////////////////////////////////////////////////////////////////
873 void AliVertex::Draw(Int_t secs,Int_t cons,Int_t jets)
875 // 3-Dimensional visualisation of an AliVertex with its attributes.
876 // The displayed tracklength is proportional to the momentum of the track.
878 // Color conventions :
879 // -------------------
880 // positive track : red
881 // neutral track : green
882 // negative track : blue
883 // jet-track : magenta (if explicit marking selected)
885 // secs = 1 --> Draw secondary vertices.
886 // 0 --> Don't draw secondary vertices.
888 // cons = 1 --> Draw (auto generated) connecting tracks.
889 // 0 --> Don't draw (auto generated) connecting tracks.
891 // jets = 1 --> Mark tracks belonging to jets.
892 // 0 --> Don't mark jet-tracks.
896 // Auto generated connecting tracks will be drawn as thin lines.
897 // Tracks belonging to jets will be marked as somewhat thinner magenta lines.
898 // This memberfunction is used recursively.
900 Double_t vec[3]={0,0,0};
907 if (fLines) delete fLines;
908 fLines=new TObjArray();
911 Int_t ntk=GetNtracks();
912 for (Int_t jtk=1; jtk<=ntk; jtk++)
918 charge=static_cast<int>(tx->GetCharge());
920 TPolyLine3D* line=new TPolyLine3D();
923 if (IsConnectTrack(tx))
927 r=tx->GetBeginPoint();
928 r.GetPosition(vec,"car");
929 line->SetNextPoint(vec[0],vec[1],vec[2]);
931 r.GetPosition(vec,"car");
932 line->SetNextPoint(vec[0],vec[1],vec[2]);
933 line->SetLineWidth(1);
938 r=tx->GetClosestPoint();
939 r.GetPosition(vec,"car");
940 line->SetNextPoint(vec[0],vec[1],vec[2]);
941 p=tx->Get3Momentum();
943 p.GetVector(vec,"car");
944 line->SetNextPoint(vec[0],vec[1],vec[2]);
945 line->SetLineWidth(3);
948 if (charge>0) line->SetLineColor(kRed); // Positive track
949 if (!charge) line->SetLineColor(kGreen); // Neutral track
950 if (charge<0) line->SetLineColor(kBlue); // Negative track
952 // Mark tracks belonging to jets
957 line->SetLineWidth(2);
958 line->SetLineColor(kMagenta);
965 // Go for secondary vertices if selected
968 Int_t nvtx=GetNvertices();
969 for (Int_t jvtx=1; jvtx<=nvtx; jvtx++)
972 if (vx) vx->Draw(secs,cons,jets);
976 ///////////////////////////////////////////////////////////////////////////