]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PHOS/AliPHOSDigit.cxx
ParticleGuesser removed and replaced by PID
[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 //_________________________________________________________________________
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>
26 #include <cassert> 
27
28 // --- AliRoot header files ---
29
30 #include "AliPHOSDigit.h"
31
32
33 ClassImp(AliPHOSDigit)
34
35 //____________________________________________________________________________
36   AliPHOSDigit::AliPHOSDigit() : fPrimary(0)
37 {
38   fNprimary = 0 ;  
39   Int_t index ; 
40   for (index = 1 ; index <= 3 ; index++)
41     SetPrimary(index, 0) ; 
42 }
43
44 //____________________________________________________________________________
45 AliPHOSDigit::AliPHOSDigit(Int_t primary, Int_t id, Int_t DigEnergy) 
46 {  
47   fId         = id ;
48   fAmp        = DigEnergy ;
49   fPrimary    = new Int_t[1] ; 
50   fPrimary[0] = primary ;
51   fNprimary   = 1 ; 
52   SetPrimary(1, primary) ; 
53
54 }
55
56 //____________________________________________________________________________
57 AliPHOSDigit::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 ;
65   for ( index = 0 ; index < fNprimary ; index++ ) {
66     fPrimary[index] = primary[index] ;
67     SetPrimary( index+1, digit.GetPrimary(index+1) ) ; 
68   }
69
70 }
71
72 //____________________________________________________________________________
73 AliPHOSDigit::~AliPHOSDigit()
74 {
75   if ( fPrimary != 0 ) 
76     delete fPrimary ; 
77 }
78
79 //____________________________________________________________________________
80 Int_t AliPHOSDigit::Compare(TObject * obj)
81 {
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 }
98
99 //____________________________________________________________________________
100 Int_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
123 //____________________________________________________________________________
124 Bool_t AliPHOSDigit::operator==(AliPHOSDigit const & digit) const 
125 {
126   if ( fId == digit.fId ) 
127     return kTRUE ;
128   else 
129     return kFALSE ;
130 }
131  
132 //____________________________________________________________________________
133 AliPHOSDigit& AliPHOSDigit::operator+(AliPHOSDigit const & digit) 
134 {
135   fAmp += digit.fAmp ;
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++ ){
143     tempo[index] = fPrimary[index] ; 
144   }  
145  
146   delete fPrimary ; 
147   fNprimary += digit.GetNprimary() ; 
148   fPrimary = new Int_t[fNprimary] ; 
149   
150   for ( index = 0 ; index < oldfNprimary  ; index++ ) { 
151     fPrimary[index] = tempo[index] ; 
152   }
153
154   Int_t jndex = 0 ; 
155   for ( index = oldfNprimary ; index < fNprimary ; index++ ) { 
156     fPrimary[index] = digit.fPrimary[jndex] ; 
157     jndex++ ; 
158   }
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
181   return *this ;
182 }
183
184 //____________________________________________________________________________
185 ostream& operator << ( ostream& out , const AliPHOSDigit & digit)
186 {
187   out << "ID " << digit.fId << " Energy = " << digit.fAmp ;
188
189   return out ;
190 }
191
192 //____________________________________________________________________________
193 void AliPHOSDigit::SetPrimary(Int_t index, Int_t value) 
194 {
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   }
206
207  }