]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PHOS/AliPHOSDigit.cxx
Add components for jet analysis on mc and rec jets
[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(),
f1731579 59 fIsLG(0),
f146da82 60 fNprimary(0),
61 fPrimary(0x0),
62 fEnergy(0.),
63 fTime(0.),
54ac223e 64 fTimeR(0.),
65 fNSamplesHG(0),
66 fNSamplesLG(0),
67 fSamplesHG(0),
68 fSamplesLG(0)
cf239357 69{
b2a60966 70 // default ctor
cf239357 71}
72
d15a28e7 73//____________________________________________________________________________
3663622c 74AliPHOSDigit::AliPHOSDigit(Int_t primary, Int_t id, Int_t digEnergy, Float_t time, Int_t index) :
f1731579 75 fIsLG(0),
3663622c 76 fNprimary(0),
77 fPrimary(0),
78 fEnergy(0.f),
79 fTime(0.f),
54ac223e 80 fTimeR(0.f),
81 fNSamplesHG(0),
82 fNSamplesLG(0),
83 fSamplesHG(0),
84 fSamplesLG(0)
d15a28e7 85{
b2a60966 86 // ctor with all data
87
7b7c1533 88 fAmp = digEnergy ;
27a73a5d 89 fEnergy = 0 ;
90 fTime = time ;
91 fTimeR = fTime ;
92 fId = id ;
93 fIndexInList = index ;
f1731579 94
27a73a5d 95 if( primary != -1){
96 fNprimary = 1 ;
97 fPrimary = new Int_t[fNprimary] ;
98 fPrimary[0] = primary ;
99 }
100 else{ //If the contribution of this primary smaller than fDigitThreshold (AliPHOSv1)
101 fNprimary = 0 ;
102 fPrimary = 0 ;
103 }
104}
105
106//____________________________________________________________________________
3663622c 107AliPHOSDigit::AliPHOSDigit(Int_t primary, Int_t id, Float_t energy, Float_t time, Int_t index) :
f1731579 108 fIsLG(0),
3663622c 109 fNprimary(0),
110 fPrimary(0),
111 fEnergy(0.f),
112 fTime(0.f),
54ac223e 113 fTimeR(0.f),
114 fNSamplesHG(0),
115 fNSamplesLG(0),
116 fSamplesHG(0),
117 fSamplesLG(0)
27a73a5d 118{
119 // ctor with all data
120
121 fAmp = 0 ;
122 fEnergy = energy ;
9688c1dd 123 fTime = time ;
04f0bda3 124 fTimeR = fTime ;
83974468 125 fId = id ;
126 fIndexInList = index ;
4a2ca5e9 127 if( primary != -1){
128 fNprimary = 1 ;
adc232ca 129 fPrimary = new Int_t[fNprimary] ;
366c5d6f 130 fPrimary[0] = primary ;
4a2ca5e9 131 }
132 else{ //If the contribution of this primary smaller than fDigitThreshold (AliPHOSv1)
adc232ca 133 fNprimary = 0 ;
134 fPrimary = 0 ;
4a2ca5e9 135 }
cf239357 136}
137
138//____________________________________________________________________________
3663622c 139AliPHOSDigit::AliPHOSDigit(const AliPHOSDigit & digit) :
140 AliDigitNew(digit),
f1731579 141 fIsLG(digit.fIsLG),
e2ee64bd 142 fNprimary(digit.fNprimary),
3663622c 143 fPrimary(0),
144 fEnergy(digit.fEnergy),
145 fTime(digit.fTime),
54ac223e 146 fTimeR(digit.fTimeR),
147 fNSamplesHG(0),
148 fNSamplesLG(0),
149 fSamplesHG(0),
150 fSamplesLG(0)
b2a60966 151{
152 // copy ctor
adc232ca 153 if(fNprimary){
154 fPrimary = new Int_t[fNprimary] ;
155 for (Int_t i = 0; i < fNprimary ; i++)
156 fPrimary[i] = digit.fPrimary[i] ;
157 }
158 else
159 fPrimary = 0 ;
83974468 160 fAmp = digit.fAmp ;
161 fId = digit.fId;
162 fIndexInList = digit.fIndexInList ;
ff4c968a 163}
164
6c8ba828 165//____________________________________________________________________________
166AliPHOSDigit & AliPHOSDigit::operator = (const AliPHOSDigit &)
167{
168 Fatal("operator =", "not implemented");
169 return *this;
170}
2e5c3041 171//____________________________________________________________________________
36d93c12 172AliPHOSDigit::~AliPHOSDigit()
2e5c3041 173{
54ac223e 174 // Delete array of primaries if any
175 if (fPrimary) delete [] fPrimary ;
176 // Delete arrays of ALTRO samples if any
177 if (fSamplesHG) delete [] fSamplesHG;
178 if (fSamplesLG) delete [] fSamplesLG;
2e5c3041 179}
180
c6f49bef 181//____________________________________________________________________________
182void AliPHOSDigit::Clear(const Option_t*)
183{
184 // Delete array of primaries if any
185 delete[] fSamplesHG; fSamplesHG = NULL ;
186 delete[] fSamplesLG; fSamplesLG = NULL ;
187 delete[] fPrimary; fPrimary = NULL ;
188
189}
190
d15a28e7 191//____________________________________________________________________________
037cc66d 192Int_t AliPHOSDigit::Compare(const TObject * obj) const
d15a28e7 193{
b2a60966 194 // Compares two digits with respect to its Id
195 // to sort according increasing Id
196
88714635 197 Int_t rv ;
cf239357 198
199 AliPHOSDigit * digit = (AliPHOSDigit *)obj ;
200
201 Int_t iddiff = fId - digit->GetId() ;
202
203 if ( iddiff > 0 )
204 rv = 1 ;
205 else if ( iddiff < 0 )
206 rv = -1 ;
207 else
208 rv = 0 ;
209
210 return rv ;
211
212}
26d4b141 213
214//____________________________________________________________________________
215Int_t AliPHOSDigit::GetPrimary(Int_t index) const
216{
2f04ed65 217 // retrieves the primary particle number given its index in the list
36d93c12 218 Int_t rv = -1 ;
36641f9d 219 if ( index <= fNprimary && index > 0){
36d93c12 220 rv = fPrimary[index-1] ;
221 }
26d4b141 222
223 return rv ;
366c5d6f 224
26d4b141 225}
54ac223e 226
227//____________________________________________________________________________
228void AliPHOSDigit::SetALTROSamplesHG(Int_t nSamplesHG, Int_t *samplesHG)
229{
230 fNSamplesHG = nSamplesHG;
48b634ff 231 if (fSamplesHG) delete [] fSamplesHG;
54ac223e 232 fSamplesHG = new UShort_t[fNSamplesHG];
233 UShort_t i;
234 for (i=0; i<fNSamplesHG; i++) {
235 fSamplesHG[i] = samplesHG[i];
236 }
237}
238//____________________________________________________________________________
239void AliPHOSDigit::SetALTROSamplesLG(Int_t nSamplesLG, Int_t *samplesLG)
240{
241 fNSamplesLG = nSamplesLG;
48b634ff 242 if (fSamplesLG) delete [] fSamplesLG;
54ac223e 243 fSamplesLG = new UShort_t[fNSamplesLG];
244 UShort_t i;
245 for (i=0; i<fNSamplesLG; i++) {
246 fSamplesLG[i] = samplesLG[i];
247 }
248}
990119d6 249//____________________________________________________________________________
702ab87e 250void AliPHOSDigit::Print(const Option_t *) const
d8ca0b45 251{
e957fea8 252 // Print the digit together with list of primaries
46c3076b 253 TString line = Form("PHOS digit: E=%.3f, Id=%d, Time=%.3e, TimeR=%.3e, NPrim=%d, nHG=%d, nLG=%d \n",
254 fEnergy,fId,fTime,fTimeR,fNprimary,fNSamplesHG,fNSamplesLG);
255 line += "\tList of primaries: ";
54ac223e 256 for (Int_t index = 0; index <fNprimary; index ++ )
46c3076b 257 line += Form(" %d ",fPrimary[index]);
258 line += "\n";
259 line += "\tSamples HG: ";
54ac223e 260 for (Int_t i = 0; i <fNSamplesHG; i++)
46c3076b 261 line += Form(" %d ",fSamplesHG[i]);
262 line += "\n";
263 line += "\tSamples LG: ";
54ac223e 264 for (Int_t i = 0; i <fNSamplesLG; i++)
46c3076b 265 line += Form(" %d ",fSamplesLG[i]);
266 line += "\n";
267 AliDebug(2,line);
d8ca0b45 268}
269//____________________________________________________________________________
a4e98857 270void AliPHOSDigit::ShiftPrimary(Int_t shift)
271{
272 //shifts primary number to BIG offset, to separate primary in different TreeK
adc232ca 273 for(Int_t index = 0; index <fNprimary; index ++ ){
274 fPrimary[index]+= shift ;
990119d6 275 }
276}
cf239357 277//____________________________________________________________________________
278Bool_t AliPHOSDigit::operator==(AliPHOSDigit const & digit) const
279{
b2a60966 280 // Two digits are equal if they have the same Id
281
cf239357 282 if ( fId == digit.fId )
d15a28e7 283 return kTRUE ;
284 else
285 return kFALSE ;
286}
cf239357 287
d15a28e7 288//____________________________________________________________________________
3663622c 289AliPHOSDigit& AliPHOSDigit::operator+=(AliPHOSDigit const & digit)
d15a28e7 290{
adc232ca 291
b2a60966 292 // Adds the amplitude of digits and completes the list of primary particles
adc232ca 293 if(digit.fNprimary>0){
294 Int_t *tmp = new Int_t[fNprimary+digit.fNprimary] ;
27a73a5d 295 if(fAmp < digit.fAmp || fEnergy < digit.fEnergy){//most energetic primary in second digit => first primaries in list from second digit
adc232ca 296 for (Int_t index = 0 ; index < digit.fNprimary ; index++)
297 tmp[index]=(digit.fPrimary)[index] ;
298 for (Int_t index = 0 ; index < fNprimary ; index++)
299 tmp[index+digit.fNprimary]=fPrimary[index] ;
300 }
301 else{ //add new primaries to the end
302 for (Int_t index = 0 ; index < fNprimary ; index++)
303 tmp[index]=fPrimary[index] ;
304 for (Int_t index = 0 ; index < digit.fNprimary ; index++)
305 tmp[index+fNprimary]=(digit.fPrimary)[index] ;
306 }
307 if(fPrimary)
308 delete []fPrimary ;
309 fPrimary = tmp ;
310 }
311 fNprimary+=digit.fNprimary ;
27a73a5d 312 fAmp += digit.fAmp ;
313 fEnergy += digit.fEnergy ;
adc232ca 314 if(fTime > digit.fTime)
315 fTime = digit.fTime ;
04f0bda3 316 fTimeR = fTime ;
54ac223e 317
318 // Add high-gain ALTRO samples
319 UShort_t i;
320 if (digit.fNSamplesHG > fNSamplesHG) {
321 UShort_t newNSamplesHG = digit.fNSamplesHG;
322 UShort_t *newSamplesHG = new UShort_t[newNSamplesHG];
323 for (i=0; i<newNSamplesHG; i++) {
324 if (i<fNSamplesHG)
325 newSamplesHG[i] = TMath::Max(1023,fSamplesHG[i] + (digit.fSamplesHG)[i]);
326 else
327 newSamplesHG[i] = (digit.fSamplesHG)[i];
328 }
329 delete [] fSamplesHG;
330 fSamplesHG = new UShort_t[newNSamplesHG];
331 for (i=0; i<newNSamplesHG; i++) {
332 fSamplesHG[i] = newSamplesHG[i];
333 }
334 delete [] newSamplesHG;
335 }
336 else {
337 for (i=0; i<fNSamplesHG; i++)
338 fSamplesHG[i] = TMath::Max(1023,fSamplesHG[i] + (digit.fSamplesHG)[i]);
339 }
340
341 // Add low-gain ALTRO samples
342 if (digit.fNSamplesLG > fNSamplesLG) {
343 UShort_t newNSamplesLG = digit.fNSamplesLG;
344 UShort_t *newSamplesLG = new UShort_t[newNSamplesLG];
345 for (i=0; i<newNSamplesLG; i++) {
346 if (i<fNSamplesLG)
347 newSamplesLG[i] = TMath::Max(1023,fSamplesLG[i] + (digit.fSamplesLG)[i]);
348 else
349 newSamplesLG[i] = (digit.fSamplesLG)[i];
350 }
351 delete [] fSamplesLG;
352 fSamplesLG = new UShort_t[newNSamplesLG];
353 for (i=0; i<newNSamplesLG; i++) {
354 fSamplesLG[i] = newSamplesLG[i];
355 }
356 delete [] newSamplesLG;
357 }
358 else {
359 for (i=0; i<fNSamplesLG; i++)
360 fSamplesLG[i] = TMath::Max(1023,fSamplesLG[i] + (digit.fSamplesLG)[i]);
361 }
f1731579 362
363 //If at least one digit in LG, then sum also
364 fIsLG=fIsLG||digit.fIsLG ;
54ac223e 365
adc232ca 366 return *this ;
88cb7938 367}
88cb7938 368//____________________________________________________________________________
3663622c 369AliPHOSDigit& AliPHOSDigit::operator *= (Float_t factor)
88cb7938 370{
371 // Multiplies the amplitude by a factor
bb53c80c 372
88cb7938 373 Float_t tempo = static_cast<Float_t>(fAmp) ;
374 tempo *= factor ;
375 fAmp = static_cast<Int_t>(TMath::Ceil(tempo)) ;
d15a28e7 376 return *this ;
377}
378
379//____________________________________________________________________________
cf239357 380ostream& operator << ( ostream& out , const AliPHOSDigit & digit)
d15a28e7 381{
b2a60966 382 // Prints the data of the digit
383
21cd0c07 384// out << "ID " << digit.fId << " Energy = " << digit.fAmp << " Time = " << digit.fTime << endl ;
385// Int_t i ;
386// for(i=0;i<digit.fNprimary;i++)
387// out << "Primary " << i+1 << " = " << digit.fPrimary[i] << endl ;
388// out << "Position in list = " << digit.fIndexInList << endl ;
389 digit.Warning("operator <<", "Implement differently") ;
d15a28e7 390 return out ;
391}
392
cf239357 393