]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PWG2/RESONANCES/AliRsnValue.cxx
Corrections after survey of Coverity tests
[u/mrichter/AliRoot.git] / PWG2 / RESONANCES / AliRsnValue.cxx
CommitLineData
2dab9030 1
b9bbd271 2//
3// Class AliRsnValue
4//
5// Definition of a single value which can be computed
6// from any of the defined input objects implemented
7// in the resonance package.
8//
9
10#include "AliRsnEvent.h"
11#include "AliRsnDaughter.h"
2dab9030 12#include "AliRsnMother.h"
b9bbd271 13#include "AliRsnPairDef.h"
14
15#include "AliRsnValue.h"
16
17ClassImp(AliRsnValue)
18
19//_____________________________________________________________________________
2dab9030 20AliRsnValue::AliRsnValue() :
0d73200d 21 TNamed(),
b2b08ca2 22 fValue(0.0),
63a2738c 23 fType(kValueTypes),
b2b08ca2 24 fArray(0)
2dab9030 25{
26//
27// Main constructor (version 1)
28// This can also be created without any argument.
29//
30}
31
32//_____________________________________________________________________________
33AliRsnValue::AliRsnValue
0d73200d 34(const char *name, EValueType type, Int_t nbins, Double_t min, Double_t max) :
35 TNamed(name, ""),
b2b08ca2 36 fValue(0.0),
63a2738c 37 fType(type),
b2b08ca2 38 fArray(0)
b9bbd271 39{
40//
2dab9030 41// Main constructor (version 1)
42// This can also be created without any argument.
b9bbd271 43//
2dab9030 44
45 SetBins(nbins, min, max);
46}
47
48//_____________________________________________________________________________
49AliRsnValue::AliRsnValue
0d73200d 50(const char *name, EValueType type, Double_t min, Double_t max, Double_t step) :
51 TNamed(name, ""),
b2b08ca2 52 fValue(0.0),
63a2738c 53 fType(type),
b2b08ca2 54 fArray(0)
2dab9030 55{
56//
57// Main constructor (version 2)
58//
59
60 SetBins(min, max, step);
b9bbd271 61}
62
63//_____________________________________________________________________________
b2b08ca2 64AliRsnValue::AliRsnValue
65(const char *name, EValueType type, Int_t nbins, Double_t *array) :
66 TNamed(name, ""),
b2b08ca2 67 fValue(0.0),
63a2738c 68 fType(type),
b2b08ca2 69 fArray(0)
b9bbd271 70{
71//
b2b08ca2 72// Main constructor (version 2)
73//
74
75 SetBins(nbins, array);
b9bbd271 76}
77
78//_____________________________________________________________________________
b2b08ca2 79void AliRsnValue::SetBins(Int_t nbins, Double_t min, Double_t max)
b9bbd271 80{
81//
b2b08ca2 82// Set binning for the axis in equally spaced bins
83// where the number of bins, minimum and maximum are given.
84//
85
86 fArray.Set(nbins + 1);
87
88 Double_t mymax = TMath::Max(min, max);
89 Double_t mymin = TMath::Min(min, max);
90
91 Int_t k = 0;
92 Double_t binSize = (mymax - mymin) / ((Double_t)nbins);
93
94 fArray[0] = mymin;
95 for (k = 1; k <= nbins; k++) fArray[k] = fArray[k-1] + binSize;
96 for (k = 0; k < fArray.GetSize() - 1; k++) AliDebug(AliLog::kDebug + 3, Form("Bin #%d: %f - %f", k, fArray[k], fArray[k+1]));
2dab9030 97}
98
99//_____________________________________________________________________________
b2b08ca2 100void AliRsnValue::SetBins(Double_t min, Double_t max, Double_t step)
2dab9030 101{
102//
b2b08ca2 103// Set binning for the axis in equally spaced bins
104// where the bin size, minimum and maximum are given.
2dab9030 105//
106
b2b08ca2 107 Double_t dblNbins = TMath::Abs(max - min) / step;
108 Int_t intNbins = ((Int_t)dblNbins) + 1;
109
110 SetBins(intNbins, min, max);
b9bbd271 111}
112
113//_____________________________________________________________________________
b2b08ca2 114void AliRsnValue::SetBins(Int_t nbins, Double_t *array)
2dab9030 115{
116//
b2b08ca2 117// Set binning for the axis in unequally spaced bins
118// using the same way it is done in TAxis
2dab9030 119//
120
b2b08ca2 121 fArray.Adopt(nbins, array);
122 for (Int_t k = 0; k < fArray.GetSize() - 1; k++) AliDebug(AliLog::kDebug + 3, Form("Bin #%d: %f - %f", k, fArray[k], fArray[k+1]));
2dab9030 123}
124
125//_____________________________________________________________________________
2e521c29 126Bool_t AliRsnValue::Eval(AliRsnMother * const mother, AliRsnPairDef * const pairDef, AliRsnEvent * const event)
b9bbd271 127{
128//
129// Evaluation of the required value.
130// Checks that the passed object is of the right type
131// and if this check is successful, returns the required value.
132// The output of the function tells if it was successful,
133// and the values must be taken with GetValue().
134//
135
2dab9030 136 // avoid segfaults
137 if (!mother) return kFALSE;
138 if (!pairDef) return kFALSE;
b9bbd271 139
2dab9030 140 Double_t mass = pairDef->GetMotherMass();
b9bbd271 141
142 switch (fType)
143 {
b9bbd271 144 case kTrack1P:
2dab9030 145 fValue = mother->GetDaughter(0)->P().Mag();
146 break;
b9bbd271 147 case kTrack2P:
2dab9030 148 fValue = mother->GetDaughter(1)->P().Mag();
149 break;
b9bbd271 150 case kTrack1Pt:
2dab9030 151 fValue = mother->GetDaughter(0)->P().Perp();
152 break;
b9bbd271 153 case kTrack2Pt:
2dab9030 154 fValue = mother->GetDaughter(1)->P().Perp();
155 break;
3c07ce75 156 case kTrack1Px:
157 fValue = mother->GetDaughter(0)->P().X();
158 break;
159 case kTrack1Py:
160 fValue = mother->GetDaughter(0)->P().Y();
161 break;
162 case kTrack1Pz:
163 fValue = mother->GetDaughter(0)->P().Z();
164 break;
165 case kTrack2Px:
166 fValue = mother->GetDaughter(1)->P().X();
167 break;
168 case kTrack2Py:
169 fValue = mother->GetDaughter(1)->P().Y();
170 break;
171 case kTrack2Pz:
172 fValue = mother->GetDaughter(1)->P().Z();
173 break;
b9bbd271 174 case kPairInvMass:
2dab9030 175 fValue = mother->Sum().M();
176 break;
b9bbd271 177 case kPairInvMassMC:
2dab9030 178 fValue = mother->SumMC().M();
179 break;
b9bbd271 180 case kPairInvMassRes:
2dab9030 181 fValue = (mother->SumMC().M() - mother->Sum().M()) / mother->SumMC().M();
182 break;
b9bbd271 183 case kPairPt:
2dab9030 184 fValue = mother->Sum().Perp();
185 break;
b9bbd271 186 case kPairEta:
2dab9030 187 fValue = mother->Sum().Eta();
188 break;
b9bbd271 189 case kPairMt:
190 if (TMath::Abs(mass) < 1E-5) AliWarning(Form("Suspicious mass value specified: %f", mass));
2dab9030 191 fValue = (TMath::Sqrt(mother->Sum().Perp2() + mass*mass) - mass);
192 break;
b9bbd271 193 case kPairY:
194 if (TMath::Abs(mass) < 1E-5) AliWarning(Form("Suspicious mass value specified: %f", mass));
2dab9030 195 mother->SetDefaultMass(mass);
196 fValue = mother->Ref().Rapidity();
197 break;
2e521c29 198 case kPairCosThetaStar:
199 fValue = mother->CosThetaStar();
200 break;
cadcd9e0 201 case kPairCosThetaStar1:
2e521c29 202 //fValue = TMath::Cos(mother->ThetaStar(kTRUE, kFALSE));
cadcd9e0 203 break;
204 case kPairCosThetaStar2:
2e521c29 205 //fValue = TMath::Cos(mother->ThetaStar(kFALSE, kFALSE));
cadcd9e0 206 break;
207 case kPairCosThetaStarMC1:
2e521c29 208 //fValue = TMath::Cos(mother->ThetaStar(kTRUE, kTRUE));
cadcd9e0 209 break;
210 case kPairCosThetaStarMC2:
2e521c29 211 //fValue = TMath::Cos(mother->ThetaStar(kFALSE, kTRUE));
cadcd9e0 212 break;
11ba7ebc 213 case kAngleToLeading:
214 {
215 int ID1 = (mother->GetDaughter(0))->GetID();
216 int ID2 = (mother->GetDaughter(1))->GetID();
217 int leadingID = event->SelectLeadingParticle(0);
218 if(leadingID == ID1 || leadingID == ID2) return kFALSE;
219 AliRsnDaughter leadingPart = event->GetDaughter(leadingID);
220 AliVParticle *ref = leadingPart.GetRef();
221
222 fValue = ref->Phi() - mother->Sum().Phi();
223 //return angle w.r.t. leading particle in the range -pi/2, 3/2pi
224 while(fValue >= TMath::Pi()) fValue -= 2*TMath::Pi();
225 while(fValue < -0.5*TMath::Pi()) fValue += 2*TMath::Pi();
226 //Printf("%g", fValue);
11ba7ebc 227 }
228 break;
b9bbd271 229 case kEventMult:
96e9d35d 230 if (!event)
231 {
232 fValue = 0.0;
233 return kFALSE;
234 }
235 else fValue = (Double_t)event->GetMultiplicity();
2dab9030 236 break;
11ba7ebc 237 case kLeadingPt:
96e9d35d 238 if (!event)
239 {
240 fValue = 0.0;
241 return kFALSE;
242 }
243 else
11ba7ebc 244 {
245 int leadingID = event->SelectLeadingParticle(0);
246 if(leadingID >= 0) {
247 AliRsnDaughter leadingPart = event->GetDaughter(leadingID);
248 AliVParticle *ref = leadingPart.GetRef();
249 fValue = ref->Pt();
250 }
251 else fValue = 0;
252 }
253 break;
2467e7c3 254 case kQInv:
255 {
256 TLorentzVector diff = mother->GetDaughter(0)->P() - mother->GetDaughter(1)->P();
257 fValue = diff.M();
258 }
259 break;
b9bbd271 260 default:
261 AliWarning("Invalid value type");
2dab9030 262 return kFALSE;
b9bbd271 263 }
2dab9030 264
265 return kTRUE;
b9bbd271 266}
c18b1218 267
69fbb331 268//_____________________________________________________________________________
269Bool_t AliRsnValue::Eval(AliRsnDaughter * const daughter, AliRsnEvent * const event)
270{
271//
272// Evaluation of the required value.
273// Checks that the passed object is of the right type
274// and if this check is successful, returns the required value.
275// The output of the function tells if it was successful,
276// and the values must be taken with GetValue().
277//
278
279 // avoid segfaults
280 if (!daughter) return kFALSE;
281
282 switch (fType)
283 {
96e9d35d 284 case kEventMult:
285 if (!event)
286 {
287 fValue = 0.0;
288 return kFALSE;
289 }
290 else fValue = (Double_t)event->GetMultiplicity();
291 break;
292 case kLeadingPt:
293 if (!event)
294 {
295 fValue = 0.0;
296 return kFALSE;
297 }
298 else
299 {
300 int leadingID = event->SelectLeadingParticle(0);
301 if(leadingID >= 0) {
302 AliRsnDaughter leadingPart = event->GetDaughter(leadingID);
303 AliVParticle *ref = leadingPart.GetRef();
304 fValue = ref->Pt();
305 }
306 else fValue = 0;
307 }
308 break;
69fbb331 309 default:
310 AliWarning("Invalid value type");
311 return kFALSE;
312 }
313
314 return kTRUE;
315}
316
c18b1218 317//_____________________________________________________________________________
318void AliRsnValue::Print(Option_t *) const
319{
320//
321// Print all bins
322//
323
324 Int_t i, n = fArray.GetSize();
325 TString msg("Array values: ");
326
327 for (i = 0; i < n; i++) msg += Form("%f, ", fArray[i]);
328
329 AliInfo(Form("Axis name: %s", GetName()));
330 AliInfo(msg.Data());
331}