Move core classes from EveDet to EveBase.
[u/mrichter/AliRoot.git] / CORRFW / AliCFContainer.cxx
CommitLineData
563113d0 1/* $Id$ */
1e9dad92 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 **************************************************************************/
563113d0 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"
1e9dad92 29//#include "AliCFGridSparse.h"
563113d0 30#include "AliCFContainer.h"
31
32//____________________________________________________________________
33ClassImp(AliCFContainer)
34
35//____________________________________________________________________
36AliCFContainer::AliCFContainer() :
37 AliCFFrame(),
38 fNStep(0),
39 fGrid(0x0)
40{
41 //
42 // default constructor
43 //
44}
45//____________________________________________________________________
46AliCFContainer::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//____________________________________________________________________
1e9dad92 55AliCFContainer::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) :
563113d0 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
1e9dad92 68 fGrid = new AliCFVGrid*[fNStep]; //the grids at the various selection steps
563113d0 69 char gname[30];
70 for(Int_t istep=0;istep<fNStep;istep++){
71 sprintf(gname,"%s%s%i",GetName(),"_SelStep", istep);
72 fGrid[istep] = new AliCFGrid(gname,title,nVarIn,nBinIn,binLimitsIn);
1e9dad92 73 //fGrid[istep] = new AliCFGridSparse(gname,title,nVarIn,nBinIn,binLimitsIn);
74 fGrid[istep]->SumW2();
563113d0 75 }
76}
77//____________________________________________________________________
78AliCFContainer::AliCFContainer(const AliCFContainer& c) :
79 AliCFFrame(),
80 fNStep(0),
81 fGrid(0x0)
82{
83 //
84 // copy constructor
85 //
86 ((AliCFContainer &)c).Copy(*this);
87}
88//____________________________________________________________________
89AliCFContainer::~AliCFContainer()
90{
91 //
92 // destructor
93 //
94 if(fGrid)delete [] fGrid;
95
96}
97//____________________________________________________________________
98AliCFContainer &AliCFContainer::operator=(const AliCFContainer &c)
99{
100 //
101 // assigment operator
102 //
103 if (this != &c)
104 ((AliCFContainer &) c).Copy(*this);
105 return *this;
106}
107//____________________________________________________________________
1e9dad92 108void AliCFContainer::SetBinLimits(Int_t varindex, Double_t *array)
563113d0 109{
110 //
111 // setting the arrays containing the bin limits
112 //
113 Int_t nbins=fNVarBins[varindex]+1;
114 for(Int_t i=0;i<nbins;i++){
115 fVarBinLimits[fOffset[varindex]+i] =array[i];
116 }
117 for(Int_t istep=0;istep<fNStep;istep++){
118 fGrid[istep]->SetBinLimits(varindex,array);
119 }
120}
121//____________________________________________________________________
122void AliCFContainer::Copy(TObject& c) const
123{
124 //
125 // copy function
126 //
127 AliCFContainer& target = (AliCFContainer &) c;
128 target.fNStep=fNStep;
129 target.fNVar=fNVar;
130 target.fNDim=fNDim;
131 target.fNVarBinLimits=fNVarBinLimits;
132 if (fNVarBins)
133 target.fNVarBins = fNVarBins;
134 if (fVarBinLimits)
135 target.fVarBinLimits = fVarBinLimits;
136 if (fGrid)
137 target.fGrid = fGrid;
138 for(Int_t istep=0;istep<fNStep;istep++){
139 for(Int_t iel=0;iel<fNDim;iel++){
140 target.fGrid[istep]->SetElement(iel,fGrid[istep]->GetElement(iel));
141 }
142 }
143}
144//____________________________________________________________________
1e9dad92 145void AliCFContainer::Fill(Double_t *var, Int_t istep, Double_t weight)
563113d0 146{
147 //
148 // Fills the grid at selection step istep for a set of values of the
149 // input variables, with a given weight (by default w=1)
150 //
151 fGrid[istep]->Fill(var,weight);
152}
153//___________________________________________________________________
1e9dad92 154TH1D *AliCFContainer::ShowProjection(Int_t ivar, Int_t istep) const
563113d0 155{
156 //
157 // returns 1-D projection along variable ivar at selection step istep
158 //
159 return fGrid[istep]->Project(ivar);
160}
161//___________________________________________________________________
1e9dad92 162TH2D *AliCFContainer::ShowProjection(Int_t ivar1, Int_t ivar2, Int_t istep) const
563113d0 163{
164 //
165 // returns 2-D projection along variables ivar1,ivar2 at selection step istep
166 //
167 return fGrid[istep]->Project(ivar1,ivar2);
168}
169//___________________________________________________________________
1e9dad92 170TH3D *AliCFContainer::ShowProjection(Int_t ivar1, Int_t ivar2, Int_t ivar3, Int_t istep) const
563113d0 171{
172 //
173 // returns 3-D projection along variables ivar1,ivar2,ivar3
174 // at selection step istep
175 //
176 return fGrid[istep]->Project(ivar1,ivar2,ivar3);
177}
178//___________________________________________________________________
1e9dad92 179TH1D *AliCFContainer::ShowSlice(Int_t ivar, Double_t *varMin, Double_t* varMax, Int_t istep) const
563113d0 180{
181 //
182 // Make a slice along variable ivar at selection level istep in range [varMin,varMax]
183 //
1e9dad92 184 return (TH1D*)fGrid[istep]->Slice(ivar,varMin,varMax);
563113d0 185}
186//____________________________________________________________________
187Long64_t AliCFContainer::Merge(TCollection* list)
188{
189 // Merge a list of AliCorrection objects with this (needed for
190 // PROOF).
191 // Returns the number of merged objects (including this).
192
193 if (!list)
194 return 0;
195
196 if (list->IsEmpty())
197 return 1;
198
199 TIterator* iter = list->MakeIterator();
200 TObject* obj;
201
202 Int_t count = 0;
203 while ((obj = iter->Next())) {
204 AliCFContainer* entry = dynamic_cast<AliCFContainer*> (obj);
205 if (entry == 0)
206 continue;
207 this->Add(entry);
208 count++;
209 }
210
211 return count+1;
212}
213
214//____________________________________________________________________
1e9dad92 215void AliCFContainer::Add(AliCFContainer* aContainerToAdd, Double_t c)
563113d0 216{
217 //
218 //add the content of container aContainerToAdd to the current one
219 //
220
221 if(aContainerToAdd->GetNStep()!=fNStep)AliError("Different number of steps, cannot add the containers");
222 if(aContainerToAdd->GetNVar()!=fNVar)AliError("Different number of variables, cannot add the containers");
223 if(aContainerToAdd->GetNDim()!=fNDim)AliError("Different number of dimensions, cannot add the containers!");
224
225 for(Int_t istep=0;istep<fNStep;istep++){
226 fGrid[istep]->Add(aContainerToAdd->GetGrid(istep),c);
227 }
228}
229//____________________________________________________________________
230Float_t AliCFContainer::GetOverFlows( Int_t ivar, Int_t istep) const {
231 //
232 // Get overflows in variable var at selection level istep
233 //
234 return fGrid[istep]->GetOverFlows(ivar);
235}
236//____________________________________________________________________
237Float_t AliCFContainer::GetOverFlows( Int_t istep) const {
238 //
239 // Get overflows in variable var at selection level istep
240 //
241 return fGrid[istep]->GetOverFlows();
242}
243//____________________________________________________________________
244Float_t AliCFContainer::GetUnderFlows( Int_t ivar, Int_t istep) const {
245 //
246 // Get overflows in variable var at selection level istep
247 //
248 return fGrid[istep]->GetUnderFlows(ivar);
249}
250//____________________________________________________________________
251Float_t AliCFContainer::GetUnderFlows( Int_t istep) const {
252 //
253 // Get overflows in variable var at selection level istep
254 //
255 return fGrid[istep]->GetUnderFlows();
256}
257//____________________________________________________________________
258Float_t AliCFContainer::GetEntries( Int_t istep) const {
259 //
260 // Get overflows in variable var at selection level istep
261 //
262 return fGrid[istep]->GetEntries();
263}
264//____________________________________________________________________
265Int_t AliCFContainer::GetEmptyBins( Int_t istep) const {
266 //
267 // Get overflows in variable var at selection level istep
268 //
269 return fGrid[istep]->GetEmptyBins();
270}
271//____________________________________________________________________
1e9dad92 272Int_t AliCFContainer::GetEmptyBins( Int_t istep, Double_t *varMin, Double_t* varMax) const {
563113d0 273 //
274 // Get overflows in variable var at selection level istep
275 //
276 return fGrid[istep]->GetEmptyBins(varMin,varMax);
277}
278//_____________________________________________________________________
1e9dad92 279Double_t AliCFContainer::GetIntegral( Int_t istep) const
563113d0 280{
281 //
282 // Get Integral at selection level istep
283 //
284 return fGrid[istep]->GetIntegral();
285}
286//_____________________________________________________________________
1e9dad92 287Double_t AliCFContainer::GetIntegral( Int_t istep, Double_t *varMin, Double_t* varMax ) const
563113d0 288{
289 //
290 // Get Integral at selection level istep
291 //
292 return fGrid[istep]->GetIntegral(varMin,varMax);
293}