]> git.uio.no Git - u/mrichter/AliRoot.git/blob - RALICE/AliJet.cxx
e667584238754d58b3b715e066aa17f28f18a41a
[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 // Coding example to make 2 jets j1 and j2.
49 // ----------------------------------------
50 // j1 contains the AliTracks t1 and t2
51 // j2 contains 10 different AliTracks via tx
52 //
53 // AliTrack t1,t2;
54 //  ...
55 //  ... // code to fill the AliTrack data
56 //  ...
57 // AliJet j1();
58 // j1.AddTrack(t1);
59 // j1.AddTrack(t2);
60 //
61 // AliJet j2();
62 // j2.SetTrackCopy(1);
63 // AliTrack* tx=new AliTrack();
64 // for (Int_t i=0; i<10; i++)
65 // {
66 //  ...
67 //  ... // code to set momentum etc... of the track tx
68 //  ...
69 //  j2.AddTrack(tx);
70 //  tx->Reset();
71 // }
72 //
73 // j1.Info();
74 // j2.Info("sph");
75 //
76 // Float_t e1=j1.GetEnergy();
77 // Float_t pnorm=j1->GetMomentum();
78 // Ali3Vector p=j1->Get3Momentum();
79 // Float_t m=j1.GetInvmass();
80 // Int_t ntk=j1.GetNtracks();
81 // AliTrack* tj=j1.GetTrack(1);
82 //
83 // delete tx;
84 //
85 // Note : All quantities are in GeV, GeV/c or GeV/c**2
86 //
87 //--- Author: Nick van Eijndhoven 10-jul-1997 UU-SAP Utrecht
88 //- Modified: NvE $Date$ UU-SAP Utrecht
89 ///////////////////////////////////////////////////////////////////////////
90
91 #include "AliJet.h"
92  
93 ClassImp(AliJet) // Class implementation to enable ROOT I/O
94  
95 AliJet::AliJet()
96 {
97 // Default constructor
98 // All variables initialised to 0
99 // Initial maximum number of tracks is set to the default value
100  fTracks=0;
101  fNtinit=0;
102  fTrackCopy=0;
103  Reset();
104  SetNtinit();
105 }
106 ///////////////////////////////////////////////////////////////////////////
107 AliJet::AliJet(Int_t n)
108 {
109 // Create a jet to hold initially a maximum of n tracks
110 // All variables initialised to 0
111  fTracks=0;
112  fNtinit=0;
113  fTrackCopy=0;
114  Reset();
115  if (n > 0)
116  {
117   SetNtinit(n);
118  }
119  else
120  {
121   cout << endl;
122   cout << " *AliJet* Initial max. number of tracks entered : " << n << endl;
123   cout << " This is invalid. Default initial maximum will be used." << endl;
124   cout << endl;
125   SetNtinit();
126  }
127 }
128 ///////////////////////////////////////////////////////////////////////////
129 AliJet::~AliJet()
130 {
131 // Default destructor
132  if (fTracks)
133  {
134   if (fTrackCopy) fTracks->Delete();
135   delete fTracks;
136   fTracks=0;
137  }
138 }
139 ///////////////////////////////////////////////////////////////////////////
140 void AliJet::SetNtinit(Int_t n)
141 {
142 // Set the initial maximum number of tracks for this jet
143  fNtinit=n;
144  fNtmax=n;
145  if (fTracks)
146  {
147   if (fTrackCopy) fTracks->Delete();
148   delete fTracks;
149   fTracks=0;
150  }
151 }
152 ///////////////////////////////////////////////////////////////////////////
153 void AliJet::Reset()
154 {
155 // Reset all variables to 0
156 // The max. number of tracks is set to the initial value again
157  fNtrk=0;
158  fQ=0;
159  Double_t a[4]={0,0,0,0};
160  SetVector(a,"sph");
161  if (fNtinit > 0) SetNtinit(fNtinit);
162 }
163 ///////////////////////////////////////////////////////////////////////////
164 void AliJet::AddTrack(AliTrack& t)
165 {
166 // Add a track to the jet.
167 // Note : In case TrackCopy is set, the originally entered track
168 //        will be automatically reset.
169 // In case the maximum number of tracks has been reached
170 // space will be extended to hold an additional amount of tracks as
171 // was initially reserved.
172  if (!fTracks) fTracks=new TObjArray(fNtmax);
173  if (fNtrk == fNtmax) // Check if maximum track number is reached
174  {
175   fNtmax+=fNtinit;
176   fTracks->Expand(fNtmax);
177  }
178  
179  // Add the track to this jet
180  fNtrk++;
181  if (fTrackCopy)
182  {
183   fTracks->Add(t.Clone());
184  }
185  else
186  {
187   fTracks->Add(&t);
188  }
189
190  (*this)+=(Ali4Vector&)t;
191  fQ+=t.GetCharge();
192
193 }
194 ///////////////////////////////////////////////////////////////////////////
195 void AliJet::Info(TString f)
196 {
197 // Provide jet information within the coordinate frame f
198  cout << " *AliJet::Info* Invmass : " << GetInvmass() << " Charge : " << fQ
199       << " Momentum : " << GetMomentum() << " Ntracks : " << fNtrk << endl;
200  cout << " ";
201  Ali4Vector::Info(f); 
202
203 ///////////////////////////////////////////////////////////////////////////
204 void AliJet::List(TString f)
205 {
206 // Provide jet and primary track information within the coordinate frame f
207
208  Info(f); // Information of the current jet
209
210  // The tracks of this jet
211  AliTrack* t; 
212  for (Int_t it=1; it<=fNtrk; it++)
213  {
214   t=GetTrack(it);
215   if (t)
216   {
217    cout << "  ---Track no. " << it << endl;
218    cout << " ";
219    t->Info(f); 
220   }
221   else
222   {
223    cout << " *AliJet::List* Error : No track present." << endl; 
224   }
225  }
226
227 ///////////////////////////////////////////////////////////////////////////
228 void AliJet::ListAll(TString f)
229 {
230 // Provide jet and prim.+sec. track information within the coordinate frame f
231
232  Info(f); // Information of the current jet
233
234  // The tracks of this jet
235  AliTrack* t; 
236  for (Int_t it=1; it<=fNtrk; it++)
237  {
238   t=GetTrack(it);
239   if (t)
240   {
241    cout << "  ---Track no. " << it << endl;
242    cout << " ";
243    t->ListAll(f); 
244   }
245   else
246   {
247    cout << " *AliJet::List* Error : No track present." << endl; 
248   }
249  }
250
251 ///////////////////////////////////////////////////////////////////////////
252 Int_t AliJet::GetNtracks()
253 {
254 // Return the current number of tracks of this jet
255  return fNtrk;
256 }
257 ///////////////////////////////////////////////////////////////////////////
258 Double_t AliJet::GetEnergy()
259 {
260 // Return the total energy of the jet
261  return GetScalar();
262 }
263 ///////////////////////////////////////////////////////////////////////////
264 Double_t AliJet::GetMomentum()
265 {
266 // Return the value of the total jet 3-momentum
267 // The error can be obtained by invoking GetResultError() after
268 // invokation of GetMomentum().
269  Double_t norm=fV.GetNorm();
270  fDresult=fV.GetResultError();
271  return norm;
272 }
273 ///////////////////////////////////////////////////////////////////////////
274 Ali3Vector AliJet::Get3Momentum()
275 {
276 // Return the the total jet 3-momentum
277  Ali3Vector p=Get3Vector();
278  return p;
279 }
280 ///////////////////////////////////////////////////////////////////////////
281 Double_t AliJet::GetInvmass()
282 {
283 // Return the invariant mass of the jet
284  Double_t m2=Dot(*this);
285  if (m2>0)
286  {
287   return sqrt(m2);
288  }
289  else
290  {
291   return 0;
292  }
293 }
294 ///////////////////////////////////////////////////////////////////////////
295 Float_t AliJet::GetCharge()
296 {
297 // Return the total charge of the jet
298  return fQ;
299 }
300 ///////////////////////////////////////////////////////////////////////////
301 AliTrack* AliJet::GetTrack(Int_t i)
302 {
303 // Return the i-th track of this jet
304  if (!fTracks)
305  {
306   cout << " *AliJet*::GetTrack* No tracks present." << endl;
307   return 0;
308  }
309  else
310  {
311   if (i<=0 || i>fNtrk)
312   {
313    cout << " *AliJet*::GetTrack* Invalid argument i : " << i
314         << " Ntrk = " << fNtrk << endl;
315    return 0;
316   }
317   else
318   {
319    return (AliTrack*)fTracks->At(i-1);
320   }
321  }
322 }
323 ///////////////////////////////////////////////////////////////////////////
324 Double_t AliJet::GetPt()
325 {
326 // Provide trans. momentum value w.r.t. z-axis.
327 // The error on the value can be obtained by GetResultError()
328 // after invokation of GetPt().
329  Ali3Vector v;
330  v=GetVecTrans();
331  Double_t norm=v.GetNorm();
332  fDresult=v.GetResultError();
333
334  return norm;
335 }
336 ///////////////////////////////////////////////////////////////////////////
337 Double_t AliJet::GetPl()
338 {
339 // Provide long. momentum value w.r.t. z-axis.
340 // Note : the returned value can also be negative.
341 // The error on the value can be obtained by GetResultError()
342 // after invokation of GetPl().
343  Ali3Vector v;
344  v=GetVecLong();
345
346  Double_t pl=v.GetNorm();
347  fDresult=v.GetResultError();
348
349  Double_t a[3];
350  v.GetVector(a,"sph");
351  if (cos(a[1])<0) pl=-pl;
352
353  return pl;
354 }
355 ///////////////////////////////////////////////////////////////////////////
356 Double_t AliJet::GetEt()
357 {
358 // Provide trans. energy value w.r.t. z-axis.
359 // The error on the value can be obtained by GetResultError()
360 // after invokation of GetEt().
361  Double_t et=GetScaTrans();
362
363  return et;
364 }
365 ///////////////////////////////////////////////////////////////////////////
366 Double_t AliJet::GetEl()
367 {
368 // Provide long. energy value w.r.t. z-axis.
369 // Note : the returned value can also be negative.
370 // The error on the value can be obtained by GetResultError()
371 // after invokation of GetEl().
372  Double_t el=GetScaLong();
373
374  return el;
375 }
376 ///////////////////////////////////////////////////////////////////////////
377 Double_t AliJet::GetMt()
378 {
379 // Provide transverse mass value w.r.t. z-axis.
380 // The error on the value can be obtained by GetResultError()
381 // after invokation of GetMt().
382  Double_t pt=GetPt();
383  Double_t dpt=GetResultError();
384  Double_t m=GetInvmass();
385  Double_t dm=GetResultError();
386
387  Double_t mt=sqrt(pt*pt+m*m);
388  Double_t dmt2=0;
389  if (mt) dmt2=(pow((pt*dpt),2)+pow((m*dm),2))/(mt*mt);
390
391  fDresult=sqrt(dmt2);
392  return mt;
393 }
394 ///////////////////////////////////////////////////////////////////////////
395 Double_t AliJet::GetRapidity()
396 {
397 // Provide rapidity value w.r.t. z-axis.
398 // The error on the value can be obtained by GetResultError()
399 // after invokation of GetRapidity().
400 // Note : Also GetPseudoRapidity() is available since this class is
401 //        derived from Ali4Vector.
402  Double_t e=GetEnergy();
403  Double_t de=GetResultError();
404  Double_t pl=GetPl();
405  Double_t dpl=GetResultError();
406  Double_t sum=e+pl;
407  Double_t dif=e-pl;
408
409  Double_t y=9999,dy2=0;
410  if (sum && dif) y=0.5*log(sum/dif);
411
412  if (sum*dif) dy2=(1./(sum*dif))*(pow((pl*de),2)+pow((e*dpl),2));
413
414  fDresult=sqrt(dy2);
415  return y;
416 }
417 ///////////////////////////////////////////////////////////////////////////
418 void AliJet::SetTrackCopy(Int_t j)
419 {
420 // (De)activate the creation of private copies of the added tracks.
421 // j=0 ==> No private copies are made; pointers of original tracks are stored.
422 // j=1 ==> Private copies of the tracks are made and these pointers are stored.
423 //
424 // Note : Once the storage contains pointer(s) to AliTrack(s) one cannot
425 //        change the TrackCopy mode anymore.
426 //        To change the TrackCopy mode for an existing AliJet containing
427 //        tracks one first has to invoke Reset().
428  if (!fTracks)
429  {
430   if (j==0 || j==1)
431   {
432    fTrackCopy=j;
433   }
434   else
435   {
436    cout << "*AliJet::SetTrackCopy* Invalid argument : " << j << endl;
437   }
438  }
439  else
440  {
441   cout << "*AliJet::SetTrackCopy* Storage already contained tracks."
442        << "  ==> TrackCopy mode not changed." << endl; 
443  }
444 }
445 ///////////////////////////////////////////////////////////////////////////
446 Int_t AliJet::GetTrackCopy()
447 {
448 // Provide value of the TrackCopy mode.
449 // 0 ==> No private copies are made; pointers of original tracks are stored.
450 // 1 ==> Private copies of the tracks are made and these pointers are stored.
451  return fTrackCopy;
452 }
453 ///////////////////////////////////////////////////////////////////////////