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