ROOT logo
//
// Class AliRsnCutPIDTPC
//
// General implementation of a single cut strategy, which can be:
// - a value contained in a given interval  [--> IsBetween()   ]
// - a value equal to a given reference     [--> MatchesValue()]
//
// In all cases, the reference value(s) is (are) given as data members
// and each kind of cut requires a given value type (Int, UInt, Double),
// but the cut check procedure is then automatized and chosen thanks to
// an enumeration of the implemented cut types.
// At the end, the user (or any other point which uses this object) has
// to use the method IsSelected() to check if this cut has been passed.
//
// authors: Martin Vala (martin.vala@cern.ch)
//          Alberto Pulvirenti (alberto.pulvirenti@ct.infn.it)
//

#include "AliPID.h"
#include "AliAnalysisManager.h"
#include "AliESDInputHandler.h"
#include "AliESDpid.h"
#include "AliAODpidUtil.h"

#include "AliRsnCutPIDTPC.h"

ClassImp(AliRsnCutPIDTPC)

//_________________________________________________________________________________________________
AliRsnCutPIDTPC::AliRsnCutPIDTPC
(const char *name, AliPID::EParticleType type, Double_t min, Double_t max, Bool_t rejectOutside) :
   AliRsnCut(name, AliRsnCut::kDaughter, min, max),
   fRejectOutside(rejectOutside),
   fMomMin(0.0),
   fMomMax(1E+20),
   fRefType(type),
   fESDpid(0x0),
   fAODpid(0x0)
{
//
// Main constructor.
//

   fBB[0] = fBB[1] = fBB[2] = fBB[3] = fBB[4] = 0.0;
}

//_________________________________________________________________________________________________
AliRsnCutPIDTPC::AliRsnCutPIDTPC
(const AliRsnCutPIDTPC &copy) :
   AliRsnCut(copy),
   fRejectOutside(copy.fRejectOutside),
   fMomMin(copy.fMomMin),
   fMomMax(copy.fMomMax),
   fRefType(copy.fRefType),
   fESDpid(copy.fESDpid),
   fAODpid(copy.fAODpid)
{
//
// Copy constructor.
//

   Int_t i;
   for (i = 0; i < 5; i++) fBB[i] = copy.fBB[i];
}

//_________________________________________________________________________________________________
AliRsnCutPIDTPC &AliRsnCutPIDTPC::operator=(const AliRsnCutPIDTPC &copy)
{
//
// Assignment operator
//

   AliRsnCut::operator=(copy);
   if (this == &copy)
      return *this;

   fRejectOutside = copy.fRejectOutside;
   fMomMin        = copy.fMomMin;
   fMomMax        = copy.fMomMax;
   fRefType       = copy.fRefType;
   fESDpid        = copy.fESDpid;
   fAODpid        = copy.fAODpid;

   Int_t i;
   for (i = 0; i < 5; i++) fBB[i] = copy.fBB[i];

   return (*this);
}

//_________________________________________________________________________________________________
void AliRsnCutPIDTPC::SetBBParam(Double_t p0, Double_t p1, Double_t p2, Double_t p3, Double_t p4)
{
//
// Properly set the Bethe-Bloch parameters in all places where it is needed.
//

   fBB[0] = p0;
   fBB[1] = p1;
   fBB[2] = p2;
   fBB[3] = p3;
   fBB[4] = p4;
}

