1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
18 //_________________________________________________________________________
20 // A Digit is the sum of the energy lost in an EMCAL Tower
21 // It also stores information on Primary, and enterring particle
22 // tracknumbers Digits are created using AliEMCALSDigitizer, followed
23 // by AliEMCALDigitizer
25 //*-- Author: Sahal Yacoob (LBL)
26 // based on : AliPHOSDigit
27 //__________________________________________________________________________
29 // --- ROOT system ---
30 #include <Riostream.h>
33 // --- Standard library ---
35 // --- AliRoot header files ---
37 #include "AliEMCALDigit.h"
38 #include "AliEMCALGeometry.h"
40 ClassImp(AliEMCALDigit)
42 //____________________________________________________________________________
43 AliEMCALDigit::AliEMCALDigit() :
68 // Need to initialise for reading old files
69 fPrimary = new Int_t[fNMaxPrimary] ;
70 fDEPrimary = new Float_t[fNMaxPrimary] ;
71 fIparent = new Int_t[fNMaxiparent] ;
72 fDEParent = new Float_t[fNMaxiparent] ;
73 for ( Int_t i = 0; i < fNMaxPrimary ; i++) {
78 for ( Int_t i = 0; i < fNMaxiparent ; i++) {
84 //____________________________________________________________________________
85 AliEMCALDigit::AliEMCALDigit(Int_t primary, Int_t iparent, Int_t id, Float_t digEnergy, Float_t time, Int_t type, Int_t index, Float_t chi2, Int_t ndf, Float_t dE)
107 // ctor with all data
109 // data memebrs of the base class (AliNewDigit)
112 fIndexInList = index ;
115 fPrimary = new Int_t[fNMaxPrimary] ;
116 fDEPrimary = new Float_t[fNMaxPrimary] ;
117 fIparent = new Int_t[fNMaxiparent] ;
118 fDEParent = new Float_t[fNMaxiparent] ;
121 fPrimary[0] = primary ;
124 fIparent[0] = iparent ;
127 else{ //If the contribution of this primary smaller than fDigitThreshold (AliEMCALv1)
136 for ( i = 1; i < fNMaxPrimary ; i++) {
141 for ( i = 1; i< fNMaxiparent ; i++) {
147 //____________________________________________________________________________
148 AliEMCALDigit::AliEMCALDigit(const AliEMCALDigit & digit)
149 : AliDigitNew(digit),
150 fAmpFloat(digit.fAmpFloat),
151 fNSamples(digit.fNSamples),
153 fNSamplesHG(digit.fNSamplesHG),
155 fNprimary(digit.fNprimary),
156 fNMaxPrimary(digit.fNMaxPrimary),
159 fNiparent(digit.fNiparent),
160 fNMaxiparent(digit.fNMaxiparent),
163 fMaxIter(digit.fMaxIter),
165 fTimeR(digit.fTimeR),
168 fDigitType(digit.fDigitType)
171 // data memebrs of the base class (AliNewDigit)
174 fIndexInList = digit.fIndexInList ;
177 if (fSamples ) delete [] fSamples ; fSamples = NULL ;
178 if (fSamplesHG ) delete [] fSamplesHG ; fSamplesHG = NULL ;
179 if (fPrimary ) delete [] fPrimary ; fPrimary = NULL ;
180 if (fDEPrimary) delete [] fDEPrimary ; fDEPrimary = NULL ;
181 if (fIparent ) delete [] fIparent ; fIparent = NULL ;
182 if (fDEParent) delete [] fDEParent ; fDEParent = NULL ;
185 fSamples = new Int_t[fNSamples];
186 for (Int_t i=0; i < digit.fNSamples; i++) fSamples[i] = digit.fSamples[i];
190 fSamplesHG = new Int_t[fNSamplesHG];
191 for (Int_t i=0; i < digit.fNSamplesHG; i++) fSamplesHG[i] = digit.fSamplesHG[i];
196 fPrimary = new Int_t [fNMaxPrimary] ;
197 fDEPrimary = new Float_t[fNMaxPrimary] ;
198 for ( Int_t i = 0; i < fNMaxPrimary ; i++) {
199 fPrimary[i] = digit.fPrimary[i] ;
200 fDEPrimary[i] = digit.fDEPrimary[i] ;
205 fIparent = new Int_t [fNMaxiparent] ;
206 fDEParent = new Float_t[fNMaxiparent] ;
207 for (Int_t j = 0; j< fNMaxiparent ; j++) {
208 fIparent[j] = digit.fIparent[j] ;
209 fDEParent[j] = digit.fDEParent[j] ;
215 //____________________________________________________________________________
216 AliEMCALDigit::~AliEMCALDigit()
218 // Delete array of primaries if any
220 if (fSamples ) delete [] fSamples ; fSamples = NULL ;
221 if (fSamplesHG ) delete [] fSamplesHG ; fSamplesHG = NULL ;
222 if (fPrimary ) delete [] fPrimary ; fPrimary = NULL ;
223 if (fDEPrimary) delete [] fDEPrimary ; fDEPrimary = NULL ;
224 if (fIparent ) delete [] fIparent ; fIparent = NULL ;
225 if (fDEParent) delete [] fDEParent ; fDEParent = NULL ;
230 //____________________________________________________________________________
231 void AliEMCALDigit::Clear(const Option_t*)
233 // Delete array of primaries if any
234 if (fSamples ) delete [] fSamples ; fSamples = NULL ;
235 if (fSamplesHG ) delete [] fSamplesHG ; fSamplesHG = NULL ;
236 if (fPrimary ) delete [] fPrimary ; fPrimary = NULL ;
237 if (fDEPrimary) delete [] fDEPrimary ; fDEPrimary = NULL ;
238 if (fIparent ) delete [] fIparent ; fIparent = NULL ;
239 if (fDEParent) delete [] fDEParent ; fDEParent = NULL ;
243 //____________________________________________________________________________
244 Int_t AliEMCALDigit::Compare(const TObject * obj) const
246 // Compares two digits with respect to its Id
247 // to sort according increasing Id
251 AliEMCALDigit * digit = (AliEMCALDigit *)obj ;
253 Int_t iddiff = fId - digit->GetId() ;
257 else if ( iddiff < 0 )
266 //____________________________________________________________________________
267 Float_t AliEMCALDigit::GetEta() const
269 //return pseudorapidity for this digit
270 // should be change in EMCALGeometry - 19-nov-04
271 Float_t eta=-10., phi=-10.;
273 const AliEMCALGeometry *g = AliEMCALGeometry::GetInstance();
274 g->EtaPhiFromIndex(id,eta,phi);
278 //____________________________________________________________________________
279 Float_t AliEMCALDigit::GetPhi() const
281 //return phi coordinate of digit
282 // should be change in EMCALGeometry - 19-nov-04
283 Float_t eta=-10., phi=-10.;
285 const AliEMCALGeometry *g = AliEMCALGeometry::GetInstance();
286 g->EtaPhiFromIndex(id,eta,phi);
290 //____________________________________________________________________________
291 Bool_t AliEMCALDigit::GetFALTROSample(const Int_t iSample, Int_t& timeBin, Int_t& amp) const
293 //Get FALTRO sample in time bin iSample
294 if (iSample >= fNSamples || iSample < 0 || fDigitType==kTrigger) return kFALSE;
296 amp = fSamples[iSample] & 0xFFF;
297 timeBin = (fSamples[iSample] >> 12) & 0xFF;
301 //____________________________________________________________________________
302 Bool_t AliEMCALDigit::GetALTROSampleLG(const Int_t iSample, Int_t& timeBin, Int_t& amp) const
304 //Get Low Gain ALTRO sample in time bin iSample
305 if (iSample >= fNSamples || iSample < 0 || fDigitType==kLG) return kFALSE;
307 amp = fSamples[iSample] & 0xFFF;
308 timeBin = (fSamples[iSample] >> 12) & 0xFF;
313 //____________________________________________________________________________
314 void AliEMCALDigit::SetALTROSamplesLG(const Int_t nSamples, Int_t *samples)
316 //Set array of ALTRO samples, Low Gain or FALTRO
317 fNSamples = nSamples;
318 fSamples = new Int_t[fNSamples];
319 for (Int_t i=0; i < fNSamples; i++) fSamples[i] = samples[i];
322 //____________________________________________________________________________
323 void AliEMCALDigit::SetALTROSamplesHG(const Int_t nSamples, Int_t *samples)
325 //Set array of ALTRO samples, High Gain.
326 fNSamplesHG = nSamples;
327 fSamplesHG = new Int_t[fNSamplesHG];
328 for (Int_t i=0; i < fNSamplesHG; i++) fSamplesHG[i] = samples[i];
332 //____________________________________________________________________________
333 Bool_t AliEMCALDigit::GetALTROSampleHG(const Int_t iSample, Int_t& timeBin, Int_t& amp) const
335 //Get High Gain ALTRO sample in time bin iSample
336 if (iSample >= fNSamplesHG || iSample < 0 || fDigitType==kHG) return kFALSE;
338 amp = fSamplesHG[iSample] & 0xFFF;
339 timeBin = (fSamplesHG[iSample] >> 12) & 0xFF;
345 //____________________________________________________________________________
346 Int_t AliEMCALDigit::GetPrimary(Int_t index) const
348 // retrieves the primary particle number given its index in the list
349 if ( (index <= fNprimary) && (index > 0)){
350 return fPrimary[index-1] ;
356 //____________________________________________________________________________
357 Float_t AliEMCALDigit::GetDEPrimary(Int_t index) const
359 // retrieves the primary particle energy contribution
360 // given its index in the list
361 if ( (index <= fNprimary) && (index > 0)){
362 return fDEPrimary[index-1] ;
369 //____________________________________________________________________________
370 Int_t AliEMCALDigit::GetIparent(Int_t index) const
372 // retrieves the primary particle number given its index in the list
373 if ( index <= fNiparent && index > 0){
374 return fIparent[index-1] ;
381 //____________________________________________________________________________
382 Float_t AliEMCALDigit::GetDEParent(Int_t index) const
384 // retrieves the parent particle energy contribution
385 // given its index in the list
386 if ( (index <= fNiparent) && (index > 0)){
387 return fDEParent[index-1] ;
393 //____________________________________________________________________________
394 void AliEMCALDigit::ShiftPrimary(Int_t shift){
395 //shifts primary number to BIG offset, to separate primary in different TreeK
397 for(index = 0; index <fNprimary; index++ ){
398 fPrimary[index] = fPrimary[index]+ shift * 10000000 ;}
399 for(index =0; index <fNiparent; index++){
400 fIparent[index] = fIparent[index] + shift * 10000000 ;}
402 //____________________________________________________________________________
403 Bool_t AliEMCALDigit::operator==(AliEMCALDigit const & digit) const
405 // Two digits are equal if they have the same Id
407 if ( fId == digit.fId )
413 //____________________________________________________________________________
414 AliEMCALDigit AliEMCALDigit::operator+(const AliEMCALDigit &digit)
416 // Adds the amplitude of digits and completes the list of primary particles
417 // if amplitude is larger than
419 fAmpFloat += digit.fAmpFloat ;
420 for (Int_t i=0; i < fNSamples ; i++) fSamples[i] += digit.fSamples[i];
421 for (Int_t i=0; i < fNSamplesHG; i++) fSamplesHG[i] += digit.fSamplesHG[i];
424 if(fTime > digit.fTime)
425 fTime = digit.fTime ;
426 if (digit.fTimeR < fTimeR)
427 fTimeR = digit.fTimeR ;
429 Int_t max1 = fNprimary ;
430 Int_t max2 = fNiparent ;
432 for (index = 0 ; index < digit.fNprimary ; index++){
433 Bool_t newPrim = kTRUE ;
435 for ( old = 0 ; (old < max1) && newPrim; old++) { //already have this primary?
436 if(fPrimary[old] == digit.fPrimary[index]) {
438 fDEPrimary[old] += digit.fDEPrimary[index];
442 if(max1<fNMaxPrimary){
443 fPrimary[max1] = digit.fPrimary[index] ;
444 fDEPrimary[max1] = digit.fDEPrimary[index] ;
448 if(fNprimary==fNMaxPrimary) {
450 TString mess = " NMaxPrimary = " ;
451 mess += fNMaxPrimary ;
452 mess += " is too small" ;
453 Fatal("AliEMCALDigit::Operator+ -->" , mess.Data()) ;
459 for (index = 0 ; index < digit.fNiparent ; index++){
460 Bool_t newParent = kTRUE ;
462 for ( old = 0 ; (old < max2) && newParent; old++) { //already have this primary?
463 if(fIparent[old] == digit.fIparent[index]) {
465 fDEParent[old] += digit.fDEParent[index];
469 if(max2<fNMaxiparent) {
470 fIparent[max2] = digit.fIparent[index] ;
471 fDEParent[max2] = digit.fDEParent[index] ;
475 if(fNiparent==fNMaxiparent) {
477 TString mess = " NMaxiparent = " ;
478 mess += fNMaxiparent ;
479 mess += " is too small" ;
480 Fatal("AliEMCALDigit::Operator+ -->", mess.Data()) ;
489 //____________________________________________________________________________
490 AliEMCALDigit AliEMCALDigit::operator*(Float_t factor)
492 // Multiplies the amplitude by a factor
494 //Float_t tempo = static_cast<Float_t>(fAmp) ;
496 //fAmp = static_cast<Int_t>(TMath::Floor(tempo)) ;
499 for (Int_t i=0; i < fNSamples ; i++) fSamples[i] = Int_t(factor*fSamples[i]);
500 for (Int_t i=0; i < fNSamplesHG; i++) fSamplesHG[i] = Int_t(factor*fSamplesHG[i]);
502 for(Int_t i=0; i < fNprimary; i++)
503 fDEPrimary[i] *= factor;
504 for(Int_t i=0; i < fNiparent; i++)
505 fDEParent[i] *= factor;
510 //____________________________________________________________________________
511 ostream& operator << ( ostream& out , const AliEMCALDigit & digit)
513 // Prints the data of the digit
515 out << "ID " << digit.fId << " Energy = " << digit.fAmp << " Time = " << digit.fTime << endl ;
516 for(Int_t i=0;i<digit.fNprimary;i++)
517 out << "Primary " << i+1 << " = " << digit.fPrimary[i]
518 << " : DE " << digit.fDEPrimary[i] << endl ;
520 for(Int_t j=0;j<digit.fNiparent;j++)
521 out << "Iparent " << j+1 << " = " << digit.fIparent[j]
522 << " : DE " << digit.fDEParent[j] << endl ;
523 out << "Position in list = " << digit.fIndexInList << endl ;
527 //____________________________________________________________________________
528 void AliEMCALDigit::Print(const Option_t* /*opt*/) const
531 printf("===\nDigit id: %4d / Energy %2.3f ; Time %e ; Time samples %d ; Chi2 %2.3f, NDF %d, Type? %d \n",
532 fId, fAmpFloat,fTime, fNSamples, fChi2, fNDF, fDigitType);
533 if(fDigitType==kTrigger){
535 for (Int_t i=0; i < GetNFALTROSamples(); i++)
538 GetFALTROSample(i, timeBin, amp);
539 printf(" (%d,%d) ",timeBin,amp);
544 printf("ALTRO, Low Gain: ");
545 for (Int_t i=0; i < GetNALTROSamplesLG(); i++)
548 GetALTROSampleLG(i, timeBin, amp);
549 printf(" (%d,%d) ",timeBin,amp);
552 printf("ALTRO, High Gain: ");
553 for (Int_t i=0; i < GetNALTROSamplesHG(); i++)
556 GetALTROSampleHG(i, timeBin, amp);
557 printf(" (%d,%d) ",timeBin,amp);