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