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