]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWG2/RESONANCES/AliRsnFunction.cxx
Class version updated.
[u/mrichter/AliRoot.git] / PWG2 / RESONANCES / AliRsnFunction.cxx
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 #include <TString.h>
24
25 #include "AliLog.h"
26
27 #include "AliRsnDaughter.h"
28 #include "AliRsnEvent.h"
29 #include "AliRsnPairDef.h"
30 #include "AliRsnCut.h"
31
32 #include "AliRsnFunction.h"
33
34 ClassImp(AliRsnFunction)
35
36 //________________________________________________________________________________________
37 AliRsnFunction::AliRsnFunction() :
38   TNamed(),
39   fPairDef(0x0),
40   fAxisList("AliRsnFunctionAxis", 0),
41   fTrack(0x0),
42   fPair(0x0),
43   fEvent(0x0),
44   fHistogram(0x0)
45 {
46 //
47 // Constructor.
48 //
49 }
50
51 //________________________________________________________________________________________
52 AliRsnFunction::AliRsnFunction(const AliRsnFunction &copy) :
53   TNamed(copy),
54   fPairDef(copy.fPairDef),
55   fAxisList(copy.fAxisList),
56   fTrack(copy.fTrack),
57   fPair(copy.fPair),
58   fEvent(copy.fEvent),
59   fHistogram(0x0)
60 {
61 //
62 // Copy constructor.
63 //
64 }
65
66 //________________________________________________________________________________________
67 const AliRsnFunction& AliRsnFunction::operator=(const AliRsnFunction& copy)
68 {
69 //
70 // Assignment operator.
71 //
72
73   SetName(copy.GetName());
74   SetTitle(copy.GetTitle());
75
76   fPairDef = copy.fPairDef;
77   fTrack = copy.fTrack;
78   fPair = copy.fPair;
79   fEvent = copy.fEvent;
80
81   if (fHistogram) delete fHistogram;
82   fHistogram = 0x0;
83
84   return (*this);
85 }
86
87 //________________________________________________________________________________________
88 const char* AliRsnFunction::GetName() const
89 {
90 //
91 // Defines the name of this object according to
92 // the function type and binning
93 //
94
95   TString name("");
96
97   TObjArrayIter next(&fAxisList);
98   AliRsnFunctionAxis *axis = 0;
99
100   while ( (axis = (AliRsnFunctionAxis*)next()) )
101   {
102     if (name.Length() > 1) name += '_';
103     name += axis->GetName();
104   }
105
106   return name.Data();
107 }
108
109 //________________________________________________________________________________________
110 void AliRsnFunction::AddAxis(AliRsnFunctionAxis *axis)
111 {
112   Int_t size = fAxisList.GetEntries();
113   new (fAxisList[size]) AliRsnFunctionAxis(*axis);
114 }
115
116 //________________________________________________________________________________________
117 THnSparseD* AliRsnFunction::CreateHistogram(const char *histoName, const char *histoTitle)
118 {
119 //
120 // Creates and returns the histogram defined using
121 // arguments fo name and title, and the first histoDef for binning.
122 // Variable-sized histogram binning is always called, due to use of histoDef,
123 // even if the bins are equal, since they are defined in this class.
124 // Eventually present histoDef's in other slots of array (1, 2) are ignored.
125 //
126
127   Int_t size = fAxisList.GetEntries();
128   if (!size) {
129     AliError("No axes defined");
130     return 0x0;
131   }
132
133   static Int_t    *nbins = new Int_t[size];
134   static Double_t *min   = new Double_t[size];
135   static Double_t *max   = new Double_t[size];
136
137   // retrieve binnings for main and secondary axes
138   AliRsnFunctionAxis *fcnAxis = 0;
139   for (Int_t i = 0; i < size; i++)
140   {
141     fcnAxis = (AliRsnFunctionAxis*)fAxisList.At(i);
142     if (!fcnAxis) {
143       nbins[i] = 0;
144       min[i] = 0.0;
145       max[i] = 0.0;
146       AliError("Empty axis");
147       continue;
148     }
149     nbins[i] = fcnAxis->GetNBins();
150     min[i] = fcnAxis->GetMin();
151     max[i] = fcnAxis->GetMax();
152   }
153
154   // create histogram
155   fHistogram = new THnSparseD(histoName, histoTitle, size, nbins, min, max);
156   fHistogram->Sumw2();
157
158   return fHistogram;
159 }
160
161 //________________________________________________________________________________________
162 Bool_t AliRsnFunction::Fill()
163 {
164 //
165 // Fill function histogram with values computed from given input object.
166 //
167
168   AliDebug(AliLog::kDebug +2,"->");
169
170   Int_t  i, nAxes = fAxisList.GetEntries();
171   static Double_t *values = new Double_t[nAxes];
172
173   AliRsnFunctionAxis *fcnAxis = 0;
174   for (i = 0; i < nAxes; i++)
175   {
176     fcnAxis = (AliRsnFunctionAxis*)fAxisList.At(i);
177     if (!fcnAxis) {
178       values[i] = 0.0;
179       continue;
180     }
181     switch (fcnAxis->GetAxisObject())
182     {
183       case AliRsnFunctionAxis::kParticle:
184         values[i] = fcnAxis->Eval(fTrack);
185         break;
186       case AliRsnFunctionAxis::kPair:
187         values[i] = fcnAxis->Eval(fPair, fPairDef);
188         break;
189       case AliRsnFunctionAxis::kEvent:
190         values[i] = fcnAxis->Eval(fEvent);
191         break;
192       default:
193         values[i] = 0.0;
194     }
195   }
196
197   // check presence of output histogram
198   if (!fHistogram) {
199     AliError("Histogram is not yet initialized");
200     return kFALSE;
201   }
202   fHistogram->Fill(values);
203
204   AliDebug(AliLog::kDebug +2,"->");
205   return kTRUE;
206 }