]> git.uio.no Git - u/mrichter/AliRoot.git/blob - ANALYSIS/EventMixing/AliMixEventCutObj.cxx
Fixes in AliMixInputEventHandler to correctly set mixing parameters + reformating...
[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
16 #include "AliMixEventCutObj.h"
17
18 ClassImp(AliMixEventCutObj)
19
20 //_________________________________________________________________________________________________
21 AliMixEventCutObj::AliMixEventCutObj(EEPAxis_t type, Float_t min, Float_t max, Float_t step) : TObject(),
22    fCutType((Int_t)type),
23    fCutMin(min),
24    fCutMax(max),
25    fCutStep(step),
26    fCutSmallVal(0),
27    fCurrentVal(min)
28 {
29    //
30    // Default constructor
31    //
32    AliDebug(AliLog::kDebug + 5, "<-");
33    if (fCutStep < 1e-5) AliError("fCutStep is too small !!! This cut will not work !!!");
34    AliDebug(AliLog::kDebug + 5, "->");
35 }
36
37 //_________________________________________________________________________________________________
38 AliMixEventCutObj::AliMixEventCutObj(const AliMixEventCutObj &obj) : TObject(obj),
39    fCutType(obj.fCutType),
40    fCutMin(obj.fCutMin),
41    fCutMax(obj.fCutMax),
42    fCutStep(obj.fCutStep),
43    fCutSmallVal(obj.fCutSmallVal),
44    fCurrentVal(obj.fCurrentVal)
45 {
46    //
47    // Copy constructor
48    //
49    AliDebug(AliLog::kDebug + 5, "<-");
50    AliDebug(AliLog::kDebug + 5, "->");
51 }
52
53 //_________________________________________________________________________________________________
54 AliMixEventCutObj& AliMixEventCutObj::operator=(const AliMixEventCutObj& obj)
55 {
56    //
57    // Assigned operator
58    //
59    if (&obj != this) {
60       TObject::operator=(obj);
61       fCutType = obj.fCutType;
62       fCutMin = obj.fCutMin;
63       fCutMax = obj.fCutMax;
64       fCutStep = obj.fCutStep;
65       fCutSmallVal = obj.fCutSmallVal;
66       fCurrentVal = obj.fCurrentVal;
67 //       fNoMore = obj.fNoMore;
68    }
69    return *this;
70 }
71
72
73 //_________________________________________________________________________________________________
74 void AliMixEventCutObj::Reset()
75 {
76    //
77    // Reset cut
78    //
79    AliDebug(AliLog::kDebug + 5, "<-");
80    fCurrentVal = fCutMin - fCutStep;
81    AliDebug(AliLog::kDebug + 5, "->");
82 }
83 //_________________________________________________________________________________________________
84 Bool_t AliMixEventCutObj::HasMore() const
85 {
86    //
87    // Return kTRUE when fCurrentVal is in interval of cut range
88    //
89    return ((fCurrentVal + fCutStep) < fCutMax);
90 }
91
92 //_________________________________________________________________________________________________
93 void AliMixEventCutObj::AddStep()
94 {
95    //
96    // Adds step
97    //
98    fCurrentVal += fCutStep;
99 }
100
101 //_________________________________________________________________________________________________
102 void AliMixEventCutObj::Print(const Option_t *) const
103 {
104    //
105    // Prints cut information
106    //
107    AliInfo(Form("%s %f %f %f", GetCutName(fCutType), fCutMin, fCutMax, fCutStep));
108 }
109 //_________________________________________________________________________________________________
110 void AliMixEventCutObj::PrintCurrentInterval()
111 {
112    //
113    // Prints current cut interval information
114    //
115    AliDebug(AliLog::kDebug, Form("%s <%f,%f>", GetCutName(fCutType), GetMin(), GetMax()));
116 }
117
118 //_________________________________________________________________________________________________
119 Int_t AliMixEventCutObj::GetNumberOfBins() const
120 {
121    //
122    // Returns number of bins
123    //
124    if (fCutStep < 1e-5) return -1;
125    return (Int_t)((fCutMax - fCutMin) / fCutStep);
126 }
127
128 //_________________________________________________________________________________________________
129 Int_t AliMixEventCutObj::GetBinNumber(Float_t num) const
130 {
131    //
132    // Returns bin (index) number in current cut.
133    // Returns -1 in case of out of range
134    //
135    Int_t binNum = 0;
136    for (Float_t i = fCutMin; i <= fCutMax - fCutSmallVal; i += fCutStep) {
137       binNum++;
138       if ((num >= i) && (num <= i + fCutStep - fCutSmallVal)) return binNum;
139    }
140    return -1;
141 }
142
143 //_________________________________________________________________________________________________
144 Int_t AliMixEventCutObj::GetIndex(AliVEvent *ev)
145 {
146    //
147    // Finds bin (index) in current cut from event information.
148    //
149    AliESDEvent *esd = dynamic_cast<AliESDEvent *>(ev);
150    if (esd) return GetIndex(esd);
151    AliAODEvent *aod = dynamic_cast<AliAODEvent *>(ev);
152    if (aod) return GetIndex(aod);
153    return -1;
154 }
155
156 //_________________________________________________________________________________________________
157 Int_t AliMixEventCutObj::GetIndex(AliESDEvent *ev)
158 {
159    //
160    // Finds bin (index) in current cut from ESD event information.
161    //
162    switch (fCutType) {
163       case kMultiplicity:
164          return GetBinNumber((Float_t)ev->GetNumberOfTracks());
165       case kZVertex:
166          return GetBinNumber(ev->GetVertex()->GetZ());
167       case kNumberV0s:
168          return GetBinNumber(ev->GetNumberOfV0s());
169       case kNumberTracklets:
170          const AliMultiplicity *multESD = ev->GetMultiplicity();
171          return GetBinNumber(multESD->GetNumberOfTracklets());
172    }
173    return -1;
174 }
175
176 //_________________________________________________________________________________________________
177 Int_t AliMixEventCutObj::GetIndex(AliAODEvent *ev)
178 {
179    //
180    // Finds bin (index) in current cut from AOD event information.
181    //
182    switch (fCutType) {
183       case kMultiplicity:
184          return GetBinNumber((Float_t)ev->GetNumberOfTracks());
185       case kZVertex:
186          return GetBinNumber(ev->GetVertex(0)->GetZ());
187       case kNumberV0s:
188          return GetBinNumber(ev->GetNumberOfV0s());
189    }
190    return -1;
191 }
192 //_________________________________________________________________________________________________
193 const char *AliMixEventCutObj::GetCutName(Int_t index) const
194 {
195    //
196    // Retruns name of cut
197    //
198
199    if (index < 0) index = fCutType;
200    switch (index) {
201       case kMultiplicity:
202          return "Multiplicity";
203       case kZVertex:
204          return "ZVertex";
205       case kNumberV0s:
206          return "NumberV0s";
207       case kNumberTracklets:
208          return "NumberTracklets";
209    }
210    return "";
211 }
212
213 //_________________________________________________________________________________________________
214 void AliMixEventCutObj::SetCurrentValueToIndex(Int_t index)
215 {
216    //
217    // Sets current value to index
218    //
219    for (Int_t i = 0; i < index; i++) AddStep();
220 }