2 // Class AliRsnAnalysisEffSE
7 // authors: Alberto Pulvirenti (alberto.pulvirenti@ct.infn.it)
8 // Martin Vala (martin.vala@cern.ch)
10 #include <Riostream.h>
12 #include "AliESDEvent.h"
13 #include "AliMCEvent.h"
15 #include "AliCFContainer.h"
16 #include "AliRsnCutManager.h"
17 #include "AliRsnValue.h"
18 #include "AliRsnAnalysisEffSE.h"
19 #include "AliRsnPairDef.h"
20 #include "AliRsnCutSet.h"
22 ClassImp(AliRsnAnalysisEffSE)
24 //_____________________________________________________________________________
25 AliRsnAnalysisEffSE::AliRsnAnalysisEffSE(const char *name) :
26 AliRsnVAnalysisTaskSE(name),
31 fAxisList("AliRsnValue", 0),
37 fEventCuts("eventCuts", AliRsnCut::kEvent)
40 // Default constructor.
43 AliDebug(AliLog::kDebug+2,"<-");
45 DefineOutput(2, TList::Class());
47 AliDebug(AliLog::kDebug+2,"->");
50 //_____________________________________________________________________________
51 AliRsnAnalysisEffSE::AliRsnAnalysisEffSE(const AliRsnAnalysisEffSE& copy) :
52 AliRsnVAnalysisTaskSE(copy),
53 fUseITSSA(copy.fUseITSSA),
54 fUseGlobal(copy.fUseGlobal),
55 fStepListMC(copy.fStepListMC),
56 fStepListESD(copy.fStepListESD),
57 fAxisList(copy.fAxisList),
58 fPairDefList(copy.fPairDefList),
59 fContainerList(copy.fContainerList),
63 fEventCuts(copy.fEventCuts)
70 //_____________________________________________________________________________
71 void AliRsnAnalysisEffSE::AddStepMC(AliRsnCutManager *mgr)
74 // Add a step on montecarlo
77 fStepListMC.AddLast(mgr);
80 //_____________________________________________________________________________
81 void AliRsnAnalysisEffSE::AddStepESD(AliRsnCutManager *mgr)
87 fStepListESD.AddLast(mgr);
90 //_____________________________________________________________________________
91 void AliRsnAnalysisEffSE::AddAxis(AliRsnValue *axis)
97 Int_t n = fAxisList.GetEntries();
98 new (fAxisList[n]) AliRsnValue(*axis);
101 //_____________________________________________________________________________
102 void AliRsnAnalysisEffSE::RsnUserCreateOutputObjects()
105 // Creation of output objects.
106 // These are created through the utility methods in the analysis manager,
107 // which produces a list of histograms for each specified set of pairs.
108 // Each of these lists is added to the main list of this task.
111 AliDebug(AliLog::kDebug+2,"<-");
113 // get number of steps and axes
115 Int_t nAxes = fAxisList.GetEntries();
116 Int_t nSteps = (Int_t)fStepListMC.GetEntries() + (Int_t)fStepListESD.GetEntries();
119 AliError("No steps defined");
123 AliError("No axes defined");
127 // initialize variable list
130 // retrieve number of bins for each axis
131 Int_t *nBins = new Int_t[nAxes];
132 TArrayD *array = new TArrayD[nAxes];
133 for (iaxis = 0; iaxis < nAxes; iaxis++)
135 AliRsnValue *fcnAxis = (AliRsnValue*)fAxisList.At(iaxis);
137 array[iaxis] = fcnAxis->GetArray();
138 nBins[iaxis] = array[iaxis].GetSize() - 1;
141 // create ouput list of containers
142 fContainerList = new TList;
143 fContainerList->SetOwner();
144 fContainerList->SetName(Form("%s_containers", GetName()));
146 // initialize output list
148 fOutList = new TList();
149 fOutList->SetOwner();
151 // create the containers
152 Int_t i, nDef = (Int_t)fPairDefList.GetEntries();
153 for (i = 0; i < nDef; i++)
155 AliRsnPairDef *def = (AliRsnPairDef*)fPairDefList[i];
156 AliCFContainer *cont = new AliCFContainer(Form("%s", def->GetPairName()), "", nSteps, nAxes, nBins);
157 // set the bin limits for each axis
158 for (iaxis = 0; iaxis < nAxes; iaxis++) cont->SetBinLimits(iaxis, array[iaxis].GetArray());
159 // add the container to output list
160 fContainerList->Add(cont);
163 fOutList->Add(fContainerList);
166 PostData(2, fOutList);
168 AliDebug(AliLog::kDebug+2,"->");
171 //_____________________________________________________________________________
172 void AliRsnAnalysisEffSE::RsnUserExec(Option_t*)
175 // Execution of the analysis task.
176 // Recovers the input event and processes it with all included pair objects.
177 // In this case, we NEED to have ESD and MC, otherwise we cannod do anything.
181 for (Int_t i = 0; i <= AliPID::kSPECIES; i++)
183 cout << AliPID::ParticleName((AliPID::EParticleType)i) << ": " << endl;
184 for (Int_t m = 0; m < AliRsnDaughter::kMethods; m++)
186 cout << "-- method: " << AliRsnDaughter::MethodName((AliRsnDaughter::EPIDMethod)m) << endl;
187 Char_t sign[2] = {'+', '-'};
188 for (Int_t s = 0; s < 2; s++)
190 TArrayI *a = fRsnPIDIndex.GetTracksArray((AliRsnDaughter::EPIDMethod)m, sign[s], (AliPID::EParticleType)i);
191 Int_t n = a->GetSize();
192 for (Int_t j = 0; j < n; j++)
195 cout << "-- -- track " << Form("%4d ", k) << ": ";
196 fRsnEvent.SetDaughter(trk, k);
197 cout << "charge = " << (trk.IsPos() ? "+ " : (trk.IsNeg() ? "- " : "0 "));
198 cout << "truePID = " << Form("%10s ", AliPID::ParticleName(trk.PerfectPID()));
199 cout << "realPID = " << Form("%10s ", AliPID::ParticleName(trk.RealisticPID()));
201 cout << "-- -- -- weights (computed): ";
202 for (Int_t q = 0; q < AliPID::kSPECIES; q++)
203 cout << Form("%15.12f", trk.ComputedWeights()[q]) << ' ';
205 cout << "-- -- -- weights (original): ";
206 for (Int_t q = 0; q < AliPID::kSPECIES; q++)
207 cout << Form("%15.12f", trk.GetRef()->PID()[q]) << ' ';
215 AliDebug(AliLog::kDebug+2,"<-");
216 if (!fESDEvent || !fMCEvent) {
217 AliError("This task can process only ESD + MC events");
220 fRsnEvent.SetRef(fESDEvent, fMCEvent);
222 // if general event cuts are added to the task (recommended)
223 // they are checked here on the RSN event interface and,
224 // if the event does not pass them, it is skipped and ProcessInfo
225 // is updated accordingly
226 if (!fEventCuts.IsSelected(&fRsnEvent)) {
227 fTaskInfo.SetEventUsed(kFALSE);
231 // if cuts are passed or not cuts were defined,
232 // update the task info before processing the event
233 fTaskInfo.SetEventUsed(kTRUE);
235 // process first MC steps and then ESD steps
236 AliRsnPairDef *pairDef = 0;
237 TObjArrayIter iter(&fPairDefList);
238 while ( (pairDef = (AliRsnPairDef*)iter.Next()) )
240 //ProcessEventMC(pairDef);
241 //ProcessEventESD(pairDef);
242 ProcessEvent(pairDef);
246 PostData(2, fOutList);
248 AliDebug(AliLog::kDebug+2,"->");
251 //_____________________________________________________________________________
252 void AliRsnAnalysisEffSE::ProcessEvent(AliRsnPairDef *pairDef)
255 // Process current event with the definitions of the specified step in MC list
256 // and store results in the container slot defined in second argument.
257 // It is associated with the AliCFContainer with the name of the pair.
260 AliStack *stack = fRsnEvent.GetRefMC()->Stack();
261 AliESDEvent *esd = fRsnEvent.GetRefESD();
262 AliMCEvent *mc = fRsnEvent.GetRefMC();
263 AliMCParticle *mother;
265 if (!pairDef) return;
266 AliCFContainer *cont = (AliCFContainer*)fContainerList->FindObject(pairDef->GetPairName());
269 // get informations from pairDef
270 Int_t pdgM = 0, pdgD[2] = {0, 0};
271 Short_t chargeD[2] = {0, 0};
272 pdgM = pairDef->GetMotherPDG();
273 pdgD[0] = AliPID::ParticleCode(pairDef->GetPID(0));
274 pdgD[1] = AliPID::ParticleCode(pairDef->GetPID(1));
275 chargeD[0] = pairDef->GetChargeShort(0);
276 chargeD[1] = pairDef->GetChargeShort(1);
278 // other utility variables
279 Int_t label[2] = {-1, -1}, first, j, ipart;
280 Short_t charge[2] = {0, 0};
281 Short_t pairDefMatch[2] = {-1, -1};
283 TParticle *part[2] = {0, 0};
285 // in this case, we first take the resonance from MC
286 // and then we find its daughters and compute cuts on them
287 for (ipart = 0; ipart < stack->GetNprimary(); ipart++)
289 // take a track from the MC event
290 mother = (AliMCParticle*) fMCEvent->GetTrack(ipart);
292 // check that it is a binary decay and the PDG code matches
293 if (mother->Particle()->GetNDaughters() != 2) continue;
294 if (mother->Particle()->GetPdgCode() != pdgM) continue;
296 // store the labels of the two daughters
297 label[0] = mother->Particle()->GetFirstDaughter();
298 label[1] = mother->Particle()->GetLastDaughter();
300 // retrieve the particles and other stuff
301 // check if they match the order in the pairDef
302 for (j = 0; j < 2; j++)
304 if (label[j] < 0) continue;
305 part[j] = stack->Particle(label[j]);
306 pdgD[j] = TMath::Abs(part[j]->GetPdgCode());
307 charge[j] = (Short_t)(part[j]->GetPDG()->Charge() / 3);
308 if (pdgD[j] == AliPID::ParticleCode(pairDef->GetPID(0)) && charge[j] == pairDef->GetChargeShort(0))
310 else if (pdgD[j] == AliPID::ParticleCode(pairDef->GetPID(1)) && charge[j] == pairDef->GetChargeShort(1))
313 pairDefMatch[j] = -1;
315 // find corresponding ESD particle: first try rejecting fakes,
316 // and in case of failure, try accepting fakes
317 esdIndex[j] = FindESDtrack(label[j], esd, kTRUE);
318 //TArrayI idx = FindESDtracks(label[j], esd);
319 //for (Int_t kk = 0; kk < idx.GetSize(); kk++) cout << "DAUGHTER " << j << " --> FOUND INDEX: " << idx[kk] << endl;
320 if (esdIndex[j] < 0) esdIndex[j] = FindESDtrack(label[j], esd, kFALSE);
321 //cout << "DAUGHTER " << j << " SINGLE FOUND INDEX = " << esdIndex[j] << endl;
324 // since each candidate good resonance is taken once, we must check
325 // that it matches the pair definition in any order, and reject in case
326 // in none of them the pair is OK
327 // anyway, we must associate the correct daughter to the correct data member
328 if (pairDefMatch[0] == 0 && pairDefMatch[1] == 1)
330 // 1st track --> 1st member of PairDef
331 fDaughter[0].SetRef(mc->GetTrack(label[0]));
332 fDaughter[0].SetRefMC((AliMCParticle*)mc->GetTrack(label[0]));
333 fDaughter[0].SetGood();
334 // 2nd track --> 2nd member of PairDef
335 fDaughter[1].SetRef(mc->GetTrack(label[1]));
336 fDaughter[1].SetRefMC((AliMCParticle*)mc->GetTrack(label[1]));
337 fDaughter[1].SetGood();
339 else if ((pairDefMatch[0] == 1 && pairDefMatch[1] == 0))
341 // 1st track --> 2nd member of PairDef
342 fDaughter[0].SetRef(mc->GetTrack(label[1]));
343 fDaughter[0].SetRefMC((AliMCParticle*)mc->GetTrack(label[1]));
344 fDaughter[0].SetGood();
345 // 2nd track --> 1st member of PairDef
346 fDaughter[1].SetRef(mc->GetTrack(label[0]));
347 fDaughter[1].SetRefMC((AliMCParticle*)mc->GetTrack(label[0]));
348 fDaughter[1].SetGood();
352 fDaughter[0].SetBad();
353 fDaughter[1].SetBad();
356 // reject the pair if the matching was unsuccessful
357 if (!fDaughter[0].IsOK() || !fDaughter[1].IsOK()) continue;
359 // first, we set the internal AliRsnMother object to
360 // the MC particles and then operate the selections on MC
361 fPair.SetDaughters(&fDaughter[0], pairDef->GetMass(0), &fDaughter[1], pairDef->GetMass(1));
362 FillContainer(cont, &fStepListMC, pairDef, 0);
364 // then, if both particles found a good match in the ESD
365 // reassociate the ESD tracks to the pair and fill ESD containers
366 if (esdIndex[0] < 0 || esdIndex[1] < 0) continue;
367 if (pairDefMatch[0] == 0 && pairDefMatch[1] == 1)
369 // 1st track --> 1st member of PairDef
370 fDaughter[0].SetRef(esd->GetTrack(esdIndex[0]));
371 // 2nd track --> 2nd member of PairDef
372 fDaughter[1].SetRef(esd->GetTrack(esdIndex[1]));
373 //cout << "****** MATCHING SCHEME 1" << endl;
375 else if ((pairDefMatch[0] == 1 && pairDefMatch[1] == 0))
377 // 1st track --> 2nd member of PairDef
378 fDaughter[0].SetRef(esd->GetTrack(esdIndex[1]));
379 // 2nd track --> 1st member of PairDef
380 fDaughter[1].SetRef(esd->GetTrack(esdIndex[0]));
381 //cout << "****** MATCHING SCHEME 2" << endl;
383 //cout << "****** IDs = " << fDaughter[0].GetID() << ' ' << fDaughter[1].GetID() << endl;
384 // here we must remember how many steps were already filled
385 first = (Int_t)fStepListMC.GetEntries();
386 FillContainer(cont, &fStepListESD, pairDef, first);
390 //_____________________________________________________________________________
391 void AliRsnAnalysisEffSE::ProcessEventMC(AliRsnPairDef */*pairDef*/)
394 // Process current event with the definitions of the specified step in MC list
395 // and store results in the container slot defined in second argument
399 AliStack *stack = fMCEvent->Stack();
400 AliMCParticle *mother, *daughter;
402 if (!pairDef) return;
403 AliCFContainer *cont = (AliCFContainer*)fContainerList->FindObject(pairDef->GetPairName().Data());
406 // other utility variables
407 Int_t i[2], j, ipart;
409 // in this case, we first take the resonance from MC
410 // and then we find its daughters and compute cuts on them
411 for (ipart = 0; ipart < stack->GetNprimary(); ipart++)
413 mother = (AliMCParticle*) fMCEvent->GetTrack(ipart);
414 if (mother->Particle()->GetNDaughters() != 2) continue;
416 i[0] = mother->Particle()->GetFirstDaughter();
417 i[1] = mother->Particle()->GetLastDaughter();
419 for (j = 0; j < 2; j++)
421 daughter = (AliMCParticle*) fMCEvent->GetTrack(i[j]);
422 fDaughter[j].SetRef(daughter);
423 fDaughter[j].SetRefMC(daughter);
424 fDaughter[j].FindMotherPDG(stack);
427 if (fDaughter[0].ChargeC() != pairDef->GetCharge(0)) continue;
428 if (fDaughter[1].ChargeC() != pairDef->GetCharge(1)) continue;
429 if (fDaughter[0].PerfectPID() != pairDef->GetType(0)) continue;
430 if (fDaughter[1].PerfectPID() != pairDef->GetType(1)) continue;
432 fPair.SetDaughters(&fDaughter[0], &fDaughter[1]);
435 FillContainer(cont, &fStepListMC, pairDef, 0);
440 //_____________________________________________________________________________
441 void AliRsnAnalysisEffSE::ProcessEventESD(AliRsnPairDef */*pairDef*/)
444 // Process current event with the definitions of the specified step in ESD list
445 // and store results in the container slot defined in second argument
449 Int_t i0, i1, first = (Int_t)fStepListMC.GetEntries();
451 if (!pairDef) return;
452 AliCFContainer *cont = (AliCFContainer*)fContainerList->FindObject(pairDef->GetPairName().Data());
455 // external loop on tracks
456 for (i0 = 0; i0 < a0->GetSize(); i0++) {
458 fRsnEvent.SetDaughter(fDaughter[0], a0->At(i0));
459 if (!fDaughter[0].IsOK()) continue;
460 fDaughter[0].SetRequiredPID(pairDef->GetType(0));
462 // internal loop on tracks
463 for (i1 = 0; i1 < a1->GetSize(); i1++) {
465 fRsnEvent.SetDaughter(fDaughter[1], a1->At(i1));
466 if (!fDaughter[1].IsOK()) continue;
467 fDaughter[1].SetRequiredPID(pairDef->GetType(1));
469 fPair.SetPair(&fDaughter[0], &fDaughter[1]);
470 if (TMath::Abs(fPair.CommonMother()) != pairDef->GetMotherPDG()) continue;
472 FillContainer(cont, &fStepListESD, pairDef, first);
478 //_____________________________________________________________________________
479 void AliRsnAnalysisEffSE::FillContainer(AliCFContainer *cont, const TObjArray *stepList, AliRsnPairDef *pd, Int_t firstOutStep)
482 // Fill the containers
485 Int_t iaxis, nAxes = fAxisList.GetEntries();
486 Int_t istep, nSteps = stepList->GetEntries();
488 // set daughters to pair
489 fPair.SetDaughters(&fDaughter[0], pd->GetMass(0), &fDaughter[1], pd->GetMass(1));
491 // compute values for all axes
492 for (iaxis = 0; iaxis < nAxes; iaxis++)
494 AliRsnValue *fcnAxis = (AliRsnValue*)fAxisList.At(iaxis);
496 if (fcnAxis->Eval(&fPair, pd, &fRsnEvent)) fVar[iaxis] = (Float_t)fcnAxis->GetValue();
500 for (istep = 0; istep < nSteps; istep++)
502 AliRsnCutManager *cutMgr = (AliRsnCutManager*)stepList->At(istep);
503 cutMgr->SetEvent(&fRsnEvent);
504 if (!cutMgr->PassCommonDaughterCuts(&fDaughter[0])) break;
505 if (!cutMgr->PassCommonDaughterCuts(&fDaughter[1])) break;
506 if (!cutMgr->PassDaughter1Cuts(&fDaughter[0])) break;
507 if (!cutMgr->PassDaughter2Cuts(&fDaughter[1])) break;
508 if (!cutMgr->PassMotherCuts(&fPair)) break;
509 //cout << "**************************************** FILLING STEP " << istep << endl;
510 cont->Fill(fVar.GetArray(), istep + firstOutStep);
514 //_____________________________________________________________________________
515 void AliRsnAnalysisEffSE::RsnTerminate(Option_t*)
519 // Could be added some monitor histograms here.
522 AliDebug(AliLog::kDebug+2,"<-");
523 AliDebug(AliLog::kDebug+2,"->");
526 //_____________________________________________________________________________
527 void AliRsnAnalysisEffSE::AddPairDef(AliRsnPairDef* pairDef)
530 // Adds pair definition
532 fPairDefList.AddLast(pairDef);
535 //_____________________________________________________________________________
536 Int_t AliRsnAnalysisEffSE::FindESDtrack(Int_t label, AliESDEvent *esd, Bool_t rejectFakes)
539 // Finds in the ESD a track whose label corresponds to that in argument.
540 // When global tracks are enabled, tries first to find a global track
541 // satisfying that requirement.
542 // If no global tracks are found, if ITS-SA are enable, tries to search among them
543 // otherwise return a negative number.
544 // If global tracks are disabled, search only among ITS SA
548 Int_t ntracks = esd->GetNumberOfTracks();
553 // loop for global tracks
556 for (i = 0; i < ntracks; i++)
558 AliESDtrack *track = esd->GetTrack(i);
559 status = (ULong_t)track->GetStatus();
560 isTPC = ((status & AliESDtrack::kTPCin) != 0);
561 if (!isTPC) continue;
563 // check that label match
564 if (TMath::Abs(track->GetLabel()) != label) continue;
566 // if required, reject fakes
567 if (rejectFakes && track->GetLabel() < 0) continue;
569 // if all checks are passed and we are searching among global
570 // this means that thie track is a global one with the right label
571 // then, the return value is set to this, and returned
576 // loop for ITS-SA tracks (this happens only if no global tracks were found
577 // or searching among globals is disabled)
580 for (i = 0; i < ntracks; i++)
582 AliESDtrack *track = esd->GetTrack(i);
583 status = (ULong_t)track->GetStatus();
584 isITSSA = ((status & AliESDtrack::kTPCin) == 0 && (status & AliESDtrack::kITSrefit) != 0 && (status & AliESDtrack::kITSpureSA) == 0 && (status & AliESDtrack::kITSpid) != 0);
585 if (!isITSSA) continue;
587 // check that label match
588 if (TMath::Abs(track->GetLabel()) != label) continue;
590 // if required, reject fakes
591 if (rejectFakes && track->GetLabel() < 0) continue;
593 // if all checks are passed and we are searching among global
594 // this means that thie track is a global one with the right label
595 // then, the return value is set to this, and returned
600 // if we reach this point, no match were found
604 //_____________________________________________________________________________
605 TArrayI AliRsnAnalysisEffSE::FindESDtracks(Int_t label, AliESDEvent *esd)
608 // Finds in the ESD a track whose label corresponds to that in argument.
609 // When global tracks are enabled, tries first to find a global track
610 // satisfying that requirement.
611 // If no global tracks are found, if ITS-SA are enable, tries to search among them
612 // otherwise return a negative number.
613 // If global tracks are disabled, search only among ITS SA
617 Int_t ntracks = esd->GetNumberOfTracks();
624 // loop for global tracks
627 for (i = 0; i < ntracks; i++)
629 AliESDtrack *track = esd->GetTrack(i);
630 status = (ULong_t)track->GetStatus();
631 isTPC = ((status & AliESDtrack::kTPCin) != 0);
632 if (!isTPC) continue;
634 // check that label match
635 if (TMath::Abs(track->GetLabel()) != label) continue;
641 // loop for ITS-SA tracks (this happens only if no global tracks were found
642 // or searching among globals is disabled)
645 for (i = 0; i < ntracks; i++)
647 AliESDtrack *track = esd->GetTrack(i);
648 status = (ULong_t)track->GetStatus();
649 isITSSA = ((status & AliESDtrack::kTPCin) == 0 && (status & AliESDtrack::kITSrefit) != 0 && (status & AliESDtrack::kITSpureSA) == 0 && (status & AliESDtrack::kITSpid) != 0);
650 if (!isITSSA) continue;
652 // check that label match
653 if (TMath::Abs(track->GetLabel()) != label) continue;