]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWGLF/RESONANCES/AliRsnDaughterSelector.cxx
Added cut set for kstar analysis (fbellini)
[u/mrichter/AliRoot.git] / PWGLF / RESONANCES / AliRsnDaughterSelector.cxx
1 #include <Riostream.h>
2 #include <TEntryList.h>
3
4 #include "AliLog.h"
5
6 #include "AliRsnCutSet.h"
7 #include "AliRsnDaughterDef.h"
8 #include "AliRsnAction.h"
9
10 #include "AliRsnDaughterSelector.h"
11
12 ClassImp(AliRsnDaughterSelector)
13
14 //__________________________________________________________________________________________________
15 AliRsnDaughterSelector::AliRsnDaughterSelector(const char *name, const char *title) :
16    TNamed(name, title),
17    fCutSetsN("AliRsnCutSet", 0),
18    fCutSetsC("AliRsnCutSet", 0),
19    fEntryListsN("TEntryList", 0),
20    fEntryListsP("TEntryList", 0),
21    fEntryListsM("TEntryList", 0),
22    fUseLabelCheck(kTRUE),
23    fActions()
24 {
25 //
26 // Default constructor.
27 //
28
29    AliDebug(AliLog::kDebug + 10, "<-");
30    AliDebug(AliLog::kDebug + 10, "->");
31 }
32
33 //__________________________________________________________________________________________________
34 AliRsnDaughterSelector::AliRsnDaughterSelector(const AliRsnDaughterSelector &copy) :
35    TNamed(copy),
36    fCutSetsN(copy.fCutSetsN),
37    fCutSetsC(copy.fCutSetsC),
38    fEntryListsN(copy.fEntryListsN),
39    fEntryListsP(copy.fEntryListsP),
40    fEntryListsM(copy.fEntryListsM),
41    fUseLabelCheck(copy.fUseLabelCheck),
42    fActions(copy.fActions)
43 {
44 //
45 // Copy constructor.
46 //
47
48    AliDebug(AliLog::kDebug + 10, "<-");
49    AliDebug(AliLog::kDebug + 10, "->");
50 }
51
52 //__________________________________________________________________________________________________
53 AliRsnDaughterSelector &AliRsnDaughterSelector::operator=(const AliRsnDaughterSelector &copy)
54 {
55 //
56 // Copy constructor.
57 //
58
59    AliDebug(AliLog::kDebug + 10, "<-");
60
61    TNamed::operator=(copy);
62    if (this == &copy)
63       return *this;
64    fCutSetsN = copy.fCutSetsN;
65    fCutSetsC = copy.fCutSetsC;
66    fEntryListsN = copy.fEntryListsN;
67    fEntryListsP = copy.fEntryListsP;
68    fEntryListsM = copy.fEntryListsM;
69    fUseLabelCheck = copy.fUseLabelCheck;
70    fActions = copy.fActions;
71
72    AliDebug(AliLog::kDebug + 10, "->");
73
74    return (*this);
75 }
76
77 //__________________________________________________________________________________________________
78 AliRsnDaughterSelector::~AliRsnDaughterSelector()
79 {
80 //
81 // Destructor
82 //
83
84    AliDebug(AliLog::kDebug + 10, "<-");
85
86    fCutSetsN.Delete();
87    fCutSetsC.Delete();
88    fEntryListsN.Delete();
89    fEntryListsP.Delete();
90    fEntryListsM.Delete();
91
92    fActions.Delete();
93
94    AliDebug(AliLog::kDebug + 10, "->");
95 }
96
97 //__________________________________________________________________________________________________
98 void AliRsnDaughterSelector::Print(Option_t *option) const
99 {
100 //
101 // Override TObject::Print()
102 //
103
104    TNamed::Print(option);
105
106    Int_t i, nSets;
107    AliRsnCutSet *set = 0x0;
108    TEntryList *list = 0x0;
109
110    // neutral
111    nSets = fCutSetsN.GetEntries();
112    for (i = 0; i < nSets; i++) {
113       set = (AliRsnCutSet *)fCutSetsN[i];
114       list = (TEntryList *)fEntryListsN[i];
115       AliInfo(Form("Neutral entry list for cut set '%s' has %d entries", set->GetName(), (Int_t)list->GetN()));
116    }
117
118    // charged
119    nSets = fCutSetsC.GetEntries();
120    for (i = 0; i < nSets; i++) {
121       set = (AliRsnCutSet *)fCutSetsC[i];
122       list = (TEntryList *)fEntryListsP[i];
123       AliInfo(Form("Positive entry list for cut set '%s' has %d entries", set->GetName(), (Int_t)list->GetN()));
124       list = (TEntryList *)fEntryListsM[i];
125       AliInfo(Form("Negative entry list for cut set '%s' has %d entries", set->GetName(), (Int_t)list->GetN()));
126    }
127 }
128
129 //__________________________________________________________________________________________________
130 void AliRsnDaughterSelector::Init()
131 {
132 //
133 // Initialize the arrays of entry lists to the same size
134 // of the corresponding arrays of cut sets.
135 // If they are not empty, they are cleared.
136 //
137
138    Int_t i, nSets;
139
140    // neutral
141    nSets = fCutSetsN.GetEntries();
142    if (!fEntryListsN.IsEmpty()) fEntryListsN.Delete();
143    for (i = 0; i < nSets; i++) {
144       AliRsnCutSet *set = (AliRsnCutSet *)fCutSetsN[i];
145       new (fEntryListsN[i]) TEntryList;
146       AliInfo(Form("Adding 1 entry list for neutrals --> cut set '%s' [scheme = '%s']", set->GetName(), set->GetCutScheme().Data()));
147    }
148
149    // charged
150    nSets = fCutSetsC.GetEntries();
151    if (!fEntryListsP.IsEmpty()) fEntryListsP.Delete();
152    if (!fEntryListsM.IsEmpty()) fEntryListsM.Delete();
153    for (i = 0; i < nSets; i++) {
154       AliRsnCutSet *set = (AliRsnCutSet *)fCutSetsC[i];
155       new (fEntryListsP[i]) TEntryList;
156       new (fEntryListsM[i]) TEntryList;
157       AliInfo(Form("Adding 2 entry lists for charged --> cut set '%s' [scheme = '%s']", set->GetName(), set->GetCutScheme().Data()));
158    }
159 }
160
161 //__________________________________________________________________________________________________
162 void AliRsnDaughterSelector::AddAction(AliRsnAction *action)
163 {
164 //
165 // Adding action
166 //
167    if (!action) return;
168
169    fActions.Add(action);
170 }
171
172
173 //__________________________________________________________________________________________________
174 void AliRsnDaughterSelector::InitActions(TList *list)
175 {
176 //
177 // Initialize output for post actiosn
178 //
179    if (!list) return;
180    TObjArray objects;
181    objects.Add(this);
182
183    TIter next(&fActions);
184    AliRsnAction *action;
185    while ((action = (AliRsnAction *)next())) {
186       action->InitAction(list,&objects);
187    }
188
189 }
190
191 //__________________________________________________________________________________________________
192 void AliRsnDaughterSelector::ExecActions(AliRsnEvent *ev)
193 {
194 //
195 // Exec Actions
196 //
197
198    if (!ev) return;
199
200    TObjArray objects;
201    objects.Add(ev);
202
203    TIter next(&fActions);
204    AliRsnAction *action;
205    while ((action = (AliRsnAction *)next())) {
206       action->ExecAction(&objects);
207    }
208 }
209
210
211 //__________________________________________________________________________________________________
212 void AliRsnDaughterSelector::Reset()
213 {
214    TEntryList *el;
215    Int_t i, nSets;
216
217    // N
218    nSets = fCutSetsN.GetEntries();
219    for (i = 0; i < nSets; i++) {
220       el = (TEntryList *)fEntryListsN.At(i);
221       el->Reset();
222    }
223
224    // charged
225    nSets = fCutSetsC.GetEntries();
226    for (i = 0; i < nSets; i++) {
227       el = (TEntryList *)fEntryListsP.At(i);
228       el->Reset();
229       el = (TEntryList *)fEntryListsM.At(i);
230       el->Reset();
231    }
232 }
233
234 //__________________________________________________________________________________________________
235 Int_t AliRsnDaughterSelector::Add(AliRsnCutSet *cuts, Bool_t charged)
236 {
237 //
238 // Add a new selection slot defined by a set of cuts and daughter definition
239 //
240
241    Int_t n = 0;
242
243    if (!charged) {
244       n = fCutSetsN.GetEntries();
245       new (fCutSetsN[n]) AliRsnCutSet(*cuts);
246    } else {
247       n = fCutSetsC.GetEntries();
248       new (fCutSetsC[n]) AliRsnCutSet(*cuts);
249    }
250
251    return n;
252 }
253
254 //__________________________________________________________________________________________________
255 Int_t AliRsnDaughterSelector::GetID(const char *name, Bool_t charged)
256 {
257 //
258 // Add a new selection slot defined by a set of cuts and daughter definition
259 //
260
261    AliRsnCutSet *cuts;
262
263    if (!charged) {
264       cuts = (AliRsnCutSet *)fCutSetsN.FindObject(name);
265       if (cuts) return fCutSetsN.IndexOf(cuts);
266    } else {
267       cuts = (AliRsnCutSet *)fCutSetsC.FindObject(name);
268       if (cuts) return fCutSetsC.IndexOf(cuts);
269    }
270
271    return -1;
272 }
273
274 //__________________________________________________________________________________________________
275 TEntryList *AliRsnDaughterSelector::GetSelected(Int_t i, Char_t charge)
276 {
277 //
278 // Retrieve a given entry list (needs charge specified as a char)
279 //
280
281    if (charge == '+')
282       return (TEntryList *)fEntryListsP.At(i);
283    else if (charge == '-')
284       return (TEntryList *)fEntryListsM.At(i);
285    else
286       return (TEntryList *)fEntryListsN.At(i);
287 }
288
289 //__________________________________________________________________________________________________
290 TEntryList *AliRsnDaughterSelector::GetSelected(Int_t i, Short_t charge)
291 {
292 //
293 // Retrieve a given entry list passing charge as short
294 //
295
296    if (charge > 0)
297       return (TEntryList *)fEntryListsP.At(i);
298    else if (charge < 0)
299       return (TEntryList *)fEntryListsM.At(i);
300    else
301       return (TEntryList *)fEntryListsN.At(i);
302 }
303
304 //__________________________________________________________________________________________________
305 void AliRsnDaughterSelector::ScanEvent(AliRsnEvent *ev)
306 {
307 //
308 // Loop over event and fill all entry lists
309 //
310
311    Int_t id, is;
312    Int_t label;
313    Int_t nSel, nTot = ev->GetAbsoluteSum();
314    AliRsnDaughter check;
315    TClonesArray *cutsArray = 0x0, *entryArray = 0x0;
316    TEntryList labelList;
317    TEntryList *el = 0;
318    AliRsnCutSet *cuts;
319    for (id = 0; id < nTot; id++) {
320       ev->SetDaughter(check, id);
321       // some checks
322       if (!check.GetRef()) {
323          AliDebugClass(1, Form("[%s]: daughter has NULL ref", GetName()));
324          continue;
325       }
326       if (!check.IsOK()) {
327          AliDebugClass(1, Form("[%s]: daughter is BAD", GetName()));
328          continue;
329       }
330       // set pointers according to charge
331       if (check.ChargeS() > 0) {
332          cutsArray = &fCutSetsC;
333          entryArray = &fEntryListsP;
334       } else if (check.ChargeS() < 0) {
335          cutsArray = &fCutSetsC;
336          entryArray = &fEntryListsM;
337       } else {
338          cutsArray = &fCutSetsN;
339          entryArray = &fEntryListsN;
340       }
341
342       // gets label for later use
343       label = check.GetLabel();
344
345       // check if label was not in labelList
346       if (fUseLabelCheck && labelList.Contains(label)) continue;
347
348       // check with all cuts in that charge
349       nSel = cutsArray->GetEntries();
350       for (is = 0; is < nSel; is++) {
351          cuts = (AliRsnCutSet *)cutsArray->At(is);
352          if (cuts->IsSelected(&check)) {
353             el = (TEntryList *)entryArray->At(is);
354             el->Enter(id);
355             if (fUseLabelCheck && label >= 0) labelList.Enter(label);
356          }
357       }
358    }
359 }
360