]> git.uio.no Git - u/mrichter/AliRoot.git/blame - CORRFW/AliCFContainer.cxx
bug fixed
[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"
db6722a5 29#include "AliCFGridSparse.h"
563113d0 30#include "AliCFContainer.h"
c8df672e 31#include "TAxis.h"
563113d0 32//____________________________________________________________________
33ClassImp(AliCFContainer)
34
35//____________________________________________________________________
36AliCFContainer::AliCFContainer() :
37 AliCFFrame(),
38 fNStep(0),
318f64b1 39 fExclOffEntriesInProj(kTRUE),
563113d0 40 fGrid(0x0)
41{
42 //
43 // default constructor
44 //
45}
46//____________________________________________________________________
47AliCFContainer::AliCFContainer(const Char_t* name, const Char_t* title) :
48 AliCFFrame(name,title),
49 fNStep(0),
318f64b1 50 fExclOffEntriesInProj(kTRUE),
563113d0 51 fGrid(0x0)
52{
53 // default constructor
54}
55
56//____________________________________________________________________
db6722a5 57AliCFContainer::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) :
563113d0 58 AliCFFrame(name,title,nVarIn,nBinIn,binLimitsIn),
59 fNStep(0),
318f64b1 60 fExclOffEntriesInProj(kTRUE),
563113d0 61 fGrid(0x0)
62{
63 //
64 // main constructor
65 //
66
67 // The selection steps
68 fNStep=nSelSteps;
69
70 // The grids
1e9dad92 71 fGrid = new AliCFVGrid*[fNStep]; //the grids at the various selection steps
563113d0 72 char gname[30];
73 for(Int_t istep=0;istep<fNStep;istep++){
74 sprintf(gname,"%s%s%i",GetName(),"_SelStep", istep);
db6722a5 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 }
1e9dad92 81 fGrid[istep]->SumW2();
563113d0 82 }
83}
84//____________________________________________________________________
85AliCFContainer::AliCFContainer(const AliCFContainer& c) :
86 AliCFFrame(),
318f64b1 87 fNStep(c.fNStep),
88 fExclOffEntriesInProj(c.fExclOffEntriesInProj),
89 fGrid(c.fGrid)
563113d0 90{
91 //
92 // copy constructor
93 //
94 ((AliCFContainer &)c).Copy(*this);
95}
96//____________________________________________________________________
97AliCFContainer::~AliCFContainer()
98{
99 //
100 // destructor
101 //
102 if(fGrid)delete [] fGrid;
103
104}
105//____________________________________________________________________
106AliCFContainer &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//____________________________________________________________________
1e9dad92 116void AliCFContainer::SetBinLimits(Int_t varindex, Double_t *array)
563113d0 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//____________________________________________________________________
130void AliCFContainer::Copy(TObject& c) const
131{
132 //
133 // copy function
134 //
135 AliCFContainer& target = (AliCFContainer &) c;
136 target.fNStep=fNStep;
318f64b1 137 target.fExclOffEntriesInProj=fExclOffEntriesInProj;
563113d0 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//____________________________________________________________________
1e9dad92 154void AliCFContainer::Fill(Double_t *var, Int_t istep, Double_t weight)
563113d0 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 //
a2255142 160 if(istep >= fNStep || istep < 0){
161 AliError("Non-existent selection step, grid was not filled");
162 return;
163 }
563113d0 164 fGrid[istep]->Fill(var,weight);
165}
166//___________________________________________________________________
1e9dad92 167TH1D *AliCFContainer::ShowProjection(Int_t ivar, Int_t istep) const
563113d0 168{
169 //
170 // returns 1-D projection along variable ivar at selection step istep
171 //
a2255142 172 if(istep >= fNStep || istep < 0){
173 AliError("Non-existent selection step, return NULL");
174 return 0x0;
175 }
318f64b1 176 fGrid[istep]->SetExcludeOffEntriesInProj(fExclOffEntriesInProj);
563113d0 177 return fGrid[istep]->Project(ivar);
178}
179//___________________________________________________________________
1e9dad92 180TH2D *AliCFContainer::ShowProjection(Int_t ivar1, Int_t ivar2, Int_t istep) const
563113d0 181{
182 //
183 // returns 2-D projection along variables ivar1,ivar2 at selection step istep
184 //
a2255142 185 if(istep >= fNStep || istep < 0){
186 AliError("Non-existent selection step, return NULL");
187 return 0x0;
188 }
318f64b1 189 fGrid[istep]->SetExcludeOffEntriesInProj(fExclOffEntriesInProj);
563113d0 190 return fGrid[istep]->Project(ivar1,ivar2);
191}
192//___________________________________________________________________
1e9dad92 193TH3D *AliCFContainer::ShowProjection(Int_t ivar1, Int_t ivar2, Int_t ivar3, Int_t istep) const
563113d0 194{
195 //
196 // returns 3-D projection along variables ivar1,ivar2,ivar3
197 // at selection step istep
198 //
a2255142 199 if(istep >= fNStep || istep < 0){
200 AliError("Non-existent selection step, return NULL");
201 return 0x0;
202 }
318f64b1 203 fGrid[istep]->SetExcludeOffEntriesInProj(fExclOffEntriesInProj);
563113d0 204 return fGrid[istep]->Project(ivar1,ivar2,ivar3);
205}
206//___________________________________________________________________
1e9dad92 207TH1D *AliCFContainer::ShowSlice(Int_t ivar, Double_t *varMin, Double_t* varMax, Int_t istep) const
563113d0 208{
209 //
210 // Make a slice along variable ivar at selection level istep in range [varMin,varMax]
211 //
a2255142 212 if(istep >= fNStep || istep < 0){
213 AliError("Non-existent selection step, return NULL");
214 return 0x0;
215 }
c8df672e 216 if (ivar >= fNVar || ivar < 0) {
217 AliError("Non-existent variable, return NULL");
218 return 0x0;
219 }
1e9dad92 220 return (TH1D*)fGrid[istep]->Slice(ivar,varMin,varMax);
563113d0 221}
c8df672e 222//___________________________________________________________________
223TH2D *AliCFContainer::ShowSlice(Int_t ivar1, Int_t ivar2, Double_t *varMin, Double_t* varMax, Int_t istep) const
224{
225 //
226 // Make a slice along variables ivar1 and ivar2 at selection level istep in range [varMin,varMax]
227 //
228 if(istep >= fNStep || istep < 0){
229 AliError("Non-existent selection step, return NULL");
230 return 0x0;
231 }
232 if (ivar1 >= fNVar || ivar1 < 0 || ivar2 >= fNVar || ivar2 < 0) {
233 AliError("Non-existent variable, return NULL");
234 return 0x0;
235 }
236 return (TH2D*)fGrid[istep]->Slice(ivar1,ivar2,varMin,varMax);
237}
238//___________________________________________________________________
239TH3D *AliCFContainer::ShowSlice(Int_t ivar1, Int_t ivar2, Int_t ivar3, Double_t *varMin, Double_t* varMax, Int_t istep) const
240{
241 //
242 // Make a slice along variables ivar1, ivar2and ivar3 at selection level istep in range [varMin,varMax]
243 //
244 if(istep >= fNStep || istep < 0){
245 AliError("Non-existent selection step, return NULL");
246 return 0x0;
247 }
248 if (ivar1 >= fNVar || ivar1 < 0 || ivar2 >= fNVar || ivar2 < 0 || ivar3 >= fNVar || ivar3 < 0) {
249 AliError("Non-existent variable, return NULL");
250 return 0x0;
251 }
252 return (TH3D*)fGrid[istep]->Slice(ivar1,ivar2,ivar3,varMin,varMax);
253}
563113d0 254//____________________________________________________________________
255Long64_t AliCFContainer::Merge(TCollection* list)
256{
257 // Merge a list of AliCorrection objects with this (needed for
258 // PROOF).
259 // Returns the number of merged objects (including this).
260
261 if (!list)
262 return 0;
263
264 if (list->IsEmpty())
265 return 1;
266
267 TIterator* iter = list->MakeIterator();
268 TObject* obj;
269
270 Int_t count = 0;
271 while ((obj = iter->Next())) {
272 AliCFContainer* entry = dynamic_cast<AliCFContainer*> (obj);
273 if (entry == 0)
274 continue;
275 this->Add(entry);
276 count++;
277 }
278
279 return count+1;
280}
281
282//____________________________________________________________________
1e9dad92 283void AliCFContainer::Add(AliCFContainer* aContainerToAdd, Double_t c)
563113d0 284{
285 //
286 //add the content of container aContainerToAdd to the current one
287 //
a2255142 288 if( (aContainerToAdd->GetNStep()!=fNStep)
289 ||
290 (aContainerToAdd->GetNVar()!=fNVar)
291 ||
292 (aContainerToAdd->GetNDim()!=fNDim)){
293 AliError("Different number of steps/sensitive variables/grid elements: cannot add the containers");
294 return;
295 }
563113d0 296 for(Int_t istep=0;istep<fNStep;istep++){
297 fGrid[istep]->Add(aContainerToAdd->GetGrid(istep),c);
298 }
299}
300//____________________________________________________________________
301Float_t AliCFContainer::GetOverFlows( Int_t ivar, Int_t istep) const {
302 //
303 // Get overflows in variable var at selection level istep
304 //
a2255142 305 if(istep >= fNStep || istep < 0){
306 AliError("Non-existent selection step, return -1");
307 return -1.;
308 }
563113d0 309 return fGrid[istep]->GetOverFlows(ivar);
310}
311//____________________________________________________________________
563113d0 312Float_t AliCFContainer::GetUnderFlows( Int_t ivar, Int_t istep) const {
313 //
a2255142 314 // Get underflows in variable var at selection level istep
563113d0 315 //
a2255142 316 if(istep >= fNStep || istep < 0){
317 AliError("Non-existent selection step, return -1");
318 return -1.;
319 }
563113d0 320 return fGrid[istep]->GetUnderFlows(ivar);
321}
322//____________________________________________________________________
563113d0 323Float_t AliCFContainer::GetEntries( Int_t istep) const {
324 //
a2255142 325 // Get total entries in variable var at selection level istep
563113d0 326 //
a2255142 327 if(istep >= fNStep || istep < 0){
328 AliError("Non-existent selection step, return -1");
329 return -1.;
330 }
563113d0 331 return fGrid[istep]->GetEntries();
332}
333//____________________________________________________________________
334Int_t AliCFContainer::GetEmptyBins( Int_t istep) const {
335 //
a2255142 336 // Get empty bins in variable var at selection level istep
563113d0 337 //
a2255142 338 if(istep >= fNStep || istep < 0){
339 AliError("Non-existent selection step, return -1");
340 return -1;
341 }
563113d0 342 return fGrid[istep]->GetEmptyBins();
343}
344//____________________________________________________________________
1e9dad92 345Int_t AliCFContainer::GetEmptyBins( Int_t istep, Double_t *varMin, Double_t* varMax) const {
563113d0 346 //
a2255142 347 // Get empty bins in a range in variable var at selection level istep
563113d0 348 //
a2255142 349 if(istep >= fNStep || istep < 0){
350 AliError("Non-existent selection step, return -1");
351 return -1;
352 }
563113d0 353 return fGrid[istep]->GetEmptyBins(varMin,varMax);
354}
355//_____________________________________________________________________
1e9dad92 356Double_t AliCFContainer::GetIntegral( Int_t istep) const
563113d0 357{
358 //
a2255142 359 // Get Integral over the grid at selection level istep
563113d0 360 //
a2255142 361 if(istep >= fNStep || istep < 0){
362 AliError("Non-existent selection step, return -1");
363 return -1.;
364 }
563113d0 365 return fGrid[istep]->GetIntegral();
366}
367//_____________________________________________________________________
1e9dad92 368Double_t AliCFContainer::GetIntegral( Int_t istep, Double_t *varMin, Double_t* varMax ) const
563113d0 369{
370 //
a2255142 371 // Get Integral over the grid in a range at selection level istep
563113d0 372 //
a2255142 373 if(istep >= fNStep || istep < 0){
374 AliError("Non-existent selection step, return -1");
375 return -1.;
376 }
563113d0 377 return fGrid[istep]->GetIntegral(varMin,varMax);
378}
c8df672e 379//_____________________________________________________________________
380void AliCFContainer::SetRangeUser(Int_t ivar, Double_t varMin, Double_t varMax, Int_t istep)
381{
382 //
383 // set axis range at step istep
384 //
385 if ( strcmp(fGrid[istep]->ClassName(),"AliCFGrid") ==0 ) {
386 AliWarning("Could not AliCFGrid::SetRangeUser(), function not implemented");
387 return;
388 }
389 if (istep >= fNStep || istep < 0){
390 AliError("Non-existent selection step");
391 return ;
392 }
393 if (ivar >= fNVar || ivar < 0){
394 AliError("Non-existent selection var");
395 return ;
396 }
397 ((AliCFGridSparse*)fGrid[istep])->GetGrid()->GetAxis(ivar)->SetRangeUser(varMin,varMax);
398}