2 // Class AliRsnListOutput
4 // This class defines a base classe to implement a Output
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 Outputs 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)
22 #include <Riostream.h>
24 #include <TCollection.h>
27 #include "AliCFContainer.h"
29 #include "AliRsnValue.h"
30 #include "AliRsnValueDaughter.h"
31 #include "AliRsnValueEvent.h"
32 #include "AliRsnLoop.h"
34 #include "AliRsnListOutput.h"
36 ClassImp(AliRsnListOutput)
38 //________________________________________________________________________________________
39 AliRsnListOutput::AliRsnListOutput(const char *name, AliRsnListOutput::EOut type) :
52 // Requires a name for this object (which will be used to name the output object)
53 // and the definition of the output type from the built-in enumeration.
57 //________________________________________________________________________________________
58 AliRsnListOutput::AliRsnListOutput(const AliRsnListOutput ©) :
60 fSkipFailed(copy.fSkipFailed),
63 fValues(copy.fValues),
64 fNValues(copy.fNValues),
71 // Since the pointer objects must be initialized in a second step,
72 // they are never copied, and then they are initialized to zero.
76 //________________________________________________________________________________________
77 AliRsnListOutput &AliRsnListOutput::operator=(const AliRsnListOutput ©)
80 // Assignment operator.
81 // Same consideration as the copiy constructor. In this case, there is
82 // the possibility to have the output objects alreasy initialized, but
83 // they are anyway reset.
86 TNamed::operator=(copy);
89 fSkipFailed = copy.fSkipFailed;
92 fValues = copy.fValues;
93 fNValues = copy.fNValues;
103 //__________________________________________________________________________________________________
104 AliRsnListOutput::~AliRsnListOutput()
108 // Deletes the output objects.
114 //__________________________________________________________________________________________________
115 void AliRsnListOutput::Reset()
118 // Clear all output objects. In general, only one will be initialized at a time.
124 //_____________________________________________________________________________
125 void AliRsnListOutput::AddValue(AliRsnValue *value)
128 // Adds a value computation object to the list.
131 fValues.AddLast(value);
135 //________________________________________________________________________________________
136 Bool_t AliRsnListOutput::Init(const char *prefix, TList *list)
139 // Initializes the output for this object.
140 // What kind of output depends on the 'fType' data member,
141 // and in case it is a CF container, also on the 'fSteps'.
142 // The object is named with the following criterion:
143 // <prefix>_<name>_<type>_<varList>
148 // all output objects are cleared
151 // count values and set dimension of arrays
152 // do also some checks for a good match between type and output
153 fNValues = fValues.GetEntries();
155 AliError("Need at least 1 value");
158 if (fType == kHistoDefault && fNValues > 3) {
159 AliInfo(Form("NValues = %d > 3 --> cannot use a normal histogram, need to use a sparse", fNValues));
160 fType = kHistoSparse;
163 // resize the output array
164 fArray.Set(fNValues);
167 Bool_t isPair=kFALSE;
170 TString name(GetName());
171 if (!name.CompareTo("pair")) isPair = kTRUE;
172 if (isPair) name = "";
173 else name.Prepend(".");
174 name.Prepend(prefix);
176 // TString name(Form("%s.%s", prefix, GetName()));
177 AliRsnValue *val = 0x0;
178 for (i = 0; i < fNValues; i++) {
181 AliError(Form("Slot %d in value list is NULL", i));
186 name += val->GetName();
191 TObject *object = 0x0;
193 // initialize appropriate output object
194 // and, if successful, insert into the list
197 // name.Append("_hist");
198 object = CreateHistogram(name.Data());
201 // name.Append("_hsparse");
202 object = CreateHistogramSparse(name.Data());
205 // name.Append("_cf");
206 object = CreateCFContainer(name.Data());
209 AliWarning("Wrong type output or initialization failure");
213 //AliInfo(Form("[%s]: initializing output '%s' (obj name = '%s') with %d values and format %d [%s]", GetName(), name.Data(), object->GetName(), fNValues, fType, object->ClassName()));
216 fIndex = fList->IndexOf(object);
223 //________________________________________________________________________________________
224 TH1 *AliRsnListOutput::CreateHistogram(const char *name)
227 // Initialize the 'default' TH1 output object.
228 // In case one of the expected axes is NULL, the initialization fails.
231 // we expect to have maximum 3 axes in this case
232 Int_t i, nbins[3] = {0, 0, 0};
234 for (i = 0; i < fNValues; i++) {
235 AliRsnValue *val = GetValue(i);
237 AliError(Form("Expected axis %d is NULL", i));
240 nbins[i] = GetValue(i)->GetArray().GetSize() - 1;
241 array[i] = GetValue(i)->GetArray();
246 // create histogram depending on the number of axes
249 hist = new TH1F(name, "", nbins[0], array[0].GetArray());
252 hist = new TH2F(name, "", nbins[0], array[0].GetArray(), nbins[1], array[1].GetArray());
255 hist = new TH3F(name, "", nbins[0], array[0].GetArray(), nbins[1], array[1].GetArray(), nbins[2], array[2].GetArray());
258 //AliError(Form("Wrong number of dimensions: %d", fNValues))
262 if (hist) hist->Sumw2();
266 //________________________________________________________________________________________
267 THnSparseF *AliRsnListOutput::CreateHistogramSparse(const char *name)
270 // Initialize the THnSparse output object.
271 // In case one of the expected axes is NULL, the initialization fails.
274 // retrieve binnings and sizes of all axes
275 // since the check for null values is done in Init(),
276 // we assume that here they must all be well defined
277 Int_t i, *nbins = new Int_t[fNValues];
278 TArrayD *array = new TArrayD[fNValues];
279 for (i = 0; i < fNValues; i++) {
280 nbins[i] = GetValue(i)->GetArray().GetSize() - 1;
281 array[i] = GetValue(i)->GetArray();
285 THnSparseF *hist = new THnSparseF(name, "", fNValues, nbins);
288 // update the various axes using the definitions given in the array of axes here
289 AliRsnValue *val = 0x0;
290 for (i = 0; i < fNValues; i++) {
292 if (val) hist->GetAxis(i)->SetName(val->GetName());
293 hist->GetAxis(i)->Set(nbins[i], array[i].GetArray());
303 //________________________________________________________________________________________
304 AliCFContainer *AliRsnListOutput::CreateCFContainer(const char *name)
307 // Initialize the AliCFContainer output object.
308 // In case one of the expected axes is NULL, the initialization fails.
311 // retrieve binnings and sizes of all axes
312 // since the check for null values is done in Init(),
313 // we assume that here they must all be well defined
314 Int_t i, *nbins = new Int_t[fNValues];
315 TArrayD *array = new TArrayD[fNValues];
316 for (i = 0; i < fNValues; i++) {
317 nbins[i] = GetValue(i)->GetArray().GetSize() - 1;
318 array[i] = GetValue(i)->GetArray();
322 AliCFContainer *cont = new AliCFContainer(name, "", fSteps, fNValues, nbins);
324 // set the bin limits for each axis
325 for (i = 0; i < fNValues; i++) {
326 cont->SetBinLimits(i, array[i].GetArray());
336 //________________________________________________________________________________________
337 Bool_t AliRsnListOutput::Fill(TObject *target, Int_t step)
340 // Uses the passed argument to compute all values.
341 // If all computations were successful, fill the output
342 // Second argument (step) is needed only in case of CF containers.
343 // Return value is the AND of all computation successes.
349 Bool_t globalOK = kTRUE;
350 AliRsnValue *val = 0x0;
351 for (i = 0; i < fNValues; i++) {
354 AliError("NULL value found");
357 globalOK = globalOK && val->Eval(target);
358 fArray[i] = (Double_t)val->GetComputedValue();
360 if (!globalOK && fSkipFailed) return kFALSE;
363 if (!fList || fIndex < 0) {
364 AliError("List not initialized");
367 TObject *obj = fList->At(fIndex);
369 AliError("Null pointer");
374 //AliInfo(Form("[%s] Object index, name, type = %d, %s (%s)", GetName(), fIndex, obj->GetName(), obj->ClassName()));
377 if (obj->IsA() == TH1F::Class()) {
378 TH1F *h = (TH1F *)obj;
381 } else if (obj->IsA() == TH2F::Class()) {
382 TH2F *h = (TH2F *)obj;
383 h->Fill(fArray[0], fArray[1]);
385 } else if (obj->IsA() == TH3F::Class()) {
386 TH3F *h = (TH3F *)obj;
387 h->Fill(fArray[0], fArray[1], fArray[2]);
389 } else if (obj->InheritsFrom(THnSparse::Class())) {
390 THnSparseF *h = (THnSparseF *)obj;
391 for (Int_t iAxis = 0; iAxis<h->GetNdimensions(); iAxis++) {
392 if (fArray.At(iAxis)>h->GetAxis(iAxis)->GetXmax() || fArray.At(iAxis)<h->GetAxis(iAxis)->GetXmin()) return kFALSE;
394 h->Fill(fArray.GetArray());
396 } else if (obj->InheritsFrom(AliCFContainer::Class())) {
397 AliCFContainer *c = (AliCFContainer *)obj;
398 c->Fill(fArray.GetArray(), step);
401 AliError(Form("Not handled class '%s'", obj->ClassName()));
406 //________________________________________________________________________________________
407 Bool_t AliRsnListOutput::Fill(AliRsnEvent *ev, AliRsnDaughter *d)
410 // Uses the passed argument to compute all values.
411 // If all computations were successful, fill the output
412 // Return value is the AND of all computation successes.
416 if (!fList || fIndex < 0) {
417 AliError("List not initialized");
420 TObject *obj = fList->At(fIndex);
422 AliError("Null pointer");
427 TIter next(&fValues);
430 Bool_t globalOK = kTRUE;
431 Double_t values[fValues.GetEntries()];
432 while ((val = (AliRsnValue *)next())) {
433 if (val->InheritsFrom(AliRsnValueDaughter::Class())) {
434 if (!d && fSkipFailed) return kFALSE;
435 globalOK = globalOK && val->Eval(d);
436 } else if (val->InheritsFrom(AliRsnValueEvent::Class())) {
437 if (!ev && fSkipFailed) return kFALSE;
438 globalOK = globalOK && val->Eval(ev);
440 values[i] = (Double_t)val->GetComputedValue();
441 if (!globalOK && fSkipFailed) return kFALSE;
446 if (obj->IsA() == TH1F::Class()) {
447 TH1F *h = (TH1F *)obj;
450 } else if (obj->IsA() == TH2F::Class()) {
451 TH2F *h = (TH2F *)obj;
452 h->Fill(values[0], values[1]);
454 } else if (obj->IsA() == TH3F::Class()) {
455 TH3F *h = (TH3F *)obj;
456 h->Fill(values[0], values[1], values[2]);
458 } else if (obj->InheritsFrom(THnSparse::Class())) {
459 THnSparseF *h = (THnSparseF *)obj;
460 for (Int_t iAxis = 0; iAxis<h->GetNdimensions(); iAxis++) {
461 if (values[iAxis]>h->GetAxis(iAxis)->GetXmax() || values[iAxis]<h->GetAxis(iAxis)->GetXmin()) return kFALSE;
466 AliError(Form("Not handled class '%s'", obj->ClassName()));