]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWG2/RESONANCES/AliRsnDaughterSelector.cxx
Added another version of cut for pp (small differences in PID)
[u/mrichter/AliRoot.git] / PWG2 / RESONANCES / AliRsnDaughterSelector.cxx
1 #include <Riostream.h>
2 #include <TEntryList.h>
3
4 #include "AliLog.h"
5 #include "AliRsnMiniParticle.h"
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    
58    fCutSetsN = copy.fCutSetsN;
59    fCutSetsC = copy.fCutSetsC;
60    fEntryListsN = copy.fEntryListsN;
61    fEntryListsP = copy.fEntryListsP;
62    fEntryListsM = copy.fEntryListsM;
63
64    AliDebug(AliLog::kDebug + 10, "->");
65    
66    return (*this);
67 }
68
69 //__________________________________________________________________________________________________
70 AliRsnDaughterSelector::~AliRsnDaughterSelector()
71 {
72 //
73 // Destructor
74 //
75
76    AliDebug(AliLog::kDebug + 10, "<-");
77    
78    fCutSetsN.Delete();
79    fCutSetsC.Delete();
80    fEntryListsN.Delete();
81    fEntryListsP.Delete();
82    fEntryListsM.Delete();
83    
84    AliDebug(AliLog::kDebug + 10, "->");
85 }
86
87 //__________________________________________________________________________________________________
88 void AliRsnDaughterSelector::Print(Option_t* option) const
89 {
90 //
91 // Override TObject::Print()
92 //
93
94    TNamed::Print(option);
95    
96    Int_t i, nSets;
97    AliRsnCutSet *set = 0x0;
98    TEntryList *list = 0x0;
99    
100    // neutral
101    nSets = fCutSetsN.GetEntries();
102    for (i = 0; i < nSets; i++) {
103       set = (AliRsnCutSet*)fCutSetsN[i];
104       list = (TEntryList*)fEntryListsN[i];
105       AliInfo(Form("Neutral entry list for cut set '%s' has %d entries", set->GetName(), (Int_t)list->GetN()));
106    }
107    
108    // charged
109    nSets = fCutSetsC.GetEntries();
110    for (i = 0; i < nSets; i++) {
111       set = (AliRsnCutSet*)fCutSetsC[i];
112       list = (TEntryList*)fEntryListsP[i];
113       AliInfo(Form("Positive entry list for cut set '%s' has %d entries", set->GetName(), (Int_t)list->GetN()));
114       list = (TEntryList*)fEntryListsM[i];
115       AliInfo(Form("Negative entry list for cut set '%s' has %d entries", set->GetName(), (Int_t)list->GetN()));
116    }
117 }
118
119 //__________________________________________________________________________________________________
120 void AliRsnDaughterSelector::Init()
121 {
122 //
123 // Initialize the arrays of entry lists to the same size
124 // of the corresponding arrays of cut sets.
125 // If they are not empty, they are cleared.
126 //
127    
128    Int_t i, nSets;
129    
130    // neutral
131    nSets = fCutSetsN.GetEntries();
132    if (!fEntryListsN.IsEmpty()) fEntryListsN.Delete();
133    for (i = 0; i < nSets; i++) {
134       AliRsnCutSet *set = (AliRsnCutSet*)fCutSetsN[i];
135       new (fEntryListsN[i]) TEntryList;
136       AliInfo(Form("Adding 1 entry list for neutrals --> cut set '%s' [scheme = '%s']", set->GetName(), set->GetCutScheme().Data()));
137    }
138    
139    // charged
140    nSets = fCutSetsC.GetEntries();
141    if (!fEntryListsP.IsEmpty()) fEntryListsP.Delete();
142    if (!fEntryListsM.IsEmpty()) fEntryListsM.Delete();
143    for (i = 0; i < nSets; i++) {
144       AliRsnCutSet *set = (AliRsnCutSet*)fCutSetsC[i];
145       new (fEntryListsP[i]) TEntryList;
146       new (fEntryListsM[i]) TEntryList;
147       AliInfo(Form("Adding 2 entry lists for charged --> cut set '%s' [scheme = '%s']", set->GetName(), set->GetCutScheme().Data()));
148    }
149 }
150
151 //__________________________________________________________________________________________________
152 void AliRsnDaughterSelector::Reset()
153 {
154    TEntryList *el;
155    Int_t i, nSets;
156    
157    // N
158    nSets = fCutSetsN.GetEntries();
159    for (i = 0; i < nSets; i++) {
160       el = (TEntryList*)fEntryListsN.At(i);
161       el->Reset();
162    }
163    
164    // charged
165    nSets = fCutSetsC.GetEntries();
166    for (i = 0; i < nSets; i++) {
167       el = (TEntryList*)fEntryListsP.At(i);
168       el->Reset();
169       el = (TEntryList*)fEntryListsM.At(i);
170       el->Reset();
171    }
172 }
173
174 //__________________________________________________________________________________________________
175 Int_t AliRsnDaughterSelector::Add(AliRsnCutSet *cuts, Bool_t charged)
176 {
177 //
178 // Add a new selection slot defined by a set of cuts and daughter definition
179 //
180
181    Int_t n = 0;
182    
183    if (!charged) {
184       n = fCutSetsN.GetEntries();
185       new (fCutSetsN[n]) AliRsnCutSet(*cuts);
186    } else {
187       n = fCutSetsC.GetEntries();
188       new (fCutSetsC[n]) AliRsnCutSet(*cuts);
189    }
190    
191    return n;
192 }
193
194 //__________________________________________________________________________________________________
195 Int_t AliRsnDaughterSelector::GetID(const char *name, Bool_t charged)
196 {
197 //
198 // Add a new selection slot defined by a set of cuts and daughter definition
199 //
200
201    AliRsnCutSet *cuts;
202    
203    if (!charged) {
204       cuts = (AliRsnCutSet*)fCutSetsN.FindObject(name);
205       if (cuts) return fCutSetsN.IndexOf(cuts);
206    } else {
207       cuts = (AliRsnCutSet*)fCutSetsC.FindObject(name);
208       if (cuts) return fCutSetsC.IndexOf(cuts);
209    }
210    
211    return -1;
212 }
213
214 //__________________________________________________________________________________________________
215 TEntryList* AliRsnDaughterSelector::GetSelected(Int_t i, Char_t charge)
216 {
217 //
218 // Retrieve a given entry list (needs charge specified as a char)
219 //
220
221    if (charge == '+')
222       return (TEntryList*)fEntryListsP.At(i);
223    else if (charge == '-')
224       return (TEntryList*)fEntryListsM.At(i);
225    else
226       return (TEntryList*)fEntryListsN.At(i);
227 }
228
229 //__________________________________________________________________________________________________
230 TEntryList* AliRsnDaughterSelector::GetSelected(Int_t i, Short_t charge)
231 {
232 //
233 // Retrieve a given entry list passing charge as short
234 //
235
236    if (charge > 0)
237       return (TEntryList*)fEntryListsP.At(i);
238    else if (charge < 0)
239       return (TEntryList*)fEntryListsM.At(i);
240    else
241       return (TEntryList*)fEntryListsN.At(i);
242 }
243
244 //__________________________________________________________________________________________________
245 void AliRsnDaughterSelector::ScanEvent(AliRsnEvent* ev)
246 {
247 //
248 // Loop over event and fill all entry lists
249 //
250
251    Int_t id, is;
252    Int_t nSel, nTot = ev->GetAbsoluteSum();
253    AliRsnDaughter check;
254    TClonesArray *cutsArray = 0x0, *entryArray = 0x0;
255    
256    for (id = 0; id < nTot; id++) {
257       ev->SetDaughter(check, id);
258       // some checks
259       if (!check.GetRef()) {
260          AliDebugClass(1, Form("[%s]: daughter has NULL ref", GetName()));
261          continue;
262       }
263       if (!check.IsOK()) {
264          AliDebugClass(1, Form("[%s]: daughter is BAD", GetName()));
265          continue;
266       }
267       // set pointers according to charge
268       if (check.ChargeS() > 0) {
269          cutsArray = &fCutSetsC;
270          entryArray = &fEntryListsP;
271       } else if (check.ChargeS() < 0) {
272          cutsArray = &fCutSetsC;
273          entryArray = &fEntryListsM;
274       } else {
275          cutsArray = &fCutSetsN;
276          entryArray = &fEntryListsN;
277       }
278       // check with all cuts in that charge
279       nSel = cutsArray->GetEntries();
280       for (is = 0; is < nSel; is++) {
281          AliRsnCutSet *cuts = (AliRsnCutSet*)cutsArray->At(is);
282          if (cuts->IsSelected(&check)) {
283             TEntryList *el = (TEntryList*)entryArray->At(is);
284             el->Enter(id);
285          }
286       }
287    }
288    
289    //Print();
290 }
291
292 //__________________________________________________________________________________________________
293 AliRsnMiniEvent AliRsnDaughterSelector::CreateMiniEvent(AliRsnEvent* ev)
294 {
295 //
296 // Loop over event and fill all entry lists
297 //
298
299    AliRsnMiniEvent newEv;
300    AliRsnMiniParticle newPart;
301
302    Int_t id, is;
303    Int_t nSel, nTot = ev->GetAbsoluteSum();
304    AliRsnDaughter check;
305    TClonesArray *cutsArray = 0x0, *entryArray = 0x0;
306    
307    for (id = 0; id < nTot; id++) {
308       ev->SetDaughter(check, id);
309       // some checks
310       if (!check.GetRef()) {
311          AliDebugClass(1, Form("[%s]: daughter has NULL ref", GetName()));
312          continue;
313       }
314       if (!check.IsOK()) {
315          AliDebugClass(1, Form("[%s]: daughter is BAD", GetName()));
316          continue;
317       }
318       // copy informations
319       if (check.GetRefMC()) {
320          newPart.PsimX() = check.GetRefMC()->Px();
321          newPart.PsimY() = check.GetRefMC()->Py();
322          newPart.PsimZ() = check.GetRefMC()->Pz();
323       }
324       newPart.PrecX() = check.GetRef()->Px();
325       newPart.PrecY() = check.GetRef()->Py();
326       newPart.PrecZ() = check.GetRef()->Pz();
327       newPart.Charge() = check.GetRef()->Charge();
328       newPart.Mother() = check.GetMother();
329       newPart.MotherPDG() = check.GetMotherPDG();
330       newPart.CutBits() = 0x0;
331       // check with all cuts in that charge
332       nSel = cutsArray->GetEntries();
333       for (is = 0; is < nSel; is++) {
334          AliRsnCutSet *cuts = (AliRsnCutSet*)cutsArray->At(is);
335          if (cuts->IsSelected(&check)) newPart.SetCutBit(is);
336       }
337       // add only if it satisfied a cut bit
338       if (newPart.CutBits() != 0) newEv.AddParticle(newPart);
339    }
340    
341    return newEv;
342    //Print();
343 }