]>
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 | // | |
e0baff8c | 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 | |
13f28255 | 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> | |
13f28255 | 25 | #include <TList.h> |
26 | #include <TString.h> | |
27 | ||
28 | #include "AliLog.h" | |
29 | ||
30 | #include "AliRsnMCInfo.h" | |
31 | #include "AliRsnDaughter.h" | |
32 | #include "AliRsnEvent.h" | |
33 | #include "AliRsnPairDef.h" | |
34 | #include "AliRsnCut.h" | |
35 | ||
36 | #include "AliRsnFunction.h" | |
37 | ||
38 | ClassImp(AliRsnFunction) | |
39 | ||
40 | //________________________________________________________________________________________ | |
41 | AliRsnFunction::AliRsnFunction() : | |
e0baff8c | 42 | fFcnType(kFcnTypes), |
43 | fRotAngle(0.0), | |
44 | fUseBins(kFALSE), | |
45 | fSkipOutsideInterval(kFALSE), | |
15d5fd02 | 46 | fNumberOfBinTypes(0), |
47 | // fBins(0), | |
48 | // fBinningCut(), | |
49 | // fBinningCutType(AliRsnCut::kLastCutType), | |
e0baff8c | 50 | fHistoDef(0x0) |
13f28255 | 51 | { |
52 | // | |
53 | // Constructor. | |
54 | // The histogram data member cannot be passed externally, | |
55 | // its initialization MUST be defined inside the Init() method, | |
56 | // which must be overridden in any derivate implementation. | |
57 | // | |
e0baff8c | 58 | |
15d5fd02 | 59 | Int_t i, j; |
60 | for (j = 0 ; j < kFcnBinTypes; j++) | |
61 | for (i = 0; i < 100; i++) | |
62 | fHisto[j][i] = 0x0; | |
63 | ||
13f28255 | 64 | } |
65 | ||
66 | //________________________________________________________________________________________ | |
67 | AliRsnFunction::AliRsnFunction | |
68 | (EFcnType type, AliRsnHistoDef *hd, Bool_t skipOut) : | |
e0baff8c | 69 | fFcnType(type), |
70 | fRotAngle(0.0), | |
71 | fUseBins(kFALSE), | |
72 | fSkipOutsideInterval(skipOut), | |
15d5fd02 | 73 | fNumberOfBinTypes(0), |
74 | // fBins(0), | |
75 | // fBinningCut(), | |
76 | // fBinningCutType(AliRsnCut::kLastCutType), | |
e0baff8c | 77 | fHistoDef(hd) |
13f28255 | 78 | { |
79 | // | |
80 | // Constructor. | |
81 | // The histogram data member cannot be passed externally, | |
82 | // its initialization MUST be defined inside the Init() method, | |
83 | // which must be overridden in any derivate implementation. | |
84 | // | |
e0baff8c | 85 | |
15d5fd02 | 86 | Int_t i, j; |
87 | for (j = 0 ; j < kFcnBinTypes; j++) | |
88 | for (i = 0; i < 100; i++) | |
89 | fHisto[j][i] = 0x0; | |
13f28255 | 90 | } |
91 | ||
92 | //________________________________________________________________________________________ | |
93 | AliRsnFunction::AliRsnFunction(const AliRsnFunction ©) : | |
e0baff8c | 94 | TObject(copy), |
95 | fFcnType(copy.fFcnType), | |
96 | fRotAngle(copy.fRotAngle), | |
97 | fUseBins(copy.fUseBins), | |
98 | fSkipOutsideInterval(copy.fSkipOutsideInterval), | |
15d5fd02 | 99 | fNumberOfBinTypes(copy.fNumberOfBinTypes), |
100 | // fBins(0), | |
101 | // fBinningCut(), | |
102 | // fBinningCutType(AliRsnCut::kLastCutType), | |
e0baff8c | 103 | fHistoDef(copy.fHistoDef) |
13f28255 | 104 | { |
105 | // | |
106 | // Copy constructor. | |
107 | // Calls the function to define binning. | |
108 | // | |
109 | ||
15d5fd02 | 110 | Int_t i, j, n; |
111 | for (j = 0 ; j < kFcnBinTypes; j++) | |
112 | for (i = 0; i < 100; i++) | |
113 | fHisto[j][i] = 0x0; | |
e0baff8c | 114 | |
115 | if (fUseBins) | |
116 | { | |
15d5fd02 | 117 | for (i = 0 ; i < kFcnBinTypes; i++){ |
118 | if (fNumberOfBinTypes<=i) continue; | |
119 | n = copy.fBins[i].GetSize(); | |
120 | Double_t *array = new Double_t[n]; | |
121 | for (j = 0; j < n; j++) array[j] = copy.fBins[i][j]; | |
122 | SetBinningCut(copy.fBinningCutType[i], copy.fBins[i].GetSize(), array,i,kTRUE); | |
123 | delete [] array; | |
124 | } | |
13f28255 | 125 | } |
126 | } | |
127 | //________________________________________________________________________________________ | |
128 | const AliRsnFunction& AliRsnFunction::operator=(const AliRsnFunction& /*copy*/) | |
129 | { | |
130 | // | |
131 | // Assignment operator. | |
132 | // Behaves like copy constructor. | |
133 | // Also in this case, the histogram is not copied, and, | |
134 | // if it was present, it is destroyed and will need to be recreated. | |
135 | // | |
136 | ||
137 | return (*this); | |
138 | } | |
139 | //________________________________________________________________________________________ | |
140 | void AliRsnFunction::Clear(Option_t* /*option*/) | |
141 | { | |
142 | // | |
143 | // Clear arrays and histogram. | |
144 | // For the sake of security, all pointers are also set explicitly to NULL. | |
145 | // | |
146 | ||
15d5fd02 | 147 | Int_t i, j; |
148 | for (j = 0 ; j < kFcnBinTypes; j++) | |
149 | for (i = 0; i < 100; i++) | |
150 | { | |
151 | delete fHisto[j][i]; | |
152 | fHisto[j][i] = 0x0; | |
153 | } | |
13f28255 | 154 | } |
155 | ||
156 | //________________________________________________________________________________________ | |
157 | TList* AliRsnFunction::Init(const char *histoName, const char *histoTitle) | |
158 | { | |
159 | // | |
160 | // Initialization function. | |
161 | // By default, it initializes the owned histogram using the method | |
162 | // from AliRsnHistoDef class, giving the same name and title of this. | |
163 | // A user can override this behaviour, if necessary. | |
164 | // Before creating, the HistoDef is checked for proper initialization. | |
165 | // | |
166 | ||
167 | Clear(); | |
e0baff8c | 168 | |
13f28255 | 169 | Int_t i, ibin, nbins = fHistoDef->GetNBins(); |
170 | Double_t min = fHistoDef->GetMin(), max = fHistoDef->GetMax(); | |
e0baff8c | 171 | |
13f28255 | 172 | // list is created and named after the general |
173 | // settings used for the contained histograms | |
174 | TList *histos = new TList; | |
175 | histos->SetName(Form("%s", GetFcnName().Data())); | |
e0baff8c | 176 | |
177 | // a general histogram is always added, | |
13f28255 | 178 | // which overrides the binning and collects everything |
15d5fd02 | 179 | |
180 | fHisto[0][0] = new TH1D(histoName, histoTitle, nbins, min, max); | |
181 | fHisto[0][0]->Sumw2(); | |
182 | histos->AddLast(fHisto[0][0]); | |
e0baff8c | 183 | |
184 | // if requested a binning w.r. to some cut variable, histograms are added | |
13f28255 | 185 | // for that in this part of the method (one per each bin) |
186 | Char_t hName[255]; | |
187 | Char_t hTitle[255]; | |
15d5fd02 | 188 | Int_t j; |
e0baff8c | 189 | if (fUseBins) |
190 | { | |
15d5fd02 | 191 | for (j = 0 ; j < kFcnBinTypes; j++){ |
192 | if (fNumberOfBinTypes<=j) continue; | |
193 | for (ibin = 0, i = 1; ibin < fBins[j].GetSize() - 1; ibin++, i++) | |
194 | { | |
195 | sprintf(hName, "%s_%d%02d_[%.2f-%.2f]", histoName, j,i,fBins[j][ibin], fBins[j][ibin+1]); | |
196 | sprintf(hTitle, "%s [%.2f-%.2f]", histoTitle, fBins[j][ibin], fBins[j][ibin+1]); | |
197 | // AliInfo(Form("Adding %s",hName)); | |
198 | fHisto[j][i] = new TH1D(hName, hTitle, nbins, min, max); | |
199 | fHisto[j][i]->Sumw2(); | |
200 | histos->AddLast(fHisto[j][i]); | |
201 | } | |
13f28255 | 202 | } |
203 | } | |
e0baff8c | 204 | |
13f28255 | 205 | // returns the full list at the end |
206 | return histos; | |
207 | } | |
208 | ||
209 | //________________________________________________________________________________________ | |
210 | void AliRsnFunction::Init(const char *histoName, const char *histoTitle, TList *histos) | |
211 | { | |
212 | // | |
213 | // Initialization function. | |
214 | // By default, it initializes the owned histogram using the method | |
215 | // from AliRsnHistoDef class, giving the same name and title of this. | |
216 | // A user can override this behaviour, if necessary. | |
217 | // Before creating, the HistoDef is checked for proper initialization. | |
218 | // | |
219 | ||
220 | Clear(); | |
e0baff8c | 221 | |
13f28255 | 222 | Int_t i, ibin, nbins = fHistoDef->GetNBins(); |
223 | Double_t min = fHistoDef->GetMin(), max = fHistoDef->GetMax(); | |
e0baff8c | 224 | |
13f28255 | 225 | // list is created and named after the general |
226 | // settings used for the contained histograms | |
e0baff8c | 227 | if (!histos) |
228 | { | |
13f28255 | 229 | AliError("NULL target list!"); |
230 | return; | |
231 | } | |
e0baff8c | 232 | |
233 | // a general histogram is always added, | |
13f28255 | 234 | // which overrides the binning and collects everything |
15d5fd02 | 235 | fHisto[0][0] = new TH1D(histoName, histoTitle, nbins, min, max); |
236 | histos->AddLast(fHisto[0][0]); | |
e0baff8c | 237 | |
238 | // if requested a binning w.r. to some cut variable, histograms are added | |
13f28255 | 239 | // for that in this part of the method (one per each bin) |
240 | Char_t hName[255]; | |
241 | Char_t hTitle[255]; | |
15d5fd02 | 242 | Int_t j; |
e0baff8c | 243 | if (fUseBins) |
244 | { | |
15d5fd02 | 245 | for (j = 0 ; j < kFcnBinTypes; j++){ |
246 | if (fNumberOfBinTypes<=j) continue; | |
247 | for (ibin = 0, i = 1; ibin < fBins[j].GetSize() - 1; ibin++, i++) | |
248 | { | |
249 | ||
250 | sprintf(hName, "%s_%d_%02d[%.2f-%.2f]", histoName,j,i, fBins[j][ibin], fBins[j][ibin+1]); | |
251 | sprintf(hTitle, "%s [%.2f-%.2f]", histoTitle, fBins[j][ibin], fBins[j][ibin+1]); | |
252 | // AliInfo(Form("Adding %s",hName)); | |
253 | fHisto[j][i] = new TH1D(hName, hTitle, nbins, min, max); | |
254 | histos->AddLast(fHisto[j][i]); | |
255 | } | |
13f28255 | 256 | } |
257 | } | |
258 | } | |
259 | ||
260 | //________________________________________________________________________________________ | |
261 | void AliRsnFunction::SetBinningCut | |
15d5fd02 | 262 | (AliRsnCut::EType type, Double_t min, Double_t max, Double_t step,Int_t index,Bool_t IsCopyConstructor) |
13f28255 | 263 | { |
264 | // | |
265 | // Set fixed bins | |
266 | // | |
e0baff8c | 267 | |
15d5fd02 | 268 | if (index >= kFcnBinTypes) { |
269 | AliError(Form("We support only %d Binning cuts(0-%d). Skipping...",kFcnBinTypes,kFcnBinTypes-1)); | |
270 | return; | |
271 | } | |
272 | ||
273 | if (!IsCopyConstructor){ | |
274 | // TODO if some one sets indexes 0,2,3 it is a bug here(i'll solve it) | |
275 | if (index == fNumberOfBinTypes) | |
276 | fNumberOfBinTypes++; | |
277 | else { | |
278 | AliError(Form("Wrong index %d. fUseBins is set to kFALSE",index)); | |
279 | // fUseBins = kFALSE; | |
280 | return; | |
281 | } | |
282 | } | |
13f28255 | 283 | |
15d5fd02 | 284 | fUseBins = kTRUE; |
13f28255 | 285 | Int_t i, nBins = (Int_t)((max - min) / step) + 1; |
15d5fd02 | 286 | fBinningCutType[index] = type; |
287 | fBins[index].Set(nBins); | |
e0baff8c | 288 | for (i = 0; i < nBins; i++) |
289 | { | |
15d5fd02 | 290 | fBins[index][i] = min + (Double_t)i * step; |
13f28255 | 291 | } |
292 | } | |
293 | ||
294 | //________________________________________________________________________________________ | |
295 | void AliRsnFunction::SetBinningCut | |
15d5fd02 | 296 | (AliRsnCut::EType type, Int_t nbins, Double_t *bins,Int_t index,Bool_t IsCopyConstructor) |
13f28255 | 297 | { |
298 | // | |
299 | // Set variable bins | |
300 | // | |
301 | ||
15d5fd02 | 302 | if (index >= kFcnBinTypes) { |
303 | AliError(Form("We support only %d Binning cuts(0-%d). Skipping...",kFcnBinTypes,kFcnBinTypes-1)); | |
304 | return; | |
305 | } | |
306 | if (!IsCopyConstructor){ | |
307 | // TODO if some one sets indexes 0,2,3 it is a bug here(i'll solve it) | |
308 | if (index >= fNumberOfBinTypes) | |
309 | fNumberOfBinTypes++; | |
310 | else { | |
311 | AliError(Form("Wrong index %d (%d). fUseBins is set to kFALSE",index,fNumberOfBinTypes)); | |
312 | // fUseBins = kFALSE; | |
313 | return; | |
314 | } | |
315 | } | |
13f28255 | 316 | |
15d5fd02 | 317 | fUseBins = kTRUE; |
13f28255 | 318 | Int_t i; |
15d5fd02 | 319 | fBinningCutType[index] = type; |
320 | fBins[index].Set(nbins); | |
e0baff8c | 321 | for (i = 0; i < nbins; i++) |
322 | { | |
15d5fd02 | 323 | fBins[index][i] = bins[i]; |
13f28255 | 324 | } |
325 | } | |
326 | ||
327 | //________________________________________________________________________________________ | |
328 | TString AliRsnFunction::GetFcnName() | |
329 | { | |
330 | // | |
331 | // Return a string which names the function type | |
332 | // | |
333 | ||
334 | TString text("Undef"); | |
335 | ||
e0baff8c | 336 | switch (fFcnType) |
337 | { | |
338 | case kInvMass: | |
339 | text = "IM"; | |
340 | break; | |
341 | case kInvMassMC: | |
342 | text = "IM_MC"; | |
343 | break; | |
344 | case kInvMassRotated: | |
345 | text = Form("IMR%.2f", fRotAngle); | |
346 | break; | |
347 | case kResolution: | |
348 | text = "RES"; | |
349 | break; | |
350 | case kPtSpectrum: | |
351 | text = "PT"; | |
0ef90328 | 352 | break; |
353 | case kEtaSpectrum: | |
354 | text = "ETA"; | |
355 | break; | |
e0baff8c | 356 | default: |
357 | AliError("Type not defined"); | |
13f28255 | 358 | } |
e0baff8c | 359 | |
13f28255 | 360 | return text; |
361 | } | |
362 | ||
363 | //________________________________________________________________________________________ | |
364 | TString AliRsnFunction::GetFcnTitle() | |
365 | { | |
366 | // | |
367 | // Return a string which names the function type | |
368 | // | |
e0baff8c | 369 | |
13f28255 | 370 | TString text("Undef"); |
371 | ||
e0baff8c | 372 | switch (fFcnType) |
373 | { | |
374 | case kInvMass: | |
375 | text = "Invariant mass"; | |
376 | break; | |
377 | case kInvMassMC: | |
378 | text = "Invariant mass (MC)"; | |
379 | break; | |
380 | case kResolution: | |
381 | text = "Resolution"; | |
382 | break; | |
383 | case kPtSpectrum: | |
384 | text = "p_{#perp} distribution"; | |
0ef90328 | 385 | break; |
386 | case kEtaSpectrum: | |
387 | text = "#eta distribution"; | |
388 | break; | |
e0baff8c | 389 | default: |
390 | AliError("Type not defined"); | |
13f28255 | 391 | } |
e0baff8c | 392 | |
13f28255 | 393 | return text; |
394 | } | |
395 | ||
396 | //________________________________________________________________________________________ | |
15d5fd02 | 397 | Bool_t AliRsnFunction::Fill(AliRsnPairParticle *pair, AliRsnPairDef *ref) |
13f28255 | 398 | { |
399 | // | |
400 | // Fillse the histogram with data contained in a defined pair. | |
401 | // This method must be overidden by an appropriate definition in each inheriting class. | |
402 | // | |
403 | ||
404 | Double_t value = FcnValue(pair, ref); | |
405 | if (fSkipOutsideInterval) | |
e0baff8c | 406 | { |
407 | if (value < fHistoDef->GetMin()) return kFALSE; | |
408 | if (value > fHistoDef->GetMax()) return kFALSE; | |
409 | } | |
410 | ||
13f28255 | 411 | // fill global histogram |
15d5fd02 | 412 | fHisto[0][0]->Fill(value); |
e0baff8c | 413 | |
13f28255 | 414 | // if bins are allocated, find right one and fill it |
e0baff8c | 415 | if (fUseBins) |
416 | { | |
15d5fd02 | 417 | Int_t i, j, ibin; |
418 | for (j = 0 ; j < kFcnBinTypes; j++){ | |
419 | if (fNumberOfBinTypes<=j) continue; | |
420 | for (ibin = 0, i = 1; ibin < fBins[j].GetSize() - 1; ibin++, i++) | |
e0baff8c | 421 | { |
15d5fd02 | 422 | if (!fHisto[j][i]) continue; |
423 | fBinningCut[j].SetCutValues(fBinningCutType[j], fBins[j][ibin], fBins[j][ibin+1]); | |
424 | if (fBinningCut[j].IsSelected(AliRsnCut::kPair, pair)) | |
425 | { | |
426 | fHisto[j][i]->Fill(value); | |
427 | break; | |
428 | } | |
13f28255 | 429 | } |
430 | } | |
431 | } | |
e0baff8c | 432 | |
13f28255 | 433 | return kTRUE; |
434 | } | |
435 | ||
436 | //________________________________________________________________________________________ | |
437 | Double_t AliRsnFunction::FcnValue(AliRsnPairParticle *pair, AliRsnPairDef *ref) | |
438 | { | |
439 | // | |
440 | // This method must be overridden in all inheritin functions. | |
441 | // It computes the value which must be used to fill the histogram. | |
442 | // | |
443 | ||
e0baff8c | 444 | switch (fFcnType) |
445 | { | |
446 | case kInvMass: | |
447 | return pair->GetInvMass(ref->GetMass(0), ref->GetMass(1)); | |
448 | case kInvMassMC: | |
449 | return pair->GetInvMassMC(ref->GetMass(0), ref->GetMass(1)); | |
450 | case kInvMassRotated: | |
451 | //AliInfo(Form("*** ROTATION ANGLE = %f ***", fRotAngle)); | |
452 | //AliInfo(Form("UNROTATED INV MASS = %f", pair->GetInvMass(ref->GetMass(0), ref->GetMass(1)))); | |
453 | //pair->GetDaughter(1)->Print("P"); | |
454 | pair->GetDaughter(1)->RotateP(fRotAngle * TMath::DegToRad()); | |
455 | pair->ResetPair(); | |
456 | //AliInfo(Form(" ROTATED INV MASS = %f", pair->GetInvMass(ref->GetMass(0), ref->GetMass(1)))); | |
457 | //pair->GetDaughter(1)->Print("P"); | |
458 | return pair->GetInvMass(ref->GetMass(0), ref->GetMass(1)); | |
459 | case kResolution: | |
460 | return FcnResolution(pair, ref); | |
461 | case kPtSpectrum: | |
462 | return pair->GetPt(); | |
0ef90328 | 463 | case kEtaSpectrum: |
464 | return pair->GetEta(); | |
e0baff8c | 465 | default: |
466 | AliError("Type not defined"); | |
13f28255 | 467 | } |
e0baff8c | 468 | |
13f28255 | 469 | return 0.0; |
470 | } | |
471 | ||
472 | //________________________________________________________________________________________ | |
473 | inline Double_t AliRsnFunction::FcnResolution(AliRsnPairParticle *pair, AliRsnPairDef *ref) | |
474 | { | |
475 | // | |
476 | // Invariant mass resolution (compared between reconstructed and montecarlo) | |
477 | // | |
478 | ||
479 | Double_t recInvMass = pair->GetInvMass(ref->GetMass(0), ref->GetMass(1)); | |
480 | Double_t simInvMass = pair->GetInvMassMC(ref->GetMass(0), ref->GetMass(1)); | |
e0baff8c | 481 | |
13f28255 | 482 | return (simInvMass - recInvMass) / simInvMass; |
483 | } |