]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWG2/RESONANCES/AliRsnAnalysisEffSE.cxx
Added pass1 and pass2 directories
[u/mrichter/AliRoot.git] / PWG2 / RESONANCES / AliRsnAnalysisEffSE.cxx
1 //
2 // Class AliRsnAnalysisEffSE
3 //
4 // TODO
5 // TODO
6 //
7 // authors: Alberto Pulvirenti (alberto.pulvirenti@ct.infn.it)
8 //          Martin Vala (martin.vala@cern.ch)
9 //
10 #include <Riostream.h>
11 #include "AliStack.h"
12 #include "AliESDEvent.h"
13 #include "AliAODEvent.h"
14 #include "AliMCEvent.h"
15
16 #include "AliCFContainer.h"
17 #include "AliRsnCutManager.h"
18 #include "AliRsnValue.h"
19 #include "AliRsnAnalysisEffSE.h"
20 #include "AliRsnPairDef.h"
21 #include "AliRsnCutSet.h"
22
23 ClassImp(AliRsnAnalysisEffSE)
24
25 //_____________________________________________________________________________
26 AliRsnAnalysisEffSE::AliRsnAnalysisEffSE(const char *name) :
27    AliRsnVAnalysisTaskSE(name),
28    fUseITSSA(kTRUE),
29    fUseGlobal(kTRUE),
30    fStepListMC(0),
31    fStepListESD(0),
32    fAxisList("AliRsnValue", 0),
33    fPairDefList(0),
34    fContainerList(0x0),
35    fOutList(0x0),
36    fVar(0),
37    fPair(),
38    fEventCuts("eventCuts", AliRsnCut::kEvent)
39 {
40 //
41 // Default constructor.
42 //
43
44    AliDebug(AliLog::kDebug + 2, "<-");
45
46    DefineOutput(2, TList::Class());
47
48    AliDebug(AliLog::kDebug + 2, "->");
49 }
50
51 //_____________________________________________________________________________
52 AliRsnAnalysisEffSE::AliRsnAnalysisEffSE(const AliRsnAnalysisEffSE& copy) :
53    AliRsnVAnalysisTaskSE(copy),
54    fUseITSSA(copy.fUseITSSA),
55    fUseGlobal(copy.fUseGlobal),
56    fStepListMC(copy.fStepListMC),
57    fStepListESD(copy.fStepListESD),
58    fAxisList(copy.fAxisList),
59    fPairDefList(copy.fPairDefList),
60    fContainerList(copy.fContainerList),
61    fOutList(0x0),
62    fVar(0),
63    fPair(),
64    fEventCuts(copy.fEventCuts)
65 {
66 //
67 // Copy constrtuctor
68 //
69 }
70
71 //_____________________________________________________________________________
72 void AliRsnAnalysisEffSE::AddStepMC(AliRsnCutManager *mgr)
73 {
74 //
75 // Add a step on montecarlo
76 //
77
78    fStepListMC.AddLast(mgr);
79 }
80
81 //_____________________________________________________________________________
82 void AliRsnAnalysisEffSE::AddStepESD(AliRsnCutManager *mgr)
83 {
84 //
85 // Add a step on ESD
86 //
87
88    fStepListESD.AddLast(mgr);
89 }
90
91 //_____________________________________________________________________________
92 void AliRsnAnalysisEffSE::AddAxis(AliRsnValue *axis)
93 {
94 //
95 // Add a new axis
96 //
97
98    Int_t n = fAxisList.GetEntries();
99    new(fAxisList[n]) AliRsnValue(*axis);
100 }
101
102 //_____________________________________________________________________________
103 void AliRsnAnalysisEffSE::RsnUserCreateOutputObjects()
104 {
105 //
106 // Creation of output objects.
107 // These are created through the utility methods in the analysis manager,
108 // which produces a list of histograms for each specified set of pairs.
109 // Each of these lists is added to the main list of this task.
110 //
111
112    AliDebug(AliLog::kDebug + 2, "<-");
113
114    // get number of steps and axes
115    Int_t iaxis  = 0;
116    Int_t nAxes  = fAxisList.GetEntries();
117    Int_t nSteps = (Int_t)fStepListMC.GetEntries() + (Int_t)fStepListESD.GetEntries();
118
119    if (!nSteps) {
120       AliError("No steps defined");
121       return;
122    }
123    if (!nAxes) {
124       AliError("No axes defined");
125       return;
126    }
127
128    // initialize variable list
129    fVar.Set(nAxes);
130
131    // retrieve number of bins for each axis
132    Int_t *nBins = new Int_t[nAxes];
133    for (iaxis = 0; iaxis < nAxes; iaxis++) {
134       AliRsnValue *fcnAxis = (AliRsnValue*)fAxisList.At(iaxis);
135       nBins[iaxis] = fcnAxis->GetArray().GetSize() - 1;
136    }
137
138    // create ouput list of containers
139    fContainerList = new TList;
140    fContainerList->SetOwner();
141    fContainerList->SetName(Form("%s_containers", GetName()));
142
143    // initialize output list
144    OpenFile(2);
145    fOutList = new TList();
146    fOutList->SetOwner();
147
148    // create the containers
149    Int_t i = 0, nDef = (Int_t)fPairDefList.GetEntries();
150    for (i = 0; i < nDef; i++) {
151       AliRsnPairDef *def = (AliRsnPairDef*)fPairDefList[i];
152       AliCFContainer *cont = new AliCFContainer(Form("%s", def->GetPairName()), "", nSteps, nAxes, nBins);
153       // set the bin limits for each axis
154       for (iaxis = 0; iaxis < nAxes; iaxis++) {
155          AliRsnValue *fcnAxis = (AliRsnValue*)fAxisList.At(iaxis);
156          cont->SetBinLimits(iaxis, fcnAxis->GetArray().GetArray());
157       }
158       // add the container to output list
159       fContainerList->Add(cont);
160    }
161
162    fOutList->Add(fContainerList);
163    fOutList->Print();
164
165    PostData(2, fOutList);
166
167    // clear heap
168    delete [] nBins;
169
170    AliDebug(AliLog::kDebug + 2, "->");
171 }
172
173 //_____________________________________________________________________________
174 void AliRsnAnalysisEffSE::RsnUserExec(Option_t*)
175 {
176 //
177 // Execution of the analysis task.
178 // Recovers the input event and processes it with all included pair objects.
179 // In this case, we NEED to have ESD and MC, otherwise we cannod do anything.
180 //
181
182    // process first MC steps and then ESD steps
183    AliRsnPairDef *pairDef = 0;
184    TObjArrayIter iter(&fPairDefList);
185    while ((pairDef = (AliRsnPairDef*)iter.Next())) {
186       if (fRsnEvent.IsESD()) ProcessEventESD(pairDef);
187       if (fRsnEvent.IsAOD()) ProcessEventAOD(pairDef);
188    }
189
190    // Post the data
191    PostData(2, fOutList);
192 }
193
194 //_____________________________________________________________________________
195 void AliRsnAnalysisEffSE::ProcessEventESD(AliRsnPairDef *pairDef)
196 {
197 //
198 // Process current event with the definitions of the specified step in MC list
199 // and store results in the container slot defined in second argument.
200 // It is associated with the AliCFContainer with the name of the pair.
201 //
202
203    AliStack      *stack = fRsnEvent.GetRefMCESD()->Stack();
204    AliESDEvent   *esd   = fRsnEvent.GetRefESD();
205    AliMCEvent    *mc    = fRsnEvent.GetRefMCESD();
206    AliMCParticle *mother;
207
208    if (!pairDef) return;
209    AliCFContainer *cont = (AliCFContainer*)fContainerList->FindObject(pairDef->GetPairName());
210    if (!cont) return;
211
212    // get informations from pairDef
213    Int_t   pdgM = 0;
214    Int_t   pdgD[2] = {0, 0};
215    Short_t chargeD[2] = {0, 0};
216    pdgM       = pairDef->GetMotherPDG();
217    pdgD   [0] = AliPID::ParticleCode(pairDef->GetPID(0));
218    pdgD   [1] = AliPID::ParticleCode(pairDef->GetPID(1));
219    chargeD[0] = pairDef->GetChargeS(0);
220    chargeD[1] = pairDef->GetChargeS(1);
221
222    // other utility variables
223    Int_t      first, j, ipart;
224    Int_t      label[2] = { -1, -1};
225    Short_t    charge[2] = {0, 0};
226    Short_t    pairDefMatch[2] = { -1, -1};
227    Int_t      esdIndex[2] = { -1, -1};
228    TParticle *part[2] = {0, 0};
229
230    // in this case, we first take the resonance from MC
231    // and then we find its daughters and compute cuts on them
232    for (ipart = 0; ipart < stack->GetNprimary(); ipart++) {
233       // take a track from the MC event
234       mother = (AliMCParticle*) fMCEvent->GetTrack(ipart);
235
236       // check that it is a binary decay and the PDG code matches
237       if (mother->Particle()->GetNDaughters() != 2) continue;
238       if (mother->Particle()->GetPdgCode() != pdgM) continue;
239
240       // store the labels of the two daughters
241       label[0] = mother->Particle()->GetFirstDaughter();
242       label[1] = mother->Particle()->GetLastDaughter();
243
244       // retrieve the particles and other stuff
245       // check if they match the order in the pairDef
246       for (j = 0; j < 2; j++) {
247          if (label[j] < 0) continue;
248          part[j]   = stack->Particle(label[j]);
249          pdgD[j]   = TMath::Abs(part[j]->GetPdgCode());
250          charge[j] = (Short_t)(part[j]->GetPDG()->Charge() / 3);
251          if (pdgD[j] == AliPID::ParticleCode(pairDef->GetPID(0)) && charge[j] == pairDef->GetChargeS(0))
252             pairDefMatch[j] = 0;
253          else if (pdgD[j] == AliPID::ParticleCode(pairDef->GetPID(1)) && charge[j] == pairDef->GetChargeS(1))
254             pairDefMatch[j] = 1;
255          else
256             pairDefMatch[j] = -1;
257
258          // find corresponding ESD particle: first try rejecting fakes,
259          // and in case of failure, try accepting fakes
260          esdIndex[j] = FindESDtrack(label[j], esd, kTRUE);
261          //TArrayI idx = FindESDtracks(label[j], esd);
262          //for (Int_t kk = 0; kk < idx.GetSize(); kk++) cout << "DAUGHTER " << j << " --> FOUND INDEX: " << idx[kk] << endl;
263          if (esdIndex[j] < 0) esdIndex[j] = FindESDtrack(label[j], esd, kFALSE);
264          //cout << "DAUGHTER " << j << " SINGLE FOUND INDEX = " << esdIndex[j] << endl;
265       }
266
267       // since each candidate good resonance is taken once, we must check
268       // that it matches the pair definition in any order, and reject in case
269       // in none of them the pair is OK
270       // anyway, we must associate the correct daughter to the correct data member
271       if (pairDefMatch[0] == 0 && pairDefMatch[1] == 1) {
272          // 1st track --> 1st member of PairDef
273          fDaughter[0].SetRef(mc->GetTrack(label[0]));
274          fDaughter[0].SetRefMC((AliMCParticle*)mc->GetTrack(label[0]));
275          fDaughter[0].SetGood();
276          // 2nd track --> 2nd member of PairDef
277          fDaughter[1].SetRef(mc->GetTrack(label[1]));
278          fDaughter[1].SetRefMC((AliMCParticle*)mc->GetTrack(label[1]));
279          fDaughter[1].SetGood();
280       } else if ((pairDefMatch[0] == 1 && pairDefMatch[1] == 0)) {
281          // 1st track --> 2nd member of PairDef
282          fDaughter[0].SetRef(mc->GetTrack(label[1]));
283          fDaughter[0].SetRefMC((AliMCParticle*)mc->GetTrack(label[1]));
284          fDaughter[0].SetGood();
285          // 2nd track --> 1st member of PairDef
286          fDaughter[1].SetRef(mc->GetTrack(label[0]));
287          fDaughter[1].SetRefMC((AliMCParticle*)mc->GetTrack(label[0]));
288          fDaughter[1].SetGood();
289       } else {
290          fDaughter[0].SetBad();
291          fDaughter[1].SetBad();
292       }
293
294       // reject the pair if the matching was unsuccessful
295       if (!fDaughter[0].IsOK() || !fDaughter[1].IsOK()) continue;
296
297       // first, we set the internal AliRsnMother object to
298       // the MC particles and then operate the selections on MC
299       fPair.SetDaughter(0, &fDaughter[0]);
300       fPair.SetDaughter(1, &fDaughter[1]);
301       fPair.ComputeSum(pairDef->GetMass1(), pairDef->GetMass2());
302       FillContainer(cont, &fStepListMC, pairDef, 0);
303
304       // then, if both particles found a good match in the ESD
305       // reassociate the ESD tracks to the pair and fill ESD containers
306       if (esdIndex[0] < 0 || esdIndex[1] < 0) continue;
307       if (pairDefMatch[0] == 0 && pairDefMatch[1] == 1) {
308          // 1st track --> 1st member of PairDef
309          fDaughter[0].SetRef(esd->GetTrack(esdIndex[0]));
310          // 2nd track --> 2nd member of PairDef
311          fDaughter[1].SetRef(esd->GetTrack(esdIndex[1]));
312          //cout << "****** MATCHING SCHEME 1" << endl;
313       } else if ((pairDefMatch[0] == 1 && pairDefMatch[1] == 0)) {
314          // 1st track --> 2nd member of PairDef
315          fDaughter[0].SetRef(esd->GetTrack(esdIndex[1]));
316          // 2nd track --> 1st member of PairDef
317          fDaughter[1].SetRef(esd->GetTrack(esdIndex[0]));
318          //cout << "****** MATCHING SCHEME 2" << endl;
319       }
320       //cout << "****** IDs = " << fDaughter[0].GetID() << ' ' << fDaughter[1].GetID() << endl;
321       // here we must remember how many steps were already filled
322       first = (Int_t)fStepListMC.GetEntries();
323       FillContainer(cont, &fStepListESD, pairDef, first);
324    }
325 }
326
327 //_____________________________________________________________________________
328 void AliRsnAnalysisEffSE::ProcessEventAOD(AliRsnPairDef *pairDef)
329 {
330 //
331 // Process current event with the definitions of the specified step in MC list
332 // and store results in the container slot defined in second argument.
333 // It is associated with the AliCFContainer with the name of the pair.
334 //
335
336    AliAODEvent      *aod   = fRsnEvent.GetRefAOD();
337    AliAODMCParticle *mother;
338    TClonesArray     *mcArray = (TClonesArray*)aod->GetList()->FindObject(AliAODMCParticle::StdBranchName());
339    if (!mcArray) return;
340
341    if (!pairDef) return;
342    AliCFContainer *cont = (AliCFContainer*)fContainerList->FindObject(pairDef->GetPairName());
343    if (!cont) return;
344
345    // get informations from pairDef
346    Int_t   pdgM = 0;
347    Int_t   pdgD[2] = {0, 0};
348    Short_t chargeD[2] = {0, 0};
349    pdgM       = pairDef->GetMotherPDG();
350    pdgD   [0] = AliPID::ParticleCode(pairDef->GetPID(0));
351    pdgD   [1] = AliPID::ParticleCode(pairDef->GetPID(1));
352    chargeD[0] = pairDef->GetChargeS(0);
353    chargeD[1] = pairDef->GetChargeS(1);
354
355    // other utility variables
356    Int_t             first, j;
357    Int_t             label [2] = { -1, -1};
358    Short_t           charge[2] = {0, 0};
359    Short_t           pairDefMatch[2] = { -1, -1};
360    Int_t             aodIndex[2] = { -1, -1};
361    AliAODMCParticle *part[2] = {0, 0};
362
363    // loop on MC particles
364    TObjArrayIter next(mcArray);
365    while ((mother = (AliAODMCParticle*)next())) {
366       // check that it is a binary decay and the PDG code matches
367       if (mother->GetNDaughters() != 2) continue;
368       if (mother->GetPdgCode() != pdgM) continue;
369
370       // store the labels of the two daughters
371       label[0] = mother->GetDaughter(0);
372       label[1] = mother->GetDaughter(1);
373
374       // retrieve the particles and other stuff
375       // check if they match the order in the pairDef
376       for (j = 0; j < 2; j++) {
377          if (label[j] < 0) continue;
378          part[j]   = (AliAODMCParticle*)mcArray->At(label[j]);
379          pdgD[j]   = TMath::Abs(part[j]->GetPdgCode());
380          charge[j] = (Short_t)(part[j]->Charge());
381          if (pdgD[j] == AliPID::ParticleCode(pairDef->GetPID(0)) && charge[j] == pairDef->GetChargeS(0))
382             pairDefMatch[j] = 0;
383          else if (pdgD[j] == AliPID::ParticleCode(pairDef->GetPID(1)) && charge[j] == pairDef->GetChargeS(1))
384             pairDefMatch[j] = 1;
385          else
386             pairDefMatch[j] = -1;
387
388          // find corresponding ESD particle: first try rejecting fakes,
389          // and in case of failure, try accepting fakes
390          aodIndex[j] = FindAODtrack(label[j], aod, kTRUE);
391          if (aodIndex[j] < 0) aodIndex[j] = FindAODtrack(label[j], aod, kFALSE);
392       }
393
394       // since each candidate good resonance is taken once, we must check
395       // that it matches the pair definition in any order, and reject in case
396       // in none of them the pair is OK
397       // anyway, we must associate the correct daughter to the correct data member
398       if (pairDefMatch[0] == 0 && pairDefMatch[1] == 1) {
399          // 1st track --> 1st member of PairDef
400          fDaughter[0].SetRef((AliAODMCParticle*)mcArray->At(label[0]));
401          fDaughter[0].SetRefMC((AliAODMCParticle*)mcArray->At(label[0]));
402          fDaughter[0].SetGood();
403          // 2nd track --> 2nd member of PairDef
404          fDaughter[1].SetRef((AliAODMCParticle*)mcArray->At(label[1]));
405          fDaughter[1].SetRefMC((AliAODMCParticle*)mcArray->At(label[1]));
406          fDaughter[1].SetGood();
407       } else if ((pairDefMatch[0] == 1 && pairDefMatch[1] == 0)) {
408          // 1st track --> 2nd member of PairDef
409          fDaughter[0].SetRef((AliAODMCParticle*)mcArray->At(label[1]));
410          fDaughter[0].SetRefMC((AliAODMCParticle*)mcArray->At(label[1]));
411          fDaughter[0].SetGood();
412          // 2nd track --> 1st member of PairDef
413          fDaughter[1].SetRef((AliAODMCParticle*)mcArray->At(label[0]));
414          fDaughter[1].SetRefMC((AliAODMCParticle*)mcArray->At(label[0]));
415          fDaughter[1].SetGood();
416       } else {
417          fDaughter[0].SetBad();
418          fDaughter[1].SetBad();
419       }
420
421       // reject the pair if the matching was unsuccessful
422       if (!fDaughter[0].IsOK() || !fDaughter[1].IsOK()) continue;
423
424       // first, we set the internal AliRsnMother object to
425       // the MC particles and then operate the selections on MC
426       fPair.SetDaughter(0, &fDaughter[0]);
427       fPair.SetDaughter(1, &fDaughter[1]);
428       fPair.ComputeSum(pairDef->GetMass1(), pairDef->GetMass2());
429       FillContainer(cont, &fStepListMC, pairDef, 0);
430
431       // then, if both particles found a good match in the AOD
432       // reassociate the AOD tracks to the pair and fill AOD containers
433       if (aodIndex[0] < 0 || aodIndex[1] < 0) continue;
434       if (pairDefMatch[0] == 0 && pairDefMatch[1] == 1) {
435          // 1st track --> 1st member of PairDef
436          fDaughter[0].SetRef(aod->GetTrack(aodIndex[0]));
437          // 2nd track --> 2nd member of PairDef
438          fDaughter[1].SetRef(aod->GetTrack(aodIndex[1]));
439          //cout << "****** MATCHING SCHEME 1" << endl;
440       } else if ((pairDefMatch[0] == 1 && pairDefMatch[1] == 0)) {
441          // 1st track --> 2nd member of PairDef
442          fDaughter[0].SetRef(aod->GetTrack(aodIndex[1]));
443          // 2nd track --> 1st member of PairDef
444          fDaughter[1].SetRef(aod->GetTrack(aodIndex[0]));
445          //cout << "****** MATCHING SCHEME 2" << endl;
446       }
447       //cout << "****** IDs = " << fDaughter[0].GetID() << ' ' << fDaughter[1].GetID() << endl;
448       // here we must remember how many steps were already filled
449       first = (Int_t)fStepListMC.GetEntries();
450       FillContainer(cont, &fStepListESD, pairDef, first);
451    }
452 }
453
454 //_____________________________________________________________________________
455 void AliRsnAnalysisEffSE::FillContainer(AliCFContainer *cont, const TObjArray *stepList, AliRsnPairDef *pd, Int_t firstOutStep)
456 {
457 //
458 // Fill the containers
459 //
460
461    Int_t  iaxis, nAxes  = fAxisList.GetEntries();
462    Int_t  istep, nSteps = stepList->GetEntries();
463    Bool_t computeOK;
464
465    // set daughters to pair
466    fPair.SetDaughter(0, &fDaughter[0]);
467    fPair.SetDaughter(1, &fDaughter[1]);
468    fPair.ComputeSum(pd->GetMass1(), pd->GetMass2());
469
470    // compute values for all axes
471    for (iaxis = 0; iaxis < nAxes; iaxis++) {
472       AliRsnValue *fcnAxis = (AliRsnValue*)fAxisList.At(iaxis);
473       fVar[iaxis] = -1E10;
474       switch (fcnAxis->GetTargetType()) {
475          case AliRsnTarget::kMother:
476             fcnAxis->SetSupportObject(pd);
477             computeOK = fcnAxis->Eval(&fPair);
478             break;
479          case AliRsnTarget::kEvent:
480             computeOK = fcnAxis->Eval(&fRsnEvent);
481             break;
482          default:
483             AliError(Form("Allowed targets are mothers and events; cannot use axis '%s' which has target '%s'", fcnAxis->GetName(), fcnAxis->GetTargetTypeName()));
484             computeOK = kFALSE;
485       }
486       if (computeOK) fVar[iaxis] = ((Float_t)fcnAxis->GetComputedValue());
487    }
488
489    // fill all steps
490    for (istep = 0; istep < nSteps; istep++) {
491       AliRsnCutManager *cutMgr = (AliRsnCutManager*)stepList->At(istep);
492       if (!cutMgr->PassCommonDaughterCuts(&fDaughter[0])) break;
493       if (!cutMgr->PassCommonDaughterCuts(&fDaughter[1])) break;
494       if (!cutMgr->PassDaughter1Cuts(&fDaughter[0])) break;
495       if (!cutMgr->PassDaughter2Cuts(&fDaughter[1])) break;
496       if (!cutMgr->PassMotherCuts(&fPair)) break;
497       //cout << "**************************************** FILLING STEP " << istep << endl;
498       cont->Fill(fVar.GetArray(), istep + firstOutStep);
499    }
500 }
501
502 //_____________________________________________________________________________
503 void AliRsnAnalysisEffSE::RsnTerminate(Option_t*)
504 {
505 //
506 // Termination.
507 // Could be added some monitor histograms here.
508 //
509
510    AliDebug(AliLog::kDebug + 2, "<-");
511    AliDebug(AliLog::kDebug + 2, "->");
512 }
513
514 //_____________________________________________________________________________
515 void AliRsnAnalysisEffSE::AddPairDef(AliRsnPairDef* pairDef)
516 {
517 //
518 //  Adds pair definition
519 //
520    fPairDefList.AddLast(pairDef);
521 }
522
523 //_____________________________________________________________________________
524 Int_t AliRsnAnalysisEffSE::FindESDtrack(Int_t label, AliESDEvent *esd, Bool_t rejectFakes)
525 {
526 //
527 // Finds in the ESD a track whose label corresponds to that in argument.
528 // When global tracks are enabled, tries first to find a global track
529 // satisfying that requirement.
530 // If no global tracks are found, if ITS-SA are enable, tries to search among them
531 // otherwise return a negative number.
532 // If global tracks are disabled, search only among ITS SA
533 //
534
535    Int_t   i = 0;
536    Int_t   ntracks = esd->GetNumberOfTracks();
537    ULong_t status;
538    Bool_t  isTPC;
539    Bool_t  isITSSA;
540
541    // loop for global tracks
542    if (fUseGlobal) {
543       for (i = 0; i < ntracks; i++) {
544          AliESDtrack *track = esd->GetTrack(i);
545          status  = (ULong_t)track->GetStatus();
546          isTPC   = ((status & AliESDtrack::kTPCin)  != 0);
547          if (!isTPC) continue;
548
549          // check that label match
550          if (TMath::Abs(track->GetLabel()) != label) continue;
551
552          // if required, reject fakes
553          if (rejectFakes && track->GetLabel() < 0) continue;
554
555          // if all checks are passed and we are searching among global
556          // this means that thie track is a global one with the right label
557          // then, the return value is set to this, and returned
558          return i;
559       }
560    }
561
562    // loop for ITS-SA tracks (this happens only if no global tracks were found
563    // or searching among globals is disabled)
564    if (fUseITSSA) {
565       for (i = 0; i < ntracks; i++) {
566          AliESDtrack *track = esd->GetTrack(i);
567          status  = (ULong_t)track->GetStatus();
568          isITSSA = ((status & AliESDtrack::kTPCin)  == 0 && (status & AliESDtrack::kITSrefit) != 0 && (status & AliESDtrack::kITSpureSA) == 0 && (status & AliESDtrack::kITSpid) != 0);
569          if (!isITSSA) continue;
570
571          // check that label match
572          if (TMath::Abs(track->GetLabel()) != label) continue;
573
574          // if required, reject fakes
575          if (rejectFakes && track->GetLabel() < 0) continue;
576
577          // if all checks are passed and we are searching among global
578          // this means that thie track is a global one with the right label
579          // then, the return value is set to this, and returned
580          return i;
581       }
582    }
583
584    // if we reach this point, no match were found
585    return -1;
586 }
587
588 //_____________________________________________________________________________
589 TArrayI AliRsnAnalysisEffSE::FindESDtracks(Int_t label, AliESDEvent *esd)
590 {
591 //
592 // Finds in the ESD a track whose label corresponds to that in argument.
593 // When global tracks are enabled, tries first to find a global track
594 // satisfying that requirement.
595 // If no global tracks are found, if ITS-SA are enable, tries to search among them
596 // otherwise return a negative number.
597 // If global tracks are disabled, search only among ITS SA
598 //
599
600    Int_t   i = 0;
601    Int_t   ntracks = esd->GetNumberOfTracks();
602    ULong_t status;
603    Bool_t  isTPC;
604    Bool_t  isITSSA;
605    TArrayI array(100);
606    Int_t   nfound = 0;
607
608    // loop for global tracks
609    if (fUseGlobal) {
610       for (i = 0; i < ntracks; i++) {
611          AliESDtrack *track = esd->GetTrack(i);
612          status  = (ULong_t)track->GetStatus();
613          isTPC   = ((status & AliESDtrack::kTPCin)  != 0);
614          if (!isTPC) continue;
615
616          // check that label match
617          if (TMath::Abs(track->GetLabel()) != label) continue;
618
619          array[nfound++] = i;
620       }
621    }
622
623    // loop for ITS-SA tracks (this happens only if no global tracks were found
624    // or searching among globals is disabled)
625    if (fUseITSSA) {
626       for (i = 0; i < ntracks; i++) {
627          AliESDtrack *track = esd->GetTrack(i);
628          status  = (ULong_t)track->GetStatus();
629          isITSSA = ((status & AliESDtrack::kTPCin)  == 0 && (status & AliESDtrack::kITSrefit) != 0 && (status & AliESDtrack::kITSpureSA) == 0 && (status & AliESDtrack::kITSpid) != 0);
630          if (!isITSSA) continue;
631
632          // check that label match
633          if (TMath::Abs(track->GetLabel()) != label) continue;
634
635          array[nfound++] = i;
636       }
637    }
638
639    array.Set(nfound);
640    return array;
641 }
642
643 //_____________________________________________________________________________
644 Int_t AliRsnAnalysisEffSE::FindAODtrack(Int_t label, AliAODEvent *aod, Bool_t rejectFakes)
645 {
646 //
647 // Finds in the ESD a track whose label corresponds to that in argument.
648 // When global tracks are enabled, tries first to find a global track
649 // satisfying that requirement.
650 // If no global tracks are found, if ITS-SA are enable, tries to search among them
651 // otherwise return a negative number.
652 // If global tracks are disabled, search only among ITS SA
653 //
654
655    Int_t   i = 0;
656    Int_t   ntracks = aod->GetNumberOfTracks();
657    ULong_t status;
658    Bool_t  isTPC;
659    Bool_t  isITSSA;
660
661    // loop for global tracks
662    if (fUseGlobal) {
663       for (i = 0; i < ntracks; i++) {
664          AliAODTrack *track = aod->GetTrack(i);
665          status  = (ULong_t)track->GetStatus();
666          isTPC   = ((status & AliESDtrack::kTPCin)  != 0);
667          if (!isTPC) continue;
668
669          // check that label match
670          if (TMath::Abs(track->GetLabel()) != label) continue;
671
672          // if required, reject fakes
673          if (rejectFakes && track->GetLabel() < 0) continue;
674
675          // if all checks are passed and we are searching among global
676          // this means that thie track is a global one with the right label
677          // then, the return value is set to this, and returned
678          return i;
679       }
680    }
681
682    // loop for ITS-SA tracks (this happens only if no global tracks were found
683    // or searching among globals is disabled)
684    if (fUseITSSA) {
685       for (i = 0; i < ntracks; i++) {
686          AliAODTrack *track = aod->GetTrack(i);
687          status  = (ULong_t)track->GetStatus();
688          isITSSA = ((status & AliESDtrack::kTPCin)  == 0 && (status & AliESDtrack::kITSrefit) != 0 && (status & AliESDtrack::kITSpureSA) == 0 && (status & AliESDtrack::kITSpid) != 0);
689          if (!isITSSA) continue;
690
691          // check that label match
692          if (TMath::Abs(track->GetLabel()) != label) continue;
693
694          // if required, reject fakes
695          if (rejectFakes && track->GetLabel() < 0) continue;
696
697          // if all checks are passed and we are searching among global
698          // this means that thie track is a global one with the right label
699          // then, the return value is set to this, and returned
700          return i;
701       }
702    }
703
704    // if we reach this point, no match were found
705    return -1;
706 }
707
708 //_____________________________________________________________________________
709 TArrayI AliRsnAnalysisEffSE::FindAODtracks(Int_t label, AliAODEvent *aod)
710 {
711 //
712 // Finds in the ESD a track whose label corresponds to that in argument.
713 // When global tracks are enabled, tries first to find a global track
714 // satisfying that requirement.
715 // If no global tracks are found, if ITS-SA are enable, tries to search among them
716 // otherwise return a negative number.
717 // If global tracks are disabled, search only among ITS SA
718 //
719
720    Int_t   i = 0;
721    Int_t   ntracks = aod->GetNumberOfTracks();
722    ULong_t status;
723    Bool_t  isTPC;
724    Bool_t  isITSSA;
725    TArrayI array(100);
726    Int_t   nfound = 0;
727
728    // loop for global tracks
729    if (fUseGlobal) {
730       for (i = 0; i < ntracks; i++) {
731          AliAODTrack *track = aod->GetTrack(i);
732          status  = (ULong_t)track->GetStatus();
733          isTPC   = ((status & AliESDtrack::kTPCin)  != 0);
734          if (!isTPC) continue;
735
736          // check that label match
737          if (TMath::Abs(track->GetLabel()) != label) continue;
738
739          array[nfound++] = i;
740       }
741    }
742
743    // loop for ITS-SA tracks (this happens only if no global tracks were found
744    // or searching among globals is disabled)
745    if (fUseITSSA) {
746       for (i = 0; i < ntracks; i++) {
747          AliAODTrack *track = aod->GetTrack(i);
748          status  = (ULong_t)track->GetStatus();
749          isITSSA = ((status & AliESDtrack::kTPCin)  == 0 && (status & AliESDtrack::kITSrefit) != 0 && (status & AliESDtrack::kITSpureSA) == 0 && (status & AliESDtrack::kITSpid) != 0);
750          if (!isITSSA) continue;
751
752          // check that label match
753          if (TMath::Abs(track->GetLabel()) != label) continue;
754
755          array[nfound++] = i;
756       }
757    }
758
759    array.Set(nfound);
760    return array;
761 }
762
763 //______________________________________________________________________________
764 Bool_t AliRsnAnalysisEffSE::EventProcess()
765 {
766 //
767 // Customized event pre-processing.
768 // First checks if the current event passes all cuts,
769 // and if it does, updates the informations and then
770 // call the operations which are already defined in the
771 // omonyme function in mother class
772 //
773
774    // initially, an event is expected to be bad
775    fTaskInfo.SetEventUsed(kFALSE);
776
777    // check the event cuts and update the info data accordingly
778    // events not passing the cuts must be rejected
779    if (!fEventCuts.IsSelected(&fRsnEvent)) {
780       fTaskInfo.SetEventUsed(kFALSE);
781       return kFALSE;
782    }
783
784    // if we reach this point, cuts were passed;
785    // then additional operations can be done
786
787    // find leading particle (without any PID/momentum restriction)
788    fRsnEvent.SelectLeadingParticle(0);
789
790    // final return value is positive
791    // but call the mother class method which updates info object
792    fTaskInfo.SetEventUsed(kTRUE);
793    return AliRsnVAnalysisTaskSE::EventProcess();
794 }