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 useTH1) :
41 fAxisList("AliRsnValue", 0),
54 //________________________________________________________________________________________
55 AliRsnFunction::AliRsnFunction(const AliRsnFunction ©) :
57 fPairDef(copy.fPairDef),
58 fAxisList(copy.fAxisList),
61 fUseTH1(copy.fUseTH1),
71 //________________________________________________________________________________________
72 const AliRsnFunction& AliRsnFunction::operator=(const AliRsnFunction& copy)
75 // Assignment operator.
78 fPairDef = copy.fPairDef;
81 fUseTH1 = copy.fUseTH1;
87 if (fHSparse) delete fHSparse;
93 //________________________________________________________________________________________
94 const char* AliRsnFunction::GetName() const
97 // Defines the name of this object according to
98 // the function type and binning
103 TObjArrayIter next(&fAxisList);
104 AliRsnValue *axis = 0;
106 while ((axis = (AliRsnValue*)next())) {
107 if (name.Length() > 1) name += '_';
108 name += axis->GetName();
114 //________________________________________________________________________________________
115 Bool_t AliRsnFunction::AddAxis(AliRsnValue *const axis)
118 // Try to add a new axis to this function.
119 // The operation succeeds only if the related value object
120 // has a target amon those allowed here (AliRsnMother, AliRsnEvent),
121 // otherwise the axis is not added.
123 // If more than 3 axes are added, switch to THnSparseF output.
124 // NOTE: this can cause large files and high memory occupancy.
127 RSNTARGET target = axis->GetTargetType();
128 if (target != AliRsnTarget::kMother && target != AliRsnTarget::kEvent) {
129 AliError(Form("Allowed targets are mothers and events; cannot use axis '%s' which has target '%s'", axis->GetName(), axis->GetTargetTypeName()));
133 Int_t size = fAxisList.GetEntries();
134 new(fAxisList[size]) AliRsnValue(*axis);
136 if (fAxisList.GetEntries() > 3) {
137 AliWarning("Adding more than 3 axes will produce a THnSparseD output.");
144 //________________________________________________________________________________________
145 TH1* AliRsnFunction::CreateHistogram(const char *histoName, const char *histoTitle)
148 // Creates and returns the histogram defined using
149 // arguments fo name and title, and the first histoDef for binning.
150 // Variable-sized histogram binning is always called, due to use of histoDef,
151 // even if the bins are equal, since they are defined in this class.
152 // Eventually present histoDef's in other slots of array (1, 2) are ignored.
154 // This version produces a THnSparseF.
157 fSize = fAxisList.GetEntries();
159 AliError("No axes defined");
161 } else if (fSize > 3) {
162 AliError("Too many axes defined for a TH1 object");
166 // retrieve binnings for main and secondary axes
167 AliRsnValue *fcnAxis;
169 for (Int_t i = 0; i < fSize; i++) {
170 fcnAxis = (AliRsnValue*)fAxisList.At(i);
172 AliError("Empty axis");
178 array[i] = fcnAxis->GetArray();
182 // create histogram depending on the number of axes
185 fH1 = new TH1F(histoName, histoTitle, array[0].GetSize() - 1, array[0].GetArray());
188 fH1 = new TH2F(histoName, histoTitle, array[0].GetSize() - 1, array[0].GetArray(), array[1].GetSize() - 1, array[1].GetArray());
191 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());
199 //________________________________________________________________________________________
200 THnSparseF* AliRsnFunction::CreateHistogramSparse(const char *histoName, const char *histoTitle)
203 // Creates and returns the histogram defined using
204 // arguments fo name and title, and the first histoDef for binning.
205 // Variable-sized histogram binning is always called, due to use of histoDef,
206 // even if the bins are equal, since they are defined in this class.
207 // Eventually present histoDef's in other slots of array (1, 2) are ignored.
209 // This version produces a THnSparseF.
212 fSize = fAxisList.GetEntries();
214 AliError("No axes defined");
218 // initialize the array of number of bins for each axis
219 // taking it from the stored values, while for the bins
220 // they are set as summied and defined later
222 Int_t *nbins = new Int_t[fSize];
223 AliRsnValue *fcnAxis = 0;
224 for (Int_t i = 0; i < fSize; i++) {
225 fcnAxis = (AliRsnValue*)fAxisList.At(i);
228 AliError("Empty axis");
231 nbins[i] = fcnAxis->GetArray().GetSize() - 1;
235 fHSparse = new THnSparseF(histoName, histoTitle, fSize, nbins, &dummyD, &dummyD);
238 // update the various axes using the definitions given in the array of axes here
239 for (Int_t i = 0; i < fSize; i++) {
240 fcnAxis = (AliRsnValue*)fAxisList.At(i);
242 AliError("Empty axis: doing unique bin betweeen -100000 and 100000");
245 fHSparse->SetBinEdges(i, fcnAxis->GetArray().GetArray());
254 //________________________________________________________________________________________
255 Bool_t AliRsnFunction::Fill()
258 // Fill function histogram with values computed from given input object.
261 AliDebug(AliLog::kDebug + 2, "->");
264 Double_t *values = new Double_t[fSize];
265 Bool_t computeOK = kFALSE;
267 AliRsnValue *fcnAxis = 0;
268 for (i = 0; i < fSize; i++) {
270 fcnAxis = (AliRsnValue*)fAxisList.At(i);
271 if (!fcnAxis) continue;
272 switch (fcnAxis->GetTargetType()) {
273 case AliRsnTarget::kMother:
274 fcnAxis->SetSupportObject(fPairDef);
275 computeOK = fcnAxis->Eval(fPair);
277 case AliRsnTarget::kEvent:
278 computeOK = fcnAxis->Eval(fEvent);
281 AliError(Form("Allowed targets are mothers and events; cannot use axis '%s' which has target '%s'", fcnAxis->GetName(), fcnAxis->GetTargetTypeName()));
284 if (computeOK) values[i] = ((Float_t)fcnAxis->GetComputedValue());
289 // check presence of output histogram
291 AliError("Required a TH1 which is not initialized");
296 // fill according to dimensions
299 TH1F *h1 = (TH1F*)fH1;
304 TH2F *h2 = (TH2F*)fH1;
305 h2->Fill(values[0], values[1]);
309 TH3F *h3 = (TH3F*)fH1;
310 h3->Fill(values[0], values[1], values[2]);
314 AliError(Form("Wrong size : %d", fSize));
319 // check presence of output histogram
321 AliError("Required a THnSparseF which is not initialized");
326 fHSparse->Fill(values);
331 AliDebug(AliLog::kDebug + 2, "->");