]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWG2/RESONANCES/AliRsnCutESD2010.cxx
2dc17e2dd0a9ab3ed1a89a1da41aa1ff144297f3
[u/mrichter/AliRoot.git] / PWG2 / RESONANCES / AliRsnCutESD2010.cxx
1 //
2 // Class AliRsnCutESD2010
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 <Riostream.h>
20
21 #include "AliESDpid.h"
22 #include "AliTOFT0maker.h"
23 #include "AliTOFcalib.h"
24 #include "AliCDBManager.h"
25 #include "AliITSPIDResponse.h"
26
27 #include "AliRsnEvent.h"
28 #include "AliRsnDaughter.h"
29 #include "AliRsnCutESD2010.h"
30
31 ClassImp(AliRsnCutESD2010)
32
33 //_________________________________________________________________________________________________
34 AliRsnCutESD2010::AliRsnCutESD2010
35 (const char *name, Bool_t isMC) :
36    AliRsnCut(name, AliRsnCut::kDaughter, 0.0, 0.0),
37    fIsMC(isMC),
38    fCheckITS(kTRUE),
39    fCheckTPC(kTRUE),
40    fCheckTOF(kTRUE),
41    fUseITSTPC(kTRUE),
42    fUseITSSA(kTRUE),
43    fPID(AliPID::kKaon),
44    fMaxITSPIDmom(0.0),
45    fMaxITSband(3.0),
46    fTPCpLimit(0.35),
47    fMinTPCband(3.0),
48    fMaxTPCband(5.0),
49    fESDpid(),
50    fESDtrackCutsTPC(),
51    fESDtrackCutsITS(),
52    fMinTOF(-3.0),
53    fMaxTOF(3.0)
54 {
55 //
56 // Main constructor.
57 //
58
59    SetMC(isMC);
60 }
61
62 //_________________________________________________________________________________________________
63 AliRsnCutESD2010::AliRsnCutESD2010
64 (const AliRsnCutESD2010& copy) :
65    AliRsnCut(copy),
66    fIsMC(copy.fIsMC),
67    fCheckITS(copy.fCheckITS),
68    fCheckTPC(copy.fCheckTPC),
69    fCheckTOF(copy.fCheckTOF),
70    fUseITSTPC(copy.fUseITSTPC),
71    fUseITSSA(copy.fUseITSSA),
72    fPID(copy.fPID),
73    fMaxITSPIDmom(copy.fMaxITSPIDmom),
74    fMaxITSband(copy.fMaxITSband),
75    fTPCpLimit(copy.fTPCpLimit),
76    fMinTPCband(copy.fMinTPCband),
77    fMaxTPCband(copy.fMaxTPCband),
78    fESDpid(copy.fESDpid),
79    fESDtrackCutsTPC(copy.fESDtrackCutsTPC),
80    fESDtrackCutsITS(copy.fESDtrackCutsITS),
81    fMinTOF(copy.fMinTOF),
82    fMaxTOF(copy.fMaxTOF)
83 {
84 //
85 // Copy constructor.
86 //
87
88    SetMC(copy.fIsMC);
89
90    Int_t i = 0;
91    for (i = 0; i < 5; i++) fTPCpar[i] = copy.fTPCpar[i];
92 }
93
94 //_________________________________________________________________________________________________
95 AliRsnCutESD2010& AliRsnCutESD2010::operator=(const AliRsnCutESD2010& copy)
96 {
97 //
98 // Assignment operator
99 //
100
101    AliRsnCut::operator=(copy);
102
103    SetMC(copy.fIsMC);
104
105    fCheckITS = copy.fCheckITS;
106    fCheckTPC = copy.fCheckTPC;
107    fCheckTOF = copy.fCheckTOF;
108    fUseITSTPC = copy.fUseITSTPC;
109    fUseITSSA = copy.fUseITSSA;
110    fPID = copy.fPID;
111    fMaxITSPIDmom = copy.fMaxITSPIDmom;
112    fMaxITSband = copy.fMaxITSband;
113    fTPCpLimit = copy.fTPCpLimit;
114    fMinTPCband = copy.fMinTPCband;
115    fMaxTPCband = copy.fMaxTPCband;
116    fMinTOF = copy.fMinTOF;
117    fMaxTOF = copy.fMaxTOF;
118    fESDpid = copy.fESDpid;
119
120    Int_t i = 0;
121    for (i = 0; i < 5; i++) fTPCpar[i] = copy.fTPCpar[i];
122
123
124    fESDtrackCutsTPC = copy.fESDtrackCutsTPC;
125    fESDtrackCutsITS = copy.fESDtrackCutsITS;
126
127    return (*this);
128 }
129
130 //_________________________________________________________________________________________________
131 void AliRsnCutESD2010::SetMC(Bool_t isMC)
132 {
133 //
134 // Sets some aspects of cuts depending on the fact that runs on MC or not
135 //
136
137    fIsMC = isMC;
138
139    AliITSPIDResponse itsresponse(fIsMC);
140    fESDpid.GetITSResponse() = itsresponse;
141 }
142
143 //_________________________________________________________________________________________________
144 Bool_t AliRsnCutESD2010::IsSelected(TObject *object)
145 {
146 //
147 // Cut checker.
148 //
149
150    // coherence check: require an ESD track
151    AliRsnDaughter *daughter = dynamic_cast<AliRsnDaughter*>(object);
152    if (!daughter) return kFALSE;
153    AliESDtrack *track = daughter->GetRefESDtrack();
154    if (!track) return kFALSE;
155
156    // if no reference event, skip
157    AliRsnEvent *rsn = AliRsnTarget::GetCurrentEvent();
158    if (!rsn) return kFALSE;
159    fESDpid.SetTOFResponse(rsn->GetRefESD(), AliESDpid::kTOF_T0);
160
161    // check quality and track type and reject tracks not passing this step
162    if (!OkQuality(track)) {
163       AliDebug(AliLog::kDebug + 2, "Failed quality cut");
164       return kFALSE;
165    }
166
167    // ITS PID can be checked always
168    // if PID is not required, the flag is sed as
169    // if the cut was alsways passed
170    Bool_t okITSpid = OkITSPID(track);
171    if (!fCheckITS) okITSpid = kTRUE;
172
173    // TPC PID can be checked only for TPC+ITS tracks
174    // if PID is not required, the flag is sed as
175    // if the cut was alsways passed
176    Bool_t okTPCpid = kFALSE;
177    if (IsITSTPC(track)) okTPCpid = OkTPCPID(track);
178    if (!fCheckTPC) okTPCpid = kTRUE;
179
180    // TOF PID can be checked only if TOF is matched
181    // if PID is not required, the flag is sed as
182    // if the cut was alsways passed
183    Bool_t okTOFpid = kFALSE;
184    if (IsITSTPC(track) && MatchTOF(track)) okTOFpid = OkTOFPID(track);
185    if (!fCheckTOF) okTOFpid = kTRUE;
186
187    // now combine all outcomes according to the different possibilities:
188    // -- ITS standalone:
189    //    --> only ITS PID, always
190    // -- ITS + TPC:
191    //    --> ITS PID, only for momenta lower than 'fMaxITSPIDmom' and when the ITSpid flag is active
192    //    --> TPC PID, always --> MASTER (first to be checked, if fails, track is rejected)
193    //    --> TOF PID, only if matched
194    if (IsITSSA(track)) {
195       if (!okITSpid) {
196          AliDebug(AliLog::kDebug + 2, "ITS standalone track --> ITS PID failed");
197          return kFALSE;
198       }
199    } else { // checking IsITSTPC() is redundant due to OkQuality() cut check
200       if (!okTPCpid) {
201          AliDebug(AliLog::kDebug + 2, "ITS+TPC track --> TPC PID failed");
202          return kFALSE;
203       } else if (MatchTOF(track) && !okTOFpid) {
204          AliDebug(AliLog::kDebug + 2, "ITS+TPC track --> TOF matched but TOF PID failed");
205          return kFALSE;
206       } else if (track->IsOn(AliESDtrack::kITSpid) && track->P() <= fMaxITSPIDmom && !okITSpid) {
207          AliDebug(AliLog::kDebug + 2, Form("ITS+TPC track --> Momentum lower than limit (%.2f) and ITS PID failed", fMaxITSPIDmom));
208          return kFALSE;
209       }
210    }
211
212    // arriving here, the track has survived all checks
213    return kTRUE;
214 }
215
216 //______________________________________________________________________________
217 Bool_t AliRsnCutESD2010::OkQuality(AliESDtrack *track)
218 {
219 //
220 // Check track quality parameters.
221 // Rejects all tracks which are not either TPC+ITS nor ITS standalone.
222 // If tracks of any type are not flagged to be used, they are rejected anyway.
223 //
224
225    if (IsITSTPC(track)) return (fUseITSTPC && fESDtrackCutsTPC.IsSelected(track));
226    if (IsITSSA(track)) return (fUseITSSA  && fESDtrackCutsITS.IsSelected(track));
227
228    return kFALSE;
229 }
230
231 //______________________________________________________________________________
232 Bool_t AliRsnCutESD2010::OkITSPID(AliESDtrack *track)
233 {
234 //
235 // Check ITS particle identification with 3sigma cut
236 //
237
238    // count PID layers and reject if they are too few
239    Int_t   k, nITSpidLayers = 0;
240    UChar_t itsCluMap = track->GetITSClusterMap();
241    for (k = 2; k < 6; k++) if (itsCluMap & (1 << k)) ++nITSpidLayers;
242    if (nITSpidLayers < 3) {
243       AliDebug(AliLog::kDebug + 2, "Rejecting track with too few ITS pid layers");
244       return kFALSE;
245    }
246
247    // check the track type (ITS+TPC or ITS standalone)
248    // and reject it if it is of none of the allowed types
249    Bool_t isSA = kFALSE;
250    if (IsITSTPC(track)) isSA = kFALSE;
251    else if (IsITSSA(track)) isSA = kTRUE;
252    else {
253       AliWarning("Track is neither ITS+TPC nor ITS standalone");
254       return kFALSE;
255    }
256
257    // create the PID response object and compute nsigma
258    AliITSPIDResponse &itsrsp = fESDpid.GetITSResponse();
259    Double_t mom    = track->P();
260    Double_t nSigma = itsrsp.GetNumberOfSigmas(mom, track->GetITSsignal(), fPID, nITSpidLayers, isSA);
261
262    // evaluate the cut
263    Bool_t ok = (TMath::Abs(nSigma) <= fMaxITSband);
264
265    // debug message
266    AliDebug(AliLog::kDebug + 2, Form("ITS nsigma = %f -- max = %f -- cut %s", nSigma, fMaxITSband, (ok ? "passed" : "failed")));
267
268    // outcome
269    return ok;
270 }
271
272 //______________________________________________________________________________
273 Bool_t AliRsnCutESD2010::OkTPCPID(AliESDtrack *track)
274 {
275 //
276 // Check TPC particle identification with {3|5}sigmacut,
277 // depending on the track total momentum.
278 //
279
280    // setup TPC PID response
281    AliTPCPIDResponse &tpcrsp = fESDpid.GetTPCResponse();
282    //tpcrsp.SetBetheBlochParameters(fTPCpar[0],fTPCpar[1],fTPCpar[2],fTPCpar[3],fTPCpar[4]);
283
284    // get momentum and number of sigmas and choose the reference band
285    Double_t mom       = track->GetInnerParam()->P();
286    Double_t nSigma    = tpcrsp.GetNumberOfSigmas(mom, track->GetTPCsignal(), track->GetTPCsignalN(), fPID);
287    Double_t maxNSigma = fMaxTPCband;
288    if (mom < fTPCpLimit) maxNSigma = fMinTPCband;
289
290    // evaluate the cut
291    Bool_t ok = (TMath::Abs(nSigma) <= maxNSigma);
292
293    // debug message
294    AliDebug(AliLog::kDebug + 2, Form("TPC nsigma = %f -- max = %f -- cut %s", nSigma, maxNSigma, (ok ? "passed" : "failed")));
295
296    // outcome
297    return ok;
298 }
299
300 //______________________________________________________________________________
301 Bool_t AliRsnCutESD2010::OkTOFPID(AliESDtrack *track)
302 {
303 //
304 // Check TOF particle identification if matched there.
305 //
306
307    // reject not TOF-matched tracks
308    if (!MatchTOF(track)) return kFALSE;
309
310    // setup TOF PID response
311    AliTOFPIDResponse &tofrsp = fESDpid.GetTOFResponse();
312
313    // get info for computation
314    Double_t momentum = track->P();
315    Double_t time     = track->GetTOFsignal();
316    Double_t timeint[AliPID::kSPECIES];
317    tofrsp.GetStartTime(momentum);
318    track->GetIntegratedTimes(timeint);
319
320    // check the cut
321    Double_t timeDiff = time - timeint[(Int_t)fPID];
322    Double_t sigmaRef = tofrsp.GetExpectedSigma(momentum, timeint[(Int_t)fPID], AliPID::ParticleMass(fPID));
323    Double_t nSigma   = timeDiff / sigmaRef;
324
325    // evaluate the cut
326    Bool_t ok = (nSigma >= fMinTOF && nSigma <= fMaxTOF);
327
328    // debug message
329    AliDebug(AliLog::kDebug + 2, Form("TOF nsigma = %f -- range = %f - %f -- cut %s", nSigma, fMinTOF, fMaxTOF, (ok ? "passed" : "failed")));
330
331    // outcome
332    return ok;
333 }
334
335 //_________________________________________________________________________________________________
336 void AliRsnCutESD2010::Print(const Option_t *) const
337 {
338 //
339 // Print information on this cut
340 //
341
342    AliInfo(Form("Cut name               : %s", GetName()));
343    AliInfo(Form("Using MC settings      : %s", (fIsMC ? "YES" : "NO")));
344    AliInfo(Form("Using TPC+ITS tracks   : %s", (fUseITSTPC ? "YES" : "NO")));
345    AliInfo(Form("Using ITS SA  tracks   : %s", (fUseITSSA ? "YES" : "NO")));
346    AliInfo(Form("Check ITS PID          : %s", (fCheckITS ? "YES" : "NO")));
347    AliInfo(Form("Check TPC PID          : %s", (fCheckTPC ? "YES" : "NO")));
348    AliInfo(Form("Check TOF PID          : %s", (fCheckTOF ? "YES" : "NO")));
349    AliInfo(Form("Reference particle     : %s", AliPID::ParticleName(fPID)));
350    AliInfo(Form("ITS PID range  (sigmas): %f", fMaxITSband));
351    AliInfo(Form("ITS PID range  (pt)    : %f", fMaxITSPIDmom));
352    AliInfo(Form("TPC PID ranges (sigmas): %f %f", fMinTPCband, fMaxTPCband));
353    AliInfo(Form("TPC PID limit  (p)     : %f", fTPCpLimit));
354    AliInfo(Form("TOF range (sigmas)     : %f - %f", fMinTOF, fMaxTOF));
355 }