]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PHOS/AliPHOSDigit.cxx
Number of ALTRO samples is reduced to 100
[u/mrichter/AliRoot.git] / PHOS / AliPHOSDigit.cxx
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
51
52
53
54 ClassImp(AliPHOSDigit)
55
56 //____________________________________________________________________________
57 AliPHOSDigit::AliPHOSDigit() :
58   AliDigitNew(),
59   fNprimary(0),  
60   fPrimary(0x0),
61   fEnergy(0.),
62   fTime(0.),
63   fTimeR(0.) 
64   
65 {
66   // default ctor 
67 }
68
69 //____________________________________________________________________________
70 AliPHOSDigit::AliPHOSDigit(Int_t primary, Int_t id, Int_t digEnergy, Float_t time, Int_t index) :
71   fNprimary(0),
72   fPrimary(0),
73   fEnergy(0.f),
74   fTime(0.f),
75   fTimeR(0.f)
76 {  
77   // ctor with all data 
78
79   fAmp         = digEnergy ;
80   fEnergy      = 0 ;
81   fTime        = time ;
82   fTimeR       = fTime ;
83   fId          = id ;
84   fIndexInList = index ; 
85   if( primary != -1){
86     fNprimary    = 1 ; 
87     fPrimary = new Int_t[fNprimary] ;
88     fPrimary[0]  = primary ;
89   }
90   else{  //If the contribution of this primary smaller than fDigitThreshold (AliPHOSv1)
91     fNprimary = 0 ; 
92     fPrimary  = 0 ;
93   }
94 }
95
96 //____________________________________________________________________________
97 AliPHOSDigit::AliPHOSDigit(Int_t primary, Int_t id, Float_t energy, Float_t time, Int_t index) :
98   fNprimary(0),
99   fPrimary(0),
100   fEnergy(0.f),
101   fTime(0.f),
102   fTimeR(0.f)
103 {  
104   // ctor with all data 
105
106   fAmp         = 0 ;
107   fEnergy      = energy ;
108   fTime        = time ;
109   fTimeR       = fTime ;
110   fId          = id ;
111   fIndexInList = index ; 
112   if( primary != -1){
113     fNprimary    = 1 ; 
114     fPrimary = new Int_t[fNprimary] ;
115     fPrimary[0]  = primary ;
116   }
117   else{  //If the contribution of this primary smaller than fDigitThreshold (AliPHOSv1)
118     fNprimary = 0 ; 
119     fPrimary  = 0 ;
120   }
121 }
122
123 //____________________________________________________________________________
124 AliPHOSDigit::AliPHOSDigit(const AliPHOSDigit & digit) : 
125   AliDigitNew(digit),
126   fNprimary(digit.fNprimary),
127   fPrimary(0),
128   fEnergy(digit.fEnergy),
129   fTime(digit.fTime),
130   fTimeR(digit.fTimeR)
131
132 {
133   // copy ctor
134   if(fNprimary){
135     fPrimary = new Int_t[fNprimary] ;
136     for (Int_t i = 0; i < fNprimary ; i++)
137        fPrimary[i]  = digit.fPrimary[i] ;
138   }
139   else
140     fPrimary = 0 ;
141   fAmp         = digit.fAmp ;
142   fId          = digit.fId;
143   fIndexInList = digit.fIndexInList ; 
144 }
145
146 //____________________________________________________________________________
147 AliPHOSDigit::~AliPHOSDigit() 
148 {
149   // Delete array of primiries if any
150   if(fPrimary)
151     delete [] fPrimary ;
152 }
153
154 //____________________________________________________________________________
155 Int_t AliPHOSDigit::Compare(const TObject * obj) const
156 {
157   // Compares two digits with respect to its Id
158   // to sort according increasing Id
159
160   Int_t rv ;
161
162   AliPHOSDigit * digit = (AliPHOSDigit *)obj ; 
163
164   Int_t iddiff = fId - digit->GetId() ; 
165
166   if ( iddiff > 0 ) 
167     rv = 1 ;
168   else if ( iddiff < 0 )
169     rv = -1 ; 
170   else
171     rv = 0 ;
172   
173   return rv ; 
174
175 }
176
177 //____________________________________________________________________________
178 Int_t AliPHOSDigit::GetPrimary(Int_t index) const
179 {
180   // retrieves the primary particle number given its index in the list 
181   Int_t rv = -1 ;
182   if ( index <= fNprimary && index > 0){
183     rv = fPrimary[index-1] ;
184   } 
185
186   return rv ; 
187   
188 }
189 //____________________________________________________________________________
190 void AliPHOSDigit::Print(const Option_t *) const
191 {
192   // Print the digit together with list of primaries
193   printf("PHOS digit: Amp=%d/E=%.3f, Id=%d, Time=%.3e, TimeR=%.3e, NPrim=%d ",fAmp,fEnergy,fId,fTime,fTimeR,fNprimary);
194   for(Int_t index = 0; index <fNprimary; index ++ )
195     printf(" %d ",fPrimary[index]); 
196   printf("\n") ;
197 }
198 //____________________________________________________________________________
199 void AliPHOSDigit::ShiftPrimary(Int_t shift)
200 {
201   //shifts primary number to BIG offset, to separate primary in different TreeK
202   for(Int_t index = 0; index <fNprimary; index ++ ){
203     fPrimary[index]+= shift ;
204   } 
205 }
206 //____________________________________________________________________________
207 Bool_t AliPHOSDigit::operator==(AliPHOSDigit const & digit) const 
208 {
209   // Two digits are equal if they have the same Id
210   
211   if ( fId == digit.fId ) 
212     return kTRUE ;
213   else 
214     return kFALSE ;
215 }
216  
217 //____________________________________________________________________________
218 AliPHOSDigit& AliPHOSDigit::operator+=(AliPHOSDigit const & digit) 
219 {
220
221   // Adds the amplitude of digits and completes the list of primary particles
222   if(digit.fNprimary>0){
223      Int_t *tmp = new Int_t[fNprimary+digit.fNprimary] ;
224      if(fAmp < digit.fAmp || fEnergy < digit.fEnergy){//most energetic primary in second digit => first primaries in list from second digit
225         for (Int_t index = 0 ; index < digit.fNprimary ; index++)
226            tmp[index]=(digit.fPrimary)[index] ;
227         for (Int_t index = 0 ; index < fNprimary ; index++)
228            tmp[index+digit.fNprimary]=fPrimary[index] ;
229      }
230      else{ //add new primaries to the end
231         for (Int_t index = 0 ; index < fNprimary ; index++)
232            tmp[index]=fPrimary[index] ;
233         for (Int_t index = 0 ; index < digit.fNprimary ; index++)
234            tmp[index+fNprimary]=(digit.fPrimary)[index] ;
235      }
236      if(fPrimary)
237        delete []fPrimary ;
238      fPrimary = tmp ;
239    }
240    fNprimary+=digit.fNprimary ;
241    fAmp     += digit.fAmp ;
242    fEnergy  += digit.fEnergy ;
243    if(fTime > digit.fTime)
244       fTime = digit.fTime ;
245    fTimeR = fTime ; 
246    return *this ;
247 }
248 //____________________________________________________________________________
249 AliPHOSDigit& AliPHOSDigit::operator *= (Float_t factor) 
250 {
251   // Multiplies the amplitude by a factor
252   
253   Float_t tempo = static_cast<Float_t>(fAmp) ; 
254   tempo *= factor ; 
255   fAmp = static_cast<Int_t>(TMath::Ceil(tempo)) ; 
256   return *this ;
257 }
258
259 //____________________________________________________________________________
260 ostream& operator << ( ostream& out , const AliPHOSDigit & digit)
261 {
262   // Prints the data of the digit
263   
264 //   out << "ID " << digit.fId << " Energy = " << digit.fAmp << " Time = " << digit.fTime << endl ; 
265 //   Int_t i ;
266 //   for(i=0;i<digit.fNprimary;i++)
267 //     out << "Primary " << i+1 << " = " << digit.fPrimary[i] << endl ;
268 //   out << "Position in list = " << digit.fIndexInList << endl ; 
269   digit.Warning("operator <<", "Implement differently") ; 
270   return out ;
271 }
272
273