]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWG2/RESONANCES/AliRsnAnalysisME.cxx
Since there are some cuts which require to take informations from the event itself
[u/mrichter/AliRoot.git] / PWG2 / RESONANCES / AliRsnAnalysisME.cxx
1 //
2 // Class AliRsnAnalysisME
3 //
4 //
5 // Virtual Class derivated from AliRsnVAnalysisTaskME which will be base class
6 // for all RSN SE tasks
7 //
8 // authors: Alberto Pulvirenti (alberto.pulvirenti@ct.infn.it)
9 //          Martin Vala (martin.vala@cern.ch)
10 //
11
12 #include "AliESDEvent.h"
13 #include "AliMCEvent.h"
14 #include "AliAODEvent.h"
15 #include "AliMultiEventInputHandler.h"
16 #include "AliRsnAnalysisME.h"
17
18 ClassImp(AliRsnAnalysisME)
19
20 //_____________________________________________________________________________
21 AliRsnAnalysisME::AliRsnAnalysisME(const char *name, Int_t numOfOutputs) :
22     AliRsnVAnalysisTaskME(name, numOfOutputs),
23     fRsnAnalysisManager(),
24     fPIDIndex(0),
25     fPIDIndexMix(0),
26     fEvent(),
27     fEventMix()
28 {
29 //
30 // Default constructor
31 //
32   AliDebug(AliLog::kDebug+2, "<-");
33   Int_t i = 0;
34   for (i = 0;i < fNumberOfOutputs;i++) {
35     DefineOutput(i + 2, TList::Class());
36   }
37   AliDebug(AliLog::kDebug+2,"->");
38 }
39
40 AliRsnAnalysisME::AliRsnAnalysisME(const AliRsnAnalysisME& copy) : AliRsnVAnalysisTaskME(copy),
41     fRsnAnalysisManager(copy.fRsnAnalysisManager),
42     fPIDIndex(copy.fPIDIndex),
43     fPIDIndexMix(copy.fPIDIndexMix),
44     fEvent(copy.fEvent),
45     fEventMix(copy.fEvent)
46 {
47   AliDebug(AliLog::kDebug+2, "<-");
48   AliDebug(AliLog::kDebug+2,"->");
49 }
50
51 //_____________________________________________________________________________
52 void AliRsnAnalysisME::RsnUserCreateOutputObjects()
53 {
54 //
55 // Creation of output objects.
56 // These are created through the utility methods in the analysis manager,
57 // which produces a list of histograms for each specified set of pairs.
58 // Each of these lists is added to the main list of this task.
59 //
60
61   AliDebug(AliLog::kDebug+2, "<-");
62
63   Int_t i;
64   for (i = 1; i < kMaxNumberOfOutputs + 1; i++) {
65     if (i <= fNumberOfOutputs + 1) OpenFile(i/* + 1*/);
66     fOutList[i] = new TList();
67     fOutList[i]->SetOwner();
68   }
69
70   for (i = 0; i < fNumberOfOutputs; i++) {
71     fRsnAnalysisManager[i].InitAllPairMgrs(fOutList[i+1]);
72   }
73
74   AliDebug(AliLog::kDebug+2,"->");
75 }
76
77 void AliRsnAnalysisME::RsnUserExec(Option_t*)
78 {
79 //
80 // Rsn User Exec
81 //
82
83   fTaskInfo.SetEventUsed(kFALSE);
84
85   AliDebug(AliLog::kDebug+2, "<-");
86   if (!CheckAndPrintEvents()) return;
87
88   DoMixing(GetEvent(0));
89
90
91   // if cuts are passed or not cuts were defined,
92   // update the task info...
93   fTaskInfo.SetEventUsed(kTRUE);
94
95   // the virtual class has already sorted tracks in the PID index
96   // so we need here just to call the execution of analysis
97   for (Int_t i = 0; i < fNumberOfOutputs; i++) {
98 //     fRsnAnalysisManager[i].ProcessAllPairMgrs(&fRsnPIDIndex, &fRsnEvent);
99     PostData(i + 2, fOutList[i+1]);
100   }
101
102   AliDebug(AliLog::kDebug+2,"->");
103 }
104
105
106 //_____________________________________________________________________________
107 void AliRsnAnalysisME::DoMixing(AliVEvent* ev)
108 {
109 //
110 // Do Mixing
111 //
112
113   Int_t nEvents = fInputHandler->GetBufferSize();
114   fESDEvent = dynamic_cast<AliESDEvent*>(ev);
115   fAODEvent = dynamic_cast<AliAODEvent*>(ev);
116
117   if (fESDEvent) {
118     AliESDEvent **esdEvent = new AliESDEvent*[nEvents];
119     for (Int_t i = 0; i < nEvents; i++) {
120       esdEvent[i] = dynamic_cast<AliESDEvent*>(GetEvent(i));
121       if (!esdEvent[i]) {
122         AliWarning(Form("Null ESD event in index %d", i));
123         continue;
124       }
125       if (i > 0)
126         DoESDMixing(esdEvent[0], esdEvent[i]);
127     }
128   } else if (fAODEvent) {
129     AliAODEvent **aodEvent = new AliAODEvent*[nEvents];
130     for (Int_t i = 0; i < nEvents; i++) {
131       aodEvent[i] = dynamic_cast<AliAODEvent*>(GetEvent(i));
132       if (!aodEvent[i]) {
133         AliWarning(Form("Null AOD event in index %d", i));
134         continue;
135       }
136       if (i > 0)
137         DoAODMixing(aodEvent[0], aodEvent[i]);
138     }
139   }
140
141 }
142
143
144 //_____________________________________________________________________________
145 void AliRsnAnalysisME::DoAODMixing(AliAODEvent* aod1, AliAODEvent* aod2)
146 {
147 //
148 // mixing of two aod events
149 //
150
151   // assign events
152   fEvent.SetRef(aod1);
153   fEventMix.SetRef(aod2);
154   if (fEvent.GetMultiplicity() < 2) return;
155   if (fEventMix.GetMultiplicity() < 2) return;
156
157   // sort tracks w.r. to PID
158   fPIDIndex.ResetAll(fEvent.GetMultiplicity());
159   fEvent.SetPriorProbability(fPrior);
160   fPIDIndex.FillFromEvent(&fEvent);
161   fPIDIndex.SetCorrectIndexSize();
162
163   fPIDIndexMix.ResetAll(fEventMix.GetMultiplicity());
164   fEventMix.SetPriorProbability(fPrior);
165   fPIDIndexMix.FillFromEvent(&fEventMix);
166   fPIDIndexMix.SetCorrectIndexSize();
167
168   for (Int_t i = 0; i < fNumberOfOutputs; i++) {
169     fRsnAnalysisManager[i].ProcessAllPairMgrs(&fPIDIndex, &fEvent, &fPIDIndexMix, &fEventMix);
170     PostData(i + 2, fOutList[i+1]);
171   }
172   AliDebug(AliLog::kDebug, Form("AOD tracks %d", aod1->GetNumberOfTracks()));
173   AliDebug(AliLog::kDebug, Form("AOD tracks %d", aod2->GetNumberOfTracks()));
174
175 }
176
177
178 //_____________________________________________________________________________
179 void AliRsnAnalysisME::DoESDMixing(AliESDEvent* esd1, AliESDEvent* esd2)
180 {
181 //
182 // mixing of two esd events
183 //
184
185   AliWarning(Form("ESD mixing not supported yet !!! (%p,%p)", esd1, esd2));
186   return;
187 }
188
189
190
191 //_____________________________________________________________________________
192 void AliRsnAnalysisME::RsnTerminate(Option_t*)
193 {
194 //
195 // Rsn Terminate
196 //
197
198   AliDebug(AliLog::kDebug+2, "<-");
199   AliDebug(AliLog::kDebug+2,"->");
200 }
201
202 //_____________________________________________________________________________
203 AliRsnAnalysisManager* AliRsnAnalysisME::GetAnalysisManager(Int_t index, TString name)
204 {
205 //
206 // Recovery the analysis manager
207 //
208
209   if (!name.IsNull()) {
210     SetAnalysisManagerName(name.Data(), index);
211   }
212
213   return &fRsnAnalysisManager[index];
214 }
215
216
217 //_____________________________________________________________________________
218 void AliRsnAnalysisME::SetPriorProbability(AliPID::EParticleType type, Double_t p)
219 {
220 //
221 // Sets the prior probability for Realistic PID, for a
222 // given particle species.
223 //
224
225   if (type >= 0 && type < (Int_t)AliPID::kSPECIES) {
226     fPrior[type] = p;
227   }
228
229 }
230
231 //_____________________________________________________________________________
232 void AliRsnAnalysisME::DumpPriors()
233 {
234   //
235   // Print all prior probabilities
236   //
237
238   Int_t i;
239   for (i = 0; i < AliPID::kSPECIES; i++) {
240     AliInfo(Form("Prior probability for %10s = %3.5f", AliPID::ParticleName((AliPID::EParticleType)i), fPrior[i]));
241   }
242 }
243
244 //_____________________________________________________________________________
245 void AliRsnAnalysisME::GetPriorProbability(Double_t *out) const
246 {
247 //
248 // Gets all prior probabilities to out
249 //
250
251   Int_t i;
252   for (i = 0;i < AliPID::kSPECIES;i++) {
253     out[i] = fPrior[i];
254   }
255 }