Improved functionality of AliRsnDaughterDef::MatchesDaughter()
[u/mrichter/AliRoot.git] / PWG2 / RESONANCES / AliRsnPairNtuple.cxx
CommitLineData
2dab9030 1//
2// *** Class AliRsnPairNtuple ***
3//
4// "Core" method for defining the work on a pari of particles.
5// For one analysis, one must setup one of this for each pair he wants to analyze,
6// adding to it all analysis which he desires to do.
7// Here he defines the cuts, and the particle types and charges, and can add
8// functions which do different operations on the same pair, and some binning
9// with respect to some kinematic variables (eta, momentum)
10//
11// authors: A. Pulvirenti (email: alberto.pulvirenti@ct.infn.it)
12// M. Vala (email: martin.vala@cern.ch)
13//
14
15#include <TList.h>
16#include <TNtuple.h>
17
18#include "AliLog.h"
19
20#include "AliRsnMother.h"
21#include "AliRsnEvent.h"
22#include "AliRsnFunction.h"
23#include "AliRsnCutSet.h"
2dab9030 24#include "AliRsnValue.h"
25
26#include "AliRsnPairNtuple.h"
27
28ClassImp(AliRsnPairNtuple)
29
30//_____________________________________________________________________________
31AliRsnPairNtuple::AliRsnPairNtuple(const char *name, AliRsnPairDef *def) :
2a1c7696 32 AliRsnPair(name, def),
33 fValues("AliRsnValue", 0),
34 fNtuple(0x0)
2dab9030 35{
36//
37// Default constructor
38//
2dab9030 39}
40
41//_____________________________________________________________________________
42AliRsnPairNtuple::AliRsnPairNtuple(const AliRsnPairNtuple& copy) :
2a1c7696 43 AliRsnPair(copy),
44 fValues(copy.fValues),
45 fNtuple(copy.fNtuple)
2dab9030 46{
47//
48// Default constructor
49//
2dab9030 50}
51
52//_____________________________________________________________________________
53AliRsnPairNtuple& AliRsnPairNtuple::operator=(const AliRsnPairNtuple& copy)
54{
2a1c7696 55 AliRsnPair::operator=(copy);
56
57 Int_t i, n = copy.fValues.GetEntries();
58 for (i = 0; i < n; i++) {
59 AliRsnValue *fcn = (AliRsnValue*)copy.fValues[i];
60 if (fcn) AddValue(fcn);
61 }
62
63 fNtuple = copy.fNtuple;
64
65 return (*this);
2dab9030 66}
67
68//_____________________________________________________________________________
69AliRsnPairNtuple::~AliRsnPairNtuple()
70{
71//
72// Destructor
73//
2dab9030 74}
75
76//_____________________________________________________________________________
77void AliRsnPairNtuple::Compute()
78{
79//
80// Makes computations using the two passed daughter objects.
81// Checks all cuts and then computes the corresponding pair object
82// and then fill the list of required values using it.
83//
84
2a1c7696 85 AliDebug(AliLog::kDebug + 2, "<-");
86
87 // compute all values
88 Int_t i, n = fValues.GetEntries();
89 TArrayF values(n);
90 AliRsnValue *value = 0x0;
91 Bool_t computeOK = kFALSE;
92 for (i = 0; i < n; i++) {
93 values[i] = -1E10;
94 value = (AliRsnValue*)fValues[i];
95 switch (value->GetTargetType()) {
96 case AliRsnTarget::kMother:
97 value->SetSupportObject(fPairDef);
98 computeOK = value->Eval(&fMother);
99 break;
100 case AliRsnTarget::kEvent:
101 computeOK = value->Eval(AliRsnTarget::GetCurrentEvent());
102 break;
103 default:
2a1c7696 104 computeOK = kFALSE;
105 }
106 if (computeOK) values[i] = ((Float_t)value->GetComputedValue());
107 }
108
109 fNtuple->Fill(values.GetArray());
110
111 AliDebug(AliLog::kDebug + 2, "->");
2dab9030 112}
113
114//_____________________________________________________________________________
115void AliRsnPairNtuple::Init(const char *prefix, TList *list)
116{
117//
118// Generates needed histograms, giving them a name based on
119// the flags defined here, on the pair definition, and attaches
120// a prefix to it, according to the argument.
121//
122// All generated histograms are stored into the output TList.
123//
124
2a1c7696 125 TString nameList("");
126
127 Int_t i, n = fValues.GetEntries();
128 AliRsnValue *val = 0;
129 for (i = 0; i < n; i++) {
130 val = (AliRsnValue*)fValues.At(i);
131 nameList += val->GetName();
132 if (i < n - 1) nameList += ':';
133 }
134
135 if (fNtuple) delete fNtuple;
136 fNtuple = new TNtuple(Form("%sntp%s", prefix, GetName()), "", nameList.Data());
137 if (list) list->Add(fNtuple);
2dab9030 138}
139
140//_____________________________________________________________________________
11ed73f6 141Bool_t AliRsnPairNtuple::AddValue(AliRsnValue* const val)
2dab9030 142{
143//
32992791 144// Adds a new computing function.
2dab9030 145//
146
2a1c7696 147 RSNTARGET target = val->GetTargetType();
148 if (target != AliRsnTarget::kMother && target != AliRsnTarget::kEvent) {
149 AliError(Form("Allowed targets are mothers and events; cannot use axis '%s' which has target '%s'", val->GetName(), val->GetTargetTypeName()));
150 return kFALSE;
151 }
152
153 Int_t size = fValues.GetEntries();
11ed73f6 154 new (fValues[size]) AliRsnValue(*val);
2a1c7696 155
156 return kTRUE;
2dab9030 157}