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)
26 #include "AliRsnDaughter.h"
27 #include "AliRsnEvent.h"
28 #include "AliRsnPairDef.h"
29 #include "AliRsnMother.h"
30 #include "AliRsnValue.h"
32 #include "AliRsnFunction.h"
34 ClassImp(AliRsnFunction)
36 //________________________________________________________________________________________
37 AliRsnFunction::AliRsnFunction(Bool_t useTH1) :
40 fAxisList("AliRsnValue", 0),
53 //________________________________________________________________________________________
54 AliRsnFunction::AliRsnFunction(const AliRsnFunction ©) :
56 fPairDef(copy.fPairDef),
57 fAxisList(copy.fAxisList),
60 fUseTH1(copy.fUseTH1),
70 //________________________________________________________________________________________
71 const AliRsnFunction& AliRsnFunction::operator=(const AliRsnFunction& copy)
74 // Assignment operator.
77 //SetName(copy.GetName());
78 //SetTitle(copy.GetTitle());
80 fPairDef = copy.fPairDef;
83 fUseTH1 = copy.fUseTH1;
89 if (fHSparse) delete fHSparse;
95 //________________________________________________________________________________________
96 const char* AliRsnFunction::GetName() const
99 // Defines the name of this object according to
100 // the function type and binning
105 TObjArrayIter next(&fAxisList);
106 AliRsnValue *axis = 0;
108 while ((axis = (AliRsnValue*)next())) {
109 if (name.Length() > 1) name += '_';
110 name += axis->GetName();
116 //________________________________________________________________________________________
117 void AliRsnFunction::AddAxis(AliRsnValue *const axis)
119 AliDebug(AliLog::kDebug+2,"<-");
120 Int_t size = fAxisList.GetEntries();
121 new(fAxisList[size]) AliRsnValue(*axis);
122 AliDebug(AliLog::kDebug+2,"->");
124 if (fAxisList.GetEntries() > 3)
126 AliWarning("A TH1-type output cannot add more than 3 axes: switching to THnSparse -- THIS COULD CAUSE VERY LARGE FILES!!!");
131 //________________________________________________________________________________________
132 TH1* AliRsnFunction::CreateHistogram(const char *histoName, const char *histoTitle)
135 // Creates and returns the histogram defined using
136 // arguments fo name and title, and the first histoDef for binning.
137 // Variable-sized histogram binning is always called, due to use of histoDef,
138 // even if the bins are equal, since they are defined in this class.
139 // Eventually present histoDef's in other slots of array (1, 2) are ignored.
141 // This version produces a THnSparseF.
144 fSize = fAxisList.GetEntries();
146 AliError("No axes defined");
149 else if (fSize < 1 || fSize > 3)
151 AliError("Too few or too many axes defined");
155 Int_t *nbins = new Int_t [fSize];
156 Double_t *min = new Double_t[fSize];
157 Double_t *max = new Double_t[fSize];
159 // retrieve binnings for main and secondary axes
160 AliRsnValue *fcnAxis = 0;
161 for (Int_t i = 0; i < fSize; i++) {
162 fcnAxis = (AliRsnValue*)fAxisList.At(i);
167 AliError("Empty axis");
170 nbins[i] = fcnAxis->GetNBins();
171 min[i] = fcnAxis->GetMin();
172 max[i] = fcnAxis->GetMax();
175 // create histogram depending on the number of axes
179 fH1 = new TH1F(histoName, histoTitle, nbins[0], min[0], max[0]);
182 fH1 = new TH2F(histoName, histoTitle, nbins[0], min[0], max[0], nbins[1], min[1], max[1]);
185 fH1 = new TH3F(histoName, histoTitle, nbins[0], min[0], max[0], nbins[1], min[1], max[1], nbins[2], min[2], max[2]);
193 //________________________________________________________________________________________
194 THnSparseF* AliRsnFunction::CreateHistogramSparse(const char *histoName, const char *histoTitle)
197 // Creates and returns the histogram defined using
198 // arguments fo name and title, and the first histoDef for binning.
199 // Variable-sized histogram binning is always called, due to use of histoDef,
200 // even if the bins are equal, since they are defined in this class.
201 // Eventually present histoDef's in other slots of array (1, 2) are ignored.
203 // This version produces a THnSparseF.
206 fSize = fAxisList.GetEntries();
208 AliError("No axes defined");
212 Int_t *nbins = new Int_t [fSize];
213 Double_t *min = new Double_t[fSize];
214 Double_t *max = new Double_t[fSize];
216 // retrieve binnings for main and secondary axes
217 AliRsnValue *fcnAxis = 0;
218 for (Int_t i = 0; i < fSize; i++) {
219 fcnAxis = (AliRsnValue*)fAxisList.At(i);
224 AliError("Empty axis");
227 nbins[i] = fcnAxis->GetNBins();
228 min[i] = fcnAxis->GetMin();
229 max[i] = fcnAxis->GetMax();
232 Int_t size = fAxisList.GetEntries();
234 AliError("No axes defined");
239 fHSparse = new THnSparseF(histoName, histoTitle, size, nbins, min, max);
251 //________________________________________________________________________________________
252 Bool_t AliRsnFunction::Fill()
255 // Fill function histogram with values computed from given input object.
258 AliDebug(AliLog::kDebug +2,"->");
261 Double_t *values = new Double_t[fSize];
263 AliRsnValue *fcnAxis = 0;
264 for (i = 0; i < fSize; i++) {
265 fcnAxis = (AliRsnValue*)fAxisList.At(i);
270 if (fcnAxis->Eval(fPair, fPairDef, fEvent)) values[i] = fcnAxis->GetValue();
276 // check presence of output histogram
278 AliError("Required a TH1 whish is not initialized");
282 // fill according to dimensions
287 TH1F *h1 = (TH1F*)fH1;
293 TH2F *h2 = (TH2F*)fH1;
294 h2->Fill(values[0], values[1]);
299 TH3F *h3 = (TH3F*)fH1;
300 h3->Fill(values[0], values[1], values[2]);
304 AliError(Form("Wrong size : %d", fSize));
310 // check presence of output histogram
312 AliError("Required a THnSparseF which is not initialized");
316 fHSparse->Fill(values);
321 AliDebug(AliLog::kDebug +2,"->");