///////////////////////////////////////////////////////////////////////////
#include "AliJet.h"
+#include "Riostream.h"
ClassImp(AliJet) // Class implementation to enable ROOT I/O
-AliJet::AliJet()
+AliJet::AliJet() : TNamed(),Ali4Vector()
{
// Default constructor
// All variables initialised to 0
fTracks=0;
fNtinit=0;
fTrackCopy=0;
+ fSelected=0;
}
///////////////////////////////////////////////////////////////////////////
-AliJet::AliJet(Int_t n)
+AliJet::AliJet(Int_t n) : TNamed(),Ali4Vector()
{
// Create a jet to hold initially a maximum of n tracks
// All variables initialised to 0
delete fTracks;
fTracks=0;
}
+ if (fSelected)
+ {
+ delete fSelected;
+ fSelected=0;
+ }
}
///////////////////////////////////////////////////////////////////////////
void AliJet::SetOwner(Bool_t own)
fTrackCopy=mode;
}
///////////////////////////////////////////////////////////////////////////
-AliJet::AliJet(AliJet& j)
+AliJet::AliJet(const AliJet& j) : TNamed(j),Ali4Vector(j)
{
// Copy constructor
- Init();
- Reset();
- SetNtinit();
- SetTrackCopy(j.GetTrackCopy());
- SetId(j.GetId());
+ fNtinit=j.fNtinit;
+ fNtmax=j.fNtmax;
+ fQ=j.fQ;
+ fNtrk=j.fNtrk;
+ fTrackCopy=j.fTrackCopy;
+ fUserId=j.fUserId;
- AliTrack* tx=0;
- for (Int_t i=1; i<=j.GetNtracks(); i++)
+ fSelected=0;
+
+ fTracks=0;
+ if (fNtrk)
+ {
+ fTracks=new TObjArray(fNtmax);
+ if (fTrackCopy) fTracks->SetOwner();
+ }
+
+ for (Int_t i=1; i<=fNtrk; i++)
{
- tx=j.GetTrack(i);
- if (tx) AddTrack(tx);
+ AliTrack* tx=j.GetTrack(i);
+ if (fTrackCopy)
+ {
+ fTracks->Add(tx->Clone());
+ }
+ else
+ {
+ fTracks->Add(tx);
+ }
}
}
///////////////////////////////////////////////////////////////////////////
// Set the initial maximum number of tracks for this jet
fNtinit=n;
fNtmax=n;
+
if (fTracks)
{
delete fTracks;
if (fNtinit > 0) SetNtinit(fNtinit);
}
///////////////////////////////////////////////////////////////////////////
-void AliJet::AddTrack(AliTrack& t,Int_t copy)
+void AliJet::AddTrack(AliTrack& t)
{
// Add a track to the jet.
-// 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.
+// See SetTrackCopy() to tailor the functionality of the stored structures.
+//
+// Note :
+// In case a private copy is made, this is performed via the Clone() memberfunction.
+// All AliTrack and derived classes have the default TObject::Clone() memberfunction.
+// However, derived classes generally contain an internal data structure which may
+// include pointers to other objects. Therefore it is recommended to provide
+// for all derived classes a specific copy constructor and override the default Clone()
+// memberfunction using this copy constructor.
+// An example for this may be seen from AliTrack.
+
+ 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.
+//
+// Note :
+// In case a private copy is made, this is performed via the Clone() memberfunction.
+
if (!fTracks)
{
fTracks=new TObjArray(fNtmax);
fNtrk++;
if (fTrackCopy && copy)
{
- fTracks->Add(new AliTrack(t));
+ fTracks->Add(t.Clone());
}
else
{
void AliJet::Data(TString f)
{
// Provide jet information within the coordinate frame f
- cout << " *AliJet::Data* Id : " << fUserId << " Invmass : " << GetInvmass() << " Charge : " << fQ
- << " Momentum : " << GetMomentum() << " Ntracks : " << fNtrk << endl;
- cout << " ";
+ const char* name=GetName();
+ const char* title=GetTitle();
+
+ cout << " *AliJet::Data*";
+ if (strlen(name)) cout << " Name : " << GetName();
+ if (strlen(title)) cout << " Title : " << GetTitle();
+ cout << endl;
+ cout << " Id : " << fUserId << " Invmass : " << GetInvmass() << " Charge : " << fQ
+ << " Momentum : " << GetMomentum() << endl;
+
+ ShowTracks(0);
+
Ali4Vector::Data(f);
}
///////////////////////////////////////////////////////////////////////////
}
}
///////////////////////////////////////////////////////////////////////////
-Int_t AliJet::GetNtracks()
+Int_t AliJet::GetNtracks(Int_t idmode,Int_t chmode,Int_t pcode)
{
-// Return the current number of tracks of this jet
- return fNtrk;
+// Provide the number of user selected tracks in this jet based on the
+// idmode, chmode and pcode selections as specified by the user.
+// For specification of the selection parameters see GetTracks().
+// The default parameters correspond to no selection, which implies
+// that invokation of GetNtracks() just returns the total number of
+// tracks registered in this jet.
+//
+// Note : In case certain selections are specified, this function
+// invokes GetTracks(idmode,chmode,pcode) to determine the
+// number of tracks corresponding to the selections.
+// When the jet contains a large number of tracks, invokation
+// of GetTracks(idmode,chmode,pcode) and subsequently invoking
+// GetEntries() for the resulting TObjArray* might be slightly
+// faster.
+
+ Int_t n=0;
+ if (idmode==0 && chmode==2 && pcode==0)
+ {
+ return fNtrk;
+ }
+ else
+ {
+ TObjArray* arr=GetTracks(idmode,chmode,pcode);
+ n=arr->GetEntries();
+ return n;
+ }
}
///////////////////////////////////////////////////////////////////////////
Double_t AliJet::GetEnergy()
return norm;
}
///////////////////////////////////////////////////////////////////////////
-Ali3Vector AliJet::Get3Momentum()
+Ali3Vector AliJet::Get3Momentum() const
{
// Return the the total jet 3-momentum
Ali3Vector p=Get3Vector();
}
}
///////////////////////////////////////////////////////////////////////////
-Float_t AliJet::GetCharge()
+Float_t AliJet::GetCharge() const
{
// Return the total charge of the jet
return fQ;
}
///////////////////////////////////////////////////////////////////////////
-AliTrack* AliJet::GetTrack(Int_t i)
+AliTrack* AliJet::GetTrack(Int_t i) const
{
// Return the i-th track of this jet
- if (!fTracks)
+
+ if (!fTracks) return 0;
+
+ if (i<=0 || i>fNtrk)
{
- cout << " *AliJet*::GetTrack* No tracks present." << endl;
+ cout << " *AliJet*::GetTrack* Invalid argument i : " << i
+ << " Ntrk = " << fNtrk << endl;
return 0;
}
else
{
- if (i<=0 || i>fNtrk)
- {
- cout << " *AliJet*::GetTrack* Invalid argument i : " << i
- << " Ntrk = " << fNtrk << endl;
- return 0;
- }
- else
- {
- return (AliTrack*)fTracks->At(i-1);
- }
+ return (AliTrack*)fTracks->At(i-1);
}
}
///////////////////////////////////////////////////////////////////////////
-AliTrack* AliJet::GetIdTrack(Int_t id)
+AliTrack* AliJet::GetIdTrack(Int_t id) const
{
// Return the track with user identifier "id" of this jet
+ if (!fTracks) return 0;
+
AliTrack* tx=0;
- AliTrack* t=0;
- if (!fTracks)
+ for (Int_t i=0; i<fNtrk; i++)
{
- cout << " *AliJet*::GetIdTrack* No tracks present." << endl;
- return 0;
+ tx=(AliTrack*)fTracks->At(i);
+ if (id == tx->GetId()) return tx;
+ }
+ return 0; // No matching id found
+}
+///////////////////////////////////////////////////////////////////////////
+TObjArray* AliJet::GetTracks(Int_t idmode,Int_t chmode,Int_t pcode)
+{
+// Provide references to user selected tracks based on the idmode, chmode
+// and pcode selections as specified by the user.
+//
+// The following selection combinations are available :
+// ----------------------------------------------------
+// idmode = -1 ==> Select tracks with negative user identifier "id"
+// 0 ==> No selection on user identifier
+// 1 ==> Select tracks with positive user identifier "id"
+//
+// chmode = -1 ==> Select tracks with negative charge
+// 0 ==> Select neutral tracks
+// 1 ==> Select tracks with positive charge
+// 2 ==> No selection on charge
+// 3 ==> Select all charged tracks
+//
+// pcode = 0 ==> No selection on particle code
+// X ==> Select tracks with particle code +X or -X
+// This allows selection of both particles and anti-particles
+// in case of PDG particle codes.
+// Selection of either particles or anti-particles can be
+// obtained in combination with the "chmode" selector.
+//
+// Examples :
+// ----------
+// idmode=-1 chmode=0 pcode=0 : Selection of all neutral tracks with negative id.
+// idmode=0 chmode=2 pcode=211 : Selection of all charged pions (PDG convention).
+// idmode=0 chmode=1 pcode=321 : Selection of all positive kaons (PDG convention).
+//
+// The default values are idmode=0 chmode=2 pcode=0 (i.e. no selections applied).
+//
+// Notes :
+// -------
+// 1) In case the user has labeled simulated tracks with negative id and
+// reconstructed tracks with positive id, this memberfunction provides
+// easy access to either all simulated or reconstructed tracks.
+// 2) Subsequent invokations of this memberfunction with e.g. chmode=-1 and chmode=1
+// provides a convenient way to investigate particle pairs with opposite charge
+// (e.g. for invariant mass analysis).
+
+ if (fSelected)
+ {
+ fSelected->Clear();
}
else
{
- for (Int_t i=0; i<fNtrk; i++)
+ fSelected=new TObjArray();
+ }
+
+ if (!fTracks) return fSelected;
+
+ AliTrack* tx=0;
+ Int_t code=0;
+ Int_t id=0;
+ Float_t q=0;
+ for (Int_t i=0; i<fNtrk; i++)
+ {
+ tx=(AliTrack*)fTracks->At(i);
+ if (!tx) continue;
+
+ code=tx->GetParticleCode();
+ if (pcode && abs(pcode)!=abs(code)) continue;
+
+ id=tx->GetId();
+ if (idmode==-1 && id>=0) continue;
+ if (idmode==1 && id<=0) continue;
+
+ q=tx->GetCharge();
+ if (chmode==-1 && q>=0) continue;
+ if (chmode==0 && fabs(q)>1e-10) continue;
+ if (chmode==1 && q<=0) continue;
+ if (chmode==3 && fabs(q)<1e-10) continue;
+
+ fSelected->Add(tx);
+ }
+
+ return fSelected;
+}
+///////////////////////////////////////////////////////////////////////////
+void AliJet::ShowTracks(Int_t mode)
+{
+// Provide an overview of the available tracks.
+// The argument mode determines the amount of information as follows :
+// mode = 0 ==> Only printout of the number of tracks
+// 1 ==> Provide a listing with 1 line of info for each track
+//
+// The default is mode=1.
+//
+ Int_t ntk=GetNtracks();
+ if (ntk)
+ {
+ if (!mode)
{
- tx=(AliTrack*)fTracks->At(i);
- if (id == tx->GetId()) t=tx;
+ cout << " There are " << ntk << " tracks available." << endl;
}
- return t;
+ else
+ {
+ cout << " The following " << ntk << " tracks are available :" << endl;
+ for (Int_t i=1; i<=ntk; i++)
+ {
+ AliTrack* tx=GetTrack(i);
+ if (tx)
+ {
+ const char* name=tx->GetName();
+ const char* title=tx->GetTitle();
+ cout << " Track : " << i;
+ cout << " Id : " << tx->GetId();
+ cout << " Q : " << tx->GetCharge() << " m : " << tx->GetMass() << " p : " << tx->GetMomentum();
+ if (strlen(name)) cout << " Name : " << name;
+ if (strlen(title)) cout << " Title : " << title;
+ cout << endl;
+ }
+ }
+ }
+ }
+ else
+ {
+ cout << " No tracks are present." << endl;
}
}
///////////////////////////////////////////////////////////////////////////
}
}
///////////////////////////////////////////////////////////////////////////
-Int_t AliJet::GetTrackCopy()
+Int_t AliJet::GetTrackCopy() const
{
// Provide value of the TrackCopy mode.
// 0 ==> No private copies are made; pointers of original tracks are stored.
fUserId=id;
}
///////////////////////////////////////////////////////////////////////////
-Int_t AliJet::GetId()
+Int_t AliJet::GetId() const
{
// Provide the user defined identifier of this jet.
return fUserId;
}
///////////////////////////////////////////////////////////////////////////
+TObject* AliJet::Clone(const char* name) const
+{
+// Make a deep copy of the current object and provide the pointer to the copy.
+// This memberfunction enables automatic creation of new objects of the
+// correct type depending on the object type, a feature which may be very useful
+// for containers when adding objects in case the container owns the objects.
+// This feature allows e.g. AliVertex to store either AliJet objects or
+// objects derived from AliJet via the AddJet memberfunction, provided
+// these derived classes also have a proper Clone memberfunction.
+
+ AliJet* jet=new AliJet(*this);
+ if (name)
+ {
+ if (strlen(name)) jet->SetName(name);
+ }
+ return jet;
+}
+///////////////////////////////////////////////////////////////////////////