]>
Commit | Line | Data |
---|---|---|
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 | //____________________________________________________________________ |
32 | ClassImp(AliCFContainer) | |
33 | ||
34 | //____________________________________________________________________ | |
35 | AliCFContainer::AliCFContainer() : | |
36 | AliCFFrame(), | |
37 | fNStep(0), | |
38 | fGrid(0x0) | |
39 | { | |
40 | // | |
41 | // default constructor | |
42 | // | |
43 | } | |
563113d0 | 44 | |
45 | //____________________________________________________________________ | |
fb494025 | 46 | AliCFContainer::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 | 65 | AliCFContainer::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 | //____________________________________________________________________ | |
76 | AliCFContainer::~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 | //____________________________________________________________________ | |
88 | AliCFContainer &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 | //____________________________________________________________________ |
98 | void 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 | 113 | void 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 | //____________________________________________________________________ |
127 | TH1* 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 | |
9105291d | 140 | //____________________________________________________________________ |
98a5f772 | 141 | AliCFContainer* 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 | 157 | AliCFContainer* 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 ; |
9105291d | 202 | return out; |
203 | } | |
204 | ||
563113d0 | 205 | //____________________________________________________________________ |
206 | Long64_t AliCFContainer::Merge(TCollection* list) | |
207 | { | |
208 | // Merge a list of AliCorrection objects with this (needed for | |
209 | // PROOF). | |
210 | // Returns the number of merged objects (including this). | |
211 | ||
212 | if (!list) | |
213 | return 0; | |
214 | ||
215 | if (list->IsEmpty()) | |
216 | return 1; | |
217 | ||
ed0e5c53 | 218 | TIter iter(list); |
563113d0 | 219 | TObject* obj; |
220 | ||
221 | Int_t count = 0; | |
ed0e5c53 | 222 | while ((obj = iter())) { |
563113d0 | 223 | AliCFContainer* entry = dynamic_cast<AliCFContainer*> (obj); |
224 | if (entry == 0) | |
225 | continue; | |
226 | this->Add(entry); | |
227 | count++; | |
228 | } | |
229 | ||
230 | return count+1; | |
231 | } | |
232 | ||
233 | //____________________________________________________________________ | |
fb494025 | 234 | void AliCFContainer::Add(const AliCFContainer* aContainerToAdd, Double_t c) |
563113d0 | 235 | { |
236 | // | |
237 | //add the content of container aContainerToAdd to the current one | |
238 | // | |
fb494025 | 239 | if ((aContainerToAdd->GetNStep() != fNStep) || |
240 | (aContainerToAdd->GetNVar() != GetNVar()) || | |
241 | (aContainerToAdd->GetNBinsTotal() != GetNBinsTotal())) | |
242 | { | |
243 | AliError("Different number of steps/sensitive variables/grid elements: cannot add the containers"); | |
244 | return; | |
245 | } | |
246 | for (Int_t istep=0; istep<fNStep; istep++) { | |
563113d0 | 247 | fGrid[istep]->Add(aContainerToAdd->GetGrid(istep),c); |
248 | } | |
249 | } | |
250 | //____________________________________________________________________ | |
fb494025 | 251 | Float_t AliCFContainer::GetOverFlows( Int_t ivar, Int_t istep, Bool_t exclusive) const { |
563113d0 | 252 | // |
253 | // Get overflows in variable var at selection level istep | |
fb494025 | 254 | // Set 'exclusive' to true for an exclusive check on variable ivar |
563113d0 | 255 | // |
a2255142 | 256 | if(istep >= fNStep || istep < 0){ |
257 | AliError("Non-existent selection step, return -1"); | |
258 | return -1.; | |
259 | } | |
fb494025 | 260 | return fGrid[istep]->GetOverFlows(ivar,exclusive); |
563113d0 | 261 | } |
262 | //____________________________________________________________________ | |
fb494025 | 263 | Float_t AliCFContainer::GetUnderFlows( Int_t ivar, Int_t istep, Bool_t exclusive) const { |
563113d0 | 264 | // |
a2255142 | 265 | // Get underflows in variable var at selection level istep |
fb494025 | 266 | // Set 'exclusive' to true for an exclusive check on variable ivar |
563113d0 | 267 | // |
a2255142 | 268 | if(istep >= fNStep || istep < 0){ |
269 | AliError("Non-existent selection step, return -1"); | |
270 | return -1.; | |
271 | } | |
fb494025 | 272 | return fGrid[istep]->GetUnderFlows(ivar,exclusive); |
563113d0 | 273 | } |
274 | //____________________________________________________________________ | |
fb494025 | 275 | Float_t AliCFContainer::GetEntries(Int_t istep) const { |
563113d0 | 276 | // |
a2255142 | 277 | // Get total entries in variable var at selection level istep |
563113d0 | 278 | // |
a2255142 | 279 | if(istep >= fNStep || istep < 0){ |
280 | AliError("Non-existent selection step, return -1"); | |
281 | return -1.; | |
282 | } | |
563113d0 | 283 | return fGrid[istep]->GetEntries(); |
284 | } | |
563113d0 | 285 | //_____________________________________________________________________ |
1e9dad92 | 286 | Double_t AliCFContainer::GetIntegral( Int_t istep) const |
563113d0 | 287 | { |
288 | // | |
a2255142 | 289 | // Get Integral over the grid at selection level istep |
563113d0 | 290 | // |
a2255142 | 291 | if(istep >= fNStep || istep < 0){ |
292 | AliError("Non-existent selection step, return -1"); | |
293 | return -1.; | |
294 | } | |
563113d0 | 295 | return fGrid[istep]->GetIntegral(); |
296 | } | |
d91baff0 | 297 | |
563113d0 | 298 | //_____________________________________________________________________ |
d91baff0 | 299 | void AliCFContainer::SetRangeUser(Int_t ivar, Double_t varMin, Double_t varMax, Bool_t useBins) const |
c8df672e | 300 | { |
301 | // | |
d91baff0 | 302 | // set axis range for variable ivar |
303 | // put useBins=kTRUE if you want to pass bin numbers instead of values | |
c8df672e | 304 | // |
fb494025 | 305 | if (ivar >= GetNVar() || ivar < 0){ |
c8df672e | 306 | AliError("Non-existent selection var"); |
307 | return ; | |
308 | } | |
d91baff0 | 309 | for (Int_t iStep=0; iStep<GetNStep(); iStep++) fGrid[iStep]->SetRangeUser(ivar,varMin,varMax,useBins); |
9105291d | 310 | } |
311 | ||
312 | //_____________________________________________________________________ | |
d91baff0 | 313 | void AliCFContainer::SetRangeUser(const Double_t* varMin, const Double_t* varMax, Bool_t useBins) const |
9105291d | 314 | { |
315 | // | |
d91baff0 | 316 | // set all axis ranges according to arrays varMin and varMax |
317 | // put useBins=kTRUE if you want to pass bin numbers instead of values | |
9105291d | 318 | // |
d91baff0 | 319 | for (Int_t iStep=0; iStep<GetNStep(); iStep++) fGrid[iStep]->SetRangeUser(varMin,varMax,useBins); |
c8df672e | 320 | } |
71b2614f | 321 | |
322 | //_____________________________________________________________________ | |
323 | void AliCFContainer::Print(const Option_t*) const { | |
324 | AliInfo("===================================================================================="); | |
325 | AliInfo(Form("AliCFContainer : name = %s title = %s",GetName(),GetTitle())); | |
326 | AliInfo(Form("number of steps \t %d",GetNStep())); | |
327 | for (Int_t iStep=0;iStep<GetNStep();iStep++) AliInfo(Form("step %d \t -> %s",iStep,GetStepTitle(iStep))); | |
328 | AliInfo(Form("number of variables \t %d",GetNVar())); | |
329 | for (Int_t iVar=0;iVar<GetNVar();iVar++) { | |
330 | Double_t *binLimits = new Double_t[GetNBins(iVar)+1]; | |
331 | GetBinLimits(iVar,binLimits); | |
332 | AliInfo(Form("variable %d \t -> %s : %d bins in [%f,%f]",iVar,GetVarTitle(iVar),GetNBins(iVar),binLimits[0],binLimits[GetNBins(iVar)])); | |
4ce766eb | 333 | delete[] binLimits; |
71b2614f | 334 | } |
335 | AliInfo("===================================================================================="); | |
336 | } |