]> git.uio.no Git - u/mrichter/AliRoot.git/blame - ANALYSIS/EventMixing/AliMixEventCutObj.cxx
Updated branch aliroot-master, development and master to
[u/mrichter/AliRoot.git] / ANALYSIS / EventMixing / AliMixEventCutObj.cxx
CommitLineData
c5e33610 1//
2// Class AliMixEventCutObj
3//
4// AliMixEventCutObj object contains information about one cut on for event mixing
5// used by AliMixEventPool class
6//
b425275c 7// authors:
c5e33610 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"
3bcab622 15#include "AliAODVertex.h"
35e08f92 16#include "AliEventplane.h"
c5e33610 17
18#include "AliMixEventCutObj.h"
19
20ClassImp(AliMixEventCutObj)
21
22//_________________________________________________________________________________________________
3bcab622 23AliMixEventCutObj::AliMixEventCutObj(AliMixEventCutObj::EEPAxis_t type, Float_t min, Float_t max, Float_t step, const char *opt) : TObject(),
b425275c 24 fCutType((Int_t)type),
298831c0 25 fCutOpt(opt),
b425275c 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, "->");
c5e33610 38}
b425275c 39
c5e33610 40//_________________________________________________________________________________________________
b425275c 41AliMixEventCutObj::AliMixEventCutObj(const AliMixEventCutObj &obj) : TObject(obj),
42 fCutType(obj.fCutType),
298831c0 43 fCutOpt(obj.fCutOpt),
b425275c 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, "->");
c5e33610 55}
56
57//_________________________________________________________________________________________________
3bcab622 58AliMixEventCutObj &AliMixEventCutObj::operator=(const AliMixEventCutObj &obj)
b425275c 59{
60 //
61 // Assigned operator
62 //
63 if (&obj != this) {
64 TObject::operator=(obj);
65 fCutType = obj.fCutType;
298831c0 66 fCutOpt = obj.fCutOpt;
b425275c 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;
c5e33610 75}
b425275c 76
77
c5e33610 78//_________________________________________________________________________________________________
b425275c 79void AliMixEventCutObj::Reset()
80{
81 //
82 // Reset cut
83 //
84 AliDebug(AliLog::kDebug + 5, "<-");
85 fCurrentVal = fCutMin - fCutStep;
86 AliDebug(AliLog::kDebug + 5, "->");
87}
88//_________________________________________________________________________________________________
89Bool_t AliMixEventCutObj::HasMore() const
90{
91 //
92 // Return kTRUE when fCurrentVal is in interval of cut range
93 //
94 return ((fCurrentVal + fCutStep) < fCutMax);
c5e33610 95}
96
97//_________________________________________________________________________________________________
b425275c 98void AliMixEventCutObj::AddStep()
99{
100 //
101 // Adds step
102 //
103 fCurrentVal += fCutStep;
c5e33610 104}
105
106//_________________________________________________________________________________________________
b425275c 107void 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));
c5e33610 113}
114//_________________________________________________________________________________________________
b425275c 115void AliMixEventCutObj::PrintCurrentInterval()
116{
117 //
118 // Prints current cut interval information
119 //
286cc142 120 AliDebug(AliLog::kDebug, Form("%s <%f,%f>", GetCutName(fCutType), GetCurrentMin(), GetCurrentMax()));
c5e33610 121}
122
123//_________________________________________________________________________________________________
b425275c 124Int_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);
c5e33610 131}
132
133//_________________________________________________________________________________________________
b425275c 134Int_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;
f2db2f8e 141 for (Float_t iCurrent = fCutMin; iCurrent < fCutMax; iCurrent += fCutStep) {
b425275c 142 binNum++;
24dc85b1 143 if ((num >= iCurrent) && (num < iCurrent + fCutStep - fCutSmallVal)) {
f2db2f8e 144 return binNum;
145 }
b425275c 146 }
147 return -1;
c5e33610 148}
149
150//_________________________________________________________________________________________________
b425275c 151Int_t AliMixEventCutObj::GetIndex(AliVEvent *ev)
152{
153 //
154 // Finds bin (index) in current cut from event information.
155 //
24dc85b1 156 return GetBinNumber(GetValue(ev));
157}
158
159//_________________________________________________________________________________________________
3bcab622 160Double_t AliMixEventCutObj::GetValue(AliVEvent *ev)
24dc85b1 161{
162 //
163 // Returns value from event
164 //
165
b425275c 166 AliESDEvent *esd = dynamic_cast<AliESDEvent *>(ev);
24dc85b1 167 if (esd) return GetValue(esd);
b425275c 168 AliAODEvent *aod = dynamic_cast<AliAODEvent *>(ev);
24dc85b1 169 if (aod) return GetValue(aod);
170
171 AliFatal("Event is not supported in Event Mixing cuts!!!!");
172 return -99999;
c5e33610 173}
174
175//_________________________________________________________________________________________________
3bcab622 176Double_t AliMixEventCutObj::GetValue(AliESDEvent *ev)
b425275c 177{
178 //
24dc85b1 179 // Returns value from esd event
b425275c 180 //
24dc85b1 181
298831c0 182 const AliMultiplicity *multESD = 0;
183
b425275c 184 switch (fCutType) {
185 case kMultiplicity:
24dc85b1 186 return (Double_t)ev->GetNumberOfTracks();
b425275c 187 case kZVertex:
24dc85b1 188 return ev->GetVertex()->GetZ();
b425275c 189 case kNumberV0s:
24dc85b1 190 return ev->GetNumberOfV0s();
b425275c 191 case kNumberTracklets:
298831c0 192 multESD = ev->GetMultiplicity();
193 if (multESD) return multESD->GetNumberOfTracklets();
194 else AliFatal("esd->GetMultiplicity() is null");
195 break;
196 case kCentrality:
35e08f92 197 {
298831c0 198 AliCentrality *c = ev->GetCentrality();
199 if (!c) AliFatal("esd->GetCentrality() is null");
298831c0 200 return c->GetCentralityPercentile(fCutOpt.Data());
35e08f92 201 }
202 case kEventPlane:
203 {
f6817f48 204 AliEventplane *evtPlane = ev->GetEventplane();
205 if (!evtPlane) evtPlane = new AliEventplane();
35e08f92 206 Double_t val = evtPlane->GetEventplane("V0",ev,fCutOpt.Atoi());
f6817f48 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;
35e08f92 224 return val;
225 }
b425275c 226 }
24dc85b1 227
298831c0 228 AliFatal("Mixing Cut TYPE is not supported for ESD");
24dc85b1 229 return -99999;
230
c5e33610 231}
232
233//_________________________________________________________________________________________________
3bcab622 234Double_t AliMixEventCutObj::GetValue(AliAODEvent *ev)
b425275c 235{
236 //
24dc85b1 237 // Returns value from aod event
b425275c 238 //
3bcab622 239
240 AliAODVertex *v=0;
b425275c 241 switch (fCutType) {
242 case kMultiplicity:
24dc85b1 243 return (Double_t) ev->GetNumberOfTracks();
b425275c 244 case kZVertex:
3bcab622 245 v = ev->GetVertex(0);
246 if (!v) return -99999;
24dc85b1 247 return ev->GetVertex(0)->GetZ();
3bcab622 248 // if verttex is null return -9999
249 return -99999;
b425275c 250 case kNumberV0s:
24dc85b1 251 return ev->GetNumberOfV0s();
298831c0 252 case kCentrality:
35e08f92 253 {
298831c0 254 AliCentrality *c = ev->GetCentrality();
35e08f92 255 if (!c) AliFatal("esd->GetCentrality() is null");
298831c0 256 return c->GetCentralityPercentile(fCutOpt.Data());
35e08f92 257 }
258 case kEventPlane:
259 {
f6817f48 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;
35e08f92 280 return val;
281 }
b425275c 282 }
24dc85b1 283
298831c0 284 AliFatal("Mixing Cut TYPE is not supported for AOD");
24dc85b1 285 return -99999;
c5e33610 286}
24dc85b1 287
c5e33610 288//_________________________________________________________________________________________________
b425275c 289const char *AliMixEventCutObj::GetCutName(Int_t index) const
c5e33610 290{
b425275c 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";
298831c0 305 case kCentrality:
306 return Form("kCentrality[%s]", fCutOpt.Data());
35e08f92 307 case kEventPlane:
308 return Form("EventPlane[%s]", fCutOpt.Data());
f6817f48 309 case kEventPlaneV0A:
310 return Form("EventPlaneV0A[%s]", fCutOpt.Data());
311 case kEventPlaneV0C:
312 return Form("EventPlaneV0A[%s]", fCutOpt.Data());
b425275c 313 }
314 return "";
c5e33610 315}
316
b425275c 317//_________________________________________________________________________________________________
318void AliMixEventCutObj::SetCurrentValueToIndex(Int_t index)
319{
320 //
321 // Sets current value to index
322 //
dce94be0 323
286cc142 324 fCurrentVal = fCutMin;
325 for (Int_t i = 0; i < index-1; i++) AddStep();
b425275c 326}
24dc85b1 327
328//_________________________________________________________________________________________________
3bcab622 329void AliMixEventCutObj::PrintValues(AliVEvent *main, AliVEvent *mix)
24dc85b1 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
f6817f48 337//_________________________________________________________________________________________________
338Bool_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}