//_________________________________________________________________________________________________
Bool_t AliRsnCutPIDTPC::IsSelected(TObject *object)
{
//
// Cut checker.
//

   // coherence check
   if (!TargetOK(object)) return kFALSE;

   // common evaluation variables
   Double_t     mom;
   AliESDtrack *esdTrack = fDaughter->Ref2ESDtrack();
   AliAODTrack *aodTrack = fDaughter->Ref2AODtrack();

   // get inner momentum, needed for BB computation
   if (esdTrack) {
      if (!esdTrack->GetInnerParam()) {
         AliDebug(AliLog::kDebug + 2, "No inner param");
         return kFALSE;
      }
      mom = esdTrack->GetInnerParam()->P();
   } else if (aodTrack) {
      if (!aodTrack->GetDetPid()) {
         AliDebug(AliLog::kDebug + 2, "No def-pid object");
         return kFALSE;
      }
      mom = aodTrack->GetDetPid()->GetTPCmomentum();
      if (mom < 1E-6) return kFALSE;
   } 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;
   }

   // assign PID nsigmas to default cut check value
   // since bad object types are rejected before, here we have an ESD track or AOD track
   if (esdTrack) {
      if (!fESDpid) {
         fESDpid = new AliESDpid;
         fESDpid->GetTPCResponse().SetBetheBlochParameters(fBB[0], fBB[1], fBB[2], fBB[3], fBB[4]);
      }
      fCutValueD = fESDpid->GetTPCResponse().GetNumberOfSigmas(mom, esdTrack->GetTPCsignal(), esdTrack->GetTPCsignalN(), fRefType);
   } else {
      if (!fAODpid) {
         fAODpid = new AliAODpidUtil;
         fAODpid->GetTPCResponse().SetBetheBlochParameters(fBB[0], fBB[1], fBB[2], fBB[3], fBB[4]);
      }
      if (aodTrack->GetTPCsignalN() == 0) aodTrack->GetDetPid()->SetTPCsignalN(aodTrack->GetTPCNcls());
      fCutValueD = fAODpid->NumberOfSigmasTPC(aodTrack, fRefType);
   }

   // use AliRsnCut default method to check cut
   Bool_t cutCheck = OkRangeD();

   // now check the momentum:
   // -- if it stays inside the accepted range, track just checked
   //    with respect to the nsigma band
   // -- if it stays outside the accepted range and 'fRejectOutside' is kTRUE,
   //    track is always rejected, while if 'fRejectOutside' is kFALSE,
   //    track is accepted if it stays inside the nsigma band
   if ((mom >= fMomMin && mom <= fMomMax))
      return cutCheck;
   else {
      AliDebug(AliLog::kDebug + 2, Form("Track momentum = %.5f, outside allowed range", mom));
      return ((!fRejectOutside) && cutCheck);
   }
}

