]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PWG2/RESONANCES/AliRsnFunction.cxx
In AliMUONGeometryModuleTransformer, AliMUONVGeometryBuilder:
[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
cc4a35d5 213 // initialize the array of number of bins for each axis
214 // taking it from the stored values, while for the bins
215 // they are set as summied and defined later
ceb7ce00 216 Double_t dummyD;
217 Int_t *nbins = new Int_t[fSize];
218 AliRsnValue *fcnAxis = 0;
cc4a35d5 219 for (Int_t i = 0; i < fSize; i++)
220 {
ceb7ce00 221 fcnAxis = (AliRsnValue*)fAxisList.At(i);
cc4a35d5 222 if (!fcnAxis)
223 {
224 nbins[i] = 1;
225 AliError("Empty axis");
226 continue;
227 }
ceb7ce00 228 nbins[i] = fcnAxis->GetArray().GetSize() - 1;
cc4a35d5 229 }
b2028424 230
b2b08ca2 231 // create histogram
cc4a35d5 232 fHSparse = new THnSparseF(histoName, histoTitle, fSize, nbins, &dummyD, &dummyD);
b2b08ca2 233 fHSparse->Sumw2();
234
235 // update the various axes using the definitions given in the array of axes here
b2b08ca2 236 for (Int_t i = 0; i < fSize; i++)
237 {
2dab9030 238 fcnAxis = (AliRsnValue*)fAxisList.At(i);
b2028424 239 if (!fcnAxis) {
b2b08ca2 240 AliError("Empty axis: doing unique bin betweeen -100000 and 100000");
b2028424 241 continue;
5eb970a4 242 }
2467e7c3 243 fHSparse->SetBinEdges(i, fcnAxis->GetArray().GetArray());
eb079724 244 }
245
eb079724 246 return fHSparse;
5eb970a4 247}
248
eb079724 249
5eb970a4 250//________________________________________________________________________________________
251Bool_t AliRsnFunction::Fill()
252{
253//
254// Fill function histogram with values computed from given input object.
255//
b2028424 256
5eb970a4 257 AliDebug(AliLog::kDebug +2,"->");
258
eb079724 259 Int_t i;
260 Double_t *values = new Double_t[fSize];
b2028424 261
2dab9030 262 AliRsnValue *fcnAxis = 0;
eb079724 263 for (i = 0; i < fSize; i++) {
2dab9030 264 fcnAxis = (AliRsnValue*)fAxisList.At(i);
b2028424 265 if (!fcnAxis) {
266 values[i] = 0.0;
267 continue;
268 }
cf4668f7 269 if (fcnAxis->Eval(fPair, fPairDef, fEvent)) values[i] = (Double_t)((Float_t)fcnAxis->GetValue());
5eb970a4 270 }
eb079724 271
272 // fill histogram
273 if (fUseTH1)
274 {
275 // check presence of output histogram
276 if (!fH1) {
277 AliError("Required a TH1 whish is not initialized");
278 return kFALSE;
279 }
280
281 // fill according to dimensions
282 switch (fSize)
283 {
284 case 1:
285 {
0d73200d 286 TH1F *h1 = (TH1F*)fH1;
eb079724 287 h1->Fill(values[0]);
288 }
289 break;
290 case 2:
291 {
0d73200d 292 TH2F *h2 = (TH2F*)fH1;
eb079724 293 h2->Fill(values[0], values[1]);
294 }
295 break;
296 case 3:
297 {
0d73200d 298 TH3F *h3 = (TH3F*)fH1;
eb079724 299 h3->Fill(values[0], values[1], values[2]);
300 }
301 break;
302 default:
303 AliError(Form("Wrong size : %d", fSize));
304 return kFALSE;
305 }
306 }
307 else
308 {
309 // check presence of output histogram
310 if (!fHSparse) {
0d73200d 311 AliError("Required a THnSparseF which is not initialized");
eb079724 312 return kFALSE;
313 }
314
315 fHSparse->Fill(values);
5eb970a4 316 }
eb079724 317
318 delete [] values;
e0baff8c 319
5eb970a4 320 AliDebug(AliLog::kDebug +2,"->");
321 return kTRUE;
13f28255 322}