]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PHOS/AliPHOSDigit.cxx
G4 compatibility changes
[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   fPrimary1    = primary ;
63   fNprimary    = 1 ; 
64 }
65
66 //____________________________________________________________________________
67 AliPHOSDigit::AliPHOSDigit(const AliPHOSDigit & digit) 
68 {
69   // copy ctor
70   
71   fAmp         = digit.fAmp ;
72   fId          = digit.fId;
73   fIndexInList = digit.fIndexInList ; 
74   fNprimary    = digit.fNprimary ;
75   fPrimary1    = digit.fPrimary1 ;
76   fPrimary2    = digit.fPrimary2 ;
77   fPrimary3    = digit.fPrimary3 ;
78 }
79
80 //____________________________________________________________________________
81 Int_t AliPHOSDigit::Compare(TObject * obj)
82 {
83   // Compares two digits with respect to its Id
84   // to sort according increasing Id
85
86   Int_t rv ; 
87
88   AliPHOSDigit * digit = (AliPHOSDigit *)obj ; 
89
90   Int_t iddiff = fId - digit->GetId() ; 
91
92   if ( iddiff > 0 ) 
93     rv = 1 ;
94   else if ( iddiff < 0 )
95     rv = -1 ; 
96   else
97     rv = 0 ;
98   
99   return rv ; 
100
101 }
102
103 //____________________________________________________________________________
104 Int_t AliPHOSDigit::GetPrimary(Int_t index) const
105 {
106   // Returns the primary particle id index =1,2,3
107  
108   Int_t rv = -1 ; 
109   if ( index > 3 )
110     cout << "AliPHOSDigit  ERROR > only 3 primaries allowed" << endl ; 
111   else {
112     switch (index) {  
113     case 1 :
114       rv = fPrimary1 ; 
115       break ; 
116     case 2 :
117       rv = fPrimary2 ; 
118       break ; 
119     case 3 :
120       rv = fPrimary3 ; 
121       break ; 
122     }
123   } 
124
125   return rv ; 
126
127 }
128
129 //____________________________________________________________________________
130 Bool_t AliPHOSDigit::operator==(AliPHOSDigit const & digit) const 
131 {
132   // Two digits are equal if they have the same Id
133   
134   if ( fId == digit.fId ) 
135     return kTRUE ;
136   else 
137     return kFALSE ;
138 }
139  
140 //____________________________________________________________________________
141 AliPHOSDigit& AliPHOSDigit::operator+(AliPHOSDigit const & digit) 
142 {
143   // Adds the amplitude of digits and completes the list of primary particles
144
145   fAmp += digit.fAmp ;
146   
147   // Here comes something crummy ... but I do not know how to stream pointers
148   // because AliPHOSDigit is in a TCLonesArray
149   
150   Int_t tempo1[3] ; 
151   tempo1[0] = fPrimary1 ; 
152   tempo1[1] = fPrimary2 ; 
153   tempo1[2] = fPrimary3 ; 
154
155   Int_t tempo2[3] ; 
156   tempo2[0] = digit.fPrimary1 ; 
157   tempo2[1] = digit.fPrimary2 ; 
158   tempo2[2] = digit.fPrimary3 ; 
159
160   Int_t max1 = fNprimary ; 
161   Int_t max2 = digit.fNprimary ; 
162  
163   if ( fNprimary >= 3 ) {
164     cout << "AliPHOSDigit + operator  ERROR > too many primaries, modify AliPHOSDigit" << endl ; 
165   } 
166   else {
167     fNprimary += digit.fNprimary ; 
168     if ( fNprimary > 3 ) {
169       cout << "AliPHOSDigit + operator  ERROR > too many primaries, modify AliPHOSDigit" << endl ; 
170       fNprimary = 3 ;
171     }
172     
173     Int_t tempo3[3] ;
174     Int_t index ; 
175     for (index = 0 ; index < 3 ; index++)
176       tempo3[index] = 0 ; 
177
178     for (index = 0 ; index < max1 ; index++)
179       tempo3[index] = tempo1[index] ;
180
181     for (index = 0 ; index < max2 ; index++)
182       tempo3[index+max1] = tempo2[index] ; 
183     
184     fPrimary1 = tempo3[0] ; 
185     fPrimary2 = tempo3[1] ; 
186     fPrimary3 = tempo3[2] ; 
187
188   }
189  // end of crummy stuff      
190
191   return *this ;
192 }
193
194 //____________________________________________________________________________
195 ostream& operator << ( ostream& out , const AliPHOSDigit & digit)
196 {
197   // Prints the data of the digit
198   
199   out << "ID " << digit.fId << " Energy = " << digit.fAmp << endl 
200       << "Primary 1 = " << digit.fPrimary1 << endl 
201       << "Primary 2 = " << digit.fPrimary2 << endl 
202       << "Primary 3 = " << digit.fPrimary3 << endl 
203       << "Position in list = " << digit.fIndexInList << endl ; 
204   return out ;
205 }
206
207