]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWGLF/RESONANCES/AliRsnLoopDaughter.cxx
Added AliRsnCutEventUtils class: interface to /Users/bellini/alisoft/aliroot/last_tru...
[u/mrichter/AliRoot.git] / PWGLF / RESONANCES / AliRsnLoopDaughter.cxx
1 //
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
7 //
8
9 #include <Riostream.h>
10 #include <TEntryList.h>
11
12 #include "AliLog.h"
13
14 #include "AliRsnEvent.h"
15 #include "AliRsnDaughterDef.h"
16 #include "AliRsnDaughterSelector.h"
17
18 #include "AliRsnLoopDaughter.h"
19
20 ClassImp(AliRsnLoopDaughter)
21
22 //_____________________________________________________________________________
23 AliRsnLoopDaughter::AliRsnLoopDaughter(const char *name, Int_t listID, AliRsnDaughterDef *def) :
24    AliRsnLoop(name),
25    fTrueMC(kFALSE),
26    fOnlyTrue(kFALSE),
27    fUseMCRef(kFALSE),
28    fListID(listID),
29    fDef(def),
30    fDaughter()
31 {
32 //
33 // Default constructor
34 //
35 }
36
37 //_____________________________________________________________________________
38 AliRsnLoopDaughter::AliRsnLoopDaughter(const AliRsnLoopDaughter &copy) :
39    AliRsnLoop(copy),
40    fTrueMC(copy.fTrueMC),
41    fOnlyTrue(copy.fOnlyTrue),
42    fUseMCRef(copy.fUseMCRef),
43    fListID(copy.fListID),
44    fDef(copy.fDef),
45    fDaughter(copy.fDaughter)
46 {
47 //
48 // Copy constructor
49 //
50 }
51
52 //_____________________________________________________________________________
53 AliRsnLoopDaughter &AliRsnLoopDaughter::operator=(const AliRsnLoopDaughter &copy)
54 {
55 //
56 // Assignment operator
57 //
58
59    AliRsnLoop::operator=(copy);
60    if (this == &copy)
61       return *this;
62    fTrueMC = copy.fTrueMC;
63    fOnlyTrue = copy.fOnlyTrue;
64    fUseMCRef = copy.fUseMCRef;
65    fListID = copy.fListID;
66    fDaughter = copy.fDaughter;
67    fDef = copy.fDef;
68
69    return (*this);
70 }
71
72 //_____________________________________________________________________________
73 AliRsnLoopDaughter::~AliRsnLoopDaughter()
74 {
75 //
76 // Destructor
77 //
78 }
79
80 //_____________________________________________________________________________
81 void AliRsnLoopDaughter::Print(Option_t * /*option*/) const
82 {
83 //
84 // Prints info about pair
85 //
86 }
87
88 //_____________________________________________________________________________
89 Bool_t AliRsnLoopDaughter::Init(const char *prefix, TList *list)
90 {
91 //
92 // Initialization function.
93 // Loops on all functions and eventual the ntuple, to initialize output objects.
94 //
95
96    return AliRsnLoop::Init(Form("%s_%s", prefix, GetName()), list);
97 }
98
99 //_____________________________________________________________________________
100 Int_t AliRsnLoopDaughter::DoLoop
101 (AliRsnEvent *evMain, AliRsnDaughterSelector *selMain, AliRsnEvent *, AliRsnDaughterSelector *)
102 {
103 //
104 // Loop function.
105 // Computes what is needed from passed events.
106 // Returns the number of pairs successfully processed.
107 //
108
109    if (!OkEvent(evMain)) return 0;
110
111    Int_t i, il, nadd = 0, nlist = 0;
112    TEntryList *list[2] = {0, 0};
113
114    if (fDef->IsChargeDefined()) {
115       list[0] = selMain->GetSelected(fListID, fDef->GetChargeC());
116       list[1] = 0x0;
117       nlist = 1;
118    } else {
119       list[0] = selMain->GetSelected(fListID, '+');
120       if (list[0]) {
121          list[1] = selMain->GetSelected(fListID, '-');
122          nlist = 2;
123       } else {
124          list[0] = selMain->GetSelected(fListID, '0');
125          list[1] = 0x0;
126          nlist = 1;
127       }
128    }
129
130    // if it is required to loop over True MC, do this here and skip the rest of the method
131    if (fTrueMC) return LoopTrueMC(evMain);
132
133    TObjArrayIter next(&fOutputs);
134    AliRsnListOutput *out = 0x0;
135
136    for (il = 0; il < nlist; il++) {
137       if (!list[il]) {
138          AliError(Form("List #%d is null", il));
139          continue;
140       }
141       for (i = 0; i < list[il]->GetN(); i++) {
142          evMain->SetDaughter(fDaughter, (Int_t)list[il]->GetEntry(i));
143          // check matching
144          if (fOnlyTrue && !fDef->MatchesPID(&fDaughter)) continue;
145          if (!fDef->MatchesCharge(&fDaughter)) continue;
146          if (!fDef->MatchesRefType(&fDaughter)) continue;
147          fDaughter.FillP(fDef->GetMass());
148          // fill outputs
149          nadd++;
150          next.Reset();
151          while ( (out = (AliRsnListOutput *)next()) ) {
152             out->Fill(&fDaughter);
153          }
154       }
155    }
156
157    return nadd;
158 }
159
160 //_____________________________________________________________________________
161 Int_t AliRsnLoopDaughter::LoopTrueMC(AliRsnEvent *rsn)
162 {
163 //
164 // Loop on event and fill containers
165 //
166
167    // check presence of MC reference
168    if (!rsn->GetRefMC()) {
169       AliError("Need a MC to compute efficiency");
170       return 0;
171    }
172
173    // check event type:
174    // must be ESD or AOD, and then use a bool to know in the rest
175    if (!rsn->IsESD() && !rsn->IsAOD()) {
176       AliError("Need to process ESD or AOD input");
177       return 0;
178    }
179
180    // retrieve the MC primary vertex position
181    // and do some additional coherence checks
182    Int_t npart = 0;
183    TClonesArray *listAOD = 0x0;
184    if (rsn->IsESD()) {
185       npart = rsn->GetRefMCESD()->GetNumberOfTracks();
186    } else {
187       AliAODEvent *aod = rsn->GetRefMCAOD();
188       listAOD = (TClonesArray *)(aod->GetList()->FindObject(AliAODMCParticle::StdBranchName()));
189       if (listAOD) npart = listAOD->GetEntries();
190    }
191
192    // check number of particles
193    if (!npart) {
194       AliInfo("Empty event");
195       return 0;
196    }
197
198    // utility variables
199    Int_t ipart, count = 0;
200    TObjArrayIter next(&fOutputs);
201    AliRsnListOutput *out = 0x0;
202    Int_t pdg = AliRsnDaughter::SpeciesPDG(fDef->GetPID());
203
204
205    // loop over particles
206    for (ipart = 0; ipart < npart; ipart++) {
207       // check i-th particle
208       if (rsn->IsESD()) {
209          if (!rsn->GetRefMCESD()->Stack()->IsPhysicalPrimary(ipart)) continue;
210          AliMCParticle *part = (AliMCParticle *)rsn->GetRefMCESD()->GetTrack(ipart);
211          if (TMath::Abs(part->Particle()->GetPdgCode()) != pdg) continue;
212          fDaughter.SetRef  (rsn->GetRefMCESD()->GetTrack(ipart));
213          fDaughter.SetRefMC(rsn->GetRefMCESD()->GetTrack(ipart));
214       } else {
215          AliAODMCParticle *part = (AliAODMCParticle *)listAOD->At(ipart);
216          if (!part->IsPhysicalPrimary()) continue;
217          if (TMath::Abs(part->GetPdgCode()) != pdg) continue;
218          fDaughter.SetRef  ((AliAODMCParticle *)listAOD->At(ipart));
219          fDaughter.SetRefMC((AliAODMCParticle *)listAOD->At(ipart));
220       }
221       //if (fDaughter.GetPDG() != AliRsnDaughter::SpeciesPDG(fDef->GetPID())) continue;
222       fDaughter.FillP(fDef->GetMass());
223       // fill outputs
224       count++;
225       next.Reset();
226       while ( (out = (AliRsnListOutput *)next()) ) {
227          out->Fill(&fDaughter);
228       }
229    }
230
231    return count;
232 }