]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PHOS/AliPHOSDigit.cxx
Continuous progress on the Fast Simulation: AliPHOSFastRecParticle is born
[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
16//_________________________________________________________________________
17// Digit class for PHOS that contains an absolute ID and an energy
18//*-- Author : Laurent Aphecetche SUBATECH
19//////////////////////////////////////////////////////////////////////////////
20
21// --- ROOT system ---
22
23// --- Standard library ---
24
25#include <iostream>
cf239357 26#include <cassert>
d15a28e7 27
28// --- AliRoot header files ---
29
30#include "AliPHOSDigit.h"
31
32
33ClassImp(AliPHOSDigit)
34
cf239357 35//____________________________________________________________________________
36 AliPHOSDigit::AliPHOSDigit() : fPrimary(0)
37{
26d4b141 38 fNprimary = 0 ;
39 Int_t index ;
40 for (index = 1 ; index <= 3 ; index++)
c198e326 41 SetPrimary(index, -1) ;
cf239357 42}
43
d15a28e7 44//____________________________________________________________________________
ff4c968a 45AliPHOSDigit::AliPHOSDigit(Int_t primary, Int_t id, Int_t DigEnergy)
d15a28e7 46{
cf239357 47 fId = id ;
48 fAmp = DigEnergy ;
49 fPrimary = new Int_t[1] ;
ff4c968a 50 fPrimary[0] = primary ;
cf239357 51 fNprimary = 1 ;
26d4b141 52 SetPrimary(1, primary) ;
53
cf239357 54}
55
56//____________________________________________________________________________
57AliPHOSDigit::AliPHOSDigit(const AliPHOSDigit & digit)
58{
59 fId = digit.fId;
60 fAmp = digit.fAmp ;
61 fNprimary = digit.GetNprimary() ;
62 fPrimary = new Int_t[fNprimary] ;
63 Int_t * primary = digit.GetPrimary() ;
64 Int_t index ;
26d4b141 65 for ( index = 0 ; index < fNprimary ; index++ ) {
cf239357 66 fPrimary[index] = primary[index] ;
26d4b141 67 SetPrimary( index+1, digit.GetPrimary(index+1) ) ;
68 }
69
ff4c968a 70}
71
72//____________________________________________________________________________
73AliPHOSDigit::~AliPHOSDigit()
74{
26d4b141 75 if ( fPrimary != 0 )
76 delete fPrimary ;
d15a28e7 77}
78
79//____________________________________________________________________________
cf239357 80Int_t AliPHOSDigit::Compare(TObject * obj)
d15a28e7 81{
cf239357 82 Int_t rv ;
83
84 AliPHOSDigit * digit = (AliPHOSDigit *)obj ;
85
86 Int_t iddiff = fId - digit->GetId() ;
87
88 if ( iddiff > 0 )
89 rv = 1 ;
90 else if ( iddiff < 0 )
91 rv = -1 ;
92 else
93 rv = 0 ;
94
95 return rv ;
96
97}
26d4b141 98
99//____________________________________________________________________________
100Int_t AliPHOSDigit::GetPrimary(Int_t index) const
101{
102 Int_t rv = -1 ;
103 if ( index > 3 )
104 cout << "AliPHOSDigit ERROR > only 3 primaries allowed" << endl ;
105 else {
106 switch (index) {
107 case 1 :
108 rv = fPrimary1 ;
109 break ;
110 case 2 :
111 rv = fPrimary2 ;
112 break ;
113 case 3 :
114 rv = fPrimary3 ;
115 break ;
116 }
117 }
118
119 return rv ;
120
121}
122
cf239357 123//____________________________________________________________________________
124Bool_t AliPHOSDigit::operator==(AliPHOSDigit const & digit) const
125{
126 if ( fId == digit.fId )
d15a28e7 127 return kTRUE ;
128 else
129 return kFALSE ;
130}
cf239357 131
d15a28e7 132//____________________________________________________________________________
cf239357 133AliPHOSDigit& AliPHOSDigit::operator+(AliPHOSDigit const & digit)
d15a28e7 134{
cf239357 135 fAmp += digit.fAmp ;
ff4c968a 136
137 Int_t * tempo = new Int_t[fNprimary] ;
138 Int_t index ;
139
140 Int_t oldfNprimary = fNprimary ;
141
142 for ( index = 0 ; index < oldfNprimary ; index++ ){
ff4c968a 143 tempo[index] = fPrimary[index] ;
144 }
145
146 delete fPrimary ;
cf239357 147 fNprimary += digit.GetNprimary() ;
ff4c968a 148 fPrimary = new Int_t[fNprimary] ;
149
150 for ( index = 0 ; index < oldfNprimary ; index++ ) {
ff4c968a 151 fPrimary[index] = tempo[index] ;
152 }
153
154 Int_t jndex = 0 ;
155 for ( index = oldfNprimary ; index < fNprimary ; index++ ) {
cf239357 156 fPrimary[index] = digit.fPrimary[jndex] ;
ff4c968a 157 jndex++ ;
158 }
26d4b141 159
160 // Here comes something crummy ... but I do not know how to stream pointers
161 // because AliPHOSDigit is in a TCLonesArray
162
163 if ( fNprimary > 3 )
164 cout << "AliPHOSDigit + operator ERROR > too many primaries, modify AliPHOSDigit" << endl ;
165 else {
166 switch (fNprimary) {
167 case 1 :
168 SetPrimary(1, fPrimary[0]) ;
169 break ;
170 case 2 :
171 SetPrimary(2, fPrimary[1]) ;
172 break ;
173 case 3:
174 SetPrimary(3, fPrimary[2]) ;
175 break ;
176 }
177 }
178
179 // end of crummy stuff
180
d15a28e7 181 return *this ;
182}
183
184//____________________________________________________________________________
cf239357 185ostream& operator << ( ostream& out , const AliPHOSDigit & digit)
d15a28e7 186{
cf239357 187 out << "ID " << digit.fId << " Energy = " << digit.fAmp ;
d15a28e7 188
189 return out ;
190}
191
26d4b141 192//____________________________________________________________________________
193void AliPHOSDigit::SetPrimary(Int_t index, Int_t value)
d15a28e7 194{
26d4b141 195 switch (index) {
196 case 1 :
197 fPrimary1 = value ;
198 break ;
199 case 2 :
200 fPrimary2 = value ;
201 break ;
202 case 3 :
203 fPrimary3 = value ;
204 break ;
205 }
cf239357 206
26d4b141 207 }