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