ROOT logo
//
// All cuts for single track in D0 analysis,
// based on track quality and particle identification
// with TPC and TOF.
// Author: Massimo Venaruzzo
//
//

#include <Riostream.h>

#include "AliPID.h"
#include "AliPIDResponse.h"
#include "AliRsnCutDaughterD0.h"

ClassImp(AliRsnCutDaughterD0)

//__________________________________________________________________________________________________
AliRsnCutDaughterD0::AliRsnCutDaughterD0(const char *name, AliPID::EParticleType pid) :
AliRsnCut(name, AliRsnTarget::kDaughter),
  fNoPID(kFALSE),
  //fIsCheckOnMother(kFALSE),
  fPID(pid),
  fCutQuality(Form("%sQuality", name)),
  fPionTPCPIDCut(3.0),
  fKaonTPCPIDCut(3.0),
  fPionTOFPIDCut(3.0),
  fKaonTOFPIDCut(3.0),
  fPtDepPIDCut(kFALSE) 
{
  //
  // Constructor
  // 
  //
  fCutQuality.SetPtRange(0.15, 1E+20);
  fCutQuality.SetEtaRange(-0.8, 0.8);
  fCutQuality.SetDCARPtFormula("");
  fCutQuality.SetDCARmin(0.0);
  fCutQuality.SetDCAZmax(2.0);
  fCutQuality.SetSPDminNClusters(0);
  fCutQuality.SetITSminNClusters(0);
  fCutQuality.SetITSmaxChi2(1E+20);
  fCutQuality.SetTPCminNClusters(0);
  fCutQuality.SetMinNCrossedRowsTPC(0,kTRUE);
  fCutQuality.SetMinNCrossedRowsOverFindableClsTPC(0.00,kTRUE);
  fCutQuality.SetTPCmaxChi2(1E20);
  fCutQuality.SetRejectKinkDaughters();
  fCutQuality.SetAODTestFilterBit(-1);
}

