]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PHOS/AliPHOSDigit.cxx
initialize pointer data member to zero in the default ctor to avoid problems with...
[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 //  It would be nice to replace the 3 identifiers by an array, but, because digits are kept in a TClonesQArray,
24 //   it is not possible to stream such an array... (beyond my understqnding!)
25 //
26 //*-- Author: Laurent Aphecetche & Yves Schutz (SUBATECH)
27
28
29 // --- ROOT system ---
30
31 // --- Standard library ---
32
33 #include <iostream.h>
34
35 // --- AliRoot header files ---
36
37 #include "AliPHOSDigit.h"
38
39
40 ClassImp(AliPHOSDigit)
41
42 //____________________________________________________________________________
43   AliPHOSDigit::AliPHOSDigit() 
44 {
45   // default ctor 
46
47   fIndexInList = -1 ; 
48   fNprimary    = 0 ;  
49   fPrimary1    = -1 ; 
50   fPrimary2    = -1 ; 
51   fPrimary3    = -1 ;
52 }
53
54 //____________________________________________________________________________
55 AliPHOSDigit::AliPHOSDigit(Int_t primary, Int_t id, Int_t DigEnergy, Int_t index) 
56 {  
57   // ctor with all data 
58
59   fAmp         = DigEnergy ;
60   fId          = id ;
61   fIndexInList = index ; 
62   if( primary != -1){
63     fNprimary    = 1 ; 
64     fPrimary1    = primary ;
65   }
66   else{  //If the contribution of this primary smaller than fDigitThreshold (AliPHOSv1)
67     fNprimary    = 0 ; 
68     fPrimary1    = -1 ;
69   }
70   fPrimary2    = -1 ; 
71   fPrimary3    = -1 ;
72 }
73
74 //____________________________________________________________________________
75 AliPHOSDigit::AliPHOSDigit(const AliPHOSDigit & digit) 
76 {
77   // copy ctor
78   
79   fAmp         = digit.fAmp ;
80   fId          = digit.fId;
81   fIndexInList = digit.fIndexInList ; 
82   fNprimary    = digit.fNprimary ;
83   fPrimary1    = digit.fPrimary1 ;
84   fPrimary2    = digit.fPrimary2 ;
85   fPrimary3    = digit.fPrimary3 ;
86 }
87
88 //____________________________________________________________________________
89 Int_t AliPHOSDigit::Compare(TObject * obj)
90 {
91   // Compares two digits with respect to its Id
92   // to sort according increasing Id
93
94   Int_t rv ;
95
96   AliPHOSDigit * digit = (AliPHOSDigit *)obj ; 
97
98   Int_t iddiff = fId - digit->GetId() ; 
99
100   if ( iddiff > 0 ) 
101     rv = 1 ;
102   else if ( iddiff < 0 )
103     rv = -1 ; 
104   else
105     rv = 0 ;
106   
107   return rv ; 
108
109 }
110
111 //____________________________________________________________________________
112 Int_t AliPHOSDigit::GetPrimary(Int_t index) const
113 {
114   // Returns the primary particle id index =1,2,3
115  
116   Int_t rv = -1 ; 
117   if ( index > 3 )
118     cout << "AliPHOSDigit  ERROR > only 3 primaries allowed" << endl ; 
119   else {
120     switch (index) {  
121     case 1 :
122       rv = fPrimary1 ; 
123       break ; 
124     case 2 :
125       rv = fPrimary2 ; 
126       break ; 
127     case 3 :
128       rv = fPrimary3 ; 
129       break ; 
130     }
131   } 
132
133   return rv ; 
134
135 }
136
137 //____________________________________________________________________________
138 Bool_t AliPHOSDigit::operator==(AliPHOSDigit const & digit) const 
139 {
140   // Two digits are equal if they have the same Id
141   
142   if ( fId == digit.fId ) 
143     return kTRUE ;
144   else 
145     return kFALSE ;
146 }
147  
148 //____________________________________________________________________________
149 AliPHOSDigit& AliPHOSDigit::operator+(AliPHOSDigit const & digit) 
150 {
151   // Adds the amplitude of digits and completes the list of primary particles
152   // if amplitude is larger than 
153
154   fAmp += digit.fAmp ;
155   
156   // Here comes something crummy ... but I do not know how to stream pointers
157   // because AliPHOSDigit is in a TCLonesArray 
158
159   Int_t tempo1[3] ; 
160   tempo1[0] = fPrimary1 ; 
161   tempo1[1] = fPrimary2 ; 
162   tempo1[2] = fPrimary3 ; 
163
164   Int_t tempo2[3] ; 
165   tempo2[0] = digit.fPrimary1 ; 
166   tempo2[1] = digit.fPrimary2 ; 
167   tempo2[2] = digit.fPrimary3 ; 
168
169   Int_t max1 = fNprimary ; 
170   Int_t max2 = digit.fNprimary ; 
171  
172   if ( fNprimary >= 3 ) {
173     cout << "AliPHOSDigit + operator  ERROR > too many primaries, modify AliPHOSDigit" << endl ; 
174   } 
175   else {
176     fNprimary += digit.fNprimary ; 
177     if ( fNprimary > 3 ) {
178       cout << "AliPHOSDigit + operator  ERROR > too many primaries, modify AliPHOSDigit" << endl ; 
179       fNprimary = 3 ;
180     }
181     
182     Int_t tempo3[3] ;
183     Int_t index ; 
184     for (index = 0 ; index < 3 ; index++)
185       tempo3[index] = 0 ; 
186
187     for (index = 0 ; index < max1 ; index++)
188       tempo3[index] = tempo1[index] ;
189
190     for (index = 0 ; index < max2 ; index++)
191       tempo3[index+max1] = tempo2[index] ; 
192     
193     fPrimary1 = tempo3[0] ; 
194     fPrimary2 = tempo3[1] ; 
195     fPrimary3 = tempo3[2] ; 
196
197   }
198  // end of crummy stuff      
199
200   return *this ;
201 }
202
203 //____________________________________________________________________________
204 ostream& operator << ( ostream& out , const AliPHOSDigit & digit)
205 {
206   // Prints the data of the digit
207   
208   out << "ID " << digit.fId << " Energy = " << digit.fAmp << endl 
209       << "Primary 1 = " << digit.fPrimary1 << endl 
210       << "Primary 2 = " << digit.fPrimary2 << endl 
211       << "Primary 3 = " << digit.fPrimary3 << endl 
212       << "Position in list = " << digit.fIndexInList << endl ; 
213   return out ;
214 }
215
216