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>
30 #include "AliRsnMCInfo.h"
31 #include "AliRsnDaughter.h"
32 #include "AliRsnEvent.h"
33 #include "AliRsnPairDef.h"
34 #include "AliRsnCut.h"
36 #include "AliRsnFunction.h"
38 ClassImp(AliRsnFunction)
40 //________________________________________________________________________________________
41 AliRsnFunction::AliRsnFunction() :
45 fSkipOutsideInterval(kFALSE),
48 fBinningCutType(AliRsnCut::kLastCutType),
53 // The histogram data member cannot be passed externally,
54 // its initialization MUST be defined inside the Init() method,
55 // which must be overridden in any derivate implementation.
59 for (i = 0; i < 100; i++)
65 //________________________________________________________________________________________
66 AliRsnFunction::AliRsnFunction
67 (EFcnType type, AliRsnHistoDef *hd, Bool_t skipOut) :
71 fSkipOutsideInterval(skipOut),
74 fBinningCutType(AliRsnCut::kLastCutType),
79 // The histogram data member cannot be passed externally,
80 // its initialization MUST be defined inside the Init() method,
81 // which must be overridden in any derivate implementation.
85 for (i = 0; i < 100; i++)
91 //________________________________________________________________________________________
92 AliRsnFunction::AliRsnFunction(const AliRsnFunction ©) :
94 fFcnType(copy.fFcnType),
95 fRotAngle(copy.fRotAngle),
96 fUseBins(copy.fUseBins),
97 fSkipOutsideInterval(copy.fSkipOutsideInterval),
100 fBinningCutType(AliRsnCut::kLastCutType),
101 fHistoDef(copy.fHistoDef)
105 // Calls the function to define binning.
109 for (i = 0; i < n; i++)
116 n = copy.fBins.GetSize();
117 Double_t *array = new Double_t[n];
118 for (i = 0; i < n; i++) array[i] = copy.fBins[i];
119 SetBinningCut(copy.fBinningCutType, copy.fBins.GetSize(), array);
123 //________________________________________________________________________________________
124 const AliRsnFunction& AliRsnFunction::operator=(const AliRsnFunction& /*copy*/)
127 // Assignment operator.
128 // Behaves like copy constructor.
129 // Also in this case, the histogram is not copied, and,
130 // if it was present, it is destroyed and will need to be recreated.
135 //________________________________________________________________________________________
136 void AliRsnFunction::Clear(Option_t* /*option*/)
139 // Clear arrays and histogram.
140 // For the sake of security, all pointers are also set explicitly to NULL.
144 for (i = 0; i < 100; i++)
151 //________________________________________________________________________________________
152 TList* AliRsnFunction::Init(const char *histoName, const char *histoTitle)
155 // Initialization function.
156 // By default, it initializes the owned histogram using the method
157 // from AliRsnHistoDef class, giving the same name and title of this.
158 // A user can override this behaviour, if necessary.
159 // Before creating, the HistoDef is checked for proper initialization.
164 Int_t i, ibin, nbins = fHistoDef->GetNBins();
165 Double_t min = fHistoDef->GetMin(), max = fHistoDef->GetMax();
167 // list is created and named after the general
168 // settings used for the contained histograms
169 TList *histos = new TList;
170 histos->SetName(Form("%s", GetFcnName().Data()));
172 // a general histogram is always added,
173 // which overrides the binning and collects everything
174 fHisto[0] = new TH1D(histoName, histoTitle, nbins, min, max);
175 histos->AddLast(fHisto[0]);
177 // if requested a binning w.r. to some cut variable, histograms are added
178 // for that in this part of the method (one per each bin)
183 for (ibin = 0, i = 1; ibin < fBins.GetSize() - 1; ibin++, i++)
185 sprintf(hName, "%s[%.2f-%.2f]", histoName, fBins[ibin], fBins[ibin+1]);
186 sprintf(hTitle, "%s [%.2f-%.2f]", histoTitle, fBins[ibin], fBins[ibin+1]);
187 fHisto[i] = new TH1D(hName, hTitle, nbins, min, max);
188 histos->AddLast(fHisto[i]);
192 // returns the full list at the end
196 //________________________________________________________________________________________
197 void AliRsnFunction::Init(const char *histoName, const char *histoTitle, TList *histos)
200 // Initialization function.
201 // By default, it initializes the owned histogram using the method
202 // from AliRsnHistoDef class, giving the same name and title of this.
203 // A user can override this behaviour, if necessary.
204 // Before creating, the HistoDef is checked for proper initialization.
209 Int_t i, ibin, nbins = fHistoDef->GetNBins();
210 Double_t min = fHistoDef->GetMin(), max = fHistoDef->GetMax();
212 // list is created and named after the general
213 // settings used for the contained histograms
216 AliError("NULL target list!");
220 // a general histogram is always added,
221 // which overrides the binning and collects everything
222 fHisto[0] = new TH1D(histoName, histoTitle, nbins, min, max);
223 histos->AddLast(fHisto[0]);
225 // if requested a binning w.r. to some cut variable, histograms are added
226 // for that in this part of the method (one per each bin)
231 for (ibin = 0, i = 1; ibin < fBins.GetSize() - 1; ibin++, i++)
233 sprintf(hName, "%s[%.2f-%.2f]", histoName, fBins[ibin], fBins[ibin+1]);
234 sprintf(hTitle, "%s [%.2f-%.2f]", histoTitle, fBins[ibin], fBins[ibin+1]);
235 fHisto[i] = new TH1D(hName, hTitle, nbins, min, max);
236 histos->AddLast(fHisto[i]);
241 //________________________________________________________________________________________
242 void AliRsnFunction::SetBinningCut
243 (AliRsnCut::EType type, Double_t min, Double_t max, Double_t step)
251 Int_t i, nBins = (Int_t)((max - min) / step) + 1;
252 fBinningCutType = type;
254 for (i = 0; i < nBins; i++)
256 fBins[i] = min + (Double_t)i * step;
260 //________________________________________________________________________________________
261 void AliRsnFunction::SetBinningCut
262 (AliRsnCut::EType type, Int_t nbins, Double_t *bins)
271 fBinningCutType = type;
273 for (i = 0; i < nbins; i++)
279 //________________________________________________________________________________________
280 TString AliRsnFunction::GetFcnName()
283 // Return a string which names the function type
286 TString text("Undef");
296 case kInvMassRotated:
297 text = Form("IMR%.2f", fRotAngle);
311 AliError("Type not defined");
317 //________________________________________________________________________________________
318 TString AliRsnFunction::GetFcnTitle()
321 // Return a string which names the function type
324 TString text("Undef");
329 text = "Invariant mass";
332 text = "Invariant mass (MC)";
338 text = "p_{#perp} distribution";
341 text = "#eta distribution";
344 text = "angle distribution";
347 AliError("Type not defined");
353 //________________________________________________________________________________________
354 Bool_t AliRsnFunction::Fill(AliRsnPairParticle *pair, AliRsnPairDef *ref, Double_t weight)
357 // Fillse the histogram with data contained in a defined pair.
358 // This method must be overidden by an appropriate definition in each inheriting class.
361 Double_t value = FcnValue(pair, ref);
362 if (fSkipOutsideInterval)
364 if (value < fHistoDef->GetMin()) return kFALSE;
365 if (value > fHistoDef->GetMax()) return kFALSE;
368 // fill global histogram
369 if (weight == 0.0) fHisto[0]->Fill(value);
370 else fHisto[0]->Fill(value, weight);
372 // if bins are allocated, find right one and fill it
376 for (ibin = 0, i = 1; ibin < fBins.GetSize() - 1; ibin++, i++)
378 if (!fHisto[i]) continue;
379 fBinningCut.SetCutValues(fBinningCutType, fBins[ibin], fBins[ibin+1]);
380 if (fBinningCut.IsSelected(AliRsnCut::kPair, pair))
382 if (weight == 0.0) fHisto[i]->Fill(value);
383 else fHisto[i]->Fill(value, weight);
392 //________________________________________________________________________________________
393 Double_t AliRsnFunction::FcnValue(AliRsnPairParticle *pair, AliRsnPairDef *ref)
396 // This method must be overridden in all inheritin functions.
397 // It computes the value which must be used to fill the histogram.
403 return pair->GetInvMass(ref->GetMass(0), ref->GetMass(1));
405 return pair->GetInvMassMC(ref->GetMass(0), ref->GetMass(1));
406 case kInvMassRotated:
407 //AliInfo(Form("*** ROTATION ANGLE = %f ***", fRotAngle));
408 //AliInfo(Form("UNROTATED INV MASS = %f", pair->GetInvMass(ref->GetMass(0), ref->GetMass(1))));
409 //pair->GetDaughter(1)->Print("P");
410 pair->GetDaughter(1)->RotateP(fRotAngle * TMath::DegToRad());
412 //AliInfo(Form(" ROTATED INV MASS = %f", pair->GetInvMass(ref->GetMass(0), ref->GetMass(1))));
413 //pair->GetDaughter(1)->Print("P");
414 return pair->GetInvMass(ref->GetMass(0), ref->GetMass(1));
416 return FcnResolution(pair, ref);
418 return pair->GetPt();
420 return pair->GetEta();
422 return pair->GetAngle();
424 AliError("Type not defined");
430 //________________________________________________________________________________________
431 inline Double_t AliRsnFunction::FcnResolution(AliRsnPairParticle *pair, AliRsnPairDef *ref)
434 // Invariant mass resolution (compared between reconstructed and montecarlo)
437 Double_t recInvMass = pair->GetInvMass(ref->GetMass(0), ref->GetMass(1));
438 Double_t simInvMass = pair->GetInvMassMC(ref->GetMass(0), ref->GetMass(1));
440 return (simInvMass - recInvMass) / simInvMass;