]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PHOS/AliPHOSDigit.cxx
Added debug methods
[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() const
136 {
137   // Print the digit together with list of primaries
138   printf("PHOS digit: Amp=%d, Id=%d, Time=%f, NPrim=%d ",fAmp,fId,fTime,fNprimary);
139   for(Int_t index = 0; index <fNprimary; index ++ )
140     printf(" %d ",fPrimary[index]); 
141   printf("\n") ;
142 }
143 //____________________________________________________________________________
144 void AliPHOSDigit::ShiftPrimary(Int_t shift)
145 {
146   //shifts primary number to BIG offset, to separate primary in different TreeK
147   for(Int_t index = 0; index <fNprimary; index ++ ){
148     fPrimary[index]+= shift ;
149   } 
150 }
151 //____________________________________________________________________________
152 Bool_t AliPHOSDigit::operator==(AliPHOSDigit const & digit) const 
153 {
154   // Two digits are equal if they have the same Id
155   
156   if ( fId == digit.fId ) 
157     return kTRUE ;
158   else 
159     return kFALSE ;
160 }
161  
162 //____________________________________________________________________________
163 AliPHOSDigit& AliPHOSDigit::operator+(AliPHOSDigit const & digit) 
164 {
165
166   // Adds the amplitude of digits and completes the list of primary particles
167   if(digit.fNprimary>0){
168      Int_t *tmp = new Int_t[fNprimary+digit.fNprimary] ;
169      if(fAmp < digit.fAmp){//most energetic primary in second digit => first primaries in list from second digit
170         for (Int_t index = 0 ; index < digit.fNprimary ; index++)
171            tmp[index]=(digit.fPrimary)[index] ;
172         for (Int_t index = 0 ; index < fNprimary ; index++)
173            tmp[index+digit.fNprimary]=fPrimary[index] ;
174      }
175      else{ //add new primaries to the end
176         for (Int_t index = 0 ; index < fNprimary ; index++)
177            tmp[index]=fPrimary[index] ;
178         for (Int_t index = 0 ; index < digit.fNprimary ; index++)
179            tmp[index+fNprimary]=(digit.fPrimary)[index] ;
180      }
181      if(fPrimary)
182        delete []fPrimary ;
183      fPrimary = tmp ;
184    }
185    fNprimary+=digit.fNprimary ;
186    fAmp += digit.fAmp ;
187    if(fTime > digit.fTime)
188       fTime = digit.fTime ;
189    return *this ;
190 }
191 //____________________________________________________________________________
192 AliPHOSDigit& AliPHOSDigit::operator*(Float_t factor) 
193 {
194   // Multiplies the amplitude by a factor
195   
196   Float_t tempo = static_cast<Float_t>(fAmp) ; 
197   tempo *= factor ; 
198   fAmp = static_cast<Int_t>(TMath::Ceil(tempo)) ; 
199   return *this ;
200 }
201
202 //____________________________________________________________________________
203 ostream& operator << ( ostream& out , const AliPHOSDigit & digit)
204 {
205   // Prints the data of the digit
206   
207 //   out << "ID " << digit.fId << " Energy = " << digit.fAmp << " Time = " << digit.fTime << endl ; 
208 //   Int_t i ;
209 //   for(i=0;i<digit.fNprimary;i++)
210 //     out << "Primary " << i+1 << " = " << digit.fPrimary[i] << endl ;
211 //   out << "Position in list = " << digit.fIndexInList << endl ; 
212   digit.Warning("operator <<", "Implement differently") ; 
213   return out ;
214 }
215
216