]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWG2/RESONANCES/AliRsnPairNtuple.cxx
Add new version of macros for RSN analysis
[u/mrichter/AliRoot.git] / PWG2 / RESONANCES / AliRsnPairNtuple.cxx
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"
24 #include "AliRsnValue.h"
25
26 #include "AliRsnPairNtuple.h"
27
28 ClassImp(AliRsnPairNtuple)
29
30 //_____________________________________________________________________________
31 AliRsnPairNtuple::AliRsnPairNtuple(const char *name, AliRsnPairDef *def) :
32    AliRsnPair(name, def),
33    fValues("AliRsnValue", 0),
34    fNtuple(0x0)
35 {
36 //
37 // Default constructor
38 //
39 }
40
41 //_____________________________________________________________________________
42 AliRsnPairNtuple::AliRsnPairNtuple(const AliRsnPairNtuple& copy) :
43    AliRsnPair(copy),
44    fValues(copy.fValues),
45    fNtuple(copy.fNtuple)
46 {
47 //
48 // Default constructor
49 //
50 }
51
52 //_____________________________________________________________________________
53 AliRsnPairNtuple& AliRsnPairNtuple::operator=(const AliRsnPairNtuple& copy)
54 {
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);
66 }
67
68 //_____________________________________________________________________________
69 AliRsnPairNtuple::~AliRsnPairNtuple()
70 {
71 //
72 // Destructor
73 //
74 }
75
76 //_____________________________________________________________________________
77 void 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
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(fMother.GetRefEvent());
102             break;
103          default:
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, "->");
112 }
113
114 //_____________________________________________________________________________
115 void 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
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);
138 }
139
140 //_____________________________________________________________________________
141 Bool_t AliRsnPairNtuple::AddValue(AliRsnValue* const val)
142 {
143 //
144 // Adds a new computing function.
145 //
146
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();
154    new (fValues[size]) AliRsnValue(*val);
155
156    return kTRUE;
157 }