#ifndef ALIMULTIPLICITY_H
#define ALIMULTIPLICITY_H
#include <TBits.h>
#include <TMath.h>
#include "AliVMultiplicity.h"
class AliRefArray;
class AliMultiplicity : public AliVMultiplicity {
public:
AliMultiplicity();
AliMultiplicity(Int_t ntr,Float_t *th, Float_t *ph, Float_t *dth, Float_t *dph, Int_t *labels,
Int_t* labelsL2, Int_t ns, Float_t *ts, Float_t *ps, Int_t *labelss, Short_t nfcL1, Short_t nfcL2, const TBits & fFastOrFiredChips);
AliMultiplicity(Int_t ntr, Int_t ns, Short_t nfcL1, Short_t nfcL2, const TBits & fFastOr);
AliMultiplicity(const AliMultiplicity& m);
AliMultiplicity& operator=(const AliMultiplicity& m);
virtual void Copy(TObject &obj) const;
virtual void Clear(Option_t* opt="");
virtual ~AliMultiplicity();
Bool_t GetMultTrackRefs() const {return TestBit(kMultTrackRefs);}
void SetMultTrackRefs(Bool_t v) {SetBit(kMultTrackRefs,v);}
Bool_t GetScaleDThetaBySin2T() const {return TestBit(kScaleDThtbySin2);}
void SetScaleDThetaBySin2T(Bool_t v) {SetBit(kScaleDThtbySin2,v);}
virtual Int_t GetNumberOfTracklets() const {return fNtracks;}
virtual Double_t GetTheta(Int_t i) const {
if(i>=0 && i<fNtracks) return fTh[i];
Error("GetTheta","Invalid track number %d",i); return -9999.;
}
virtual Double_t GetPhi(Int_t i) const {
if(i>=0 && i<fNtracks) return fPhi[i];
Error("GetPhi","Invalid track number %d",i); return -9999.;
}
virtual Double_t GetDeltaPhi(Int_t i) const {
if(i>=0 && i<fNtracks) return fDeltPhi[i];
Error("GetDeltaPhi","Invalid track number %d",i); return -9999.;
}
virtual Int_t GetLabel(Int_t i, Int_t layer) const;
virtual void SetLabel(Int_t i, Int_t layer, Int_t label);
virtual Double_t* GetTheta() const {return (Double_t*)fTh;}
virtual Double_t* GetPhi() const {return (Double_t*)fPhi;}
virtual Double_t* GetDeltPhi() const {return (Double_t*)fDeltPhi;}
virtual Int_t* GetLabels() const {return (Int_t*)fLabels;}
virtual Int_t* GetLabels2() const {return (Int_t*)fLabelsL2;}
virtual void Print(Option_t *opt="") const;
Double_t GetDeltaTheta(Int_t i) const {
if(fDeltTh && i>=0 && i<fNtracks) return fDeltTh[i];
Error("GetDeltaTheta","DeltaTheta not available in data or Invalid track number %d(max %d)",i, fNtracks); return -9999.;
}
Double_t CalcDist(Int_t it) const;
Float_t GetThetaAll(int icl, int lr) const;
Float_t GetPhiAll(int icl, int lr) const;
Int_t GetLabelAll(int icl, int lr) const;
Int_t GetLabelSingle(Int_t i) const;
Int_t GetLabelSingleLr(Int_t i, Int_t layer) const;
void SetLabelSingle(Int_t i, Int_t label);
Bool_t FreeClustersTracklet(Int_t i, Int_t mode) const;
Bool_t FreeSingleCluster(Int_t i, Int_t mode) const;
Int_t SetNumberOfSingleClustersSPD2(Int_t n) {return fNsingleSPD2 = n;}
Int_t GetNumberOfSingleClusters() const {return fNsingle;}
Int_t GetNumberOfSingleClustersLr(Int_t lr) const;
Bool_t AreSPD2SinglesStored() const {return TestBit(kSPD2Sng);}
void SetSPD2SinglesStored(Bool_t v=kTRUE) {return SetBit(kSPD2Sng,v);}
Double_t GetThetaSingle(Int_t i) const {
if(i>=0 && i<fNsingle) return fThsingle[i];
Error("GetThetaSingle","Invalid cluster number %d",i); return -9999.;
}
Double_t GetThetaSingleLr(Int_t i, Int_t lr) const {
if (lr==1) {
if (!AreSPD2SinglesStored()) {Error("GetThetaSingle","Invalid cluster number %d for lr %d",i,lr); return -9999.;}
else i += GetNumberOfSingleClustersLr(0);
}
if(i>=0 && i<fNsingle) return fThsingle[i];
Error("GetThetaSingle","Invalid cluster number %d",i); return -9999.;
}
Double_t GetPhiSingle(Int_t i) const {
if(i>=0 && i<fNsingle) return fPhisingle[i];
Error("GetPhisingle","Invalid cluster number %d",i); return -9999.;
}
Double_t GetPhiSingleLr(Int_t i, Int_t lr) const {
if (lr==1) {
if (!AreSPD2SinglesStored()) {Error("GetPhiSingle","Invalid cluster number %d for lr %d",i,lr); return -9999.;}
else i += GetNumberOfSingleClustersLr(0);
}
if(i>=0 && i<fNsingle) return fPhisingle[i];
Error("GetPhisingle","Invalid cluster number %d",i); return -9999.;
}
Short_t GetNumberOfFiredChips(Int_t layer) const { return fFiredChips[layer]; }
void SetFiredChips(Int_t layer, Short_t firedChips) { fFiredChips[layer] = firedChips; }
UInt_t GetNumberOfITSClusters(Int_t layer) const { return layer<6 ? fITSClusters[layer] : 0; }
UInt_t GetNumberOfITSClusters(Int_t layMin, Int_t layMax) const ;
void SetITSClusters(Int_t layer, UInt_t clusters) { fITSClusters[layer] = clusters; }
void SetFastOrFiredChips(UInt_t chipKey){fFastOrFiredChips.SetBitNumber(chipKey);}
const TBits & GetFastOrFiredChips() const {return fFastOrFiredChips;}
Bool_t TestFastOrFiredChips(UInt_t chipKey) const {return fFastOrFiredChips.TestBitNumber(chipKey);}
void SetFiredChipMap(TBits & firedChips){fClusterFiredChips = firedChips;}
void SetFiredChipMap(UInt_t chipKey){fClusterFiredChips.SetBitNumber(chipKey);}
const TBits & GetFiredChipMap() const {return fClusterFiredChips;}
Bool_t TestFiredChipMap(UInt_t chipKey) const {return fClusterFiredChips.TestBitNumber(chipKey);}
Bool_t GetTrackletTrackIDs(Int_t i, Int_t mode, Int_t &spd1, Int_t &spd2) const;
Int_t GetTrackletTrackIDsLay(Int_t lr,Int_t i, Int_t mode, UInt_t* refs, UInt_t maxRef) const;
Bool_t GetSingleClusterTrackID(Int_t i, Int_t mode, Int_t &tr) const;
Int_t GetSingleClusterTrackIDs(Int_t i, Int_t mode, UInt_t* refs, UInt_t maxRef) const;
Double_t* GetDeltTheta() const {return (Double_t*)fDeltTh;}
Double_t* GetThetaSingle() const {return (Double_t*)fThsingle;}
Double_t* GetPhiSingle() const {return (Double_t*)fPhisingle;}
Int_t* GetLabelsSingle() const {return (Int_t*)fLabelssingle;}
void AttachTracklet2TrackRefs(AliRefArray* l1t1,AliRefArray* l1t2,AliRefArray* l2t1,AliRefArray* l2t2) {
fTCl2Tracks[0][0] = l1t1; fTCl2Tracks[0][1] = l1t2; fTCl2Tracks[1][0] = l2t1; fTCl2Tracks[1][1] = l2t2;
}
void AttachCluster2TrackRefs(AliRefArray* l1t1,AliRefArray* l1t2) {
fSCl2Tracks[0] = l1t1; fSCl2Tracks[1] = l1t2;
}
void SetTrackletData(Int_t id, const Float_t* tlet, UInt_t trSPD1=0, UInt_t trSPD2=0);
void SetSingleClusterData(Int_t id, const Float_t* scl,UInt_t tr=0);
void CompactBits();
void SetDPhiWindow2(Float_t v=-1) {fDPhiWindow2 = v;}
void SetDThetaWindow2(Float_t v=-1) {fDThetaWindow2 = v;}
void SetDPhiShift(Float_t v=-1) {fDPhiShift = v;}
void SetNStdDev(Float_t v=1) {fNStdDev = v;}
Float_t GetDPhiWindow2() const {return fDPhiWindow2;}
Float_t GetDThetaWindow2() const {return fDThetaWindow2;}
Float_t GetDPhiShift() const {return fDPhiShift;}
Float_t GetNStdDev() const {return fNStdDev;}
protected:
void Duplicate(const AliMultiplicity &m);
Int_t fNtracks;
Int_t fNsingle;
Int_t fNsingleSPD2;
Float_t fDPhiWindow2;
Float_t fDThetaWindow2;
Float_t fDPhiShift;
Float_t fNStdDev;
Int_t *fLabels;
Int_t *fLabelsL2;
UInt_t* fUsedClusS;
ULong64_t* fUsedClusT;
AliRefArray *fTCl2Tracks[2][2];
AliRefArray *fSCl2Tracks[2];
Double32_t *fTh;
Double32_t *fPhi;
Double32_t *fDeltTh;
Double32_t *fDeltPhi;
Double32_t *fThsingle;
Double32_t *fPhisingle;
Int_t *fLabelssingle;
Short_t fFiredChips[2];
UInt_t fITSClusters[6];
TBits fFastOrFiredChips;
TBits fClusterFiredChips;
ClassDef(AliMultiplicity,20);
};
inline Int_t AliMultiplicity::GetLabel(Int_t i, Int_t layer) const
{
if(i>=0 && i<fNtracks) {
if (layer == 0) {
return fLabels[i];
} else if (layer == 1) {
if (fLabelsL2) {
return fLabelsL2[i];
} else {
Warning("GetLabel", "No information for layer 2 available !");
return -9999;
}
} else {
Error("GetLabel","Invalid layer number %d",layer); return -9999;
}
} else {
Error("GetLabel","Invalid track number %d",i); return -9999;
}
return -9999;
}
inline Int_t AliMultiplicity::GetLabelSingle(Int_t i) const
{
if(i>=0 && i<fNsingle) {
return fLabelssingle[i];
} else {
Error("GetLabelSingle","Invalid cluster number %d",i); return -9999;
}
return -9999;
}
inline Double_t AliMultiplicity::CalcDist(Int_t i) const
{
if (i<0 && i>=fNtracks) return -1;
if (fDPhiWindow2<1E-9 || fDThetaWindow2<1E-9) return -1;
double dphi = TMath::Abs(fDeltPhi[i]) - fDPhiShift;
double dtheta = fDeltTh[i];
if (GetScaleDThetaBySin2T()) {
double sinTI = TMath::Sin(fTh[i]-dtheta/2);
sinTI *= sinTI;
dtheta /= sinTI>1.e-6 ? sinTI : 1.e-6;
}
return dphi*dphi/fDPhiWindow2 + dtheta*dtheta/fDThetaWindow2;
}
inline Int_t AliMultiplicity::GetNumberOfSingleClustersLr(Int_t lr) const
{
if (lr==0) return fNsingle - fNsingleSPD2;
return AreSPD2SinglesStored() ? fNsingleSPD2 : -1;
}
#endif