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