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