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)
22 #include <Riostream.h>
27 #include "AliRsnDaughter.h"
28 #include "AliRsnEvent.h"
29 #include "AliRsnPairDef.h"
30 #include "AliRsnCut.h"
32 #include "AliRsnFunction.h"
34 ClassImp(AliRsnFunction)
36 //________________________________________________________________________________________
37 AliRsnFunction::AliRsnFunction() :
47 // Constructor for 1D functions.
48 // Requires only the binning of the output function,
49 // which is stored as 'main' histoDef in fHistoDef[0]
52 fBinType[0] = kNoBins;
53 fBinType[1] = kNoBins;
60 //________________________________________________________________________________________
61 AliRsnFunction::AliRsnFunction
62 (EFcnType fcnType, AliRsnHistoDef *hd) :
72 // Constructor for 1D functions.
73 // Requires only the binning of the output function,
74 // which is stored as 'main' histoDef in fHistoDef[0]
77 fBinType[0] = kNoBins;
78 fBinType[1] = kNoBins;
87 //________________________________________________________________________________________
88 AliRsnFunction::AliRsnFunction
89 (EFcnType fcnType, EBinType binType, AliRsnHistoDef *hdMain, AliRsnHistoDef *hdBin) :
99 // Constructor for 2D functions.
100 // Requires the binning of the output function,
101 // which is stored as 'main' histoDef in fHistoDef[0],
102 // and a definition for a secondary binning, stored in fHistoDef[1]
105 fBinType[0] = binType;
106 fBinType[1] = kNoBins;
108 fHistoDef[0] = hdMain;
109 fHistoDef[1] = hdBin;
115 //________________________________________________________________________________________
116 AliRsnFunction::AliRsnFunction
117 (EFcnType fcnType, EBinType binType1, EBinType binType2,
118 AliRsnHistoDef *hdMain, AliRsnHistoDef *hdBin1, AliRsnHistoDef *hdBin2) :
127 // Constructor for 3D functions.
128 // Requires the binning of the output function,
129 // which is stored as 'main' histoDef in fHistoDef[0],
130 // and a definition for two secondary binnings, stored in fHistoDef[1,2]
133 fBinType[0] = binType1;
134 fBinType[1] = binType2;
136 fHistoDef[0] = hdMain;
137 fHistoDef[1] = hdBin1;
138 fHistoDef[2] = hdBin2;
143 //________________________________________________________________________________________
144 AliRsnFunction::AliRsnFunction(const AliRsnFunction ©) :
146 fFcnType(copy.fFcnType),
147 fPairDef(copy.fPairDef),
158 for (i = 0; i < 3; i++) {
159 fHistoDef[i] = copy.fHistoDef[i];
160 if (i < 2) fBinType[i] = copy.fBinType[i];
166 //________________________________________________________________________________________
167 const AliRsnFunction& AliRsnFunction::operator=(const AliRsnFunction& copy)
170 // Assignment operator.
173 SetName(copy.GetName());
174 SetTitle(copy.GetTitle());
176 fFcnType = copy.fFcnType;
178 fPairDef = copy.fPairDef;
181 for (i = 0; i < 3; i++) {
182 fHistoDef[i] = copy.fHistoDef[i];
183 if (i < 2) fBinType[i] = copy.fBinType[i];
186 fTrack = copy.fTrack;
188 fEvent = copy.fEvent;
190 if (fHistogram) delete fHistogram;
198 //________________________________________________________________________________________
199 const char* AliRsnFunction::FcnName()
202 // Defines the name of this object according to
203 // the function type and binning
237 //________________________________________________________________________________________
238 void AliRsnFunction::DefineName()
241 // Defines the name of this object according to
242 // the function type and binning
245 Int_t dim = CheckDim();
253 SetName(Form("%s_%s", FcnName(), BinName(fBinType[0])));
256 SetName(Form("%s_%s_%s", FcnName(), BinName(fBinType[0]), BinName(fBinType[1])));
263 //________________________________________________________________________________________
264 Double_t AliRsnFunction::Eval()
267 // Compute value for functions with 'event' argument type
277 return fTrack->Eta();
279 return fPair->GetInvMass(fPairDef->GetMass(0), fPairDef->GetMass(1));
281 return fPair->GetInvMassMC(fPairDef->GetMass(0), fPairDef->GetMass(1));
283 value = fPair->GetInvMass(fPairDef->GetMass(0), fPairDef->GetMass(1));
284 value -= fPair->GetInvMassMC(fPairDef->GetMass(0), fPairDef->GetMass(1));
285 value /= fPair->GetInvMassMC(fPairDef->GetMass(0), fPairDef->GetMass(1));
288 return fPair->GetPt();
290 return fPair->GetEta();
292 return fEvent->GetMultiplicity();
294 AliWarning("Function type not supported");
299 //_________________________________________________________________________________________________
300 Bool_t AliRsnFunction::CheckInput(Option_t *option)
303 // Checks if the argument type is coherent with
304 // the function type required
310 if (opt.Contains("TRACK")) {
312 AliError("Input track object is NULL");
317 if (opt.Contains("PAIR")) {
319 AliError("Input pair object is NULL");
324 if (opt.Contains("EVENT")) {
326 AliError("Input event object is NULL");
334 //________________________________________________________________________________________
335 TH1* AliRsnFunction::CreateHistogram(const char *histoName, const char *histoTitle)
338 // Creates and returns the histogram defined using
339 // arguments fo name and title, and the first histoDef for binning.
340 // Variable-sized histogram binning is always called, due to use of histoDef,
341 // even if the bins are equal, since they are defined in this class.
342 // Eventually present histoDef's in other slots of array (1, 2) are ignored.
345 // first binning is required
346 if (!fHistoDef[0]) return 0;
348 // retrieve binnings for main and secondary axes
349 Int_t i, nbins[3] = {0, 0, 0};
350 Double_t min[3] = {0., 0., 0.}, max[3] = {0., 0., 0.};
351 for (i = 0; i < 3; i++)
355 nbins[i] = fHistoDef[i]->GetNBins();
356 min[i] = fHistoDef[i]->GetMin();
357 max[i] = fHistoDef[i]->GetMax();
361 // define the kind of output according to the number of histoDefs
362 if (fHistogram) delete fHistogram;
363 if (!nbins[1] && !nbins[2]) {
364 fHistogram = new TH1D(histoName, histoTitle, nbins[0], min[0], max[0]);
365 fHistogram->SetXTitle(FcnName());
367 else if (nbins[1] > 0 && !nbins[2]) {
368 fHistogram = new TH2D(histoName, histoTitle, nbins[0], min[0], max[0], nbins[1], min[1], max[1]);
369 fHistogram->SetXTitle(FcnName());
370 fHistogram->SetYTitle(BinName(fBinType[0]));
373 fHistogram = new TH3D(histoName, histoTitle, nbins[0], min[0], max[0], nbins[1], min[1], max[1], nbins[2], min[2], max[2]);
374 fHistogram->SetXTitle(FcnName());
375 fHistogram->SetYTitle(BinName(fBinType[0]));
376 fHistogram->SetZTitle(BinName(fBinType[1]));
384 //________________________________________________________________________________________
385 Bool_t AliRsnFunction::Fill()
388 // Fill function histogram with values computed from given input object.
390 AliDebug(AliLog::kDebug +2,"->");
392 // checks coherence between fcn type and passed argument
396 if (!CheckInput("TRACK")) return kFALSE;
403 if (!CheckInput("PAIR")) return kFALSE;
406 if (!CheckInput("EVENT")) return kFALSE;
409 AliError(Form("Input type %d not defined", (Int_t)fFcnType));
413 // check presence of output histogram
415 AliError("Histogram is not yet initialized");
419 // compute value and stores into histogram
420 Int_t dim = CheckDim();
421 Double_t mainValue, binValue[2];
423 TH1D *h1 = dynamic_cast<TH1D*>(fHistogram);
424 TH2D *h2 = dynamic_cast<TH2D*>(fHistogram);
425 TH3D *h3 = dynamic_cast<TH3D*>(fHistogram);
432 if (h1) h1->Fill(mainValue);
435 binValue[0] = BinValue(fBinType[0]);
436 if (h2) h2->Fill(mainValue, binValue[0]);
439 binValue[0] = BinValue(fBinType[0]);
440 binValue[1] = BinValue(fBinType[1]);
441 if (h3) h3->Fill(mainValue, binValue[0], binValue[1]);
444 AliError("Wrong number of dimensions in the histogram. Check HD initialization");
448 AliDebug(AliLog::kDebug +2,"->");
452 //________________________________________________________________________________________
453 Double_t AliRsnFunction::BinValue(EBinType binType)
456 // Computes the value for binning from the argument.
457 // For each kind of binning type, the object is expected
458 // to be of a given type, otherwise an error is raised.
461 // checks coherence between bin type and passed argument
464 if (!CheckInput("PAIR")) return 0.0;
465 return fPair->GetPt();
467 if (!CheckInput("PAIR")) return 0.0;
468 return fPair->GetEta();
470 if (!CheckInput("EVENT")) return 0.0;
471 return fEvent->GetMultiplicity();
473 AliError(Form("%s: Binning type not defined", GetName()));
478 //________________________________________________________________________________________
479 Int_t AliRsnFunction::CheckDim()
482 // Checks number of dimensions.
483 // Makes sure that eventual binnings are coherent and well defined
486 if (!fHistoDef[0]) return 0;
487 if (fHistoDef[0] && !fHistoDef[1] && !fHistoDef[2]) return 1;
488 if (fHistoDef[0] && fHistoDef[1] && !fHistoDef[2]) return 2;
493 //________________________________________________________________________________________
494 const char* AliRsnFunction::BinName(EBinType binType)
497 // Defines the name of binning