]> git.uio.no Git - u/mrichter/AliRoot.git/blob - RALICE/AliJet.cxx
Also first (prototype) version of class IceDwalk introduced to perform
[u/mrichter/AliRoot.git] / RALICE / AliJet.cxx
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
16 // $Id$
17
18 ///////////////////////////////////////////////////////////////////////////
19 // Class AliJet
20 // Creation and investigation of a jet of particle tracks.
21 // An AliJet can be constructed by adding AliTracks.
22 //
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.
33 //
34 //    Note :
35 //    Modifications made to the original tracks also affect the AliTrack objects
36 //    which are stored in the AliJet. 
37 //
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 //
48 // See also the documentation provided for the memberfunction SetOwner(). 
49 //
50 // Coding example to make 2 jets j1 and j2.
51 // ----------------------------------------
52 // j1 contains the AliTracks t1 and t2
53 // j2 contains 10 different AliTracks via tx
54 //
55 // AliTrack t1,t2;
56 //  ...
57 //  ... // code to fill the AliTrack data
58 //  ...
59 // AliJet j1();
60 // j1.AddTrack(t1);
61 // j1.AddTrack(t2);
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 // }
74 //
75 // j1.Data();
76 // j2.Data("sph");
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 //
85 // delete tx;
86 //
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
90 //- Modified: NvE $Date$ UU-SAP Utrecht
91 ///////////////////////////////////////////////////////////////////////////
92
93 #include "AliJet.h"
94 #include "Riostream.h"
95  
96 ClassImp(AliJet) // Class implementation to enable ROOT I/O
97  
98 AliJet::AliJet() : TNamed(),Ali4Vector()
99 {
100 // Default constructor
101 // All variables initialised to 0
102 // Initial maximum number of tracks is set to the default value
103  Init();
104  Reset();
105  SetNtinit();
106 }
107 ///////////////////////////////////////////////////////////////////////////
108 void AliJet::Init()
109 {
110 // Initialisation of pointers etc...
111  fTracks=0;
112  fNtinit=0;
113  fTrackCopy=0;
114  fSelected=0;
115 }
116 ///////////////////////////////////////////////////////////////////////////
117 AliJet::AliJet(Int_t n) : TNamed(),Ali4Vector()
118 {
119 // Create a jet to hold initially a maximum of n tracks
120 // All variables initialised to 0
121  Init();
122  Reset();
123  if (n > 0)
124  {
125   SetNtinit(n);
126  }
127  else
128  {
129   cout << endl;
130   cout << " *AliJet* Initial max. number of tracks entered : " << n << endl;
131   cout << " This is invalid. Default initial maximum will be used." << endl;
132   cout << endl;
133   SetNtinit();
134  }
135 }
136 ///////////////////////////////////////////////////////////////////////////
137 AliJet::~AliJet()
138 {
139 // Default destructor
140  if (fTracks)
141  {
142   delete fTracks;
143   fTracks=0;
144  }
145  if (fSelected)
146  {
147   delete fSelected;
148   fSelected=0;
149  }
150 }
151 ///////////////////////////////////////////////////////////////////////////
152 void AliJet::SetOwner(Bool_t own)
153 {
154 // Set ownership of all added objects. 
155 // The default parameter is own=kTRUE.
156 //
157 // Invokation of this memberfunction also sets all the copy modes
158 // (e.g. TrackCopy & co.) according to the value of own.
159 //
160 // This function (with own=kTRUE) is particularly useful when reading data
161 // from a tree/file, since Reset() will then actually remove all the
162 // added objects from memory irrespective of the copy mode settings
163 // during the tree/file creation process. In this way it provides a nice way
164 // of preventing possible memory leaks in the reading/analysis process.
165 //
166 // In addition this memberfunction can also be used as a shortcut to set all
167 // copy modes in one go during a tree/file creation process.
168 // However, in this case the user has to take care to only set/change the
169 // ownership (and copy mode) for empty objects (e.g. newly created objects
170 // or after invokation of the Reset() memberfunction) otherwise it will
171 // very likely result in inconsistent destructor behaviour.
172
173  Int_t mode=1;
174  if (!own) mode=0;
175  if (fTracks) fTracks->SetOwner(own);
176  fTrackCopy=mode;
177 }
178 ///////////////////////////////////////////////////////////////////////////
179 AliJet::AliJet(const AliJet& j) : TNamed(j),Ali4Vector(j)
180 {
181 // Copy constructor
182  fNtinit=j.fNtinit;
183  fNtmax=j.fNtmax;
184  fQ=j.fQ;
185  fNtrk=j.fNtrk;
186  fTrackCopy=j.fTrackCopy;
187  fUserId=j.fUserId;
188
189  fSelected=0;
190
191  fTracks=0;
192  if (fNtrk)
193  {
194   fTracks=new TObjArray(fNtmax);
195   if (fTrackCopy) fTracks->SetOwner();
196  }
197
198  for (Int_t i=1; i<=fNtrk; i++)
199  {
200   AliTrack* tx=j.GetTrack(i);
201   if (fTrackCopy)
202   {
203    fTracks->Add(tx->Clone());
204   }
205   else
206   {
207    fTracks->Add(tx);
208   }
209  } 
210 }
211 ///////////////////////////////////////////////////////////////////////////
212 void AliJet::SetNtinit(Int_t n)
213 {
214 // Set the initial maximum number of tracks for this jet
215  fNtinit=n;
216  fNtmax=n;
217
218  if (fTracks)
219  {
220   delete fTracks;
221   fTracks=0;
222  }
223 }
224 ///////////////////////////////////////////////////////////////////////////
225 void AliJet::Reset()
226 {
227 // Reset all variables to 0
228 // The max. number of tracks is set to the initial value again
229  fNtrk=0;
230  fQ=0;
231  fUserId=0;
232  Double_t a[4]={0,0,0,0};
233  SetVector(a,"sph");
234  if (fNtinit > 0) SetNtinit(fNtinit);
235 }
236 ///////////////////////////////////////////////////////////////////////////
237 void AliJet::AddTrack(AliTrack& t)
238 {
239 // Add a track to the jet.
240 // In case the maximum number of tracks has been reached
241 // space will be extended to hold an additional amount of tracks as
242 // was initially reserved.
243 // See SetTrackCopy() to tailor the functionality of the stored structures.
244 //
245 // Notes :
246 // -------
247 // In case a private copy is made, this is performed via the Clone() memberfunction.
248 // All AliTrack and derived classes have the default TObject::Clone() memberfunction.
249 // However, derived classes generally contain an internal data structure which may
250 // include pointers to other objects. Therefore it is recommended to provide
251 // for all derived classes a specific copy constructor and override the default Clone()
252 // memberfunction using this copy constructor.
253 // An example for this may be seen from AliTrack.   
254 //
255 // In case NO private copy is made, a check will be performed if this
256 // specific track is already present in the jet.
257 // If this is the case, no action is performed to prevent multiple
258 // additions of the same track.
259
260
261  AddTrack(t,1);
262 }
263 ///////////////////////////////////////////////////////////////////////////
264 void AliJet::AddTrack(AliTrack& t,Int_t copy)
265 {
266 // Internal memberfunction to actually add a track to the jet.
267 // In case the maximum number of tracks has been reached
268 // space will be extended to hold an additional amount of tracks as
269 // was initially reserved.
270 //
271 // If copy=0 NO copy of the track will be made, irrespective of the setting
272 // of the TrackCopy flag.
273 // This allows a proper treatment of automatically generated connecting
274 // tracks between vertices.
275 //
276 // In case NO copy of the track is made, a check will be performed if this
277 // specific track is already present in the jet.
278 // If this is the case, no action is performed to prevent multiple
279 // additions of the same track.
280 //
281 // Note :
282 // In case a private copy is made, this is performed via the Clone() memberfunction.
283
284  if (!fTracks)
285  {
286   fTracks=new TObjArray(fNtmax);
287   if (fTrackCopy) fTracks->SetOwner();
288  }
289  else if (!fTrackCopy || !copy) // Check if this track is already present
290  {
291   for (Int_t i=0; i<fNtrk; i++)
292   {
293    AliTrack* tx=(AliTrack*)fTracks->At(i);
294    if (tx == &t) return;
295   }
296  }
297
298  if (fNtrk == fNtmax) // Check if maximum track number is reached
299  {
300   fNtmax+=fNtinit;
301   fTracks->Expand(fNtmax);
302  }
303  
304  // Add the track to this jet
305  fNtrk++;
306  if (fTrackCopy && copy)
307  {
308   fTracks->Add(t.Clone());
309  }
310  else
311  {
312   fTracks->Add(&t);
313  }
314
315  (*this)+=(Ali4Vector&)t;
316  fQ+=t.GetCharge();
317
318 }
319 ///////////////////////////////////////////////////////////////////////////
320 void AliJet::Data(TString f,TString u)
321 {
322 // Provide jet information within the coordinate frame f
323 //
324 // The string argument "u" allows to choose between different angular units
325 // in case e.g. a spherical frame is selected.
326 // u = "rad" : angles provided in radians
327 //     "deg" : angles provided in degrees
328 //
329 // The defaults are f="car" and u="rad".
330
331  const char* name=GetName();
332  const char* title=GetTitle();
333
334  cout << " *AliJet::Data*";
335  if (strlen(name))  cout << " Name : " << GetName();
336  if (strlen(title)) cout << " Title : " << GetTitle();
337  cout << endl;
338  cout << " Id : " << fUserId << " Invmass : " << GetInvmass() << " Charge : " << fQ
339       << " Momentum : " << GetMomentum() << endl;
340
341  ShowTracks(0);
342
343  Ali4Vector::Data(f,u); 
344
345 ///////////////////////////////////////////////////////////////////////////
346 void AliJet::List(TString f,TString u)
347 {
348 // Provide jet and primary track information within the coordinate frame f
349 //
350 // The string argument "u" allows to choose between different angular units
351 // in case e.g. a spherical frame is selected.
352 // u = "rad" : angles provided in radians
353 //     "deg" : angles provided in degrees
354 //
355 // The defaults are f="car" and u="rad".
356
357  Data(f,u); // Information of the current jet
358
359  // The tracks of this jet
360  AliTrack* t; 
361  for (Int_t it=1; it<=fNtrk; it++)
362  {
363   t=GetTrack(it);
364   if (t)
365   {
366    cout << "  ---Track no. " << it << endl;
367    cout << " ";
368    t->Data(f,u); 
369   }
370   else
371   {
372    cout << " *AliJet::List* Error : No track present." << endl; 
373   }
374  }
375
376 ///////////////////////////////////////////////////////////////////////////
377 void AliJet::ListAll(TString f,TString u)
378 {
379 // Provide jet and prim.+sec. track information within the coordinate frame f
380 //
381 // The string argument "u" allows to choose between different angular units
382 // in case e.g. a spherical frame is selected.
383 // u = "rad" : angles provided in radians
384 //     "deg" : angles provided in degrees
385 //
386 // The defaults are f="car" and u="rad".
387
388  Data(f,u); // Information of the current jet
389
390  // The tracks of this jet
391  AliTrack* t; 
392  for (Int_t it=1; it<=fNtrk; it++)
393  {
394   t=GetTrack(it);
395   if (t)
396   {
397    cout << "  ---Track no. " << it << endl;
398    cout << " ";
399    t->ListAll(f,u); 
400   }
401   else
402   {
403    cout << " *AliJet::List* Error : No track present." << endl; 
404   }
405  }
406
407 ///////////////////////////////////////////////////////////////////////////
408 Int_t AliJet::GetNtracks(Int_t idmode,Int_t chmode,Int_t pcode)
409 {
410 // Provide the number of user selected tracks in this jet based on the
411 // idmode, chmode and pcode selections as specified by the user.
412 // For specification of the selection parameters see GetTracks().
413 // The default parameters correspond to no selection, which implies
414 // that invokation of GetNtracks() just returns the total number of
415 // tracks registered in this jet.
416 //
417 // Note : In case certain selections are specified, this function
418 //        invokes GetTracks(idmode,chmode,pcode) to determine the
419 //        number of tracks corresponding to the selections.
420 //        When the jet contains a large number of tracks, invokation
421 //        of GetTracks(idmode,chmode,pcode) and subsequently invoking
422 //        GetEntries() for the resulting TObjArray* might be slightly
423 //        faster.
424
425  Int_t n=0;
426  if (idmode==0 && chmode==2 && pcode==0)
427  {
428   return fNtrk;
429  }
430  else
431  {
432   TObjArray* arr=GetTracks(idmode,chmode,pcode);
433   n=arr->GetEntries();
434   return n;
435  }
436 }
437 ///////////////////////////////////////////////////////////////////////////
438 Double_t AliJet::GetEnergy()
439 {
440 // Return the total energy of the jet
441  return GetScalar();
442 }
443 ///////////////////////////////////////////////////////////////////////////
444 Double_t AliJet::GetMomentum()
445 {
446 // Return the value of the total jet 3-momentum
447 // The error can be obtained by invoking GetResultError() after
448 // invokation of GetMomentum().
449  Double_t norm=fV.GetNorm();
450  fDresult=fV.GetResultError();
451  return norm;
452 }
453 ///////////////////////////////////////////////////////////////////////////
454 Ali3Vector AliJet::Get3Momentum() const
455 {
456 // Return the the total jet 3-momentum
457  Ali3Vector p=Get3Vector();
458  return p;
459 }
460 ///////////////////////////////////////////////////////////////////////////
461 Double_t AliJet::GetInvmass()
462 {
463 // Return the invariant mass of the jet
464  Double_t m2=Dot(*this);
465  if (m2>0)
466  {
467   return sqrt(m2);
468  }
469  else
470  {
471   return 0;
472  }
473 }
474 ///////////////////////////////////////////////////////////////////////////
475 Float_t AliJet::GetCharge() const
476 {
477 // Return the total charge of the jet
478  return fQ;
479 }
480 ///////////////////////////////////////////////////////////////////////////
481 AliTrack* AliJet::GetTrack(Int_t i) const
482 {
483 // Return the i-th track of this jet
484
485  if (!fTracks) return 0;
486
487  if (i<=0 || i>fNtrk)
488  {
489   cout << " *AliJet*::GetTrack* Invalid argument i : " << i
490        << " Ntrk = " << fNtrk << endl;
491   return 0;
492  }
493  else
494  {
495   return (AliTrack*)fTracks->At(i-1);
496  }
497 }
498 ///////////////////////////////////////////////////////////////////////////
499 AliTrack* AliJet::GetIdTrack(Int_t id) const
500 {
501 // Return the track with user identifier "id" of this jet
502  if (!fTracks) return 0;
503
504  AliTrack* tx=0;
505  for (Int_t i=0; i<fNtrk; i++)
506  {
507   tx=(AliTrack*)fTracks->At(i);
508   if (id == tx->GetId()) return tx;
509  }
510  return 0; // No matching id found
511 }
512 ///////////////////////////////////////////////////////////////////////////
513 TObjArray* AliJet::GetTracks(Int_t idmode,Int_t chmode,Int_t pcode)
514 {
515 // Provide references to user selected tracks based on the idmode, chmode
516 // and pcode selections as specified by the user.
517 //
518 // The following selection combinations are available :
519 // ----------------------------------------------------
520 // idmode = -1 ==> Select tracks with negative user identifier "id"
521 //           0 ==> No selection on user identifier
522 //           1 ==> Select tracks with positive user identifier "id"
523 //
524 // chmode = -1 ==> Select tracks with negative charge
525 //           0 ==> Select neutral tracks
526 //           1 ==> Select tracks with positive charge
527 //           2 ==> No selection on charge
528 //           3 ==> Select all charged tracks
529 //
530 // pcode  =  0 ==> No selection on particle code
531 //           X ==> Select tracks with particle code +X or -X
532 //                 This allows selection of both particles and anti-particles
533 //                 in case of PDG particle codes.
534 //                 Selection of either particles or anti-particles can be
535 //                 obtained in combination with the "chmode" selector.
536 //
537 // Examples :
538 // ----------
539 // idmode=-1 chmode=0 pcode=0   : Selection of all neutral tracks with negative id.
540 // idmode=0  chmode=2 pcode=211 : Selection of all charged pions (PDG convention).
541 // idmode=0  chmode=1 pcode=321 : Selection of all positive kaons (PDG convention).
542 //
543 // The default values are idmode=0 chmode=2 pcode=0 (i.e. no selections applied).
544 //
545 // Notes :
546 // -------
547 // 1) In case the user has labeled simulated tracks with negative id and
548 //    reconstructed tracks with positive id, this memberfunction provides
549 //    easy access to either all simulated or reconstructed tracks.
550 // 2) Subsequent invokations of this memberfunction with e.g. chmode=-1 and chmode=1
551 //    provides a convenient way to investigate particle pairs with opposite charge
552 //    (e.g. for invariant mass analysis).
553
554  if (fSelected)
555  {
556   fSelected->Clear();
557  }
558  else
559  {
560   fSelected=new TObjArray();
561  }
562
563  if (!fTracks) return fSelected;
564
565  AliTrack* tx=0;
566  Int_t code=0;
567  Int_t id=0;
568  Float_t q=0;
569  for (Int_t i=0; i<fNtrk; i++)
570  {
571   tx=(AliTrack*)fTracks->At(i);
572   if (!tx) continue;
573
574   code=tx->GetParticleCode();
575   if (pcode && abs(pcode)!=abs(code)) continue;
576
577   id=tx->GetId();
578   if (idmode==-1 && id>=0) continue;
579   if (idmode==1 && id<=0) continue;
580
581   q=tx->GetCharge();
582   if (chmode==-1 && q>=0) continue;
583   if (chmode==0 && fabs(q)>1e-10) continue;
584   if (chmode==1 && q<=0) continue;
585   if (chmode==3 && fabs(q)<1e-10) continue;
586
587   fSelected->Add(tx);
588  }
589
590  return fSelected;
591 }
592 ///////////////////////////////////////////////////////////////////////////
593 void AliJet::ShowTracks(Int_t mode)
594 {
595 // Provide an overview of the available tracks.
596 // The argument mode determines the amount of information as follows :
597 // mode = 0 ==> Only printout of the number of tracks
598 //        1 ==> Provide a listing with 1 line of info for each track
599 //
600 // The default is mode=1.
601 //
602  Int_t ntk=GetNtracks();
603  if (ntk)
604  {
605   if (!mode)
606   {
607    cout << " There are " << ntk << " tracks available." << endl; 
608   }
609   else
610   {
611    cout << " The following " << ntk << " tracks are available :" << endl; 
612    for (Int_t i=1; i<=ntk; i++)
613    {
614     AliTrack* tx=GetTrack(i);
615     if (tx)
616     {
617      const char* name=tx->GetName();
618      const char* title=tx->GetTitle();
619      cout << " Track : " << i;
620      cout << " Id : " << tx->GetId();
621      cout << " Q : " << tx->GetCharge() << " m : " << tx->GetMass() << " p : " << tx->GetMomentum();
622      if (strlen(name)) cout << " Name : " << name;
623      if (strlen(title)) cout << " Title : " << title;
624      cout << endl;
625     }
626    }
627   }
628  }
629  else
630  {
631   cout << " No tracks are present." << endl;
632  }
633 }
634 ///////////////////////////////////////////////////////////////////////////
635 Double_t AliJet::GetPt()
636 {
637 // Provide trans. momentum value w.r.t. z-axis.
638 // The error on the value can be obtained by GetResultError()
639 // after invokation of GetPt().
640  Ali3Vector v;
641  v=GetVecTrans();
642  Double_t norm=v.GetNorm();
643  fDresult=v.GetResultError();
644
645  return norm;
646 }
647 ///////////////////////////////////////////////////////////////////////////
648 Double_t AliJet::GetPl()
649 {
650 // Provide long. momentum value w.r.t. z-axis.
651 // Note : the returned value can also be negative.
652 // The error on the value can be obtained by GetResultError()
653 // after invokation of GetPl().
654  Ali3Vector v;
655  v=GetVecLong();
656
657  Double_t pl=v.GetNorm();
658  fDresult=v.GetResultError();
659
660  Double_t a[3];
661  v.GetVector(a,"sph");
662  if (cos(a[1])<0) pl=-pl;
663
664  return pl;
665 }
666 ///////////////////////////////////////////////////////////////////////////
667 Double_t AliJet::GetEt()
668 {
669 // Provide trans. energy value w.r.t. z-axis.
670 // The error on the value can be obtained by GetResultError()
671 // after invokation of GetEt().
672  Double_t et=GetScaTrans();
673
674  return et;
675 }
676 ///////////////////////////////////////////////////////////////////////////
677 Double_t AliJet::GetEl()
678 {
679 // Provide long. energy value w.r.t. z-axis.
680 // Note : the returned value can also be negative.
681 // The error on the value can be obtained by GetResultError()
682 // after invokation of GetEl().
683  Double_t el=GetScaLong();
684
685  return el;
686 }
687 ///////////////////////////////////////////////////////////////////////////
688 Double_t AliJet::GetMt()
689 {
690 // Provide transverse mass value w.r.t. z-axis.
691 // The error on the value can be obtained by GetResultError()
692 // after invokation of GetMt().
693  Double_t pt=GetPt();
694  Double_t dpt=GetResultError();
695  Double_t m=GetInvmass();
696  Double_t dm=GetResultError();
697
698  Double_t mt=sqrt(pt*pt+m*m);
699  Double_t dmt2=0;
700  if (mt) dmt2=(pow((pt*dpt),2)+pow((m*dm),2))/(mt*mt);
701
702  fDresult=sqrt(dmt2);
703  return mt;
704 }
705 ///////////////////////////////////////////////////////////////////////////
706 Double_t AliJet::GetRapidity()
707 {
708 // Provide rapidity value w.r.t. z-axis.
709 // The error on the value can be obtained by GetResultError()
710 // after invokation of GetRapidity().
711 // Note : Also GetPseudoRapidity() is available since this class is
712 //        derived from Ali4Vector.
713  Double_t e=GetEnergy();
714  Double_t de=GetResultError();
715  Double_t pl=GetPl();
716  Double_t dpl=GetResultError();
717  Double_t sum=e+pl;
718  Double_t dif=e-pl;
719
720  Double_t y=9999,dy2=0;
721  if (sum && dif) y=0.5*log(sum/dif);
722
723  if (sum*dif) dy2=(1./(sum*dif))*(pow((pl*de),2)+pow((e*dpl),2));
724
725  fDresult=sqrt(dy2);
726  return y;
727 }
728 ///////////////////////////////////////////////////////////////////////////
729 void AliJet::SetTrackCopy(Int_t j)
730 {
731 // (De)activate the creation of private copies of the added tracks.
732 // j=0 ==> No private copies are made; pointers of original tracks are stored.
733 // j=1 ==> Private copies of the tracks are made and these pointers are stored.
734 //
735 // Note : Once the storage contains pointer(s) to AliTrack(s) one cannot
736 //        change the TrackCopy mode anymore.
737 //        To change the TrackCopy mode for an existing AliJet containing
738 //        tracks one first has to invoke Reset().
739  if (!fTracks)
740  {
741   if (j==0 || j==1)
742   {
743    fTrackCopy=j;
744   }
745   else
746   {
747    cout << "*AliJet::SetTrackCopy* Invalid argument : " << j << endl;
748   }
749  }
750  else
751  {
752   cout << "*AliJet::SetTrackCopy* Storage already contained tracks."
753        << "  ==> TrackCopy mode not changed." << endl; 
754  }
755 }
756 ///////////////////////////////////////////////////////////////////////////
757 Int_t AliJet::GetTrackCopy() const
758 {
759 // Provide value of the TrackCopy mode.
760 // 0 ==> No private copies are made; pointers of original tracks are stored.
761 // 1 ==> Private copies of the tracks are made and these pointers are stored.
762  return fTrackCopy;
763 }
764 ///////////////////////////////////////////////////////////////////////////
765 void AliJet::SetId(Int_t id)
766 {
767 // Set a user defined identifier for this jet.
768  fUserId=id;
769 }
770 ///////////////////////////////////////////////////////////////////////////
771 Int_t AliJet::GetId() const
772 {
773 // Provide the user defined identifier of this jet.
774  return fUserId;
775 }
776 ///////////////////////////////////////////////////////////////////////////
777 TObjArray* AliJet::SortTracks(Int_t mode,TObjArray* tracks)
778 {
779 // Order the references to an array of tracks by looping over the input array "tracks"
780 // and checking the value of a certain observable.
781 // The ordered array is returned as a TObjArray.
782 // In case tracks=0 (default), the registered tracks of the current jet are used. 
783 // Note that the original track array is not modified.
784 // Via the "mode" argument the user can specify the observable to be checked upon
785 // and specify whether sorting should be performed in decreasing order (mode<0)
786 // or in increasing order (mode>0).
787 //
788 // The convention for the observable selection is the following :
789 // mode : 1 ==> Number of signals associated to the track
790 //        2 ==> Track energy
791 //        3 ==> Track momentum
792 //        4 ==> Mass of the track
793 //        5 ==> Transverse momentum of the track
794 //        6 ==> Longitudinal momentum of the track
795 //        7 ==> Transverse energy of the track
796 //        8 ==> Longitudinal energy of the track
797 //        9 ==> Transverse mass of the track
798 //       10 ==> Track rapidity
799 //       11 ==> Pseudo-rapidity of the track
800 //
801 // The default is mode=-1.
802 //
803 // Note : This sorting routine uses a common area in memory, which is used
804 //        by various other sorting facilities as well.
805 //        This means that the resulting sorted TObjArray may be overwritten
806 //        when another sorting is invoked.
807 //        To retain the sorted list of pointers, the user is advised to copy
808 //        the pointers contained in the returned TObjArray into a private
809 //        TObjArray instance.
810
811  if (fSelected)
812  {
813   delete fSelected;
814   fSelected=0;
815  }
816
817  if (!tracks) tracks=fTracks;
818  
819  if (abs(mode)>11 || !tracks) return fSelected;
820
821  Int_t ntracks=tracks->GetEntries();
822  if (!ntracks)
823  {
824   return fSelected;
825  }
826  else
827  {
828   fSelected=new TObjArray(ntracks);
829  }
830
831  Double_t val1,val2; // Values of the observable to be tested upon
832  
833  Int_t nord=0;
834  for (Int_t i=0; i<ntracks; i++) // Loop over all tracks of the array
835  {
836   AliTrack* tx=(AliTrack*)tracks->At(i);
837
838   if (!tx) continue;
839  
840   if (nord == 0) // store the first track at the first ordered position
841   {
842    nord++;
843    fSelected->AddAt(tx,nord-1);
844    continue;
845   }
846  
847   for (Int_t j=0; j<=nord; j++) // put track in the right ordered position
848   {
849    if (j == nord) // track has smallest (mode<0) or largest (mode>0) observable value seen so far
850    {
851     nord++;
852     fSelected->AddAt(tx,j); // add track at the end
853     break; // go for next track
854    }
855    
856    switch (abs(mode))
857    {
858     case 1:
859      val1=tx->GetNsignals();
860      val2=((AliTrack*)fSelected->At(j))->GetNsignals();
861      break;
862     case 2:
863      val1=tx->GetEnergy();
864      val2=((AliTrack*)fSelected->At(j))->GetEnergy();
865      break;
866     case 3:
867      val1=tx->GetMomentum();
868      val2=((AliTrack*)fSelected->At(j))->GetMomentum();
869      break;
870     case 4:
871      val1=tx->GetMass();
872      val2=((AliTrack*)fSelected->At(j))->GetMass();
873      break;
874     case 5:
875      val1=tx->GetPt();
876      val2=((AliTrack*)fSelected->At(j))->GetPt();
877      break;
878     case 6:
879      val1=tx->GetPl();
880      val2=((AliTrack*)fSelected->At(j))->GetPl();
881      break;
882     case 7:
883      val1=tx->GetEt();
884      val2=((AliTrack*)fSelected->At(j))->GetEt();
885      break;
886     case 8:
887      val1=tx->GetEl();
888      val2=((AliTrack*)fSelected->At(j))->GetEl();
889      break;
890     case 9:
891      val1=tx->GetMt();
892      val2=((AliTrack*)fSelected->At(j))->GetMt();
893      break;
894     case 10:
895      val1=tx->GetRapidity();
896      val2=((AliTrack*)fSelected->At(j))->GetRapidity();
897      break;
898     case 11:
899      val1=tx->GetPseudoRapidity();
900      val2=((AliTrack*)fSelected->At(j))->GetPseudoRapidity();
901      break;
902    }
903
904    if (mode<0 && val1 < val2) continue;
905    if (mode>0 && val1 > val2) continue;
906  
907    nord++;
908    for (Int_t k=nord-1; k>j; k--) // create empty position
909    {
910     fSelected->AddAt(fSelected->At(k-1),k);
911    }
912    fSelected->AddAt(tx,j); // put track at empty position
913    break; // go for next track
914   }
915  }
916  return fSelected;
917 }
918 ///////////////////////////////////////////////////////////////////////////
919 TObject* AliJet::Clone(const char* name) const
920 {
921 // Make a deep copy of the current object and provide the pointer to the copy.
922 // This memberfunction enables automatic creation of new objects of the
923 // correct type depending on the object type, a feature which may be very useful
924 // for containers when adding objects in case the container owns the objects.
925 // This feature allows e.g. AliVertex to store either AliJet objects or
926 // objects derived from AliJet via the AddJet memberfunction, provided
927 // these derived classes also have a proper Clone memberfunction. 
928
929  AliJet* jet=new AliJet(*this);
930  if (name)
931  {
932   if (strlen(name)) jet->SetName(name);
933  }
934  return jet;
935 }
936 ///////////////////////////////////////////////////////////////////////////