]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PWG2/RESONANCES/AliRsnFunction.cxx
fixed warnings
[u/mrichter/AliRoot.git] / PWG2 / RESONANCES / AliRsnFunction.cxx
CommitLineData
13f28255 1//
2// Class AliRsnFunction
3//
4// This class defines a base classe to implement a function
5// which uses the internal RSN package event format (AliRsnEvent).
6// It contains some default flags which turn out to be useful:
7// - a flag to select only the "true" pairs (tracks from same resonance)
8// - a flag to know if the computation is done over two events (mixing)
9//
10// Any kind of analysis object should be implemented as inheriting from this
11// because the AliRsnAnalyzer which executes the analysis will accept a collection
12// of such objects, in order to have a unique format of processing method
13//
e0baff8c 14// The user who implements a kind of computation type should inherit from
15// this class and override the virtual functions defined in it, which
13f28255 16// initialize the final output histogram and define how to process data.
17//
18//
19// author: A. Pulvirenti (email: alberto.pulvirenti@ct.infn.it)
20//
21
13f28255 22#include <TString.h>
b2b08ca2 23#include <TAxis.h>
13f28255 24
25#include "AliLog.h"
26
13f28255 27#include "AliRsnDaughter.h"
28#include "AliRsnEvent.h"
29#include "AliRsnPairDef.h"
2dab9030 30#include "AliRsnMother.h"
31#include "AliRsnValue.h"
13f28255 32
33#include "AliRsnFunction.h"
34
35ClassImp(AliRsnFunction)
36
37//________________________________________________________________________________________
eb079724 38AliRsnFunction::AliRsnFunction(Bool_t useTH1) :
2e521c29 39 TObject(),
4fbb2459 40 fPairDef(0x0),
2dab9030 41 fAxisList("AliRsnValue", 0),
4fbb2459 42 fPair(0x0),
43 fEvent(0x0),
eb079724 44 fUseTH1(useTH1),
45 fSize(0),
46 fH1(0x0),
47 fHSparse(0x0)
13f28255 48{
5eb970a4 49//
b2028424 50// Constructor.
5eb970a4 51//
8a22fe6f 52}
13f28255 53
54//________________________________________________________________________________________
5eb970a4 55AliRsnFunction::AliRsnFunction(const AliRsnFunction &copy) :
2e521c29 56 TObject(copy),
4fbb2459 57 fPairDef(copy.fPairDef),
58 fAxisList(copy.fAxisList),
4fbb2459 59 fPair(copy.fPair),
60 fEvent(copy.fEvent),
eb079724 61 fUseTH1(copy.fUseTH1),
62 fSize(copy.fSize),
63 fH1(0x0),
64 fHSparse(0x0)
13f28255 65{
5eb970a4 66//
67// Copy constructor.
68//
13f28255 69}
70
71//________________________________________________________________________________________
5eb970a4 72const AliRsnFunction& AliRsnFunction::operator=(const AliRsnFunction& copy)
13f28255 73{
5eb970a4 74//
75// Assignment operator.
76//
77
2e521c29 78 //SetName(copy.GetName());
79 //SetTitle(copy.GetTitle());
5eb970a4 80
5eb970a4 81 fPairDef = copy.fPairDef;
5eb970a4 82 fPair = copy.fPair;
83 fEvent = copy.fEvent;
eb079724 84 fUseTH1 = copy.fUseTH1;
85 fSize = copy.fSize;
5eb970a4 86
eb079724 87 if (fH1) delete fH1;
88 fH1 = 0x0;
89
90 if (fHSparse) delete fHSparse;
91 fHSparse = 0x0;
5eb970a4 92
5eb970a4 93 return (*this);
13f28255 94}
95
96//________________________________________________________________________________________
b2028424 97const char* AliRsnFunction::GetName() const
13f28255 98{
5eb970a4 99//
100// Defines the name of this object according to
101// the function type and binning
102//
13f28255 103
b2028424 104 TString name("");
e0baff8c 105
b2028424 106 TObjArrayIter next(&fAxisList);
2dab9030 107 AliRsnValue *axis = 0;
13f28255 108
2dab9030 109 while ((axis = (AliRsnValue*)next())) {
b2028424 110 if (name.Length() > 1) name += '_';
111 name += axis->GetName();
13f28255 112 }
13f28255 113
b2028424 114 return name.Data();
5eb970a4 115}
116
b2028424 117//________________________________________________________________________________________
2dab9030 118void AliRsnFunction::AddAxis(AliRsnValue *const axis)
5eb970a4 119{
2dab9030 120 AliDebug(AliLog::kDebug+2,"<-");
b2028424 121 Int_t size = fAxisList.GetEntries();
2dab9030 122 new(fAxisList[size]) AliRsnValue(*axis);
123 AliDebug(AliLog::kDebug+2,"->");
124
125 if (fAxisList.GetEntries() > 3)
eb079724 126 {
127 AliWarning("A TH1-type output cannot add more than 3 axes: switching to THnSparse -- THIS COULD CAUSE VERY LARGE FILES!!!");
128 fUseTH1 = kFALSE;
129 }
13f28255 130}
131
132//________________________________________________________________________________________
eb079724 133TH1* AliRsnFunction::CreateHistogram(const char *histoName, const char *histoTitle)
13f28255 134{
5eb970a4 135//
136// Creates and returns the histogram defined using
137// arguments fo name and title, and the first histoDef for binning.
138// Variable-sized histogram binning is always called, due to use of histoDef,
139// even if the bins are equal, since they are defined in this class.
140// Eventually present histoDef's in other slots of array (1, 2) are ignored.
eb079724 141//
0d73200d 142// This version produces a THnSparseF.
5eb970a4 143//
13f28255 144
eb079724 145 fSize = fAxisList.GetEntries();
146 if (!fSize) {
147 AliError("No axes defined");
148 return 0x0;
149 }
150 else if (fSize < 1 || fSize > 3)
151 {
152 AliError("Too few or too many axes defined");
153 return 0x0;
154 }
155
eb079724 156 // retrieve binnings for main and secondary axes
b2b08ca2 157 AliRsnValue *fcnAxis;
158 TArrayD array[3];
159 for (Int_t i = 0; i < fSize; i++)
160 {
2dab9030 161 fcnAxis = (AliRsnValue*)fAxisList.At(i);
b2b08ca2 162 if (!fcnAxis)
163 {
eb079724 164 AliError("Empty axis");
b2b08ca2 165 array[i].Set(2);
166 array[i][0] = -1E5;
167 array[i][1] = -1E5;
eb079724 168 continue;
169 }
b2b08ca2 170 else
171 {
172 array[i] = fcnAxis->GetArray();
173 }
eb079724 174 }
175
176 // create histogram depending on the number of axes
177 switch (fSize)
178 {
179 case 1:
b2b08ca2 180 fH1 = new TH1F(histoName, histoTitle, array[0].GetSize() - 1, array[0].GetArray());
eb079724 181 break;
182 case 2:
b2b08ca2 183 fH1 = new TH2F(histoName, histoTitle, array[0].GetSize() - 1, array[0].GetArray(), array[1].GetSize() - 1, array[1].GetArray());
eb079724 184 break;
185 case 3:
b2b08ca2 186 fH1 = new TH3F(histoName, histoTitle, array[0].GetSize() - 1, array[0].GetArray(), array[1].GetSize() - 1, array[1].GetArray(), array[2].GetSize() - 1, array[2].GetArray());
eb079724 187 break;
188 }
189 fH1->Sumw2();
190
191 return fH1;
192}
193
194//________________________________________________________________________________________
0d73200d 195THnSparseF* AliRsnFunction::CreateHistogramSparse(const char *histoName, const char *histoTitle)
eb079724 196{
197//
198// Creates and returns the histogram defined using
199// arguments fo name and title, and the first histoDef for binning.
200// Variable-sized histogram binning is always called, due to use of histoDef,
201// even if the bins are equal, since they are defined in this class.
202// Eventually present histoDef's in other slots of array (1, 2) are ignored.
203//
0d73200d 204// This version produces a THnSparseF.
eb079724 205//
206
207 fSize = fAxisList.GetEntries();
208 if (!fSize) {
b2028424 209 AliError("No axes defined");
210 return 0x0;
211 }
b2b08ca2 212
213 // create dummy variables to initialize the histogram
214 Int_t dummyI;
215 Double_t dummyD;
b2028424 216
b2b08ca2 217 // create histogram
218 fHSparse = new THnSparseF(histoName, histoTitle, fSize, &dummyI, &dummyD, &dummyD);
219 fHSparse->Sumw2();
220
221 // update the various axes using the definitions given in the array of axes here
2dab9030 222 AliRsnValue *fcnAxis = 0;
b2b08ca2 223 for (Int_t i = 0; i < fSize; i++)
224 {
2dab9030 225 fcnAxis = (AliRsnValue*)fAxisList.At(i);
b2028424 226 if (!fcnAxis) {
b2b08ca2 227 AliError("Empty axis: doing unique bin betweeen -100000 and 100000");
b2028424 228 continue;
5eb970a4 229 }
2467e7c3 230 fHSparse->SetBinEdges(i, fcnAxis->GetArray().GetArray());
eb079724 231 }
232
eb079724 233 return fHSparse;
5eb970a4 234}
235
eb079724 236
5eb970a4 237//________________________________________________________________________________________
238Bool_t AliRsnFunction::Fill()
239{
240//
241// Fill function histogram with values computed from given input object.
242//
b2028424 243
5eb970a4 244 AliDebug(AliLog::kDebug +2,"->");
245
eb079724 246 Int_t i;
247 Double_t *values = new Double_t[fSize];
b2028424 248
2dab9030 249 AliRsnValue *fcnAxis = 0;
eb079724 250 for (i = 0; i < fSize; i++) {
2dab9030 251 fcnAxis = (AliRsnValue*)fAxisList.At(i);
b2028424 252 if (!fcnAxis) {
253 values[i] = 0.0;
254 continue;
255 }
cf4668f7 256 if (fcnAxis->Eval(fPair, fPairDef, fEvent)) values[i] = (Double_t)((Float_t)fcnAxis->GetValue());
5eb970a4 257 }
eb079724 258
259 // fill histogram
260 if (fUseTH1)
261 {
262 // check presence of output histogram
263 if (!fH1) {
264 AliError("Required a TH1 whish is not initialized");
265 return kFALSE;
266 }
267
268 // fill according to dimensions
269 switch (fSize)
270 {
271 case 1:
272 {
0d73200d 273 TH1F *h1 = (TH1F*)fH1;
eb079724 274 h1->Fill(values[0]);
275 }
276 break;
277 case 2:
278 {
0d73200d 279 TH2F *h2 = (TH2F*)fH1;
eb079724 280 h2->Fill(values[0], values[1]);
281 }
282 break;
283 case 3:
284 {
0d73200d 285 TH3F *h3 = (TH3F*)fH1;
eb079724 286 h3->Fill(values[0], values[1], values[2]);
287 }
288 break;
289 default:
290 AliError(Form("Wrong size : %d", fSize));
291 return kFALSE;
292 }
293 }
294 else
295 {
296 // check presence of output histogram
297 if (!fHSparse) {
0d73200d 298 AliError("Required a THnSparseF which is not initialized");
eb079724 299 return kFALSE;
300 }
301
302 fHSparse->Fill(values);
5eb970a4 303 }
eb079724 304
305 delete [] values;
e0baff8c 306
5eb970a4 307 AliDebug(AliLog::kDebug +2,"->");
308 return kTRUE;
13f28255 309}