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