]> git.uio.no Git - u/mrichter/AliRoot.git/blob - EMCAL/AliEMCALDigit.cxx
fSDigitsInRun was not calculated anymore
[u/mrichter/AliRoot.git] / EMCAL / AliEMCALDigit.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 //  EMCAL 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 EMCAL 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 "AliEMCALDigit.h"
38
39
40 ClassImp(AliEMCALDigit)
41
42 //____________________________________________________________________________
43   AliEMCALDigit::AliEMCALDigit() 
44 {
45   // default ctor 
46
47   fIndexInList = -1 ; 
48   fNprimary    = 0 ;  
49   fNMaxPrimary = 5 ; 
50   fNiparent     = 0 ;
51   fNMaxiparent = fNMaxPrimary*10;
52 }
53
54 //____________________________________________________________________________
55 AliEMCALDigit::AliEMCALDigit(Int_t primary, Int_t iparent, Int_t id, Int_t DigEnergy, Int_t index) 
56 {  
57   // ctor with all data 
58
59   fNMaxPrimary = 5 ; 
60   fNMaxiparent = fNMaxPrimary*10;
61   fAmp         = DigEnergy ;
62   fId          = id ;
63   fIndexInList = index ; 
64   if( primary != -1){
65     fNprimary    = 1 ; 
66     fPrimary[0]  = primary ;
67     fNiparent   = 1 ;
68     fIparent[0] = iparent ;    
69
70   }
71   else{  //If the contribution of this primary smaller than fDigitThreshold (AliEMCALv1)
72     fNprimary    = 0 ; 
73     fPrimary[0]  = -1 ;
74     fNiparent   = 0 ;
75     fIparent[0] = -1 ;    
76
77   }
78   Int_t i ;
79   for ( i = 1; i < fNMaxPrimary ; i++)
80     fPrimary[i]  = -1 ; 
81
82   for ( Int_t j =1; j< fNMaxiparent ; j++)
83     fIparent[j] = -1 ;  
84 }
85
86 //____________________________________________________________________________
87 AliEMCALDigit::AliEMCALDigit(const AliEMCALDigit & digit) 
88 {
89   // copy ctor
90   
91
92   fNMaxPrimary = digit.fNMaxPrimary ;  
93   fNMaxiparent = digit.fNMaxiparent ;
94   Int_t i ;
95   for ( i = 0; i < fNMaxPrimary ; i++)
96   fPrimary[i]  = digit.fPrimary[i] ;
97   Int_t j ;
98   for (j = 0; j< fNMaxiparent ; j++)
99   fIparent[j]  = digit.fIparent[j] ;
100   fAmp         = digit.fAmp ;
101   fId          = digit.fId;
102   fIndexInList = digit.fIndexInList ; 
103   fNprimary    = digit.fNprimary ;
104   fNiparent    = digit.fNiparent ;
105 }
106
107 //____________________________________________________________________________
108 AliEMCALDigit::~AliEMCALDigit() 
109 {
110   // Delete array of primiries if any
111   
112 }
113
114 //____________________________________________________________________________
115 Int_t AliEMCALDigit::Compare(const TObject * obj) const
116 {
117   // Compares two digits with respect to its Id
118   // to sort according increasing Id
119
120   Int_t rv ;
121
122   AliEMCALDigit * digit = (AliEMCALDigit *)obj ; 
123
124   Int_t iddiff = fId - digit->GetId() ; 
125
126   if ( iddiff > 0 ) 
127     rv = 1 ;
128   else if ( iddiff < 0 )
129     rv = -1 ; 
130   else
131     rv = 0 ;
132   
133   return rv ; 
134
135 }
136
137 //____________________________________________________________________________
138 Int_t AliEMCALDigit::GetPrimary(Int_t index) const
139 {
140   // retrieves the primary particle number given its index in the list 
141   Int_t rv = -1 ;
142   if ( index <= fNprimary ){
143     rv = fPrimary[index-1] ;
144   } 
145
146   return rv ; 
147   
148 }
149
150 //____________________________________________________________________________
151 Int_t AliEMCALDigit::GetIparent(Int_t index) const
152 {
153   // retrieves the primary particle number given its index in the list 
154   Int_t rv = -1 ;
155   if ( index <= fNiparent ){
156     rv = fIparent[index-1] ;
157   } 
158
159   return rv ; 
160   
161 }
162
163
164 //____________________________________________________________________________
165 void AliEMCALDigit::ShiftPrimary(Int_t shift){
166   //shifts primary nimber to BIG offset, to separate primary in different TreeK
167   Int_t index  ;
168   for(index = 0; index <fNprimary; index++ ){
169     fPrimary[index] = fPrimary[index]+ shift * 10000000   ;}
170   for(index =0; index <fNiparent; index++){
171     fIparent[index] = fIparent[index] + shift * 10000000 ;}
172 }
173 //____________________________________________________________________________
174 Bool_t AliEMCALDigit::operator==(AliEMCALDigit const & digit) const 
175 {
176   // Two digits are equal if they have the same Id
177   
178   if ( fId == digit.fId ) 
179     return kTRUE ;
180   else 
181     return kFALSE ;
182 }
183  
184 //____________________________________________________________________________
185 AliEMCALDigit& AliEMCALDigit::operator+(AliEMCALDigit const & digit) 
186 {
187   // Adds the amplitude of digits and completes the list of primary particles
188   // if amplitude is larger than 
189   
190   fAmp += digit.fAmp ;
191   
192   Int_t max1 = fNprimary ; 
193   Int_t max2 = fNiparent ;  
194   Int_t index ; 
195   for (index = 0 ; index < digit.fNprimary ; index++){
196     Bool_t deja = kTRUE ;
197     Int_t old ;
198     for ( old = 0 ; (old < max1) && deja; old++) { //already have this primary?
199       if(fPrimary[old] == (digit.fPrimary)[index])
200         deja = kFALSE;
201     }
202     if(deja){
203       fPrimary[fNprimary] = (digit.fPrimary)[index] ; 
204       fNprimary++ ;
205       if(fNprimary>fNMaxPrimary) {
206         cout << "AliEMCALDigit >> Increase NMaxPrimary "<< endl ;
207         return *this ;
208       }
209     }
210   }
211   
212   for (index = 0 ; index < digit.fNiparent ; index++){
213     Bool_t dejavu = kTRUE ;
214     Int_t old ;
215     for ( old = 0 ; (old < max2) && dejavu; old++) { //already have this primary?
216       if(fIparent[old] == (digit.fIparent)[index])
217         dejavu = kFALSE;
218     }
219     if(dejavu){
220       fIparent[fNiparent] = (digit.fIparent)[index] ; 
221       fNiparent++ ;
222       if(fNiparent>fNMaxiparent) {
223         cout << "AliEMCALDigit >> Increase NMaxiparent "<< endl ;
224         return *this ;
225       }
226     }
227   }
228   
229   return *this ;
230 }
231
232 //____________________________________________________________________________
233 ostream& operator << ( ostream& out , const AliEMCALDigit & digit)
234 {
235   // Prints the data of the digit
236   
237   out << "ID " << digit.fId << " Energy = " << digit.fAmp << endl ; 
238   Int_t i,j ;
239   for(i=0;i<digit.fNprimary;i++)
240     out << "Primary " << i+1 << " = " << digit.fPrimary[i] << endl ;
241    
242   for(j=0;j<digit.fNiparent;j++)
243     out << "Iparent " << j+1 << " = " << digit.fIparent[j] << endl ;
244  out << "Position in list = " << digit.fIndexInList << endl ; 
245   return out ;
246 }
247
248