]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWG2/RESONANCES/AliRsnEventFunction.cxx
Main changes:
[u/mrichter/AliRoot.git] / PWG2 / RESONANCES / AliRsnEventFunction.cxx
1 //
2 // Class AliRsnEventFunction
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 <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 #include "AliRsnCutSet.h"
36
37 #include "AliRsnEventFunction.h"
38
39 ClassImp(AliRsnEventFunction)
40
41 //________________________________________________________________________________________
42 AliRsnEventFunction::AliRsnEventFunction() :
43   fType(kTypes),
44   fPIDMethod(AliRsnDaughter::kNoPID),
45   fPIDType(AliRsnPID::kUnknown),
46   fCharge('0'),
47   fLeadPtMin(0.0),
48   fAccept(kFALSE),
49   fUseBins(kFALSE),
50   fBins(0),
51   fBinningCut(),
52   fBinningCutType(AliRsnCut::kLastCutType),
53   fEventCuts(0x0),
54   fTrackCuts(0x0),
55   fHistoDef(0x0)
56 {
57   //
58   // Constructor.
59   // The histogram data member cannot be passed externally,
60   // its initialization MUST be defined inside the Init() method,
61   // which must be overridden in any derivate implementation.
62   //
63
64   Int_t i;
65   for (i = 0; i < 100; i++)
66   {
67     fHisto[i] = 0x0;
68   }
69 }
70
71 //________________________________________________________________________________________
72 AliRsnEventFunction::AliRsnEventFunction
73 (EType type, AliRsnHistoDef *hd, AliRsnDaughter::EPIDMethod pidMethod,
74  AliRsnPID::EType pidType, Char_t sign) :
75   fType(type),
76   fPIDMethod(pidMethod),
77   fPIDType(pidType),
78   fCharge(sign),
79   fLeadPtMin(0.0),
80   fAccept(kFALSE),
81   fUseBins(kFALSE),
82   fBins(0),
83   fBinningCut(),
84   fBinningCutType(AliRsnCut::kLastCutType),
85   fEventCuts(0x0),
86   fTrackCuts(0x0),
87   fHistoDef(hd)
88 {
89   //
90   // Constructor.
91   // The histogram data member cannot be passed externally,
92   // its initialization MUST be defined inside the Init() method,
93   // which must be overridden in any derivate implementation.
94   //
95
96   Int_t i;
97   for (i = 0; i < 100; i++)
98   {
99     fHisto[i] = 0x0;
100   }
101 }
102
103 //________________________________________________________________________________________
104 AliRsnEventFunction::AliRsnEventFunction(const AliRsnEventFunction &copy) :
105   TObject(copy),
106   fType(copy.fType),
107   fPIDMethod(copy.fPIDMethod),
108   fPIDType(copy.fPIDType),
109   fCharge(copy.fCharge),
110   fLeadPtMin(copy.fLeadPtMin),
111   fAccept(kFALSE),
112   fUseBins(copy.fUseBins),
113   fBins(0),
114   fBinningCut(),
115   fBinningCutType(AliRsnCut::kLastCutType),
116   fEventCuts(copy.fEventCuts),
117   fTrackCuts(copy.fTrackCuts),
118   fHistoDef(copy.fHistoDef)
119 {
120   //
121   // Constructor.
122   // The histogram data member cannot be passed externally,
123   // its initialization MUST be defined inside the Init() method,
124   // which must be overridden in any derivate implementation.
125   //
126
127   Int_t i, n = 100;
128   for (i = 0; i < n; i++)
129   {
130     fHisto[i] = 0x0;
131   }
132
133   if (fUseBins)
134   {
135     n = copy.fBins.GetSize();
136     Double_t *array = new Double_t[n];
137     for (i = 0; i < n; i++) array[i] = copy.fBins[i];
138     SetBinningCut(copy.fBinningCutType, copy.fBins.GetSize(), array);
139     delete [] array;
140   }
141 }
142
143 //________________________________________________________________________________________
144 void AliRsnEventFunction::Clear(Option_t* /*option*/)
145 {
146   //
147   // Clear arrays and histogram.
148   // For the sake of security, all pointers are also set explicitly to NULL.
149   //
150
151   Int_t i;
152   for (i = 0; i < 100; i++)
153   {
154     delete fHisto[i];
155     fHisto[i] = 0x0;
156   }
157 }
158
159 //________________________________________________________________________________________
160 void AliRsnEventFunction::Init(TList *histos)
161 {
162   //
163   // Initialization function.
164   // By default, it initializes the owned histogram using the method
165   // from AliRsnHistoDef class, giving the same name and title of this.
166   // A user can override this behaviour, if necessary.
167   // Before creating, the HistoDef is checked for proper initialization.
168   //
169
170   Clear();
171
172   Int_t i, ibin, nbins = fHistoDef->GetNBins();
173   Double_t min = fHistoDef->GetMin(), max = fHistoDef->GetMax();
174
175   // list is created and named after the general
176   // settings used for the contained histograms
177   if (!histos)
178   {
179     AliError("NULL target list!");
180     return;
181   }
182
183   // a general histogram is always added,
184   // which overrides the binning and collects everything
185   fHisto[0] = new TH1D(GetFcnName(), "", nbins, min, max);
186   histos->AddLast(fHisto[0]);
187
188   // if requested a binning w.r. to some cut variable, histograms are added
189   // for that in this part of the method (one per each bin)
190   Char_t hName[255];
191   if (fUseBins)
192   {
193     for (ibin = 0, i = 1; ibin < fBins.GetSize() - 1; ibin++, i++)
194     {
195       sprintf(hName, "%s[%.2f-%.2f]", GetFcnName().Data(), fBins[ibin], fBins[ibin+1]);
196       fHisto[i] = new TH1D(hName, "", nbins, min, max);
197       histos->AddLast(fHisto[i]);
198     }
199   }
200 }
201
202 //________________________________________________________________________________________
203 void AliRsnEventFunction::SetBinningCut
204 (AliRsnCut::EType type, Double_t min, Double_t max, Double_t step)
205 {
206   //
207   // Set fixed bins
208   //
209
210   fUseBins = kTRUE;
211
212   Int_t i, nBins = (Int_t)((max - min) / step) + 1;
213   fBinningCutType = type;
214   fBins.Set(nBins);
215   for (i = 0; i < nBins; i++)
216   {
217     fBins[i] = min + (Double_t)i * step;
218   }
219 }
220
221 //________________________________________________________________________________________
222 void AliRsnEventFunction::SetBinningCut
223 (AliRsnCut::EType type, Int_t nbins, Double_t *bins)
224 {
225   //
226   // Set variable bins
227   //
228
229   fUseBins = kTRUE;
230
231   Int_t i;
232   fBinningCutType = type;
233   fBins.Set(nbins);
234   for (i = 0; i < nbins; i++)
235   {
236     fBins[i] = bins[i];
237   }
238 }
239
240 //________________________________________________________________________________________
241 TString AliRsnEventFunction::GetFcnName()
242 {
243   //
244   // Return a string which names the function type
245   //
246
247   TString text("Undef");
248
249   switch (fType)
250   {
251     case kMultiplicity:
252       text = "MULT";
253       break;
254     case kLeadingMomentum:
255       text = "PLEAD";
256       break;
257     case kLeadingTheta:
258       text = "LEADTHETA";
259       break;
260     case kAverageMomentum:
261       text = "PAVG";
262       break;
263     case kAngleLeadingMean:
264       text = "ANGLEADMEAN";
265       break;
266     case kAngleLeadingRMS:
267       text = "ANGLEADRMS";
268       break;
269     case kVtResolution:
270       text = "VTRES";
271       break;
272     case kVzResolution:
273       text = "VZRES";
274       break;
275     default:
276       AliError("Type not defined");
277   }
278
279   switch (fPIDMethod)
280   {
281     case AliRsnDaughter::kNoPID:
282       text += "_NOPID_";
283       break;
284     case AliRsnDaughter::kPerfect:
285       text += "_PERFECT_";
286       break;
287     case AliRsnDaughter::kRealistic:
288       text += "_REALISTIC_";
289       break;
290     default:
291       AliError("PID method not defined");
292   }
293
294   text += AliRsnPID::ParticleName(fPIDType);
295   text += fCharge;
296
297   if (fEventCuts) {
298     text += '_';
299     text += fEventCuts->GetName();
300   }
301   if (fTrackCuts) {
302     text += '_';
303     text += fTrackCuts->GetName();
304   }
305
306   return text;
307 }
308
309 //________________________________________________________________________________________
310 Bool_t AliRsnEventFunction::Fill(AliRsnEvent *event)
311 {
312   //
313   // Fillse the histogram with data contained in a defined pair.
314   // This method must be overidden by an appropriate definition in each inheriting class.
315   //
316
317   if (fEventCuts) if (!fEventCuts->IsSelected(AliRsnCut::kEvent, event)) return kFALSE;
318
319   // first of all, set all selection definitions, using the ones in this object
320   event->SetSelectionPIDType(fPIDType);
321   event->SetSelectionCharge(fCharge);
322   event->SetSelectionPIDMethod(fPIDMethod);
323   event->SetSelectionTrackCuts(fTrackCuts);
324
325   Double_t value = FcnValue(event);
326   if (!fAccept) return kFALSE;
327
328   // fill global histogram
329   fHisto[0]->Fill(value);
330
331   // if bins are allocated, find right one and fill it
332   if (fUseBins)
333   {
334     Int_t i, ibin;
335     for (ibin = 0, i = 1; ibin < fBins.GetSize() - 1; ibin++, i++)
336     {
337       if (!fHisto[i]) continue;
338       fBinningCut.SetCutValues(fBinningCutType, (Double_t)fBins[ibin], (Double_t)fBins[ibin+1]);
339       fBinningCut.SetCutValues(fBinningCutType, (Int_t)fBins[ibin], (Int_t)fBins[ibin+1]);
340       if (fBinningCut.IsSelected(AliRsnCut::kEvent, event))
341       {
342         fHisto[i]->Fill(value);
343         break;
344       }
345     }
346   }
347
348   return kTRUE;
349 }
350
351 //________________________________________________________________________________________
352 Double_t AliRsnEventFunction::FcnValue(AliRsnEvent *event)
353 {
354   //
355   // This method must be overridden in all inheritin functions.
356   // It computes the value which must be used to fill the histogram.
357   //
358
359   Int_t count;
360   Double_t output, v[3], vMC[3], vt, vtMC, mean = 0.0, rms = 0.0;
361   AliRsnDaughter *trk = 0x0;
362
363   switch (fType)
364   {
365     case kMultiplicity:
366       fAccept = kTRUE;
367       output = (Double_t)event->GetMultiplicity();
368       break;
369     case kLeadingMomentum:
370       trk = event->GetLeadingParticle(fLeadPtMin);
371       if (trk) {
372         fAccept = kTRUE;
373         output = trk->P();
374       }
375       else {
376         fAccept = kFALSE;
377         output = 0.0;
378       }
379       break;
380     case kLeadingTheta:
381       trk = event->GetLeadingParticle(fLeadPtMin);
382       if (trk) {
383         fAccept = kTRUE;
384         output = trk->Theta();
385       }
386       else {
387         fAccept = kFALSE;
388         output = 0.0;
389       }
390       break;
391     case kAverageMomentum:
392       output = event->GetAverageMomentum(count);
393       fAccept = (count > 0);
394       break;
395     case kAngleLeadingMean:
396     case kAngleLeadingRMS:
397       fAccept = event->GetAngleDistrWRLeading(mean, rms, fLeadPtMin);
398       if (fType == kAngleLeadingMean) output = mean; else output = rms;
399       break;
400     case kVzResolution:
401     case kVtResolution:
402       fAccept = kTRUE;
403       v[0] = event->GetPrimaryVertexX();
404       v[1] = event->GetPrimaryVertexY();
405       v[2] = event->GetPrimaryVertexZ();
406       vMC[0] = event->GetPrimaryVertexXMC();
407       vMC[1] = event->GetPrimaryVertexYMC();
408       vMC[2] = event->GetPrimaryVertexZMC();
409       vt = TMath::Sqrt(v[0]*v[0] + v[1]*v[1]);
410       vtMC = TMath::Sqrt(vMC[0]*vMC[0] + vMC[1]*vMC[1]);
411       if (fType == kVtResolution) return (vt - vtMC); else return (v[2] - vMC[2]);
412       break;
413     default:
414       AliError(Form("Type '%d' not supported for EVENT functions", fType));
415       fAccept = kFALSE;
416       output = 0.0;
417   }
418
419   return output;
420 }
421