]>
Commit | Line | Data |
---|---|---|
8d122774 | 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 | /* $Id$ */ | |
17 | ||
18 | //------------------------------------------------------------------------- | |
19 | // AOD class to store calorimeter cell data | |
20 | // Author: Markus Oldenburg, CERN | |
21 | //------------------------------------------------------------------------- | |
22 | ||
23 | #include "AliAODCaloCells.h" | |
24 | ||
25 | ClassImp(AliAODCaloCells) | |
26 | ||
77e93dc2 | 27 | //_______________________________________________________ |
28 | AliAODCaloCells::AliAODCaloCells() : | |
29 | AliVCaloCells(), fNCells(0), fCellNumber(0), | |
30 | fAmplitude(0), fTime(0), fEFraction(0), fMCLabel(0), | |
31 | fIsSorted(kTRUE), fType(kUndef) | |
8d122774 | 32 | { |
33 | // default constructor | |
34 | } | |
35 | ||
77e93dc2 | 36 | //_____________________________________________________________________________________ |
c8fe2783 | 37 | AliAODCaloCells::AliAODCaloCells(const char* name, const char* title, VCells_t ttype) : |
77e93dc2 | 38 | AliVCaloCells(name, title), fNCells(0), fCellNumber(0), |
39 | fAmplitude(0), fTime(0), fEFraction(0), fMCLabel(0), | |
40 | fIsSorted(kTRUE), fType(ttype) | |
8d122774 | 41 | { |
c8fe2783 | 42 | //constructor |
8d122774 | 43 | } |
44 | ||
77e93dc2 | 45 | //________________________________________________________________ |
5c1dc41f | 46 | AliAODCaloCells::AliAODCaloCells(const AliAODCaloCells& cells) : |
77e93dc2 | 47 | AliVCaloCells(cells), fNCells(cells.fNCells), fCellNumber(0), |
48 | fAmplitude(0), fTime(0), fEFraction(0), fMCLabel(0), | |
49 | fIsSorted(cells.fIsSorted), fType(cells.fType) | |
5c1dc41f | 50 | { |
51 | // Copy constructor | |
c8fe2783 | 52 | fCellNumber = new Short_t[fNCells]; |
53 | fAmplitude = new Double32_t[fNCells]; | |
77e93dc2 | 54 | fTime = new Double32_t[fNCells]; |
55 | fMCLabel = new Short_t[fNCells]; | |
56 | fEFraction = new Double32_t[fNCells]; | |
57 | ||
c8fe2783 | 58 | for (Int_t i = 0; i < fNCells; i++) { |
59 | fCellNumber[i] = cells.fCellNumber[i]; | |
60 | fAmplitude[i] = cells.fAmplitude[i]; | |
77e93dc2 | 61 | if(cells.fMCLabel) fTime[i] = cells.fTime[i]; |
62 | if(cells.fMCLabel) fMCLabel[i] = cells.fMCLabel[i]; | |
63 | if(cells.fEFraction)fEFraction[i] = cells.fEFraction[i]; | |
c8fe2783 | 64 | } |
5c1dc41f | 65 | } |
66 | ||
77e93dc2 | 67 | //________________________________________________________________________ |
0d7404df | 68 | AliAODCaloCells& AliAODCaloCells::operator=(const AliAODCaloCells& source) |
5c1dc41f | 69 | { |
77e93dc2 | 70 | // Assignment operator |
71 | if(this != &source) | |
72 | { | |
0d7404df | 73 | AliVCaloCells::operator=(source); |
74 | ||
77e93dc2 | 75 | if(fNCells != source.fNCells) |
76 | { | |
0d7404df | 77 | delete [] fCellNumber; |
78 | delete [] fAmplitude; | |
77e93dc2 | 79 | delete [] fTime; |
80 | delete [] fMCLabel; | |
81 | delete [] fEFraction; | |
82 | ||
0d7404df | 83 | fNCells = source.fNCells; |
77e93dc2 | 84 | |
0d7404df | 85 | fCellNumber = new Short_t[fNCells]; |
86 | fAmplitude = new Double32_t[fNCells]; | |
77e93dc2 | 87 | fTime = new Double32_t[fNCells]; |
88 | fMCLabel = new Short_t[fNCells]; | |
89 | fEFraction = new Double32_t[fNCells]; | |
0d7404df | 90 | } |
77e93dc2 | 91 | |
0d7404df | 92 | memcpy(fCellNumber,source.fCellNumber, fNCells*sizeof(Short_t)); |
93 | memcpy(fAmplitude, source.fAmplitude, fNCells*sizeof(Double32_t)); | |
77e93dc2 | 94 | if(source.fTime && fTime) memcpy(fTime, source.fTime, fNCells*sizeof(Double32_t)); |
95 | if(source.fMCLabel && fMCLabel) memcpy(fMCLabel, source.fMCLabel, fNCells*sizeof(Short_t)); | |
96 | if(source.fEFraction && fEFraction) memcpy(fEFraction, source.fEFraction, fNCells*sizeof(Double32_t)); | |
97 | ||
0d7404df | 98 | fIsSorted = source.fIsSorted; |
99 | fType = source.fType; | |
c8fe2783 | 100 | } |
0d7404df | 101 | |
c8fe2783 | 102 | return *this; |
0d7404df | 103 | |
5c1dc41f | 104 | } |
105 | ||
77e93dc2 | 106 | //_________________________________ |
8d122774 | 107 | AliAODCaloCells::~AliAODCaloCells() |
108 | { | |
109 | // destructor | |
110 | ||
111 | DeleteContainer(); | |
112 | } | |
113 | ||
8dd6eba0 | 114 | void AliAODCaloCells::Clear(const Option_t*) |
115 | { | |
116 | // clear | |
117 | ||
118 | DeleteContainer(); | |
119 | } | |
ecff8f07 | 120 | |
77e93dc2 | 121 | void AliAODCaloCells::Copy(TObject &obj) const |
122 | { | |
ecff8f07 | 123 | |
124 | // this overwrites the virtual TOBject::Copy() | |
125 | // to allow run time copying without casting | |
126 | // in AliESDEvent | |
127 | ||
128 | if(this==&obj)return; | |
129 | AliAODCaloCells *robj = dynamic_cast<AliAODCaloCells*>(&obj); | |
130 | if(!robj)return; // not an AliAODCaloCells | |
131 | *robj = *this; | |
132 | ||
133 | } | |
134 | ||
77e93dc2 | 135 | //______________________________________________________________________ |
136 | AliVCaloCells *AliAODCaloCells::CopyCaloCells(Bool_t all = kTRUE) const | |
137 | { | |
ecff8f07 | 138 | |
139 | // copy the calo cells into a new object. If option all=FALSE, just the object type, | |
140 | // for mixing | |
141 | ||
142 | AliVCaloCells *obj = new AliAODCaloCells(); | |
143 | ||
144 | if(all){ | |
145 | obj->SetName (GetName()) ; | |
146 | obj->SetTitle(GetTitle()) ; | |
147 | obj->SetType (GetType()) ; | |
148 | ||
149 | obj->SetNumberOfCells(fNCells); | |
150 | for (Short_t i = 0; i < fNCells; i++) | |
77e93dc2 | 151 | { |
152 | Int_t mclabel = -1; | |
153 | if(fMCLabel) mclabel = fMCLabel[i]; | |
154 | ||
155 | Float_t efrac = 0.; | |
156 | if(fEFraction) efrac = fEFraction[i]; | |
157 | ||
158 | Float_t time = -1; | |
159 | if(fTime) time = fTime[i]; | |
160 | ||
161 | obj->SetCell(i,fCellNumber[i],fAmplitude[i],time,mclabel,efrac); | |
162 | } | |
ecff8f07 | 163 | } |
164 | ||
165 | return obj; | |
166 | ||
167 | } | |
168 | ||
77e93dc2 | 169 | //___________________________________________________ |
8d122774 | 170 | void AliAODCaloCells::CreateContainer(Short_t nCells) |
171 | { | |
172 | // function that creates container to store calorimeter cell data | |
173 | ||
174 | DeleteContainer(); | |
175 | ||
176 | if (nCells <= 0) { | |
177 | fNCells = 0; | |
178 | return; | |
179 | } | |
180 | ||
181 | fNCells = nCells; | |
182 | ||
183 | fCellNumber = new Short_t[fNCells]; | |
c8fe2783 | 184 | fAmplitude = new Double32_t[fNCells]; |
77e93dc2 | 185 | fTime = new Double32_t[fNCells]; |
186 | fMCLabel = new Short_t[fNCells]; | |
187 | fEFraction = new Double32_t[fNCells]; | |
c8fe2783 | 188 | |
341952b8 | 189 | // set to zero |
190 | for(int i = 0;i<fNCells;++i){ | |
77e93dc2 | 191 | fAmplitude[i] = fCellNumber[i] = fTime[i] =fMCLabel[i] = fEFraction[i] = 0 ; |
341952b8 | 192 | } |
8d122774 | 193 | } |
194 | ||
77e93dc2 | 195 | //_____________________________________ |
8d122774 | 196 | void AliAODCaloCells::DeleteContainer() |
197 | { | |
198 | // deletes allocated memory | |
199 | ||
200 | if (fCellNumber) | |
201 | { | |
202 | delete[] fCellNumber; | |
c8fe2783 | 203 | fCellNumber = NULL; |
8d122774 | 204 | } |
205 | ||
206 | if (fAmplitude) | |
207 | { | |
208 | delete[] fAmplitude; | |
c8fe2783 | 209 | fAmplitude = NULL; |
8d122774 | 210 | } |
c8fe2783 | 211 | |
77e93dc2 | 212 | if (fTime) |
213 | { | |
214 | delete[] fTime; | |
215 | fTime = NULL; | |
216 | } | |
217 | ||
218 | if (fMCLabel) | |
219 | { | |
220 | delete[] fMCLabel; | |
221 | fMCLabel = NULL; | |
222 | } | |
223 | ||
224 | if (fEFraction) | |
225 | { | |
226 | delete[] fEFraction; | |
227 | fEFraction = NULL; | |
228 | } | |
229 | ||
230 | ||
8d122774 | 231 | fNCells = 0; |
232 | fIsSorted = kFALSE; | |
233 | } | |
234 | ||
77e93dc2 | 235 | //__________________________ |
8d122774 | 236 | void AliAODCaloCells::Sort() |
237 | { | |
238 | // sort the cell array by cell number | |
239 | ||
240 | Int_t *idxArray = new Int_t[fNCells]; | |
241 | TMath::Sort(fNCells,fCellNumber,idxArray,kFALSE); | |
242 | ||
c8fe2783 | 243 | Short_t *newIndex = new Short_t[fNCells]; |
8d122774 | 244 | Double32_t *newAmplitude = new Double32_t[fNCells]; |
77e93dc2 | 245 | Double32_t *newTime = new Double32_t[fNCells]; |
246 | Short_t *newMCLabel = new Short_t[fNCells]; | |
247 | Double32_t *newEFraction = new Double32_t[fNCells]; | |
248 | ||
249 | for (Int_t i=0; i < fNCells; i++) | |
250 | { | |
c8fe2783 | 251 | newIndex[i] = fCellNumber[idxArray[i]]; |
77e93dc2 | 252 | newAmplitude[i] = fAmplitude [idxArray[i]]; |
253 | if(fTime) newTime[i] = fTime [idxArray[i]]; | |
254 | if(fMCLabel) newMCLabel[i] = fMCLabel [idxArray[i]]; | |
255 | if(fEFraction) newEFraction[i] = fEFraction[idxArray[i]]; | |
8d122774 | 256 | } |
77e93dc2 | 257 | |
8d122774 | 258 | delete [] fCellNumber; |
259 | delete [] fAmplitude; | |
77e93dc2 | 260 | delete [] fTime; |
261 | delete [] fMCLabel; | |
262 | delete [] fEFraction; | |
263 | ||
264 | ||
8d122774 | 265 | fCellNumber = newIndex; |
c8fe2783 | 266 | fAmplitude = newAmplitude; |
77e93dc2 | 267 | if(fTime) fTime = newTime; |
268 | if(fMCLabel) fMCLabel = newMCLabel; | |
269 | if(fEFraction) fEFraction = newEFraction; | |
270 | ||
8d122774 | 271 | delete [] idxArray; |
272 | ||
273 | fIsSorted = kTRUE; | |
274 | } | |
275 | ||
77e93dc2 | 276 | //________________________________________________________________________________________ |
277 | Bool_t AliAODCaloCells::SetCell(Short_t pos, Short_t cellNumber, Double32_t amplitude, | |
278 | Double32_t time, Short_t mclabel, Double32_t efrac) | |
8d122774 | 279 | { |
280 | // Sets a cell at the given position | |
281 | ||
77e93dc2 | 282 | if (pos>=0 && pos < fNCells) |
283 | { | |
8d122774 | 284 | fCellNumber[pos] = cellNumber; |
c8fe2783 | 285 | fAmplitude[pos] = amplitude; |
77e93dc2 | 286 | |
287 | if(!fTime) fTime = new Double_t[fNCells]; | |
288 | if(!fMCLabel) fMCLabel = new Short_t[fNCells]; | |
289 | if(!fEFraction) fEFraction = new Double32_t[fNCells]; | |
290 | ||
291 | fTime[pos] = time; | |
292 | fMCLabel[pos] = mclabel; | |
293 | fEFraction[pos] = efrac; | |
294 | ||
295 | fIsSorted = kFALSE; | |
296 | ||
8d122774 | 297 | return kTRUE; |
77e93dc2 | 298 | |
8d122774 | 299 | } else { |
300 | return kFALSE; | |
301 | } | |
302 | } | |
77e93dc2 | 303 | |
304 | ||
305 | ||
306 |