]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWG2/RESONANCES/AliRsnCutPIDTPC.cxx
Improved functionality of AliRsnDaughterDef::MatchesDaughter()
[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 "AliAnalysisManager.h"
20 #include "AliESDInputHandler.h"
21 #include "AliRsnCutPIDTPC.h"
22
23 ClassImp(AliRsnCutPIDTPC)
24
25 //_________________________________________________________________________________________________
26 AliRsnCutPIDTPC::AliRsnCutPIDTPC
27 (const char *name, AliPID::EParticleType type, Double_t min, Double_t max, Bool_t rejectOutside) :
28    AliRsnCut(name, AliRsnCut::kDaughter, min, max),
29    fInitialized(kFALSE),
30    fRejectOutside(rejectOutside),
31    fMomMin(0.0),
32    fMomMax(1E+20),
33    fRefType(type),
34    fESDpid(),
35    fAODpid()
36 {
37 //
38 // Main constructor.
39 //
40 }
41
42 //_________________________________________________________________________________________________
43 AliRsnCutPIDTPC::AliRsnCutPIDTPC
44 (const AliRsnCutPIDTPC& copy) :
45    AliRsnCut(copy),
46    fInitialized(kFALSE),
47    fRejectOutside(copy.fRejectOutside),
48    fMomMin(copy.fMomMin),
49    fMomMax(copy.fMomMax),
50    fRefType(copy.fRefType),
51    fESDpid(copy.fESDpid),
52    fAODpid(copy.fAODpid)
53 {
54 //
55 // Copy constructor.
56 //
57 }
58
59 //_________________________________________________________________________________________________
60 AliRsnCutPIDTPC& AliRsnCutPIDTPC::operator=(const AliRsnCutPIDTPC& copy)
61 {
62 //
63 // Assignment operator
64 //
65
66    AliRsnCut::operator=(copy);
67
68    fInitialized   = kFALSE;
69    fRejectOutside = copy.fRejectOutside;
70    fMomMin        = copy.fMomMin;
71    fMomMax        = copy.fMomMax;
72    fRefType       = copy.fRefType;
73    fESDpid        = copy.fESDpid;
74    fAODpid        = copy.fAODpid;
75
76    return (*this);
77 }
78
79 //_________________________________________________________________________________________________
80 void AliRsnCutPIDTPC::SetBBParam(Double_t p0, Double_t p1, Double_t p2, Double_t p3, Double_t p4)
81 {
82 //
83 // Properly set the Bethe-Bloch parameters in all places where it is needed.
84 //
85
86    fESDpid.GetTPCResponse().SetBetheBlochParameters(p0, p1, p2, p3, p4);
87    fAODpid.GetTPCResponse().SetBetheBlochParameters(p0, p1, p2, p3, p4);
88 }
89
90 //_________________________________________________________________________________________________
91 Bool_t AliRsnCutPIDTPC::IsSelected(TObject *object)
92 {
93 //
94 // Cut checker.
95 //
96
97    // initialize if needed
98    if (!fInitialized) Initialize();
99
100    // coherence check
101    if (!TargetOK(object)) return kFALSE;
102
103    // reject not TPC tracks
104    AliVTrack *vtrack = dynamic_cast<AliVTrack*>(fDaughter->GetRef());
105    if (!vtrack) return kFALSE;
106    if (!IsTPC(vtrack)) {
107       AliDebug(AliLog::kDebug + 2, "Track is not found in TPC");
108       return kFALSE;
109    }
110
111    // common evaluation variables
112    Double_t     mom;
113    AliESDtrack *esdTrack = fDaughter->GetRefESDtrack();
114    AliAODTrack *aodTrack = fDaughter->GetRefAODtrack();
115
116    // get inner momentum, needed for BB computation
117    if (esdTrack)
118       mom = esdTrack->GetInnerParam()->P();
119    else if (aodTrack)
120       mom = aodTrack->GetDetPid()->GetTPCmomentum();
121    else {
122       AliDebug(AliLog::kDebug + 2, Form("Impossible to process an object of type '%s'. Cut applicable only to ESD/AOD tracks", fDaughter->GetRef()->ClassName()));
123       return kFALSE;
124    }
125
126    // assign PID nsigmas to default cut check value
127    // since bad object types are rejected before, here we have an ESD track or AOD track
128    if (esdTrack)
129       fCutValueD = fESDpid.GetTPCResponse().GetNumberOfSigmas(mom, esdTrack->GetTPCsignal(), esdTrack->GetTPCsignalN(), fRefType);
130    else
131       fCutValueD = fAODpid.NumberOfSigmasTPC(aodTrack, fRefType);
132
133    // use AliRsnCut default method to check cut
134    Bool_t cutCheck = OkRangeD();
135
136    // now check the momentum:
137    // -- if it stays inside the accepted range, track just checked
138    //    with respect to the nsigma band
139    // -- if it stays outside the accepted range and 'fRejectOutside' is kTRUE,
140    //    track is always rejected, while if 'fRejectOutside' is kFALSE,
141    //    track is accepted if it stays inside the nsigma band
142    if ((mom >= fMomMin && mom <= fMomMax))
143       return cutCheck;
144    else {
145       AliDebug(AliLog::kDebug + 2, Form("Track momentum = %.5f, outside allowed range", mom));
146       return ((!fRejectOutside) && cutCheck);
147    }
148 }
149
150 //_________________________________________________________________________________________________
151 void AliRsnCutPIDTPC::Print(const Option_t *) const
152 {
153 //
154 // Print information on this cut
155 //
156
157    AliInfo(Form("Cut name                    : %s", GetName()));
158    AliInfo(Form("--> cut range (nsigma)      : %.3f %.3f", fMinD, fMaxD));
159    AliInfo(Form("--> momentum range          : %.3f %.3f", fMomMin, fMomMax));
160    AliInfo(Form("--> tracks outside range are: %s", (fRejectOutside ? "rejected" : "accepted")));
161 }
162
163 //_________________________________________________________________________________________________
164 void AliRsnCutPIDTPC::Initialize()
165 {
166 //
167 // Initialize ESD pid object from global one
168 //
169
170    AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
171    AliESDInputHandler *handler = dynamic_cast<AliESDInputHandler*>(mgr->GetInputEventHandler());
172    if (handler) {
173       AliESDpid *pid = handler->GetESDpid();
174       fESDpid = (*pid);
175    }
176
177    fInitialized = kTRUE;
178 }