]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PWGLF/RESONANCES/AliRsnCutTrackQuality.cxx
Bug fix for MC mother label
[u/mrichter/AliRoot.git] / PWGLF / RESONANCES / AliRsnCutTrackQuality.cxx
CommitLineData
35e49ca5 1//
2// Class AliRsnCutTrackQuality
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#include <TFormula.h>
21#include <TBits.h>
22
23#include "AliLog.h"
35e49ca5 24#include "AliESDtrackCuts.h"
25
26#include "AliRsnEvent.h"
27#include "AliRsnDaughter.h"
28#include "AliRsnCutTrackQuality.h"
29
30ClassImp(AliRsnCutTrackQuality)
31
32//_________________________________________________________________________________________________
33AliRsnCutTrackQuality::AliRsnCutTrackQuality(const char *name) :
f34f960b 34 AliRsnCut(name, AliRsnTarget::kDaughter, 0.0, 0.0),
2a1c7696 35 fFlagsOn(0x0),
36 fFlagsOff(0x0),
37 fRejectKinkDaughters(kTRUE),
38 fDCARfixed(kTRUE),
39 fDCARptFormula(""),
d7712d44 40 fDCARmax(1E20),
2a1c7696 41 fDCAZfixed(kTRUE),
42 fDCAZptFormula(""),
d7712d44 43 fDCAZmax(1E20),
2a1c7696 44 fSPDminNClusters(0),
45 fITSminNClusters(0),
d7712d44 46 fITSmaxChi2(1E20),
2a1c7696 47 fTPCminNClusters(0),
f34f960b 48 fTPCmaxChi2(1E20),
49 fAODTestFilterBit(-1)
35e49ca5 50{
51//
52// Default constructor.
53// Initializes all cuts in such a way that all of them are disabled.
54//
55
d7712d44 56 SetPtRange(0.0, 1E20);
57 SetEtaRange(-1E20, 1E20);
35e49ca5 58}
59
60//_________________________________________________________________________________________________
61AliRsnCutTrackQuality::AliRsnCutTrackQuality(const AliRsnCutTrackQuality &copy) :
2a1c7696 62 AliRsnCut(copy),
63 fFlagsOn(copy.fFlagsOn),
64 fFlagsOff(copy.fFlagsOff),
65 fRejectKinkDaughters(copy.fRejectKinkDaughters),
66 fDCARfixed(copy.fDCARfixed),
67 fDCARptFormula(copy.fDCARptFormula),
68 fDCARmax(copy.fDCARmax),
69 fDCAZfixed(copy.fDCAZfixed),
70 fDCAZptFormula(copy.fDCAZptFormula),
71 fDCAZmax(copy.fDCAZmax),
72 fSPDminNClusters(copy.fSPDminNClusters),
73 fITSminNClusters(copy.fITSminNClusters),
74 fITSmaxChi2(copy.fITSmaxChi2),
75 fTPCminNClusters(copy.fTPCminNClusters),
f34f960b 76 fTPCmaxChi2(copy.fTPCmaxChi2),
77 fAODTestFilterBit(copy.fAODTestFilterBit)
35e49ca5 78{
79//
80// Copy constructor.
81// Just copy all data member values.
82//
83
2a1c7696 84 SetPtRange(copy.fPt[0], copy.fPt[1]);
85 SetEtaRange(copy.fEta[0], copy.fEta[1]);
35e49ca5 86}
87
88//_________________________________________________________________________________________________
61f275d1 89AliRsnCutTrackQuality &AliRsnCutTrackQuality::operator=(const AliRsnCutTrackQuality &copy)
35e49ca5 90{
91//
92// Assignment operator.
93// Just copy all data member values.
94//
95
61f275d1 96 if (this == &copy)
97 return *this;
98
2a1c7696 99 fFlagsOn = copy.fFlagsOn;
100 fFlagsOff = copy.fFlagsOff;
101 fRejectKinkDaughters = copy.fRejectKinkDaughters;
102 fDCARfixed = copy.fDCARfixed;
103 fDCARptFormula = copy.fDCARptFormula;
104 fDCARmax = copy.fDCARmax;
105 fDCAZfixed = copy.fDCAZfixed;
106 fDCAZptFormula = copy.fDCAZptFormula;
107 fDCAZmax = copy.fDCAZmax;
108 fSPDminNClusters = copy.fSPDminNClusters;
109 fITSminNClusters = copy.fITSminNClusters;
110 fITSmaxChi2 = copy.fITSmaxChi2;
111 fTPCminNClusters = copy.fTPCminNClusters;
112 fTPCmaxChi2 = copy.fTPCmaxChi2;
f34f960b 113 fAODTestFilterBit = copy.fAODTestFilterBit;
2a1c7696 114
115 SetPtRange(copy.fPt[0], copy.fPt[1]);
116 SetEtaRange(copy.fEta[0], copy.fEta[1]);
117
118 return (*this);
35e49ca5 119}
120
121//_________________________________________________________________________________________________
122void AliRsnCutTrackQuality::DisableAll()
123{
124//
125// Disable all cuts
126//
2a1c7696 127
128 fFlagsOn = 0x0;
129 fFlagsOff = 0x0;
130 fRejectKinkDaughters = kFALSE;
131 fDCARfixed = kTRUE;
132 fDCARptFormula = "";
d7712d44 133 fDCARmax = 1E20;
2a1c7696 134 fDCAZfixed = kTRUE;
135 fDCAZptFormula = "";
d7712d44 136 fDCAZmax = 1E20;
2a1c7696 137 fSPDminNClusters = 0;
138 fITSminNClusters = 0;
d7712d44 139 fITSmaxChi2 = 1E20;
2a1c7696 140 fTPCminNClusters = 0;
d7712d44 141 fTPCmaxChi2 = 1E20;
f34f960b 142 fAODTestFilterBit = -1;
2a1c7696 143
d7712d44 144 SetPtRange(0.0, 1E20);
145 SetEtaRange(-1E20, 1E20);
35e49ca5 146}
147
148//_________________________________________________________________________________________________
149Bool_t AliRsnCutTrackQuality::IsSelected(TObject *object)
150{
151//
152// Cut checker.
153// Checks the type of object being evaluated
154// and then calls the appropriate sub-function (for ESD or AOD)
155//
156
2a1c7696 157 // coherence check
158 if (!TargetOK(object)) return kFALSE;
159
160 // status is checked in the same way for all tracks, using AliVTrack
161 // as a convention, if a the collection of 'on' flags is '0x0', it
162 // is assumed that no flags are required, and this check is skipped;
163 // for the collection of 'off' flags this is not needed
f34f960b 164 AliVTrack *vtrack = fDaughter->Ref2Vtrack();
2a1c7696 165 if (!vtrack) {
f34f960b 166 AliDebug(AliLog::kDebug + 2, "This object is not either an ESD nor AOD track");
2a1c7696 167 return kFALSE;
168 }
169 ULong_t status = (ULong_t)vtrack->GetStatus();
170 ULong_t checkOn = status & fFlagsOn;
171 ULong_t checkOff = status & fFlagsOff;
172 if (fFlagsOn != 0x0 && checkOn != fFlagsOn) {
f34f960b 173 AliDebug(AliLog::kDebug + 2, Form("Failed flag check: required %s", Binary(fFlagsOn)));
174 AliDebug(AliLog::kDebug + 2, Form(" track has %s", Binary(status )));
2a1c7696 175 return kFALSE;
176 }
177 if (checkOff != 0) {
f34f960b 178 AliDebug(AliLog::kDebug + 2, Form("Failed flag check: forbidden %s", Binary(fFlagsOff)));
179 AliDebug(AliLog::kDebug + 2, Form(" track has %s", Binary(status )));
2a1c7696 180 return kFALSE;
181 }
f34f960b 182 AliDebug(AliLog::kDebug + 3, Form("Flag check OK: required %s", Binary(fFlagsOn)));
183 AliDebug(AliLog::kDebug + 3, Form(" forbidden %s", Binary(fFlagsOff)));
184 AliDebug(AliLog::kDebug + 3, Form(" track has %s", Binary(status )));
2a1c7696 185
186 // retrieve real object type
f34f960b 187 AliESDtrack *esdTrack = fDaughter->Ref2ESDtrack();
188 AliAODTrack *aodTrack = fDaughter->Ref2AODtrack();
2a1c7696 189 if (esdTrack) {
190 AliDebug(AliLog::kDebug + 2, "Checking an ESD track");
191 return CheckESD(esdTrack);
192 } else if (aodTrack) {
193 AliDebug(AliLog::kDebug + 2, "Checking an AOD track");
194 return CheckAOD(aodTrack);
195 } else {
196 AliDebug(AliLog::kDebug + 2, Form("This object is not either an ESD nor AOD track, it is an %s", fDaughter->GetRef()->ClassName()));
197 return kFALSE;
198 }
35e49ca5 199}
200
201//_________________________________________________________________________________________________
202Bool_t AliRsnCutTrackQuality::CheckESD(AliESDtrack *track)
203{
204//
205// Check an ESD track.
206// This is done using the default track checker for ESD.
207// It is declared static, not to recreate it every time.
208//
209
2a1c7696 210 static AliESDtrackCuts cuts;
211
212 // general acceptance/pt cuts
213 cuts.SetPtRange(fPt[0], fPt[1]);
214 cuts.SetEtaRange(fEta[0], fEta[1]);
215
216 // transverse DCA cuts
217 if (fDCARfixed)
218 cuts.SetMaxDCAToVertexXY(fDCARmax);
219 else
220 cuts.SetMaxDCAToVertexXYPtDep(fDCARptFormula.Data());
221
222 // longitudinal DCA cuts
223 if (fDCAZfixed)
224 cuts.SetMaxDCAToVertexZ(fDCAZmax);
225 else
226 cuts.SetMaxDCAToVertexZPtDep(fDCAZptFormula.Data());
227
228 // these options are always disabled in current version
229 cuts.SetDCAToVertex2D(kFALSE);
230 cuts.SetRequireSigmaToVertex(kFALSE);
231
232 // TPC related cuts for TPC+ITS tracks
233 cuts.SetMinNClustersTPC(fTPCminNClusters);
234 cuts.SetMaxChi2PerClusterTPC(fTPCmaxChi2);
235 cuts.SetAcceptKinkDaughters(!fRejectKinkDaughters);
236
237 // ITS related cuts for TPC+ITS tracks
238 if (fSPDminNClusters > 0)
239 cuts.SetClusterRequirementITS(AliESDtrackCuts::kSPD, AliESDtrackCuts::kAny);
240
241 // now that all is initialized, do the check
242 return cuts.IsSelected(track);
35e49ca5 243}
244
245//_________________________________________________________________________________________________
246Bool_t AliRsnCutTrackQuality::CheckAOD(AliAODTrack *track)
247{
248//
249// Check an AOD track.
250// This is done doing directly all checks, since there is not
251// an equivalend checker for AOD tracks
252//
2a1c7696 253
f34f960b 254 // if a test bit is used, check it and skip the following
255 if (fAODTestFilterBit >= 0) {
e5ebff7e 256 UInt_t bit = 1 << fAODTestFilterBit;
f34f960b 257 AliDebugClass(2, Form("Required a test filter bit for AOD check: %u (result: %s)", bit, (track->TestFilterBit(bit) ? "accept" : "reject")));
61f275d1 258 if (!track->TestFilterBit(bit))
f34f960b 259 return kFALSE;
260 else {
261 if (track->Pt() < fPt[0] || track->Pt() > fPt[1]) return kFALSE;
262 if (track->Eta() < fEta[0] || track->Eta() > fEta[1]) return kFALSE;
263 return kTRUE;
264 }
265 }
61f275d1 266
d7712d44 267 // try to retrieve the reference AOD event
268 AliAODEvent *aodEvent = 0x0;
269 if (fEvent) aodEvent = fEvent->GetRefAOD();
270 if (!aodEvent) {
271 AliError("AOD reference event is not initialized!");
272 return kFALSE;
273 }
274
2a1c7696 275 // step #0: check SPD and ITS clusters
276 Int_t nSPD = 0;
277 nSPD = TESTBIT(track->GetITSClusterMap(), 0);
278 nSPD += TESTBIT(track->GetITSClusterMap(), 1);
279 if (nSPD < fSPDminNClusters) {
280 AliDebug(AliLog::kDebug + 2, "Not enough SPD clusters in this track. Rejected");
35e49ca5 281 return kFALSE;
2a1c7696 282 }
283
284 // step #1: check number of clusters in TPC
285 if (track->GetTPCNcls() < fTPCminNClusters) {
286 AliDebug(AliLog::kDebug + 2, "Too few TPC clusters. Rejected");
287 return kFALSE;
288 }
289 if (track->GetITSNcls() < fITSminNClusters) {
290 AliDebug(AliLog::kDebug + 2, "Too few ITS clusters. Rejected");
291 return kFALSE;
292 }
293
294 // step #2: check chi square
295 if (track->Chi2perNDF() > fTPCmaxChi2) {
296 AliDebug(AliLog::kDebug + 2, "Bad chi2. Rejected");
297 return kFALSE;
298 }
299 if (track->Chi2perNDF() > fITSmaxChi2) {
300 AliDebug(AliLog::kDebug + 2, "Bad chi2. Rejected");
301 return kFALSE;
302 }
303
304 // step #3: reject kink daughters
305 AliAODVertex *vertex = track->GetProdVertex();
306 if (vertex && fRejectKinkDaughters) {
307 if (vertex->GetType() == AliAODVertex::kKink) {
308 AliDebug(AliLog::kDebug + 2, "Kink daughter. Rejected");
309 return kFALSE;
310 }
311 }
312
313 // step #4: DCA cut (transverse)
c865cb1d 314 // --> reject all tracks not ITS refitted
2a1c7696 315 Double_t b[2], cov[3];
d7712d44 316 vertex = aodEvent->GetPrimaryVertex();
2a1c7696 317 if (!vertex) {
318 AliDebug(AliLog::kDebug + 2, "NULL vertex");
319 return kFALSE;
320 }
c865cb1d 321 if ((track->GetStatus() & AliESDtrack::kITSrefit) == 0) {
322 AliDebug(AliLog::kDebug + 2, "Not ITS refitted");
323 return kFALSE;
324 }
d7712d44 325 if (!track->PropagateToDCA(vertex, aodEvent->GetMagneticField(), kVeryBig, b, cov)) {
2a1c7696 326 AliDebug(AliLog::kDebug + 2, "Failed propagation to vertex");
327 return kFALSE;
328 }
329 // if the DCA cut is not fixed, compute current value
330 if (!fDCARfixed) {
331 static TString str(fDCARptFormula);
332 str.ReplaceAll("pt", "x");
333 static const TFormula dcaXY(Form("%s_dcaXY", GetName()), str.Data());
334 fDCARmax = dcaXY.Eval(track->Pt());
335 }
336 // check the cut
337 if (TMath::Abs(b[0]) > fDCARmax) {
338 AliDebug(AliLog::kDebug + 2, "Too large transverse DCA");
339 return kFALSE;
340 }
341
342 // step #5: DCA cut (longitudinal)
343 // the DCA has already been computed above
344 // if the DCA cut is not fixed, compute current value
345 if (!fDCAZfixed) {
346 static TString str(fDCAZptFormula);
347 str.ReplaceAll("pt", "x");
348 static const TFormula dcaZ(Form("%s_dcaXY", GetName()), str.Data());
349 fDCAZmax = dcaZ.Eval(track->Pt());
350 }
351 // check the cut
352 if (TMath::Abs(b[1]) > fDCAZmax) {
353 AliDebug(AliLog::kDebug + 2, "Too large longitudinal DCA");
354 return kFALSE;
355 }
356
357 // step #6: check eta/pt range
358 if (track->Eta() < fEta[0] || track->Eta() > fEta[1]) {
359 AliDebug(AliLog::kDebug + 2, "Outside ETA acceptance");
360 return kFALSE;
361 }
362 if (track->Pt() < fPt[0] || track->Pt() > fPt[1]) {
363 AliDebug(AliLog::kDebug + 2, "Outside PT acceptance");
364 return kFALSE;
365 }
366
367 // if we are here, all cuts were passed and no exit point was got
c865cb1d 368 AliDebug(AliLog::kDebug + 2, "============================= ACCEPTED TRACK =====================================================");
2a1c7696 369 return kTRUE;
35e49ca5 370}
a909ffad 371
372//_________________________________________________________________________________________________
373void AliRsnCutTrackQuality::Print(const Option_t *) const
374{
375//
376// Print information on this cut
377//
378
2a1c7696 379 AliInfo(Form("Cut name : %s", GetName()));
380 AliInfo(Form("Required flags (off, on): %lx %lx", fFlagsOn, fFlagsOff));
381 AliInfo(Form("Ranges in eta, pt : %.2f - %.2f, %.2f - %.2f", fEta[0], fEta[1], fPt[0], fPt[1]));
382 AliInfo(Form("Kink daughters are : %s", (fRejectKinkDaughters ? "rejected" : "accepted")));
383 AliInfo(Form("TPC requirements : min. cluster = %d, max chi2 = %f", fTPCminNClusters, fTPCmaxChi2));
384 AliInfo(Form("ITS requirements : min. cluster = %d (all), %d (SPD), max chi2 = %f", fITSminNClusters, fSPDminNClusters, fITSmaxChi2));
385
386 if (fDCARfixed) {
387 AliInfo(Form("DCA r cut : fixed to %f cm", fDCARmax));
388 } else {
389 AliInfo(Form("DCA r cut formula : %s", fDCARptFormula.Data()));
390 }
391
392 if (fDCAZfixed) {
393 AliInfo(Form("DCA z cut : fixed to %f cm", fDCAZmax));
394 } else {
395 AliInfo(Form("DCA z cut formula : %s", fDCAZptFormula.Data()));
396 }
a909ffad 397}