]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PHOS/AliPHOSDigit.cxx
Added const where it made sense
[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 // --- Standard library ---
30
31 #include <iostream.h>
32
33 // --- AliRoot header files ---
34
35 #include "AliPHOSDigit.h"
36
37
38 ClassImp(AliPHOSDigit)
39
40 //____________________________________________________________________________
41   AliPHOSDigit::AliPHOSDigit() 
42 {
43   // default ctor 
44
45   fIndexInList = -1 ; 
46   fNprimary    = 0 ;  
47   fNMaxPrimary = 5 ; 
48   fShiftOffset = 10000000 ;
49 }
50
51 //____________________________________________________________________________
52 AliPHOSDigit::AliPHOSDigit(Int_t primary, Int_t id, Int_t digEnergy, Float_t time, Int_t index) 
53 {  
54   // ctor with all data 
55
56   fNMaxPrimary = 5 ; 
57   fAmp         = digEnergy ;
58   fTime        = time ;
59   fId          = id ;
60   fIndexInList = index ; 
61   fShiftOffset = 10000000 ;
62   if( primary != -1){
63     fNprimary    = 1 ; 
64     fPrimary[0]  = primary ;
65   }
66   else{  //If the contribution of this primary smaller than fDigitThreshold (AliPHOSv1)
67     fNprimary    = 0 ; 
68     fPrimary[0]  = -1 ;
69   }
70   Int_t i ;
71   for ( i = 1; i < fNMaxPrimary ; i++)
72     fPrimary[i]  = -1 ; 
73 }
74
75 //____________________________________________________________________________
76 AliPHOSDigit::AliPHOSDigit(const AliPHOSDigit & digit) 
77 {
78   // copy ctor
79   
80
81   fNMaxPrimary = digit.fNMaxPrimary ;  
82   Int_t i ;
83   fShiftOffset = 10000000 ;
84   for ( i = 0; i < fNMaxPrimary ; i++)
85     fPrimary[i]  = digit.fPrimary[i] ;
86   fAmp         = digit.fAmp ;
87   fTime        = digit.fTime ;
88   fId          = digit.fId;
89   fIndexInList = digit.fIndexInList ; 
90   fNprimary    = digit.fNprimary ;
91 }
92
93 //____________________________________________________________________________
94 AliPHOSDigit::~AliPHOSDigit() 
95 {
96   // Delete array of primiries if any
97   
98 }
99
100 //____________________________________________________________________________
101 Int_t AliPHOSDigit::Compare(const TObject * obj) const
102 {
103   // Compares two digits with respect to its Id
104   // to sort according increasing Id
105
106   Int_t rv ;
107
108   AliPHOSDigit * digit = (AliPHOSDigit *)obj ; 
109
110   Int_t iddiff = fId - digit->GetId() ; 
111
112   if ( iddiff > 0 ) 
113     rv = 1 ;
114   else if ( iddiff < 0 )
115     rv = -1 ; 
116   else
117     rv = 0 ;
118   
119   return rv ; 
120
121 }
122
123 //____________________________________________________________________________
124 Int_t AliPHOSDigit::GetPrimary(Int_t index) const
125 {
126   // retrieves the primary particle number given its index in the list 
127   Int_t rv = -1 ;
128   if ( index <= fNprimary && index > 0){
129     rv = fPrimary[index-1] ;
130   } 
131
132   return rv ; 
133   
134 }
135 //____________________________________________________________________________
136 void AliPHOSDigit::Print(Option_t *option) const
137 {
138   printf("PHOS digit: Amp=%d, Id=%d\n",fAmp,fId);
139 }
140 //____________________________________________________________________________
141 void AliPHOSDigit::ShiftPrimary(Int_t shift)
142 {
143   //shifts primary number to BIG offset, to separate primary in different TreeK
144   Int_t index  ;
145   for(index = 0; index <fNprimary; index ++ ){
146     fPrimary[index] = fPrimary[index]+ shift * fShiftOffset ;
147   } 
148 }
149 //____________________________________________________________________________
150 Bool_t AliPHOSDigit::operator==(AliPHOSDigit const & digit) const 
151 {
152   // Two digits are equal if they have the same Id
153   
154   if ( fId == digit.fId ) 
155     return kTRUE ;
156   else 
157     return kFALSE ;
158 }
159  
160 //____________________________________________________________________________
161 AliPHOSDigit& AliPHOSDigit::operator+(AliPHOSDigit const & digit) 
162 {
163   // Adds the amplitude of digits and completes the list of primary particles
164   // if amplitude is larger than 
165   
166   fAmp += digit.fAmp ;
167   if(fTime > digit.fTime)
168     fTime = digit.fTime ;
169   
170   Int_t max1 = fNprimary ; 
171   
172   Int_t index ; 
173   for (index = 0 ; index < digit.fNprimary ; index++){
174     Bool_t deja = kTRUE ;
175     Int_t old ;
176     for ( old = 0 ; (old < max1) && deja; old++) { //already have this primary?
177       if(fPrimary[old] == (digit.fPrimary)[index])
178         deja = kFALSE;
179     }
180     if(deja){
181       fPrimary[fNprimary] = (digit.fPrimary)[index] ; 
182       fNprimary++ ;
183       if(fNprimary>fNMaxPrimary) {
184         cout << "AliPHOSDigit >> Increase NMaxPrimary "<< endl ;
185         return *this ;
186       }
187     }
188   }
189   
190   return *this ;
191 }
192
193 //____________________________________________________________________________
194 ostream& operator << ( ostream& out , const AliPHOSDigit & digit)
195 {
196   // Prints the data of the digit
197   
198   out << "ID " << digit.fId << " Energy = " << digit.fAmp << " Time = " << digit.fTime << endl ; 
199   Int_t i ;
200   for(i=0;i<digit.fNprimary;i++)
201     out << "Primary " << i+1 << " = " << digit.fPrimary[i] << endl ;
202   out << "Position in list = " << digit.fIndexInList << endl ; 
203   return out ;
204 }
205
206