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 // 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
57 // AliTrack t1,t2,t3,t4;
59 // ... // code to fill the track data
64 // ... // code to fill the jet data
68 // v1.SetVertexCopy(1);
75 // Float_t r1[3]={2.4,0.1,-8.5};
76 // v1.SetPosition(r1,"car");
79 // v2.SetTrackCopy(1);
81 // AliTrack* tx=new AliTrack();
82 // for (Int_t i=0; i<10; i++)
85 // ... // code to fill the track data
91 // Float_t r2[3]={1.6,-3.2,5.7};
92 // v2.SetPosition(r2,"car");
99 // Float_t r3[3]={6.2,4.8,1.3};
100 // v3.SetPosition(r3,"car");
106 // Float_t e1=v1.GetEnergy();
107 // Ali3Vector p1=v1.Get3Momentum();
109 // v1.GetPosition(loc,"sph");
110 // AliPosition r=v2.GetPosition();
112 // Int_t nt=v2.GetNtracks();
113 // AliTrack* tv=v2.GetTrack(1); // Access track number 1 of Vertex v2
115 // Specify the vertices v2 and v3 as secondary vertices of v1
122 // Int_t nv=v1.GetNvtx();
123 // AliVertex* vx=v1.GetVertex(1); // Access 1st secondary vertex of v1
124 // Float_t e=vx->GetEnergy();
126 // Float_t M=v1.GetInvmass();
128 // Reconstruct Vertex v1 from scratch
131 // v1.SetNvmax(25); // Increase initial no. of sec. vertices
135 // Float_t pos[3]={7,9,4};
136 // v1.SetPosition(pos,"car");
138 // Note : All quantities are in GeV, GeV/c or GeV/c**2
140 //--- Author: Nick van Eijndhoven 04-apr-1998 UU-SAP Utrecht
141 //- Modified: NvE $Date$ UU-SAP Utrecht
142 ///////////////////////////////////////////////////////////////////////////
144 #include "AliVertex.h"
146 ClassImp(AliVertex) // Class implementation to enable ROOT I/O
148 AliVertex::AliVertex()
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.
160 ///////////////////////////////////////////////////////////////////////////
161 void AliVertex::Init()
163 // Initialisation of pointers etc...
175 ///////////////////////////////////////////////////////////////////////////
176 AliVertex::AliVertex(Int_t n)
178 // Create a vertex to hold initially a maximum of n tracks
179 // All variables initialised to 0
189 cout << " *AliVertex* Initial max. number of tracks entered : " << n << endl;
190 cout << " This is invalid. Default initial maximum will be used." << endl;
197 ///////////////////////////////////////////////////////////////////////////
198 AliVertex::~AliVertex()
200 // Default destructor
227 ///////////////////////////////////////////////////////////////////////////
228 AliVertex::AliVertex(AliVertex& v)
236 SetTrackCopy(v.GetTrackCopy());
237 SetVertexCopy(v.GetVertexCopy());
238 SetJetCopy(v.GetJetCopy());
240 SetPosition(v.GetPosition());
242 // Copy all tracks except the ones coming from jets
244 Int_t jetflag=0,connect=0;
246 for (Int_t it=1; it<=v.GetNtracks(); it++)
251 jetflag=v.IsJetTrack(tx);
252 connect=v.IsConnectTrack(tx);
254 if (!jetflag && !connect) AddTrack(tx);
260 fConnects=new TObjArray(fNvmax);
261 if (!fTrackCopy) fConnects->SetOwner();
263 tx2=new AliTrack(*tx);
270 // Copy all the (secondary) vertices without re-creating connecting tracks
271 // The connecting tracks have already been copied above
273 for (Int_t iv=1; iv<=v.GetNvertices(); iv++)
276 if (vx) AddVertex(vx,0);
279 // Copy all the jets including the jet tracks for these jets for which
280 // this was also the case in the original vertex
282 for (Int_t ij=1; ij<=v.GetNjets(); ij++)
288 if (jx->GetNtracks())
293 jetflag=v.IsJetTrack(tx);
300 ///////////////////////////////////////////////////////////////////////////
301 void AliVertex::SetNvmax(Int_t n)
303 // Set the initial maximum number of (secondary) vertices
318 ///////////////////////////////////////////////////////////////////////////
319 void AliVertex::SetNjmax(Int_t n)
321 // Set the initial maximum number of jets
336 ///////////////////////////////////////////////////////////////////////////
337 void AliVertex::Reset()
339 // Reset all variables to 0 and reset all stored vertex and jet lists.
340 // The max. number of tracks is set to the initial value again
341 // The max. number of vertices is set to the default value again
342 // The max. number of jets is set to the default value again
346 Double_t a[3]={0,0,0};
347 SetPosition(a,"sph");
348 SetPositionErrors(a,"car");
351 if (fNvmax>0) SetNvmax(fNvmax);
359 if (fNjmax>0) SetNjmax(fNjmax);
372 ///////////////////////////////////////////////////////////////////////////
373 void AliVertex::ResetVertices()
375 // Reset the stored vertex list and delete all connecting tracks which
376 // were generated automatically via connect=1 in AddVertex().
377 // The max. number of vertices is set to the default value again.
378 // All physics quantities are updated according to the removal of the
379 // connecting tracks.
383 for (Int_t i=0; i<=fConnects->GetLast(); i++)
385 t=(AliTrack*)fConnects->At(i);
386 AliTrack* test=(AliTrack*)fTracks->Remove(t);
390 (Ali4Vector&)(*this)-=(Ali4Vector&)(*t);
392 if (fTrackCopy) delete t;
399 if (fNvmax>0) SetNvmax(fNvmax);
406 ///////////////////////////////////////////////////////////////////////////
407 void AliVertex::AddJet(AliJet& j,Int_t tracks)
409 // Add a jet (and its tracks) to the vertex
410 // In case the maximum number of jets has been reached,
411 // the array space will be extended automatically
413 // Note : By default the tracks of the jet are added to the current (primary)
415 // The automatic addition of the tracks of the jet can be suppressed
416 // by specifying tracks=0. In this case only the AliJet object will
417 // be stored according to the mode specified by SetJetCopy().
418 // The latter will enable jet studies based on a fixed list of tracks
419 // as contained e.g. in an AliVertex or AliEvent.
422 fJets=new TObjArray(fNjmax);
423 if (fJetCopy) fJets->SetOwner();
425 if (fNjets == fNjmax) // Check if maximum jet number is reached
428 fJets->Expand(fNjmax);
431 // Add the jet to the list
433 if (fJetCopy) jx=new AliJet(j);
441 // Add the tracks of the jet to this vertex
446 fJetTracks=new TObjArray();
448 Int_t copy=1-(jx->GetTrackCopy());
450 for (Int_t i=1; i<=jx->GetNtracks(); i++)
461 ///////////////////////////////////////////////////////////////////////////
462 void AliVertex::AddVertex(AliVertex& v,Int_t connect)
464 // Add a (secondary) vertex to the current vertex.
465 // In case the maximum number of (secondary) vertices has been reached,
466 // the array space will be extended automatically
468 // Note : By default the 4-momentum and charge of the current (primary) vertex
469 // are updated by automatically creating the track connecting
470 // both vertices. The track parameters are taken from the
471 // 4-momentum and charge of the secondary vertex.
472 // The automatic creation of the connecting track and updating
473 // of the (primary) vertex 4-momentum and charge can be suppressed
474 // by specifying connect=0. In this case, however, the user
475 // has to introduce the connecting track lateron by hand
476 // explicitly in order to match the kinematics and charge.
480 fVertices=new TObjArray(fNvmax);
481 if (fVertexCopy) fVertices->SetOwner();
483 if (fNvtx == fNvmax) // Check if maximum vertex number is reached
486 fVertices->Expand(fNvmax);
489 // Add the linked (secondary) vertex to the list
491 if (fVertexCopy) vx=new AliVertex(v);
499 // Create connecting track and update 4-momentum and charge for current vertex
502 AliTrack* t=new AliTrack();
503 t->SetBeginPoint(GetPosition());
504 t->SetEndPoint(v.GetPosition());
505 t->SetCharge(v.GetCharge());
506 t->Set4Momentum((Ali4Vector&)v);
512 fConnects=new TObjArray(fNvmax);
513 if (!fTrackCopy) fConnects->SetOwner();
518 ///////////////////////////////////////////////////////////////////////////
519 void AliVertex::Info(TString f)
521 // Provide vertex information within the coordinate frame f
522 cout << " *AliVertex::Info* Id : " << fUserId << " Invmass : " << GetInvmass()
523 << " Charge : " << GetCharge() << " Momentum : " << GetMomentum()
524 << " Ntracks : " << GetNtracks() << " Nvertices : " << fNvtx
525 << " Njets : " << fNjets << endl;
529 AliPosition::Info(f);
531 ///////////////////////////////////////////////////////////////////////////
532 void AliVertex::List(TString f)
534 // Provide primary track and sec. vertex information within the coordinate frame f
536 Info(f); // Information of the current vertex
538 // The tracks of this vertex
540 for (Int_t it=1; it<=GetNtracks(); it++)
545 cout << " ---Track no. " << it << endl;
551 cout << " *AliVertex::List* Error : No track present." << endl;
555 // The secondary vertices of this vertex
557 for (Int_t iv=1; iv<=GetNvertices(); iv++)
562 cout << " ---Level 1 sec. vertex no. " << iv << endl;
568 cout << " *AliVertex::List* Error : No sec. vertex present." << endl;
572 ///////////////////////////////////////////////////////////////////////////
573 void AliVertex::ListAll(TString f)
575 // Provide complete (sec) vertex and (decay) track info within the coordinate frame f
577 Info(f); // Information of the current vertex
579 // The tracks of this vertex
581 for (Int_t it=1; it<=GetNtracks(); it++)
586 cout << " ---Track no. " << it << endl;
592 cout << " *AliVertex::ListAll* Error : No track present." << endl;
597 Dump(v,1,f); // Information of all sec. vertices
599 //////////////////////////////////////////////////////////////////////////
600 void AliVertex::Dump(AliVertex* v,Int_t n,TString f)
602 // Recursively provide the info of all secondary vertices of this vertex
604 for (Int_t iv=1; iv<=v->GetNvertices(); iv++)
609 cout << " ---Level " << n << " sec. vertex no. " << iv << endl;
613 // The tracks of this vertex
615 for (Int_t it=1; it<=vs->GetNtracks(); it++)
620 cout << " ---Track no. " << it << endl;
626 cout << " *AliVertex::Dump* Error : No track present." << endl;
630 // Go for next sec. vertex level of this sec. vertex recursively
635 cout << " *AliVertex::Dump* Error : No sec. vertex present." << endl;
639 //////////////////////////////////////////////////////////////////////////
640 Int_t AliVertex::GetNvertices()
642 // Return the current number of (secondary) vertices
645 ///////////////////////////////////////////////////////////////////////////
646 AliVertex* AliVertex::GetVertex(Int_t i)
648 // Return the i-th (secondary) vertex of the current vertex
651 cout << " *AliVertex*::GetVertex* No (secondary) vertices present." << endl;
658 cout << " *AliVertex*::GetVertex* Invalid argument i : " << i
659 << " Nvtx = " << fNvtx << endl;
664 return (AliVertex*)fVertices->At(i-1);
668 ///////////////////////////////////////////////////////////////////////////
669 AliVertex* AliVertex::GetIdVertex(Int_t id)
671 // Return the (sec.) vertex with user identifier "id"
676 cout << " *AliVertex*::GetIdVertex* No (secondary) vertices present." << endl;
681 for (Int_t i=0; i<fNvtx; i++)
683 vx=(AliVertex*)fVertices->At(i);
684 if (id == vx->GetId()) v=vx;
689 ///////////////////////////////////////////////////////////////////////////
690 void AliVertex::SetVertexCopy(Int_t j)
692 // (De)activate the creation of private copies of the added vertices.
693 // j=0 ==> No private copies are made; pointers of original vertices are stored.
694 // j=1 ==> Private copies of the vertices are made and these pointers are stored.
696 // Note : Once the storage contains pointer(s) to AliVertex objects one cannot
697 // change the VertexCopy mode anymore.
698 // To change the VertexCopy mode for an existing AliVertex containing
699 // vertices one first has to invoke Reset().
708 cout << "*AliVertex::SetVertexCopy* Invalid argument : " << j << endl;
713 cout << "*AliVertex::SetVertexCopy* Storage already contained vertices."
714 << " ==> VertexCopy mode not changed." << endl;
717 ///////////////////////////////////////////////////////////////////////////
718 Int_t AliVertex::GetVertexCopy()
720 // Provide value of the VertexCopy mode.
721 // 0 ==> No private copies are made; pointers of original vertices are stored.
722 // 1 ==> Private copies of the vertices are made and these pointers are stored.
725 ///////////////////////////////////////////////////////////////////////////
726 Int_t AliVertex::GetNjets()
728 // Return the current number of jets
731 ///////////////////////////////////////////////////////////////////////////
732 AliJet* AliVertex::GetJet(Int_t i)
734 // Return the i-th jet of the current vertex
737 cout << " *AliVertex*::GetJet* No jets present." << endl;
742 if (i<=0 || i>fNjets)
744 cout << " *AliVertex*::GetJet* Invalid argument i : " << i
745 << " Njets = " << fNjets << endl;
750 return (AliJet*)fJets->At(i-1);
754 ///////////////////////////////////////////////////////////////////////////
755 AliJet* AliVertex::GetIdJet(Int_t id)
757 // Return the jet with user identifier "id"
762 cout << " *AliVertex*::GetIdJet* No jets present." << endl;
767 for (Int_t i=0; i<fNjets; i++)
769 jx=(AliJet*)fJets->At(i);
770 if (id == jx->GetId()) j=jx;
775 ///////////////////////////////////////////////////////////////////////////
776 void AliVertex::SetJetCopy(Int_t j)
778 // (De)activate the creation of private copies of the added jets.
779 // j=0 ==> No private copies are made; pointers of original jets are stored.
780 // j=1 ==> Private copies of the jets are made and these pointers are stored.
782 // Note : Once the storage contains pointer(s) to AliJet objects one cannot
783 // change the JetCopy mode anymore.
784 // To change the JetCopy mode for an existing AliVertex containing
785 // jets one first has to invoke Reset().
794 cout << "*AliVertex::SetJetCopy* Invalid argument : " << j << endl;
799 cout << "*AliVertex::SetJetCopy* Storage already contained jets."
800 << " ==> JetCopy mode not changed." << endl;
803 ///////////////////////////////////////////////////////////////////////////
804 Int_t AliVertex::GetJetCopy()
806 // Provide value of the JetCopy mode.
807 // 0 ==> No private copies are made; pointers of original jets are stored.
808 // 1 ==> Private copies of the jets are made and these pointers are stored.
811 ///////////////////////////////////////////////////////////////////////////
812 Int_t AliVertex::IsConnectTrack(AliTrack* t)
814 // Indicate whether a track from the tracklist was created via the
815 // connection of a (secondary) vertex or not.
816 // In case the track was the result of (secondary) vertex addition the
817 // return value is 1, otherwise the value 0 will be returned.
821 if (fConnects->FindObject(t)) connect=1;
825 ///////////////////////////////////////////////////////////////////////////
826 Int_t AliVertex::IsJetTrack(AliTrack* t)
828 // Indicate whether a track from the tracklist was created via the
829 // addition of a jet or not.
830 // In case the track was the result of jet addition the return value is 1,
831 // otherwise the value 0 will be returned.
835 if (fJetTracks->FindObject(t)) jetflag=1;
839 ///////////////////////////////////////////////////////////////////////////
840 void AliVertex::Draw(Int_t secs,Int_t cons,Int_t jets)
842 // 3-Dimensional visualisation of an AliVertex with its attributes.
843 // The displayed tracklength is proportional to the momentum of the track.
845 // Color conventions :
846 // -------------------
847 // positive track : red
848 // neutral track : green
849 // negative track : blue
850 // jet-track : magenta (if explicit marking selected)
852 // secs = 1 --> Draw secondary vertices.
853 // 0 --> Don't draw secondary vertices.
855 // cons = 1 --> Draw (auto generated) connecting tracks.
856 // 0 --> Don't draw (auto generated) connecting tracks.
858 // jets = 1 --> Mark tracks belonging to jets.
859 // 0 --> Don't mark jet-tracks.
863 // Auto generated connecting tracks will be drawn as thin lines.
864 // Tracks belonging to jets will be marked as somewhat thinner magenta lines.
865 // This memberfunction is used recursively.
867 Double_t vec[3]={0,0,0};
874 if (fLines) delete fLines;
875 fLines=new TObjArray();
878 Int_t ntk=GetNtracks();
879 for (Int_t jtk=1; jtk<=ntk; jtk++)
885 charge=tx->GetCharge();
887 TPolyLine3D* line=new TPolyLine3D();
890 if (IsConnectTrack(tx))
894 r=tx->GetBeginPoint();
895 r.GetPosition(vec,"car");
896 line->SetNextPoint(vec[0],vec[1],vec[2]);
898 r.GetPosition(vec,"car");
899 line->SetNextPoint(vec[0],vec[1],vec[2]);
900 line->SetLineWidth(1);
905 r=tx->GetClosestPoint();
906 r.GetPosition(vec,"car");
907 line->SetNextPoint(vec[0],vec[1],vec[2]);
908 p=tx->Get3Momentum();
910 p.GetVector(vec,"car");
911 line->SetNextPoint(vec[0],vec[1],vec[2]);
912 line->SetLineWidth(3);
915 if (charge>0) line->SetLineColor(kRed); // Positive track
916 if (!charge) line->SetLineColor(kGreen); // Neutral track
917 if (charge<0) line->SetLineColor(kBlue); // Negative track
919 // Mark tracks belonging to jets
924 line->SetLineWidth(2);
925 line->SetLineColor(kMagenta);
932 // Go for secondary vertices if selected
935 Int_t nvtx=GetNvertices();
936 for (Int_t jvtx=1; jvtx<=nvtx; jvtx++)
939 if (vx) vx->Draw(secs,cons,jets);
943 ///////////////////////////////////////////////////////////////////////////