]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWG2/RESONANCES/AliRsnAnalysisManager.cxx
Coding rule violations corrected.
[u/mrichter/AliRoot.git] / PWG2 / RESONANCES / AliRsnAnalysisManager.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3  *                                                                        *
4  * Author: The ALICE Off-line Project.                                    *
5  * Contributors are mentioned in the code where appropriate.              *
6  *                                                                        *
7  * Permission to use, copy, modify and distribute this software and its   *
8  * documentation strictly for non-commercial purposes is hereby granted   *
9  * without fee, provided that the above copyright notice appears in all   *
10  * copies and that both the copyright notice and this permission notice   *
11  * appear in the supporting documentation. The authors make no claims     *
12  * about the suitability of this software for any purpose. It is          *
13  * provided "as is" without express or implied warranty.                  *
14  **************************************************************************/
15
16 ////////////////////////////////////////////////////////////////////////////////
17 //
18 //  This is the uppermost level in the analysis task and is built as a 
19 //  separate object since up to this level the execution of the analysis 
20 //  is not directly related to the real analysis task structure.
21 //  An analysis task for resonances will just configure and initialize an
22 //  instance of this class, which will do all the work, and will share with it
23 //  the TList containing all the outputs.
24 //
25 //  This object collects all AliRsnPair and AliRsnMonitor objects which do
26 //  the computations and fill histograms, each properly initialized with 
27 //  outputs (histos, ntuples) and cuts on whatever is needed.
28 //  
29 //  authors: A. Pulvirenti (alberto.pulvirenti@ct.infn.it)
30 //           M. Vala (martin.vala@cern.ch)
31 //
32 ////////////////////////////////////////////////////////////////////////////////
33
34 #include <TH1.h>
35 #include <TROOT.h>
36
37 #include "AliLog.h"
38 #include "AliStack.h"
39 #include "AliVEvent.h"
40 #include "AliMCEvent.h"
41 #include "AliRsnEvent.h"
42 #include "AliRsnPairFunctions.h"
43 #include "AliRsnPairNtuple.h"
44 #include "AliRsnMonitorFunctions.h"
45 #include "AliRsnMonitorNtuple.h"
46
47 #include "AliRsnAnalysisManager.h"
48
49
50 ClassImp(AliRsnAnalysisManager)
51
52 //_____________________________________________________________________________
53 AliRsnAnalysisManager::AliRsnAnalysisManager(const char *name) :
54    TNamed(name, ""),
55    fAddUsageHist(kFALSE),
56    fList(0x0),
57    fPairs(0),
58    fMonitors(0),
59    fGlobalTrackCuts()
60 {
61 //
62 // Default constructor
63 //
64 }
65
66 //_____________________________________________________________________________
67 AliRsnAnalysisManager::AliRsnAnalysisManager(const AliRsnAnalysisManager& copy) :
68    TNamed(copy),
69    fAddUsageHist(copy.fAddUsageHist),
70    fList(copy.fList),
71    fPairs(copy.fPairs),
72    fMonitors(copy.fMonitors),
73    fGlobalTrackCuts(copy.fGlobalTrackCuts)
74 {
75 //
76 // Copy constructor
77 //
78 }
79
80 //_____________________________________________________________________________
81 AliRsnAnalysisManager& AliRsnAnalysisManager::operator=(const AliRsnAnalysisManager& copy)
82 {
83 //
84 // Assignment operator
85 //
86
87    TNamed::operator=(copy);
88
89    fAddUsageHist = copy.fAddUsageHist;
90    fList = copy.fList;
91    fPairs = copy.fPairs;
92    fMonitors = copy.fMonitors;
93    fGlobalTrackCuts = copy.fGlobalTrackCuts;
94
95    return (*this);
96 }
97
98 //_____________________________________________________________________________
99 void AliRsnAnalysisManager::Add(AliRsnPair *pair)
100 {
101 //
102 // Adds a new pair to the list.
103 //
104
105    AliDebug(AliLog::kDebug + 2, "<-");
106
107    if (!pair) {
108       AliWarning(Form("AliRsnPairManager is %p. Skipping ...", pair));
109       return;
110    }
111
112    AliDebug(AliLog::kDebug + 1, Form("Adding %s [%d]...", pair->GetName(), fPairs.GetEntries()));
113    fPairs.Add(pair);
114
115    AliDebug(AliLog::kDebug + 2, "->");
116 }
117
118 //_____________________________________________________________________________
119 void AliRsnAnalysisManager::Add(AliRsnMonitor *monitor)
120 {
121 //
122 // Adds a new monitor to the list.
123 //
124
125    AliDebug(AliLog::kDebug + 2, "<-");
126
127    if (!monitor) {
128       AliWarning(Form("AliRsnPairManager is %p. Skipping ...", monitor));
129       return;
130    }
131
132    AliDebug(AliLog::kDebug + 1, Form("Adding %s [%d]...", monitor->GetName(), fMonitors.GetEntries()));
133    fMonitors.Add(monitor);
134
135    AliDebug(AliLog::kDebug + 2, "->");
136 }
137
138 //_____________________________________________________________________________
139 void AliRsnAnalysisManager::Print(Option_t* /*dummy*/) const
140 {
141 //
142 // Overload of the TObject::Print() method
143 //
144
145    AliInfo(Form("\t======== Analysis Manager %s ========", GetName()));
146    PrintArray();
147 }
148
149 //_____________________________________________________________________________
150 void AliRsnAnalysisManager::PrintArray() const
151 {
152 //
153 // Calls the "Print" method of all included pair managers
154 //
155
156    AliDebug(AliLog::kDebug + 2, "<-");
157
158    AliRsnPair *pair = 0;
159    TObjArrayIter nextPair(&fPairs);
160    while ((pair = (AliRsnPair*)nextPair())) pair->Print();
161    
162    AliRsnMonitor *monitor = 0;
163    TObjArrayIter nextMonitor(&fMonitors);
164    while ((monitor = (AliRsnMonitor*)nextMonitor())) monitor->Print();
165
166    AliDebug(AliLog::kDebug + 2, "->");
167 }
168
169 //_____________________________________________________________________________
170 void AliRsnAnalysisManager::InitAllPairs(TList *list)
171 {
172 //
173 // Initialize all pair managers, and put all the TList of histograms
174 // generated by each one into a unique final output TList
175 //
176
177    Int_t i = 0;
178
179    // pairs
180    AliRsnPair   *pair = 0;
181    TObjArrayIter nextPair(&fPairs);
182    while ((pair = (AliRsnPair*)nextPair())) {
183       AliDebug(AliLog::kDebug + 1, Form("InitAllPairs of the PairManager(%s) [%d] ...", pair->GetName(), i++));
184       pair->Init(GetName(), list);
185
186       // add a counter for used/unused events for each pair
187       if (fAddUsageHist) {
188          TH1I *hPairUsed = new TH1I(Form("%s_%s_USED", GetName(), pair->GetName()), "Used events for pair", 2, 0, 2);
189          list->Add(hPairUsed);
190       }
191    }
192    
193    // monitors
194    i = 0;
195    AliRsnMonitor *monitor = 0;
196    TObjArrayIter  nextMonitor(&fMonitors);
197    while ((monitor = (AliRsnMonitor*)nextMonitor())) {
198       AliDebug(AliLog::kDebug + 1, Form("InitAllPairs of the PairManager(%s) [%d] ...", monitor->GetName(), i++));
199       monitor->Init(GetName(), list);
200    }
201
202    // set list pointer
203    fList = list;
204    fList->Print();
205 }
206
207 //_____________________________________________________________________________
208 void AliRsnAnalysisManager::ProcessAll(Bool_t pureMC)
209 {
210 //
211 // Loop on all pairs/monitors stored here 
212 // and process all candidate daughters.
213 //
214
215    AliDebug(AliLog::kDebug + 2, "<-");
216    
217    // don't do anything if the output list isn't initialized
218    if (!fList) return;
219
220    // skip if the global event pointers are NULL
221    if (!AliRsnEvent::IsCurrentEvent1()) return;
222    if (!AliRsnEvent::IsCurrentEvent2()) return;
223
224    // for better readability, reference two pointers to the current events
225    AliRsnEvent *ev0 = AliRsnEvent::GetCurrentEvent1();
226    AliRsnEvent *ev1 = AliRsnEvent::GetCurrentEvent2();
227    
228    // if MC reference is absent, cannot process pure MC
229    if (pureMC && (!ev0->GetRefMC() || !ev1->GetRefMC())) {
230       AliError("Cannot process a pure MC analysis without MC references!");
231       return;
232    }
233
234    // count total number of candidates per event
235    // (sum of tracks, V0s and cascades)
236    Int_t nTot[2];
237    if (pureMC) {
238       nTot[0] = ev0->GetRefMC()->GetNumberOfTracks();
239       nTot[1] = ev1->GetRefMC()->GetNumberOfTracks();
240    } else {
241       nTot[0] = AliRsnEvent::GetCurrentEvent1()->GetAbsoluteSum();
242       nTot[1] = AliRsnEvent::GetCurrentEvent2()->GetAbsoluteSum();
243    }
244
245    // variables
246    Int_t                    i0, i1, i, start;
247    AliRsnDaughter           daughter0, daughter1;
248    AliRsnPair              *pair = 0x0;
249    AliRsnMonitor           *monitor = 0x0;
250    TObjArrayIter            nextPair(&fPairs);
251    TObjArrayIter            nextMonitor(&fMonitors);
252
253    // reset all counters which tell us
254    // how many entries were added now
255    while ((pair = (AliRsnPair*)nextPair())) {
256       pair->ResetCount();
257    }
258
259    // external loop
260    for (i0 = 0; i0 < nTot[0]; i0++) {
261       
262       // try to assign first track
263       // and check global cuts
264       // in case of ESD pure MC, skip not physical primaries
265       if (pureMC) {
266          if (ev0->IsESD()) if (!ev0->GetRefMCESD()->Stack()->IsPhysicalPrimary(i0)) continue;
267          if (!ev0->SetDaughterMC(daughter0, i0)) continue;
268       } else {
269          if (!ev0->SetDaughterAbs(daughter0, i0)) continue;
270       }
271       if (!fGlobalTrackCuts.IsSelected(&daughter0)) continue;
272       
273       // process all single-track monitors
274       nextMonitor.Reset();
275       while ((monitor = (AliRsnMonitor*)nextMonitor())) if (monitor->Fill(&daughter0)) monitor->Compute();
276
277       // define start of inner loop depending if we are processing one or two events
278       start = (AliRsnEvent::SameEvent() ? i0 + 1 : 0);
279
280       // internal loop (same criterion)
281       for (i1 = start; i1 < nTot[1]; i1++) {
282
283          // try to assign first track
284          // and check global cuts
285          // in case of ESD pure MC, skip not physical primaries
286          if (pureMC) {
287             if (ev1->IsESD()) if (!ev1->GetRefMCESD()->Stack()->IsPhysicalPrimary(i1)) continue;
288             if (!ev1->SetDaughterMC(daughter1, i1)) continue;
289          } else {
290             if (!ev1->SetDaughterAbs(daughter1, i1)) continue;
291          }
292          if (!fGlobalTrackCuts.IsSelected(&daughter1)) continue;
293
294          // loop over all pairs and make computations
295          i = 0;
296          nextPair.Reset();
297          while ((pair = (AliRsnPair*)nextPair())) {
298             
299             // debug message
300             AliDebug(AliLog::kDebug + 1, Form("ProcessAllPairs of the AnalysisManager(%s) [%d] ...", pair->GetName(), i++));
301
302             // process the two tracks
303             // the Fill() method returns kTRUE if the two daughters
304             // do match the pair definition of each AliRsnPait object,
305             // and the pair is processed only in this case
306             if (pair->Fill(&daughter0, &daughter1)) {
307                pair->Compute();
308             } else if (pair->Fill(&daughter1, &daughter0)) {
309                pair->Compute();
310             }
311          }
312       }
313    }
314
315    // update all count histograms counters
316    if (fAddUsageHist) {
317       nextPair.Reset();
318       while ((pair = (AliRsnPair*)nextPair())) {
319          TH1I *hist = (TH1I*)fList->FindObject(Form("%s_%s_USED", GetName(), pair->GetName()));
320          if (!hist) continue;
321          if (pair->GetCount() > 0) hist->Fill(1); else hist->Fill(0);
322       }
323    }
324
325    AliDebug(AliLog::kDebug + 2, "->");
326 }