]> git.uio.no Git - u/mrichter/AliRoot.git/blame - RALICE/AliVertex.cxx
27-oct-2005 NvE Memberfunction GetX to access individual vector components also intro...
[u/mrichter/AliRoot.git] / RALICE / AliVertex.cxx
CommitLineData
4c039060 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
f531a546 16// $Id$
4c039060 17
959fbac5 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//
f34f4acb 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.
35044448 36//
37// Note :
f34f4acb 38// Modifications made to the original vertices also affect the AliVertex objects
35044448 39// which are stored.
40//
f34f4acb 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
35044448 49// AliVertex::Reset, AliVertex::AddTrack and parameter setting memberfunctions.
f34f4acb 50//
8e8e6c7f 51// See also the documentation provided for the memberfunction SetOwner().
52//
959fbac5 53// Coding example to make 3 vertices v1, v2 and v3.
54// ------------------------------------------------
55// v1 contains the tracks 1,2,3 and 4
f34f4acb 56// v2 contains many different tracks
959fbac5 57// v3 contains the jets 1 and 2
58//
f34f4acb 59// AliTrack t1,t2,t3,t4;
959fbac5 60// ...
61// ... // code to fill the track data
62// ...
63//
64// AliJet j1,j2;
65// ...
66// ... // code to fill the jet data
67// ...
68//
f34f4acb 69// AliVertex v1;
70// v1.SetVertexCopy(1);
959fbac5 71//
f531a546 72// v1.AddTrack(t1);
73// v1.AddTrack(t2);
74// v1.AddTrack(t3);
75// v1.AddTrack(t4);
959fbac5 76//
77// Float_t r1[3]={2.4,0.1,-8.5};
78// v1.SetPosition(r1,"car");
79//
f34f4acb 80// AliVertex v2;
81// v2.SetTrackCopy(1);
82//
83// AliTrack* tx=new AliTrack();
84// for (Int_t i=0; i<10; i++)
85// {
86// ...
87// ... // code to fill the track data
88// ...
89// v2.AddTrack(tx);
90// tx->Reset();
91// }
959fbac5 92//
93// Float_t r2[3]={1.6,-3.2,5.7};
94// v2.SetPosition(r2,"car");
95//
96// AliVertex v3;
97//
f531a546 98// v3.AddJet(j1);
99// v3.AddJet(j2);
959fbac5 100//
101// Float_t r3[3]={6.2,4.8,1.3};
102// v3.SetPosition(r3,"car");
103//
84bb7c66 104// v1.Data("sph");
959fbac5 105// v2.ListAll();
106// v3.List("cyl");
107//
108// Float_t e1=v1.GetEnergy();
109// Ali3Vector p1=v1.Get3Momentum();
110// Float_t loc[3];
111// v1.GetPosition(loc,"sph");
112// AliPosition r=v2.GetPosition();
84bb7c66 113// r.Data();
959fbac5 114// Int_t nt=v2.GetNtracks();
115// AliTrack* tv=v2.GetTrack(1); // Access track number 1 of Vertex v2
116//
117// Specify the vertices v2 and v3 as secondary vertices of v1
118//
f531a546 119// v1.AddVertex(v2);
120// v1.AddVertex(v3);
959fbac5 121//
122// v1.List();
123//
124// Int_t nv=v1.GetNvtx();
125// AliVertex* vx=v1.GetVertex(1); // Access 1st secondary vertex of v1
126// Float_t e=vx->GetEnergy();
127//
128// Float_t M=v1.GetInvmass();
129//
130// Reconstruct Vertex v1 from scratch
131//
132// v1.Reset();
133// v1.SetNvmax(25); // Increase initial no. of sec. vertices
f531a546 134// v1.AddTrack(t3);
f34f4acb 135// v1.AddTrack(t4);
f531a546 136// v1.AddJet(j2);
959fbac5 137// Float_t pos[3]={7,9,4};
138// v1.SetPosition(pos,"car");
139//
140// Note : All quantities are in GeV, GeV/c or GeV/c**2
141//
142//--- Author: Nick van Eijndhoven 04-apr-1998 UU-SAP Utrecht
f531a546 143//- Modified: NvE $Date$ UU-SAP Utrecht
959fbac5 144///////////////////////////////////////////////////////////////////////////
145
d88f97cc 146#include "AliVertex.h"
c72198f1 147#include "Riostream.h"
d88f97cc 148
149ClassImp(AliVertex) // Class implementation to enable ROOT I/O
150
c72198f1 151AliVertex::AliVertex() : AliJet(),AliPosition()
d88f97cc 152{
959fbac5 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.
6516b62d 157 Init();
d88f97cc 158 Reset();
d88f97cc 159 SetNvmax();
f34f4acb 160 SetNjmax();
d88f97cc 161}
162///////////////////////////////////////////////////////////////////////////
6516b62d 163void AliVertex::Init()
d88f97cc 164{
6516b62d 165// Initialisation of pointers etc...
d88f97cc 166 fNvmax=0;
167 fVertices=0;
29beb80d 168 fConnects=0;
f34f4acb 169 fVertexCopy=0;
170 fNjmax=0;
171 fJets=0;
6516b62d 172 fJetTracks=0;
f34f4acb 173 fJetCopy=0;
a37bb40e 174 fLines=0;
6516b62d 175}
176///////////////////////////////////////////////////////////////////////////
c72198f1 177AliVertex::AliVertex(Int_t n) : AliJet(n),AliPosition()
6516b62d 178{
179// Create a vertex to hold initially a maximum of n tracks
180// All variables initialised to 0
c72198f1 181 if (n<=0)
d88f97cc 182 {
c72198f1 183 cout << " *** This AliJet initialisation was invoked via the AliVertex ctor." << endl;
d88f97cc 184 }
c72198f1 185 Init();
186 Reset();
d88f97cc 187 SetNvmax();
f34f4acb 188 SetNjmax();
d88f97cc 189}
190///////////////////////////////////////////////////////////////////////////
191AliVertex::~AliVertex()
192{
193// Default destructor
f34f4acb 194 if (fVertices)
195 {
f34f4acb 196 delete fVertices;
197 fVertices=0;
198 }
29beb80d 199 if (fConnects)
200 {
29beb80d 201 delete fConnects;
202 fConnects=0;
203 }
f34f4acb 204 if (fJets)
205 {
f34f4acb 206 delete fJets;
207 fJets=0;
208 }
6516b62d 209 if (fJetTracks)
210 {
211 delete fJetTracks;
212 fJetTracks=0;
213 }
a37bb40e 214 if (fLines)
215 {
216 delete fLines;
217 fLines=0;
218 }
6516b62d 219}
220///////////////////////////////////////////////////////////////////////////
8e8e6c7f 221void AliVertex::SetOwner(Bool_t own)
222{
223// Set ownership of all added objects.
224// The default parameter is own=kTRUE.
225//
226// Invokation of this memberfunction also sets all the copy modes
227// (e.g. TrackCopy & co.) according to the value of own.
228//
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.
234//
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.
241
242 Int_t mode=1;
243 if (!own) mode=0;
244 if (fVertices) fVertices->SetOwner(own);
245 fVertexCopy=mode;
246 if (fJets) fJets->SetOwner(own);
247 fJetCopy=mode;
248
249 AliJet::SetOwner(own);
250}
251///////////////////////////////////////////////////////////////////////////
261c0caf 252AliVertex::AliVertex(const AliVertex& v) : AliJet(v.fNtinit),AliPosition(v)
6516b62d 253{
254// Copy constructor
255 Init();
c72198f1 256 fNvtx=0;
257 fNjets=0;
258 SetNvmax(v.fNvmax);
259 SetNjmax(v.fNjmax);
6516b62d 260 SetTrackCopy(v.GetTrackCopy());
261 SetVertexCopy(v.GetVertexCopy());
262 SetJetCopy(v.GetJetCopy());
263 SetId(v.GetId());
6516b62d 264
265 // Copy all tracks except the ones coming from jets
266 AliTrack* tx=0;
267 Int_t jetflag=0,connect=0;
268 AliTrack* tx2=0;
325b076c 269 for (Int_t it=1; it<=v.fNtrk; it++)
6516b62d 270 {
271 tx=v.GetTrack(it);
272 if (tx)
273 {
274 jetflag=v.IsJetTrack(tx);
275 connect=v.IsConnectTrack(tx);
276
277 if (!jetflag && !connect) AddTrack(tx);
278
279 if (connect)
280 {
281 if (!fConnects)
282 {
283 fConnects=new TObjArray(fNvmax);
284 if (!fTrackCopy) fConnects->SetOwner();
285 }
286 tx2=new AliTrack(*tx);
287 fConnects->Add(tx2);
288 AddTrack(tx2,0);
289 }
290 }
291 }
292
293 // Copy all the (secondary) vertices without re-creating connecting tracks
294 // The connecting tracks have already been copied above
295 AliVertex* vx=0;
296 for (Int_t iv=1; iv<=v.GetNvertices(); iv++)
297 {
298 vx=v.GetVertex(iv);
299 if (vx) AddVertex(vx,0);
300 }
301
302 // Copy all the jets including the jet tracks for these jets for which
303 // this was also the case in the original vertex
304 AliJet* jx=0;
305 for (Int_t ij=1; ij<=v.GetNjets(); ij++)
306 {
307 jx=v.GetJet(ij);
308 if (jx)
309 {
310 jetflag=0;
311 if (jx->GetNtracks())
312 {
313 tx=jx->GetTrack(1);
314 if (tx)
315 {
316 jetflag=v.IsJetTrack(tx);
317 }
318 }
319 AddJet(jx,jetflag);
320 }
321 }
d88f97cc 322}
323///////////////////////////////////////////////////////////////////////////
324void AliVertex::SetNvmax(Int_t n)
325{
326// Set the initial maximum number of (secondary) vertices
327 if (n > 0)
328 {
329 fNvmax=n;
330 }
331 else
332 {
333 fNvmax=1;
334 }
f34f4acb 335 if (fVertices)
336 {
f34f4acb 337 delete fVertices;
338 fVertices=0;
339 }
340}
341///////////////////////////////////////////////////////////////////////////
342void AliVertex::SetNjmax(Int_t n)
343{
344// Set the initial maximum number of jets
345 if (n > 0)
346 {
347 fNjmax=n;
348 }
349 else
350 {
351 fNjmax=1;
352 }
353 if (fJets)
354 {
f34f4acb 355 delete fJets;
356 fJets=0;
357 }
d88f97cc 358}
359///////////////////////////////////////////////////////////////////////////
360void AliVertex::Reset()
361{
7849a8ab 362// Reset all variables to 0 and reset all stored vertex and jet lists.
d88f97cc 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
7849a8ab 365// The max. number of jets is set to the default value again
d88f97cc 366
367 AliJet::Reset();
368
f531a546 369 Double_t a[3]={0,0,0};
370 SetPosition(a,"sph");
371 SetPositionErrors(a,"car");
372
d88f97cc 373 fNvtx=0;
374 if (fNvmax>0) SetNvmax(fNvmax);
29beb80d 375 if (fConnects)
376 {
29beb80d 377 delete fConnects;
378 fConnects=0;
379 }
f34f4acb 380
381 fNjets=0;
382 if (fNjmax>0) SetNjmax(fNjmax);
6516b62d 383 if (fJetTracks)
384 {
385 delete fJetTracks;
386 fJetTracks=0;
387 }
a37bb40e 388
389 if (fLines)
390 {
391 delete fLines;
392 fLines=0;
393 }
d88f97cc 394}
395///////////////////////////////////////////////////////////////////////////
7849a8ab 396void AliVertex::ResetVertices()
397{
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.
35044448 401// All physics quantities are updated according to the removal of the
402// connecting tracks.
7849a8ab 403 AliTrack* t;
404 if (fConnects)
405 {
406 for (Int_t i=0; i<=fConnects->GetLast(); i++)
407 {
408 t=(AliTrack*)fConnects->At(i);
409 AliTrack* test=(AliTrack*)fTracks->Remove(t);
35044448 410 if (test)
411 {
412 fNtrk--;
413 (Ali4Vector&)(*this)-=(Ali4Vector&)(*t);
414 fQ-=t->GetCharge();
6516b62d 415 if (fTrackCopy) delete t;
35044448 416 }
7849a8ab 417 }
418 fTracks->Compress();
419 }
420
7849a8ab 421 fNvtx=0;
422 if (fNvmax>0) SetNvmax(fNvmax);
423 if (fConnects)
424 {
7849a8ab 425 delete fConnects;
426 fConnects=0;
427 }
428}
429///////////////////////////////////////////////////////////////////////////
f34f4acb 430void AliVertex::AddJet(AliJet& j,Int_t tracks)
d88f97cc 431{
f34f4acb 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
435//
436// Note : By default the tracks of the jet are added to the current (primary)
437// vertex.
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.
5f25234b 443//
444// In case a private copy is made, this is performed via the Clone() memberfunction.
445// All AliJet and derived classes have the default TObject::Clone() memberfunction.
446// However, derived classes generally contain an internal data structure which may
447// include pointers to other objects. Therefore it is recommended to provide
448// for all derived classes a specific copy constructor and override the default Clone()
449// memberfunction using this copy constructor.
450// An example for this may be seen from AliJet.
451
6516b62d 452 if (!fJets)
453 {
454 fJets=new TObjArray(fNjmax);
455 if (fJetCopy) fJets->SetOwner();
456 }
f34f4acb 457 if (fNjets == fNjmax) // Check if maximum jet number is reached
d88f97cc 458 {
f34f4acb 459 fNjmax++;
460 fJets->Expand(fNjmax);
461 }
462
463 // Add the jet to the list
6516b62d 464 AliJet* jx=&j;
5f25234b 465 if (fJetCopy) jx=(AliJet*)j.Clone();
6516b62d 466
467 if (jx)
f34f4acb 468 {
6516b62d 469 fNjets++;
470 fJets->Add(jx);
f34f4acb 471 }
472
473 // Add the tracks of the jet to this vertex
474 if (tracks)
475 {
6516b62d 476 if (!fJetTracks)
477 {
478 fJetTracks=new TObjArray();
479 }
480 Int_t copy=1-(jx->GetTrackCopy());
f34f4acb 481 AliTrack* tj;
6516b62d 482 for (Int_t i=1; i<=jx->GetNtracks(); i++)
f34f4acb 483 {
6516b62d 484 tj=jx->GetTrack(i);
485 if (tj)
486 {
487 AddTrack(tj,copy);
488 fJetTracks->Add(tj);
489 }
f34f4acb 490 }
d88f97cc 491 }
492}
493///////////////////////////////////////////////////////////////////////////
f531a546 494void AliVertex::AddVertex(AliVertex& v,Int_t connect)
d88f97cc 495{
496// Add a (secondary) vertex to the current vertex.
497// In case the maximum number of (secondary) vertices has been reached,
498// the array space will be extended automatically
499//
29beb80d 500// Note : By default the 4-momentum and charge of the current (primary) vertex
501// are updated by automatically creating the track connecting
502// both vertices. The track parameters are taken from the
503// 4-momentum and charge of the secondary vertex.
504// The automatic creation of the connecting track and updating
505// of the (primary) vertex 4-momentum and charge can be suppressed
506// by specifying connect=0. In this case, however, the user
507// has to introduce the connecting track lateron by hand
508// explicitly in order to match the kinematics and charge.
d88f97cc 509//
5f25234b 510// In case a private copy is made, this is performed via the Clone() memberfunction.
511// All AliVertex and derived classes have the default TObject::Clone() memberfunction.
512// However, derived classes generally contain an internal data structure which may
513// include pointers to other objects. Therefore it is recommended to provide
514// for all derived classes a specific copy constructor and override the default Clone()
515// memberfunction using this copy constructor.
516// An example for this may be seen from AliVertex.
517
6516b62d 518 if (!fVertices)
519 {
520 fVertices=new TObjArray(fNvmax);
521 if (fVertexCopy) fVertices->SetOwner();
522 }
d88f97cc 523 if (fNvtx == fNvmax) // Check if maximum vertex number is reached
524 {
525 fNvmax++;
526 fVertices->Expand(fNvmax);
527 }
29beb80d 528
529 // Add the linked (secondary) vertex to the list
6516b62d 530 AliVertex* vx=&v;
5f25234b 531 if (fVertexCopy) vx=(AliVertex*)v.Clone();
6516b62d 532
533 if (vx)
f34f4acb 534 {
6516b62d 535 fNvtx++;
536 fVertices->Add(vx);
537 }
29beb80d 538
539 // Create connecting track and update 4-momentum and charge for current vertex
540 if (connect)
541 {
43bfa5be 542 AliTrack* t=new AliTrack();
6516b62d 543 t->SetBeginPoint(GetPosition());
544 t->SetEndPoint(v.GetPosition());
545 t->SetCharge(v.GetCharge());
546 t->Set4Momentum((Ali4Vector&)v);
29beb80d 547
6516b62d 548 AddTrack(t,0);
29beb80d 549
6516b62d 550 if (!fConnects)
551 {
552 fConnects=new TObjArray(fNvmax);
553 if (!fTrackCopy) fConnects->SetOwner();
554 }
29beb80d 555 fConnects->Add(t);
556 }
d88f97cc 557}
558///////////////////////////////////////////////////////////////////////////
1f241680 559void AliVertex::Data(TString f,TString u)
d88f97cc 560{
561// Provide vertex information within the coordinate frame f
1f241680 562//
563// The string argument "u" allows to choose between different angular units
564// in case e.g. a spherical frame is selected.
565// u = "rad" : angles provided in radians
566// "deg" : angles provided in degrees
567//
568// The defaults are f="car" and u="rad".
569
47dddbe4 570 const char* name=GetName();
571 const char* title=GetTitle();
572 cout << " *AliVertex::Data*";
573 if (strlen(name)) cout << " Name : " << GetName();
574 if (strlen(title)) cout << " Title : " << GetTitle();
575 cout << endl;
387a745b 576 cout << " Id : " << fUserId << " Invmass : " << GetInvmass()
d88f97cc 577 << " Charge : " << GetCharge() << " Momentum : " << GetMomentum()
f34f4acb 578 << " Ntracks : " << GetNtracks() << " Nvertices : " << fNvtx
579 << " Njets : " << fNjets << endl;
d88f97cc 580 cout << " ";
1f241680 581 Ali4Vector::Data(f,u);
d88f97cc 582 cout << " Position";
1f241680 583 AliPosition::Data(f,u);
d88f97cc 584}
585///////////////////////////////////////////////////////////////////////////
1f241680 586void AliVertex::List(TString f,TString u)
d88f97cc 587{
588// Provide primary track and sec. vertex information within the coordinate frame f
1f241680 589//
590// The string argument "u" allows to choose between different angular units
591// in case e.g. a spherical frame is selected.
592// u = "rad" : angles provided in radians
593// "deg" : angles provided in degrees
594//
595// The defaults are f="car" and u="rad".
d88f97cc 596
1f241680 597 Data(f,u); // Information of the current vertex
d88f97cc 598
599 // The tracks of this vertex
600 AliTrack* t;
601 for (Int_t it=1; it<=GetNtracks(); it++)
602 {
603 t=GetTrack(it);
604 if (t)
605 {
606 cout << " ---Track no. " << it << endl;
607 cout << " ";
1f241680 608 t->Data(f,u);
d88f97cc 609 }
610 else
611 {
612 cout << " *AliVertex::List* Error : No track present." << endl;
613 }
614 }
615
616 // The secondary vertices of this vertex
617 AliVertex* v;
618 for (Int_t iv=1; iv<=GetNvertices(); iv++)
619 {
620 v=GetVertex(iv);
621 if (v)
622 {
623 cout << " ---Level 1 sec. vertex no. " << iv << endl;
624 cout << " ";
1f241680 625 v->Data(f,u);
d88f97cc 626 }
627 else
628 {
629 cout << " *AliVertex::List* Error : No sec. vertex present." << endl;
630 }
631 }
632}
633///////////////////////////////////////////////////////////////////////////
1f241680 634void AliVertex::ListAll(TString f,TString u)
d88f97cc 635{
636// Provide complete (sec) vertex and (decay) track info within the coordinate frame f
1f241680 637//
638// The string argument "u" allows to choose between different angular units
639// in case e.g. a spherical frame is selected.
640// u = "rad" : angles provided in radians
641// "deg" : angles provided in degrees
642//
643// The defaults are f="car" and u="rad".
d88f97cc 644
1f241680 645 Data(f,u); // Information of the current vertex
d88f97cc 646
647 // The tracks of this vertex
648 AliTrack* t;
649 for (Int_t it=1; it<=GetNtracks(); it++)
650 {
651 t=GetTrack(it);
652 if (t)
653 {
654 cout << " ---Track no. " << it << endl;
655 cout << " ";
1f241680 656 t->ListAll(f,u);
d88f97cc 657 }
658 else
659 {
660 cout << " *AliVertex::ListAll* Error : No track present." << endl;
661 }
662 }
663
664 AliVertex* v=this;
1f241680 665 Dumps(v,1,f,u); // Information of all sec. vertices
d88f97cc 666}
667//////////////////////////////////////////////////////////////////////////
1f241680 668void AliVertex::Dumps(AliVertex* v,Int_t n,TString f,TString u)
d88f97cc 669{
670// Recursively provide the info of all secondary vertices of this vertex
671 AliVertex* vs;
672 for (Int_t iv=1; iv<=v->GetNvertices(); iv++)
673 {
674 vs=v->GetVertex(iv);
675 if (vs)
676 {
677 cout << " ---Level " << n << " sec. vertex no. " << iv << endl;
678 cout << " ";
1f241680 679 vs->Data(f,u);
d88f97cc 680
681 // The tracks of this vertex
682 AliTrack* t;
683 for (Int_t it=1; it<=vs->GetNtracks(); it++)
684 {
685 t=vs->GetTrack(it);
686 if (t)
687 {
688 cout << " ---Track no. " << it << endl;
689 cout << " ";
1f241680 690 t->ListAll(f,u);
d88f97cc 691 }
692 else
693 {
1c01b4f8 694 cout << " *AliVertex::Dumps* Error : No track present." << endl;
d88f97cc 695 }
696 }
697
698 // Go for next sec. vertex level of this sec. vertex recursively
1f241680 699 Dumps(vs,n+1,f,u);
d88f97cc 700 }
701 else
702 {
1c01b4f8 703 cout << " *AliVertex::Dumps* Error : No sec. vertex present." << endl;
d88f97cc 704 }
705 }
706}
707//////////////////////////////////////////////////////////////////////////
261c0caf 708Int_t AliVertex::GetNvertices() const
d88f97cc 709{
710// Return the current number of (secondary) vertices
711 return fNvtx;
712}
713///////////////////////////////////////////////////////////////////////////
261c0caf 714AliVertex* AliVertex::GetVertex(Int_t i) const
d88f97cc 715{
716// Return the i-th (secondary) vertex of the current vertex
f34f4acb 717 if (!fVertices)
718 {
719 cout << " *AliVertex*::GetVertex* No (secondary) vertices present." << endl;
720 return 0;
721 }
722 else
723 {
724 if (i<=0 || i>fNvtx)
725 {
726 cout << " *AliVertex*::GetVertex* Invalid argument i : " << i
727 << " Nvtx = " << fNvtx << endl;
728 return 0;
729 }
730 else
731 {
732 return (AliVertex*)fVertices->At(i-1);
733 }
734 }
735}
736///////////////////////////////////////////////////////////////////////////
261c0caf 737AliVertex* AliVertex::GetIdVertex(Int_t id) const
43bfa5be 738{
739// Return the (sec.) vertex with user identifier "id"
740 AliVertex* vx=0;
741 AliVertex* v=0;
742 if (!fVertices)
743 {
744 cout << " *AliVertex*::GetIdVertex* No (secondary) vertices present." << endl;
745 return 0;
746 }
747 else
748 {
749 for (Int_t i=0; i<fNvtx; i++)
750 {
751 vx=(AliVertex*)fVertices->At(i);
752 if (id == vx->GetId()) v=vx;
753 }
754 return v;
755 }
756}
757///////////////////////////////////////////////////////////////////////////
f34f4acb 758void AliVertex::SetVertexCopy(Int_t j)
759{
760// (De)activate the creation of private copies of the added vertices.
761// j=0 ==> No private copies are made; pointers of original vertices are stored.
762// j=1 ==> Private copies of the vertices are made and these pointers are stored.
763//
764// Note : Once the storage contains pointer(s) to AliVertex objects one cannot
765// change the VertexCopy mode anymore.
766// To change the VertexCopy mode for an existing AliVertex containing
767// vertices one first has to invoke Reset().
768 if (!fVertices)
769 {
770 if (j==0 || j==1)
771 {
772 fVertexCopy=j;
773 }
774 else
775 {
776 cout << "*AliVertex::SetVertexCopy* Invalid argument : " << j << endl;
777 }
778 }
779 else
780 {
781 cout << "*AliVertex::SetVertexCopy* Storage already contained vertices."
782 << " ==> VertexCopy mode not changed." << endl;
783 }
784}
785///////////////////////////////////////////////////////////////////////////
261c0caf 786Int_t AliVertex::GetVertexCopy() const
f34f4acb 787{
788// Provide value of the VertexCopy mode.
789// 0 ==> No private copies are made; pointers of original vertices are stored.
790// 1 ==> Private copies of the vertices are made and these pointers are stored.
791 return fVertexCopy;
792}
793///////////////////////////////////////////////////////////////////////////
261c0caf 794Int_t AliVertex::GetNjets() const
f34f4acb 795{
796// Return the current number of jets
797 return fNjets;
798}
799///////////////////////////////////////////////////////////////////////////
261c0caf 800AliJet* AliVertex::GetJet(Int_t i) const
f34f4acb 801{
802// Return the i-th jet of the current vertex
803 if (!fJets)
804 {
805 cout << " *AliVertex*::GetJet* No jets present." << endl;
806 return 0;
807 }
808 else
809 {
810 if (i<=0 || i>fNjets)
811 {
812 cout << " *AliVertex*::GetJet* Invalid argument i : " << i
813 << " Njets = " << fNjets << endl;
814 return 0;
815 }
816 else
817 {
818 return (AliJet*)fJets->At(i-1);
819 }
820 }
821}
822///////////////////////////////////////////////////////////////////////////
261c0caf 823AliJet* AliVertex::GetIdJet(Int_t id) const
43bfa5be 824{
825// Return the jet with user identifier "id"
826 AliJet* jx=0;
827 AliJet* j=0;
828 if (!fJets)
829 {
830 cout << " *AliVertex*::GetIdJet* No jets present." << endl;
831 return 0;
832 }
833 else
834 {
835 for (Int_t i=0; i<fNjets; i++)
836 {
837 jx=(AliJet*)fJets->At(i);
838 if (id == jx->GetId()) j=jx;
839 }
840 return j;
841 }
842}
843///////////////////////////////////////////////////////////////////////////
f34f4acb 844void AliVertex::SetJetCopy(Int_t j)
845{
846// (De)activate the creation of private copies of the added jets.
847// j=0 ==> No private copies are made; pointers of original jets are stored.
848// j=1 ==> Private copies of the jets are made and these pointers are stored.
849//
850// Note : Once the storage contains pointer(s) to AliJet objects one cannot
851// change the JetCopy mode anymore.
852// To change the JetCopy mode for an existing AliVertex containing
853// jets one first has to invoke Reset().
854 if (!fJets)
855 {
856 if (j==0 || j==1)
857 {
858 fJetCopy=j;
859 }
860 else
861 {
862 cout << "*AliVertex::SetJetCopy* Invalid argument : " << j << endl;
863 }
864 }
865 else
866 {
867 cout << "*AliVertex::SetJetCopy* Storage already contained jets."
868 << " ==> JetCopy mode not changed." << endl;
869 }
870}
871///////////////////////////////////////////////////////////////////////////
261c0caf 872Int_t AliVertex::GetJetCopy() const
f34f4acb 873{
874// Provide value of the JetCopy mode.
875// 0 ==> No private copies are made; pointers of original jets are stored.
876// 1 ==> Private copies of the jets are made and these pointers are stored.
877 return fJetCopy;
d88f97cc 878}
879///////////////////////////////////////////////////////////////////////////
261c0caf 880Int_t AliVertex::IsConnectTrack(AliTrack* t) const
6516b62d 881{
882// Indicate whether a track from the tracklist was created via the
883// connection of a (secondary) vertex or not.
884// In case the track was the result of (secondary) vertex addition the
885// return value is 1, otherwise the value 0 will be returned.
886 Int_t connect=0;
887 if (fConnects)
888 {
889 if (fConnects->FindObject(t)) connect=1;
890 }
891 return connect;
892}
893///////////////////////////////////////////////////////////////////////////
261c0caf 894Int_t AliVertex::IsJetTrack(AliTrack* t) const
6516b62d 895{
896// Indicate whether a track from the tracklist was created via the
897// addition of a jet or not.
898// In case the track was the result of jet addition the return value is 1,
899// otherwise the value 0 will be returned.
900 Int_t jetflag=0;
901 if (fJetTracks)
902 {
903 if (fJetTracks->FindObject(t)) jetflag=1;
904 }
905 return jetflag;
906}
907///////////////////////////////////////////////////////////////////////////
a37bb40e 908void AliVertex::Draw(Int_t secs,Int_t cons,Int_t jets)
909{
910// 3-Dimensional visualisation of an AliVertex with its attributes.
911// The displayed tracklength is proportional to the momentum of the track.
912//
913// Color conventions :
914// -------------------
915// positive track : red
916// neutral track : green
917// negative track : blue
918// jet-track : magenta (if explicit marking selected)
919//
1c01b4f8 920// secs = 1 --> Draw secondary vertices. (Default)
a37bb40e 921// 0 --> Don't draw secondary vertices.
922//
1c01b4f8 923// cons = 1 --> Draw (auto generated) connecting tracks. (Default)
a37bb40e 924// 0 --> Don't draw (auto generated) connecting tracks.
925//
926// jets = 1 --> Mark tracks belonging to jets.
1c01b4f8 927// 0 --> Don't mark jet-tracks. (Default)
a37bb40e 928//
929// Notes :
930// -------
931// Auto generated connecting tracks will be drawn as thin lines.
932// Tracks belonging to jets will be marked as somewhat thinner magenta lines.
933// This memberfunction is used recursively.
934//
935 Double_t vec[3]={0,0,0};
936 AliTrack* tx=0;
937 AliVertex* vx=0;
c72198f1 938 AliPosition* r=0;
a37bb40e 939 Ali3Vector p;
1c01b4f8 940 Float_t charge;
a37bb40e 941
c72198f1 942 AliPosition dummy;
943
a37bb40e 944 if (fLines) delete fLines;
945 fLines=new TObjArray();
946 fLines->SetOwner();
947
948 Int_t ntk=GetNtracks();
949 for (Int_t jtk=1; jtk<=ntk; jtk++)
950 {
951 tx=GetTrack(jtk);
952
953 if (!tx) continue;
954
1c01b4f8 955 charge=tx->GetCharge();
a37bb40e 956
957 TPolyLine3D* line=new TPolyLine3D();
958 fLines->Add(line);
959
960 if (IsConnectTrack(tx))
961 {
962 if (cons==1)
963 {
964 r=tx->GetBeginPoint();
c72198f1 965 if (!r) r=&dummy;
966 r->GetPosition(vec,"car");
a37bb40e 967 line->SetNextPoint(vec[0],vec[1],vec[2]);
968 r=tx->GetEndPoint();
c72198f1 969 if (!r) r=&dummy;
970 r->GetPosition(vec,"car");
a37bb40e 971 line->SetNextPoint(vec[0],vec[1],vec[2]);
972 line->SetLineWidth(1);
973 }
974 }
975 else
976 {
977 r=tx->GetClosestPoint();
c72198f1 978 if (!r) r=&dummy;
979 r->GetPosition(vec,"car");
a37bb40e 980 line->SetNextPoint(vec[0],vec[1],vec[2]);
981 p=tx->Get3Momentum();
c72198f1 982 p=p+(*r);
a37bb40e 983 p.GetVector(vec,"car");
984 line->SetNextPoint(vec[0],vec[1],vec[2]);
985 line->SetLineWidth(3);
986 }
987
1c01b4f8 988 line->SetLineColor(kGreen); // Neutral track
989 if (charge>0) line->SetLineColor(kRed); // Positive track
990 if (charge<0) line->SetLineColor(kBlue); // Negative track
a37bb40e 991
992 // Mark tracks belonging to jets
993 if (IsJetTrack(tx))
994 {
995 if (jets==1)
996 {
997 line->SetLineWidth(2);
998 line->SetLineColor(kMagenta);
999 }
1000 }
1001
1002 line->Draw();
1003 }
1004
1005 // Go for secondary vertices if selected
1006 if (secs==1)
1007 {
1008 Int_t nvtx=GetNvertices();
1009 for (Int_t jvtx=1; jvtx<=nvtx; jvtx++)
1010 {
1011 vx=GetVertex(jvtx);
1012 if (vx) vx->Draw(secs,cons,jets);
1013 }
1014 }
1015}
1016///////////////////////////////////////////////////////////////////////////
4962c850 1017TObjArray* AliVertex::SortJets(Int_t mode,TObjArray* jets)
1018{
1019// Order the references to an array of jets by looping over the input array "jets"
1020// and checking the value of a certain observable.
1021// The ordered array is returned as a TObjArray.
1022// In case jets=0 (default), the registered jets of the current vertex are used.
1023// Note that the original jet array is not modified.
1024// Via the "mode" argument the user can specify the observable to be checked upon
1025// and specify whether sorting should be performed in decreasing order (mode<0)
1026// or in increasing order (mode>0).
1027//
1028// The convention for the observable selection is the following :
1029// mode : 1 ==> Number of tracks in the jet
1030// 2 ==> Jet energy
1031// 3 ==> Jet momentum
1032// 4 ==> Invariant mass of the jet
1033// 5 ==> Transverse momentum of the jet
1034// 6 ==> Longitudinal momentum of the jet
1035// 7 ==> Transverse energy of the jet
1036// 8 ==> Longitudinal energy of the jet
1037// 9 ==> Transverse mass of the jet
1038// 10 ==> Jet rapidity
1039// 11 ==> Pseudo-rapidity of the jet
1040//
1041// The default is mode=-1.
1042//
1043// Note : This sorting routine uses a common area in memory, which is used
1044// by various other sorting facilities as well.
1045// This means that the resulting sorted TObjArray may be overwritten
1046// when another sorting is invoked.
1047// To retain the sorted list of pointers, the user is advised to copy
1048// the pointers contained in the returned TObjArray into a private
1049// TObjArray instance.
1050
1051 if (fSelected)
1052 {
1053 delete fSelected;
1054 fSelected=0;
1055 }
1056
1057 if (!jets) jets=fJets;
1058
1059 if (abs(mode)>11 || !jets) return fSelected;
1060
1061 Int_t njets=jets->GetEntries();
1062 if (!njets)
1063 {
1064 return fSelected;
1065 }
1066 else
1067 {
1068 fSelected=new TObjArray(njets);
1069 }
1070
1071 Double_t val1,val2; // Values of the observable to be tested upon
1072
1073 Int_t nord=0;
1074 for (Int_t i=0; i<njets; i++) // Loop over all jets of the array
1075 {
1076 AliJet* jx=(AliJet*)jets->At(i);
1077
1078 if (!jx) continue;
1079
1080 if (nord == 0) // store the first jet at the first ordered position
1081 {
1082 nord++;
1083 fSelected->AddAt(jx,nord-1);
1084 continue;
1085 }
1086
1087 for (Int_t j=0; j<=nord; j++) // put jet in the right ordered position
1088 {
1089 if (j == nord) // jet has smallest (mode<0) or largest (mode>0) observable value seen so far
1090 {
1091 nord++;
1092 fSelected->AddAt(jx,j); // add jet at the end
1093 break; // go for next jet
1094 }
1095
1096 switch (abs(mode))
1097 {
1098 case 1:
1099 val1=jx->GetNtracks();
1100 val2=((AliJet*)fSelected->At(j))->GetNtracks();
1101 break;
1102 case 2:
1103 val1=jx->GetEnergy();
1104 val2=((AliJet*)fSelected->At(j))->GetEnergy();
1105 break;
1106 case 3:
1107 val1=jx->GetMomentum();
1108 val2=((AliJet*)fSelected->At(j))->GetMomentum();
1109 break;
1110 case 4:
1111 val1=jx->GetInvmass();
1112 val2=((AliJet*)fSelected->At(j))->GetInvmass();
1113 break;
1114 case 5:
1115 val1=jx->GetPt();
1116 val2=((AliJet*)fSelected->At(j))->GetPt();
1117 break;
1118 case 6:
1119 val1=jx->GetPl();
1120 val2=((AliJet*)fSelected->At(j))->GetPl();
1121 break;
1122 case 7:
1123 val1=jx->GetEt();
1124 val2=((AliJet*)fSelected->At(j))->GetEt();
1125 break;
1126 case 8:
1127 val1=jx->GetEl();
1128 val2=((AliJet*)fSelected->At(j))->GetEl();
1129 break;
1130 case 9:
1131 val1=jx->GetMt();
1132 val2=((AliJet*)fSelected->At(j))->GetMt();
1133 break;
1134 case 10:
1135 val1=jx->GetRapidity();
1136 val2=((AliJet*)fSelected->At(j))->GetRapidity();
1137 break;
1138 case 11:
1139 val1=jx->GetPseudoRapidity();
1140 val2=((AliJet*)fSelected->At(j))->GetPseudoRapidity();
1141 break;
1142 }
1143
1144 if (mode<0 && val1 < val2) continue;
1145 if (mode>0 && val1 > val2) continue;
1146
1147 nord++;
1148 for (Int_t k=nord-1; k>j; k--) // create empty position
1149 {
1150 fSelected->AddAt(fSelected->At(k-1),k);
1151 }
1152 fSelected->AddAt(jx,j); // put jet at empty position
1153 break; // go for next jet
1154 }
1155 }
1156 return fSelected;
1157}
1158///////////////////////////////////////////////////////////////////////////
261c0caf 1159TObject* AliVertex::Clone(const char* name) const
5f25234b 1160{
1161// Make a deep copy of the current object and provide the pointer to the copy.
1162// This memberfunction enables automatic creation of new objects of the
1163// correct type depending on the object type, a feature which may be very useful
1164// for containers when adding objects in case the container owns the objects.
1165// This feature allows e.g. AliEvent to store either AliVertex objects or
1166// objects derived from AliVertex via the AddVertex memberfunction, provided
1167// these derived classes also have a proper Clone memberfunction.
1168
1169 AliVertex* vtx=new AliVertex(*this);
1170 if (name)
1171 {
1172 if (strlen(name)) vtx->SetName(name);
1173 }
1174 return vtx;
1175}
1176///////////////////////////////////////////////////////////////////////////