]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWG2/RESONANCES/AliRsnAnalysisTaskEff.cxx
Coverity fixes
[u/mrichter/AliRoot.git] / PWG2 / RESONANCES / AliRsnAnalysisTaskEff.cxx
1 //
2 // Class AliRsnAnalysisTaskEff
3 //
4 // Base class for efficiency computation tasks
5 // which should be inherited by different efficiency computators
6 //
7 // author: Alberto Pulvirenti (alberto.pulvirenti@ct.infn.it)
8 //
9
10 #include "AliVEvent.h"
11
12 #include "AliRsnEvent.h"
13 #include "AliRsnCutSet.h"
14
15 #include "AliRsnAnalysisTaskEff.h"
16
17 ClassImp(AliRsnAnalysisTaskEff)
18
19 //_____________________________________________________________________________
20 AliRsnAnalysisTaskEff::AliRsnAnalysisTaskEff(const char *name) :
21    AliRsnVAnalysisTask(name),
22    fDefs(0),
23    fStepsMC(0),
24    fStepsRec(0),
25    fAxes("AliRsnValue", 0),
26    fOutList(0x0),
27    fEventCuts("eventCuts", AliRsnCut::kEvent),
28    fVar(0)
29 {
30 //
31 // Default constructor.
32 //
33
34    DefineOutput(2, TList::Class());
35 }
36
37 //_____________________________________________________________________________
38 AliRsnAnalysisTaskEff::AliRsnAnalysisTaskEff(const AliRsnAnalysisTaskEff& copy) :
39    AliRsnVAnalysisTask(copy),
40    fDefs(copy.fDefs),
41    fStepsMC(copy.fStepsMC),
42    fStepsRec(copy.fStepsRec),
43    fAxes(copy.fAxes),
44    fOutList(0x0),
45    fEventCuts(copy.fEventCuts),
46    fVar(0)
47 {
48 //
49 // Copy constrtuctor
50 //
51 }
52
53 //_____________________________________________________________________________
54 AliRsnAnalysisTaskEff& AliRsnAnalysisTaskEff::operator=(const AliRsnAnalysisTaskEff& copy)
55 {
56 //
57 // Assignment operator
58 //
59
60    AliRsnVAnalysisTask::operator=(copy);
61    
62    fDefs = copy.fDefs;
63    fStepsMC = copy.fStepsMC;
64    fStepsRec = copy.fStepsRec;
65    fAxes = copy.fAxes;
66    fEventCuts = copy.fEventCuts;
67    
68    return (*this);
69 }
70
71 //_____________________________________________________________________________
72 void AliRsnAnalysisTaskEff::AddDef(TObject* def)
73 {
74 //
75 //  Adds pair definition
76 //
77    fDefs.AddLast(def);
78 }
79
80 //_____________________________________________________________________________
81 void AliRsnAnalysisTaskEff::AddAxis(AliRsnValue *axis)
82 {
83 //
84 // Add a new axis
85 //
86
87    Int_t n = fAxes.GetEntries();
88    new (fAxes[n]) AliRsnValue(*axis);
89 }
90
91 //_____________________________________________________________________________
92 void AliRsnAnalysisTaskEff::AddStepMC(TObject *cuts)
93 {
94 //
95 // Add a step on montecarlo
96 //
97
98    fStepsMC.AddLast(cuts);
99 }
100
101 //_____________________________________________________________________________
102 void AliRsnAnalysisTaskEff::AddStepRec(TObject *cuts)
103 {
104 //
105 // Add a step on ESD
106 //
107
108    fStepsRec.AddLast(cuts);
109 }
110
111 //_____________________________________________________________________________
112 void AliRsnAnalysisTaskEff::RsnUserCreateOutputObjects()
113 {
114 //
115 // Creation of output objects.
116 // These are created through the utility methods in the analysis manager,
117 // which produces a list of histograms for each specified set of pairs.
118 // Each of these lists is added to the main list of this task.
119 //
120
121    // get number of steps and axes
122    Int_t iaxis  = 0;
123    Int_t nAxes  = fAxes.GetEntries();
124    Int_t nSteps = (Int_t)fStepsMC.GetEntries() + (Int_t)fStepsRec.GetEntries();
125
126    if (!nSteps) {
127       AliError("No steps defined");
128       return;
129    }
130    if (!nAxes) {
131       AliError("No axes defined");
132       return;
133    }
134
135    // initialize variable list
136    fVar.Set(nAxes);
137
138    // retrieve number of bins for each axis
139    Int_t *nBins = new Int_t[nAxes];
140    for (iaxis = 0; iaxis < nAxes; iaxis++) {
141       AliRsnValue *fcnAxis = (AliRsnValue*)fAxes.At(iaxis);
142       nBins[iaxis] = fcnAxis->GetArray().GetSize() - 1;
143    }
144
145    // initialize output list
146    OpenFile(2);
147    fOutList = new TList();
148    fOutList->SetOwner();
149
150    // create the containers
151    Int_t i, nDef = (Int_t)fDefs.GetEntries();
152    for (i = 0; i < nDef; i++) {
153       // instantiate a new container
154       AliCFContainer *cont = new AliCFContainer(fDefs[i]->GetName(), "", nSteps, nAxes, nBins);
155       // set the bin limits for each axis
156       for (iaxis = 0; iaxis < nAxes; iaxis++) {
157          AliRsnValue *fcnAxis = (AliRsnValue*)fAxes.At(iaxis);
158          cont->SetBinLimits(iaxis, fcnAxis->GetArray().GetArray());
159       }
160       // add the container to output list
161       fOutList->Add(cont);
162    }
163
164    PostData(2, fOutList);
165
166    // clear heap
167    delete [] nBins;
168 }
169
170 //_____________________________________________________________________________
171 void AliRsnAnalysisTaskEff::RsnUserExec(Option_t*)
172 {
173 //
174 // Execution of the analysis task.
175 // Recovers the input event and processes it with all included pair objects.
176 // In this case, we NEED to have reconstruction and MC, otherwise we cannot do anything.
177 //
178
179    if (fRsnEvent[0].IsESD()) ProcessEventESD();
180    if (fRsnEvent[0].IsAOD()) ProcessEventAOD();
181
182    PostData(2, fOutList);
183 }
184
185 //_____________________________________________________________________________
186 void AliRsnAnalysisTaskEff::RsnTerminate(Option_t*)
187 {
188 //
189 // Termination.
190 // Could be added some monitor histograms here.
191 //
192 }
193
194 //______________________________________________________________________________
195 Bool_t AliRsnAnalysisTaskEff::RsnEventProcess()
196 {
197 //
198 // Customized event pre-processing.
199 // First checks if the current event passes all cuts,
200 // and if it does, updates the informations and then
201 // call the operations which are already defined in the
202 // omonyme function in mother class
203 //
204
205    // initially, an event is expected to be bad
206    fTaskInfo.SetEventUsed(kFALSE);
207
208    // check the event cuts and update the info data accordingly
209    // events not passing the cuts must be rejected
210    if (!fEventCuts.IsSelected(&fRsnEvent[0])) {
211       fTaskInfo.SetEventUsed(kFALSE);
212       return kFALSE;
213    }
214
215    // if we reach this point, cuts were passed;
216    // then additional operations can be done
217
218    // find leading particle (without any PID/momentum restriction)
219    fRsnEvent[0].SelectLeadingParticle(0);
220
221    // final return value is positive
222    // but call the mother class method which updates info object
223    fTaskInfo.SetEventUsed(kTRUE);
224    return AliRsnVAnalysisTask::RsnEventProcess();
225 }
226
227 //_____________________________________________________________________________
228 TArrayI AliRsnAnalysisTaskEff::FindTracks(Int_t label, AliVEvent *event)
229 {
230 //
231 // Loops an event and find all tracks which have a label
232 // equal to that passed as first argument.
233 //
234
235    Int_t   i = 0, nfound = 0;
236    Int_t   ntracks = event->GetNumberOfTracks();
237    TArrayI array(100);
238
239    for (i = 0; i < ntracks; i++) {
240       AliVParticle *track = event->GetTrack(i);
241       if (TMath::Abs(track->GetLabel()) != label) continue;
242       array[nfound++] = i;
243    }
244
245    array.Set(nfound);
246    return array;
247 }
248
249 //_____________________________________________________________________________
250 Int_t AliRsnAnalysisTaskEff::NGoodSteps()
251 {
252 //
253 // Tells the maximum step where cuts for the checked objects are passed
254 //
255
256    AliInfo("Must be overloaded in inheriting tasks");
257    
258    return 0;
259 }
260
261 //_____________________________________________________________________________
262 void AliRsnAnalysisTaskEff::ProcessEventESD()
263 {
264 //
265 // Process current event with the definitions of the specified step in MC list
266 // and store results in the container slot defined in second argument.
267 // It is associated with the AliCFContainer with the name of the pair.
268 //
269
270    AliInfo("Must be overloaded in inheriting tasks");
271 }
272
273 //_____________________________________________________________________________
274 void AliRsnAnalysisTaskEff::ProcessEventAOD()
275 {
276 //
277 // Process current event with the definitions of the specified step in MC list
278 // and store results in the container slot defined in second argument.
279 // It is associated with the AliCFContainer with the name of the pair.
280 //
281
282    AliInfo("Must be overloaded in inheriting tasks");
283 }
284
285 //_____________________________________________________________________________
286 void AliRsnAnalysisTaskEff::FillContainer(Bool_t, TObject*)
287 {
288 //
289 // Fill the containers
290 //
291
292    AliInfo("Must be overloaded in inheriting tasks");
293 }