]> git.uio.no Git - u/mrichter/AliRoot.git/blob - ANALYSIS/EventMixing/AliMixEventCutObj.cxx
Added EventPlane cut for mixing
[u/mrichter/AliRoot.git] / ANALYSIS / EventMixing / 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), GetMin(), GetMax()));
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          if (fCutOpt.IsNull()) AliFatal("fCutOpt is null");
201          return c->GetCentralityPercentile(fCutOpt.Data());
202       }
203       case kEventPlane:
204       {
205          AliEventplane *evtPlane = new AliEventplane();
206          if (fCutOpt.IsNull()) AliFatal("fCutOpt is null");
207          if (!fCutOpt.IsDigit()) AliFatal("fCutOpt is not a digit string");
208          Double_t val = evtPlane->GetEventplane("V0",ev,fCutOpt.Atoi());
209          delete evtPlane;
210          return val;
211       }
212    }
213
214    AliFatal("Mixing Cut TYPE is not supported for ESD");
215    return -99999;
216
217 }
218
219 //_________________________________________________________________________________________________
220 Double_t AliMixEventCutObj::GetValue(AliAODEvent *ev)
221 {
222    //
223    // Returns value from aod event
224    //
225
226    AliAODVertex *v=0;
227    switch (fCutType) {
228       case kMultiplicity:
229          return (Double_t) ev->GetNumberOfTracks();
230       case kZVertex:
231          v = ev->GetVertex(0);
232          if (!v)  return -99999;
233          return ev->GetVertex(0)->GetZ();
234          // if verttex is null return -9999
235          return -99999;
236       case kNumberV0s:
237          return ev->GetNumberOfV0s();
238       case kCentrality:
239       {
240          AliCentrality *c = ev->GetCentrality();
241          if (!c) AliFatal("esd->GetCentrality() is null");
242          if (fCutOpt.IsNull()) AliFatal("fCutOpt is null");
243          return c->GetCentralityPercentile(fCutOpt.Data());
244       }
245       case kEventPlane:
246       {
247          AliEventplane *evtPlane = new AliEventplane();
248          if (fCutOpt.IsNull()) AliFatal("fCutOpt is null");
249          if (!fCutOpt.IsDigit()) AliFatal("fCutOpt is not a digit string");
250          Double_t val = evtPlane->GetEventplane("V0",ev,fCutOpt.Atoi());
251          delete evtPlane;
252          return val;
253       }
254    }
255
256    AliFatal("Mixing Cut TYPE is not supported for AOD");
257    return -99999;
258 }
259
260 //_________________________________________________________________________________________________
261 const char *AliMixEventCutObj::GetCutName(Int_t index) const
262 {
263    //
264    // Retruns name of cut
265    //
266
267    if (index < 0) index = fCutType;
268    switch (index) {
269       case kMultiplicity:
270          return "Multiplicity";
271       case kZVertex:
272          return "ZVertex";
273       case kNumberV0s:
274          return "NumberV0s";
275       case kNumberTracklets:
276          return "NumberTracklets";
277       case kCentrality:
278          return Form("kCentrality[%s]", fCutOpt.Data());
279       case kEventPlane:
280          return Form("EventPlane[%s]", fCutOpt.Data());
281    }
282    return "";
283 }
284
285 //_________________________________________________________________________________________________
286 void AliMixEventCutObj::SetCurrentValueToIndex(Int_t index)
287 {
288    //
289    // Sets current value to index
290    //
291    for (Int_t i = 0; i < index; i++) AddStep();
292 }
293
294 //_________________________________________________________________________________________________
295 void AliMixEventCutObj::PrintValues(AliVEvent *main, AliVEvent *mix)
296 {
297    //
298    // Prints values of both events for current type
299    //
300    AliInfo(Form("name=%s main=%f mix=%f", GetCutName(), GetValue(main), GetValue(mix)));
301 }
302