Transition to NewIO
[u/mrichter/AliRoot.git] / PHOS / AliPHOSDigit.cxx
CommitLineData
d15a28e7 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
b2a60966 16/* $Id$ */
17
d15a28e7 18//_________________________________________________________________________
b2a60966 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
b2a60966 23//
9688c1dd 24//*-- Author: Laurent Aphecetche & Yves Schutz (SUBATECH) & Dmitri Peressounko (RRC KI & SUBATECH)
b2a60966 25
d15a28e7 26
27// --- ROOT system ---
28
88cb7938 29#include "TMath.h"
30
d15a28e7 31// --- Standard library ---
32
d15a28e7 33// --- AliRoot header files ---
34
35#include "AliPHOSDigit.h"
36
37
88cb7938 38
39
d15a28e7 40ClassImp(AliPHOSDigit)
41
42//____________________________________________________________________________
f741ce93 43 AliPHOSDigit::AliPHOSDigit()
cf239357 44{
b2a60966 45 // default ctor
46
83974468 47 fIndexInList = -1 ;
48 fNprimary = 0 ;
88cb7938 49 fNMaxPrimary = 5 ;
50 fPrimary = 0;
cf239357 51}
52
53//____________________________________________________________________________
9688c1dd 54AliPHOSDigit::AliPHOSDigit(Int_t primary, Int_t id, Int_t digEnergy, Float_t time, Int_t index)
d15a28e7 55{
b2a60966 56 // ctor with all data
57
2e5c3041 58 fNMaxPrimary = 5 ;
7b7c1533 59 fAmp = digEnergy ;
9688c1dd 60 fTime = time ;
83974468 61 fId = id ;
62 fIndexInList = index ;
88cb7938 63 fPrimary = new Int_t[fNMaxPrimary] ;
4a2ca5e9 64 if( primary != -1){
65 fNprimary = 1 ;
366c5d6f 66 fPrimary[0] = primary ;
4a2ca5e9 67 }
68 else{ //If the contribution of this primary smaller than fDigitThreshold (AliPHOSv1)
69 fNprimary = 0 ;
366c5d6f 70 fPrimary[0] = -1 ;
4a2ca5e9 71 }
366c5d6f 72 Int_t i ;
73 for ( i = 1; i < fNMaxPrimary ; i++)
74 fPrimary[i] = -1 ;
cf239357 75}
76
77//____________________________________________________________________________
78AliPHOSDigit::AliPHOSDigit(const AliPHOSDigit & digit)
b2a60966 79{
80 // copy ctor
81
36d93c12 82
83 fNMaxPrimary = digit.fNMaxPrimary ;
88cb7938 84 fPrimary = new Int_t[fNMaxPrimary] ;
36d93c12 85 Int_t i ;
86 for ( i = 0; i < fNMaxPrimary ; i++)
87 fPrimary[i] = digit.fPrimary[i] ;
83974468 88 fAmp = digit.fAmp ;
9688c1dd 89 fTime = digit.fTime ;
83974468 90 fId = digit.fId;
91 fIndexInList = digit.fIndexInList ;
92 fNprimary = digit.fNprimary ;
ff4c968a 93}
94
95//____________________________________________________________________________
36d93c12 96AliPHOSDigit::~AliPHOSDigit()
2e5c3041 97{
98 // Delete array of primiries if any
88cb7938 99 delete [] fPrimary ;
2e5c3041 100}
101
102//____________________________________________________________________________
037cc66d 103Int_t AliPHOSDigit::Compare(const TObject * obj) const
d15a28e7 104{
b2a60966 105 // Compares two digits with respect to its Id
106 // to sort according increasing Id
107
88714635 108 Int_t rv ;
cf239357 109
110 AliPHOSDigit * digit = (AliPHOSDigit *)obj ;
111
112 Int_t iddiff = fId - digit->GetId() ;
113
114 if ( iddiff > 0 )
115 rv = 1 ;
116 else if ( iddiff < 0 )
117 rv = -1 ;
118 else
119 rv = 0 ;
120
121 return rv ;
122
123}
26d4b141 124
125//____________________________________________________________________________
126Int_t AliPHOSDigit::GetPrimary(Int_t index) const
127{
2f04ed65 128 // retrieves the primary particle number given its index in the list
36d93c12 129 Int_t rv = -1 ;
36641f9d 130 if ( index <= fNprimary && index > 0){
36d93c12 131 rv = fPrimary[index-1] ;
132 }
26d4b141 133
134 return rv ;
366c5d6f 135
26d4b141 136}
990119d6 137//____________________________________________________________________________
d8ca0b45 138void AliPHOSDigit::Print(Option_t *option) const
139{
140 printf("PHOS digit: Amp=%d, Id=%d\n",fAmp,fId);
141}
142//____________________________________________________________________________
a4e98857 143void AliPHOSDigit::ShiftPrimary(Int_t shift)
144{
145 //shifts primary number to BIG offset, to separate primary in different TreeK
990119d6 146 Int_t index ;
147 for(index = 0; index <fNprimary; index ++ ){
21c293b7 148 fPrimary[index] = fPrimary[index]+ shift ;
990119d6 149 }
150}
cf239357 151//____________________________________________________________________________
152Bool_t AliPHOSDigit::operator==(AliPHOSDigit const & digit) const
153{
b2a60966 154 // Two digits are equal if they have the same Id
155
cf239357 156 if ( fId == digit.fId )
d15a28e7 157 return kTRUE ;
158 else
159 return kFALSE ;
160}
cf239357 161
d15a28e7 162//____________________________________________________________________________
cf239357 163AliPHOSDigit& AliPHOSDigit::operator+(AliPHOSDigit const & digit)
d15a28e7 164{
b2a60966 165 // Adds the amplitude of digits and completes the list of primary particles
4a2ca5e9 166 // if amplitude is larger than
36d93c12 167
88cb7938 168 fAmp += digit.fAmp ;
169 if(fTime > digit.fTime)
170 fTime = digit.fTime ;
171
172 Int_t max1 = fNprimary ;
173
174 Int_t index ;
175 for (index = 0 ; index < digit.fNprimary ; index++){
176 Bool_t deja = kTRUE ;
177 Int_t old ;
178 for ( old = 0 ; (old < max1) && deja; old++) { //already have this primary?
179 if(fPrimary[old] == (digit.fPrimary)[index])
180 deja = kFALSE;
550bee17 181 }
88cb7938 182 if(deja){
183 fPrimary[fNprimary] = (digit.fPrimary)[index] ;
184 fNprimary++ ;
185 if(fNprimary>fNMaxPrimary) {
186 Error("Operator +", "Increase NMaxPrimary") ;
187 return *this ;
bb53c80c 188 }
bb53c80c 189 }
f741ce93 190 }
550bee17 191
88cb7938 192 return *this ;
193}
194
195//____________________________________________________________________________
196AliPHOSDigit& AliPHOSDigit::operator*(Float_t factor)
197{
198 // Multiplies the amplitude by a factor
bb53c80c 199
88cb7938 200 Float_t tempo = static_cast<Float_t>(fAmp) ;
201 tempo *= factor ;
202 fAmp = static_cast<Int_t>(TMath::Ceil(tempo)) ;
d15a28e7 203 return *this ;
204}
205
206//____________________________________________________________________________
cf239357 207ostream& operator << ( ostream& out , const AliPHOSDigit & digit)
d15a28e7 208{
b2a60966 209 // Prints the data of the digit
210
21cd0c07 211// out << "ID " << digit.fId << " Energy = " << digit.fAmp << " Time = " << digit.fTime << endl ;
212// Int_t i ;
213// for(i=0;i<digit.fNprimary;i++)
214// out << "Primary " << i+1 << " = " << digit.fPrimary[i] << endl ;
215// out << "Position in list = " << digit.fIndexInList << endl ;
216 digit.Warning("operator <<", "Implement differently") ;
d15a28e7 217 return out ;
218}
219
cf239357 220