]>
Commit | Line | Data |
---|---|---|
563113d0 | 1 | /* $Id$ */ |
2 | ||
3 | //--------------------------------------------------------------------// | |
4 | // // | |
5 | // AliCFFrame Class // | |
6 | // Class to accumulate data on an N-dimensional grid, to be used // | |
7 | // as input to get corrections for Reconstruction & Trigger efficiency// | |
8 | // // | |
9 | // -- Author : S.Arcelli // | |
10 | // Still to be done: // | |
11 | // --Implement methods to merge cells // | |
12 | // --Interpolate among bins in a range // | |
13 | //--------------------------------------------------------------------// | |
14 | // | |
15 | // | |
16 | ||
17 | #include "TSystem.h" | |
18 | #include <TFile.h> | |
19 | #include <AliLog.h> | |
20 | #include "AliCFFrame.h" | |
21 | ||
22 | //____________________________________________________________________ | |
23 | ClassImp(AliCFFrame) | |
24 | ||
25 | //____________________________________________________________________ | |
26 | AliCFFrame::AliCFFrame() : | |
27 | TNamed(), | |
28 | fNVar(0), | |
29 | fNDim(0), | |
30 | fNVarBinLimits(0), | |
31 | fNVarBins(0x0), | |
32 | fIndex(0x0), | |
33 | fProduct(0x0), | |
34 | fOffset(0x0), | |
35 | fVarBinLimits(0x0) | |
36 | { | |
37 | // default constructor | |
38 | } | |
39 | //____________________________________________________________________ | |
40 | AliCFFrame::AliCFFrame(const Char_t* name, const Char_t* title) : | |
41 | TNamed(name,title), | |
42 | fNVar(0), | |
43 | fNDim(0), | |
44 | fNVarBinLimits(0), | |
45 | fNVarBins(0x0), | |
46 | fIndex(0x0), | |
47 | fProduct(0x0), | |
48 | fOffset(0x0), | |
49 | fVarBinLimits(0x0) | |
50 | { | |
51 | // named constructor | |
52 | } | |
53 | //____________________________________________________________________ | |
54 | AliCFFrame::AliCFFrame(const Char_t* name, const Char_t* title, const Int_t nVarIn, const Int_t * nBinIn, const Float_t *binLimitsIn) : | |
55 | TNamed(name,title), | |
56 | fNVar(0), | |
57 | fNDim(0), | |
58 | fNVarBinLimits(0), | |
59 | fNVarBins(0x0), | |
60 | fIndex(0x0), | |
61 | fProduct(0x0), | |
62 | fOffset(0x0), | |
63 | fVarBinLimits(0x0) | |
64 | { | |
65 | // | |
66 | // main constructor | |
67 | // | |
68 | ||
69 | //the number of variables on the grid | |
70 | fNVar=nVarIn; | |
71 | ||
72 | // the binning in each variable | |
73 | fNVarBins= new Int_t[fNVar]; | |
74 | ||
75 | fIndex= new Int_t[fNVar]; | |
76 | ||
77 | Int_t ndimTot=1; | |
78 | Int_t nbinTot=0; | |
79 | ||
80 | ||
81 | //Calculate total number of elements and bins... | |
82 | ||
83 | for(Int_t i=0;i<fNVar;i++){ | |
84 | fNVarBins[i]=nBinIn[i]; | |
85 | ndimTot*=nBinIn[i]; | |
86 | nbinTot+=(nBinIn[i]+1); | |
87 | } | |
88 | ||
89 | ||
90 | //total number of elements | |
91 | ||
92 | fNDim=ndimTot; | |
93 | ||
94 | fOffset= new Int_t[fNVar]; | |
95 | fProduct= new Int_t[fNVar]; | |
96 | ||
97 | for(Int_t ivar=0;ivar<fNVar;ivar++){ | |
98 | Int_t offset=0; | |
99 | for(Int_t i =0;i<ivar;i++)offset+=(fNVarBins[i]+1); | |
100 | fOffset[ivar]=offset; | |
101 | Int_t prod=1; | |
102 | for(Int_t i=0;i<ivar;i++)prod*=fNVarBins[i]; | |
103 | fProduct[ivar]=prod; | |
104 | } | |
105 | ||
106 | //The bin limits | |
107 | ||
108 | fNVarBinLimits=nbinTot; | |
109 | fVarBinLimits=new Float_t[fNVarBinLimits]; | |
110 | if(binLimitsIn){ | |
111 | for(Int_t i=0;i<fNVarBinLimits;i++){ | |
112 | fVarBinLimits[i] =binLimitsIn[i]; | |
113 | } | |
114 | } | |
115 | } | |
116 | //____________________________________________________________________ | |
117 | AliCFFrame::AliCFFrame(const AliCFFrame& c) : | |
118 | TNamed(), | |
119 | fNVar(0), | |
120 | fNDim(0), | |
121 | fNVarBinLimits(0), | |
122 | fNVarBins(0x0), | |
123 | fIndex(0x0), | |
124 | fProduct(0x0), | |
125 | fOffset(0x0), | |
126 | fVarBinLimits(0x0) | |
127 | { | |
128 | // | |
129 | // copy constructor | |
130 | // | |
131 | ((AliCFFrame &)c).Copy(*this); | |
132 | } | |
133 | //____________________________________________________________________ | |
134 | AliCFFrame::~AliCFFrame() | |
135 | { | |
136 | // | |
137 | // destructor | |
138 | // | |
139 | if(fNVarBins)delete [] fNVarBins; | |
140 | if(fVarBinLimits)delete [] fVarBinLimits; | |
141 | if(fIndex)delete [] fIndex; | |
142 | if(fProduct)delete [] fProduct; | |
143 | if(fOffset)delete [] fOffset; | |
144 | ||
145 | } | |
146 | //____________________________________________________________________ | |
147 | AliCFFrame &AliCFFrame::operator=(const AliCFFrame &c) | |
148 | { | |
149 | // | |
150 | // assigment operator | |
151 | // | |
152 | if (this != &c) | |
153 | ((AliCFFrame &) c).Copy(*this); | |
154 | return *this; | |
155 | } | |
156 | //____________________________________________________________________ | |
157 | void AliCFFrame::SetBinLimits(Int_t ivar, Float_t *array) | |
158 | { | |
159 | // | |
160 | // setting the arrays containing the bin limits | |
161 | // | |
162 | Int_t nbins=fNVarBins[ivar]+1; | |
163 | for(Int_t i=0;i<nbins;i++){ | |
164 | fVarBinLimits[fOffset[ivar]+i] =array[i]; | |
165 | } | |
166 | } | |
167 | //____________________________________________________________________ | |
168 | void AliCFFrame::GetBinLimits(Int_t ivar, Float_t *array) const | |
169 | { | |
170 | // | |
171 | // getting the arrays containing the bin limits | |
172 | // | |
173 | Int_t nbins=fNVarBins[ivar]+1; | |
174 | for(Int_t i=0;i<nbins;i++){ | |
175 | array[i]=fVarBinLimits[fOffset[ivar]+i]; | |
176 | } | |
177 | } | |
178 | //____________________________________________________________________ | |
179 | Int_t AliCFFrame::GetBinIndex(Int_t *ibin) const | |
180 | { | |
181 | // | |
182 | // getting the element number on the grid for a given set of bin indeces | |
183 | // | |
184 | Int_t ind=ibin[fNVar-1]; | |
185 | for(Int_t i=fNVar-1;i>0;i--){ | |
186 | ind=ibin[i-1]+ind*fNVarBins[i-1]; | |
187 | } | |
188 | return ind; | |
189 | } | |
190 | //____________________________________________________________________ | |
191 | Int_t AliCFFrame::GetBinIndex(Int_t ivar, Int_t ind) const | |
192 | { | |
193 | // | |
194 | // getting the bin index on a given dim. ivar for a given element ind on the grid | |
195 | // | |
196 | Int_t index=-1; | |
197 | for(Int_t i=fNVar-1;i>=0;i--){ | |
198 | index=ind/fProduct[i]; | |
199 | fIndex[i]=index; | |
200 | ind-=index*fProduct[i]; | |
201 | } | |
202 | ||
203 | index=fIndex[ivar]; | |
204 | return index; | |
205 | } | |
206 | //____________________________________________________________________ | |
207 | void AliCFFrame::GetBinIndex(Int_t ind, Int_t *bins ) const | |
208 | { | |
209 | // | |
210 | // getting the set of bin indeces for a given element ind on the grid | |
211 | // | |
212 | Int_t index=-1; | |
213 | for(Int_t i=fNVar-1;i>=0;i--){ | |
214 | index=ind/fProduct[i]; | |
215 | bins[i]=index; | |
216 | ind-=index*fProduct[i]; | |
217 | } | |
218 | return; | |
219 | } | |
220 | //____________________________________________________________________ | |
221 | Float_t AliCFFrame::GetBinCenter(Int_t ivar, Int_t ibin) const | |
222 | { | |
223 | // | |
224 | // getting the bin center of a given bin ibin on the dim. (axis) ivar | |
225 | // | |
226 | ||
227 | Float_t binMin=fVarBinLimits[fOffset[ivar]+ibin]; | |
228 | Float_t binMax=fVarBinLimits[fOffset[ivar]+ibin+1]; | |
229 | Float_t val=0.5*(binMin+binMax); | |
230 | return val; | |
231 | } | |
232 | //____________________________________________________________________ | |
233 | void AliCFFrame::GetBinCenter(Int_t *ibin, Float_t *binCenter) const | |
234 | { | |
235 | // | |
236 | // gives the centers of the N-dim bin identified by a set of bin indeces | |
237 | // invar | |
238 | // | |
239 | for(Int_t i=0;i<fNVar;i++){ | |
240 | binCenter[i]=GetBinCenter(i,ibin[i]); | |
241 | } | |
242 | } | |
243 | //____________________________________________________________________ | |
244 | void AliCFFrame::Copy(TObject& c) const | |
245 | { | |
246 | // | |
247 | // copy function | |
248 | // | |
249 | AliCFFrame& target = (AliCFFrame &) c; | |
250 | ||
251 | target.fNVar=fNVar; | |
252 | target.fNDim=fNDim; | |
253 | target.fNVarBinLimits=fNVarBinLimits; | |
254 | if (fNVarBins) | |
255 | target.fNVarBins = fNVarBins; | |
256 | if (fVarBinLimits) | |
257 | target.fVarBinLimits = fVarBinLimits; | |
258 | if (fProduct) | |
259 | target.fProduct = fProduct; | |
260 | if (fOffset) | |
261 | target.fOffset = fOffset; | |
262 | } | |
263 | //____________________________________________________________________ | |
264 | void AliCFFrame::PrintBinLimits() | |
265 | { | |
266 | // | |
267 | // printing the array containing the bin limits | |
268 | // | |
269 | for(Int_t i=0;i<fNVarBinLimits;i++){ | |
270 | AliInfo(Form("bin limit index %i is: %f",i, fVarBinLimits[i])); | |
271 | } | |
272 | } | |
273 | //____________________________________________________________________ | |
274 | void AliCFFrame::PrintNBins() | |
275 | { | |
276 | // | |
277 | // printing the array containing the # of bins | |
278 | // | |
279 | for(Int_t i=0;i<fNVar;i++){ | |
280 | AliInfo(Form("bins in var %i are: %i",i, fNVarBins[i])); | |
281 | } | |
282 | } | |
283 | //____________________________________________________________________ | |
284 | void AliCFFrame::Save(const Char_t *outfile) const | |
285 | { | |
286 | // | |
287 | // Save the grid to a root file | |
288 | // | |
289 | ||
290 | const char *dirname = "./"; | |
291 | TString filename = outfile; | |
292 | TFile *file=0x0; | |
293 | if((gSystem->FindFile(dirname,filename))!=NULL){ | |
294 | file = new TFile( outfile,"UPDATE"); | |
295 | } | |
296 | else{ | |
297 | file = new TFile( outfile,"RECREATE"); | |
298 | } | |
299 | file->cd(); | |
300 | //write the object to a file | |
301 | this->Write(GetName(),TObject::kSingleKey); | |
302 | file->Close(); | |
303 | delete file; | |
304 | } |