]> git.uio.no Git - u/mrichter/AliRoot.git/blob - CORRFW/AliCFContainer.cxx
Putting real capa values
[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   fExclOffEntriesInProj(kTRUE),
40   fGrid(0x0)
41 {
42   //
43   // default constructor
44   //
45 }
46 //____________________________________________________________________
47 AliCFContainer::AliCFContainer(const Char_t* name, const Char_t* title) : 
48   AliCFFrame(name,title),
49   fNStep(0),
50   fExclOffEntriesInProj(kTRUE),
51   fGrid(0x0)
52 {
53   // default constructor
54 }
55
56 //____________________________________________________________________
57 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) :  
58   AliCFFrame(name,title,nVarIn,nBinIn,binLimitsIn),
59   fNStep(0),
60   fExclOffEntriesInProj(kTRUE),
61   fGrid(0x0)
62 {
63   //
64   // main constructor
65   //
66
67   // The selection steps
68   fNStep=nSelSteps;
69
70   // The grids 
71   fGrid = new AliCFVGrid*[fNStep]; //the grids at the various selection steps
72   char gname[30];
73   for(Int_t istep=0;istep<fNStep;istep++){
74     sprintf(gname,"%s%s%i",GetName(),"_SelStep", istep);
75     if(!useSparse){
76       fGrid[istep] = new AliCFGrid(gname,title,nVarIn,nBinIn,binLimitsIn); 
77       }
78     else{
79       fGrid[istep] = new AliCFGridSparse(gname,title,nVarIn,nBinIn,binLimitsIn); 
80     }
81     fGrid[istep]->SumW2(); 
82   }
83 }
84 //____________________________________________________________________
85 AliCFContainer::AliCFContainer(const AliCFContainer& c) : 
86   AliCFFrame(),
87   fNStep(c.fNStep),
88   fExclOffEntriesInProj(c.fExclOffEntriesInProj),
89   fGrid(c.fGrid)
90 {
91   //
92   // copy constructor
93   //
94   ((AliCFContainer &)c).Copy(*this);
95 }
96 //____________________________________________________________________
97 AliCFContainer::~AliCFContainer()
98 {
99   //
100   // destructor
101   //
102   if(fGrid)delete [] fGrid;
103
104 }
105 //____________________________________________________________________
106 AliCFContainer &AliCFContainer::operator=(const AliCFContainer &c)
107 {
108   //
109   // assigment operator
110   //
111   if (this != &c)
112     ((AliCFContainer &) c).Copy(*this);
113   return *this;
114
115 //____________________________________________________________________
116 void AliCFContainer::SetBinLimits(Int_t varindex, Double_t *array)
117 {
118   //
119   // setting the arrays containing the bin limits 
120   //
121   Int_t nbins=fNVarBins[varindex]+1;
122   for(Int_t i=0;i<nbins;i++){
123     fVarBinLimits[fOffset[varindex]+i] =array[i];
124   } 
125   for(Int_t istep=0;istep<fNStep;istep++){
126     fGrid[istep]->SetBinLimits(varindex,array);
127   }
128
129 //____________________________________________________________________
130 void AliCFContainer::Copy(TObject& c) const
131 {
132   //
133   // copy function
134   //
135   AliCFContainer& target = (AliCFContainer &) c;
136   target.fNStep=fNStep;
137   target.fExclOffEntriesInProj=fExclOffEntriesInProj;
138   target.fNVar=fNVar;
139   target.fNDim=fNDim;
140   target.fNVarBinLimits=fNVarBinLimits;
141   if (fNVarBins)
142     target.fNVarBins = fNVarBins;
143   if (fVarBinLimits)
144     target.fVarBinLimits = fVarBinLimits;
145   if (fGrid)
146     target.fGrid = fGrid;
147     for(Int_t istep=0;istep<fNStep;istep++){
148       for(Int_t iel=0;iel<fNDim;iel++){
149         target.fGrid[istep]->SetElement(iel,fGrid[istep]->GetElement(iel));
150       } 
151     }  
152 }
153 //____________________________________________________________________
154 void AliCFContainer::Fill(Double_t *var, Int_t istep, Double_t weight)
155 {
156   //
157   // Fills the grid at selection step istep for a set of values of the 
158   // input variables, with a given weight (by default w=1)
159   //
160   if(istep >= fNStep || istep < 0){
161     AliError("Non-existent selection step, grid was not filled");
162     return;
163   }
164   fGrid[istep]->Fill(var,weight);
165 }
166 //___________________________________________________________________
167 TH1D *AliCFContainer::ShowProjection(Int_t ivar, Int_t istep) const
168 {
169   //
170   // returns 1-D projection along variable ivar at selection step istep
171   //
172   if(istep >= fNStep || istep < 0){
173     AliError("Non-existent selection step, return NULL");
174     return 0x0;
175   }
176   fGrid[istep]->SetExcludeOffEntriesInProj(fExclOffEntriesInProj);
177   return fGrid[istep]->Project(ivar);
178 }
179 //___________________________________________________________________
180 TH2D *AliCFContainer::ShowProjection(Int_t ivar1, Int_t ivar2, Int_t istep) const
181 {
182   //
183   // returns 2-D projection along variables ivar1,ivar2 at selection step istep
184   //
185   if(istep >= fNStep || istep < 0){
186     AliError("Non-existent selection step, return NULL");
187     return 0x0;
188   }
189   fGrid[istep]->SetExcludeOffEntriesInProj(fExclOffEntriesInProj);
190   return fGrid[istep]->Project(ivar1,ivar2);
191 }
192 //___________________________________________________________________
193 TH3D *AliCFContainer::ShowProjection(Int_t ivar1, Int_t ivar2, Int_t ivar3, Int_t istep) const
194 {
195   //
196   // returns 3-D projection along variables ivar1,ivar2,ivar3 
197   // at selection step istep
198   //
199   if(istep >= fNStep || istep < 0){
200     AliError("Non-existent selection step, return NULL");
201     return 0x0;
202   }
203   fGrid[istep]->SetExcludeOffEntriesInProj(fExclOffEntriesInProj);
204   return fGrid[istep]->Project(ivar1,ivar2,ivar3);
205 }
206 //___________________________________________________________________
207 TH1D *AliCFContainer::ShowSlice(Int_t ivar, Double_t *varMin, Double_t* varMax, Int_t istep) const
208 {
209   //
210   // Make a slice along variable ivar at selection level istep in range [varMin,varMax]
211   //
212   if(istep >= fNStep || istep < 0){
213     AliError("Non-existent selection step, return NULL");
214     return 0x0;
215   }
216   return (TH1D*)fGrid[istep]->Slice(ivar,varMin,varMax);
217 }
218 //____________________________________________________________________
219 Long64_t AliCFContainer::Merge(TCollection* list)
220 {
221   // Merge a list of AliCorrection objects with this (needed for
222   // PROOF). 
223   // Returns the number of merged objects (including this).
224
225   if (!list)
226     return 0;
227   
228   if (list->IsEmpty())
229     return 1;
230
231   TIterator* iter = list->MakeIterator();
232   TObject* obj;
233   
234   Int_t count = 0;
235   while ((obj = iter->Next())) {
236     AliCFContainer* entry = dynamic_cast<AliCFContainer*> (obj);
237     if (entry == 0) 
238       continue;
239     this->Add(entry);
240     count++;
241   }
242
243   return count+1;
244 }
245
246 //____________________________________________________________________
247 void AliCFContainer::Add(AliCFContainer* aContainerToAdd, Double_t c)
248 {
249   //
250   //add the content of container aContainerToAdd to the current one
251   //
252   if( (aContainerToAdd->GetNStep()!=fNStep)
253       ||
254       (aContainerToAdd->GetNVar()!=fNVar)
255       ||
256       (aContainerToAdd->GetNDim()!=fNDim)){
257     AliError("Different number of steps/sensitive variables/grid elements: cannot add the containers");
258     return;
259   }
260   for(Int_t istep=0;istep<fNStep;istep++){
261     fGrid[istep]->Add(aContainerToAdd->GetGrid(istep),c);
262   }
263 }
264 //____________________________________________________________________
265 Float_t AliCFContainer::GetOverFlows( Int_t ivar, Int_t istep) const {
266   //
267   // Get overflows in variable var at selection level istep
268   //
269   if(istep >= fNStep || istep < 0){
270     AliError("Non-existent selection step, return -1");
271     return -1.;
272   }
273   return fGrid[istep]->GetOverFlows(ivar);
274
275 //____________________________________________________________________
276 Float_t AliCFContainer::GetUnderFlows( Int_t ivar, Int_t istep) const {
277   //
278   // Get underflows in variable var at selection level istep
279   //
280   if(istep >= fNStep || istep < 0){
281     AliError("Non-existent selection step, return -1");
282     return -1.;
283   }
284   return fGrid[istep]->GetUnderFlows(ivar);
285
286 //____________________________________________________________________
287 Float_t AliCFContainer::GetEntries( Int_t istep) const {
288   //
289   // Get total entries in variable var at selection level istep
290   //
291   if(istep >= fNStep || istep < 0){
292     AliError("Non-existent selection step, return -1");
293     return -1.;
294   }
295   return fGrid[istep]->GetEntries();
296
297 //____________________________________________________________________
298 Int_t AliCFContainer::GetEmptyBins( Int_t istep) const {
299   //
300   // Get empty bins in variable var at selection level istep
301   //
302   if(istep >= fNStep || istep < 0){
303     AliError("Non-existent selection step, return -1");
304     return -1;
305   }
306   return fGrid[istep]->GetEmptyBins();
307
308 //____________________________________________________________________
309 Int_t AliCFContainer::GetEmptyBins( Int_t istep, Double_t *varMin, Double_t* varMax) const {
310   //
311   // Get empty bins in a range in variable var at selection level istep
312   //
313   if(istep >= fNStep || istep < 0){
314     AliError("Non-existent selection step, return -1");
315     return -1;
316   }
317   return fGrid[istep]->GetEmptyBins(varMin,varMax);
318
319 //_____________________________________________________________________
320 Double_t AliCFContainer::GetIntegral( Int_t istep) const 
321 {
322   //
323   // Get Integral over the grid at selection level istep
324   //
325   if(istep >= fNStep || istep < 0){
326     AliError("Non-existent selection step, return -1");
327     return -1.;
328   }
329   return fGrid[istep]->GetIntegral();
330 }
331 //_____________________________________________________________________
332 Double_t AliCFContainer::GetIntegral( Int_t istep, Double_t *varMin, Double_t* varMax ) const 
333 {
334   //
335   // Get Integral over the grid in a range at selection level istep
336   //
337   if(istep >= fNStep || istep < 0){
338     AliError("Non-existent selection step, return -1");
339     return -1.;
340   }
341   return fGrid[istep]->GetIntegral(varMin,varMax);
342 }