]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PHOS/AliPHOSDigit.cxx
Use cloning of AliESDtrack to ExternalTrackParam rather than AliESDtrack
[u/mrichter/AliRoot.git] / PHOS / AliPHOSDigit.cxx
CommitLineData
d15a28e7 1/**************************************************************************
2 * Copyright(c) 1998-1999, 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
b2a60966 16/* $Id$ */
17
702ab87e 18/* History of cvs commits:
19 *
20 * $Log$
3663622c 21 * Revision 1.39 2006/04/22 15:04:24 hristov
22 * Effective C++ initialization of data members in the default constructor
23 *
f146da82 24 * Revision 1.38 2006/04/22 10:30:17 hristov
25 * Add fEnergy to AliPHOSDigit and operate with EMC amplitude in energy units (Yu.Kharlov)
26 *
27a73a5d 27 * Revision 1.37 2005/05/28 14:19:04 schutz
28 * Compilation warnings fixed by T.P.
29 *
702ab87e 30 */
31
d15a28e7 32//_________________________________________________________________________
b2a60966 33// PHOS digit: Id
34// energy
35// 3 identifiers for the primary particle(s) at the origine of the digit
36// The digits are made in FinishEvent() by summing all the hits in a single PHOS crystal or PPSD gas cell
b2a60966 37//
9688c1dd 38//*-- Author: Laurent Aphecetche & Yves Schutz (SUBATECH) & Dmitri Peressounko (RRC KI & SUBATECH)
b2a60966 39
d15a28e7 40
41// --- ROOT system ---
42
88cb7938 43#include "TMath.h"
44
d15a28e7 45// --- Standard library ---
46
d15a28e7 47// --- AliRoot header files ---
48
49#include "AliPHOSDigit.h"
46c3076b 50#include "AliLog.h"
d15a28e7 51
88cb7938 52
53
d15a28e7 54ClassImp(AliPHOSDigit)
55
cf239357 56//____________________________________________________________________________
f146da82 57AliPHOSDigit::AliPHOSDigit() :
58 AliDigitNew(),
59 fNprimary(0),
60 fPrimary(0x0),
61 fEnergy(0.),
62 fTime(0.),
54ac223e 63 fTimeR(0.),
64 fNSamplesHG(0),
65 fNSamplesLG(0),
66 fSamplesHG(0),
67 fSamplesLG(0)
cf239357 68{
b2a60966 69 // default ctor
cf239357 70}
71
d15a28e7 72//____________________________________________________________________________
3663622c 73AliPHOSDigit::AliPHOSDigit(Int_t primary, Int_t id, Int_t digEnergy, Float_t time, Int_t index) :
74 fNprimary(0),
75 fPrimary(0),
76 fEnergy(0.f),
77 fTime(0.f),
54ac223e 78 fTimeR(0.f),
79 fNSamplesHG(0),
80 fNSamplesLG(0),
81 fSamplesHG(0),
82 fSamplesLG(0)
d15a28e7 83{
b2a60966 84 // ctor with all data
85
7b7c1533 86 fAmp = digEnergy ;
27a73a5d 87 fEnergy = 0 ;
88 fTime = time ;
89 fTimeR = fTime ;
90 fId = id ;
91 fIndexInList = index ;
92 if( primary != -1){
93 fNprimary = 1 ;
94 fPrimary = new Int_t[fNprimary] ;
95 fPrimary[0] = primary ;
96 }
97 else{ //If the contribution of this primary smaller than fDigitThreshold (AliPHOSv1)
98 fNprimary = 0 ;
99 fPrimary = 0 ;
100 }
101}
102
103//____________________________________________________________________________
3663622c 104AliPHOSDigit::AliPHOSDigit(Int_t primary, Int_t id, Float_t energy, Float_t time, Int_t index) :
105 fNprimary(0),
106 fPrimary(0),
107 fEnergy(0.f),
108 fTime(0.f),
54ac223e 109 fTimeR(0.f),
110 fNSamplesHG(0),
111 fNSamplesLG(0),
112 fSamplesHG(0),
113 fSamplesLG(0)
27a73a5d 114{
115 // ctor with all data
116
117 fAmp = 0 ;
118 fEnergy = energy ;
9688c1dd 119 fTime = time ;
04f0bda3 120 fTimeR = fTime ;
83974468 121 fId = id ;
122 fIndexInList = index ;
4a2ca5e9 123 if( primary != -1){
124 fNprimary = 1 ;
adc232ca 125 fPrimary = new Int_t[fNprimary] ;
366c5d6f 126 fPrimary[0] = primary ;
4a2ca5e9 127 }
128 else{ //If the contribution of this primary smaller than fDigitThreshold (AliPHOSv1)
adc232ca 129 fNprimary = 0 ;
130 fPrimary = 0 ;
4a2ca5e9 131 }
cf239357 132}
133
134//____________________________________________________________________________
3663622c 135AliPHOSDigit::AliPHOSDigit(const AliPHOSDigit & digit) :
136 AliDigitNew(digit),
137 fNprimary(digit.fNprimary),
138 fPrimary(0),
139 fEnergy(digit.fEnergy),
140 fTime(digit.fTime),
54ac223e 141 fTimeR(digit.fTimeR),
142 fNSamplesHG(0),
143 fNSamplesLG(0),
144 fSamplesHG(0),
145 fSamplesLG(0)
b2a60966 146{
147 // copy ctor
adc232ca 148 if(fNprimary){
149 fPrimary = new Int_t[fNprimary] ;
150 for (Int_t i = 0; i < fNprimary ; i++)
151 fPrimary[i] = digit.fPrimary[i] ;
152 }
153 else
154 fPrimary = 0 ;
83974468 155 fAmp = digit.fAmp ;
156 fId = digit.fId;
157 fIndexInList = digit.fIndexInList ;
ff4c968a 158}
159
6c8ba828 160//____________________________________________________________________________
161AliPHOSDigit & AliPHOSDigit::operator = (const AliPHOSDigit &)
162{
163 Fatal("operator =", "not implemented");
164 return *this;
165}
2e5c3041 166//____________________________________________________________________________
36d93c12 167AliPHOSDigit::~AliPHOSDigit()
2e5c3041 168{
54ac223e 169 // Delete array of primaries if any
170 if (fPrimary) delete [] fPrimary ;
171 // Delete arrays of ALTRO samples if any
172 if (fSamplesHG) delete [] fSamplesHG;
173 if (fSamplesLG) delete [] fSamplesLG;
2e5c3041 174}
175
d15a28e7 176//____________________________________________________________________________
037cc66d 177Int_t AliPHOSDigit::Compare(const TObject * obj) const
d15a28e7 178{
b2a60966 179 // Compares two digits with respect to its Id
180 // to sort according increasing Id
181
88714635 182 Int_t rv ;
cf239357 183
184 AliPHOSDigit * digit = (AliPHOSDigit *)obj ;
185
186 Int_t iddiff = fId - digit->GetId() ;
187
188 if ( iddiff > 0 )
189 rv = 1 ;
190 else if ( iddiff < 0 )
191 rv = -1 ;
192 else
193 rv = 0 ;
194
195 return rv ;
196
197}
26d4b141 198
199//____________________________________________________________________________
200Int_t AliPHOSDigit::GetPrimary(Int_t index) const
201{
2f04ed65 202 // retrieves the primary particle number given its index in the list
36d93c12 203 Int_t rv = -1 ;
36641f9d 204 if ( index <= fNprimary && index > 0){
36d93c12 205 rv = fPrimary[index-1] ;
206 }
26d4b141 207
208 return rv ;
366c5d6f 209
26d4b141 210}
54ac223e 211
212//____________________________________________________________________________
213void AliPHOSDigit::SetALTROSamplesHG(Int_t nSamplesHG, Int_t *samplesHG)
214{
215 fNSamplesHG = nSamplesHG;
48b634ff 216 if (fSamplesHG) delete [] fSamplesHG;
54ac223e 217 fSamplesHG = new UShort_t[fNSamplesHG];
218 UShort_t i;
219 for (i=0; i<fNSamplesHG; i++) {
220 fSamplesHG[i] = samplesHG[i];
221 }
222}
223//____________________________________________________________________________
224void AliPHOSDigit::SetALTROSamplesLG(Int_t nSamplesLG, Int_t *samplesLG)
225{
226 fNSamplesLG = nSamplesLG;
48b634ff 227 if (fSamplesLG) delete [] fSamplesLG;
54ac223e 228 fSamplesLG = new UShort_t[fNSamplesLG];
229 UShort_t i;
230 for (i=0; i<fNSamplesLG; i++) {
231 fSamplesLG[i] = samplesLG[i];
232 }
233}
990119d6 234//____________________________________________________________________________
702ab87e 235void AliPHOSDigit::Print(const Option_t *) const
d8ca0b45 236{
e957fea8 237 // Print the digit together with list of primaries
46c3076b 238 TString line = Form("PHOS digit: E=%.3f, Id=%d, Time=%.3e, TimeR=%.3e, NPrim=%d, nHG=%d, nLG=%d \n",
239 fEnergy,fId,fTime,fTimeR,fNprimary,fNSamplesHG,fNSamplesLG);
240 line += "\tList of primaries: ";
54ac223e 241 for (Int_t index = 0; index <fNprimary; index ++ )
46c3076b 242 line += Form(" %d ",fPrimary[index]);
243 line += "\n";
244 line += "\tSamples HG: ";
54ac223e 245 for (Int_t i = 0; i <fNSamplesHG; i++)
46c3076b 246 line += Form(" %d ",fSamplesHG[i]);
247 line += "\n";
248 line += "\tSamples LG: ";
54ac223e 249 for (Int_t i = 0; i <fNSamplesLG; i++)
46c3076b 250 line += Form(" %d ",fSamplesLG[i]);
251 line += "\n";
252 AliDebug(2,line);
d8ca0b45 253}
254//____________________________________________________________________________
a4e98857 255void AliPHOSDigit::ShiftPrimary(Int_t shift)
256{
257 //shifts primary number to BIG offset, to separate primary in different TreeK
adc232ca 258 for(Int_t index = 0; index <fNprimary; index ++ ){
259 fPrimary[index]+= shift ;
990119d6 260 }
261}
cf239357 262//____________________________________________________________________________
263Bool_t AliPHOSDigit::operator==(AliPHOSDigit const & digit) const
264{
b2a60966 265 // Two digits are equal if they have the same Id
266
cf239357 267 if ( fId == digit.fId )
d15a28e7 268 return kTRUE ;
269 else
270 return kFALSE ;
271}
cf239357 272
d15a28e7 273//____________________________________________________________________________
3663622c 274AliPHOSDigit& AliPHOSDigit::operator+=(AliPHOSDigit const & digit)
d15a28e7 275{
adc232ca 276
b2a60966 277 // Adds the amplitude of digits and completes the list of primary particles
adc232ca 278 if(digit.fNprimary>0){
279 Int_t *tmp = new Int_t[fNprimary+digit.fNprimary] ;
27a73a5d 280 if(fAmp < digit.fAmp || fEnergy < digit.fEnergy){//most energetic primary in second digit => first primaries in list from second digit
adc232ca 281 for (Int_t index = 0 ; index < digit.fNprimary ; index++)
282 tmp[index]=(digit.fPrimary)[index] ;
283 for (Int_t index = 0 ; index < fNprimary ; index++)
284 tmp[index+digit.fNprimary]=fPrimary[index] ;
285 }
286 else{ //add new primaries to the end
287 for (Int_t index = 0 ; index < fNprimary ; index++)
288 tmp[index]=fPrimary[index] ;
289 for (Int_t index = 0 ; index < digit.fNprimary ; index++)
290 tmp[index+fNprimary]=(digit.fPrimary)[index] ;
291 }
292 if(fPrimary)
293 delete []fPrimary ;
294 fPrimary = tmp ;
295 }
296 fNprimary+=digit.fNprimary ;
27a73a5d 297 fAmp += digit.fAmp ;
298 fEnergy += digit.fEnergy ;
adc232ca 299 if(fTime > digit.fTime)
300 fTime = digit.fTime ;
04f0bda3 301 fTimeR = fTime ;
54ac223e 302
303 // Add high-gain ALTRO samples
304 UShort_t i;
305 if (digit.fNSamplesHG > fNSamplesHG) {
306 UShort_t newNSamplesHG = digit.fNSamplesHG;
307 UShort_t *newSamplesHG = new UShort_t[newNSamplesHG];
308 for (i=0; i<newNSamplesHG; i++) {
309 if (i<fNSamplesHG)
310 newSamplesHG[i] = TMath::Max(1023,fSamplesHG[i] + (digit.fSamplesHG)[i]);
311 else
312 newSamplesHG[i] = (digit.fSamplesHG)[i];
313 }
314 delete [] fSamplesHG;
315 fSamplesHG = new UShort_t[newNSamplesHG];
316 for (i=0; i<newNSamplesHG; i++) {
317 fSamplesHG[i] = newSamplesHG[i];
318 }
319 delete [] newSamplesHG;
320 }
321 else {
322 for (i=0; i<fNSamplesHG; i++)
323 fSamplesHG[i] = TMath::Max(1023,fSamplesHG[i] + (digit.fSamplesHG)[i]);
324 }
325
326 // Add low-gain ALTRO samples
327 if (digit.fNSamplesLG > fNSamplesLG) {
328 UShort_t newNSamplesLG = digit.fNSamplesLG;
329 UShort_t *newSamplesLG = new UShort_t[newNSamplesLG];
330 for (i=0; i<newNSamplesLG; i++) {
331 if (i<fNSamplesLG)
332 newSamplesLG[i] = TMath::Max(1023,fSamplesLG[i] + (digit.fSamplesLG)[i]);
333 else
334 newSamplesLG[i] = (digit.fSamplesLG)[i];
335 }
336 delete [] fSamplesLG;
337 fSamplesLG = new UShort_t[newNSamplesLG];
338 for (i=0; i<newNSamplesLG; i++) {
339 fSamplesLG[i] = newSamplesLG[i];
340 }
341 delete [] newSamplesLG;
342 }
343 else {
344 for (i=0; i<fNSamplesLG; i++)
345 fSamplesLG[i] = TMath::Max(1023,fSamplesLG[i] + (digit.fSamplesLG)[i]);
346 }
347
adc232ca 348 return *this ;
88cb7938 349}
88cb7938 350//____________________________________________________________________________
3663622c 351AliPHOSDigit& AliPHOSDigit::operator *= (Float_t factor)
88cb7938 352{
353 // Multiplies the amplitude by a factor
bb53c80c 354
88cb7938 355 Float_t tempo = static_cast<Float_t>(fAmp) ;
356 tempo *= factor ;
357 fAmp = static_cast<Int_t>(TMath::Ceil(tempo)) ;
d15a28e7 358 return *this ;
359}
360
361//____________________________________________________________________________
cf239357 362ostream& operator << ( ostream& out , const AliPHOSDigit & digit)
d15a28e7 363{
b2a60966 364 // Prints the data of the digit
365
21cd0c07 366// out << "ID " << digit.fId << " Energy = " << digit.fAmp << " Time = " << digit.fTime << endl ;
367// Int_t i ;
368// for(i=0;i<digit.fNprimary;i++)
369// out << "Primary " << i+1 << " = " << digit.fPrimary[i] << endl ;
370// out << "Position in list = " << digit.fIndexInList << endl ;
371 digit.Warning("operator <<", "Implement differently") ;
d15a28e7 372 return out ;
373}
374
cf239357 375