]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - RALICE/AliJet.cxx
remove obsolete macro
[u/mrichter/AliRoot.git] / RALICE / AliJet.cxx
index e667584238754d58b3b715e066aa17f28f18a41a..d8bdff3c0d7790633b0b6450cb36e31e2a8dc459 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();
@@ -97,20 +99,24 @@ AliJet::AliJet()
 // Default constructor
 // All variables initialised to 0
 // Initial maximum number of tracks is set to the default value
+ Init();
+ Reset();
+ SetNtinit();
+}
+///////////////////////////////////////////////////////////////////////////
+void AliJet::Init()
+{
+// Initialisation of pointers etc...
  fTracks=0;
  fNtinit=0;
  fTrackCopy=0;
- Reset();
- SetNtinit();
 }
 ///////////////////////////////////////////////////////////////////////////
 AliJet::AliJet(Int_t n)
 {
 // Create a jet to hold initially a maximum of n tracks
 // All variables initialised to 0
- fTracks=0;
- fNtinit=0;
- fTrackCopy=0;
+ Init();
  Reset();
  if (n > 0)
  {
@@ -131,12 +137,55 @@ 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)
+{
+// Copy constructor
+ Init();
+ Reset();
+ SetNtinit();
+ SetTrackCopy(j.GetTrackCopy());
+ SetId(j.GetId());
+
+ AliTrack* tx=0;
+ for (Int_t i=1; i<=j.GetNtracks(); i++)
+ {
+  tx=j.GetTrack(i);
+  if (tx) AddTrack(tx);
+ } 
+}
+///////////////////////////////////////////////////////////////////////////
 void AliJet::SetNtinit(Int_t n)
 {
 // Set the initial maximum number of tracks for this jet
@@ -144,7 +193,6 @@ void AliJet::SetNtinit(Int_t n)
  fNtmax=n;
  if (fTracks)
  {
-  if (fTrackCopy) fTracks->Delete();
   delete fTracks;
   fTracks=0;
  }
@@ -156,20 +204,24 @@ void AliJet::Reset()
 // The max. number of tracks is set to the initial value again
  fNtrk=0;
  fQ=0;
+ fUserId=0;
  Double_t a[4]={0,0,0,0};
  SetVector(a,"sph");
  if (fNtinit > 0) SetNtinit(fNtinit);
 }
 ///////////////////////////////////////////////////////////////////////////
-void AliJet::AddTrack(AliTrack& t)
+void AliJet::AddTrack(AliTrack& t,Int_t copy)
 {
 // Add a track to the jet.
-// Note : In case TrackCopy is set, the originally entered track
-//        will be automatically reset.
+// Note : The optional parameter "copy" is for internal use only.
 // 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);
+ if (!fTracks)
+ {
+  fTracks=new TObjArray(fNtmax);
+  if (fTrackCopy) fTracks->SetOwner();
+ }
  if (fNtrk == fNtmax) // Check if maximum track number is reached
  {
   fNtmax+=fNtinit;
@@ -178,9 +230,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
  {
@@ -192,20 +244,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* 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; 
@@ -216,7 +268,7 @@ void AliJet::List(TString f)
   {
    cout << "  ---Track no. " << it << endl;
    cout << " ";
-   t->Info(f); 
+   t->Data(f); 
   }
   else
   {
@@ -229,7 +281,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; 
@@ -321,6 +373,27 @@ AliTrack* AliJet::GetTrack(Int_t i)
  }
 }
 ///////////////////////////////////////////////////////////////////////////
+AliTrack* AliJet::GetIdTrack(Int_t id)
+{
+// Return the track with user identifier "id" of this jet
+ AliTrack* tx=0;
+ AliTrack* t=0;
+ if (!fTracks)
+ {
+  cout << " *AliJet*::GetIdTrack* No tracks present." << endl;
+  return 0;
+ }
+ else
+ {
+  for (Int_t i=0; i<fNtrk; i++)
+  {
+   tx=(AliTrack*)fTracks->At(i);
+   if (id == tx->GetId()) t=tx;
+  }
+  return t;
+ }
+}
+///////////////////////////////////////////////////////////////////////////
 Double_t AliJet::GetPt()
 {
 // Provide trans. momentum value w.r.t. z-axis.
@@ -451,3 +524,15 @@ Int_t AliJet::GetTrackCopy()
  return fTrackCopy;
 }
 ///////////////////////////////////////////////////////////////////////////
+void AliJet::SetId(Int_t id)
+{
+// Set a user defined identifier for this jet.
+ fUserId=id;
+}
+///////////////////////////////////////////////////////////////////////////
+Int_t AliJet::GetId()
+{
+// Provide the user defined identifier of this jet.
+ return fUserId;
+}
+///////////////////////////////////////////////////////////////////////////