]> git.uio.no Git - u/mrichter/AliRoot.git/blame_incremental - PHOS/AliPHOSDigit.cxx
Add Event-Shape-Engineering code for Femtoscopy
[u/mrichter/AliRoot.git] / PHOS / AliPHOSDigit.cxx
... / ...
CommitLineData
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
16/* $Id$ */
17
18/* History of cvs commits:
19 *
20 * $Log$
21 * Revision 1.39 2006/04/22 15:04:24 hristov
22 * Effective C++ initialization of data members in the default constructor
23 *
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 *
27 * Revision 1.37 2005/05/28 14:19:04 schutz
28 * Compilation warnings fixed by T.P.
29 *
30 */
31
32//_________________________________________________________________________
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
37//
38//*-- Author: Laurent Aphecetche & Yves Schutz (SUBATECH) & Dmitri Peressounko (RRC KI & SUBATECH)
39
40
41// --- ROOT system ---
42
43#include "TMath.h"
44
45// --- Standard library ---
46
47// --- AliRoot header files ---
48
49#include "AliPHOSDigit.h"
50#include "AliLog.h"
51
52
53
54ClassImp(AliPHOSDigit)
55
56//____________________________________________________________________________
57AliPHOSDigit::AliPHOSDigit() :
58 AliDigitNew(),
59 fIsLG(0),
60 fNprimary(0),
61 fPrimary(0x0),
62 fEnergy(0.),
63 fTime(0.),
64 fTimeR(0.),
65 fNSamplesHG(0),
66 fNSamplesLG(0),
67 fSamplesHG(0),
68 fSamplesLG(0)
69{
70 // default ctor
71}
72
73//____________________________________________________________________________
74AliPHOSDigit::AliPHOSDigit(Int_t primary, Int_t id, Int_t digEnergy, Float_t time, Int_t index) :
75 fIsLG(0),
76 fNprimary(0),
77 fPrimary(0),
78 fEnergy(0.f),
79 fTime(0.f),
80 fTimeR(0.f),
81 fNSamplesHG(0),
82 fNSamplesLG(0),
83 fSamplesHG(0),
84 fSamplesLG(0)
85{
86 // ctor with all data
87
88 fAmp = digEnergy ;
89 fEnergy = 0 ;
90 fTime = time ;
91 fTimeR = fTime ;
92 fId = id ;
93 fIndexInList = index ;
94
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//____________________________________________________________________________
107AliPHOSDigit::AliPHOSDigit(Int_t primary, Int_t id, Float_t energy, Float_t time, Int_t index) :
108 fIsLG(0),
109 fNprimary(0),
110 fPrimary(0),
111 fEnergy(0.f),
112 fTime(0.f),
113 fTimeR(0.f),
114 fNSamplesHG(0),
115 fNSamplesLG(0),
116 fSamplesHG(0),
117 fSamplesLG(0)
118{
119 // ctor with all data
120
121 fAmp = 0 ;
122 fEnergy = energy ;
123 fTime = time ;
124 fTimeR = fTime ;
125 fId = id ;
126 fIndexInList = index ;
127 if( primary != -1){
128 fNprimary = 1 ;
129 fPrimary = new Int_t[fNprimary] ;
130 fPrimary[0] = primary ;
131 }
132 else{ //If the contribution of this primary smaller than fDigitThreshold (AliPHOSv1)
133 fNprimary = 0 ;
134 fPrimary = 0 ;
135 }
136}
137
138//____________________________________________________________________________
139AliPHOSDigit::AliPHOSDigit(const AliPHOSDigit & digit) :
140 AliDigitNew(digit),
141 fIsLG(digit.fIsLG),
142 fNprimary(digit.fNprimary),
143 fPrimary(0),
144 fEnergy(digit.fEnergy),
145 fTime(digit.fTime),
146 fTimeR(digit.fTimeR),
147 fNSamplesHG(0),
148 fNSamplesLG(0),
149 fSamplesHG(0),
150 fSamplesLG(0)
151{
152 // copy ctor
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 ;
160 fAmp = digit.fAmp ;
161 fId = digit.fId;
162 fIndexInList = digit.fIndexInList ;
163}
164
165//____________________________________________________________________________
166AliPHOSDigit & AliPHOSDigit::operator = (const AliPHOSDigit &)
167{
168 Fatal("operator =", "not implemented");
169 return *this;
170}
171//____________________________________________________________________________
172AliPHOSDigit::~AliPHOSDigit()
173{
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;
179}
180
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
191//____________________________________________________________________________
192Int_t AliPHOSDigit::Compare(const TObject * obj) const
193{
194 // Compares two digits with respect to its Id
195 // to sort according increasing Id
196
197 Int_t rv ;
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}
213
214//____________________________________________________________________________
215Int_t AliPHOSDigit::GetPrimary(Int_t index) const
216{
217 // retrieves the primary particle number given its index in the list
218 Int_t rv = -1 ;
219 if ( index <= fNprimary && index > 0){
220 rv = fPrimary[index-1] ;
221 }
222
223 return rv ;
224
225}
226
227//____________________________________________________________________________
228void AliPHOSDigit::SetALTROSamplesHG(Int_t nSamplesHG, Int_t *samplesHG)
229{
230 fNSamplesHG = nSamplesHG;
231 if (fSamplesHG) delete [] fSamplesHG;
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;
242 if (fSamplesLG) delete [] fSamplesLG;
243 fSamplesLG = new UShort_t[fNSamplesLG];
244 UShort_t i;
245 for (i=0; i<fNSamplesLG; i++) {
246 fSamplesLG[i] = samplesLG[i];
247 }
248}
249//____________________________________________________________________________
250void AliPHOSDigit::Print(const Option_t *) const
251{
252 // Print the digit together with list of primaries
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: ";
256 for (Int_t index = 0; index <fNprimary; index ++ )
257 line += Form(" %d ",fPrimary[index]);
258 line += "\n";
259 line += "\tSamples HG: ";
260 for (Int_t i = 0; i <fNSamplesHG; i++)
261 line += Form(" %d ",fSamplesHG[i]);
262 line += "\n";
263 line += "\tSamples LG: ";
264 for (Int_t i = 0; i <fNSamplesLG; i++)
265 line += Form(" %d ",fSamplesLG[i]);
266 line += "\n";
267 AliDebug(2,line);
268}
269//____________________________________________________________________________
270void AliPHOSDigit::ShiftPrimary(Int_t shift)
271{
272 //shifts primary number to BIG offset, to separate primary in different TreeK
273 for(Int_t index = 0; index <fNprimary; index ++ ){
274 fPrimary[index]+= shift ;
275 }
276}
277//____________________________________________________________________________
278Bool_t AliPHOSDigit::operator==(AliPHOSDigit const & digit) const
279{
280 // Two digits are equal if they have the same Id
281
282 if ( fId == digit.fId )
283 return kTRUE ;
284 else
285 return kFALSE ;
286}
287
288//____________________________________________________________________________
289AliPHOSDigit& AliPHOSDigit::operator+=(AliPHOSDigit const & digit)
290{
291
292 // Adds the amplitude of digits and completes the list of primary particles
293 if(digit.fNprimary>0){
294 Int_t *tmp = new Int_t[fNprimary+digit.fNprimary] ;
295 if(fAmp < digit.fAmp || fEnergy < digit.fEnergy){//most energetic primary in second digit => first primaries in list from second digit
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 ;
312 fAmp += digit.fAmp ;
313 fEnergy += digit.fEnergy ;
314 if(fTime > digit.fTime)
315 fTime = digit.fTime ;
316 fTimeR = fTime ;
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 }
362
363 //If at least one digit in LG, then sum also
364 fIsLG=fIsLG||digit.fIsLG ;
365
366 return *this ;
367}
368//____________________________________________________________________________
369AliPHOSDigit& AliPHOSDigit::operator *= (Float_t factor)
370{
371 // Multiplies the amplitude by a factor
372
373 Float_t tempo = static_cast<Float_t>(fAmp) ;
374 tempo *= factor ;
375 fAmp = static_cast<Int_t>(TMath::Ceil(tempo)) ;
376 return *this ;
377}
378
379//____________________________________________________________________________
380ostream& operator << ( ostream& out , const AliPHOSDigit & digit)
381{
382 // Prints the data of the digit
383
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") ;
390 return out ;
391}
392
393