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