]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PHOS/AliPHOSDigit.cxx
Adding PHOS ALTRO mapping. To be used inside AliPHOSRawStream in order to map the...
[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.38  2006/04/22 10:30:17  hristov
22  * Add fEnergy to AliPHOSDigit and operate with EMC amplitude in energy units (Yu.Kharlov)
23  *
24  * Revision 1.37  2005/05/28 14:19:04  schutz
25  * Compilation warnings fixed by T.P.
26  *
27  */
28
29 //_________________________________________________________________________
30 //  PHOS digit: Id
31 //              energy
32 //              3 identifiers for the primary particle(s) at the origine of the digit
33 //  The digits are made in FinishEvent() by summing all the hits in a single PHOS crystal or PPSD gas cell
34 //
35 //*-- Author: Laurent Aphecetche & Yves Schutz (SUBATECH) & Dmitri Peressounko (RRC KI & SUBATECH)
36
37
38 // --- ROOT system ---
39
40 #include "TMath.h"
41
42 // --- Standard library ---
43
44 // --- AliRoot header files ---
45
46 #include "AliPHOSDigit.h"
47
48
49
50
51 ClassImp(AliPHOSDigit)
52
53 //____________________________________________________________________________
54 AliPHOSDigit::AliPHOSDigit() :
55   AliDigitNew(),
56   fNprimary(0),  
57   fPrimary(0x0),
58   fEnergy(0.),
59   fTime(0.),
60   fTimeR(0.) 
61   
62 {
63   // default ctor 
64 }
65
66 //____________________________________________________________________________
67 AliPHOSDigit::AliPHOSDigit(Int_t primary, Int_t id, Int_t digEnergy, Float_t time, Int_t index) 
68 {  
69   // ctor with all data 
70
71   fAmp         = digEnergy ;
72   fEnergy      = 0 ;
73   fTime        = time ;
74   fTimeR       = fTime ;
75   fId          = id ;
76   fIndexInList = index ; 
77   if( primary != -1){
78     fNprimary    = 1 ; 
79     fPrimary = new Int_t[fNprimary] ;
80     fPrimary[0]  = primary ;
81   }
82   else{  //If the contribution of this primary smaller than fDigitThreshold (AliPHOSv1)
83     fNprimary = 0 ; 
84     fPrimary  = 0 ;
85   }
86 }
87
88 //____________________________________________________________________________
89 AliPHOSDigit::AliPHOSDigit(Int_t primary, Int_t id, Float_t energy, Float_t time, Int_t index) 
90 {  
91   // ctor with all data 
92
93   fAmp         = 0 ;
94   fEnergy      = energy ;
95   fTime        = time ;
96   fTimeR       = fTime ;
97   fId          = id ;
98   fIndexInList = index ; 
99   if( primary != -1){
100     fNprimary    = 1 ; 
101     fPrimary = new Int_t[fNprimary] ;
102     fPrimary[0]  = primary ;
103   }
104   else{  //If the contribution of this primary smaller than fDigitThreshold (AliPHOSv1)
105     fNprimary = 0 ; 
106     fPrimary  = 0 ;
107   }
108 }
109
110 //____________________________________________________________________________
111 AliPHOSDigit::AliPHOSDigit(const AliPHOSDigit & digit) : AliDigitNew(digit)
112 {
113   // copy ctor
114
115   fNprimary = digit.fNprimary ;  
116   if(fNprimary){
117     fPrimary = new Int_t[fNprimary] ;
118     for (Int_t i = 0; i < fNprimary ; i++)
119        fPrimary[i]  = digit.fPrimary[i] ;
120   }
121   else
122     fPrimary = 0 ;
123   fAmp         = digit.fAmp ;
124   fEnergy      = digit.fEnergy ;
125   fTime        = digit.fTime ;
126   fTimeR       = digit.fTimeR ;
127   fId          = digit.fId;
128   fIndexInList = digit.fIndexInList ; 
129 }
130
131 //____________________________________________________________________________
132 AliPHOSDigit::~AliPHOSDigit() 
133 {
134   // Delete array of primiries if any
135   if(fPrimary)
136     delete [] fPrimary ;
137 }
138
139 //____________________________________________________________________________
140 Int_t AliPHOSDigit::Compare(const TObject * obj) const
141 {
142   // Compares two digits with respect to its Id
143   // to sort according increasing Id
144
145   Int_t rv ;
146
147   AliPHOSDigit * digit = (AliPHOSDigit *)obj ; 
148
149   Int_t iddiff = fId - digit->GetId() ; 
150
151   if ( iddiff > 0 ) 
152     rv = 1 ;
153   else if ( iddiff < 0 )
154     rv = -1 ; 
155   else
156     rv = 0 ;
157   
158   return rv ; 
159
160 }
161
162 //____________________________________________________________________________
163 Int_t AliPHOSDigit::GetPrimary(Int_t index) const
164 {
165   // retrieves the primary particle number given its index in the list 
166   Int_t rv = -1 ;
167   if ( index <= fNprimary && index > 0){
168     rv = fPrimary[index-1] ;
169   } 
170
171   return rv ; 
172   
173 }
174 //____________________________________________________________________________
175 void AliPHOSDigit::Print(const Option_t *) const
176 {
177   // Print the digit together with list of primaries
178   printf("PHOS digit: Amp=%d/E=%.3f, Id=%d, Time=%.3e, TimeR=%.3e, NPrim=%d ",fAmp,fEnergy,fId,fTime,fTimeR,fNprimary);
179   for(Int_t index = 0; index <fNprimary; index ++ )
180     printf(" %d ",fPrimary[index]); 
181   printf("\n") ;
182 }
183 //____________________________________________________________________________
184 void AliPHOSDigit::ShiftPrimary(Int_t shift)
185 {
186   //shifts primary number to BIG offset, to separate primary in different TreeK
187   for(Int_t index = 0; index <fNprimary; index ++ ){
188     fPrimary[index]+= shift ;
189   } 
190 }
191 //____________________________________________________________________________
192 Bool_t AliPHOSDigit::operator==(AliPHOSDigit const & digit) const 
193 {
194   // Two digits are equal if they have the same Id
195   
196   if ( fId == digit.fId ) 
197     return kTRUE ;
198   else 
199     return kFALSE ;
200 }
201  
202 //____________________________________________________________________________
203 AliPHOSDigit& AliPHOSDigit::operator+(AliPHOSDigit const & digit) 
204 {
205
206   // Adds the amplitude of digits and completes the list of primary particles
207   if(digit.fNprimary>0){
208      Int_t *tmp = new Int_t[fNprimary+digit.fNprimary] ;
209      if(fAmp < digit.fAmp || fEnergy < digit.fEnergy){//most energetic primary in second digit => first primaries in list from second digit
210         for (Int_t index = 0 ; index < digit.fNprimary ; index++)
211            tmp[index]=(digit.fPrimary)[index] ;
212         for (Int_t index = 0 ; index < fNprimary ; index++)
213            tmp[index+digit.fNprimary]=fPrimary[index] ;
214      }
215      else{ //add new primaries to the end
216         for (Int_t index = 0 ; index < fNprimary ; index++)
217            tmp[index]=fPrimary[index] ;
218         for (Int_t index = 0 ; index < digit.fNprimary ; index++)
219            tmp[index+fNprimary]=(digit.fPrimary)[index] ;
220      }
221      if(fPrimary)
222        delete []fPrimary ;
223      fPrimary = tmp ;
224    }
225    fNprimary+=digit.fNprimary ;
226    fAmp     += digit.fAmp ;
227    fEnergy  += digit.fEnergy ;
228    if(fTime > digit.fTime)
229       fTime = digit.fTime ;
230    fTimeR = fTime ; 
231    return *this ;
232 }
233 //____________________________________________________________________________
234 AliPHOSDigit& AliPHOSDigit::operator*(Float_t factor) 
235 {
236   // Multiplies the amplitude by a factor
237   
238   Float_t tempo = static_cast<Float_t>(fAmp) ; 
239   tempo *= factor ; 
240   fAmp = static_cast<Int_t>(TMath::Ceil(tempo)) ; 
241   return *this ;
242 }
243
244 //____________________________________________________________________________
245 ostream& operator << ( ostream& out , const AliPHOSDigit & digit)
246 {
247   // Prints the data of the digit
248   
249 //   out << "ID " << digit.fId << " Energy = " << digit.fAmp << " Time = " << digit.fTime << endl ; 
250 //   Int_t i ;
251 //   for(i=0;i<digit.fNprimary;i++)
252 //     out << "Primary " << i+1 << " = " << digit.fPrimary[i] << endl ;
253 //   out << "Position in list = " << digit.fIndexInList << endl ; 
254   digit.Warning("operator <<", "Implement differently") ; 
255   return out ;
256 }
257
258