]> git.uio.no Git - u/mrichter/AliRoot.git/blame - RALICE/AliJet.cxx
Minor correction needed on HP
[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.
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//
959fbac5 45// Coding example to make 2 jets j1 and j2.
46// ----------------------------------------
c1f25d1d 47// j1 contains the AliTracks t1 and t2
48// j2 contains 10 different AliTracks via tx
959fbac5 49//
c1f25d1d 50// AliTrack t1,t2;
959fbac5 51// ...
52// ... // code to fill the AliTrack data
53// ...
c1f25d1d 54// AliJet j1();
f531a546 55// j1.AddTrack(t1);
56// j1.AddTrack(t2);
c1f25d1d 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// }
959fbac5 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//
c1f25d1d 80// delete tx;
81//
959fbac5 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
f531a546 85//- Modified: NvE $Date$ UU-SAP Utrecht
959fbac5 86///////////////////////////////////////////////////////////////////////////
87
d88f97cc 88#include "AliJet.h"
89
90ClassImp(AliJet) // Class implementation to enable ROOT I/O
91
92AliJet::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;
c1f25d1d 99 fTrackCopy=0;
d88f97cc 100 Reset();
101 SetNtinit();
102}
103///////////////////////////////////////////////////////////////////////////
104AliJet::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;
c1f25d1d 110 fTrackCopy=0;
d88f97cc 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///////////////////////////////////////////////////////////////////////////
126AliJet::~AliJet()
127{
128// Default destructor
c1f25d1d 129 if (fTracks)
130 {
131 if (fTrackCopy) fTracks->Delete();
132 delete fTracks;
133 fTracks=0;
134 }
d88f97cc 135}
136///////////////////////////////////////////////////////////////////////////
137void AliJet::SetNtinit(Int_t n)
138{
139// Set the initial maximum number of tracks for this jet
140 fNtinit=n;
141 fNtmax=n;
79830a7e 142 if (fTracks)
c1f25d1d 143 {
144 if (fTrackCopy) fTracks->Delete();
145 delete fTracks;
146 fTracks=0;
147 }
d88f97cc 148}
149///////////////////////////////////////////////////////////////////////////
150void 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///////////////////////////////////////////////////////////////////////////
f531a546 161void AliJet::AddTrack(AliTrack& t)
d88f97cc 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
c1f25d1d 167 if (!fTracks) fTracks=new TObjArray(fNtmax);
d88f97cc 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++;
c1f25d1d 176 if (fTrackCopy)
177 {
178 AliTrack* tx=new AliTrack(t);
179 fTracks->Add(tx);
180 }
181 else
182 {
183 fTracks->Add(&t);
184 }
d88f97cc 185 (*this)+=(Ali4Vector&)t;
186 fQ+=t.GetCharge();
187}
188///////////////////////////////////////////////////////////////////////////
189void 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///////////////////////////////////////////////////////////////////////////
198void 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///////////////////////////////////////////////////////////////////////////
222void 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///////////////////////////////////////////////////////////////////////////
246Int_t AliJet::GetNtracks()
247{
248// Return the current number of tracks of this jet
249 return fNtrk;
250}
251///////////////////////////////////////////////////////////////////////////
252Double_t AliJet::GetEnergy()
253{
254// Return the total energy of the jet
255 return GetScalar();
256}
257///////////////////////////////////////////////////////////////////////////
258Double_t AliJet::GetMomentum()
259{
260// Return the value of the total jet 3-momentum
d071d629 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;
d88f97cc 266}
267///////////////////////////////////////////////////////////////////////////
268Ali3Vector AliJet::Get3Momentum()
269{
270// Return the the total jet 3-momentum
271 Ali3Vector p=Get3Vector();
272 return p;
273}
274///////////////////////////////////////////////////////////////////////////
275Double_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///////////////////////////////////////////////////////////////////////////
289Float_t AliJet::GetCharge()
290{
291// Return the total charge of the jet
292 return fQ;
293}
294///////////////////////////////////////////////////////////////////////////
295AliTrack* AliJet::GetTrack(Int_t i)
296{
297// Return the i-th track of this jet
f34f4acb 298 if (!fTracks)
299 {
300 cout << " *AliJet*::GetTrack* No tracks present." << endl;
301 return 0;
302 }
303 else
304 {
305 if (i<=0 || i>fNtrk)
306 {
307 cout << " *AliJet*::GetTrack* Invalid argument i : " << i
308 << " Ntrk = " << fNtrk << endl;
309 return 0;
310 }
311 else
312 {
313 return (AliTrack*)fTracks->At(i-1);
314 }
315 }
d88f97cc 316}
317///////////////////////////////////////////////////////////////////////////
d071d629 318Double_t AliJet::GetPt()
319{
320// Provide trans. momentum value w.r.t. z-axis.
321// The error on the value can be obtained by GetResultError()
322// after invokation of GetPt().
323 Ali3Vector v;
324 v=GetVecTrans();
325 Double_t norm=v.GetNorm();
326 fDresult=v.GetResultError();
327
328 return norm;
329}
330///////////////////////////////////////////////////////////////////////////
331Double_t AliJet::GetPl()
332{
333// Provide long. momentum value w.r.t. z-axis.
8adaf597 334// Note : the returned value can also be negative.
d071d629 335// The error on the value can be obtained by GetResultError()
336// after invokation of GetPl().
337 Ali3Vector v;
338 v=GetVecLong();
8adaf597 339
340 Double_t pl=v.GetNorm();
d071d629 341 fDresult=v.GetResultError();
342
8adaf597 343 Double_t a[3];
344 v.GetVector(a,"sph");
345 if (cos(a[1])<0) pl=-pl;
346
347 return pl;
d071d629 348}
349///////////////////////////////////////////////////////////////////////////
350Double_t AliJet::GetEt()
351{
352// Provide trans. energy value w.r.t. z-axis.
353// The error on the value can be obtained by GetResultError()
354// after invokation of GetEt().
355 Double_t et=GetScaTrans();
356
357 return et;
358}
359///////////////////////////////////////////////////////////////////////////
360Double_t AliJet::GetEl()
361{
362// Provide long. energy value w.r.t. z-axis.
8adaf597 363// Note : the returned value can also be negative.
d071d629 364// The error on the value can be obtained by GetResultError()
365// after invokation of GetEl().
366 Double_t el=GetScaLong();
367
368 return el;
369}
370///////////////////////////////////////////////////////////////////////////
371Double_t AliJet::GetMt()
372{
373// Provide transverse mass value w.r.t. z-axis.
374// The error on the value can be obtained by GetResultError()
375// after invokation of GetMt().
376 Double_t pt=GetPt();
377 Double_t dpt=GetResultError();
378 Double_t m=GetInvmass();
379 Double_t dm=GetResultError();
380
381 Double_t mt=sqrt(pt*pt+m*m);
382 Double_t dmt2=0;
383 if (mt) dmt2=(pow((pt*dpt),2)+pow((m*dm),2))/(mt*mt);
384
385 fDresult=sqrt(dmt2);
386 return mt;
387}
388///////////////////////////////////////////////////////////////////////////
8adaf597 389Double_t AliJet::GetRapidity()
390{
391// Provide rapidity value w.r.t. z-axis.
392// The error on the value can be obtained by GetResultError()
393// after invokation of GetRapidity().
394// Note : Also GetPseudoRapidity() is available since this class is
395// derived from Ali4Vector.
396 Double_t e=GetEnergy();
397 Double_t de=GetResultError();
398 Double_t pl=GetPl();
399 Double_t dpl=GetResultError();
400 Double_t sum=e+pl;
401 Double_t dif=e-pl;
402
403 Double_t y=9999,dy2=0;
404 if (sum && dif) y=0.5*log(sum/dif);
405
406 if (sum*dif) dy2=(1./(sum*dif))*(pow((pl*de),2)+pow((e*dpl),2));
407
408 fDresult=sqrt(dy2);
409 return y;
410}
411///////////////////////////////////////////////////////////////////////////
c1f25d1d 412void AliJet::SetTrackCopy(Int_t j)
413{
414// (De)activate the creation of private copies of the added tracks.
415// j=0 ==> No private copies are made; pointers of original tracks are stored.
416// j=1 ==> Private copies of the tracks are made and these pointers are stored.
417//
418// Note : Once the storage contains pointer(s) to AliTrack(s) one cannot
419// change the TrackCopy mode anymore.
420// To change the TrackCopy mode for an existing AliJet containing
421// tracks one first has to invoke Reset().
422 if (!fTracks)
423 {
424 if (j==0 || j==1)
425 {
426 fTrackCopy=j;
427 }
428 else
429 {
430 cout << "*AliJet::SetTrackCopy* Invalid argument : " << j << endl;
431 }
432 }
433 else
434 {
435 cout << "*AliJet::SetTrackCopy* Storage already contained tracks."
436 << " ==> TrackCopy mode not changed." << endl;
437 }
438}
439///////////////////////////////////////////////////////////////////////////
440Int_t AliJet::GetTrackCopy()
441{
442// Provide value of the TrackCopy mode.
443// 0 ==> No private copies are made; pointers of original tracks are stored.
444// 1 ==> Private copies of the tracks are made and these pointers are stored.
445 return fTrackCopy;
446}
447///////////////////////////////////////////////////////////////////////////