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