]> git.uio.no Git - u/mrichter/AliRoot.git/blob - RALICE/AliJet.cxx
08-mar-2003 NvE Compiler option /GR introduced for MSVC++ in mklibs.bat to explicitly...
[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() : TObject(),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 }
115 ///////////////////////////////////////////////////////////////////////////
116 AliJet::AliJet(Int_t n) : TObject(),Ali4Vector()
117 {
118 // Create a jet to hold initially a maximum of n tracks
119 // All variables initialised to 0
120  Init();
121  Reset();
122  if (n > 0)
123  {
124   SetNtinit(n);
125  }
126  else
127  {
128   cout << endl;
129   cout << " *AliJet* Initial max. number of tracks entered : " << n << endl;
130   cout << " This is invalid. Default initial maximum will be used." << endl;
131   cout << endl;
132   SetNtinit();
133  }
134 }
135 ///////////////////////////////////////////////////////////////////////////
136 AliJet::~AliJet()
137 {
138 // Default destructor
139  if (fTracks)
140  {
141   delete fTracks;
142   fTracks=0;
143  }
144 }
145 ///////////////////////////////////////////////////////////////////////////
146 void AliJet::SetOwner(Bool_t own)
147 {
148 // Set ownership of all added objects. 
149 // The default parameter is own=kTRUE.
150 //
151 // Invokation of this memberfunction also sets all the copy modes
152 // (e.g. TrackCopy & co.) according to the value of own.
153 //
154 // This function (with own=kTRUE) is particularly useful when reading data
155 // from a tree/file, since Reset() will then actually remove all the
156 // added objects from memory irrespective of the copy mode settings
157 // during the tree/file creation process. In this way it provides a nice way
158 // of preventing possible memory leaks in the reading/analysis process.
159 //
160 // In addition this memberfunction can also be used as a shortcut to set all
161 // copy modes in one go during a tree/file creation process.
162 // However, in this case the user has to take care to only set/change the
163 // ownership (and copy mode) for empty objects (e.g. newly created objects
164 // or after invokation of the Reset() memberfunction) otherwise it will
165 // very likely result in inconsistent destructor behaviour.
166
167  Int_t mode=1;
168  if (!own) mode=0;
169  if (fTracks) fTracks->SetOwner(own);
170  fTrackCopy=mode;
171 }
172 ///////////////////////////////////////////////////////////////////////////
173 AliJet::AliJet(AliJet& j) : TObject(j),Ali4Vector(j)
174 {
175 // Copy constructor
176  fNtinit=j.fNtinit;
177  fNtmax=j.fNtmax;
178  fQ=j.fQ;
179  fNtrk=j.fNtrk;
180  fTrackCopy=j.fTrackCopy;
181  fUserId=j.fUserId;
182
183  fTracks=0;
184  if (fNtrk)
185  {
186   fTracks=new TObjArray(fNtmax);
187   if (fTrackCopy) fTracks->SetOwner();
188  }
189
190  for (Int_t i=1; i<=fNtrk; i++)
191  {
192   AliTrack* tx=j.GetTrack(i);
193   if (fTrackCopy)
194   {
195    fTracks->Add(new AliTrack(*tx));
196   }
197   else
198   {
199    fTracks->Add(tx);
200   }
201  } 
202 }
203 ///////////////////////////////////////////////////////////////////////////
204 void AliJet::SetNtinit(Int_t n)
205 {
206 // Set the initial maximum number of tracks for this jet
207  fNtinit=n;
208  fNtmax=n;
209  if (fTracks)
210  {
211   delete fTracks;
212   fTracks=0;
213  }
214 }
215 ///////////////////////////////////////////////////////////////////////////
216 void AliJet::Reset()
217 {
218 // Reset all variables to 0
219 // The max. number of tracks is set to the initial value again
220  fNtrk=0;
221  fQ=0;
222  fUserId=0;
223  Double_t a[4]={0,0,0,0};
224  SetVector(a,"sph");
225  if (fNtinit > 0) SetNtinit(fNtinit);
226 }
227 ///////////////////////////////////////////////////////////////////////////
228 void AliJet::AddTrack(AliTrack& t,Int_t copy)
229 {
230 // Add a track to the jet.
231 // Note : The optional parameter "copy" is for internal use only.
232 // In case the maximum number of tracks has been reached
233 // space will be extended to hold an additional amount of tracks as
234 // was initially reserved.
235  if (!fTracks)
236  {
237   fTracks=new TObjArray(fNtmax);
238   if (fTrackCopy) fTracks->SetOwner();
239  }
240  if (fNtrk == fNtmax) // Check if maximum track number is reached
241  {
242   fNtmax+=fNtinit;
243   fTracks->Expand(fNtmax);
244  }
245  
246  // Add the track to this jet
247  fNtrk++;
248  if (fTrackCopy && copy)
249  {
250   fTracks->Add(new AliTrack(t));
251  }
252  else
253  {
254   fTracks->Add(&t);
255  }
256
257  (*this)+=(Ali4Vector&)t;
258  fQ+=t.GetCharge();
259
260 }
261 ///////////////////////////////////////////////////////////////////////////
262 void AliJet::Data(TString f)
263 {
264 // Provide jet information within the coordinate frame f
265  cout << " *AliJet::Data* Id : " << fUserId << " Invmass : " << GetInvmass() << " Charge : " << fQ
266       << " Momentum : " << GetMomentum() << " Ntracks : " << fNtrk << endl;
267
268  Ali4Vector::Data(f); 
269
270 ///////////////////////////////////////////////////////////////////////////
271 void AliJet::List(TString f)
272 {
273 // Provide jet and primary track information within the coordinate frame f
274
275  Data(f); // Information of the current jet
276
277  // The tracks of this jet
278  AliTrack* t; 
279  for (Int_t it=1; it<=fNtrk; it++)
280  {
281   t=GetTrack(it);
282   if (t)
283   {
284    cout << "  ---Track no. " << it << endl;
285    cout << " ";
286    t->Data(f); 
287   }
288   else
289   {
290    cout << " *AliJet::List* Error : No track present." << endl; 
291   }
292  }
293
294 ///////////////////////////////////////////////////////////////////////////
295 void AliJet::ListAll(TString f)
296 {
297 // Provide jet and prim.+sec. track information within the coordinate frame f
298
299  Data(f); // Information of the current jet
300
301  // The tracks of this jet
302  AliTrack* t; 
303  for (Int_t it=1; it<=fNtrk; it++)
304  {
305   t=GetTrack(it);
306   if (t)
307   {
308    cout << "  ---Track no. " << it << endl;
309    cout << " ";
310    t->ListAll(f); 
311   }
312   else
313   {
314    cout << " *AliJet::List* Error : No track present." << endl; 
315   }
316  }
317
318 ///////////////////////////////////////////////////////////////////////////
319 Int_t AliJet::GetNtracks()
320 {
321 // Return the current number of tracks of this jet
322  return fNtrk;
323 }
324 ///////////////////////////////////////////////////////////////////////////
325 Double_t AliJet::GetEnergy()
326 {
327 // Return the total energy of the jet
328  return GetScalar();
329 }
330 ///////////////////////////////////////////////////////////////////////////
331 Double_t AliJet::GetMomentum()
332 {
333 // Return the value of the total jet 3-momentum
334 // The error can be obtained by invoking GetResultError() after
335 // invokation of GetMomentum().
336  Double_t norm=fV.GetNorm();
337  fDresult=fV.GetResultError();
338  return norm;
339 }
340 ///////////////////////////////////////////////////////////////////////////
341 Ali3Vector AliJet::Get3Momentum()
342 {
343 // Return the the total jet 3-momentum
344  Ali3Vector p=Get3Vector();
345  return p;
346 }
347 ///////////////////////////////////////////////////////////////////////////
348 Double_t AliJet::GetInvmass()
349 {
350 // Return the invariant mass of the jet
351  Double_t m2=Dot(*this);
352  if (m2>0)
353  {
354   return sqrt(m2);
355  }
356  else
357  {
358   return 0;
359  }
360 }
361 ///////////////////////////////////////////////////////////////////////////
362 Float_t AliJet::GetCharge()
363 {
364 // Return the total charge of the jet
365  return fQ;
366 }
367 ///////////////////////////////////////////////////////////////////////////
368 AliTrack* AliJet::GetTrack(Int_t i)
369 {
370 // Return the i-th track of this jet
371  if (!fTracks)
372  {
373   cout << " *AliJet*::GetTrack* No tracks present." << endl;
374   return 0;
375  }
376  else
377  {
378   if (i<=0 || i>fNtrk)
379   {
380    cout << " *AliJet*::GetTrack* Invalid argument i : " << i
381         << " Ntrk = " << fNtrk << endl;
382    return 0;
383   }
384   else
385   {
386    return (AliTrack*)fTracks->At(i-1);
387   }
388  }
389 }
390 ///////////////////////////////////////////////////////////////////////////
391 AliTrack* AliJet::GetIdTrack(Int_t id)
392 {
393 // Return the track with user identifier "id" of this jet
394  AliTrack* tx=0;
395  AliTrack* t=0;
396  if (!fTracks)
397  {
398   cout << " *AliJet*::GetIdTrack* No tracks present." << endl;
399   return 0;
400  }
401  else
402  {
403   for (Int_t i=0; i<fNtrk; i++)
404   {
405    tx=(AliTrack*)fTracks->At(i);
406    if (id == tx->GetId()) t=tx;
407   }
408   return t;
409  }
410 }
411 ///////////////////////////////////////////////////////////////////////////
412 Double_t AliJet::GetPt()
413 {
414 // Provide trans. momentum value w.r.t. z-axis.
415 // The error on the value can be obtained by GetResultError()
416 // after invokation of GetPt().
417  Ali3Vector v;
418  v=GetVecTrans();
419  Double_t norm=v.GetNorm();
420  fDresult=v.GetResultError();
421
422  return norm;
423 }
424 ///////////////////////////////////////////////////////////////////////////
425 Double_t AliJet::GetPl()
426 {
427 // Provide long. momentum value w.r.t. z-axis.
428 // Note : the returned value can also be negative.
429 // The error on the value can be obtained by GetResultError()
430 // after invokation of GetPl().
431  Ali3Vector v;
432  v=GetVecLong();
433
434  Double_t pl=v.GetNorm();
435  fDresult=v.GetResultError();
436
437  Double_t a[3];
438  v.GetVector(a,"sph");
439  if (cos(a[1])<0) pl=-pl;
440
441  return pl;
442 }
443 ///////////////////////////////////////////////////////////////////////////
444 Double_t AliJet::GetEt()
445 {
446 // Provide trans. energy value w.r.t. z-axis.
447 // The error on the value can be obtained by GetResultError()
448 // after invokation of GetEt().
449  Double_t et=GetScaTrans();
450
451  return et;
452 }
453 ///////////////////////////////////////////////////////////////////////////
454 Double_t AliJet::GetEl()
455 {
456 // Provide long. energy value w.r.t. z-axis.
457 // Note : the returned value can also be negative.
458 // The error on the value can be obtained by GetResultError()
459 // after invokation of GetEl().
460  Double_t el=GetScaLong();
461
462  return el;
463 }
464 ///////////////////////////////////////////////////////////////////////////
465 Double_t AliJet::GetMt()
466 {
467 // Provide transverse mass value w.r.t. z-axis.
468 // The error on the value can be obtained by GetResultError()
469 // after invokation of GetMt().
470  Double_t pt=GetPt();
471  Double_t dpt=GetResultError();
472  Double_t m=GetInvmass();
473  Double_t dm=GetResultError();
474
475  Double_t mt=sqrt(pt*pt+m*m);
476  Double_t dmt2=0;
477  if (mt) dmt2=(pow((pt*dpt),2)+pow((m*dm),2))/(mt*mt);
478
479  fDresult=sqrt(dmt2);
480  return mt;
481 }
482 ///////////////////////////////////////////////////////////////////////////
483 Double_t AliJet::GetRapidity()
484 {
485 // Provide rapidity value w.r.t. z-axis.
486 // The error on the value can be obtained by GetResultError()
487 // after invokation of GetRapidity().
488 // Note : Also GetPseudoRapidity() is available since this class is
489 //        derived from Ali4Vector.
490  Double_t e=GetEnergy();
491  Double_t de=GetResultError();
492  Double_t pl=GetPl();
493  Double_t dpl=GetResultError();
494  Double_t sum=e+pl;
495  Double_t dif=e-pl;
496
497  Double_t y=9999,dy2=0;
498  if (sum && dif) y=0.5*log(sum/dif);
499
500  if (sum*dif) dy2=(1./(sum*dif))*(pow((pl*de),2)+pow((e*dpl),2));
501
502  fDresult=sqrt(dy2);
503  return y;
504 }
505 ///////////////////////////////////////////////////////////////////////////
506 void AliJet::SetTrackCopy(Int_t j)
507 {
508 // (De)activate the creation of private copies of the added tracks.
509 // j=0 ==> No private copies are made; pointers of original tracks are stored.
510 // j=1 ==> Private copies of the tracks are made and these pointers are stored.
511 //
512 // Note : Once the storage contains pointer(s) to AliTrack(s) one cannot
513 //        change the TrackCopy mode anymore.
514 //        To change the TrackCopy mode for an existing AliJet containing
515 //        tracks one first has to invoke Reset().
516  if (!fTracks)
517  {
518   if (j==0 || j==1)
519   {
520    fTrackCopy=j;
521   }
522   else
523   {
524    cout << "*AliJet::SetTrackCopy* Invalid argument : " << j << endl;
525   }
526  }
527  else
528  {
529   cout << "*AliJet::SetTrackCopy* Storage already contained tracks."
530        << "  ==> TrackCopy mode not changed." << endl; 
531  }
532 }
533 ///////////////////////////////////////////////////////////////////////////
534 Int_t AliJet::GetTrackCopy()
535 {
536 // Provide value of the TrackCopy mode.
537 // 0 ==> No private copies are made; pointers of original tracks are stored.
538 // 1 ==> Private copies of the tracks are made and these pointers are stored.
539  return fTrackCopy;
540 }
541 ///////////////////////////////////////////////////////////////////////////
542 void AliJet::SetId(Int_t id)
543 {
544 // Set a user defined identifier for this jet.
545  fUserId=id;
546 }
547 ///////////////////////////////////////////////////////////////////////////
548 Int_t AliJet::GetId()
549 {
550 // Provide the user defined identifier of this jet.
551  return fUserId;
552 }
553 ///////////////////////////////////////////////////////////////////////////