#include "AliAnalysisManager.h"
#include "AliESDInputHandler.h"
#include "AliESDtrack.h"
#include "AliESDpid.h"
#include "AliAODTrack.h"
#include "AliAODpidUtil.h"
#include "AliRsnCutPIDTOF.h"
ClassImp(AliRsnCutPIDTOF)
AliRsnCutPIDTOF::AliRsnCutPIDTOF
(const char *name, AliPID::EParticleType ref, Double_t min, Double_t max, Bool_t rejectUnmatched) :
AliRsnCut(name, AliRsnCut::kDaughter, min, max),
fRejectUnmatched(rejectUnmatched),
fRefType(AliPID::kUnknown),
fRefMass(0.0),
fESDpid(0x0),
fAODpid(0x0)
{
SetRefType(ref);
}
AliRsnCutPIDTOF::AliRsnCutPIDTOF(const AliRsnCutPIDTOF ©) :
AliRsnCut(copy),
fRejectUnmatched(copy.fRejectUnmatched),
fRefType(AliPID::kUnknown),
fRefMass(0.0),
fESDpid(copy.fESDpid),
fAODpid(copy.fAODpid)
{
SetRefType(copy.fRefType);
}
AliRsnCutPIDTOF &AliRsnCutPIDTOF::operator=(const AliRsnCutPIDTOF ©)
{
if (this == ©)
return *this;
fRejectUnmatched = copy.fRejectUnmatched;
fESDpid = copy.fESDpid;
fAODpid = copy.fAODpid;
SetRefType(copy.fRefType);
return (*this);
}
Bool_t AliRsnCutPIDTOF::IsSelected(TObject *object)
{
if (!TargetOK(object)) return kFALSE;
AliVTrack *vtrack = fDaughter->Ref2Vtrack();
if (!vtrack) {
AliDebug(AliLog::kDebug + 2, Form("Impossible to process an object of type '%s'. Cut applicable only to ESD/AOD tracks", fDaughter->GetRef()->ClassName()));
return kFALSE;
}
if (!IsMatched(vtrack)) {
AliDebug(AliLog::kDebug + 2, "Track is not matched with TOF");
if (fRejectUnmatched) return kFALSE;
}
Double_t tof, sigma, times[AliPID::kSPECIESC];
Double_t &ref = times[(Int_t)fRefType];
AliESDtrack *esdTrack = fDaughter->Ref2ESDtrack();
AliAODTrack *aodTrack = fDaughter->Ref2AODtrack();
if (esdTrack) {
AliESDEvent *esd = 0x0;
if (fEvent) esd = fEvent->GetRefESD();
if (!esd) {
AliError("Processing an ESD track, but target is not an ESD event");
return kFALSE;
}
if (!fESDpid) fESDpid = new AliESDpid;
fESDpid->SetTOFResponse(esd, AliESDpid::kTOF_T0);
esdTrack->GetIntegratedTimes(times,AliPID::kSPECIESC);
tof = (Double_t)(esdTrack->GetTOFsignal() - fESDpid->GetTOFResponse().GetStartTime(esdTrack->P()));
sigma = (Double_t)fESDpid->GetTOFResponse().GetExpectedSigma(esdTrack->P(), ref, fRefMass);
fCutValueD = (tof - ref) / sigma;
return OkRangeD();
} else if (aodTrack) {
if (!fAODpid) fAODpid = new AliAODpidUtil;
fCutValueD = (Double_t)fAODpid->NumberOfSigmasTOF(aodTrack, fRefType);
return OkRangeD();
} else {
AliDebug(AliLog::kDebug + 2, Form("Impossible to process an object of type '%s'. Cut applicable only to ESD/AOD tracks", fDaughter->GetRef()->ClassName()));
return kFALSE;
}
}
void AliRsnCutPIDTOF::Print(const Option_t *) const
{
AliInfo(Form("Cut name, type : %s %s", GetName(), ClassName()));
AliInfo(Form("TOF PID cut range (sigmas): %.3f %.3f", fMinD, fMaxD));
AliInfo(Form("Unmatched tracks are : %s", (fRejectUnmatched ? "rejected" : "accepted")));
}