]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWG2/RESONANCES/AliRsnAnalysisManager.cxx
Solved some of the issues raised by coverity server.
[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   AliRsnPair   *pair = 0;
133   TObjArrayIter next(&fPairs);
134   Int_t i = 0;
135   while ((pair = (AliRsnPair*)next())) 
136   {
137     AliDebug(AliLog::kDebug+1, Form("InitAllPairs of the PairManager(%s) [%d] ...", pair->GetName(), i++));
138     pair->Init("", list);
139     
140     // add a counter for used/unused events for each pair
141     TH1I *hPairUsed = new TH1I(Form("_%s_USED", pair->GetName()), "Used events for pair", 2, 0, 2);
142     list->Add(hPairUsed);
143   }
144   
145   fList = list;
146   
147   AliDebug(AliLog::kDebug+2, "->");
148 }
149
150 //_____________________________________________________________________________
151 void AliRsnAnalysisManager::ProcessAllPairs()
152 {
153 //
154 // Process one or two events for all pair managers.
155 //
156
157   static Int_t evnum = 0;
158   evnum++;
159
160   AliDebug(AliLog::kDebug+2,"<-");
161   
162   // skip if the global event pointers are NULL
163   if (!AliRsnEvent::IsCurrentEvent1()) return;
164   if (!AliRsnEvent::IsCurrentEvent2()) return;
165   
166   // for better readability, reference two pointers to the current events
167   AliRsnEvent *ev0 = AliRsnEvent::GetCurrentEvent1();
168   AliRsnEvent *ev1 = AliRsnEvent::GetCurrentEvent2();
169   
170   // count total number of candidates per event
171   // (sum of tracks, V0s and cascades)
172   Int_t nTot[2];
173   nTot[0] = AliRsnEvent::GetCurrentEvent1()->GetAbsoluteSum();
174   nTot[1] = AliRsnEvent::GetCurrentEvent2()->GetAbsoluteSum();
175   
176   // variables
177   Int_t          i0, i1, i, start, index0, index1;
178   AliRsnDaughter daughter0, daughter1;
179   AliRsnPair    *pair = 0x0;
180   TObjArrayIter  next(&fPairs);
181   AliRsnDaughter::ERefType type0, type1;
182   
183   // reset all counters which tell us
184   // how many entries were added now
185   while ((pair = (AliRsnPair*)next())) 
186   {
187     pair->ResetCount();
188   }
189   
190   // external loop
191   for (i0 = 0; i0 < nTot[0]; i0++)
192   {
193     // assign first track
194     if (!ev0->ConvertAbsoluteIndex(i0, index0, type0)) continue;
195     ev0->SetDaughter(daughter0, index0, type0);
196     
197     // check global cuts
198     if (!fGlobalTrackCuts.IsSelected(&daughter0)) continue;
199     
200     // define start depending if we are processing one or two events
201     start = (AliRsnEvent::SameEvent() ? i0 + 1 : 0);
202         
203     // internal loop (same criterion)
204     for (i1 = start; i1 < nTot[1]; i1++)
205     {
206       // if looking same event, skip the case when the two indexes are equal
207       // if (AliRsnEvent::SameEvent() && i0 == i1) continue;
208       
209       // assign second track
210       if (!ev1->ConvertAbsoluteIndex(i1, index1, type1)) continue;
211       ev1->SetDaughter(daughter1, index1, type1);
212       
213       // check global cuts
214       if (!fGlobalTrackCuts.IsSelected(&daughter1)) continue;
215       
216       // loop over all pairs and make computations
217       next.Reset();
218       i = 0;
219       while ((pair = (AliRsnPair*)next())) 
220       {
221         AliDebug(AliLog::kDebug+1, Form("ProcessAllPairs of the AnalysisManager(%s) [%d] ...", pair->GetName(), i++));
222         
223         // if the pair is a like-sign, skip the case when i1 < i0,
224         // in order not to double count each like-sign pair
225         // (equivalent to looping from i0+1 to ntracks)
226         // if (AliRsnEvent::SameEvent() && pair->GetPairDef()->IsLikeSign() && i1 < i0) continue;
227                 
228         // process the two tracks
229         if (pair->Fill(&daughter0, &daughter1))
230         {
231           pair->Compute();
232         }
233         else if (pair->Fill(&daughter1, &daughter0))
234         {
235           pair->Compute();
236         }
237       }
238     }
239   }
240   
241   // update all count histograms counters
242   next.Reset();
243   if (!fList) return;
244   while ((pair = (AliRsnPair*)next())) 
245   {
246     TH1I *hist = (TH1I*)fList->FindObject(Form("_%s_USED", pair->GetName()));
247     if (!hist) continue;
248     if (pair->GetCount() > 0) hist->Fill(1); else hist->Fill(0);
249   }
250
251   AliDebug(AliLog::kDebug+2,"->");
252 }
253
254 //_____________________________________________________________________________
255 void AliRsnAnalysisManager::ProcessAllPairsMC()
256 {
257 //
258 // Process one or two events for all pair managers.
259 //
260
261   AliDebug(AliLog::kDebug+2,"<-");
262   
263   // skip if the global event pointers are NULL
264   if (!AliRsnEvent::IsCurrentEvent1()) return;
265   if (!AliRsnEvent::IsCurrentEvent2()) return;
266   
267   // for better readability, reference two pointers to the current events
268   AliRsnEvent *ev0 = AliRsnEvent::GetCurrentEvent1();
269   AliRsnEvent *ev1 = AliRsnEvent::GetCurrentEvent2();
270   
271   // this time the number of tracks comes from MC
272   Int_t nTracks[2];
273   nTracks[0] = ev0->GetRefMC()->GetNumberOfTracks();
274   nTracks[1] = ev1->GetRefMC()->GetNumberOfTracks();
275   
276   // external loop
277   // joins the loop on tracks and v0s, by looping the indexes from 0
278   // to the sum of them, and checking what to take depending of its value
279   Int_t          i0, i1, start, i;
280   Bool_t         filled;
281   AliRsnDaughter daughter0, daughter1;
282   AliRsnPair    *pair = 0x0;
283   TObjArrayIter  next(&fPairs);
284   
285   // reset all counters
286   while ((pair = (AliRsnPair*)next())) 
287   {
288     pair->ResetCount();
289   }
290   
291   for (i0 = 0; i0 < nTracks[0]; i0++)
292   {
293     // skip not physical primaries
294     if (!ev0->GetRefMCESD()->Stack()->IsPhysicalPrimary(i0)) continue;
295     
296     // assign first track
297     ev0->SetDaughterMC(daughter0, i0);
298     
299     // define start depending if we are processing one or two events
300     start = (AliRsnEvent::SameEvent() ? i0 + 1 : 0);
301         
302     // internal loop (same criterion)
303     for (i1 = start; i1 < nTracks[1]; i1++)
304     {
305       // if looking same event, skip the case when the two indexes are equal
306       if (AliRsnEvent::SameEvent() && i0 == i1) continue;
307       
308       // skip not physical primaries
309       if (!ev1->GetRefMCESD()->Stack()->IsPhysicalPrimary(i1)) continue;
310       
311       // assign second track
312       ev1->SetDaughterMC(daughter1, i1);
313       
314       // loop over all pairs and make computations
315       next.Reset();
316       i = 0;
317       while ((pair = (AliRsnPair*)next())) 
318       {
319         AliDebug(AliLog::kDebug+1, Form("ProcessAllPairs of the AnalysisManager(%s) [%d] ...", pair->GetName(), i++));
320         
321         // if the pair is a like-sign, skip the case when i1 < i0,
322         // in order not to double count each like-sign pair
323         // (equivalent to looping from i0+1 to ntracks)
324         if (pair->GetPairDef()->IsLikeSign() && i1 < i0) continue;
325                 
326         // process the two tracks
327         filled = pair->Fill(&daughter0, &daughter1);
328         if (!filled) continue;
329         pair->Compute();
330       }
331     }
332   }
333   
334   // update all count histograms counters
335   next.Reset();
336   if (!fList) return;
337   while ((pair = (AliRsnPair*)next())) 
338   {
339     TH1I *hist = (TH1I*)fList->FindObject(Form("_%s_USED", pair->GetName()));
340     if (!hist) continue;
341     if (pair->GetCount() > 0) hist->Fill(1); else hist->Fill(0);
342   }
343
344   AliDebug(AliLog::kDebug+2,"->");
345 }
346