L1phase shift corrected
[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// //
9105291d 18// AliCFContainer Class //
19// Class to accumulate data on an N-dimensional grids, at different //
563113d0 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>
db6722a5 28#include "AliCFGridSparse.h"
563113d0 29#include "AliCFContainer.h"
c8df672e 30#include "TAxis.h"
563113d0 31//____________________________________________________________________
32ClassImp(AliCFContainer)
33
34//____________________________________________________________________
35AliCFContainer::AliCFContainer() :
36 AliCFFrame(),
37 fNStep(0),
38 fGrid(0x0)
39{
40 //
41 // default constructor
42 //
43}
563113d0 44
45//____________________________________________________________________
fb494025 46AliCFContainer::AliCFContainer(const Char_t* name, const Char_t* title, const Int_t nSelSteps, const Int_t nVarIn, const Int_t* nBinIn) :
47 AliCFFrame(name,title),
48 fNStep(nSelSteps),
563113d0 49 fGrid(0x0)
50{
51 //
52 // main constructor
53 //
54
563113d0 55 // The grids
fb494025 56 fGrid = new AliCFGridSparse*[fNStep]; //the grids at the various selection steps
fb494025 57 for (Int_t istep=0; istep<fNStep; istep++) {
d91baff0 58 fGrid[istep] = new AliCFGridSparse(Form("%s_SelStep%d",name,istep),Form("step%d",istep),nVarIn,nBinIn);
fb494025 59 fGrid[istep]->SumW2();
563113d0 60 }
d91baff0 61 for (Int_t iVar=0; iVar<nVarIn; iVar++) SetVarTitle(iVar,Form("var%d",iVar));
fb494025 62 AliInfo(Form("Grids created for %d steps required \n => Don't forget to set the bin limits !!",fNStep));
563113d0 63}
64//____________________________________________________________________
fb494025 65AliCFContainer::AliCFContainer(const AliCFContainer& c) :
66 AliCFFrame(c.fName,c.fTitle),
67 fNStep(0),
68 fGrid(0x0)
563113d0 69{
70 //
71 // copy constructor
72 //
fb494025 73 c.Copy(*this);
563113d0 74}
75//____________________________________________________________________
76AliCFContainer::~AliCFContainer()
77{
78 //
79 // destructor
80 //
ed0e5c53 81 if (fGrid) {
82 for ( Int_t istep=0; istep<fNStep; istep++ )
83 delete fGrid[istep];
84 }
85 delete [] fGrid;
563113d0 86}
87//____________________________________________________________________
88AliCFContainer &AliCFContainer::operator=(const AliCFContainer &c)
89{
90 //
91 // assigment operator
92 //
fb494025 93 if (this != &c) c.Copy(*this);
563113d0 94 return *this;
95}
fb494025 96
563113d0 97//____________________________________________________________________
98void AliCFContainer::Copy(TObject& c) const
99{
100 //
101 // copy function
102 //
fb494025 103 AliCFFrame::Copy(c);
563113d0 104 AliCFContainer& target = (AliCFContainer &) c;
fb494025 105 target.fNStep = fNStep;
106 target.fGrid = new AliCFGridSparse*[fNStep];
107 for (Int_t iStep=0; iStep<fNStep; iStep++) {
108 if (fGrid[iStep]) target.fGrid[iStep] = new AliCFGridSparse(*(fGrid[iStep]));
109 }
563113d0 110}
fb494025 111
563113d0 112//____________________________________________________________________
fb494025 113void AliCFContainer::Fill(const Double_t *var, Int_t istep, Double_t weight)
563113d0 114{
115 //
116 // Fills the grid at selection step istep for a set of values of the
117 // input variables, with a given weight (by default w=1)
118 //
a2255142 119 if(istep >= fNStep || istep < 0){
120 AliError("Non-existent selection step, grid was not filled");
121 return;
122 }
563113d0 123 fGrid[istep]->Fill(var,weight);
124}
9105291d 125
d91baff0 126//____________________________________________________________________
127TH1* AliCFContainer::Project(Int_t istep, Int_t ivar1, Int_t ivar2, Int_t ivar3) const
563113d0 128{
129 //
d91baff0 130 // returns a projection along variables ivar1 (and ivar2 (and ivar3))
563113d0 131 // at selection step istep
132 //
d91baff0 133 if (istep >= fNStep || istep < 0){
a2255142 134 AliError("Non-existent selection step, return NULL");
135 return 0x0;
136 }
563113d0 137 return fGrid[istep]->Project(ivar1,ivar2,ivar3);
138}
d91baff0 139
563113d0 140//____________________________________________________________________
98a5f772 141AliCFContainer* AliCFContainer::MakeSlice(Int_t nVars, const Int_t* vars, const Double_t* varMin, const Double_t* varMax, Bool_t useBins) const
9105291d 142{
143 //
38b1447f 144 // Makes a slice along the "nVars" variables defined in the array "vars[nVars]" for all the container steps.
fb494025 145 // The ranges of ALL the container variables must be defined in the array varMin[GetNVar()] and varMax[GetNVar()]
38b1447f 146 // The function returns a new container of nVars variables.
98a5f772 147 // If useBins=true, varMin and varMax are taken as bin numbers
38b1447f 148 //
149 Int_t* steps = new Int_t[fNStep];
150 for (Int_t iStep=0;iStep<fNStep;iStep++) steps[iStep]=iStep;
d91baff0 151 AliCFContainer* out = MakeSlice(fNStep,steps,nVars,vars,varMin,varMax,useBins);
9be0fa4e 152 delete [] steps ;
153 return out;
38b1447f 154}
155
156//____________________________________________________________________
d91baff0 157AliCFContainer* AliCFContainer::MakeSlice(Int_t nSteps, const Int_t* steps,
158 Int_t nVars, const Int_t* vars,
159 const Double_t* varMin, const Double_t* varMax, Bool_t useBins) const
38b1447f 160{
161 //
162 // Makes a slice along the "nVars" variables defined in the array "vars[nVars]" for the given "nSteps" defined in "steps[nSteps]".
fb494025 163 // The ranges of ALL the container variables must be defined in the array varMin[GetNVar()] and varMax[GetNVar()]
a8b83c87 164 // The function returns a new container of nVars variables.
98a5f772 165 // If useBins=true, varMin and varMax are taken as bin numbers
9105291d 166 //
167
fb494025 168 if (nVars < 1 || nVars > GetNVar()) AliError("Bad number of dimensions required for the slice");
38b1447f 169 if (nSteps< 1 || nSteps> fNStep) AliError("Bad number of steps required for the slice");
9105291d 170
9be0fa4e 171 AliInfo(Form("Making a slice in %d dimension(s)",nVars));
172
173 // create the output grids
fb494025 174 AliCFGridSparse** grids = new AliCFGridSparse*[nSteps] ;
d91baff0 175 for (Int_t iStep=0; iStep<nSteps; iStep++) grids[iStep] = fGrid[steps[iStep]]->MakeSlice(nVars,vars,varMin,varMax,useBins);
176
9be0fa4e 177 TAxis ** axis = new TAxis*[nVars];
178 for (Int_t iVar=0; iVar<nVars; iVar++) axis[iVar] = ((AliCFGridSparse*)grids[0])->GetGrid()->GetAxis(iVar); //same axis for every grid
179
9105291d 180 //define new binning for new container
181 Int_t* bins=new Int_t[nVars];
9be0fa4e 182 for (Int_t iVar=0; iVar<nVars; iVar++) bins[iVar] = axis[iVar]->GetNbins();
183
38b1447f 184 AliCFContainer* out = new AliCFContainer(fName,fTitle,nSteps,nVars,bins);
9105291d 185
186 //set the bin limits
187 for (Int_t iVar=0; iVar<nVars; iVar++) {
9be0fa4e 188 Int_t nBins = bins[iVar];
189 Double_t *array = new Double_t[nBins+1];
162b9b82 190 for (Int_t iBin=1; iBin<=nBins+1; iBin++) {
9be0fa4e 191 array[iBin-1] = axis[iVar]->GetBinLowEdge(iBin);
192 }
9105291d 193 out->SetBinLimits(iVar,array);
9be0fa4e 194 delete [] array;
9105291d 195 }
196
38b1447f 197 //set grid for the given steps
9be0fa4e 198 for (Int_t iStep=0; iStep<nSteps; iStep++) out->SetGrid(iStep,grids[iStep]);
9105291d 199
98a5f772 200 delete [] bins;
9be0fa4e 201 delete [] axis ;
79c0eecc 202 delete [] grids;
9105291d 203 return out;
204}
205
206//____________________________________________________________________
563113d0 207Long64_t AliCFContainer::Merge(TCollection* list)
208{
209 // Merge a list of AliCorrection objects with this (needed for
210 // PROOF).
211 // Returns the number of merged objects (including this).
212
213 if (!list)
214 return 0;
215
216 if (list->IsEmpty())
217 return 1;
218
ed0e5c53 219 TIter iter(list);
563113d0 220 TObject* obj;
221
222 Int_t count = 0;
ed0e5c53 223 while ((obj = iter())) {
563113d0 224 AliCFContainer* entry = dynamic_cast<AliCFContainer*> (obj);
225 if (entry == 0)
226 continue;
227 this->Add(entry);
228 count++;
229 }
230
231 return count+1;
232}
233
234//____________________________________________________________________
fb494025 235void AliCFContainer::Add(const AliCFContainer* aContainerToAdd, Double_t c)
563113d0 236{
237 //
238 //add the content of container aContainerToAdd to the current one
239 //
fb494025 240 if ((aContainerToAdd->GetNStep() != fNStep) ||
241 (aContainerToAdd->GetNVar() != GetNVar()) ||
242 (aContainerToAdd->GetNBinsTotal() != GetNBinsTotal()))
243 {
244 AliError("Different number of steps/sensitive variables/grid elements: cannot add the containers");
245 return;
246 }
247 for (Int_t istep=0; istep<fNStep; istep++) {
563113d0 248 fGrid[istep]->Add(aContainerToAdd->GetGrid(istep),c);
249 }
250}
251//____________________________________________________________________
fb494025 252Float_t AliCFContainer::GetOverFlows( Int_t ivar, Int_t istep, Bool_t exclusive) const {
563113d0 253 //
254 // Get overflows in variable var at selection level istep
fb494025 255 // Set 'exclusive' to true for an exclusive check on variable ivar
563113d0 256 //
a2255142 257 if(istep >= fNStep || istep < 0){
258 AliError("Non-existent selection step, return -1");
259 return -1.;
260 }
fb494025 261 return fGrid[istep]->GetOverFlows(ivar,exclusive);
563113d0 262}
263//____________________________________________________________________
fb494025 264Float_t AliCFContainer::GetUnderFlows( Int_t ivar, Int_t istep, Bool_t exclusive) const {
563113d0 265 //
a2255142 266 // Get underflows in variable var at selection level istep
fb494025 267 // Set 'exclusive' to true for an exclusive check on variable ivar
563113d0 268 //
a2255142 269 if(istep >= fNStep || istep < 0){
270 AliError("Non-existent selection step, return -1");
271 return -1.;
272 }
fb494025 273 return fGrid[istep]->GetUnderFlows(ivar,exclusive);
563113d0 274}
275//____________________________________________________________________
fb494025 276Float_t AliCFContainer::GetEntries(Int_t istep) const {
563113d0 277 //
a2255142 278 // Get total entries in variable var at selection level istep
563113d0 279 //
a2255142 280 if(istep >= fNStep || istep < 0){
281 AliError("Non-existent selection step, return -1");
282 return -1.;
283 }
563113d0 284 return fGrid[istep]->GetEntries();
285}
563113d0 286//_____________________________________________________________________
1e9dad92 287Double_t AliCFContainer::GetIntegral( Int_t istep) const
563113d0 288{
289 //
a2255142 290 // Get Integral over the grid at selection level istep
563113d0 291 //
a2255142 292 if(istep >= fNStep || istep < 0){
293 AliError("Non-existent selection step, return -1");
294 return -1.;
295 }
563113d0 296 return fGrid[istep]->GetIntegral();
297}
d91baff0 298
563113d0 299//_____________________________________________________________________
d91baff0 300void AliCFContainer::SetRangeUser(Int_t ivar, Double_t varMin, Double_t varMax, Bool_t useBins) const
c8df672e 301{
302 //
d91baff0 303 // set axis range for variable ivar
304 // put useBins=kTRUE if you want to pass bin numbers instead of values
c8df672e 305 //
fb494025 306 if (ivar >= GetNVar() || ivar < 0){
c8df672e 307 AliError("Non-existent selection var");
308 return ;
309 }
d91baff0 310 for (Int_t iStep=0; iStep<GetNStep(); iStep++) fGrid[iStep]->SetRangeUser(ivar,varMin,varMax,useBins);
9105291d 311}
312
313//_____________________________________________________________________
d91baff0 314void AliCFContainer::SetRangeUser(const Double_t* varMin, const Double_t* varMax, Bool_t useBins) const
9105291d 315{
316 //
d91baff0 317 // set all axis ranges according to arrays varMin and varMax
318 // put useBins=kTRUE if you want to pass bin numbers instead of values
9105291d 319 //
d91baff0 320 for (Int_t iStep=0; iStep<GetNStep(); iStep++) fGrid[iStep]->SetRangeUser(varMin,varMax,useBins);
c8df672e 321}
71b2614f 322
323//_____________________________________________________________________
324void AliCFContainer::Print(const Option_t*) const {
325 AliInfo("====================================================================================");
326 AliInfo(Form("AliCFContainer : name = %s title = %s",GetName(),GetTitle()));
327 AliInfo(Form("number of steps \t %d",GetNStep()));
328 for (Int_t iStep=0;iStep<GetNStep();iStep++) AliInfo(Form("step %d \t -> %s",iStep,GetStepTitle(iStep)));
329 AliInfo(Form("number of variables \t %d",GetNVar()));
330 for (Int_t iVar=0;iVar<GetNVar();iVar++) {
331 Double_t *binLimits = new Double_t[GetNBins(iVar)+1];
332 GetBinLimits(iVar,binLimits);
333 AliInfo(Form("variable %d \t -> %s : %d bins in [%f,%f]",iVar,GetVarTitle(iVar),GetNBins(iVar),binLimits[0],binLimits[GetNBins(iVar)]));
4ce766eb 334 delete[] binLimits;
71b2614f 335 }
336 AliInfo("====================================================================================");
337}