]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - RALICE/AliJet.cxx
Replacing fabs by TMath::Abs
[u/mrichter/AliRoot.git] / RALICE / AliJet.cxx
index ae492ff4c675005c70a29f16d813f48fdbf8932c..9d8c8efffa9a66b28bc14463d3235b201d23d7c7 100644 (file)
@@ -45,6 +45,8 @@
 //    creating only one AliTrack instance in the main programme and using the
 //    AliTrack::Reset() and AliTrack parameter setting memberfunctions.
 //
+// See also the documentation provided for the memberfunction SetOwner(). 
+//
 // Coding example to make 2 jets j1 and j2.
 // ----------------------------------------
 // j1 contains the AliTracks t1 and t2
@@ -70,8 +72,8 @@
 //  tx->Reset();
 // }
 //
-// j1.Info();
-// j2.Info("sph");
+// j1.Data();
+// j2.Data("sph");
 //
 // Float_t e1=j1.GetEnergy();
 // Float_t pnorm=j1->GetMomentum();
 ///////////////////////////////////////////////////////////////////////////
 
 #include "AliJet.h"
+#include "Riostream.h"
  
 ClassImp(AliJet) // Class implementation to enable ROOT I/O
  
-AliJet::AliJet()
+AliJet::AliJet() : TObject(),Ali4Vector()
 {
 // Default constructor
 // All variables initialised to 0
 // Initial maximum number of tracks is set to the default value
- fTracks=0;
- fNtinit=0;
- fTrackCopy=0;
+ Init();
  Reset();
  SetNtinit();
 }
 ///////////////////////////////////////////////////////////////////////////
