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