]> git.uio.no Git - u/mrichter/AliRoot.git/blob - CORRFW/AliCFContainer.cxx
some cleanup
[u/mrichter/AliRoot.git] / CORRFW / AliCFContainer.cxx
1 /* $Id$ */
2
3 //--------------------------------------------------------------------//
4 //                                                                    //
5 // AliCFContainer Class                                           //
6 // Class to accumulate data on an N-dimensional grids, at different    //
7 // selection stages. To be used as an input to get corrections for    //
8 // Reconstruction & Trigger efficiency                                // 
9 //                                                                    //
10 // -- Author : S.Arcelli                                              //
11 //--------------------------------------------------------------------//
12 //
13 //
14 #include <AliLog.h>
15 #include "AliCFGrid.h"
16 #include "AliCFContainer.h"
17
18 //____________________________________________________________________
19 ClassImp(AliCFContainer)
20
21 //____________________________________________________________________
22 AliCFContainer::AliCFContainer() : 
23   AliCFFrame(),
24   fNStep(0),
25   fGrid(0x0)
26 {
27   //
28   // default constructor
29   //
30 }
31 //____________________________________________________________________
32 AliCFContainer::AliCFContainer(const Char_t* name, const Char_t* title) : 
33   AliCFFrame(name,title),
34   fNStep(0),
35   fGrid(0x0)
36 {
37   // default constructor
38 }
39
40 //____________________________________________________________________
41 AliCFContainer::AliCFContainer(const Char_t* name, const Char_t* title,const Int_t nSelSteps, const Int_t nVarIn, const Int_t * nBinIn, const Float_t *binLimitsIn) :  
42   AliCFFrame(name,title,nVarIn,nBinIn,binLimitsIn),
43   fNStep(0),
44   fGrid(0x0)
45 {
46   //
47   // main constructor
48   //
49
50   // The selection steps
51   fNStep=nSelSteps;
52
53   // The grids 
54   fGrid = new AliCFGrid*[fNStep]; //the grids at the various selection steps
55   char gname[30];
56   for(Int_t istep=0;istep<fNStep;istep++){
57     sprintf(gname,"%s%s%i",GetName(),"_SelStep", istep);
58     fGrid[istep] = new AliCFGrid(gname,title,nVarIn,nBinIn,binLimitsIn); 
59   }
60 }
61 //____________________________________________________________________
62 AliCFContainer::AliCFContainer(const AliCFContainer& c) : 
63   AliCFFrame(),
64   fNStep(0),
65   fGrid(0x0)
66 {
67   //
68   // copy constructor
69   //
70   ((AliCFContainer &)c).Copy(*this);
71 }
72 //____________________________________________________________________
73 AliCFContainer::~AliCFContainer()
74 {
75   //
76   // destructor
77   //
78   if(fGrid)delete [] fGrid;
79
80 }
81 //____________________________________________________________________
82 AliCFContainer &AliCFContainer::operator=(const AliCFContainer &c)
83 {
84   //
85   // assigment operator
86   //
87   if (this != &c)
88     ((AliCFContainer &) c).Copy(*this);
89   return *this;
90
91 //____________________________________________________________________
92 void AliCFContainer::SetBinLimits(Int_t varindex, Float_t *array)
93 {
94   //
95   // setting the arrays containing the bin limits 
96   //
97   Int_t nbins=fNVarBins[varindex]+1;
98   for(Int_t i=0;i<nbins;i++){
99     fVarBinLimits[fOffset[varindex]+i] =array[i];
100   } 
101   for(Int_t istep=0;istep<fNStep;istep++){
102     fGrid[istep]->SetBinLimits(varindex,array);
103   }
104
105 //____________________________________________________________________
106 void AliCFContainer::Copy(TObject& c) const
107 {
108   //
109   // copy function
110   //
111   AliCFContainer& target = (AliCFContainer &) c;
112   target.fNStep=fNStep;
113   target.fNVar=fNVar;
114   target.fNDim=fNDim;
115   target.fNVarBinLimits=fNVarBinLimits;
116   if (fNVarBins)
117     target.fNVarBins = fNVarBins;
118   if (fVarBinLimits)
119     target.fVarBinLimits = fVarBinLimits;
120   if (fGrid)
121     target.fGrid = fGrid;
122     for(Int_t istep=0;istep<fNStep;istep++){
123       for(Int_t iel=0;iel<fNDim;iel++){
124         target.fGrid[istep]->SetElement(iel,fGrid[istep]->GetElement(iel));
125       } 
126     }  
127 }
128 //____________________________________________________________________
129 void AliCFContainer::Fill(Float_t *var, Int_t istep, Float_t weight)
130 {
131   //
132   // Fills the grid at selection step istep for a set of values of the 
133   // input variables, with a given weight (by default w=1)
134   //
135   fGrid[istep]->Fill(var,weight);
136 }
137 //___________________________________________________________________
138 TH1F *AliCFContainer::ShowProjection(Int_t ivar, Int_t istep) const
139 {
140   //
141   // returns 1-D projection along variable ivar at selection step istep
142   //
143   return fGrid[istep]->Project(ivar);
144 }
145 //___________________________________________________________________
146 TH2F *AliCFContainer::ShowProjection(Int_t ivar1, Int_t ivar2, Int_t istep) const
147 {
148   //
149   // returns 2-D projection along variables ivar1,ivar2 at selection step istep
150   //
151   return fGrid[istep]->Project(ivar1,ivar2);
152 }
153 //___________________________________________________________________
154 TH3F *AliCFContainer::ShowProjection(Int_t ivar1, Int_t ivar2, Int_t ivar3, Int_t istep) const
155 {
156   //
157   // returns 3-D projection along variables ivar1,ivar2,ivar3 
158   // at selection step istep
159   //
160   return fGrid[istep]->Project(ivar1,ivar2,ivar3);
161 }
162 //___________________________________________________________________
163 TH1F *AliCFContainer::ShowSlice(Int_t ivar, Float_t *varMin, Float_t* varMax, Int_t istep) const
164 {
165   //
166   // Make a slice along variable ivar at selection level istep in range [varMin,varMax]
167   //
168   return (TH1F*)fGrid[istep]->Slice(ivar,varMin,varMax);
169 }
170 //____________________________________________________________________
171 Long64_t AliCFContainer::Merge(TCollection* list)
172 {
173   // Merge a list of AliCorrection objects with this (needed for
174   // PROOF). 
175   // Returns the number of merged objects (including this).
176
177   if (!list)
178     return 0;
179   
180   if (list->IsEmpty())
181     return 1;
182
183   TIterator* iter = list->MakeIterator();
184   TObject* obj;
185   
186   Int_t count = 0;
187   while ((obj = iter->Next())) {
188     AliCFContainer* entry = dynamic_cast<AliCFContainer*> (obj);
189     if (entry == 0) 
190       continue;
191     this->Add(entry);
192     count++;
193   }
194
195   return count+1;
196 }
197
198 //____________________________________________________________________
199 void AliCFContainer::Add(AliCFContainer* aContainerToAdd, Float_t c)
200 {
201   //
202   //add the content of container aContainerToAdd to the current one
203   //
204
205   if(aContainerToAdd->GetNStep()!=fNStep)AliError("Different number of steps, cannot add the containers");
206   if(aContainerToAdd->GetNVar()!=fNVar)AliError("Different number of variables, cannot add the containers");
207   if(aContainerToAdd->GetNDim()!=fNDim)AliError("Different number of dimensions, cannot add the containers!");
208   
209   for(Int_t istep=0;istep<fNStep;istep++){
210     fGrid[istep]->Add(aContainerToAdd->GetGrid(istep),c);
211   }
212 }
213 //____________________________________________________________________
214 Float_t AliCFContainer::GetOverFlows( Int_t ivar, Int_t istep) const {
215   //
216   // Get overflows in variable var at selection level istep
217   //
218   return fGrid[istep]->GetOverFlows(ivar);
219
220 //____________________________________________________________________
221 Float_t AliCFContainer::GetOverFlows( Int_t istep) const {
222   //
223   // Get overflows in variable var at selection level istep
224   //
225   return fGrid[istep]->GetOverFlows();
226
227 //____________________________________________________________________
228 Float_t AliCFContainer::GetUnderFlows( Int_t ivar, Int_t istep) const {
229   //
230   // Get overflows in variable var at selection level istep
231   //
232   return fGrid[istep]->GetUnderFlows(ivar);
233
234 //____________________________________________________________________
235 Float_t AliCFContainer::GetUnderFlows( Int_t istep) const {
236   //
237   // Get overflows in variable var at selection level istep
238   //
239   return fGrid[istep]->GetUnderFlows();
240
241 //____________________________________________________________________
242 Float_t AliCFContainer::GetEntries( Int_t istep) const {
243   //
244   // Get overflows in variable var at selection level istep
245   //
246   return fGrid[istep]->GetEntries();
247
248 //____________________________________________________________________
249 Int_t AliCFContainer::GetEmptyBins( Int_t istep) const {
250   //
251   // Get overflows in variable var at selection level istep
252   //
253   return fGrid[istep]->GetEmptyBins();
254
255 //____________________________________________________________________
256 Int_t AliCFContainer::GetEmptyBins( Int_t istep, Float_t *varMin, Float_t* varMax) const {
257   //
258   // Get overflows in variable var at selection level istep
259   //
260   return fGrid[istep]->GetEmptyBins(varMin,varMax);
261
262 //_____________________________________________________________________
263 Float_t AliCFContainer::GetIntegral( Int_t istep) const 
264 {
265   //
266   // Get Integral at selection level istep
267   //
268   return fGrid[istep]->GetIntegral();
269 }
270 //_____________________________________________________________________
271 Float_t AliCFContainer::GetIntegral( Int_t istep, Float_t *varMin, Float_t* varMax ) const 
272 {
273   //
274   // Get Integral at selection level istep
275   //
276   return fGrid[istep]->GetIntegral(varMin,varMax);
277 }