2 // Class AliRsnFunction
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)
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
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
16 // initialize the final output histogram and define how to process data.
19 // author: A. Pulvirenti (email: alberto.pulvirenti@ct.infn.it)
27 #include "AliRsnDaughter.h"
28 #include "AliRsnEvent.h"
29 #include "AliRsnPairDef.h"
30 #include "AliRsnMother.h"
31 #include "AliRsnValue.h"
33 #include "AliRsnFunction.h"
35 ClassImp(AliRsnFunction)
37 //________________________________________________________________________________________
38 AliRsnFunction::AliRsnFunction(Bool_t single, Bool_t useTH1) :
41 fAxisList("AliRsnValue", 0),
56 //________________________________________________________________________________________
57 AliRsnFunction::AliRsnFunction(const AliRsnFunction ©) :
59 fPairDef(copy.fPairDef),
60 fAxisList(copy.fAxisList),
63 fDaughter(copy.fDaughter),
64 fSingle(copy.fSingle),
65 fUseTH1(copy.fUseTH1),
75 //________________________________________________________________________________________
76 const AliRsnFunction& AliRsnFunction::operator=(const AliRsnFunction& copy)
79 // Assignment operator.
82 fPairDef = copy.fPairDef;
85 fDaughter = copy.fDaughter;
86 fSingle = copy.fSingle;
87 fUseTH1 = copy.fUseTH1;
93 if (fHSparse) delete fHSparse;
99 //________________________________________________________________________________________
100 const char* AliRsnFunction::GetName() const
103 // Defines the name of this object according to
104 // the function type and binning
109 TObjArrayIter next(&fAxisList);
110 AliRsnValue *axis = 0;
112 while ((axis = (AliRsnValue*)next())) {
113 if (name.Length() > 1) name += '_';
114 name += axis->GetName();
120 //________________________________________________________________________________________
121 Bool_t AliRsnFunction::AddAxis(AliRsnValue *const axis)
124 // Try to add a new axis to this function.
125 // The operation succeeds only if the related value object
126 // has a target compatible with the function type:
127 // -- 'single' functions, for tracks/events: AliRsnDaughter or AliRsnEvent
128 // -- 'not single' functions, for pairs/events : AliRsnMother or AliRsnEvent
129 // otherwise the axis is not added.
131 // If more than 3 axes are added, switch to THnSparseF output.
132 // NOTE: this can cause large files and high memory occupancy.
135 RSNTARGET target = axis->GetTargetType();
136 if (target == AliRsnTarget::kDaughter && !fSingle) {
137 AliError("An axis with 'AliRsnDaughter' target is not allowed in a non-single function");
140 if (target == AliRsnTarget::kMother && fSingle) {
141 AliError("An axis with 'AliRsnMother' target is not allowed in a single function");
145 Int_t size = fAxisList.GetEntries();
146 new(fAxisList[size]) AliRsnValue(*axis);
148 if (fAxisList.GetEntries() > 3) {
149 AliWarning("Adding more than 3 axes will produce a THnSparseD output.");
156 //________________________________________________________________________________________
157 TH1* AliRsnFunction::CreateHistogram(const char *histoName, const char *histoTitle)
160 // Creates and returns the histogram defined using
161 // arguments fo name and title, and the first histoDef for binning.
162 // Variable-sized histogram binning is always called, due to use of histoDef,
163 // even if the bins are equal, since they are defined in this class.
164 // Eventually present histoDef's in other slots of array (1, 2) are ignored.
166 // This version produces a THnSparseF.
169 fSize = fAxisList.GetEntries();
171 AliError("No axes defined");
173 } else if (fSize > 3) {
174 AliError("Too many axes defined for a TH1 object");
178 // retrieve binnings for main and secondary axes
179 AliRsnValue *fcnAxis;
181 for (Int_t i = 0; i < fSize; i++) {
182 fcnAxis = (AliRsnValue*)fAxisList.At(i);
184 AliError("Empty axis");
190 array[i] = fcnAxis->GetArray();
194 // create histogram depending on the number of axes
197 fH1 = new TH1F(histoName, histoTitle, array[0].GetSize() - 1, array[0].GetArray());
200 fH1 = new TH2F(histoName, histoTitle, array[0].GetSize() - 1, array[0].GetArray(), array[1].GetSize() - 1, array[1].GetArray());
203 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());
211 //________________________________________________________________________________________
212 THnSparseF* AliRsnFunction::CreateHistogramSparse(const char *histoName, const char *histoTitle)
215 // Creates and returns the histogram defined using
216 // arguments fo name and title, and the first histoDef for binning.
217 // Variable-sized histogram binning is always called, due to use of histoDef,
218 // even if the bins are equal, since they are defined in this class.
219 // Eventually present histoDef's in other slots of array (1, 2) are ignored.
221 // This version produces a THnSparseF.
224 fSize = fAxisList.GetEntries();
226 AliError("No axes defined");
230 // initialize the array of number of bins for each axis
231 // taking it from the stored values, while for the bins
232 // they are set as summied and defined later
234 Int_t *nbins = new Int_t[fSize];
235 AliRsnValue *fcnAxis = 0;
236 for (Int_t i = 0; i < fSize; i++) {
237 fcnAxis = (AliRsnValue*)fAxisList.At(i);
240 AliError("Empty axis");
243 nbins[i] = fcnAxis->GetArray().GetSize() - 1;
247 fHSparse = new THnSparseF(histoName, histoTitle, fSize, nbins, &dummyD, &dummyD);
250 // update the various axes using the definitions given in the array of axes here
251 for (Int_t i = 0; i < fSize; i++) {
252 fcnAxis = (AliRsnValue*)fAxisList.At(i);
254 AliError("Empty axis: doing unique bin betweeen -100000 and 100000");
257 fHSparse->SetBinEdges(i, fcnAxis->GetArray().GetArray());
266 //________________________________________________________________________________________
267 Bool_t AliRsnFunction::Fill()
270 // Fill function histogram with values computed from given input object.
273 AliDebug(AliLog::kDebug + 2, "->");
276 Double_t *values = new Double_t[fSize];
277 Bool_t computeOK = kFALSE;
279 AliRsnValue *fcnAxis = 0;
280 for (i = 0; i < fSize; i++) {
282 fcnAxis = (AliRsnValue*)fAxisList.At(i);
283 if (!fcnAxis) continue;
284 switch (fcnAxis->GetTargetType()) {
285 case AliRsnTarget::kMother:
287 fcnAxis->SetSupportObject(fPairDef);
288 computeOK = fcnAxis->Eval(fPair);
291 AliError(Form("Allowed targets are daughters and events; cannot use axis '%s' which has target '%s'", fcnAxis->GetName(), fcnAxis->GetTargetTypeName()));
295 case AliRsnTarget::kEvent:
296 computeOK = fcnAxis->Eval(fEvent);
298 case AliRsnTarget::kDaughter:
300 computeOK = fcnAxis->Eval(fDaughter);
303 AliError(Form("Allowed targets are daughters and events; cannot use axis '%s' which has target '%s'", fcnAxis->GetName(), fcnAxis->GetTargetTypeName()));
308 AliError(Form("Allowed targets are mothers and events; cannot use axis '%s' which has target '%s'", fcnAxis->GetName(), fcnAxis->GetTargetTypeName()));
311 if (computeOK) values[i] = ((Float_t)fcnAxis->GetComputedValue());
316 // check presence of output histogram
318 AliError("Required a TH1 which is not initialized");
323 // fill according to dimensions
326 TH1F *h1 = (TH1F*)fH1;
331 TH2F *h2 = (TH2F*)fH1;
332 h2->Fill(values[0], values[1]);
336 TH3F *h3 = (TH3F*)fH1;
337 h3->Fill(values[0], values[1], values[2]);
341 AliError(Form("Wrong size : %d", fSize));
346 // check presence of output histogram
348 AliError("Required a THnSparseF which is not initialized");
353 fHSparse->Fill(values);
358 AliDebug(AliLog::kDebug + 2, "->");