]> git.uio.no Git - u/mrichter/AliRoot.git/blob - EVENTMIX/AliMixEventCutObj.cxx
Merge branch 'feature-movesplit'
[u/mrichter/AliRoot.git] / EVENTMIX / AliMixEventCutObj.cxx
1 //
2 // Class AliMixEventCutObj
3 //
4 // AliMixEventCutObj object contains information about one cut on for event mixing
5 // used by AliMixEventPool class
6 //
7 // authors:
8 //          Martin Vala (martin.vala@cern.ch)
9 //
10
11 #include "AliLog.h"
12 #include "AliESDEvent.h"
13 #include "AliAODEvent.h"
14 #include "AliMultiplicity.h"
15 #include "AliAODVertex.h"
16 #include "AliEventplane.h"
17
18 #include "AliMixEventCutObj.h"
19
20 ClassImp(AliMixEventCutObj)
21
22 //_________________________________________________________________________________________________
23 AliMixEventCutObj::AliMixEventCutObj(AliMixEventCutObj::EEPAxis_t type, Float_t min, Float_t max, Float_t step, const char *opt) : TObject(),
24    fCutType((Int_t)type),
25    fCutOpt(opt),
26    fCutMin(min),
27    fCutMax(max),
28    fCutStep(step),
29    fCutSmallVal(0),
30    fCurrentVal(min)
31 {
32    //
33    // Default constructor
34    //
35    AliDebug(AliLog::kDebug + 5, "<-");
36    if (fCutStep < 1e-5) AliError("fCutStep is too small !!! This cut will not work !!!");
37    AliDebug(AliLog::kDebug + 5, "->");
38 }
39
40 //_________________________________________________________________________________________________
41 AliMixEventCutObj::AliMixEventCutObj(const AliMixEventCutObj &obj) : TObject(obj),
42    fCutType(obj.fCutType),
43    fCutOpt(obj.fCutOpt),
44    fCutMin(obj.fCutMin),
45    fCutMax(obj.fCutMax),
46    fCutStep(obj.fCutStep),
47    fCutSmallVal(obj.fCutSmallVal),
48    fCurrentVal(obj.fCurrentVal)
49 {
50    //
51    // Copy constructor
52    //
53    AliDebug(AliLog::kDebug + 5, "<-");
54    AliDebug(AliLog::kDebug + 5, "->");
55 }
56
57 //_________________________________________________________________________________________________
58 AliMixEventCutObj &AliMixEventCutObj::operator=(const AliMixEventCutObj &obj)
59 {
60    //
61    // Assigned operator
62    //
63    if (&obj != this) {
64       TObject::operator=(obj);
65       fCutType = obj.fCutType;
66       fCutOpt = obj.fCutOpt;
67       fCutMin = obj.fCutMin;
68       fCutMax = obj.fCutMax;
69       fCutStep = obj.fCutStep;
70       fCutSmallVal = obj.fCutSmallVal;
71       fCurrentVal = obj.fCurrentVal;
72 //       fNoMore = obj.fNoMore;
73    }
74    return *this;
75 }
76
77
78 //_________________________________________________________________________________________________
79 void AliMixEventCutObj::Reset()
80 {
81    //
82    // Reset cut
83    //
84    AliDebug(AliLog::kDebug + 5, "<-");
85    fCurrentVal = fCutMin - fCutStep;
86    AliDebug(AliLog::kDebug + 5, "->");
87 }
88 //_________________________________________________________________________________________________
89 Bool_t AliMixEventCutObj::HasMore() const
90 {
91    //
92    // Return kTRUE when fCurrentVal is in interval of cut range
93    //
94    return ((fCurrentVal + fCutStep) < fCutMax);
95 }
96
97 //_________________________________________________________________________________________________
98 void AliMixEventCutObj::AddStep()
99 {
100    //
101    // Adds step
102    //
103    fCurrentVal += fCutStep;
104 }
105
106 //_________________________________________________________________________________________________
107 void AliMixEventCutObj::Print(const Option_t *) const
108 {
109    //
110    // Prints cut information
111    //
112    AliInfo(Form("%s %f %f %f", GetCutName(fCutType), fCutMin, fCutMax, fCutStep));
113 }
114 //_________________________________________________________________________________________________
115 void AliMixEventCutObj::PrintCurrentInterval()
116 {
117    //
118    // Prints current cut interval information
119    //
120    AliDebug(AliLog::kDebug, Form("%s <%f,%f>", GetCutName(fCutType), GetCurrentMin(), GetCurrentMax()));
121 }
122
123 //_________________________________________________________________________________________________
124 Int_t AliMixEventCutObj::GetNumberOfBins() const
125 {
126    //
127    // Returns number of bins
128    //
129    if (fCutStep < 1e-5) return -1;
130    return (Int_t)((fCutMax - fCutMin) / fCutStep);
131 }
132
133 //_________________________________________________________________________________________________
134 Int_t AliMixEventCutObj::GetBinNumber(Float_t num) const
135 {
136    //
137    // Returns bin (index) number in current cut.
138    // Returns -1 in case of out of range
139    //
140    Int_t binNum = 0;
141    for (Float_t iCurrent = fCutMin; iCurrent < fCutMax; iCurrent += fCutStep) {
142       binNum++;
143       if ((num >= iCurrent) && (num < iCurrent + fCutStep - fCutSmallVal)) {
144          return binNum;
145       }
146    }
147    return -1;
148 }
149
150 //_________________________________________________________________________________________________
151 Int_t AliMixEventCutObj::GetIndex(AliVEvent *ev)
152 {
153    //
154    // Finds bin (index) in current cut from event information.
155    //
156    return GetBinNumber(GetValue(ev));
157 }
158
159 //_________________________________________________________________________________________________
160 Double_t AliMixEventCutObj::GetValue(AliVEvent *ev)
161 {
162    //
163    // Returns value from event
164    //
165
166    AliESDEvent *esd = dynamic_cast<AliESDEvent *>(ev);
167    if (esd) return GetValue(esd);
168    AliAODEvent *aod = dynamic_cast<AliAODEvent *>(ev);
169    if (aod) return GetValue(aod);
170
171    AliFatal("Event is not supported in Event Mixing cuts!!!!");
172    return -99999;
173 }
174
175 //_________________________________________________________________________________________________
176 Double_t AliMixEventCutObj::GetValue(AliESDEvent *ev)
177 {
178    //
179    // Returns value from esd event
180    //
181
182    const AliMultiplicity *multESD = 0;
183
184    switch (fCutType) {
185       case kMultiplicity:
186          return (Double_t)ev->GetNumberOfTracks();
187       case kZVertex:
188          return ev->GetVertex()->GetZ();
189       case kNumberV0s:
190          return ev->GetNumberOfV0s();
191       case kNumberTracklets:
192          multESD = ev->GetMultiplicity();
193          if (multESD) return multESD->GetNumberOfTracklets();
194          else AliFatal("esd->GetMultiplicity() is null");
195          break;
196       case kCentrality:
197       {
198          AliCentrality *c = ev->GetCentrality();
199          if (!c) AliFatal("esd->GetCentrality() is null");
200          return c->GetCentralityPercentile(fCutOpt.Data());
201       }
202       case kEventPlane:
203       {
204          AliEventplane *evtPlane = ev->GetEventplane();
205          if (!evtPlane) evtPlane = new AliEventplane();
206          Double_t val = evtPlane->GetEventplane("V0",ev,fCutOpt.Atoi());
207          if (!ev->GetEventplane()) delete evtPlane;
208          return val;
209       }
210       case kEventPlaneV0A:
211       {
212          AliEventplane *evtPlane = ev->GetEventplane();
213          if (!evtPlane) evtPlane = new AliEventplane();
214          Double_t val = evtPlane->GetEventplane("V0A",ev,fCutOpt.Atoi());
215          if (!ev->GetEventplane()) delete evtPlane;
216          return val;
217       }
218       case kEventPlaneV0C:
219       {
220          AliEventplane *evtPlane = ev->GetEventplane();
221          if (!evtPlane) evtPlane = new AliEventplane();
222          Double_t val = evtPlane->GetEventplane("V0C",ev,fCutOpt.Atoi());
223          if (!ev->GetEventplane()) delete evtPlane;
224          return val;
225       }
226    }
227
228    AliFatal("Mixing Cut TYPE is not supported for ESD");
229    return -99999;
230
231 }
232
233 //_________________________________________________________________________________________________
234 Double_t AliMixEventCutObj::GetValue(AliAODEvent *ev)
235 {
236    //
237    // Returns value from aod event
238    //
239
240    AliAODVertex *v=0;
241    switch (fCutType) {
242       case kMultiplicity:
243          return (Double_t) ev->GetNumberOfTracks();
244       case kZVertex:
245          v = ev->GetVertex(0);
246          if (!v)  return -99999;
247          return ev->GetVertex(0)->GetZ();
248          // if verttex is null return -9999
249          return -99999;
250       case kNumberV0s:
251          return ev->GetNumberOfV0s();
252       case kCentrality:
253       {
254          AliCentrality *c = ev->GetCentrality();
255          if (!c) AliFatal("esd->GetCentrality() is null");
256          return c->GetCentralityPercentile(fCutOpt.Data());
257       }
258       case kEventPlane:
259       {
260          AliEventplane *evtPlane = ev->GetEventplane();
261          if (!evtPlane) evtPlane = new AliEventplane();
262          Double_t val = evtPlane->GetEventplane("V0A",ev,fCutOpt.Atoi());
263          if (!ev->GetEventplane()) delete evtPlane;
264          return val;
265       }
266       case kEventPlaneV0A:
267       {
268          AliEventplane *evtPlane = ev->GetEventplane();
269          if (!evtPlane) evtPlane = new AliEventplane();
270          Double_t val = evtPlane->GetEventplane("V0A",ev,fCutOpt.Atoi());
271          if (!ev->GetEventplane()) delete evtPlane;
272          return val;
273       }
274       case kEventPlaneV0C:
275       {
276          AliEventplane *evtPlane = ev->GetEventplane();
277          if (!evtPlane) evtPlane = new AliEventplane();
278          Double_t val = evtPlane->GetEventplane("V0C",ev,fCutOpt.Atoi());
279          if (!ev->GetEventplane()) delete evtPlane;
280          return val;
281       }
282    }
283
284    AliFatal("Mixing Cut TYPE is not supported for AOD");
285    return -99999;
286 }
287
288 //_________________________________________________________________________________________________
289 const char *AliMixEventCutObj::GetCutName(Int_t index) const
290 {
291    //
292    // Retruns name of cut
293    //
294
295    if (index < 0) index = fCutType;
296    switch (index) {
297       case kMultiplicity:
298          return "Multiplicity";
299       case kZVertex:
300          return "ZVertex";
301       case kNumberV0s:
302          return "NumberV0s";
303       case kNumberTracklets:
304          return "NumberTracklets";
305       case kCentrality:
306          return Form("kCentrality[%s]", fCutOpt.Data());
307       case kEventPlane:
308          return Form("EventPlane[%s]", fCutOpt.Data());
309       case kEventPlaneV0A:
310          return Form("EventPlaneV0A[%s]", fCutOpt.Data());
311       case kEventPlaneV0C:
312          return Form("EventPlaneV0A[%s]", fCutOpt.Data());
313    }
314    return "";
315 }
316
317 //_________________________________________________________________________________________________
318 void AliMixEventCutObj::SetCurrentValueToIndex(Int_t index)
319 {
320    //
321    // Sets current value to index
322    //
323
324    fCurrentVal = fCutMin;
325    for (Int_t i = 0; i < index-1; i++) AddStep();
326 }
327
328 //_________________________________________________________________________________________________
329 void AliMixEventCutObj::PrintValues(AliVEvent *main, AliVEvent *mix)
330 {
331    //
332    // Prints values of both events for current type
333    //
334    AliInfo(Form("name=%s main=%f mix=%f", GetCutName(), GetValue(main), GetValue(mix)));
335 }
336
337 //_________________________________________________________________________________________________
338 Bool_t AliMixEventCutObj::IsValid()
339 {
340    //
341    // Check if cut is valid
342    //
343    switch (fCutType) {
344
345       case kCentrality:
346       {
347          if (fCutOpt.IsNull()) {
348             AliError("fCutOpt is null");
349             return kFALSE;
350          }
351          break;
352       }
353       case kEventPlane:
354       {
355          if (fCutOpt.IsNull()) {
356             AliError("fCutOpt is null");
357             return kFALSE;
358          }
359          if (!fCutOpt.IsDigit()) {
360             AliError("fCutOpt is not a digit string");
361             return kFALSE;
362          }
363          break;
364       }
365       case kEventPlaneV0A:
366       {
367          if (fCutOpt.IsNull()) {
368             AliError("fCutOpt is null");
369             return kFALSE;
370          }
371          if (!fCutOpt.IsDigit()) {
372             AliError("fCutOpt is not a digit string");
373             return kFALSE;
374          }
375          break;
376       }
377       case kEventPlaneV0C:
378       {
379          if (fCutOpt.IsNull()) {
380             AliError("fCutOpt is null");
381             return kFALSE;
382          }
383          if (!fCutOpt.IsDigit()) {
384             AliError("fCutOpt is not a digit string");
385             return kFALSE;
386          }
387          break;
388       }
389       default: {
390          break;
391       }
392    }
393
394    return kTRUE;
395 }