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 //SetName(copy.GetName());
79 //SetTitle(copy.GetTitle());
81 fPairDef = copy.fPairDef;
84 fUseTH1 = copy.fUseTH1;
90 if (fHSparse) delete fHSparse;
96 //________________________________________________________________________________________
97 const char* AliRsnFunction::GetName() const
100 // Defines the name of this object according to
101 // the function type and binning
106 TObjArrayIter next(&fAxisList);
107 AliRsnValue *axis = 0;
109 while ((axis = (AliRsnValue*)next())) {
110 if (name.Length() > 1) name += '_';
111 name += axis->GetName();
117 //________________________________________________________________________________________
118 void AliRsnFunction::AddAxis(AliRsnValue *const axis)
120 AliDebug(AliLog::kDebug+2,"<-");
121 Int_t size = fAxisList.GetEntries();
122 new(fAxisList[size]) AliRsnValue(*axis);
123 AliDebug(AliLog::kDebug+2,"->");
125 if (fAxisList.GetEntries() > 3)
127 AliWarning("A TH1-type output cannot add more than 3 axes: switching to THnSparse -- THIS COULD CAUSE VERY LARGE FILES!!!");
132 //________________________________________________________________________________________
133 TH1* AliRsnFunction::CreateHistogram(const char *histoName, const char *histoTitle)
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.
142 // This version produces a THnSparseF.
145 fSize = fAxisList.GetEntries();
147 AliError("No axes defined");
150 else if (fSize < 1 || fSize > 3)
152 AliError("Too few or too many axes defined");
156 // retrieve binnings for main and secondary axes
157 AliRsnValue *fcnAxis;
159 for (Int_t i = 0; i < fSize; i++)
161 fcnAxis = (AliRsnValue*)fAxisList.At(i);
164 AliError("Empty axis");
172 array[i] = fcnAxis->GetArray();
176 // create histogram depending on the number of axes
180 fH1 = new TH1F(histoName, histoTitle, array[0].GetSize() - 1, array[0].GetArray());
183 fH1 = new TH2F(histoName, histoTitle, array[0].GetSize() - 1, array[0].GetArray(), array[1].GetSize() - 1, array[1].GetArray());
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());
194 //________________________________________________________________________________________
195 THnSparseF* AliRsnFunction::CreateHistogramSparse(const char *histoName, const char *histoTitle)
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.
204 // This version produces a THnSparseF.
207 fSize = fAxisList.GetEntries();
209 AliError("No axes defined");
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
217 Int_t *nbins = new Int_t[fSize];
218 AliRsnValue *fcnAxis = 0;
219 for (Int_t i = 0; i < fSize; i++)
221 fcnAxis = (AliRsnValue*)fAxisList.At(i);
225 AliError("Empty axis");
228 nbins[i] = fcnAxis->GetArray().GetSize() - 1;
232 fHSparse = new THnSparseF(histoName, histoTitle, fSize, nbins, &dummyD, &dummyD);
235 // update the various axes using the definitions given in the array of axes here
236 for (Int_t i = 0; i < fSize; i++)
238 fcnAxis = (AliRsnValue*)fAxisList.At(i);
240 AliError("Empty axis: doing unique bin betweeen -100000 and 100000");
243 fHSparse->SetBinEdges(i, fcnAxis->GetArray().GetArray());
252 //________________________________________________________________________________________
253 Bool_t AliRsnFunction::Fill()
256 // Fill function histogram with values computed from given input object.
259 AliDebug(AliLog::kDebug +2,"->");
262 Double_t *values = new Double_t[fSize];
264 AliRsnValue *fcnAxis = 0;
265 for (i = 0; i < fSize; i++) {
266 fcnAxis = (AliRsnValue*)fAxisList.At(i);
272 if (fcnAxis->Eval(fPair, fPairDef, fEvent)) values[i] = (Double_t)((Float_t)fcnAxis->GetValue());
278 // check presence of output histogram
280 AliError("Required a TH1 which is not initialized");
285 // fill according to dimensions
290 TH1F *h1 = (TH1F*)fH1;
296 TH2F *h2 = (TH2F*)fH1;
297 h2->Fill(values[0], values[1]);
302 TH3F *h3 = (TH3F*)fH1;
303 h3->Fill(values[0], values[1], values[2]);
307 AliError(Form("Wrong size : %d", fSize));
314 // check presence of output histogram
316 AliError("Required a THnSparseF which is not initialized");
321 fHSparse->Fill(values);
326 AliDebug(AliLog::kDebug +2,"->");