]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWG2/RESONANCES/AliRsnAnalysisManager.cxx
Removed old ME classes, since the nex event mixing has been introduced and is integra...
[u/mrichter/AliRoot.git] / PWG2 / RESONANCES / AliRsnAnalysisManager.cxx
1 //
2 // Class AliRsnAnalysisManager
3 //
4 // This is the uppermost level of analysis objects collection.
5 // It contains a list of pair managers, which all will process
6 // a pool of events passed to this object, and fill their histograms.
7 //
8 // The utility of this object is to define a unique implementation
9 // of the whole processing, which can then be included in the different
10 // designs of AnalysisTask provided for SE and ME analysis.
11 //
12 // The base architecture is still AliRsnVManager, but in this case
13 // all the objects in the list will be AliRsnPairManager's.
14 //
15 // author     : M. Vala       [martin.vala@cern.ch]
16 // revised by : A. Pulvirenti [alberto.pulvirenti@ct.infn.it]
17 //
18
19 #include <TH1.h>
20 #include <TROOT.h>
21
22 #include "AliLog.h"
23 #include "AliStack.h"
24 #include "AliVEvent.h"
25 #include "AliMCEvent.h"
26 #include "AliRsnEvent.h"
27 #include "AliRsnPairFunctions.h"
28 #include "AliRsnPairNtuple.h"
29 #include "AliRsnAnalysisManager.h"
30
31
32 ClassImp(AliRsnAnalysisManager)
33
34 //_____________________________________________________________________________
35 AliRsnAnalysisManager::AliRsnAnalysisManager(const char*name) :
36    TNamed(name, ""),
37    fList(0x0),
38    fPairs(0),
39    fGlobalTrackCuts()
40 {
41 //
42 // Default constructor
43 //
44 }
45
46 //_____________________________________________________________________________
47 AliRsnAnalysisManager::AliRsnAnalysisManager(const AliRsnAnalysisManager& copy) :
48    TNamed(copy),
49    fList(copy.fList),
50    fPairs(copy.fPairs),
51    fGlobalTrackCuts(copy.fGlobalTrackCuts)
52 {
53 //
54 // Copy constructor
55 //
56 }
57
58 //_____________________________________________________________________________
59 AliRsnAnalysisManager& AliRsnAnalysisManager::operator=(const AliRsnAnalysisManager& copy)
60 {
61 //
62 // Assignment operator
63 //
64
65    TNamed::operator=(copy);
66
67    fList = copy.fList;
68    fPairs = copy.fPairs;
69    fGlobalTrackCuts = copy.fGlobalTrackCuts;
70
71    return (*this);
72 }
73
74 //_____________________________________________________________________________
75 void AliRsnAnalysisManager::Add(AliRsnPair *pair)
76 {
77 //
78 // Adds a new pair manager to the list.
79 //
80
81    AliDebug(AliLog::kDebug + 2, "<-");
82
83    if (!pair) {
84       AliWarning(Form("AliRsnPairManager is %p. Skipping ...", pair));
85       return;
86    }
87
88    AliDebug(AliLog::kDebug + 1, Form("Adding %s [%d]...", pair->GetName(), fPairs.GetEntries()));
89    fPairs.Add(pair);
90
91    AliDebug(AliLog::kDebug + 2, "->");
92 }
93
94 //_____________________________________________________________________________
95 void AliRsnAnalysisManager::Print(Option_t* /*dummy*/) const
96 {
97 //
98 // Overload of the TObject::Print() method
99 //
100
101    AliInfo(Form("\t======== Analysis Manager %s ========", GetName()));
102    PrintArray();
103 }
104
105 //_____________________________________________________________________________
106 void AliRsnAnalysisManager::PrintArray() const
107 {
108 //
109 // Calls the "Print" method of all included pair managers
110 //
111
112    AliDebug(AliLog::kDebug + 2, "<-");
113
114    AliRsnPair *pair = 0;
115    TObjArrayIter next(&fPairs);
116    while ((pair = (AliRsnPair*)next())) pair->Print();
117
118    AliDebug(AliLog::kDebug + 2, "->");
119 }
120
121 //_____________________________________________________________________________
122 void AliRsnAnalysisManager::InitAllPairs(TList *list)
123 {
124 //
125 // Initialize all pair managers, and put all the TList of histograms
126 // generated by each one into a unique final output TList
127 //
128
129    AliDebug(AliLog::kDebug + 2, "<-");
130
131    AliRsnPair   *pair = 0;
132    TObjArrayIter next(&fPairs);
133    Int_t i = 0;
134    while ((pair = (AliRsnPair*)next())) {
135       AliDebug(AliLog::kDebug + 1, Form("InitAllPairs of the PairManager(%s) [%d] ...", pair->GetName(), i++));
136 //     pair->Init("", list);
137       pair->Init(GetName(), list);
138
139       // add a counter for used/unused events for each pair
140       TH1I *hPairUsed = new TH1I(Form("%s_%s_USED", GetName(), pair->GetName()), "Used events for pair", 2, 0, 2);
141       list->Add(hPairUsed);
142    }
143
144    fList = list;
145
146    AliDebug(AliLog::kDebug + 2, "->");
147 }
148
149 //_____________________________________________________________________________
150 void AliRsnAnalysisManager::ProcessAllPairs()
151 {
152 //
153 // Process one or two events for all pair managers.
154 //
155
156    static Int_t evnum = 0;
157    evnum++;
158
159    AliDebug(AliLog::kDebug + 2, "<-");
160
161    // skip if the global event pointers are NULL
162    if (!AliRsnEvent::IsCurrentEvent1()) return;
163    if (!AliRsnEvent::IsCurrentEvent2()) return;
164
165    // for better readability, reference two pointers to the current events
166    AliRsnEvent *ev0 = AliRsnEvent::GetCurrentEvent1();
167    AliRsnEvent *ev1 = AliRsnEvent::GetCurrentEvent2();
168
169    // count total number of candidates per event
170    // (sum of tracks, V0s and cascades)
171    Int_t nTot[2];
172    nTot[0] = AliRsnEvent::GetCurrentEvent1()->GetAbsoluteSum();
173    nTot[1] = AliRsnEvent::GetCurrentEvent2()->GetAbsoluteSum();
174
175    // variables
176    Int_t          i0, i1, i, start, index0, index1;
177    AliRsnDaughter daughter0, daughter1;
178    AliRsnPair    *pair = 0x0;
179    TObjArrayIter  next(&fPairs);
180    AliRsnDaughter::ERefType type0, type1;
181
182    // reset all counters which tell us
183    // how many entries were added now
184    while ((pair = (AliRsnPair*)next())) {
185       pair->ResetCount();
186    }
187
188    // external loop
189    for (i0 = 0; i0 < nTot[0]; i0++) {
190       // assign first track
191       if (!ev0->ConvertAbsoluteIndex(i0, index0, type0)) continue;
192       ev0->SetDaughter(daughter0, index0, type0);
193
194       // check global cuts
195       if (!fGlobalTrackCuts.IsSelected(&daughter0)) continue;
196
197       // define start depending if we are processing one or two events
198       start = (AliRsnEvent::SameEvent() ? i0 + 1 : 0);
199
200       // internal loop (same criterion)
201       for (i1 = start; i1 < nTot[1]; i1++) {
202          // if looking same event, skip the case when the two indexes are equal
203          // if (AliRsnEvent::SameEvent() && i0 == i1) continue;
204
205          // assign second track
206          if (!ev1->ConvertAbsoluteIndex(i1, index1, type1)) continue;
207          ev1->SetDaughter(daughter1, index1, type1);
208
209          // check global cuts
210          if (!fGlobalTrackCuts.IsSelected(&daughter1)) continue;
211
212          // loop over all pairs and make computations
213          next.Reset();
214          i = 0;
215          while ((pair = (AliRsnPair*)next())) {
216             AliDebug(AliLog::kDebug + 1, Form("ProcessAllPairs of the AnalysisManager(%s) [%d] ...", pair->GetName(), i++));
217
218             // if the pair is a like-sign, skip the case when i1 < i0,
219             // in order not to double count each like-sign pair
220             // (equivalent to looping from i0+1 to ntracks)
221             // if (AliRsnEvent::SameEvent() && pair->GetPairDef()->IsLikeSign() && i1 < i0) continue;
222
223             // process the two tracks
224             if (pair->Fill(&daughter0, &daughter1)) {
225                pair->Compute();
226             } else if (pair->Fill(&daughter1, &daughter0)) {
227                pair->Compute();
228             }
229          }
230       }
231    }
232
233    // update all count histograms counters
234    next.Reset();
235    if (!fList) return;
236    while ((pair = (AliRsnPair*)next())) {
237       TH1I *hist = (TH1I*)fList->FindObject(Form("_%s_USED", pair->GetName()));
238       if (!hist) continue;
239       if (pair->GetCount() > 0) hist->Fill(1); else hist->Fill(0);
240    }
241
242    AliDebug(AliLog::kDebug + 2, "->");
243 }
244
245 //_____________________________________________________________________________
246 void AliRsnAnalysisManager::ProcessAllPairsMC()
247 {
248 //
249 // Process one or two events for all pair managers.
250 //
251
252    AliDebug(AliLog::kDebug + 2, "<-");
253
254    // skip if the global event pointers are NULL
255    if (!AliRsnEvent::IsCurrentEvent1()) return;
256    if (!AliRsnEvent::IsCurrentEvent2()) return;
257
258    // for better readability, reference two pointers to the current events
259    AliRsnEvent *ev0 = AliRsnEvent::GetCurrentEvent1();
260    AliRsnEvent *ev1 = AliRsnEvent::GetCurrentEvent2();
261
262    // this time the number of tracks comes from MC
263    Int_t nTracks[2];
264    nTracks[0] = ev0->GetRefMC()->GetNumberOfTracks();
265    nTracks[1] = ev1->GetRefMC()->GetNumberOfTracks();
266
267    // external loop
268    // joins the loop on tracks and v0s, by looping the indexes from 0
269    // to the sum of them, and checking what to take depending of its value
270    Int_t          i0, i1, start, i;
271    Bool_t         filled;
272    AliRsnDaughter daughter0, daughter1;
273    AliRsnPair    *pair = 0x0;
274    TObjArrayIter  next(&fPairs);
275
276    // reset all counters
277    while ((pair = (AliRsnPair*)next())) {
278       pair->ResetCount();
279    }
280
281    for (i0 = 0; i0 < nTracks[0]; i0++) {
282       // skip not physical primaries
283       if (!ev0->GetRefMCESD()->Stack()->IsPhysicalPrimary(i0)) continue;
284
285       // assign first track
286       ev0->SetDaughterMC(daughter0, i0);
287
288       // define start depending if we are processing one or two events
289       start = (AliRsnEvent::SameEvent() ? i0 + 1 : 0);
290
291       // internal loop (same criterion)
292       for (i1 = start; i1 < nTracks[1]; i1++) {
293          // if looking same event, skip the case when the two indexes are equal
294          if (AliRsnEvent::SameEvent() && i0 == i1) continue;
295
296          // skip not physical primaries
297          if (!ev1->GetRefMCESD()->Stack()->IsPhysicalPrimary(i1)) continue;
298
299          // assign second track
300          ev1->SetDaughterMC(daughter1, i1);
301
302          // loop over all pairs and make computations
303          next.Reset();
304          i = 0;
305          while ((pair = (AliRsnPair*)next())) {
306             AliDebug(AliLog::kDebug + 1, Form("ProcessAllPairs of the AnalysisManager(%s) [%d] ...", pair->GetName(), i++));
307
308             // if the pair is a like-sign, skip the case when i1 < i0,
309             // in order not to double count each like-sign pair
310             // (equivalent to looping from i0+1 to ntracks)
311             if (pair->GetPairDef()->IsLikeSign() && i1 < i0) continue;
312
313             // process the two tracks
314             filled = pair->Fill(&daughter0, &daughter1);
315             if (!filled) continue;
316             pair->Compute();
317          }
318       }
319    }
320
321    // update all count histograms counters
322    next.Reset();
323    if (!fList) return;
324    while ((pair = (AliRsnPair*)next())) {
325       TH1I *hist = (TH1I*)fList->FindObject(Form("_%s_USED", pair->GetName()));
326       if (!hist) continue;
327       if (pair->GetCount() > 0) hist->Fill(1); else hist->Fill(0);
328    }
329
330    AliDebug(AliLog::kDebug + 2, "->");
331 }
332