]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PHOS/AliPHOSDigit.cxx
Changed the primaries handling by inserting an array of Int_t
[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   fNMaxPrimary = 5 ; 
50   fPrimary = new Int_t[fNMaxPrimary] ;
51 }
52
53 //____________________________________________________________________________
54 AliPHOSDigit::AliPHOSDigit(Int_t primary, Int_t id, Int_t DigEnergy, Int_t index) 
55 {  
56   // ctor with all data 
57
58   fAmp         = DigEnergy ;
59   fId          = id ;
60   fIndexInList = index ; 
61   if( primary != -1){
62     fNprimary    = 1 ; 
63     fPrimary[0]  = primary ;
64   }
65   else{  //If the contribution of this primary smaller than fDigitThreshold (AliPHOSv1)
66     fNprimary    = 0 ; 
67     fPrimary[0]  = -1 ;
68   }
69   Int_t i ;
70   for ( i = 1; i < fNMaxPrimary ; i++)
71     fPrimary[i]  = -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   fNMaxPrimary = digit.fNMaxPrimary ;
84   Int_t i ;
85   for ( i = 0; i < fNMaxPrimary ; i++)
86     fPrimary[i]  = digit.fPrimary[i] ;
87 }
88
89 //____________________________________________________________________________
90 Int_t AliPHOSDigit::Compare(TObject * obj)
91 {
92   // Compares two digits with respect to its Id
93   // to sort according increasing Id
94
95   Int_t rv ;
96
97   AliPHOSDigit * digit = (AliPHOSDigit *)obj ; 
98
99   Int_t iddiff = fId - digit->GetId() ; 
100
101   if ( iddiff > 0 ) 
102     rv = 1 ;
103   else if ( iddiff < 0 )
104     rv = -1 ; 
105   else
106     rv = 0 ;
107   
108   return rv ; 
109
110 }
111
112 //____________________________________________________________________________
113 Int_t AliPHOSDigit::GetPrimary(Int_t index) const
114 {
115   // Returns the primary particle id index =1,2,3
116  
117   Int_t rv = -1 ; 
118   if ( index > fNMaxPrimary )
119     cout << "AliPHOSDigit  ERROR > only " << fNMaxPrimary << " primaries allowed" << endl ; 
120   else 
121     rv = fPrimary[index-1] ; 
122
123   return rv ; 
124   
125 }
126
127 //____________________________________________________________________________
128 Bool_t AliPHOSDigit::operator==(AliPHOSDigit const & digit) const 
129 {
130   // Two digits are equal if they have the same Id
131   
132   if ( fId == digit.fId ) 
133     return kTRUE ;
134   else 
135     return kFALSE ;
136 }
137  
138 //____________________________________________________________________________
139 AliPHOSDigit& AliPHOSDigit::operator+(AliPHOSDigit const & digit) 
140 {
141   // Adds the amplitude of digits and completes the list of primary particles
142   // if amplitude is larger than 
143
144   fAmp += digit.fAmp ;
145
146   Int_t max1 = fNprimary ; 
147   Int_t max2 = digit.fNprimary ; 
148  
149   if ( fNprimary >= fNMaxPrimary ) 
150     cout << "AliPHOSDigit + operator  ERROR > too many primaries, modify AliPHOSDigit" << endl ;
151   else {
152     fNprimary += digit.fNprimary ; 
153     if ( fNprimary > fNMaxPrimary ) {
154       cout << "AliPHOSDigit + operator  ERROR > too many primaries, modify AliPHOSDigit" << endl ; 
155       fNprimary = fNMaxPrimary ;
156     }
157     Int_t index ; 
158     for (index = 0 ; index < max2 ; index++)
159       fPrimary[index+max1] = (digit.fPrimary)[index] ; 
160   }
161
162   return *this ;
163 }
164
165 //____________________________________________________________________________
166 ostream& operator << ( ostream& out , const AliPHOSDigit & digit)
167 {
168   // Prints the data of the digit
169   
170   out << "ID " << digit.fId << " Energy = " << digit.fAmp << endl 
171       << "Primary 1 = " << digit.fPrimary[0] << endl 
172       << "Primary 2 = " << digit.fPrimary[1] << endl 
173       << "Primary 3 = " << digit.fPrimary[2] << endl 
174       << "Primary 4 = " << digit.fPrimary[3] << endl 
175       << "Primary 5 = " << digit.fPrimary[4] << endl 
176        << "Position in list = " << digit.fIndexInList << endl ; 
177   return out ;
178 }
179
180