Improved functionality of AliRsnDaughterDef::MatchesDaughter()
[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
d0282f3d 10#include <Riostream.h>
32992791 11#include "AliESDtrackCuts.h"
b9bbd271 12#include "AliRsnEvent.h"
13#include "AliRsnDaughter.h"
2dab9030 14#include "AliRsnMother.h"
b9bbd271 15#include "AliRsnPairDef.h"
11ed73f6 16#include "AliRsnDaughterDef.h"
b9bbd271 17
18#include "AliRsnValue.h"
19
20ClassImp(AliRsnValue)
21
22//_____________________________________________________________________________
2dab9030 23AliRsnValue::AliRsnValue() :
2a1c7696 24 AliRsnTarget(),
25 fComputedValue(0),
26 fValueType(kValueTypes),
27 fBinArray(0),
28 fSupportObject(0x0)
2dab9030 29{
30//
32992791 31// Default constructor without arguments.
32// Initialize data members to meaningless values.
2a1c7696 33// This method is provided for ROOT streaming,
32992791 34// but should never be used directly by a user.
2dab9030 35//
32992791 36
2a1c7696 37 AssignTarget();
2dab9030 38}
39
40//_____________________________________________________________________________
41AliRsnValue::AliRsnValue
0d73200d 42(const char *name, EValueType type, Int_t nbins, Double_t min, Double_t max) :
2a1c7696 43 AliRsnTarget(name, AliRsnTarget::kTargetTypes),
44 fComputedValue(0.0),
45 fValueType(type),
46 fBinArray(0),
47 fSupportObject(0x0)
b9bbd271 48{
49//
32992791 50// Main constructor (version 1).
51// This constructor defines in meaningful way all data members,
52// and defined a fixed binnings, subdividing the specified interval
53// into that many bins as specified in the integer argument.
54// ---
55// This method is also the entry point for all instances
56// of this class which don't need to do binning (e.g.: TNtuple inputs),
57// since arguments 3 to 5 have default values which don't create any
58// binning array, in order not to allocate memory when this is useless.
b9bbd271 59//
2dab9030 60
2a1c7696 61 AssignTarget();
62 SetBins(nbins, min, max);
2dab9030 63}
64
65//_____________________________________________________________________________
66AliRsnValue::AliRsnValue
0d73200d 67(const char *name, EValueType type, Double_t min, Double_t max, Double_t step) :
2a1c7696 68 AliRsnTarget(name, AliRsnTarget::kTargetTypes),
69 fComputedValue(0.0),
70 fValueType(type),
71 fBinArray(0),
72 fSupportObject(0x0)
2dab9030 73{
74//
32992791 75// Main constructor (version 2).
76// This constructor defines in meaningful way all data members
77// and creates enough equal bins of the specified size to cover
78// the required interval.
2dab9030 79//
80
2a1c7696 81 AssignTarget();
82 SetBins(min, max, step);
b9bbd271 83}
84
85//_____________________________________________________________________________
b2b08ca2 86AliRsnValue::AliRsnValue
87(const char *name, EValueType type, Int_t nbins, Double_t *array) :
2a1c7696 88 AliRsnTarget(name, AliRsnTarget::kTargetTypes),
89 fComputedValue(0.0),
90 fValueType(type),
91 fBinArray(0),
92 fSupportObject(0x0)
b9bbd271 93{
94//
32992791 95// Main constructor (version 3).
96// This constructor defines in meaningful way all data members
97// and creates a set of variable bins delimited by the passed array.
b2b08ca2 98//
99
2a1c7696 100 AssignTarget();
101 SetBins(nbins, array);
b9bbd271 102}
103
104//_____________________________________________________________________________
2a1c7696 105AliRsnValue::AliRsnValue(const AliRsnValue& copy) :
106 AliRsnTarget(copy),
107 fComputedValue(copy.fComputedValue),
108 fValueType(copy.fValueType),
109 fBinArray(copy.fBinArray),
110 fSupportObject(copy.fSupportObject)
52944696 111{
112//
32992791 113// Copy constructor.
114// Duplicates the binning array and copies all settings.
2a1c7696 115// Calls also the function that assigns properly the
32992791 116// expected target, depending on the computation type.
52944696 117//
32992791 118
2a1c7696 119 AssignTarget();
52944696 120}
121
122//_____________________________________________________________________________
123AliRsnValue& AliRsnValue::operator=(const AliRsnValue& copy)
124{
125//
32992791 126// Assignment operator.
127// Works like copy constructor.
52944696 128//
129
2a1c7696 130 AliRsnTarget::operator=(copy);
131
132 fComputedValue = copy.fComputedValue;
133 fBinArray = copy.fBinArray;
134 fSupportObject = copy.fSupportObject;
135
136 AssignTarget();
137
138 return (*this);
52944696 139}
140
141//_____________________________________________________________________________
b2b08ca2 142void AliRsnValue::SetBins(Int_t nbins, Double_t min, Double_t max)
b9bbd271 143{
144//
b2b08ca2 145// Set binning for the axis in equally spaced bins
146// where the number of bins, minimum and maximum are given.
147//
148
2a1c7696 149 if (!nbins) {
150 fBinArray.Set(0);
151 return;
152 }
153
154 fBinArray.Set(nbins + 1);
155
156 Double_t mymax = TMath::Max(min, max);
157 Double_t mymin = TMath::Min(min, max);
158
159 Int_t k = 0;
160 Double_t binSize = (mymax - mymin) / ((Double_t)nbins);
161
162 fBinArray[0] = mymin;
163 for (k = 1; k <= nbins; k++) fBinArray[k] = fBinArray[k - 1] + binSize;
2dab9030 164}
165
166//_____________________________________________________________________________
b2b08ca2 167void AliRsnValue::SetBins(Double_t min, Double_t max, Double_t step)
2dab9030 168{
169//
b2b08ca2 170// Set binning for the axis in equally spaced bins
171// where the bin size, minimum and maximum are given.
2dab9030 172//
173
2a1c7696 174 Double_t dblNbins = TMath::Abs(max - min) / step;
175 Int_t intNbins = ((Int_t)dblNbins) + 1;
176
177 SetBins(intNbins, min, max);
b9bbd271 178}
179
180//_____________________________________________________________________________
b2b08ca2 181void AliRsnValue::SetBins(Int_t nbins, Double_t *array)
2dab9030 182{
183//
b2b08ca2 184// Set binning for the axis in unequally spaced bins
185// using the same way it is done in TAxis
2dab9030 186//
187
2a1c7696 188 if (!nbins) {
189 fBinArray.Set(0);
190 return;
191 }
192
193 fBinArray.Adopt(nbins, array);
32992791 194}
195
196//_____________________________________________________________________________
197const char* AliRsnValue::GetValueTypeName() const
198{
199//
200// This method returns a string to give a name to each possible
201// computation value.
202//
2a1c7696 203
204 switch (fValueType) {
205 case kTrackP: return "SingleTrackPtot";
206 case kTrackPt: return "SingleTrackPt";
207 case kTrackEta: return "SingleTrackEta";
11ed73f6 208 case kTrackY: return "SingleTrackRapidity";
2a1c7696 209 case kPairP1: return "PairPtotDaughter1";
210 case kPairP2: return "PairPtotDaughter2";
211 case kPairP1t: return "PairPtDaughter1";
212 case kPairP2t: return "PairPtDaughter2";
213 case kPairP1z: return "PairPzDaughter1";
214 case kPairP2z: return "PairPzDaughter2";
215 case kPairInvMass: return "PairInvMass";
216 case kPairInvMassMC: return "PairInvMassMC";
217 case kPairInvMassRes: return "PairInvMassResolution";
218 case kPairPt: return "PairPt";
219 case kPairPz: return "PairPz";
220 case kPairEta: return "PairEta";
221 case kPairMt: return "PairMt";
222 case kPairY: return "PairY";
223 case kPairPhi: return "PairPhi";
224 case kPairPhiMC: return "PairPhiMC";
225 case kPairPtRatio: return "PairPtRatio";
226 case kPairDipAngle: return "PairDipAngle";
227 case kPairCosThetaStar: return "PairCosThetaStar";
228 case kPairQInv: return "PairQInv";
229 case kPairAngleToLeading: return "PairAngleToLeading";
230 case kEventLeadingPt: return "EventLeadingPt";
231 case kEventMult: return "EventMult";
232 case kEventMultESDCuts: return "EventMultESDCuts";
233 case kEventVz: return "EventVz";
234 default: return "Undefined";
235 }
32992791 236}
237
238//_____________________________________________________________________________
239void AliRsnValue::AssignTarget()
240{
241//
242// This method assigns the target to be expected by this object
243// in the computation, depending on its type chosen in the enum.
244//
2a1c7696 245
246 switch (fValueType) {
247 // track related values
248 case kTrackP:
249 case kTrackPt:
250 case kTrackEta:
11ed73f6 251 case kTrackY:
2a1c7696 252 SetTargetType(AliRsnTarget::kDaughter); // end of track-related values
253 break;
254 // pair related values
255 case kPairP1:
256 case kPairP2:
257 case kPairP1t:
258 case kPairP2t:
259 case kPairP1z:
260 case kPairP2z:
261 case kPairInvMass:
262 case kPairInvMassMC:
263 case kPairInvMassRes:
264 case kPairPt:
265 case kPairPz:
266 case kPairEta:
267 case kPairMt:
268 case kPairY:
269 case kPairPhi:
270 case kPairPhiMC:
271 case kPairPtRatio:
272 case kPairDipAngle:
273 case kPairCosThetaStar:
274 case kPairQInv:
275 case kPairAngleToLeading:
276 SetTargetType(AliRsnTarget::kMother); // end of pair-related values
277 break;
278 // event related values
279 case kEventLeadingPt:
280 case kEventMult:
281 case kEventMultESDCuts:
282 case kEventVz:
283 SetTargetType(AliRsnTarget::kEvent); // end of event-related values
284 break;
285 // undefined value
286 default:
287 SetTargetType(AliRsnTarget::kTargetTypes); // undefined targets
288 }
2dab9030 289}
290
291//_____________________________________________________________________________
32992791 292Bool_t AliRsnValue::Eval(TObject *object, Bool_t useMC)
b9bbd271 293{
294//
295// Evaluation of the required value.
296// Checks that the passed object is of the right type
32992791 297// and if this check is successful, computes the required value.
298// The output of the function tells if computing was successful,
b9bbd271 299// and the values must be taken with GetValue().
300//
301
2a1c7696 302 // cast the input to the allowed types
303 AliRsnDaughter *daughter = dynamic_cast<AliRsnDaughter*>(object);
304 AliRsnMother *mother = dynamic_cast<AliRsnMother*>(object);
305
306 // common variables
307 TLorentzVector pRec; // 4-momentum for single track or pair sum (reco)
308 TLorentzVector pSim; // 4-momentum for single track or pair sum (MC)
309 TLorentzVector pRec0; // 4-momentum of first daughter (reco)
310 TLorentzVector pSim0; // 4-momentum of first daughter (MC)
311 TLorentzVector pRec1; // 4-momentum of second daughter (reco)
312 TLorentzVector pSim1; // 4-momentum of second daughter (MC)
313
314 // check that the input object is the correct class type
315 switch (fTargetType) {
316 case AliRsnTarget::kDaughter:
317 if (daughter) {
318 pRec = daughter->Psim();
319 pSim = daughter->Prec();
320 } else {
321 AliError(Form("[%s] expected: AliRsnDaughter, passed: [%s]", GetName(), object->ClassName()));
322 return kFALSE;
323 }
324 break;
325 case AliRsnTarget::kMother:
326 if (mother) {
327 pRec = mother->Sum();
328 pSim = mother->SumMC();
329 pRec0 = mother->GetDaughter(0)->Prec();
330 pRec1 = mother->GetDaughter(1)->Prec();
331 pSim0 = mother->GetDaughter(0)->Psim();
332 pSim1 = mother->GetDaughter(1)->Psim();
333 } else {
334 AliError(Form("[%s] expected: AliRsnMother, passed: [%s]", GetName(), object->ClassName()));
335 return kFALSE;
336 }
337 break;
338 case AliRsnTarget::kEvent:
339 if (!AliRsnTarget::GetCurrentEvent()) {
340 AliError(Form("[%s] expected: AliRsnEvent, passed: [%s]", GetName(), object->ClassName()));
341 return kFALSE;
342 }
343 break;
344 default:
345 AliError(Form("[%s] Wrong type", GetName()));
346 return kFALSE;
347 }
348
349 // cast the support object to the types which could be needed
11ed73f6 350 AliESDtrackCuts *esdCuts = dynamic_cast<AliESDtrackCuts*>(fSupportObject);
351 AliRsnPairDef *pairDef = dynamic_cast<AliRsnPairDef*>(fSupportObject);
352 AliRsnDaughterDef *daughterDef = dynamic_cast<AliRsnDaughterDef*>(fSupportObject);
2a1c7696 353
354 // compute value depending on type
355 switch (fValueType) {
356 case kTrackP:
357 fComputedValue = useMC ? pSim.Mag() : pRec.Mag();
358 break;
359 case kTrackPt:
360 fComputedValue = useMC ? pSim.Perp() : pRec.Perp();
361 break;
362 case kTrackEta:
363 fComputedValue = useMC ? pSim.Eta() : pRec.Eta();
364 break;
11ed73f6 365 case kTrackY:
366 // for this computation, replace the computed mass with the default mass
367 // for doing this, an initialized daughterDef is required to get the mass
368 if (!daughterDef) {
369 AliError(Form("[%s] Required a correctly initialized DaughterDef to compute this value", GetName()));
370 fComputedValue = 1E+10;
371 return kFALSE;
372 } else {
373 pRec.SetXYZM(pRec.X(), pRec.Y(), pRec.Z(), daughterDef->GetMass());
374 pSim.SetXYZM(pSim.X(), pSim.Y(), pSim.Z(), daughterDef->GetMass());
375 fComputedValue = useMC ? pSim.Rapidity() : pRec.Rapidity();
376 }
377 break;
2a1c7696 378 case kPairP1:
379 fComputedValue = useMC ? pSim0.Mag() : pRec0.Mag();
380 break;
381 case kPairP2:
382 fComputedValue = useMC ? pSim1.Mag() : pRec1.Mag();
383 break;
384 case kPairP1t:
385 fComputedValue = useMC ? pSim0.Perp() : pRec0.Perp();
386 break;
387 case kPairP2t:
388 fComputedValue = useMC ? pSim1.Perp() : pRec1.Perp();
389 break;
390 case kPairP1z:
391 fComputedValue = useMC ? pSim0.Z() : pRec0.Z();
392 break;
393 case kPairP2z:
394 fComputedValue = useMC ? pSim1.Z() : pRec1.Z();
395 break;
396 case kPairInvMass:
397 fComputedValue = useMC ? pSim.M() : pRec.M();
398 break;
399 case kPairInvMassRes:
400 fComputedValue = (pSim.M() - pRec.M()) / pSim.M();
401 break;
402 case kPairPt:
403 fComputedValue = useMC ? pSim.Perp() : pRec.Perp();
404 break;
405 case kPairEta:
406 fComputedValue = useMC ? pSim.Eta() : pRec.Eta();
407 break;
408 case kPairMt:
409 // for this computation, replace the computed mass with the default mass
410 // for doing this, an initialized pairDef is required to get the mass
411 if (!pairDef) {
412 AliError(Form("[%s] Required a correctly initialized PairDef to compute this value", GetName()));
413 fComputedValue = 1E+10;
414 return kFALSE;
415 } else {
416 pRec.SetXYZM(pRec.X(), pRec.Y(), pRec.Z(), pairDef->GetMotherMass());
417 pSim.SetXYZM(pSim.X(), pSim.Y(), pSim.Z(), pairDef->GetMotherMass());
418 fComputedValue = useMC ? pSim.Mt() : pRec.Mt();
419 }
420 break;
421 case kPairY:
422 // for this computation, replace the computed mass with the default mass
423 // for doing this, an initialized pairDef is required to get the mass
424 if (!pairDef) {
425 AliError(Form("[%s] Required a correctly initialized PairDef to compute this value", GetName()));
426 fComputedValue = 1E+10;
427 return kFALSE;
428 } else {
429 pRec.SetXYZM(pRec.X(), pRec.Y(), pRec.Z(), pairDef->GetMotherMass());
430 pSim.SetXYZM(pSim.X(), pSim.Y(), pSim.Z(), pairDef->GetMotherMass());
431 fComputedValue = useMC ? pSim.Rapidity() : pRec.Rapidity();
432 }
433 break;
434 case kPairPhi:
435 fComputedValue = useMC ? pSim.Phi() : pRec.Phi();
436 break;
437 case kPairPtRatio:
438 if (useMC) {
439 fComputedValue = TMath::Abs(pSim0.Perp() - pSim1.Perp());
440 fComputedValue /= TMath::Abs(pSim0.Perp() + pSim1.Perp());
441 } else {
442 fComputedValue = TMath::Abs(pRec0.Perp() - pRec1.Perp());
443 fComputedValue /= TMath::Abs(pRec0.Perp() + pRec1.Perp());
444 }
445 break;
446 case kPairDipAngle:
447 fComputedValue = useMC ? pSim0.Angle(pSim1.Vect()) : pRec0.Angle(pRec1.Vect());
448 fComputedValue = TMath::Abs(TMath::Cos(fComputedValue));
449 break;
450 case kPairCosThetaStar:
451 fComputedValue = mother->CosThetaStar(useMC);
452 break;
453 case kPairQInv:
454 pSim0 -= pSim1;
455 pRec0 -= pRec1;
456 fComputedValue = useMC ? pSim0.M() : pRec0.M();
457 break;
458 case kPairAngleToLeading: {
459 AliRsnEvent *event = AliRsnTarget::GetCurrentEvent();
460 int ID1 = (mother->GetDaughter(0))->GetID();
461 int ID2 = (mother->GetDaughter(1))->GetID();
462 //int leadingID = event->SelectLeadingParticle(0);
463 Int_t leadingID = event->GetLeadingParticleID();
9c4aeffd 464 if (leadingID == ID1 || leadingID == ID2) {
465 fComputedValue = -99.;
466 return kFALSE;
467 }
2a1c7696 468 AliRsnDaughter leadingPart = event->GetDaughter(leadingID);
469 AliVParticle *ref = leadingPart.GetRef();
470 fComputedValue = ref->Phi() - mother->Sum().Phi();
471 //return angle w.r.t. leading particle in the range -pi/2, 3/2pi
2ace31c1 472 while (fComputedValue >= 1.5 * TMath::Pi()) fComputedValue -= 2 * TMath::Pi();
2a1c7696 473 while (fComputedValue < -0.5 * TMath::Pi()) fComputedValue += 2 * TMath::Pi();
474 //Printf("%g", fComputedValue);
45bb0283 475 }
0cba004a 476 break;
2a1c7696 477 case kEventMult:
478 fComputedValue = (Double_t)AliRsnTarget::GetCurrentEvent()->GetMultiplicity(0x0);
479 break;
480 case kEventMultESDCuts:
481 // this value requires an initialized ESDtrackCuts
482 if (!esdCuts) {
483 AliError(Form("[%s] Required a correctly initialized ESDtrackCuts to compute this value", GetName()));
484 fComputedValue = 1E+10;
485 return kFALSE;
486 }
487 fComputedValue = (Double_t)AliRsnTarget::GetCurrentEvent()->GetMultiplicity(esdCuts);
488 break;
489 case kEventLeadingPt: {
490 int leadingID = AliRsnTarget::GetCurrentEvent()->GetLeadingParticleID(); //fEvent->SelectLeadingParticle(0);
491 if (leadingID >= 0) {
492 AliRsnDaughter leadingPart = AliRsnTarget::GetCurrentEvent()->GetDaughter(leadingID);
493 AliVParticle *ref = leadingPart.GetRef();
494 fComputedValue = ref->Pt();
495 } else fComputedValue = 0;
2467e7c3 496 }
497 break;
2a1c7696 498 case kEventVz:
499 fComputedValue = AliRsnTarget::GetCurrentEvent()->GetRef()->GetPrimaryVertex()->GetZ();
500 break;
501 default:
502 AliError(Form("[%s] Invalid value type for this computation", GetName()));
503 return kFALSE;
504 }
505
506 return kTRUE;
b9bbd271 507}
c18b1218 508
509//_____________________________________________________________________________
32992791 510void AliRsnValue::Print(Option_t * /*option */) const
69fbb331 511{
512//
32992791 513// Print informations about this object
69fbb331 514//
515
2a1c7696 516 AliInfo("=== VALUE INFO =================================================");
517 AliInfo(Form(" Name : %s", GetName()));
518 AliInfo(Form(" Type : %s", GetValueTypeName()));
519 AliInfo(Form(" Current computed value: %f", fComputedValue));
520 Int_t i;
521 for (i = 0; i < fBinArray.GetSize(); i++) {
522 AliInfo(Form(" Bin limit #%d = %f", i, fBinArray[i]));
523 }
524 AliInfo(Form(" Support object : %s", (fSupportObject ? fSupportObject->ClassName() : " NO SUPPORT")));
525 AliInfo("=== END VALUE INFO =============================================");
c18b1218 526}