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()))
108 if (name.Length() > 1) name += '_';
109 name += axis->GetName();
115 //________________________________________________________________________________________
116 Bool_t AliRsnFunction::AddAxis(AliRsnValue *const axis)
119 // Try to add a new axis to this function.
120 // The operation succeeds only if the related value object
121 // has a target amon those allowed here (AliRsnMother, AliRsnEvent),
122 // otherwise the axis is not added.
124 // If more than 3 axes are added, switch to THnSparseF output.
125 // NOTE: this can cause large files and high memory occupancy.
128 RSNTARGET target = axis->GetTargetType();
129 if (target != AliRsnTarget::kMother && target != AliRsnTarget::kEvent)
131 AliError(Form("Allowed targets are mothers and events; cannot use axis '%s' which has target '%s'", axis->GetName(), axis->GetTargetTypeName()));
135 Int_t size = fAxisList.GetEntries();
136 new (fAxisList[size]) AliRsnValue(*axis);
138 if (fAxisList.GetEntries() > 3)
140 AliWarning("Adding more than 3 axes will produce a THnSparseD output.");
147 //________________________________________________________________________________________
148 TH1* AliRsnFunction::CreateHistogram(const char *histoName, const char *histoTitle)
151 // Creates and returns the histogram defined using
152 // arguments fo name and title, and the first histoDef for binning.
153 // Variable-sized histogram binning is always called, due to use of histoDef,
154 // even if the bins are equal, since they are defined in this class.
155 // Eventually present histoDef's in other slots of array (1, 2) are ignored.
157 // This version produces a THnSparseF.
160 fSize = fAxisList.GetEntries();
163 AliError("No axes defined");
168 AliError("Too many axes defined for a TH1 object");
172 // retrieve binnings for main and secondary axes
173 AliRsnValue *fcnAxis;
175 for (Int_t i = 0; i < fSize; i++)
177 fcnAxis = (AliRsnValue*)fAxisList.At(i);
180 AliError("Empty axis");
188 array[i] = fcnAxis->GetArray();
192 // create histogram depending on the number of axes
196 fH1 = new TH1F(histoName, histoTitle, array[0].GetSize() - 1, array[0].GetArray());
199 fH1 = new TH2F(histoName, histoTitle, array[0].GetSize() - 1, array[0].GetArray(), array[1].GetSize() - 1, array[1].GetArray());
202 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());
210 //________________________________________________________________________________________
211 THnSparseF* AliRsnFunction::CreateHistogramSparse(const char *histoName, const char *histoTitle)
214 // Creates and returns the histogram defined using
215 // arguments fo name and title, and the first histoDef for binning.
216 // Variable-sized histogram binning is always called, due to use of histoDef,
217 // even if the bins are equal, since they are defined in this class.
218 // Eventually present histoDef's in other slots of array (1, 2) are ignored.
220 // This version produces a THnSparseF.
223 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++)
238 fcnAxis = (AliRsnValue*)fAxisList.At(i);
242 AliError("Empty axis");
245 nbins[i] = fcnAxis->GetArray().GetSize() - 1;
249 fHSparse = new THnSparseF(histoName, histoTitle, fSize, nbins, &dummyD, &dummyD);
252 // update the various axes using the definitions given in the array of axes here
253 for (Int_t i = 0; i < fSize; i++)
255 fcnAxis = (AliRsnValue*)fAxisList.At(i);
257 AliError("Empty axis: doing unique bin betweeen -100000 and 100000");
260 fHSparse->SetBinEdges(i, fcnAxis->GetArray().GetArray());
269 //________________________________________________________________________________________
270 Bool_t AliRsnFunction::Fill()
273 // Fill function histogram with values computed from given input object.
276 AliDebug(AliLog::kDebug +2,"->");
279 Double_t *values = new Double_t[fSize];
280 Bool_t computeOK = kFALSE;
282 AliRsnValue *fcnAxis = 0;
283 for (i = 0; i < fSize; i++)
286 fcnAxis = (AliRsnValue*)fAxisList.At(i);
287 if (!fcnAxis) continue;
288 switch (fcnAxis->GetTargetType())
290 case AliRsnTarget::kMother:
291 fcnAxis->SetSupportObject(fPairDef);
292 computeOK = fcnAxis->Eval(fPair);
294 case AliRsnTarget::kEvent:
295 computeOK = fcnAxis->Eval(fEvent);
298 AliError(Form("Allowed targets are mothers and events; cannot use axis '%s' which has target '%s'", fcnAxis->GetName(), fcnAxis->GetTargetTypeName()));
301 if (computeOK) values[i] = ((Float_t)fcnAxis->GetComputedValue());
307 // check presence of output histogram
310 AliError("Required a TH1 which is not initialized");
315 // fill according to dimensions
320 TH1F *h1 = (TH1F*)fH1;
326 TH2F *h2 = (TH2F*)fH1;
327 h2->Fill(values[0], values[1]);
332 TH3F *h3 = (TH3F*)fH1;
333 h3->Fill(values[0], values[1], values[2]);
337 AliError(Form("Wrong size : %d", fSize));
344 // check presence of output histogram
347 AliError("Required a THnSparseF which is not initialized");
352 fHSparse->Fill(values);
357 AliDebug(AliLog::kDebug +2,"->");