]> git.uio.no Git - u/mrichter/AliRoot.git/blame - RALICE/AliJet.cxx
New class. Set and Get trigger board strip positions from mapping
[u/mrichter/AliRoot.git] / RALICE / AliJet.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 AliJet
20// Creation and investigation of a jet of particle tracks.
21// An AliJet can be constructed by adding AliTracks.
22//
c1f25d1d 23// To provide maximal flexibility to the user, two modes of track storage
24// are provided by means of the memberfunction SetTrackCopy().
25//
26// a) SetTrackCopy(0) (which is the default).
27// Only the pointers of the 'added' tracks are stored.
28// This mode is typically used by making jet studies based on a fixed list
29// of tracks which stays under user control or is contained for instance
30// in an AliEvent.
31// In this way the AliJet just represents a 'logical structure' for the
32// physics analysis which can be embedded in e.g. an AliEvent or AliVertex.
35044448 33//
34// Note :
c1f25d1d 35// Modifications made to the original tracks also affect the AliTrack objects
36// which are stored in the AliJet.
35044448 37//
c1f25d1d 38// b) SetTrackCopy(1).
39// Of every 'added' track a private copy will be made of which the pointer
40// will be stored.
41// In this way the AliJet represents an entity on its own and modifications
42// made to the original tracks do not affect the AliTrack objects which are
43// stored in the AliJet.
44// This mode will allow 'adding' many different AliTracks into an AliJet by
45// creating only one AliTrack instance in the main programme and using the
46// AliTrack::Reset() and AliTrack parameter setting memberfunctions.
47//
8e8e6c7f 48// See also the documentation provided for the memberfunction SetOwner().
49//
959fbac5 50// Coding example to make 2 jets j1 and j2.
51// ----------------------------------------
c1f25d1d 52// j1 contains the AliTracks t1 and t2
53// j2 contains 10 different AliTracks via tx
959fbac5 54//
c1f25d1d 55// AliTrack t1,t2;
959fbac5 56// ...
57// ... // code to fill the AliTrack data
58// ...
c1f25d1d 59// AliJet j1();
f531a546 60// j1.AddTrack(t1);
61// j1.AddTrack(t2);
c1f25d1d 62//
63// AliJet j2();
64// j2.SetTrackCopy(1);
65// AliTrack* tx=new AliTrack();
66// for (Int_t i=0; i<10; i++)
67// {
68// ...
69// ... // code to set momentum etc... of the track tx
70// ...
71// j2.AddTrack(tx);
72// tx->Reset();
73// }
959fbac5 74//
84bb7c66 75// j1.Data();
76// j2.Data("sph");
959fbac5 77//
78// Float_t e1=j1.GetEnergy();
79// Float_t pnorm=j1->GetMomentum();
80// Ali3Vector p=j1->Get3Momentum();
81// Float_t m=j1.GetInvmass();
82// Int_t ntk=j1.GetNtracks();
83// AliTrack* tj=j1.GetTrack(1);
84//
c1f25d1d 85// delete tx;
86//
959fbac5 87// Note : All quantities are in GeV, GeV/c or GeV/c**2
88//
89//--- Author: Nick van Eijndhoven 10-jul-1997 UU-SAP Utrecht
f531a546 90//- Modified: NvE $Date$ UU-SAP Utrecht
959fbac5 91///////////////////////////////////////////////////////////////////////////
92
d88f97cc 93#include "AliJet.h"
c72198f1 94#include "Riostream.h"
d88f97cc 95
96ClassImp(AliJet) // Class implementation to enable ROOT I/O
97
387a745b 98AliJet::AliJet() : TNamed(),Ali4Vector()
d88f97cc 99{
100// Default constructor
101// All variables initialised to 0
102// Initial maximum number of tracks is set to the default value
6516b62d 103 Init();
104 Reset();
105 SetNtinit();
106}
107///////////////////////////////////////////////////////////////////////////
108void AliJet::Init()
109{
110// Initialisation of pointers etc...
d88f97cc 111 fTracks=0;
112 fNtinit=0;
c1f25d1d 113 fTrackCopy=0;
413d0114 114 fRef=0;
ea0b5b7f 115 fSelected=0;
d88f97cc 116}
117///////////////////////////////////////////////////////////////////////////
387a745b 118AliJet::AliJet(Int_t n) : TNamed(),Ali4Vector()
d88f97cc 119{
120// Create a jet to hold initially a maximum of n tracks
121// All variables initialised to 0
6516b62d 122 Init();
d88f97cc 123 Reset();
124 if (n > 0)
125 {
126 SetNtinit(n);
127 }
128 else
129 {
130 cout << endl;
131 cout << " *AliJet* Initial max. number of tracks entered : " << n << endl;
132 cout << " This is invalid. Default initial maximum will be used." << endl;
133 cout << endl;
134 SetNtinit();
135 }
136}
137///////////////////////////////////////////////////////////////////////////
138AliJet::~AliJet()
139{
140// Default destructor
c1f25d1d 141 if (fTracks)
142 {
c1f25d1d 143 delete fTracks;
144 fTracks=0;
145 }
413d0114 146 if (fRef)
147 {
148 delete fRef;
149 fRef=0;
150 }
ea0b5b7f 151 if (fSelected)
152 {
153 delete fSelected;
154 fSelected=0;
155 }
d88f97cc 156}
157///////////////////////////////////////////////////////////////////////////
8e8e6c7f 158void AliJet::SetOwner(Bool_t own)
159{
160// Set ownership of all added objects.
161// The default parameter is own=kTRUE.
162//
163// Invokation of this memberfunction also sets all the copy modes
164// (e.g. TrackCopy & co.) according to the value of own.
165//
166// This function (with own=kTRUE) is particularly useful when reading data
167// from a tree/file, since Reset() will then actually remove all the
168// added objects from memory irrespective of the copy mode settings
169// during the tree/file creation process. In this way it provides a nice way
170// of preventing possible memory leaks in the reading/analysis process.
171//
172// In addition this memberfunction can also be used as a shortcut to set all
173// copy modes in one go during a tree/file creation process.
174// However, in this case the user has to take care to only set/change the
175// ownership (and copy mode) for empty objects (e.g. newly created objects
176// or after invokation of the Reset() memberfunction) otherwise it will
177// very likely result in inconsistent destructor behaviour.
178
179 Int_t mode=1;
180 if (!own) mode=0;
181 if (fTracks) fTracks->SetOwner(own);
182 fTrackCopy=mode;
183}
184///////////////////////////////////////////////////////////////////////////
261c0caf 185AliJet::AliJet(const AliJet& j) : TNamed(j),Ali4Vector(j)
6516b62d 186{
187// Copy constructor
c72198f1 188 fNtinit=j.fNtinit;
189 fNtmax=j.fNtmax;
190 fQ=j.fQ;
191 fNtrk=j.fNtrk;
192 fTrackCopy=j.fTrackCopy;
193 fUserId=j.fUserId;
413d0114 194 if (j.fRef) fRef=new AliPositionObj(*(j.fRef));
c72198f1 195
ea0b5b7f 196 fSelected=0;
197
c72198f1 198 fTracks=0;
199 if (fNtrk)
200 {
201 fTracks=new TObjArray(fNtmax);
202 if (fTrackCopy) fTracks->SetOwner();
203 }
6516b62d 204
c72198f1 205 for (Int_t i=1; i<=fNtrk; i++)
6516b62d 206 {
c72198f1 207 AliTrack* tx=j.GetTrack(i);
208 if (fTrackCopy)
209 {
5f25234b 210 fTracks->Add(tx->Clone());
c72198f1 211 }
212 else
213 {
214 fTracks->Add(tx);
215 }
6516b62d 216 }
217}
218///////////////////////////////////////////////////////////////////////////
d88f97cc 219void AliJet::SetNtinit(Int_t n)
220{
221// Set the initial maximum number of tracks for this jet
222 fNtinit=n;
223 fNtmax=n;
f4d1f676 224
79830a7e 225 if (fTracks)
c1f25d1d 226 {
c1f25d1d 227 delete fTracks;
228 fTracks=0;
229 }
413d0114 230 if (fRef)
231 {
232 delete fRef;
233 fRef=0;
234 }
d88f97cc 235}
236///////////////////////////////////////////////////////////////////////////
237void AliJet::Reset()
238{
239// Reset all variables to 0
240// The max. number of tracks is set to the initial value again
241 fNtrk=0;
242 fQ=0;
43bfa5be 243 fUserId=0;
d88f97cc 244 Double_t a[4]={0,0,0,0};
245 SetVector(a,"sph");
246 if (fNtinit > 0) SetNtinit(fNtinit);
247}
248///////////////////////////////////////////////////////////////////////////
1fbffa23 249void AliJet::AddTrack(AliTrack& t)
d88f97cc 250{
35044448 251// Add a track to the jet.
d88f97cc 252// In case the maximum number of tracks has been reached
253// space will be extended to hold an additional amount of tracks as
35044448 254// was initially reserved.
1fbffa23 255// See SetTrackCopy() to tailor the functionality of the stored structures.
5f25234b 256//
1f241680 257// Notes :
258// -------
5f25234b 259// In case a private copy is made, this is performed via the Clone() memberfunction.
260// All AliTrack and derived classes have the default TObject::Clone() memberfunction.
261// However, derived classes generally contain an internal data structure which may
262// include pointers to other objects. Therefore it is recommended to provide
263// for all derived classes a specific copy constructor and override the default Clone()
264// memberfunction using this copy constructor.
265// An example for this may be seen from AliTrack.
1f241680 266//
267// In case NO private copy is made, a check will be performed if this
268// specific track is already present in the jet.
269// If this is the case, no action is performed to prevent multiple
270// additions of the same track.
271
5f25234b 272
1fbffa23 273 AddTrack(t,1);
274}
275///////////////////////////////////////////////////////////////////////////
276void AliJet::AddTrack(AliTrack& t,Int_t copy)
277{
278// Internal memberfunction to actually add a track to the jet.
279// In case the maximum number of tracks has been reached
280// space will be extended to hold an additional amount of tracks as
281// was initially reserved.
282//
283// If copy=0 NO copy of the track will be made, irrespective of the setting
284// of the TrackCopy flag.
285// This allows a proper treatment of automatically generated connecting
286// tracks between vertices.
5f25234b 287//
1f241680 288// In case NO copy of the track is made, a check will be performed if this
289// specific track is already present in the jet.
290// If this is the case, no action is performed to prevent multiple
291// additions of the same track.
292//
5f25234b 293// Note :
294// In case a private copy is made, this is performed via the Clone() memberfunction.
295
6516b62d 296 if (!fTracks)
297 {
298 fTracks=new TObjArray(fNtmax);
299 if (fTrackCopy) fTracks->SetOwner();
300 }
1f241680 301 else if (!fTrackCopy || !copy) // Check if this track is already present
302 {
303 for (Int_t i=0; i<fNtrk; i++)
304 {
305 AliTrack* tx=(AliTrack*)fTracks->At(i);
306 if (tx == &t) return;
307 }
308 }
309
d88f97cc 310 if (fNtrk == fNtmax) // Check if maximum track number is reached
311 {
312 fNtmax+=fNtinit;
313 fTracks->Expand(fNtmax);
314 }
315
316 // Add the track to this jet
317 fNtrk++;
6516b62d 318 if (fTrackCopy && copy)
c1f25d1d 319 {
5f25234b 320 fTracks->Add(t.Clone());
c1f25d1d 321 }
322 else
323 {
324 fTracks->Add(&t);
325 }
35044448 326
d88f97cc 327 (*this)+=(Ali4Vector&)t;
328 fQ+=t.GetCharge();
35044448 329
d88f97cc 330}
331///////////////////////////////////////////////////////////////////////////
1f241680 332void AliJet::Data(TString f,TString u)
d88f97cc 333{
334// Provide jet information within the coordinate frame f
1f241680 335//
336// The string argument "u" allows to choose between different angular units
337// in case e.g. a spherical frame is selected.
338// u = "rad" : angles provided in radians
339// "deg" : angles provided in degrees
340//
341// The defaults are f="car" and u="rad".
342
5f25234b 343 const char* name=GetName();
344 const char* title=GetTitle();
345
346 cout << " *AliJet::Data*";
347 if (strlen(name)) cout << " Name : " << GetName();
348 if (strlen(title)) cout << " Title : " << GetTitle();
349 cout << endl;
387a745b 350 cout << " Id : " << fUserId << " Invmass : " << GetInvmass() << " Charge : " << fQ
ea0b5b7f 351 << " Momentum : " << GetMomentum() << endl;
352
353 ShowTracks(0);
c72198f1 354
1f241680 355 Ali4Vector::Data(f,u);
d88f97cc 356}
357///////////////////////////////////////////////////////////////////////////
1f241680 358void AliJet::List(TString f,TString u)
d88f97cc 359{
360// Provide jet and primary track information within the coordinate frame f
1f241680 361//
362// The string argument "u" allows to choose between different angular units
363// in case e.g. a spherical frame is selected.
364// u = "rad" : angles provided in radians
365// "deg" : angles provided in degrees
366//
367// The defaults are f="car" and u="rad".
d88f97cc 368
1f241680 369 Data(f,u); // Information of the current jet
413d0114 370 if (fRef) { cout << " Ref-point :"; fRef->Data(f,u); }
d88f97cc 371
372 // The tracks of this jet
373 AliTrack* t;
374 for (Int_t it=1; it<=fNtrk; it++)
375 {
376 t=GetTrack(it);
377 if (t)
378 {
379 cout << " ---Track no. " << it << endl;
380 cout << " ";
1f241680 381 t->Data(f,u);
d88f97cc 382 }
383 else
384 {
385 cout << " *AliJet::List* Error : No track present." << endl;
386 }
387 }
388}
389///////////////////////////////////////////////////////////////////////////
1f241680 390void AliJet::ListAll(TString f,TString u)
d88f97cc 391{
392// Provide jet and prim.+sec. track information within the coordinate frame f
1f241680 393//
394// The string argument "u" allows to choose between different angular units
395// in case e.g. a spherical frame is selected.
396// u = "rad" : angles provided in radians
397// "deg" : angles provided in degrees
398//
399// The defaults are f="car" and u="rad".
d88f97cc 400
1f241680 401 Data(f,u); // Information of the current jet
413d0114 402 if (fRef) { cout << " Ref-point :"; fRef->Data(f,u); }
d88f97cc 403
404 // The tracks of this jet
405 AliTrack* t;
406 for (Int_t it=1; it<=fNtrk; it++)
407 {
408 t=GetTrack(it);
409 if (t)
410 {
411 cout << " ---Track no. " << it << endl;
412 cout << " ";
1f241680 413 t->ListAll(f,u);
d88f97cc 414 }
415 else
416 {
417 cout << " *AliJet::List* Error : No track present." << endl;
418 }
419 }
420}
421///////////////////////////////////////////////////////////////////////////
325b076c 422Int_t AliJet::GetNtracks(Int_t idmode,Int_t chmode,Int_t pcode)
d88f97cc 423{
325b076c 424// Provide the number of user selected tracks in this jet based on the
425// idmode, chmode and pcode selections as specified by the user.
426// For specification of the selection parameters see GetTracks().
427// The default parameters correspond to no selection, which implies
428// that invokation of GetNtracks() just returns the total number of
429// tracks registered in this jet.
430//
431// Note : In case certain selections are specified, this function
432// invokes GetTracks(idmode,chmode,pcode) to determine the
433// number of tracks corresponding to the selections.
434// When the jet contains a large number of tracks, invokation
435// of GetTracks(idmode,chmode,pcode) and subsequently invoking
436// GetEntries() for the resulting TObjArray* might be slightly
437// faster.
438
439 Int_t n=0;
440 if (idmode==0 && chmode==2 && pcode==0)
441 {
442 return fNtrk;
443 }
444 else
445 {
446 TObjArray* arr=GetTracks(idmode,chmode,pcode);
447 n=arr->GetEntries();
448 return n;
449 }
d88f97cc 450}
451///////////////////////////////////////////////////////////////////////////
452Double_t AliJet::GetEnergy()
453{
454// Return the total energy of the jet
455 return GetScalar();
456}
457///////////////////////////////////////////////////////////////////////////
458Double_t AliJet::GetMomentum()
459{
460// Return the value of the total jet 3-momentum
d071d629 461// The error can be obtained by invoking GetResultError() after
462// invokation of GetMomentum().
463 Double_t norm=fV.GetNorm();
464 fDresult=fV.GetResultError();
465 return norm;
d88f97cc 466}
467///////////////////////////////////////////////////////////////////////////
261c0caf 468Ali3Vector AliJet::Get3Momentum() const
d88f97cc 469{
470// Return the the total jet 3-momentum
471 Ali3Vector p=Get3Vector();
472 return p;
473}
474///////////////////////////////////////////////////////////////////////////
475Double_t AliJet::GetInvmass()
476{
477// Return the invariant mass of the jet
478 Double_t m2=Dot(*this);
479 if (m2>0)
480 {
481 return sqrt(m2);
482 }
483 else
484 {
485 return 0;
486 }
487}
488///////////////////////////////////////////////////////////////////////////
261c0caf 489Float_t AliJet::GetCharge() const
d88f97cc 490{
491// Return the total charge of the jet
492 return fQ;
493}
494///////////////////////////////////////////////////////////////////////////
261c0caf 495AliTrack* AliJet::GetTrack(Int_t i) const
d88f97cc 496{
497// Return the i-th track of this jet
ea0b5b7f 498
499 if (!fTracks) return 0;
500
501 if (i<=0 || i>fNtrk)
f34f4acb 502 {
ea0b5b7f 503 cout << " *AliJet*::GetTrack* Invalid argument i : " << i
504 << " Ntrk = " << fNtrk << endl;
f34f4acb 505 return 0;
506 }
507 else
508 {
ea0b5b7f 509 return (AliTrack*)fTracks->At(i-1);
f34f4acb 510 }
d88f97cc 511}
512///////////////////////////////////////////////////////////////////////////
261c0caf 513AliTrack* AliJet::GetIdTrack(Int_t id) const
43bfa5be 514{
515// Return the track with user identifier "id" of this jet
4f368c8c 516 if (!fTracks) return 0;
517
43bfa5be 518 AliTrack* tx=0;
4f368c8c 519 for (Int_t i=0; i<fNtrk; i++)
43bfa5be 520 {
4f368c8c 521 tx=(AliTrack*)fTracks->At(i);
522 if (id == tx->GetId()) return tx;
43bfa5be 523 }
4f368c8c 524 return 0; // No matching id found
43bfa5be 525}
526///////////////////////////////////////////////////////////////////////////
ea0b5b7f 527TObjArray* AliJet::GetTracks(Int_t idmode,Int_t chmode,Int_t pcode)
528{
529// Provide references to user selected tracks based on the idmode, chmode
530// and pcode selections as specified by the user.
531//
532// The following selection combinations are available :
533// ----------------------------------------------------
534// idmode = -1 ==> Select tracks with negative user identifier "id"
535// 0 ==> No selection on user identifier
536// 1 ==> Select tracks with positive user identifier "id"
537//
538// chmode = -1 ==> Select tracks with negative charge
539// 0 ==> Select neutral tracks
540// 1 ==> Select tracks with positive charge
541// 2 ==> No selection on charge
325b076c 542// 3 ==> Select all charged tracks
ea0b5b7f 543//
544// pcode = 0 ==> No selection on particle code
545// X ==> Select tracks with particle code +X or -X
546// This allows selection of both particles and anti-particles
547// in case of PDG particle codes.
548// Selection of either particles or anti-particles can be
549// obtained in combination with the "chmode" selector.
550//
551// Examples :
552// ----------
553// idmode=-1 chmode=0 pcode=0 : Selection of all neutral tracks with negative id.
554// idmode=0 chmode=2 pcode=211 : Selection of all charged pions (PDG convention).
555// idmode=0 chmode=1 pcode=321 : Selection of all positive kaons (PDG convention).
556//
557// The default values are idmode=0 chmode=2 pcode=0 (i.e. no selections applied).
558//
559// Notes :
560// -------
561// 1) In case the user has labeled simulated tracks with negative id and
562// reconstructed tracks with positive id, this memberfunction provides
563// easy access to either all simulated or reconstructed tracks.
564// 2) Subsequent invokations of this memberfunction with e.g. chmode=-1 and chmode=1
565// provides a convenient way to investigate particle pairs with opposite charge
566// (e.g. for invariant mass analysis).
50e93041 567// 3) The selected track pointers are returned via a multi-purpose array,
568// which will be overwritten by subsequent selections.
569// In case the selected track list is to be used amongst other selections,
570// the user is advised to store the selected track pointers in a local
571// TObjArray or TRefArray.
ea0b5b7f 572
573 if (fSelected)
574 {
575 fSelected->Clear();
576 }
577 else
578 {
579 fSelected=new TObjArray();
580 }
581
582 if (!fTracks) return fSelected;
583
584 AliTrack* tx=0;
585 Int_t code=0;
586 Int_t id=0;
587 Float_t q=0;
588 for (Int_t i=0; i<fNtrk; i++)
589 {
590 tx=(AliTrack*)fTracks->At(i);
591 if (!tx) continue;
592
593 code=tx->GetParticleCode();
594 if (pcode && abs(pcode)!=abs(code)) continue;
595
596 id=tx->GetId();
597 if (idmode==-1 && id>=0) continue;
598 if (idmode==1 && id<=0) continue;
599
600 q=tx->GetCharge();
601 if (chmode==-1 && q>=0) continue;
602 if (chmode==0 && fabs(q)>1e-10) continue;
603 if (chmode==1 && q<=0) continue;
325b076c 604 if (chmode==3 && fabs(q)<1e-10) continue;
ea0b5b7f 605
606 fSelected->Add(tx);
607 }
608
609 return fSelected;
610}
611///////////////////////////////////////////////////////////////////////////
50e93041 612TObjArray* AliJet::GetTracks(TString name)
613{
614// Provide references to all tracks with the specified name.
615//
616// Notes :
617// -------
618// 1) In case the user has labeled reconstructed tracks with the name of
619// the applied reconstruction algorithm, this memberfunction provides
620// easy access to all tracks reconstructed by a certain method.
621// 2) The selected track pointers are returned via a multi-purpose array,
622// which will be overwritten by subsequent selections.
623// In case the selected track list is to be used amongst other selections,
624// the user is advised to store the selected track pointers in a local
625// TObjArray or TRefArray.
626
627 if (fSelected)
628 {
629 fSelected->Clear();
630 }
631 else
632 {
633 fSelected=new TObjArray();
634 }
635
636 if (!fTracks) return fSelected;
637
638 AliTrack* tx=0;
639 TString s;
640 for (Int_t i=0; i<fNtrk; i++)
641 {
642 tx=(AliTrack*)fTracks->At(i);
643 if (!tx) continue;
644
645 s=tx->GetName();
646 if (s == name) fSelected->Add(tx);
647 }
648
649 return fSelected;
650}
651///////////////////////////////////////////////////////////////////////////
30672a96 652void AliJet::RemoveTracks(TString name)
653{
654// Remove all tracks with the specified name.
655// If name="*" all tracks will be removed.
656//
657// Note :
658// ------
659// In case the user has labeled reconstructed tracks with the name of
660// the applied reconstruction algorithm, this memberfunction provides
661// easy removal of all tracks reconstructed by a certain method.
662
663 if (!fTracks) return;
664
665 AliTrack* tx=0;
666 TString s;
667 TObject* obj=0;
668 for (Int_t i=0; i<fNtrk; i++)
669 {
670 tx=(AliTrack*)fTracks->At(i);
671 if (!tx) continue;
672
673 s=tx->GetName();
674 if (s==name || name=="*")
675 {
676 obj=fTracks->Remove(tx);
677 if (obj && fTracks->IsOwner()) delete tx;
678 }
679 }
680 fTracks->Compress();
681 fNtrk=fTracks->GetEntries();
682}
683///////////////////////////////////////////////////////////////////////////
684void AliJet::RemoveTracks(Int_t idmode,Int_t chmode,Int_t pcode)
685{
686// Remove user selected tracks based on the idmode, chmode and pcode
687// selections as specified by the user.
688// For defintions of these selections see the corresponding GetTracks()
689// memberfunction.
690
691 if (!fTracks) return;
692
693 TObjArray* arr=GetTracks(idmode,chmode,pcode);
694 if (!arr) return;
695
696 Int_t ntk=arr->GetEntries();
697 if (!ntk) return;
698
699 AliTrack* tx=0;
700 TObject* obj=0;
701 for (Int_t i=0; i<ntk; i++)
702 {
703 tx=(AliTrack*)arr->At(i);
704 if (!tx) continue;
705
706 obj=fTracks->Remove(tx);
707 if (obj && fTracks->IsOwner()) delete tx;
708 }
709 fTracks->Compress();
710 fNtrk=fTracks->GetEntries();
711 arr->Clear();
712}
713///////////////////////////////////////////////////////////////////////////
325b076c 714void AliJet::ShowTracks(Int_t mode)
ea0b5b7f 715{
716// Provide an overview of the available tracks.
717// The argument mode determines the amount of information as follows :
718// mode = 0 ==> Only printout of the number of tracks
719// 1 ==> Provide a listing with 1 line of info for each track
720//
721// The default is mode=1.
722//
723 Int_t ntk=GetNtracks();
724 if (ntk)
725 {
726 if (!mode)
727 {
728 cout << " There are " << ntk << " tracks available." << endl;
729 }
730 else
731 {
732 cout << " The following " << ntk << " tracks are available :" << endl;
733 for (Int_t i=1; i<=ntk; i++)
734 {
735 AliTrack* tx=GetTrack(i);
736 if (tx)
737 {
738 const char* name=tx->GetName();
739 const char* title=tx->GetTitle();
740 cout << " Track : " << i;
741 cout << " Id : " << tx->GetId();
742 cout << " Q : " << tx->GetCharge() << " m : " << tx->GetMass() << " p : " << tx->GetMomentum();
743 if (strlen(name)) cout << " Name : " << name;
744 if (strlen(title)) cout << " Title : " << title;
745 cout << endl;
746 }
747 }
748 }
749 }
750 else
751 {
752 cout << " No tracks are present." << endl;
753 }
754}
755///////////////////////////////////////////////////////////////////////////
d071d629 756Double_t AliJet::GetPt()
757{
758// Provide trans. momentum value w.r.t. z-axis.
759// The error on the value can be obtained by GetResultError()
760// after invokation of GetPt().
761 Ali3Vector v;
762 v=GetVecTrans();
763 Double_t norm=v.GetNorm();
764 fDresult=v.GetResultError();
765
766 return norm;
767}
768///////////////////////////////////////////////////////////////////////////
769Double_t AliJet::GetPl()
770{
771// Provide long. momentum value w.r.t. z-axis.
8adaf597 772// Note : the returned value can also be negative.
d071d629 773// The error on the value can be obtained by GetResultError()
774// after invokation of GetPl().
775 Ali3Vector v;
776 v=GetVecLong();
8adaf597 777
778 Double_t pl=v.GetNorm();
d071d629 779 fDresult=v.GetResultError();
780
8adaf597 781 Double_t a[3];
782 v.GetVector(a,"sph");
783 if (cos(a[1])<0) pl=-pl;
784
785 return pl;
d071d629 786}
787///////////////////////////////////////////////////////////////////////////
788Double_t AliJet::GetEt()
789{
790// Provide trans. energy value w.r.t. z-axis.
791// The error on the value can be obtained by GetResultError()
792// after invokation of GetEt().
793 Double_t et=GetScaTrans();
794
795 return et;
796}
797///////////////////////////////////////////////////////////////////////////
798Double_t AliJet::GetEl()
799{
800// Provide long. energy value w.r.t. z-axis.
8adaf597 801// Note : the returned value can also be negative.
d071d629 802// The error on the value can be obtained by GetResultError()
803// after invokation of GetEl().
804 Double_t el=GetScaLong();
805
806 return el;
807}
808///////////////////////////////////////////////////////////////////////////
809Double_t AliJet::GetMt()
810{
811// Provide transverse mass value w.r.t. z-axis.
812// The error on the value can be obtained by GetResultError()
813// after invokation of GetMt().
814 Double_t pt=GetPt();
815 Double_t dpt=GetResultError();
816 Double_t m=GetInvmass();
817 Double_t dm=GetResultError();
818
819 Double_t mt=sqrt(pt*pt+m*m);
820 Double_t dmt2=0;
821 if (mt) dmt2=(pow((pt*dpt),2)+pow((m*dm),2))/(mt*mt);
822
823 fDresult=sqrt(dmt2);
824 return mt;
825}
826///////////////////////////////////////////////////////////////////////////
8adaf597 827Double_t AliJet::GetRapidity()
828{
829// Provide rapidity value w.r.t. z-axis.
830// The error on the value can be obtained by GetResultError()
831// after invokation of GetRapidity().
832// Note : Also GetPseudoRapidity() is available since this class is
833// derived from Ali4Vector.
834 Double_t e=GetEnergy();
835 Double_t de=GetResultError();
836 Double_t pl=GetPl();
837 Double_t dpl=GetResultError();
838 Double_t sum=e+pl;
839 Double_t dif=e-pl;
840
841 Double_t y=9999,dy2=0;
842 if (sum && dif) y=0.5*log(sum/dif);
843
844 if (sum*dif) dy2=(1./(sum*dif))*(pow((pl*de),2)+pow((e*dpl),2));
845
846 fDresult=sqrt(dy2);
847 return y;
848}
849///////////////////////////////////////////////////////////////////////////
c1f25d1d 850void AliJet::SetTrackCopy(Int_t j)
851{
852// (De)activate the creation of private copies of the added tracks.
853// j=0 ==> No private copies are made; pointers of original tracks are stored.
854// j=1 ==> Private copies of the tracks are made and these pointers are stored.
855//
856// Note : Once the storage contains pointer(s) to AliTrack(s) one cannot
857// change the TrackCopy mode anymore.
858// To change the TrackCopy mode for an existing AliJet containing
859// tracks one first has to invoke Reset().
860 if (!fTracks)
861 {
862 if (j==0 || j==1)
863 {
864 fTrackCopy=j;
865 }
866 else
867 {
868 cout << "*AliJet::SetTrackCopy* Invalid argument : " << j << endl;
869 }
870 }
871 else
872 {
873 cout << "*AliJet::SetTrackCopy* Storage already contained tracks."
874 << " ==> TrackCopy mode not changed." << endl;
875 }
876}
877///////////////////////////////////////////////////////////////////////////
261c0caf 878Int_t AliJet::GetTrackCopy() const
c1f25d1d 879{
880// Provide value of the TrackCopy mode.
881// 0 ==> No private copies are made; pointers of original tracks are stored.
882// 1 ==> Private copies of the tracks are made and these pointers are stored.
883 return fTrackCopy;
884}
885///////////////////////////////////////////////////////////////////////////
43bfa5be 886void AliJet::SetId(Int_t id)
887{
888// Set a user defined identifier for this jet.
889 fUserId=id;
890}
891///////////////////////////////////////////////////////////////////////////
261c0caf 892Int_t AliJet::GetId() const
43bfa5be 893{
894// Provide the user defined identifier of this jet.
895 return fUserId;
896}
897///////////////////////////////////////////////////////////////////////////
413d0114 898void AliJet::SetReferencePoint(AliPosition& p)
899{
900// Store the position of the jet reference-point.
901// The reference-point of a jet provides a means to define a generic
902// space-time location for the jet as a whole.
903// This doesn't have to be necessarily the location where all the constituent
904// tracks originate (e.g. a bundle of parallel tracks doesn't have such
905// a location). As such the meaning of this reference-point is different from
906// a normal vertex position and allows to provide complimentary information.
907// This reference point is the preferable point to start e.g. extrapolations
908// and investigate coincidences in space and/or time.
909 if (fRef) delete fRef;
910 fRef=new AliPositionObj(p);
911}
912///////////////////////////////////////////////////////////////////////////
913AliPosition* AliJet::GetReferencePoint()
914{
915// Provide the position of the jet reference-point.
916// The reference-point of a jet provides a means to define a generic
917// space-time location for the jet as a whole.
918// This doesn't have to be necessarily the location where all the constituent
919// tracks originate (e.g. a bundle of parallel tracks doesn't have such
920// a location). As such the meaning of this reference-point is different from
921// a normal vertex position and allows to provide complimentary information.
922// This reference point is the preferable point to start e.g. extrapolations
923// and investigate coincidences in space and/or time.
924 return fRef;
925}
926///////////////////////////////////////////////////////////////////////////
e51b7d1a 927TObjArray* AliJet::SortTracks(Int_t mode,TObjArray* tracks)
928{
929// Order the references to an array of tracks by looping over the input array "tracks"
930// and checking the value of a certain observable.
931// The ordered array is returned as a TObjArray.
932// In case tracks=0 (default), the registered tracks of the current jet are used.
933// Note that the original track array is not modified.
934// Via the "mode" argument the user can specify the observable to be checked upon
935// and specify whether sorting should be performed in decreasing order (mode<0)
936// or in increasing order (mode>0).
937//
938// The convention for the observable selection is the following :
939// mode : 1 ==> Number of signals associated to the track
940// 2 ==> Track energy
941// 3 ==> Track momentum
942// 4 ==> Mass of the track
943// 5 ==> Transverse momentum of the track
944// 6 ==> Longitudinal momentum of the track
945// 7 ==> Transverse energy of the track
946// 8 ==> Longitudinal energy of the track
947// 9 ==> Transverse mass of the track
948// 10 ==> Track rapidity
949// 11 ==> Pseudo-rapidity of the track
950//
951// The default is mode=-1.
952//
953// Note : This sorting routine uses a common area in memory, which is used
954// by various other sorting facilities as well.
955// This means that the resulting sorted TObjArray may be overwritten
956// when another sorting is invoked.
957// To retain the sorted list of pointers, the user is advised to copy
958// the pointers contained in the returned TObjArray into a private
959// TObjArray instance.
960
961 if (fSelected)
962 {
963 delete fSelected;
964 fSelected=0;
965 }
966
967 if (!tracks) tracks=fTracks;
968
969 if (abs(mode)>11 || !tracks) return fSelected;
970
971 Int_t ntracks=tracks->GetEntries();
972 if (!ntracks)
973 {
974 return fSelected;
975 }
976 else
977 {
978 fSelected=new TObjArray(ntracks);
979 }
980
981 Double_t val1,val2; // Values of the observable to be tested upon
982
983 Int_t nord=0;
984 for (Int_t i=0; i<ntracks; i++) // Loop over all tracks of the array
985 {
986 AliTrack* tx=(AliTrack*)tracks->At(i);
987
988 if (!tx) continue;
989
990 if (nord == 0) // store the first track at the first ordered position
991 {
992 nord++;
993 fSelected->AddAt(tx,nord-1);
994 continue;
995 }
996
997 for (Int_t j=0; j<=nord; j++) // put track in the right ordered position
998 {
999 if (j == nord) // track has smallest (mode<0) or largest (mode>0) observable value seen so far
1000 {
1001 nord++;
1002 fSelected->AddAt(tx,j); // add track at the end
1003 break; // go for next track
1004 }
64b63904 1005
1006 val1=0;
1007 val2=0;
1008
e51b7d1a 1009 switch (abs(mode))
1010 {
1011 case 1:
1012 val1=tx->GetNsignals();
1013 val2=((AliTrack*)fSelected->At(j))->GetNsignals();
1014 break;
1015 case 2:
1016 val1=tx->GetEnergy();
1017 val2=((AliTrack*)fSelected->At(j))->GetEnergy();
1018 break;
1019 case 3:
1020 val1=tx->GetMomentum();
1021 val2=((AliTrack*)fSelected->At(j))->GetMomentum();
1022 break;
1023 case 4:
1024 val1=tx->GetMass();
1025 val2=((AliTrack*)fSelected->At(j))->GetMass();
1026 break;
1027 case 5:
1028 val1=tx->GetPt();
1029 val2=((AliTrack*)fSelected->At(j))->GetPt();
1030 break;
1031 case 6:
1032 val1=tx->GetPl();
1033 val2=((AliTrack*)fSelected->At(j))->GetPl();
1034 break;
1035 case 7:
1036 val1=tx->GetEt();
1037 val2=((AliTrack*)fSelected->At(j))->GetEt();
1038 break;
1039 case 8:
1040 val1=tx->GetEl();
1041 val2=((AliTrack*)fSelected->At(j))->GetEl();
1042 break;
1043 case 9:
1044 val1=tx->GetMt();
1045 val2=((AliTrack*)fSelected->At(j))->GetMt();
1046 break;
1047 case 10:
1048 val1=tx->GetRapidity();
1049 val2=((AliTrack*)fSelected->At(j))->GetRapidity();
1050 break;
1051 case 11:
1052 val1=tx->GetPseudoRapidity();
1053 val2=((AliTrack*)fSelected->At(j))->GetPseudoRapidity();
1054 break;
1055 }
1056
f5b75967 1057 if (mode<0 && val1 <= val2) continue;
1058 if (mode>0 && val1 >= val2) continue;
e51b7d1a 1059
1060 nord++;
1061 for (Int_t k=nord-1; k>j; k--) // create empty position
1062 {
1063 fSelected->AddAt(fSelected->At(k-1),k);
1064 }
1065 fSelected->AddAt(tx,j); // put track at empty position
1066 break; // go for next track
1067 }
1068 }
1069 return fSelected;
1070}
1071///////////////////////////////////////////////////////////////////////////
9427ac75 1072Double_t AliJet::GetDistance(AliPosition* p)
1073{
1074// Provide distance of the current jet to the position p.
1075// The error on the result can be obtained as usual by invoking
1076// GetResultError() afterwards.
1077//
1078// The distance will be provided in the unit scale of the AliPosition p.
1079// As such it is possible to obtain a correctly computed distance even in case
1080// the jet parameters have a different unit scale.
1081// However, it is recommended to work always with one single unit scale.
1082//
1083// Note : In case of incomplete information, a distance value of -1 is
1084// returned.
1085
1086 Double_t dist=-1.;
1087 fDresult=0.;
1088
1089 if (!p) return dist;
1090
1091 // Obtain a defined position on this jet
1092 AliPosition* rx=fRef;
1093
1094 if (!rx) return dist;
1095
1096 Ali3Vector pj=Get3Momentum();
1097
1098 if (pj.GetNorm() <= 0.) return dist;
1099
1100 AliTrack tj;
1101 tj.Set3Momentum(pj);
1102 tj.SetReferencePoint(*rx);
1103 dist=tj.GetDistance(p);
1104 fDresult=tj.GetResultError();
1105 return dist;
1106}
1107///////////////////////////////////////////////////////////////////////////
1108Double_t AliJet::GetDistance(AliTrack* t)
1109{
1110// Provide distance of the current jet to the track t.
1111// The error on the result can be obtained as usual by invoking
1112// GetResultError() afterwards.
1113//
1114// The distance will be provided in the unit scale of the current jet.
1115// As such it is possible to obtain a correctly computed distance even in case
1116// the jet and track parameters have a different unit scale.
1117// However, it is recommended to work always with one single unit scale.
1118//
1119// Note : In case of incomplete information, a distance value of -1 is
1120// returned.
1121
1122 Double_t dist=-1.;
1123 fDresult=0.;
1124
1125 if (!t) return dist;
1126
1127 // Obtain a defined position on this jet
1128 AliPosition* rx=fRef;
1129
1130 if (!rx) return dist;
1131
1132 Ali3Vector pj=Get3Momentum();
1133
1134 if (pj.GetNorm() <= 0.) return dist;
1135
1136 AliTrack tj;
1137 tj.Set3Momentum(pj);
1138 tj.SetReferencePoint(*rx);
1139 dist=tj.GetDistance(t);
1140 fDresult=tj.GetResultError();
1141 return dist;
1142}
1143///////////////////////////////////////////////////////////////////////////
1144Double_t AliJet::GetDistance(AliJet* j)
1145{
1146// Provide distance of the current jet to the jet j.
1147// The error on the result can be obtained as usual by invoking
1148// GetResultError() afterwards.
1149//
1150// The distance will be provided in the unit scale of the current jet.
1151// As such it is possible to obtain a correctly computed distance even in case
1152// the jet and track parameters have a different unit scale.
1153// This implies that in such cases the results of j1.GetDistance(j2) and
1154// j2.GetDistance(j1) will be numerically different.
1155// However, it is recommended to work always with one single unit scale.
1156//
1157// Note : In case of incomplete information, a distance value of -1 is
1158// returned.
1159
1160 Double_t dist=-1.;
1161 fDresult=0.;
1162
1163 if (!j) return dist;
1164
1165 // Obtain a defined position on jet j
1166 AliPosition* rx=j->GetReferencePoint();
1167
1168 if (!rx) return dist;
1169
1170 Ali3Vector pj=j->Get3Momentum();
1171
1172 if (pj.GetNorm() <= 0.) return dist;
1173
1174 AliTrack tj;
1175 tj.Set3Momentum(pj);
1176 tj.SetReferencePoint(*rx);
1177 dist=GetDistance(tj);
1178 return dist;
1179}
1180///////////////////////////////////////////////////////////////////////////
261c0caf 1181TObject* AliJet::Clone(const char* name) const
5f25234b 1182{
1183// Make a deep copy of the current object and provide the pointer to the copy.
1184// This memberfunction enables automatic creation of new objects of the
1185// correct type depending on the object type, a feature which may be very useful
1186// for containers when adding objects in case the container owns the objects.
1187// This feature allows e.g. AliVertex to store either AliJet objects or
1188// objects derived from AliJet via the AddJet memberfunction, provided
1189// these derived classes also have a proper Clone memberfunction.
1190
1191 AliJet* jet=new AliJet(*this);
1192 if (name)
1193 {
1194 if (strlen(name)) jet->SetName(name);
1195 }
1196 return jet;
1197}
1198///////////////////////////////////////////////////////////////////////////