]>
Commit | Line | Data |
---|---|---|
13f28255 | 1 | // |
2 | // Class AliRsnFunction | |
3 | // | |
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) | |
9 | // | |
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 | |
13 | // | |
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. | |
17 | // | |
18 | // | |
19 | // author: A. Pulvirenti (email: alberto.pulvirenti@ct.infn.it) | |
20 | // | |
21 | ||
22 | #include <Riostream.h> | |
23 | ||
24 | #include <TH1.h> | |
25 | #include <TH2.h> | |
26 | #include <TList.h> | |
27 | #include <TString.h> | |
28 | ||
29 | #include "AliLog.h" | |
30 | ||
31 | #include "AliRsnMCInfo.h" | |
32 | #include "AliRsnDaughter.h" | |
33 | #include "AliRsnEvent.h" | |
34 | #include "AliRsnPairDef.h" | |
35 | #include "AliRsnCut.h" | |
36 | ||
37 | #include "AliRsnFunction.h" | |
38 | ||
39 | ClassImp(AliRsnFunction) | |
40 | ||
41 | //________________________________________________________________________________________ | |
42 | AliRsnFunction::AliRsnFunction() : | |
43 | fFcnType(kFcnTypes), | |
44 | fUseBins(kFALSE), | |
45 | fSkipOutsideInterval(kFALSE), | |
46 | fBins(0), | |
47 | fBinningCut(), | |
48 | fBinningCutType(AliRsnCut::kLastCutType), | |
49 | fHistoDef(0x0) | |
50 | { | |
51 | // | |
52 | // Constructor. | |
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. | |
56 | // | |
57 | ||
58 | Int_t i; | |
59 | for (i = 0; i < 100; i++) { | |
60 | fHisto[i] = 0x0; | |
61 | } | |
62 | } | |
63 | ||
64 | //________________________________________________________________________________________ | |
65 | AliRsnFunction::AliRsnFunction | |
66 | (EFcnType type, AliRsnHistoDef *hd, Bool_t skipOut) : | |
67 | fFcnType(type), | |
68 | fUseBins(kFALSE), | |
69 | fSkipOutsideInterval(skipOut), | |
70 | fBins(0), | |
71 | fBinningCut(), | |
72 | fBinningCutType(AliRsnCut::kLastCutType), | |
73 | fHistoDef(hd) | |
74 | { | |
75 | // | |
76 | // Constructor. | |
77 | // The histogram data member cannot be passed externally, | |
78 | // its initialization MUST be defined inside the Init() method, | |
79 | // which must be overridden in any derivate implementation. | |
80 | // | |
81 | ||
82 | Int_t i; | |
83 | for (i = 0; i < 100; i++) { | |
84 | fHisto[i] = 0x0; | |
85 | } | |
86 | } | |
87 | ||
88 | //________________________________________________________________________________________ | |
89 | AliRsnFunction::AliRsnFunction(const AliRsnFunction ©) : | |
90 | TObject(copy), | |
91 | fFcnType(copy.fFcnType), | |
92 | fUseBins(copy.fUseBins), | |
93 | fSkipOutsideInterval(copy.fSkipOutsideInterval), | |
94 | fBins(0), | |
95 | fBinningCut(), | |
96 | fBinningCutType(AliRsnCut::kLastCutType), | |
97 | fHistoDef(copy.fHistoDef) | |
98 | { | |
99 | // | |
100 | // Copy constructor. | |
101 | // Calls the function to define binning. | |
102 | // | |
103 | ||
104 | Int_t i, n = 100; | |
105 | for (i = 0; i < n; i++) { | |
106 | fHisto[i] = 0x0; | |
107 | } | |
108 | ||
109 | if (fUseBins) { | |
110 | n = copy.fBins.GetSize(); | |
111 | Double_t *array = new Double_t[n]; | |
112 | for (i = 0; i < n; i++) array[i] = copy.fBins[i]; | |
113 | SetBinningCut(copy.fBinningCutType, copy.fBins.GetSize(), array); | |
114 | delete [] array; | |
115 | } | |
116 | } | |
117 | //________________________________________________________________________________________ | |
118 | const AliRsnFunction& AliRsnFunction::operator=(const AliRsnFunction& /*copy*/) | |
119 | { | |
120 | // | |
121 | // Assignment operator. | |
122 | // Behaves like copy constructor. | |
123 | // Also in this case, the histogram is not copied, and, | |
124 | // if it was present, it is destroyed and will need to be recreated. | |
125 | // | |
126 | ||
127 | return (*this); | |
128 | } | |
129 | //________________________________________________________________________________________ | |
130 | void AliRsnFunction::Clear(Option_t* /*option*/) | |
131 | { | |
132 | // | |
133 | // Clear arrays and histogram. | |
134 | // For the sake of security, all pointers are also set explicitly to NULL. | |
135 | // | |
136 | ||
137 | Int_t i; | |
138 | for (i = 0; i < 100; i++) { | |
139 | delete fHisto[i]; | |
140 | fHisto[i] = 0x0; | |
141 | } | |
142 | } | |
143 | ||
144 | //________________________________________________________________________________________ | |
145 | TList* AliRsnFunction::Init(const char *histoName, const char *histoTitle) | |
146 | { | |
147 | // | |
148 | // Initialization function. | |
149 | // By default, it initializes the owned histogram using the method | |
150 | // from AliRsnHistoDef class, giving the same name and title of this. | |
151 | // A user can override this behaviour, if necessary. | |
152 | // Before creating, the HistoDef is checked for proper initialization. | |
153 | // | |
154 | ||
155 | Clear(); | |
156 | ||
157 | Int_t i, ibin, nbins = fHistoDef->GetNBins(); | |
158 | Double_t min = fHistoDef->GetMin(), max = fHistoDef->GetMax(); | |
159 | ||
160 | // list is created and named after the general | |
161 | // settings used for the contained histograms | |
162 | TList *histos = new TList; | |
163 | histos->SetName(Form("%s", GetFcnName().Data())); | |
164 | ||
165 | // a general histogram is always added, | |
166 | // which overrides the binning and collects everything | |
167 | fHisto[0] = new TH1D(histoName, histoTitle, nbins, min, max); | |
168 | histos->AddLast(fHisto[0]); | |
169 | ||
170 | // if requested a binning w.r. to some cut variable, histograms are added | |
171 | // for that in this part of the method (one per each bin) | |
172 | Char_t hName[255]; | |
173 | Char_t hTitle[255]; | |
174 | if (fUseBins) { | |
175 | for (ibin = 0, i = 1; ibin < fBins.GetSize() - 1; ibin++, i++) { | |
176 | sprintf(hName, "%s[%.2f-%.2f]", histoName, fBins[ibin], fBins[ibin+1]); | |
177 | sprintf(hTitle, "%s [%.2f-%.2f]", histoTitle, fBins[ibin], fBins[ibin+1]); | |
178 | fHisto[i] = new TH1D(hName, hTitle, nbins, min, max); | |
179 | histos->AddLast(fHisto[i]); | |
180 | } | |
181 | } | |
182 | ||
183 | // returns the full list at the end | |
184 | return histos; | |
185 | } | |
186 | ||
187 | //________________________________________________________________________________________ | |
188 | void AliRsnFunction::Init(const char *histoName, const char *histoTitle, TList *histos) | |
189 | { | |
190 | // | |
191 | // Initialization function. | |
192 | // By default, it initializes the owned histogram using the method | |
193 | // from AliRsnHistoDef class, giving the same name and title of this. | |
194 | // A user can override this behaviour, if necessary. | |
195 | // Before creating, the HistoDef is checked for proper initialization. | |
196 | // | |
197 | ||
198 | Clear(); | |
199 | ||
200 | Int_t i, ibin, nbins = fHistoDef->GetNBins(); | |
201 | Double_t min = fHistoDef->GetMin(), max = fHistoDef->GetMax(); | |
202 | ||
203 | // list is created and named after the general | |
204 | // settings used for the contained histograms | |
205 | if (!histos) { | |
206 | AliError("NULL target list!"); | |
207 | return; | |
208 | } | |
209 | ||
210 | // a general histogram is always added, | |
211 | // which overrides the binning and collects everything | |
212 | fHisto[0] = new TH1D(histoName, histoTitle, nbins, min, max); | |
213 | histos->AddLast(fHisto[0]); | |
214 | ||
215 | // if requested a binning w.r. to some cut variable, histograms are added | |
216 | // for that in this part of the method (one per each bin) | |
217 | Char_t hName[255]; | |
218 | Char_t hTitle[255]; | |
219 | if (fUseBins) { | |
220 | for (ibin = 0, i = 1; ibin < fBins.GetSize() - 1; ibin++, i++) { | |
221 | sprintf(hName, "%s[%.2f-%.2f]", histoName, fBins[ibin], fBins[ibin+1]); | |
222 | sprintf(hTitle, "%s [%.2f-%.2f]", histoTitle, fBins[ibin], fBins[ibin+1]); | |
223 | fHisto[i] = new TH1D(hName, hTitle, nbins, min, max); | |
224 | histos->AddLast(fHisto[i]); | |
225 | } | |
226 | } | |
227 | } | |
228 | ||
229 | //________________________________________________________________________________________ | |
230 | void AliRsnFunction::SetBinningCut | |
231 | (AliRsnCut::EType type, Double_t min, Double_t max, Double_t step) | |
232 | { | |
233 | // | |
234 | // Set fixed bins | |
235 | // | |
236 | ||
237 | fUseBins = kTRUE; | |
238 | ||
239 | Int_t i, nBins = (Int_t)((max - min) / step) + 1; | |
240 | fBinningCutType = type; | |
241 | fBins.Set(nBins); | |
242 | for (i = 0; i < nBins; i++) { | |
243 | fBins[i] = min + (Double_t)i * step; | |
244 | } | |
245 | } | |
246 | ||
247 | //________________________________________________________________________________________ | |
248 | void AliRsnFunction::SetBinningCut | |
249 | (AliRsnCut::EType type, Int_t nbins, Double_t *bins) | |
250 | { | |
251 | // | |
252 | // Set variable bins | |
253 | // | |
254 | ||
255 | fUseBins = kTRUE; | |
256 | ||
257 | Int_t i; | |
258 | fBinningCutType = type; | |
259 | fBins.Set(nbins); | |
260 | for (i = 0; i < nbins; i++) { | |
261 | fBins[i] = bins[i]; | |
262 | } | |
263 | } | |
264 | ||
265 | //________________________________________________________________________________________ | |
266 | TString AliRsnFunction::GetFcnName() | |
267 | { | |
268 | // | |
269 | // Return a string which names the function type | |
270 | // | |
271 | ||
272 | TString text("Undef"); | |
273 | ||
274 | switch (fFcnType) { | |
275 | case kInvMass: | |
276 | text = "IM"; | |
277 | break; | |
278 | case kInvMassMC: | |
279 | text = "IM_MC"; | |
280 | break; | |
281 | case kResolution: | |
282 | text = "RES"; | |
283 | break; | |
284 | case kPtSpectrum: | |
285 | text = "PT"; | |
286 | default: | |
287 | AliError("Type not defined"); | |
288 | } | |
289 | ||
290 | return text; | |
291 | } | |
292 | ||
293 | //________________________________________________________________________________________ | |
294 | TString AliRsnFunction::GetFcnTitle() | |
295 | { | |
296 | // | |
297 | // Return a string which names the function type | |
298 | // | |
299 | ||
300 | TString text("Undef"); | |
301 | ||
302 | switch (fFcnType) { | |
303 | case kInvMass: | |
304 | text = "Invariant mass"; | |
305 | break; | |
306 | case kInvMassMC: | |
307 | text = "Invariant mass (MC)"; | |
308 | break; | |
309 | case kResolution: | |
310 | text = "Resolution"; | |
311 | break; | |
312 | case kPtSpectrum: | |
313 | text = "p_{#perp} distribution"; | |
314 | default: | |
315 | AliError("Type not defined"); | |
316 | } | |
317 | ||
318 | return text; | |
319 | } | |
320 | ||
321 | //________________________________________________________________________________________ | |
322 | Bool_t AliRsnFunction::Fill(AliRsnPairParticle *pair, AliRsnPairDef *ref, Double_t weight) | |
323 | { | |
324 | // | |
325 | // Fillse the histogram with data contained in a defined pair. | |
326 | // This method must be overidden by an appropriate definition in each inheriting class. | |
327 | // | |
328 | ||
329 | Double_t value = FcnValue(pair, ref); | |
330 | if (fSkipOutsideInterval) | |
331 | { | |
332 | if (value < fHistoDef->GetMin()) return kFALSE; | |
333 | if (value > fHistoDef->GetMax()) return kFALSE; | |
334 | } | |
335 | ||
336 | // fill global histogram | |
337 | if (weight == 0.0) fHisto[0]->Fill(value); | |
338 | else fHisto[0]->Fill(value, weight); | |
339 | ||
340 | // if bins are allocated, find right one and fill it | |
341 | if (fUseBins) { | |
342 | Int_t i, ibin; | |
343 | for (ibin = 0, i = 1; ibin < fBins.GetSize() - 1; ibin++, i++) { | |
344 | if (!fHisto[i]) continue; | |
345 | fBinningCut.SetCutValues(fBinningCutType, fBins[ibin], fBins[ibin+1]); | |
346 | if (fBinningCut.IsSelected(AliRsnCut::kPair, pair)) { | |
347 | if (weight == 0.0) fHisto[i]->Fill(value); | |
348 | else fHisto[i]->Fill(value, weight); | |
349 | break; | |
350 | } | |
351 | } | |
352 | } | |
353 | ||
354 | return kTRUE; | |
355 | } | |
356 | ||
357 | //________________________________________________________________________________________ | |
358 | Double_t AliRsnFunction::FcnValue(AliRsnPairParticle *pair, AliRsnPairDef *ref) | |
359 | { | |
360 | // | |
361 | // This method must be overridden in all inheritin functions. | |
362 | // It computes the value which must be used to fill the histogram. | |
363 | // | |
364 | ||
365 | switch (fFcnType) { | |
366 | case kInvMass: | |
367 | return pair->GetInvMass(ref->GetMass(0), ref->GetMass(1)); | |
368 | case kInvMassMC: | |
369 | return pair->GetInvMassMC(ref->GetMass(0), ref->GetMass(1)); | |
370 | case kResolution: | |
371 | return FcnResolution(pair, ref); | |
372 | case kPtSpectrum: | |
373 | return pair->GetPt(); | |
374 | default: | |
375 | AliError("Type not defined"); | |
376 | } | |
377 | ||
378 | return 0.0; | |
379 | } | |
380 | ||
381 | //________________________________________________________________________________________ | |
382 | inline Double_t AliRsnFunction::FcnResolution(AliRsnPairParticle *pair, AliRsnPairDef *ref) | |
383 | { | |
384 | // | |
385 | // Invariant mass resolution (compared between reconstructed and montecarlo) | |
386 | // | |
387 | ||
388 | Double_t recInvMass = pair->GetInvMass(ref->GetMass(0), ref->GetMass(1)); | |
389 | Double_t simInvMass = pair->GetInvMassMC(ref->GetMass(0), ref->GetMass(1)); | |
390 | ||
391 | return (simInvMass - recInvMass) / simInvMass; | |
392 | } |