]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWG2/RESONANCES/AliRsnCutPIDTPC.cxx
Coverity fix
[u/mrichter/AliRoot.git] / PWG2 / RESONANCES / AliRsnCutPIDTPC.cxx
1 //
2 // Class AliRsnCutPIDTPC
3 //
4 // General implementation of a single cut strategy, which can be:
5 // - a value contained in a given interval  [--> IsBetween()   ]
6 // - a value equal to a given reference     [--> MatchesValue()]
7 //
8 // In all cases, the reference value(s) is (are) given as data members
9 // and each kind of cut requires a given value type (Int, UInt, Double),
10 // but the cut check procedure is then automatized and chosen thanks to
11 // an enumeration of the implemented cut types.
12 // At the end, the user (or any other point which uses this object) has
13 // to use the method IsSelected() to check if this cut has been passed.
14 //
15 // authors: Martin Vala (martin.vala@cern.ch)
16 //          Alberto Pulvirenti (alberto.pulvirenti@ct.infn.it)
17 //
18
19 #include "AliPID.h"
20 #include "AliAnalysisManager.h"
21 #include "AliESDInputHandler.h"
22 #include "AliESDpid.h"
23 #include "AliAODpidUtil.h"
24
25 #include "AliRsnCutPIDTPC.h"
26
27 ClassImp(AliRsnCutPIDTPC)
28
29 //_________________________________________________________________________________________________
30 AliRsnCutPIDTPC::AliRsnCutPIDTPC
31 (const char *name, AliPID::EParticleType type, Double_t min, Double_t max, Bool_t rejectOutside) :
32    AliRsnCut(name, AliRsnCut::kDaughter, min, max),
33    fRejectOutside(rejectOutside),
34    fMomMin(0.0),
35    fMomMax(1E+20),
36    fRefType(type),
37    fESDpid(0x0),
38    fAODpid(0x0)
39 {
40 //
41 // Main constructor.
42 //
43
44    fBB[0] = fBB[1] = fBB[2] = fBB[3] = fBB[4] = 0.0;
45 }
46
47 //_________________________________________________________________________________________________
48 AliRsnCutPIDTPC::AliRsnCutPIDTPC
49 (const AliRsnCutPIDTPC& copy) :
50    AliRsnCut(copy),
51    fRejectOutside(copy.fRejectOutside),
52    fMomMin(copy.fMomMin),
53    fMomMax(copy.fMomMax),
54    fRefType(copy.fRefType),
55    fESDpid(copy.fESDpid),
56    fAODpid(copy.fAODpid)
57 {
58 //
59 // Copy constructor.
60 //
61
62    Int_t i;
63    for (i = 0; i < 5; i++) fBB[i] = copy.fBB[i];
64 }
65
66 //_________________________________________________________________________________________________
67 AliRsnCutPIDTPC& AliRsnCutPIDTPC::operator=(const AliRsnCutPIDTPC& copy)
68 {
69 //
70 // Assignment operator
71 //
72
73    AliRsnCut::operator=(copy);
74
75    fRejectOutside = copy.fRejectOutside;
76    fMomMin        = copy.fMomMin;
77    fMomMax        = copy.fMomMax;
78    fRefType       = copy.fRefType;
79    fESDpid        = copy.fESDpid;
80    fAODpid        = copy.fAODpid;
81    
82    Int_t i;
83    for (i = 0; i < 5; i++) fBB[i] = copy.fBB[i];
84
85    return (*this);
86 }
87
88 //_________________________________________________________________________________________________
89 void AliRsnCutPIDTPC::SetBBParam(Double_t p0, Double_t p1, Double_t p2, Double_t p3, Double_t p4)
90 {
91 //
92 // Properly set the Bethe-Bloch parameters in all places where it is needed.
93 //
94
95    fBB[0] = p0;
96    fBB[1] = p1;
97    fBB[2] = p2;
98    fBB[3] = p3;
99    fBB[4] = p4;
100 }
101
102 //_________________________________________________________________________________________________
103 Bool_t AliRsnCutPIDTPC::IsSelected(TObject *object)
104 {
105 //
106 // Cut checker.
107 //
108
109    // coherence check
110    if (!TargetOK(object)) return kFALSE;
111
112    // common evaluation variables
113    Double_t     mom;
114    AliESDtrack *esdTrack = fDaughter->Ref2ESDtrack();
115    AliAODTrack *aodTrack = fDaughter->Ref2AODtrack();
116
117    // get inner momentum, needed for BB computation
118    if (esdTrack) {
119       if (!esdTrack->GetInnerParam()) {
120          AliDebug(AliLog::kDebug + 2, "No inner param");
121          return kFALSE;
122       }
123       mom = esdTrack->GetInnerParam()->P();
124    } else if (aodTrack) {
125       if (!aodTrack->GetDetPid()) {
126          AliDebug(AliLog::kDebug + 2, "No def-pid object");
127          return kFALSE;
128       }
129       mom = aodTrack->GetDetPid()->GetTPCmomentum();
130       if (mom < 1E-6) return kFALSE;
131    } else {
132       AliDebug(AliLog::kDebug + 2, Form("Impossible to process an object of type '%s'. Cut applicable only to ESD/AOD tracks", fDaughter->GetRef()->ClassName()));
133       return kFALSE;
134    }
135
136    // assign PID nsigmas to default cut check value
137    // since bad object types are rejected before, here we have an ESD track or AOD track
138    if (esdTrack) {
139       if (!fESDpid) {
140          fESDpid = new AliESDpid;
141          fESDpid->GetTPCResponse().SetBetheBlochParameters(fBB[0], fBB[1], fBB[2], fBB[3], fBB[4]);
142       }
143       fCutValueD = fESDpid->GetTPCResponse().GetNumberOfSigmas(mom, esdTrack->GetTPCsignal(), esdTrack->GetTPCsignalN(), fRefType);
144    } else {
145       if (!fAODpid) {
146          fAODpid = new AliAODpidUtil;
147          fAODpid->GetTPCResponse().SetBetheBlochParameters(fBB[0], fBB[1], fBB[2], fBB[3], fBB[4]);
148       }
149       if (aodTrack->GetTPCsignalN() == 0) aodTrack->GetDetPid()->SetTPCsignalN(aodTrack->GetTPCNcls());
150       fCutValueD = fAODpid->NumberOfSigmasTPC(aodTrack, fRefType);
151    }
152
153    // use AliRsnCut default method to check cut
154    Bool_t cutCheck = OkRangeD();
155
156    // now check the momentum:
157    // -- if it stays inside the accepted range, track just checked
158    //    with respect to the nsigma band
159    // -- if it stays outside the accepted range and 'fRejectOutside' is kTRUE,
160    //    track is always rejected, while if 'fRejectOutside' is kFALSE,
161    //    track is accepted if it stays inside the nsigma band
162    if ((mom >= fMomMin && mom <= fMomMax))
163       return cutCheck;
164    else {
165       AliDebug(AliLog::kDebug + 2, Form("Track momentum = %.5f, outside allowed range", mom));
166       return ((!fRejectOutside) && cutCheck);
167    }
168 }
169
170 //_________________________________________________________________________________________________
171 void AliRsnCutPIDTPC::Print(const Option_t *) const
172 {
173 //
174 // Print information on this cut
175 //
176
177    AliInfo(Form("Cut name                    : %s", GetName()));
178    AliInfo(Form("--> cut range (nsigma)      : %.3f %.3f", fMinD, fMaxD));
179    AliInfo(Form("--> momentum range          : %.3f %.3f", fMomMin, fMomMax));
180    AliInfo(Form("--> tracks outside range are: %s", (fRejectOutside ? "rejected" : "accepted")));
181 }