//_________________________________________________________________________________________________
void AliRsnCutPIDTPC::Print(const Option_t *) const
{
//
// Print information on this cut
//

   AliInfo(Form("Cut name                    : %s", GetName()));
   AliInfo(Form("--> cut range (nsigma)      : %.3f %.3f", fMinD, fMaxD));
   AliInfo(Form("--> momentum range          : %.3f %.3f", fMomMin, fMomMax));
   AliInfo(Form("--> tracks outside range are: %s", (fRejectOutside ? "rejected" : "accepted")));
}
 AliRsnCutPIDTPC.cxx:1
 AliRsnCutPIDTPC.cxx:2
 AliRsnCutPIDTPC.cxx:3
 AliRsnCutPIDTPC.cxx:4
 AliRsnCutPIDTPC.cxx:5
 AliRsnCutPIDTPC.cxx:6
 AliRsnCutPIDTPC.cxx:7
 AliRsnCutPIDTPC.cxx:8
 AliRsnCutPIDTPC.cxx:9
 AliRsnCutPIDTPC.cxx:10
 AliRsnCutPIDTPC.cxx:11
 AliRsnCutPIDTPC.cxx:12
 AliRsnCutPIDTPC.cxx:13
 AliRsnCutPIDTPC.cxx:14
 AliRsnCutPIDTPC.cxx:15
 AliRsnCutPIDTPC.cxx:16
 AliRsnCutPIDTPC.cxx:17
 AliRsnCutPIDTPC.cxx:18
 AliRsnCutPIDTPC.cxx:19
 AliRsnCutPIDTPC.cxx:20
 AliRsnCutPIDTPC.cxx:21
 AliRsnCutPIDTPC.cxx:22
 AliRsnCutPIDTPC.cxx:23
 AliRsnCutPIDTPC.cxx:24
 AliRsnCutPIDTPC.cxx:25
 AliRsnCutPIDTPC.cxx:26
 AliRsnCutPIDTPC.cxx:27
 AliRsnCutPIDTPC.cxx:28
 AliRsnCutPIDTPC.cxx:29
 AliRsnCutPIDTPC.cxx:30
 AliRsnCutPIDTPC.cxx:31
 AliRsnCutPIDTPC.cxx:32
 AliRsnCutPIDTPC.cxx:33
 AliRsnCutPIDTPC.cxx:34
 AliRsnCutPIDTPC.cxx:35
 AliRsnCutPIDTPC.cxx:36
 AliRsnCutPIDTPC.cxx:37
 AliRsnCutPIDTPC.cxx:38
 AliRsnCutPIDTPC.cxx:39
 AliRsnCutPIDTPC.cxx:40
 AliRsnCutPIDTPC.cxx:41
 AliRsnCutPIDTPC.cxx:42
 AliRsnCutPIDTPC.cxx:43
 AliRsnCutPIDTPC.cxx:44
 AliRsnCutPIDTPC.cxx:45
 AliRsnCutPIDTPC.cxx:46
 AliRsnCutPIDTPC.cxx:47
 AliRsnCutPIDTPC.cxx:48
 AliRsnCutPIDTPC.cxx:49
 AliRsnCutPIDTPC.cxx:50
 AliRsnCutPIDTPC.cxx:51
 AliRsnCutPIDTPC.cxx:52
 AliRsnCutPIDTPC.cxx:53
 AliRsnCutPIDTPC.cxx:54
 AliRsnCutPIDTPC.cxx:55
 AliRsnCutPIDTPC.cxx:56
 AliRsnCutPIDTPC.cxx:57
 AliRsnCutPIDTPC.cxx:58
 AliRsnCutPIDTPC.cxx:59
 AliRsnCutPIDTPC.cxx:60
 AliRsnCutPIDTPC.cxx:61
 AliRsnCutPIDTPC.cxx:62
 AliRsnCutPIDTPC.cxx:63
 AliRsnCutPIDTPC.cxx:64
 AliRsnCutPIDTPC.cxx:65
 AliRsnCutPIDTPC.cxx:66
 AliRsnCutPIDTPC.cxx:67
 AliRsnCutPIDTPC.cxx:68
 AliRsnCutPIDTPC.cxx:69
 AliRsnCutPIDTPC.cxx:70
 AliRsnCutPIDTPC.cxx:71
 AliRsnCutPIDTPC.cxx:72
 AliRsnCutPIDTPC.cxx:73
 AliRsnCutPIDTPC.cxx:74
 AliRsnCutPIDTPC.cxx:75
 AliRsnCutPIDTPC.cxx:76
 AliRsnCutPIDTPC.cxx:77
 AliRsnCutPIDTPC.cxx:78
 AliRsnCutPIDTPC.cxx:79
 AliRsnCutPIDTPC.cxx:80
 AliRsnCutPIDTPC.cxx:81
 AliRsnCutPIDTPC.cxx:82
 AliRsnCutPIDTPC.cxx:83
 AliRsnCutPIDTPC.cxx:84
 AliRsnCutPIDTPC.cxx:85
 AliRsnCutPIDTPC.cxx:86
 AliRsnCutPIDTPC.cxx:87
 AliRsnCutPIDTPC.cxx:88
 AliRsnCutPIDTPC.cxx:89
 AliRsnCutPIDTPC.cxx:90
 AliRsnCutPIDTPC.cxx:91
 AliRsnCutPIDTPC.cxx:92
 AliRsnCutPIDTPC.cxx:93
 AliRsnCutPIDTPC.cxx:94
 AliRsnCutPIDTPC.cxx:95
 AliRsnCutPIDTPC.cxx:96
 AliRsnCutPIDTPC.cxx:97
 AliRsnCutPIDTPC.cxx:98
 AliRsnCutPIDTPC.cxx:99
 AliRsnCutPIDTPC.cxx:100
 AliRsnCutPIDTPC.cxx:101
 AliRsnCutPIDTPC.cxx:102
 AliRsnCutPIDTPC.cxx:103
 AliRsnCutPIDTPC.cxx:104
 AliRsnCutPIDTPC.cxx:105
 AliRsnCutPIDTPC.cxx:106
 AliRsnCutPIDTPC.cxx:107
 AliRsnCutPIDTPC.cxx:108
 AliRsnCutPIDTPC.cxx:109
 AliRsnCutPIDTPC.cxx:110
 AliRsnCutPIDTPC.cxx:111
 AliRsnCutPIDTPC.cxx:112
 AliRsnCutPIDTPC.cxx:113
 AliRsnCutPIDTPC.cxx:114
 AliRsnCutPIDTPC.cxx:115
 AliRsnCutPIDTPC.cxx:116
 AliRsnCutPIDTPC.cxx:117
 AliRsnCutPIDTPC.cxx:118
 AliRsnCutPIDTPC.cxx:119
 AliRsnCutPIDTPC.cxx:120
 AliRsnCutPIDTPC.cxx:121
 AliRsnCutPIDTPC.cxx:122
 AliRsnCutPIDTPC.cxx:123
 AliRsnCutPIDTPC.cxx:124
 AliRsnCutPIDTPC.cxx:125
 AliRsnCutPIDTPC.cxx:126
 AliRsnCutPIDTPC.cxx:127
 AliRsnCutPIDTPC.cxx:128
 AliRsnCutPIDTPC.cxx:129
 AliRsnCutPIDTPC.cxx:130
 AliRsnCutPIDTPC.cxx:131
 AliRsnCutPIDTPC.cxx:132
 AliRsnCutPIDTPC.cxx:133
 AliRsnCutPIDTPC.cxx:134
 AliRsnCutPIDTPC.cxx:135
 AliRsnCutPIDTPC.cxx:136
 AliRsnCutPIDTPC.cxx:137
 AliRsnCutPIDTPC.cxx:138
 AliRsnCutPIDTPC.cxx:139
 AliRsnCutPIDTPC.cxx:140
 AliRsnCutPIDTPC.cxx:141
 AliRsnCutPIDTPC.cxx:142
 AliRsnCutPIDTPC.cxx:143
 AliRsnCutPIDTPC.cxx:144
 AliRsnCutPIDTPC.cxx:145
 AliRsnCutPIDTPC.cxx:146
 AliRsnCutPIDTPC.cxx:147
 AliRsnCutPIDTPC.cxx:148
 AliRsnCutPIDTPC.cxx:149
 AliRsnCutPIDTPC.cxx:150
 AliRsnCutPIDTPC.cxx:151
 AliRsnCutPIDTPC.cxx:152
 AliRsnCutPIDTPC.cxx:153
 AliRsnCutPIDTPC.cxx:154
 AliRsnCutPIDTPC.cxx:155
 AliRsnCutPIDTPC.cxx:156
 AliRsnCutPIDTPC.cxx:157
 AliRsnCutPIDTPC.cxx:158
 AliRsnCutPIDTPC.cxx:159
 AliRsnCutPIDTPC.cxx:160
 AliRsnCutPIDTPC.cxx:161
 AliRsnCutPIDTPC.cxx:162
 AliRsnCutPIDTPC.cxx:163
 AliRsnCutPIDTPC.cxx:164
 AliRsnCutPIDTPC.cxx:165
 AliRsnCutPIDTPC.cxx:166
 AliRsnCutPIDTPC.cxx:167
 AliRsnCutPIDTPC.cxx:168
 AliRsnCutPIDTPC.cxx:169
 AliRsnCutPIDTPC.cxx:170
 AliRsnCutPIDTPC.cxx:171
 AliRsnCutPIDTPC.cxx:172
 AliRsnCutPIDTPC.cxx:173
 AliRsnCutPIDTPC.cxx:174
 AliRsnCutPIDTPC.cxx:175
 AliRsnCutPIDTPC.cxx:176
 AliRsnCutPIDTPC.cxx:177
 AliRsnCutPIDTPC.cxx:178
 AliRsnCutPIDTPC.cxx:179
 AliRsnCutPIDTPC.cxx:180
 AliRsnCutPIDTPC.cxx:181
 AliRsnCutPIDTPC.cxx:182
 AliRsnCutPIDTPC.cxx:183