2 // Computator for single daughters.
3 // Implements a simple loop on tracks from one of the entry lists
4 // filled by the task AliRsnInputHandler, adding a check on their
5 // definition specified in the daughter def.
6 // Author: A. Pulvirenti
10 #include <TEntryList.h>
14 #include "AliRsnEvent.h"
15 #include "AliRsnDaughterDef.h"
16 #include "AliRsnDaughterSelector.h"
18 #include "AliRsnLoopDaughter.h"
20 ClassImp(AliRsnLoopDaughter)
22 //_____________________________________________________________________________
23 AliRsnLoopDaughter::AliRsnLoopDaughter(const char *name, Int_t listID, AliRsnDaughterDef *def) :
32 // Default constructor
36 //_____________________________________________________________________________
37 AliRsnLoopDaughter::AliRsnLoopDaughter(const AliRsnLoopDaughter& copy) :
39 fTrueMC(copy.fTrueMC),
40 fOnlyTrue(copy.fOnlyTrue),
41 fListID(copy.fListID),
43 fDaughter(copy.fDaughter)
50 //_____________________________________________________________________________
51 AliRsnLoopDaughter& AliRsnLoopDaughter::operator=(const AliRsnLoopDaughter& copy)
54 // Assignment operator
57 AliRsnLoop::operator=(copy);
58 fTrueMC = copy.fTrueMC;
59 fOnlyTrue = copy.fOnlyTrue;
60 fListID = copy.fListID;
61 fDaughter = copy.fDaughter;
67 //_____________________________________________________________________________
68 AliRsnLoopDaughter::~AliRsnLoopDaughter()
75 //_____________________________________________________________________________
76 void AliRsnLoopDaughter::Print(Option_t* /*option*/) const
79 // Prints info about pair
83 //_____________________________________________________________________________
84 Bool_t AliRsnLoopDaughter::Init(const char *prefix, TList *list)
87 // Initialization function.
88 // Loops on all functions and eventual the ntuple, to initialize output objects.
91 return AliRsnLoop::Init(Form("%s_%s", prefix, GetName()), list);
94 //_____________________________________________________________________________
95 Int_t AliRsnLoopDaughter::DoLoop
96 (AliRsnEvent *evMain, AliRsnDaughterSelector *selMain, AliRsnEvent *, AliRsnDaughterSelector *)
100 // Computes what is needed from passed events.
101 // Returns the number of pairs successfully processed.
104 if (!OkEvent(evMain)) return 0;
106 Int_t i, il, nadd = 0, nlist = 0;
107 TEntryList *list[2] = {0, 0};
109 if (fDef->IsChargeDefined()) {
110 list[0] = selMain->GetSelected(fListID, fDef->GetChargeC());
114 list[0] = selMain->GetSelected(fListID, '+');
116 list[1] = selMain->GetSelected(fListID, '-');
119 list[0] = selMain->GetSelected(fListID, '0');
125 // if it is required to loop over True MC, do this here and skip the rest of the method
126 if (fTrueMC) return LoopTrueMC(evMain);
128 TObjArrayIter next(&fOutputs);
129 AliRsnListOutput *out = 0x0;
131 for (il = 0; il < nlist; il++) {
133 AliError(Form("List #%d is null", il));
136 for (i = 0; i < list[il]->GetN(); i++) {
137 evMain->SetDaughter(fDaughter, (Int_t)list[il]->GetEntry(i));
139 if (fOnlyTrue && !fDef->MatchesPID(&fDaughter)) continue;
140 if (!fDef->MatchesCharge(&fDaughter)) continue;
141 if (!fDef->MatchesRefType(&fDaughter)) continue;
142 fDaughter.FillP(fDef->GetMass());
146 while ( (out = (AliRsnListOutput*)next()) ) {
147 out->Fill(&fDaughter);
155 //_____________________________________________________________________________
156 Int_t AliRsnLoopDaughter::LoopTrueMC(AliRsnEvent *rsn)
159 // Loop on event and fill containers
162 // check presence of MC reference
163 if (!rsn->GetRefMC()) {
164 AliError("Need a MC to compute efficiency");
169 // must be ESD or AOD, and then use a bool to know in the rest
170 if (!rsn->IsESD() && !rsn->IsAOD()) {
171 AliError("Need to process ESD or AOD input");
175 // retrieve the MC primary vertex position
176 // and do some additional coherence checks
178 TClonesArray *listAOD = 0x0;
180 npart = rsn->GetRefMCESD()->GetNumberOfTracks();
182 AliAODEvent *aod = rsn->GetRefMCAOD();
183 listAOD = (TClonesArray*)(aod->GetList()->FindObject(AliAODMCParticle::StdBranchName()));
184 if (listAOD) npart = listAOD->GetEntries();
187 // check number of particles
189 AliInfo("Empty event");
194 Int_t ipart, count = 0;
195 TObjArrayIter next(&fOutputs);
196 AliRsnListOutput *out = 0x0;
197 Int_t pdg = AliRsnDaughter::SpeciesPDG(fDef->GetPID());
200 // loop over particles
201 for (ipart = 0; ipart < npart; ipart++) {
202 // check i-th particle
204 if (!rsn->GetRefMCESD()->Stack()->IsPhysicalPrimary(ipart)) continue;
205 AliMCParticle *part = (AliMCParticle*)rsn->GetRefMCESD()->GetTrack(ipart);
206 if (TMath::Abs(part->Particle()->GetPdgCode()) != pdg) continue;
207 fDaughter.SetRef (rsn->GetRefMCESD()->GetTrack(ipart));
208 fDaughter.SetRefMC(rsn->GetRefMCESD()->GetTrack(ipart));
210 AliAODMCParticle *part = (AliAODMCParticle*)listAOD->At(ipart);
211 if (!part->IsPhysicalPrimary()) continue;
212 if (TMath::Abs(part->GetPdgCode()) != pdg) continue;
213 fDaughter.SetRef ((AliAODMCParticle*)listAOD->At(ipart));
214 fDaughter.SetRefMC((AliAODMCParticle*)listAOD->At(ipart));
216 //if (fDaughter.GetPDG() != AliRsnDaughter::SpeciesPDG(fDef->GetPID())) continue;
217 fDaughter.FillP(fDef->GetMass());
221 while ( (out = (AliRsnListOutput*)next()) ) {
222 out->Fill(&fDaughter);