]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PHOS/AliPHOSDigit.cxx
Fast simulation ready to be tested
[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
6a3f1304 163 if ( fNprimary > 3 ) {
26d4b141 164 cout << "AliPHOSDigit + operator ERROR > too many primaries, modify AliPHOSDigit" << endl ;
6a3f1304 165 fNprimary = 3 ;
166 }
167 else {
26d4b141 168 switch (fNprimary) {
169 case 1 :
170 SetPrimary(1, fPrimary[0]) ;
171 break ;
172 case 2 :
173 SetPrimary(2, fPrimary[1]) ;
174 break ;
175 case 3:
176 SetPrimary(3, fPrimary[2]) ;
177 break ;
178 }
179 }
180
181 // end of crummy stuff
182
d15a28e7 183 return *this ;
184}
185
186//____________________________________________________________________________
cf239357 187ostream& operator << ( ostream& out , const AliPHOSDigit & digit)
d15a28e7 188{
cf239357 189 out << "ID " << digit.fId << " Energy = " << digit.fAmp ;
d15a28e7 190
191 return out ;
192}
193
26d4b141 194//____________________________________________________________________________
195void AliPHOSDigit::SetPrimary(Int_t index, Int_t value)
d15a28e7 196{
26d4b141 197 switch (index) {
198 case 1 :
199 fPrimary1 = value ;
200 break ;
201 case 2 :
202 fPrimary2 = value ;
203 break ;
204 case 3 :
205 fPrimary3 = value ;
206 break ;
207 }
cf239357 208
26d4b141 209 }