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