-AliJet::AliJet(Int_t n)
+void AliJet::Init()
 {
-// Create a jet to hold initially a maximum of n tracks
-// All variables initialised to 0
+// Initialisation of pointers etc...
  fTracks=0;
  fNtinit=0;
  fTrackCopy=0;
+}
+///////////////////////////////////////////////////////////////////////////
+AliJet::AliJet(Int_t n) : TObject(),Ali4Vector()
+{
+// Create a jet to hold initially a maximum of n tracks
+// All variables initialised to 0
+ Init();
  Reset();
  if (n > 0)
  {
@@ -131,12 +138,69 @@ AliJet::~AliJet()
 // Default destructor
  if (fTracks)
  {
-  if (fTrackCopy) fTracks->Delete();
   delete fTracks;
   fTracks=0;
  }
 }
 ///////////////////////////////////////////////////////////////////////////
+void AliJet::SetOwner(Bool_t own)
+{
+// Set ownership of all added objects. 
+// The default parameter is own=kTRUE.
+//
+// Invokation of this memberfunction also sets all the copy modes
+// (e.g. TrackCopy & co.) according to the value of own.
+//
+// This function (with own=kTRUE) is particularly useful when reading data
+// from a tree/file, since Reset() will then actually remove all the
+// added objects from memory irrespective of the copy mode settings
+// during the tree/file creation process. In this way it provides a nice way
+// of preventing possible memory leaks in the reading/analysis process.
+//
+// In addition this memberfunction can also be used as a shortcut to set all
+// copy modes in one go during a tree/file creation process.
+// However, in this case the user has to take care to only set/change the
+// ownership (and copy mode) for empty objects (e.g. newly created objects
+// or after invokation of the Reset() memberfunction) otherwise it will
+// very likely result in inconsistent destructor behaviour.
+
+ Int_t mode=1;
+ if (!own) mode=0;
+ if (fTracks) fTracks->SetOwner(own);
+ fTrackCopy=mode;
+}
+///////////////////////////////////////////////////////////////////////////
+AliJet::AliJet(AliJet& j) : TObject(j),Ali4Vector(j)
+{
+// Copy constructor
+ fNtinit=j.fNtinit;
+ fNtmax=j.fNtmax;
+ fQ=j.fQ;
+ fNtrk=j.fNtrk;
+ fTrackCopy=j.fTrackCopy;
+ fUserId=j.fUserId;
+
+ fTracks=0;
+ if (fNtrk)
+ {
+  fTracks=new TObjArray(fNtmax);
+  if (fTrackCopy) fTracks->SetOwner();
+ }
+
+ for (Int_t i=1; i<=fNtrk; i++)
+ {
+  AliTrack* tx=j.GetTrack(i);
+  if (fTrackCopy)
+  {
+   fTracks->Add(new AliTrack(*tx));
+  }
+  else
+  {
+   fTracks->Add(tx);
+  }
+ } 
+}
+///////////////////////////////////////////////////////////////////////////
 void AliJet::SetNtinit(Int_t n)
 {
 // Set the initial maximum number of tracks for this jet
@@ -144,7 +208,6 @@ void AliJet::SetNtinit(Int_t n)
  fNtmax=n;
  if (fTracks)
  {
-  if (fTrackCopy) fTracks->Delete();
   delete fTracks;
   fTracks=0;
  }
@@ -165,12 +228,29 @@ void AliJet::Reset()
 void AliJet::AddTrack(AliTrack& t)
 {
 // Add a track to the jet.
-// Note : In case TrackCopy is set, the originally entered track
-//        will be automatically reset.
 // In case the maximum number of tracks has been reached
 // space will be extended to hold an additional amount of tracks as
 // was initially reserved.
- if (!fTracks) fTracks=new TObjArray(fNtmax);
+// See SetTrackCopy() to tailor the functionality of the stored structures.
+ AddTrack(t,1);
+}
+///////////////////////////////////////////////////////////////////////////
+void AliJet::AddTrack(AliTrack& t,Int_t copy)
+{
+// Internal memberfunction to actually add a track to the jet.
+// In case the maximum number of tracks has been reached
+// space will be extended to hold an additional amount of tracks as
+// was initially reserved.
+//
+// If copy=0 NO copy of the track will be made, irrespective of the setting
+// of the TrackCopy flag.
+// This allows a proper treatment of automatically generated connecting
+// tracks between vertices.
+ if (!fTracks)
+ {
+  fTracks=new TObjArray(fNtmax);
+  if (fTrackCopy) fTracks->SetOwner();
+ }
  if (fNtrk == fNtmax) // Check if maximum track number is reached
  {
   fNtmax+=fNtinit;
@@ -179,9 +259,9 @@ void AliJet::AddTrack(AliTrack& t)
  
  // Add the track to this jet
  fNtrk++;
- if (fTrackCopy)
+ if (fTrackCopy && copy)
  {
-  fTracks->Add(t.Clone());
+  fTracks->Add(new AliTrack(t));
  }
  else
  {
@@ -193,20 +273,20 @@ void AliJet::AddTrack(AliTrack& t)
 
 }
 ///////////////////////////////////////////////////////////////////////////
-void AliJet::Info(TString f)
+void AliJet::Data(TString f)
 {
 // Provide jet information within the coordinate frame f
- cout << " *AliJet::Info* Id : " << fUserId << " Invmass : " << GetInvmass() << " Charge : " << fQ
+ cout << " *AliJet::Data* Id : " << fUserId << " Invmass : " << GetInvmass() << " Charge : " << fQ
       << " Momentum : " << GetMomentum() << " Ntracks : " << fNtrk << endl;
- cout << " ";
- Ali4Vector::Info(f); 
+
+ Ali4Vector::Data(f); 
 } 
 ///////////////////////////////////////////////////////////////////////////
 void AliJet::List(TString f)
 {
 // Provide jet and primary track information within the coordinate frame f
 
Info(f); // Information of the current jet
Data(f); // Information of the current jet
 
  // The tracks of this jet
  AliTrack* t; 
@@ -217,7 +297,7 @@ void AliJet::List(TString f)
   {
    cout << "  ---Track no. " << it << endl;
    cout << " ";
-   t->Info(f); 
+   t->Data(f); 
   }
   else
   {
@@ -230,7 +310,7 @@ void AliJet::ListAll(TString f)
 {
 // Provide jet and prim.+sec. track information within the coordinate frame f
 
Info(f); // Information of the current jet
Data(f); // Information of the current jet
 
  // The tracks of this jet
  AliTrack* t;