]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWG2/RESONANCES/AliRsnAnalysisManager.cxx
Update TPCCEda to write output file in parts (to avoid too big files produced in...
[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   {
85     AliWarning(Form("AliRsnPairManager is %p. Skipping ...", pair));
86     return;
87   }
88
89   AliDebug(AliLog::kDebug+1, Form("Adding %s [%d]...", pair->GetName(), fPairs.GetEntries()));
90   fPairs.Add(pair);
91
92   AliDebug(AliLog::kDebug+2,"->");
93 }
94
95 //_____________________________________________________________________________
96 void AliRsnAnalysisManager::Print(Option_t* /*dummy*/) const
97 {
98 //
99 // Overload of the TObject::Print() method
100 //
101
102   AliInfo(Form("\t======== Analysis Manager %s ========", GetName()));
103   PrintArray();
104 }
105
106 //_____________________________________________________________________________
107 void AliRsnAnalysisManager::PrintArray() const
108 {
109 //
110 // Calls the "Print" method of all included pair managers
111 //
112
113   AliDebug(AliLog::kDebug+2,"<-");
114
115   AliRsnPair *pair = 0;
116   TObjArrayIter next(&fPairs);
117   while ((pair = (AliRsnPair*)next())) pair->Print();
118
119   AliDebug(AliLog::kDebug+2,"->");
120 }
121
122 //_____________________________________________________________________________
123 void AliRsnAnalysisManager::InitAllPairs(TList *list)
124 {
125 //
126 // Initialize all pair managers, and put all the TList of histograms
127 // generated by each one into a unique final output TList
128 //
129
130   AliDebug(AliLog::kDebug+2,"<-");
131
132 //   TList *list = new TList();
133 //   list->SetName(GetName());
134 //   list->SetOwner();
135
136   AliRsnPair   *pair = 0;
137   TObjArrayIter next(&fPairs);
138   Int_t i = 0;
139   while ((pair = (AliRsnPair*)next())) 
140   {
141     if (!pair) continue;
142     AliDebug(AliLog::kDebug+1, Form("InitAllPairs of the PairManager(%s) [%d] ...", pair->GetName(), i++));
143     pair->Init("", list);
144     
145     // add a counter for used/unused events for each pair
146     TH1I *hPairUsed = new TH1I(Form("_%s_USED", pair->GetName()), "Used events for pair", 2, 0, 2);
147     list->Add(hPairUsed);
148   }
149   AliDebug(AliLog::kDebug+2, "->");
150 //   return list;
151
152   fList = list;
153 }
154
155 //_____________________________________________________________________________
156 void AliRsnAnalysisManager::ProcessAllPairs(AliRsnEvent *ev0, AliRsnEvent *ev1)
157 {
158 //
159 // Process one or two events for all pair managers.
160 //
161
162   AliDebug(AliLog::kDebug+2,"<-");
163   
164   if (!ev1) ev1 = ev0;
165   
166   Int_t nTot[2];
167   nTot[0] = ev0->GetAbsoluteSum();
168   nTot[1] = ev1->GetAbsoluteSum();
169   
170   // external loop
171   // joins the loop on tracks and v0s, by looping the indexes from 0
172   // to the sum of them, and checking what to take depending of its value
173   // in this step, the global cuts are checked
174   Int_t          i0, i1, i, realIndex;
175   AliRsnDaughter daughter0, daughter1;
176   AliRsnPair    *pair = 0x0;
177   TObjArrayIter  next(&fPairs);
178   AliRsnDaughter::ERefType type;
179   
180   // reset all counters
181   while ((pair = (AliRsnPair*)next())) 
182   {
183     pair->ResetCount();
184   }
185   
186   for (i0 = 0; i0 < nTot[0]; i0++)
187   {
188     // assign first track
189     if (!ev0->ConvertAbsoluteIndex(i0, realIndex, type)) continue;
190     ev0->SetDaughter(daughter0, realIndex, type);
191     
192     // check global cuts
193     if (!fGlobalTrackCuts.IsSelected(&daughter0)) continue;
194         
195     // internal loop (same criterion)
196     for (i1 = 0; i1 < nTot[1]; i1++)
197     {
198       // if looking same event, skip the case when the two indexes are equal
199       if (ev0 == ev1 && i0 == i1) continue;
200       
201       // assign second track
202       if (!ev1->ConvertAbsoluteIndex(i1, realIndex, type)) continue;
203       ev1->SetDaughter(daughter1, realIndex, type);
204       
205       // check global cuts
206       if (!fGlobalTrackCuts.IsSelected(&daughter1)) continue;
207       
208       // loop over all pairs and make computations
209       next.Reset();
210       i = 0;
211       while ((pair = (AliRsnPair*)next())) 
212       {
213         AliDebug(AliLog::kDebug+1, Form("ProcessAllPairs of the AnalysisManager(%s) [%d] ...", pair->GetName(), i++));
214         
215         // if the pair is a like-sign, skip the case when i1 < i0,
216         // in order not to double count each like-sign pair
217         // (equivalent to looping from i0+1 to ntracks)
218         if (pair->GetPairDef()->IsLikeSign() && i1 < i0) continue;
219                 
220         // process the two tracks
221         if (!pair->Fill(&daughter0, &daughter1, ev0, ev1)) continue;
222         pair->Compute();
223       }
224     }
225   }
226   
227   // update all count histograms counters
228   next.Reset();
229   if (!fList) return;
230   while ((pair = (AliRsnPair*)next())) 
231   {
232     TH1I *hist = (TH1I*)fList->FindObject(Form("_%s_USED", pair->GetName()));
233     if (!hist) continue;
234     if (pair->GetCount() > 0) hist->Fill(1); else hist->Fill(0);
235   }
236
237   AliDebug(AliLog::kDebug+2,"->");
238 }
239
240 //_____________________________________________________________________________
241 void AliRsnAnalysisManager::ProcessAllPairsMC(AliRsnEvent *ev0, AliRsnEvent *ev1)
242 {
243 //
244 // Process one or two events for all pair managers.
245 //
246
247   AliDebug(AliLog::kDebug+2,"<-");
248   
249   if (!ev1) ev1 = ev0;
250   
251   Int_t nTracks[2];
252   nTracks[0] = ev0->GetRefMC()->GetNumberOfTracks();
253   nTracks[1] = ev1->GetRefMC()->GetNumberOfTracks();
254   
255   // external loop
256   // joins the loop on tracks and v0s, by looping the indexes from 0
257   // to the sum of them, and checking what to take depending of its value
258   Int_t          i0, i1, i;
259   Bool_t         filled;
260   AliRsnDaughter daughter0, daughter1;
261   AliRsnPair    *pair = 0x0;
262   TObjArrayIter  next(&fPairs);
263   
264   // reset all counters
265   while ((pair = (AliRsnPair*)next())) 
266   {
267     pair->ResetCount();
268   }
269   
270   for (i0 = 0; i0 < nTracks[0]; i0++)
271   {
272     // skip not physical primaries
273     if (!ev0->GetRefMCESD()->Stack()->IsPhysicalPrimary(i0)) continue;
274     
275     // assign first track
276     ev0->SetDaughterMC(daughter0, i0);
277         
278     // internal loop (same criterion)
279     for (i1 = 0; i1 < nTracks[1]; i1++)
280     {
281       // if looking same event, skip the case when the two indexes are equal
282       if (ev0 == ev1 && i0 == i1) continue;
283       
284       // skip not physical primaries
285       if (!ev1->GetRefMCESD()->Stack()->IsPhysicalPrimary(i1)) continue;
286       
287       // assign second track
288       ev1->SetDaughterMC(daughter1, i1);
289       
290       // loop over all pairs and make computations
291       next.Reset();
292       i = 0;
293       while ((pair = (AliRsnPair*)next())) 
294       {
295         AliDebug(AliLog::kDebug+1, Form("ProcessAllPairs of the AnalysisManager(%s) [%d] ...", pair->GetName(), i++));
296         
297         // if the pair is a like-sign, skip the case when i1 < i0,
298         // in order not to double count each like-sign pair
299         // (equivalent to looping from i0+1 to ntracks)
300         if (pair->GetPairDef()->IsLikeSign() && i1 < i0) continue;
301                 
302         // process the two tracks
303         filled = pair->Fill(&daughter0, &daughter1, ev0, ev1);
304         if (!filled) continue;
305         pair->Compute();
306       }
307     }
308   }
309   
310   // update all count histograms counters
311   next.Reset();
312   if (!fList) return;
313   while ((pair = (AliRsnPair*)next())) 
314   {
315     TH1I *hist = (TH1I*)fList->FindObject(Form("_%s_USED", pair->GetName()));
316     if (!hist) continue;
317     if (pair->GetCount() > 0) hist->Fill(1); else hist->Fill(0);
318   }
319
320   AliDebug(AliLog::kDebug+2,"->");
321 }
322