]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWG2/RESONANCES/AliRsnMonitorNtuple.cxx
Add new version of macros for RSN analysis
[u/mrichter/AliRoot.git] / PWG2 / RESONANCES / AliRsnMonitorNtuple.cxx
1 //
2 // *** Class AliRsnMonitorNtuple ***
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 "AliRsnMonitorNtuple.h"
27
28 ClassImp(AliRsnMonitorNtuple)
29
30 //_____________________________________________________________________________
31 AliRsnMonitorNtuple::AliRsnMonitorNtuple(const char *name, AliRsnDaughterDef *def) :
32    AliRsnMonitor(name, def),
33    fValues("AliRsnValue", 0),
34    fNtuple(0x0)
35 {
36 //
37 // Default constructor
38 //
39
40    AliDebug(AliLog::kDebug + 2, "<-");
41    AliDebug(AliLog::kDebug + 2, "->");
42 }
43
44 //_____________________________________________________________________________
45 AliRsnMonitorNtuple::AliRsnMonitorNtuple(const AliRsnMonitorNtuple& copy) :
46    AliRsnMonitor(copy),
47    fValues(copy.fValues),
48    fNtuple(copy.fNtuple)
49 {
50 //
51 // Default constructor
52 //
53
54    AliDebug(AliLog::kDebug + 2, "<-");
55    AliDebug(AliLog::kDebug + 2, "->");
56 }
57
58 //_____________________________________________________________________________
59 AliRsnMonitorNtuple& AliRsnMonitorNtuple::operator=(const AliRsnMonitorNtuple& copy)
60 {
61    AliRsnMonitor::operator=(copy);
62
63    Int_t i, n = copy.fValues.GetEntries();
64    for (i = 0; i < n; i++) {
65       AliRsnValue *fcn = (AliRsnValue*)copy.fValues[i];
66       if (fcn) AddValue(fcn);
67    }
68
69    fNtuple = copy.fNtuple;
70
71    return (*this);
72 }
73
74 //_____________________________________________________________________________
75 AliRsnMonitorNtuple::~AliRsnMonitorNtuple()
76 {
77 //
78 // Destructor
79 //
80
81    AliDebug(AliLog::kDebug + 2, "<-");
82    AliDebug(AliLog::kDebug + 2, "->");
83 }
84
85 //_____________________________________________________________________________
86 void AliRsnMonitorNtuple::Compute()
87 {
88 //
89 // Makes computations using the two passed daughter objects.
90 // Checks all cuts and then computes the corresponding pair object
91 // and then fill the list of required values using it.
92 //
93
94    AliDebug(AliLog::kDebug + 2, "<-");
95
96    // compute all values
97    Int_t        i, n = fValues.GetEntries();
98    TArrayF      values(n);
99    AliRsnValue *value = 0x0;
100    Bool_t       computeOK = kFALSE, globalOK = kTRUE;
101    for (i = 0; i < n; i++) {
102       values[i] = -1E10;
103       value = (AliRsnValue*)fValues[i];
104       switch (value->GetTargetType()) {
105          case AliRsnTarget::kDaughter:
106             computeOK = value->Eval(fDaughter);
107             break;
108          case AliRsnTarget::kEvent:
109             computeOK = value->Eval(fDaughter->GetOwnerEvent());
110             break;
111          default:
112             AliError(Form("Allowed targets are mothers and events; cannot use axis '%s' which has target '%s'", value->GetName(), value->GetTargetTypeName()));
113             computeOK = kFALSE;
114       }
115       if (computeOK) 
116          values[i] = ((Float_t)value->GetComputedValue());
117       else 
118          globalOK = kFALSE;
119    }
120
121    if (globalOK) fNtuple->Fill(values.GetArray());
122
123    AliDebug(AliLog::kDebug + 2, "->");
124 }
125
126 //_____________________________________________________________________________
127 void AliRsnMonitorNtuple::Init(const char *prefix, TList *list)
128 {
129 //
130 // Generates needed histograms, giving them a name based on
131 // the flags defined here, on the pair definition, and attaches
132 // a prefix to it, according to the argument.
133 //
134 // All generated histograms are stored into the output TList.
135 //
136
137    AliDebug(AliLog::kDebug + 2, "<-");
138
139    TString nameList("");
140
141    Int_t        i, n = fValues.GetEntries();
142    AliRsnValue *val = 0;
143    for (i = 0; i < n; i++) {
144       val = (AliRsnValue*)fValues.At(i);
145       nameList += val->GetName();
146       if (i < n - 1) nameList += ':';
147    }
148
149    if (fNtuple) delete fNtuple;
150    fNtuple = new TNtuple(Form("%sntp%s", prefix, GetName()), "", nameList.Data());
151    if (list) list->Add(fNtuple);
152
153    AliDebug(AliLog::kDebug + 2, "->");
154 }
155
156 //_____________________________________________________________________________
157 Bool_t AliRsnMonitorNtuple::AddValue(AliRsnValue *const val)
158 {
159 //
160 // Adds a new computing function.
161 //
162
163    RSNTARGET target = val->GetTargetType();
164    if (target != AliRsnTarget::kMother && target != AliRsnTarget::kEvent) {
165       AliError(Form("Allowed targets are mothers and events; cannot use axis '%s' which has target '%s'", val->GetName(), val->GetTargetTypeName()));
166       return kFALSE;
167    }
168
169    Int_t size = fValues.GetEntries();
170    new(fValues[size]) AliRsnValue(*val);
171
172    return kTRUE;
173 }