]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWG2/RESONANCES/AliRsnAnalysisTrackEffSE.cxx
MCEvent::GetTrack gives back *VParticle.
[u/mrichter/AliRoot.git] / PWG2 / RESONANCES / AliRsnAnalysisTrackEffSE.cxx
1 //
2 // Class AliRsnAnalysisTrackEffSE
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 "AliMCEvent.h"
14
15 #include "AliCFContainer.h"
16 #include "AliRsnCutSet.h"
17 #include "AliRsnFunctionAxis.h"
18 #include "AliRsnAnalysisTrackEffSE.h"
19 #include "AliRsnCutSet.h"
20
21 ClassImp(AliRsnAnalysisTrackEffSE)
22
23 //_____________________________________________________________________________
24 AliRsnAnalysisTrackEffSE::AliRsnAnalysisTrackEffSE(const char *name) :
25   AliRsnVAnalysisTaskSE(name),
26   fEventCuts(0x0),
27   fStepListMC(0),
28   fStepListESD(0),
29   fAxisList(0),
30   fVar(0)
31 {
32 //
33 // Default constructor.
34 //
35
36   AliDebug(AliLog::kDebug+2,"<-");
37
38   DefineOutput(2, TList::Class());
39
40   Int_t i;
41   for (i = 0; i <= AliPID::kSPECIES; i++) fContainer[i] = 0x0;
42
43   AliDebug(AliLog::kDebug+2,"->");
44 }
45
46 //_____________________________________________________________________________
47 AliRsnAnalysisTrackEffSE::AliRsnAnalysisTrackEffSE(const AliRsnAnalysisTrackEffSE& copy) :
48   AliRsnVAnalysisTaskSE(copy),
49   fEventCuts(copy.fEventCuts),
50   fStepListMC(copy.fStepListMC),
51   fStepListESD(copy.fStepListESD),
52   fAxisList(copy.fAxisList),
53   fVar(0)
54 {
55 //
56 // Copy constrtuctor
57 //
58 }
59
60 //_____________________________________________________________________________
61 void AliRsnAnalysisTrackEffSE::RsnUserCreateOutputObjects()
62 {
63 //
64 // Creation of output objects.
65 // These are created through the utility methods in the analysis manager,
66 // which produces a list of histograms for each specified set of pairs.
67 // Each of these lists is added to the main list of this task.
68 //
69
70   AliDebug(AliLog::kDebug+2,"<-");
71
72   // get number of steps and axes
73   Int_t iaxis;
74   Int_t nAxes  = fAxisList.GetEntries();
75   Int_t nSteps = (Int_t)fStepListMC.GetEntries() + (Int_t)fStepListESD.GetEntries();
76
77   if (!nSteps) {
78     AliError("No steps defined");
79     return;
80   }
81   if (!nAxes) {
82     AliError("No axes defined");
83     return;
84   }
85
86   // initialize variable list
87   fVar.Set(nAxes);
88
89   // retrieve number of bins for each axis
90   Int_t   *nBins     = new Int_t[nAxes];
91   TArrayD *binLimits = new TArrayD[nAxes];
92   for (iaxis = 0; iaxis < nAxes; iaxis++) {
93     AliRsnFunctionAxis *fcnAxis = (AliRsnFunctionAxis*)fAxisList.At(iaxis);
94     binLimits[iaxis] = fcnAxis->GetArray();
95     nBins[iaxis] = binLimits[iaxis].GetSize() - 1;
96   }
97
98   // initialize output list
99   OpenFile(2);
100   fOutList[1] = new TList();
101   fOutList[1]->SetOwner();
102
103   // create the containers
104   Int_t i;
105   for (i = 0; i <= AliPID::kSPECIES; i++)
106   {
107     if (i < AliPID::kSPECIES) fContainer[i] = new AliCFContainer(Form("%s", AliPID::ParticleName((AliPID::EParticleType)i)), "", nSteps, nAxes, nBins);
108     else fContainer[i] = new AliCFContainer("all", "", nSteps, nAxes, nBins);
109     // set the bin limits for each axis
110     for (iaxis = 0; iaxis < nAxes; iaxis++) fContainer[i]->SetBinLimits(iaxis, binLimits[iaxis].GetArray());
111     // add the container to output list
112     fOutList[1]->Add(fContainer[i]);
113   }
114
115   AliDebug(AliLog::kDebug+2,"->");
116 }
117
118 //_____________________________________________________________________________
119 void AliRsnAnalysisTrackEffSE::RsnUserExec(Option_t*)
120 {
121 //
122 // Execution of the analysis task.
123 // Recovers the input event and processes it with all included pair objects.
124 // In this case, we NEED to have ESD and MC, otherwise we cannod do anything.
125 //
126
127   AliDebug(AliLog::kDebug+2,"<-");
128   if (!fESDEvent || !fMCEvent) {
129     AliError("This task can process only ESD + MC events");
130     return;
131   }
132   fRsnEvent.SetRef(fESDEvent, fMCEvent);
133
134   // if general event cuts are added to the task (recommended)
135   // they are checked here on the RSN event interface and,
136   // if the event does not pass them, it is skipped and ProcessInfo
137   // is updated accordingly
138   if (fEventCuts) {
139     if (!fEventCuts->IsSelected(AliRsnCut::kEvent, &fRsnEvent)) {
140       fTaskInfo.SetEventUsed(kFALSE);
141       return;
142     }
143   }
144
145   // if cuts are passed or not cuts were defined,
146   // update the task info before processing the event
147   fTaskInfo.SetEventUsed(kTRUE);
148
149   // process first MC steps and then ESD steps
150   ProcessEventMC();
151   ProcessEventESD();
152
153   // Post the data
154   PostData(2, fOutList[1]);
155
156   AliDebug(AliLog::kDebug+2,"->");
157 }
158
159 //_____________________________________________________________________________
160 void AliRsnAnalysisTrackEffSE::ProcessEventMC()
161 {
162 //
163 // Process current event with the definitions of the specified step in MC list
164 // and store results in the container slot defined in second argument
165 //
166
167   AliStack      *stack = fMCEvent->Stack();
168   AliMCParticle *part;
169
170   // other utility variables
171   Int_t ipart;
172
173   // in this case, we first take the resonance from MC
174   // and then we find its daughters and compute cuts on them
175   for (ipart = 0; ipart < fMCEvent->GetNumberOfTracks(); ipart++)
176   {
177     part = (AliMCParticle*) fMCEvent->GetTrack(ipart);
178
179     fDaughter.SetRef(part);
180     fDaughter.SetParticle(part->Particle());
181     fDaughter.FindMotherPDG(stack);
182     
183     FillContainer(&fStepListMC, 0);
184   }
185 }
186
187 //_____________________________________________________________________________
188 void AliRsnAnalysisTrackEffSE::ProcessEventESD()
189 {
190 //
191 // Process current event with the definitions of the specified step in ESD list
192 // and store results in the container slot defined in second argument
193 //
194
195   Int_t ic, i, first = (Int_t)fStepListMC.GetEntries();
196
197   // get arrays of all charged tracks
198   TArrayI *a[2];
199   a[0] = fRsnPIDIndex.GetTracksArray(AliRsnDaughter::kNoPID, '+', AliPID::kUnknown);
200   a[1] = fRsnPIDIndex.GetTracksArray(AliRsnDaughter::kNoPID, '-', AliPID::kUnknown);
201
202   // external loop on tracks
203   for (ic = 0; ic < 2; ic++)
204   {
205     for (i = 0; i < a[ic]->GetSize(); i++)
206     {
207       // connect interface
208       fRsnEvent.SetDaughter(fDaughter, a[ic]->At(i));
209       if (!fDaughter.IsOK()) continue;
210       fDaughter.SetRequiredPID(fDaughter.PerfectPID());
211
212       FillContainer(&fStepListESD, first);
213     }
214   }
215 }
216
217 //_____________________________________________________________________________
218 void AliRsnAnalysisTrackEffSE::FillContainer
219 (const TObjArray *stepList, Int_t firstOutStep)
220 {
221 //
222 // Fill the containers
223 //
224
225   Int_t ipid;
226   Int_t iaxis, nAxes  = fAxisList.GetEntries();
227   Int_t istep, nSteps = stepList->GetEntries();
228
229   // compute values for all axes
230   for (iaxis = 0; iaxis < nAxes; iaxis++) {
231     AliRsnFunctionAxis *fcnAxis = (AliRsnFunctionAxis*)fAxisList.At(iaxis);
232     switch (fcnAxis->GetAxisObject())
233     {
234       case AliRsnFunctionAxis::kParticle:
235         fVar[iaxis] = (Double_t)fcnAxis->Eval(&fDaughter);
236         break;
237       case AliRsnFunctionAxis::kEvent:
238         fVar[iaxis] = (Double_t)fcnAxis->Eval(&fRsnEvent);
239         break;
240       default:
241         fVar[iaxis] = 0.0;
242     }
243   }
244
245   // fill all steps
246   for (istep = 0; istep < nSteps; istep++) {
247     AliRsnCutSet *cutSet = (AliRsnCutSet*)stepList->At(istep);
248     if (!cutSet->IsSelected(AliRsnCut::kParticle, &fDaughter)) break;
249     if (stepList == &fStepListESD && !PassedAllCutsMC()) break;
250
251     ipid = (Int_t)fDaughter.PerfectPID();
252     if (ipid == (Int_t)AliPID::kUnknown) ipid = (Int_t)AliPID::kSPECIES;
253     fContainer[ipid]->Fill(fVar.GetArray(), istep + firstOutStep);
254     fContainer[AliPID::kSPECIES]->Fill(fVar.GetArray(), istep + firstOutStep);
255   }
256 }
257
258 //_____________________________________________________________________________
259 Bool_t AliRsnAnalysisTrackEffSE::PassedAllCutsMC()
260 {
261 //
262 // Check if this daughter passes all cuts MC
263 //
264
265   Int_t istep, nSteps = fStepListMC.GetEntries();
266
267   for (istep = 0; istep < nSteps; istep++) {
268     AliRsnCutSet *cutSet = (AliRsnCutSet*)fStepListMC.At(istep);
269     if (!cutSet->IsSelected(AliRsnCut::kParticle, &fDaughter)) return kFALSE;
270   }
271
272   return kTRUE;
273 }
274
275 //_____________________________________________________________________________
276 void AliRsnAnalysisTrackEffSE::RsnTerminate(Option_t*)
277 {
278 //
279 // Termination.
280 // Could be added some monitor histograms here.
281 //
282
283   AliDebug(AliLog::kDebug+2,"<-");
284   AliDebug(AliLog::kDebug+2,"->");
285 }
286