]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWG2/RESONANCES/AliRsnFunction.cxx
Modifications in analysis tasks for train
[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 <TString.h>
23
24 #include "AliLog.h"
25
26 #include "AliRsnDaughter.h"
27 #include "AliRsnEvent.h"
28 #include "AliRsnPairDef.h"
29 #include "AliRsnPairParticle.h"
30 #include "AliRsnFunctionAxis.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     if (name.Length() > 1) name += '_';
102     name += axis->GetName();
103   }
104
105   return name.Data();
106 }
107
108 //________________________________________________________________________________________
109 void AliRsnFunction::AddAxis(AliRsnFunctionAxis *const axis)
110 {
111   Int_t size = fAxisList.GetEntries();
112   new(fAxisList[size]) AliRsnFunctionAxis(*axis);
113 }
114
115 //________________________________________________________________________________________
116 THnSparseD* AliRsnFunction::CreateHistogram(const char *histoName, const char *histoTitle)
117 {
118 //
119 // Creates and returns the histogram defined using
120 // arguments fo name and title, and the first histoDef for binning.
121 // Variable-sized histogram binning is always called, due to use of histoDef,
122 // even if the bins are equal, since they are defined in this class.
123 // Eventually present histoDef's in other slots of array (1, 2) are ignored.
124 //
125
126   Int_t size = fAxisList.GetEntries();
127   if (!size) {
128     AliError("No axes defined");
129     return 0x0;
130   }
131
132   Int_t    *nbins = new Int_t[size];
133   Double_t *min   = new Double_t[size];
134   Double_t *max   = new Double_t[size];
135
136   // retrieve binnings for main and secondary axes
137   AliRsnFunctionAxis *fcnAxis = 0;
138   for (Int_t i = 0; i < size; i++) {
139     fcnAxis = (AliRsnFunctionAxis*)fAxisList.At(i);
140     if (!fcnAxis) {
141       nbins[i] = 0;
142       min[i] = 0.0;
143       max[i] = 0.0;
144       AliError("Empty axis");
145       continue;
146     }
147     nbins[i] = fcnAxis->GetNBins();
148     min[i] = fcnAxis->GetMin();
149     max[i] = fcnAxis->GetMax();
150   }
151
152   // create histogram
153   fHistogram = new THnSparseD(histoName, histoTitle, size, nbins, min, max);
154   fHistogram->Sumw2();
155
156   return fHistogram;
157 }
158
159 //________________________________________________________________________________________
160 Bool_t AliRsnFunction::Fill()
161 {
162 //
163 // Fill function histogram with values computed from given input object.
164 //
165
166   AliDebug(AliLog::kDebug +2,"->");
167
168   Int_t  i, nAxes = fAxisList.GetEntries();
169   Double_t *values = new Double_t[nAxes];
170
171   AliRsnFunctionAxis *fcnAxis = 0;
172   for (i = 0; i < nAxes; i++) {
173     fcnAxis = (AliRsnFunctionAxis*)fAxisList.At(i);
174     if (!fcnAxis) {
175       values[i] = 0.0;
176       continue;
177     }
178     switch (fcnAxis->GetAxisObject()) {
179     case AliRsnFunctionAxis::kParticle:
180       values[i] = fcnAxis->Eval(fTrack);
181       break;
182     case AliRsnFunctionAxis::kPair:
183       values[i] = fcnAxis->Eval(fPair, fPairDef);
184       break;
185     case AliRsnFunctionAxis::kEvent:
186       values[i] = fcnAxis->Eval(fEvent);
187       break;
188     default:
189       values[i] = 0.0;
190     }
191   }
192
193   // check presence of output histogram
194   if (!fHistogram) {
195     AliError("Histogram is not yet initialized");
196     return kFALSE;
197   }
198   //TArrayD val(values); val->Print();
199   fHistogram->Fill(values);
200
201   AliDebug(AliLog::kDebug +2,"->");
202   return kTRUE;
203 }