//__________________________________________________________________________________________________
Bool_t AliRsnCutDaughterD0::IsSelected(TObject *obj)
{
  //
  // Global check
  //

  // coherence check
  if (!TargetOK(obj)) return kFALSE;
  
  // if this class is used to check the mothers in the acceptance, accept (will be applied only selection on min pt and eta)
  //if (fIsCheckOnMother) return kTRUE;

  // check track
  AliVTrack *track = dynamic_cast<AliVTrack *>(fDaughter->GetRef());
  if (!track) return kFALSE;
   
  AliDebugClass(2, "Checking status...");
  // check flags
  if ((track->GetStatus() & AliESDtrack::kTPCin   ) == 0) return kFALSE;
  if ((track->GetStatus() & AliESDtrack::kTPCrefit) == 0) return kFALSE;
  if ((track->GetStatus() & AliESDtrack::kITSrefit) == 0) return kFALSE;
  AliDebugClass(2, "...passed");
  
  // quality
  AliDebugClass(2, "Checking quality cuts...");
  if (!fCutQuality.IsSelected(obj)) return kFALSE;
  AliDebugClass(2, "...passed");

  // if no PID is required, accept
  if (fNoPID) return kTRUE;
  
  
  // check initialization of PID object
  AliPIDResponse *pid = fEvent->GetPIDResponse();
  if (!pid) {
    AliFatal("NULL PID response");
    return kFALSE;
  }
  
  AliDebugClass(2, "Checking TPC and TOF Matching..."); 
  // check if TPC and TOF are matched
  // and computes all values used in the PID cut
  Bool_t   isTPC  = MatchTPC(track);
  Bool_t   isTOF  = MatchTOF(track);   
  AliDebugClass(2, "...passed");
   
  Double_t pTPC   = track->GetTPCmomentum();
  Double_t p      = track->P();
  Double_t nsTPC  = TMath::Abs(pid->NumberOfSigmasTPC(track, fPID));
  Double_t nsTOF  = isTOF ? TMath::Abs(pid->NumberOfSigmasTOF(track, fPID)) : 1E20;
  Double_t maxTPC = 1E20;
  Double_t maxTOF = 1E20;
  AliDebugClass(2, "Checking PID...");

  if(!fPtDepPIDCut){
    // applies the cut differently depending on the PID and the momentum
    if (isTPC && isTOF) {
      if (fPID == AliPID::kPion) {maxTPC = fPionTPCPIDCut; maxTOF = fPionTOFPIDCut;}
      if (fPID == AliPID::kKaon) {maxTPC = fKaonTPCPIDCut; maxTOF = fKaonTOFPIDCut;}
      return (nsTPC <= maxTPC && nsTOF <= maxTOF);
    } else if (isTPC){
      if (fPID == AliPID::kPion) maxTPC = fPionTPCPIDCut;
      if (fPID == AliPID::kKaon) maxTPC = fKaonTPCPIDCut;
      return (nsTPC <= maxTPC); 
    }
    else return kTRUE;
  } else {
    // applies the cut differently depending on the PID and the momentum
    if (isTPC && isTOF) {
      // TPC: 5sigma cut for all
      if (nsTPC > 5.0) return kFALSE;
      // TOF: 3sigma below 1.5 GeV, 2sigma above
      if (p < 1.5) maxTOF = 3.0; else maxTOF = 2.0;
      return (nsTOF <= maxTOF);
    } else if(isTPC){
      // TPC:
      // all   below   350         MeV: 5sigma
      // all   between 350 and 500 MeV: 3sigma
      // pions above   500         MeV: 2sigma
      // kaons between 500 and 700 MeV: 2sigma
      // kaons above   700         MeV: rejected
      if (pTPC <= 0.35)
	maxTPC = 5.0;
      else if (pTPC > 0.35 && pTPC <= 0.5)
	maxTPC = 3.0;
      else {
	if (fPID == AliPID::kPion)
	  maxTPC = 2.0;
	else if (fPID == AliPID::kKaon) {
	  if (pTPC <= 0.7)
	    maxTPC = 2.0;
	  else
	    return kFALSE;
	}
      }
      return (nsTPC <= maxTPC);
    } 
    else return kTRUE;
  }    
  
  AliDebugClass(2, "...passed"); 
  // if we reach this point, all checks were successful
  AliDebugClass(2, "Good Pion/Kaon Candidate Found!!");
}
 AliRsnCutDaughterD0.cxx:1
 AliRsnCutDaughterD0.cxx:2
 AliRsnCutDaughterD0.cxx:3
 AliRsnCutDaughterD0.cxx:4
 AliRsnCutDaughterD0.cxx:5
 AliRsnCutDaughterD0.cxx:6
 AliRsnCutDaughterD0.cxx:7
 AliRsnCutDaughterD0.cxx:8
 AliRsnCutDaughterD0.cxx:9
 AliRsnCutDaughterD0.cxx:10
 AliRsnCutDaughterD0.cxx:11
 AliRsnCutDaughterD0.cxx:12
 AliRsnCutDaughterD0.cxx:13
 AliRsnCutDaughterD0.cxx:14
 AliRsnCutDaughterD0.cxx:15
 AliRsnCutDaughterD0.cxx:16
 AliRsnCutDaughterD0.cxx:17
 AliRsnCutDaughterD0.cxx:18
 AliRsnCutDaughterD0.cxx:19
 AliRsnCutDaughterD0.cxx:20
 AliRsnCutDaughterD0.cxx:21
 AliRsnCutDaughterD0.cxx:22
 AliRsnCutDaughterD0.cxx:23
 AliRsnCutDaughterD0.cxx:24
 AliRsnCutDaughterD0.cxx:25
 AliRsnCutDaughterD0.cxx:26
 AliRsnCutDaughterD0.cxx:27
 AliRsnCutDaughterD0.cxx:28
 AliRsnCutDaughterD0.cxx:29
 AliRsnCutDaughterD0.cxx:30
 AliRsnCutDaughterD0.cxx:31
 AliRsnCutDaughterD0.cxx:32
 AliRsnCutDaughterD0.cxx:33
 AliRsnCutDaughterD0.cxx:34
 AliRsnCutDaughterD0.cxx:35
 AliRsnCutDaughterD0.cxx:36
 AliRsnCutDaughterD0.cxx:37
 AliRsnCutDaughterD0.cxx:38
 AliRsnCutDaughterD0.cxx:39
 AliRsnCutDaughterD0.cxx:40
 AliRsnCutDaughterD0.cxx:41
 AliRsnCutDaughterD0.cxx:42
 AliRsnCutDaughterD0.cxx:43
 AliRsnCutDaughterD0.cxx:44
 AliRsnCutDaughterD0.cxx:45
 AliRsnCutDaughterD0.cxx:46
 AliRsnCutDaughterD0.cxx:47
 AliRsnCutDaughterD0.cxx:48
 AliRsnCutDaughterD0.cxx:49
 AliRsnCutDaughterD0.cxx:50
 AliRsnCutDaughterD0.cxx:51
 AliRsnCutDaughterD0.cxx:52
 AliRsnCutDaughterD0.cxx:53
 AliRsnCutDaughterD0.cxx:54
 AliRsnCutDaughterD0.cxx:55
 AliRsnCutDaughterD0.cxx:56
 AliRsnCutDaughterD0.cxx:57
 AliRsnCutDaughterD0.cxx:58
 AliRsnCutDaughterD0.cxx:59
 AliRsnCutDaughterD0.cxx:60
 AliRsnCutDaughterD0.cxx:61
 AliRsnCutDaughterD0.cxx:62
 AliRsnCutDaughterD0.cxx:63
 AliRsnCutDaughterD0.cxx:64
 AliRsnCutDaughterD0.cxx:65
 AliRsnCutDaughterD0.cxx:66
 AliRsnCutDaughterD0.cxx:67
 AliRsnCutDaughterD0.cxx:68
 AliRsnCutDaughterD0.cxx:69
 AliRsnCutDaughterD0.cxx:70
 AliRsnCutDaughterD0.cxx:71
 AliRsnCutDaughterD0.cxx:72
 AliRsnCutDaughterD0.cxx:73
 AliRsnCutDaughterD0.cxx:74
 AliRsnCutDaughterD0.cxx:75
 AliRsnCutDaughterD0.cxx:76
 AliRsnCutDaughterD0.cxx:77
 AliRsnCutDaughterD0.cxx:78
 AliRsnCutDaughterD0.cxx:79
 AliRsnCutDaughterD0.cxx:80
 AliRsnCutDaughterD0.cxx:81
 AliRsnCutDaughterD0.cxx:82
 AliRsnCutDaughterD0.cxx:83
 AliRsnCutDaughterD0.cxx:84
 AliRsnCutDaughterD0.cxx:85
 AliRsnCutDaughterD0.cxx:86
 AliRsnCutDaughterD0.cxx:87
 AliRsnCutDaughterD0.cxx:88
 AliRsnCutDaughterD0.cxx:89
 AliRsnCutDaughterD0.cxx:90
 AliRsnCutDaughterD0.cxx:91
 AliRsnCutDaughterD0.cxx:92
 AliRsnCutDaughterD0.cxx:93
 AliRsnCutDaughterD0.cxx:94
 AliRsnCutDaughterD0.cxx:95
 AliRsnCutDaughterD0.cxx:96
 AliRsnCutDaughterD0.cxx:97
 AliRsnCutDaughterD0.cxx:98
 AliRsnCutDaughterD0.cxx:99
 AliRsnCutDaughterD0.cxx:100
 AliRsnCutDaughterD0.cxx:101
 AliRsnCutDaughterD0.cxx:102
 AliRsnCutDaughterD0.cxx:103
 AliRsnCutDaughterD0.cxx:104
 AliRsnCutDaughterD0.cxx:105
 AliRsnCutDaughterD0.cxx:106
 AliRsnCutDaughterD0.cxx:107
 AliRsnCutDaughterD0.cxx:108
 AliRsnCutDaughterD0.cxx:109
 AliRsnCutDaughterD0.cxx:110
 AliRsnCutDaughterD0.cxx:111
 AliRsnCutDaughterD0.cxx:112
 AliRsnCutDaughterD0.cxx:113
 AliRsnCutDaughterD0.cxx:114
 AliRsnCutDaughterD0.cxx:115
 AliRsnCutDaughterD0.cxx:116
 AliRsnCutDaughterD0.cxx:117
 AliRsnCutDaughterD0.cxx:118
 AliRsnCutDaughterD0.cxx:119
 AliRsnCutDaughterD0.cxx:120
 AliRsnCutDaughterD0.cxx:121
 AliRsnCutDaughterD0.cxx:122
 AliRsnCutDaughterD0.cxx:123
 AliRsnCutDaughterD0.cxx:124
 AliRsnCutDaughterD0.cxx:125
 AliRsnCutDaughterD0.cxx:126
 AliRsnCutDaughterD0.cxx:127
 AliRsnCutDaughterD0.cxx:128
 AliRsnCutDaughterD0.cxx:129
 AliRsnCutDaughterD0.cxx:130
 AliRsnCutDaughterD0.cxx:131
 AliRsnCutDaughterD0.cxx:132
 AliRsnCutDaughterD0.cxx:133
 AliRsnCutDaughterD0.cxx:134
 AliRsnCutDaughterD0.cxx:135
 AliRsnCutDaughterD0.cxx:136
 AliRsnCutDaughterD0.cxx:137
 AliRsnCutDaughterD0.cxx:138
 AliRsnCutDaughterD0.cxx:139
 AliRsnCutDaughterD0.cxx:140
 AliRsnCutDaughterD0.cxx:141
 AliRsnCutDaughterD0.cxx:142
 AliRsnCutDaughterD0.cxx:143
 AliRsnCutDaughterD0.cxx:144
 AliRsnCutDaughterD0.cxx:145
 AliRsnCutDaughterD0.cxx:146
 AliRsnCutDaughterD0.cxx:147
 AliRsnCutDaughterD0.cxx:148
 AliRsnCutDaughterD0.cxx:149
 AliRsnCutDaughterD0.cxx:150
 AliRsnCutDaughterD0.cxx:151
 AliRsnCutDaughterD0.cxx:152
 AliRsnCutDaughterD0.cxx:153
 AliRsnCutDaughterD0.cxx:154