Line data Source code
1 : /**************************************************************************
2 : * Copyright(c) 1998-2007, ALICE Experiment at CERN, All rights reserved. *
3 : * *
4 : * Author: The ALICE Off-line Project. *
5 : * Contributors are mentioned in the code where appropriate. *
6 : * *
7 : * Permission to use, copy, modify and distribute this software and its *
8 : * documentation strictly for non-commercial purposes is hereby granted *
9 : * without fee, provided that the above copyright notice appears in all *
10 : * copies and that both the copyright notice and this permission notice *
11 : * appear in the supporting documentation. The authors make no claims *
12 : * about the suitability of this software for any purpose. It is *
13 : * provided "as is" without express or implied warranty. *
14 : **************************************************************************/
15 :
16 : #include "AliAODCaloCells.h"
17 :
18 : /// \cond CLASSIMP
19 170 : ClassImp(AliAODCaloCells) ;
20 : /// \endcond
21 :
22 : ///
23 : /// Default constructor.
24 : ///
25 : //_______________________________________________________
26 : AliAODCaloCells::AliAODCaloCells() :
27 8 : AliVCaloCells(), fNCells(0), fHGLG(0), fCellNumber(0),
28 4 : fAmplitude(0), fTime(0), fEFraction(0), fMCLabel(0),
29 4 : fIsSorted(kTRUE), fType(kUndef)
30 20 : {
31 8 : }
32 :
33 : ///
34 : /// Constructor.
35 : ///
36 : //_____________________________________________________________________________________
37 : AliAODCaloCells::AliAODCaloCells(const char* name, const char* title, VCells_t ttype) :
38 0 : AliVCaloCells(name, title), fNCells(0), fHGLG(0), fCellNumber(0),
39 0 : fAmplitude(0), fTime(0), fEFraction(0), fMCLabel(0),
40 0 : fIsSorted(kTRUE), fType(ttype)
41 0 : {
42 0 : }
43 :
44 : ///
45 : /// Copy constructor.
46 : ///
47 : //________________________________________________________________
48 : AliAODCaloCells::AliAODCaloCells(const AliAODCaloCells& cells) :
49 0 : AliVCaloCells(cells), fNCells(cells.fNCells), fHGLG(0), fCellNumber(0),
50 0 : fAmplitude(0), fTime(0), fEFraction(0), fMCLabel(0),
51 0 : fIsSorted(cells.fIsSorted), fType(cells.fType)
52 0 : {
53 0 : fCellNumber = new Short_t[fNCells];
54 0 : fAmplitude = new Double32_t[fNCells];
55 0 : fTime = new Double32_t[fNCells];
56 0 : fMCLabel = new Int_t[fNCells];
57 0 : fEFraction = new Double32_t[fNCells];
58 :
59 0 : for (Int_t i = 0; i < fNCells; i++) {
60 0 : fCellNumber[i] = cells.fCellNumber[i];
61 0 : fAmplitude[i] = cells.fAmplitude[i];
62 0 : if(cells.fTime) fTime[i] = cells.fTime[i];
63 0 : if(cells.fMCLabel) fMCLabel[i] = cells.fMCLabel[i];
64 0 : if(cells.fEFraction)fEFraction[i] = cells.fEFraction[i];
65 : }
66 0 : if(cells.fHGLG){
67 0 : fHGLG = new Bool_t[fNCells] ;
68 0 : for (Int_t i = 0; i < fNCells; i++) {
69 0 : fHGLG[i] = cells.fHGLG[i];
70 : }
71 0 : }
72 0 : }
73 :
74 : ///
75 : /// Assignment operator.
76 : ///
77 : //________________________________________________________________________
78 : AliAODCaloCells& AliAODCaloCells::operator=(const AliAODCaloCells& source)
79 : {
80 0 : if(this != &source)
81 : {
82 0 : AliVCaloCells::operator=(source);
83 :
84 0 : if(fNCells != source.fNCells)
85 : {
86 0 : if(fHGLG)
87 0 : delete [] fHGLG ;
88 0 : delete [] fCellNumber;
89 0 : delete [] fAmplitude;
90 0 : delete [] fTime;
91 0 : delete [] fMCLabel;
92 0 : delete [] fEFraction;
93 :
94 0 : fNCells = source.fNCells;
95 :
96 0 : if(source.fHGLG)
97 0 : fHGLG = new Bool_t[fNCells] ;
98 0 : fCellNumber = new Short_t[fNCells];
99 0 : fAmplitude = new Double32_t[fNCells];
100 0 : fTime = new Double32_t[fNCells];
101 0 : fMCLabel = new Int_t[fNCells];
102 0 : fEFraction = new Double32_t[fNCells];
103 0 : }
104 :
105 0 : if(source.fHGLG)
106 0 : memcpy(fCellNumber,source.fHGLG,fNCells*sizeof(Bool_t));
107 0 : memcpy(fCellNumber,source.fCellNumber, fNCells*sizeof(Short_t));
108 0 : memcpy(fAmplitude, source.fAmplitude, fNCells*sizeof(Double32_t));
109 0 : if(source.fTime && fTime) memcpy(fTime, source.fTime, fNCells*sizeof(Double32_t));
110 0 : if(source.fMCLabel && fMCLabel) memcpy(fMCLabel, source.fMCLabel, fNCells*sizeof(Int_t));
111 0 : if(source.fEFraction && fEFraction) memcpy(fEFraction, source.fEFraction, fNCells*sizeof(Double32_t));
112 :
113 0 : fIsSorted = source.fIsSorted;
114 0 : fType = source.fType;
115 0 : }
116 :
117 0 : return *this;
118 :
119 : }
120 :
121 : //_________________________________
122 : AliAODCaloCells::~AliAODCaloCells()
123 0 : {
124 : // destructor
125 :
126 0 : DeleteContainer();
127 0 : }
128 :
129 : ///
130 : /// Clear arrays.
131 : ///
132 : //__________________________________________
133 : void AliAODCaloCells::Clear(const Option_t*)
134 : {
135 0 : DeleteContainer();
136 0 : }
137 :
138 : ///
139 : /// This overwrites the virtual TObject::Copy()
140 : /// to allow run time copying without casting
141 : /// in AliAODEvent.
142 : ///
143 : //____________________________________________
144 : void AliAODCaloCells::Copy(TObject &obj) const
145 : {
146 0 : if(this==&obj)return;
147 0 : AliAODCaloCells *robj = dynamic_cast<AliAODCaloCells*>(&obj);
148 0 : if(!robj)return; // not an AliAODCaloCells
149 0 : *robj = *this;
150 0 : }
151 :
152 : ///
153 : /// Copy the calo cells into a new object. If option all=FALSE, just the object type,
154 : /// for mixing.
155 : ///
156 : //_____________________________________________________________________
157 : AliVCaloCells *AliAODCaloCells::CopyCaloCells(Bool_t all = kTRUE) const
158 : {
159 0 : AliVCaloCells *obj = new AliAODCaloCells();
160 :
161 0 : if(all){
162 0 : obj->SetName (GetName()) ;
163 0 : obj->SetTitle(GetTitle()) ;
164 0 : obj->SetType (GetType()) ;
165 :
166 0 : obj->SetNumberOfCells(fNCells);
167 0 : for (Short_t i = 0; i < fNCells; i++)
168 : {
169 : Int_t mclabel = -1;
170 0 : if(fMCLabel) mclabel = fMCLabel[i];
171 :
172 : Float_t efrac = 0.;
173 0 : if(fEFraction) efrac = fEFraction[i];
174 :
175 : Float_t time = -1;
176 0 : if(fTime) time = fTime[i];
177 :
178 0 : obj->SetCell(i,fCellNumber[i],fAmplitude[i],time,mclabel,efrac);
179 : }
180 0 : }
181 :
182 0 : return obj;
183 :
184 0 : }
185 :
186 : ///
187 : /// Function that creates container to store calorimeter cell data.
188 : ///
189 : //___________________________________________________
190 : void AliAODCaloCells::CreateContainer(Short_t nCells)
191 : {
192 32 : DeleteContainer();
193 :
194 16 : if (nCells <= 0)
195 : {
196 0 : fNCells = 0;
197 0 : return;
198 : }
199 :
200 16 : fNCells = nCells;
201 :
202 16 : fHGLG = new Bool_t[fNCells];
203 16 : fCellNumber = new Short_t[fNCells];
204 16 : fAmplitude = new Double32_t[fNCells];
205 16 : fTime = new Double32_t[fNCells];
206 16 : fMCLabel = new Int_t[fNCells];
207 16 : fEFraction = new Double32_t[fNCells];
208 :
209 : // set to zero
210 670 : for(int i = 0;i<fNCells;++i)
211 : {
212 319 : fHGLG[i]=kFALSE ;
213 319 : fAmplitude [i] = 0.;
214 319 : fCellNumber[i] = -1 ;
215 319 : fEFraction [i] = 0.;
216 319 : fTime [i] = -1.;
217 319 : fMCLabel [i] = -1 ;
218 : }
219 16 : }
220 :
221 : ///
222 : /// Deletes allocated memory.
223 : ///
224 : //_____________________________________
225 : void AliAODCaloCells::DeleteContainer()
226 : {
227 96 : if(fHGLG){
228 32 : delete[] fHGLG;
229 16 : fHGLG = 0 ;
230 16 : }
231 :
232 48 : if (fCellNumber)
233 : {
234 32 : delete[] fCellNumber;
235 16 : fCellNumber = NULL;
236 16 : }
237 :
238 48 : if (fAmplitude)
239 : {
240 32 : delete[] fAmplitude;
241 16 : fAmplitude = NULL;
242 16 : }
243 :
244 48 : if (fTime)
245 : {
246 32 : delete[] fTime;
247 16 : fTime = NULL;
248 16 : }
249 :
250 48 : if (fMCLabel)
251 : {
252 32 : delete[] fMCLabel;
253 16 : fMCLabel = NULL;
254 16 : }
255 :
256 48 : if (fEFraction)
257 : {
258 32 : delete[] fEFraction;
259 16 : fEFraction = NULL;
260 16 : }
261 :
262 :
263 48 : fNCells = 0;
264 48 : fIsSorted = kFALSE;
265 48 : }
266 :
267 : ///
268 : /// Sort the cell array by cell number.
269 : ///
270 : //__________________________
271 : void AliAODCaloCells::Sort()
272 : {
273 32 : Int_t *idxArray = new Int_t[fNCells];
274 16 : TMath::Sort(fNCells,fCellNumber,idxArray,kFALSE);
275 :
276 : Bool_t *newHGLG =0x0 ;
277 32 : if(fHGLG) newHGLG = new Bool_t[fNCells];
278 16 : Short_t *newIndex = new Short_t[fNCells];
279 16 : Double32_t *newAmplitude = new Double32_t[fNCells];
280 :
281 : Double32_t *newTime = 0 ;
282 : Int_t *newMCLabel = 0 ;
283 : Double32_t *newEFraction = 0 ;
284 32 : if(fTime) newTime = new Double32_t[fNCells];
285 32 : if(fMCLabel) newMCLabel = new Int_t[fNCells];
286 32 : if(fEFraction) newEFraction = new Double32_t[fNCells];
287 :
288 670 : for (Int_t i=0; i < fNCells; i++)
289 : {
290 319 : newIndex[i] = fCellNumber[idxArray[i]];
291 319 : newAmplitude[i] = fAmplitude [idxArray[i]];
292 638 : if(fTime) newTime[i] = fTime [idxArray[i]];
293 638 : if(fMCLabel) newMCLabel[i] = fMCLabel [idxArray[i]];
294 638 : if(fEFraction) newEFraction[i] = fEFraction[idxArray[i]];
295 : }
296 :
297 16 : if(fHGLG)
298 : {
299 670 : for (Int_t i=0; i < fNCells; i++)
300 : {
301 319 : newHGLG[i] = fHGLG[idxArray[i]];
302 : }
303 32 : delete [] fHGLG;
304 : }
305 :
306 32 : delete [] fCellNumber;
307 32 : delete [] fAmplitude;
308 32 : delete [] fTime;
309 32 : delete [] fMCLabel;
310 32 : delete [] fEFraction;
311 :
312 16 : fHGLG = newHGLG;
313 16 : fCellNumber = newIndex;
314 16 : fAmplitude = newAmplitude;
315 16 : fTime = newTime;
316 16 : fMCLabel = newMCLabel;
317 16 : fEFraction = newEFraction;
318 :
319 32 : delete [] idxArray;
320 :
321 16 : fIsSorted = kTRUE;
322 16 : }
323 :
324 : ///
325 : /// Sets a cell at the given position.
326 : /// \param pos: cell position in array.
327 : /// \param cellNumber: Cell absolute Id. number.
328 : /// \param amplitude: Cell signal (GeV).
329 : /// \param time: Cell time (s).
330 : /// \param mclabel: MC particle index in kine array.
331 : /// \param efrac: Fraction of energy from embedding.
332 : /// \param isHG: bool true if cell is from high gain.
333 : ///
334 : //________________________________________________________________________________________
335 : Bool_t AliAODCaloCells::SetCell(Short_t pos, Short_t cellNumber, Double32_t amplitude,
336 : Double32_t time, Int_t mclabel, Double32_t efrac, Bool_t isHG)
337 : {
338 1002 : if (pos>=0 && pos < fNCells)
339 : {
340 501 : if(fHGLG)
341 501 : fHGLG[pos]=isHG ;
342 501 : fCellNumber[pos] = cellNumber;
343 501 : fAmplitude[pos] = amplitude;
344 :
345 : // note: initialize (can't use memset for non-0 values)
346 : // plus sizeof(Double32_t) is 0
347 501 : if(!fTime){
348 0 : fTime = new Double32_t[fNCells];
349 :
350 0 : for( Int_t i = 0; i < fNCells; i++ )
351 0 : fTime[i] = -1;
352 0 : }
353 501 : if(!fMCLabel){
354 0 : fMCLabel = new Int_t[fNCells];
355 :
356 0 : for( Int_t i = 0; i < fNCells; i++ )
357 0 : fMCLabel[i] = -1;
358 0 : }
359 501 : if(!fEFraction){
360 0 : fEFraction = new Double32_t[fNCells];
361 :
362 0 : for( Int_t i = 0; i < fNCells; i++ )
363 0 : fEFraction[i] = 0;
364 0 : }
365 :
366 501 : fTime[pos] = time;
367 501 : fMCLabel[pos] = mclabel;
368 501 : fEFraction[pos] = efrac;
369 :
370 501 : fIsSorted = kFALSE;
371 :
372 501 : return kTRUE;
373 :
374 : } else {
375 0 : return kFALSE;
376 : }
377 501 : }
378 :
379 :
380 :
381 :
|