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"
41 ClassImp(AliEMCALDigit)
43 //____________________________________________________________________________
44 AliEMCALDigit::AliEMCALDigit() :
69 // Need to initialise for reading old files
70 fPrimary = new Int_t[fNMaxPrimary] ;
71 fDEPrimary = new Float_t[fNMaxPrimary] ;
72 fIparent = new Int_t[fNMaxiparent] ;
73 fDEParent = new Float_t[fNMaxiparent] ;
74 for ( Int_t i = 0; i < fNMaxPrimary ; i++) {
79 for ( Int_t i = 0; i < fNMaxiparent ; i++) {
85 //____________________________________________________________________________
86 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)
109 // ctor with all data
111 // data memebrs of the base class (AliNewDigit)
114 fIndexInList = index ;
117 fPrimary = new Int_t[fNMaxPrimary] ;
118 fDEPrimary = new Float_t[fNMaxPrimary] ;
119 fIparent = new Int_t[fNMaxiparent] ;
120 fDEParent = new Float_t[fNMaxiparent] ;
123 fPrimary[0] = primary ;
126 fIparent[0] = iparent ;
129 else{ //If the contribution of this primary smaller than fDigitThreshold (AliEMCALv1)
138 for ( i = 1; i < fNMaxPrimary ; i++) {
143 for ( i = 1; i< fNMaxiparent ; i++) {
149 //____________________________________________________________________________
150 AliEMCALDigit::AliEMCALDigit(const AliEMCALDigit & digit)
151 : AliDigitNew(digit),
152 fAmpFloat(digit.fAmpFloat),
153 fNSamples(digit.fNSamples),
155 fNSamplesHG(digit.fNSamplesHG),
157 fNprimary(digit.fNprimary),
158 fNMaxPrimary(digit.fNMaxPrimary),
161 fNiparent(digit.fNiparent),
162 fNMaxiparent(digit.fNMaxiparent),
165 fMaxIter(digit.fMaxIter),
167 fTimeR(digit.fTimeR),
170 fDigitType(digit.fDigitType),
171 fAmpCalib(digit.fAmpCalib)
174 // data memebrs of the base class (AliNewDigit)
177 fIndexInList = digit.fIndexInList ;
180 if (fSamples ) delete [] fSamples ; fSamples = NULL ;
181 if (fSamplesHG ) delete [] fSamplesHG ; fSamplesHG = NULL ;
182 if (fPrimary ) delete [] fPrimary ; fPrimary = NULL ;
183 if (fDEPrimary) delete [] fDEPrimary ; fDEPrimary = NULL ;
184 if (fIparent ) delete [] fIparent ; fIparent = NULL ;
185 if (fDEParent) delete [] fDEParent ; fDEParent = NULL ;
188 fSamples = new Int_t[fNSamples];
189 for (Int_t i=0; i < digit.fNSamples; i++) fSamples[i] = digit.fSamples[i];
193 fSamplesHG = new Int_t[fNSamplesHG];
194 for (Int_t i=0; i < digit.fNSamplesHG; i++) fSamplesHG[i] = digit.fSamplesHG[i];
199 fPrimary = new Int_t [fNMaxPrimary] ;
200 fDEPrimary = new Float_t[fNMaxPrimary] ;
201 for ( Int_t i = 0; i < fNMaxPrimary ; i++) {
202 fPrimary[i] = digit.fPrimary[i] ;
203 fDEPrimary[i] = digit.fDEPrimary[i] ;
208 fIparent = new Int_t [fNMaxiparent] ;
209 fDEParent = new Float_t[fNMaxiparent] ;
210 for (Int_t j = 0; j< fNMaxiparent ; j++) {
211 fIparent[j] = digit.fIparent[j] ;
212 fDEParent[j] = digit.fDEParent[j] ;
218 //____________________________________________________________________________
219 AliEMCALDigit::~AliEMCALDigit()
221 // Delete array of primaries if any
223 if (fSamples ) delete [] fSamples ; fSamples = NULL ;
224 if (fSamplesHG ) delete [] fSamplesHG ; fSamplesHG = NULL ;
225 if (fPrimary ) delete [] fPrimary ; fPrimary = NULL ;
226 if (fDEPrimary) delete [] fDEPrimary ; fDEPrimary = NULL ;
227 if (fIparent ) delete [] fIparent ; fIparent = NULL ;
228 if (fDEParent) delete [] fDEParent ; fDEParent = NULL ;
233 //____________________________________________________________________________
234 void AliEMCALDigit::Clear(const Option_t*)
236 // Delete array of primaries if any
237 if (fSamples ) delete [] fSamples ; fSamples = NULL ;
238 if (fSamplesHG ) delete [] fSamplesHG ; fSamplesHG = NULL ;
239 if (fPrimary ) delete [] fPrimary ; fPrimary = NULL ;
240 if (fDEPrimary) delete [] fDEPrimary ; fDEPrimary = NULL ;
241 if (fIparent ) delete [] fIparent ; fIparent = NULL ;
242 if (fDEParent) delete [] fDEParent ; fDEParent = NULL ;
246 //____________________________________________________________________________
247 Int_t AliEMCALDigit::Compare(const TObject * obj) const
249 // Compares two digits with respect to its Id
250 // to sort according increasing Id
254 AliEMCALDigit * digit = (AliEMCALDigit *)obj ;
256 Int_t iddiff = fId - digit->GetId() ;
260 else if ( iddiff < 0 )
269 //____________________________________________________________________________
270 Float_t AliEMCALDigit::GetEta() const
272 //return pseudorapidity for this digit
273 // should be change in EMCALGeometry - 19-nov-04
274 Float_t eta=-10., phi=-10.;
276 const AliEMCALGeometry *g = AliEMCALGeometry::GetInstance();
277 g->EtaPhiFromIndex(id,eta,phi);
281 //____________________________________________________________________________
282 Float_t AliEMCALDigit::GetPhi() const
284 //return phi coordinate of digit
285 // should be change in EMCALGeometry - 19-nov-04
286 Float_t eta=-10., phi=-10.;
288 const AliEMCALGeometry *g = AliEMCALGeometry::GetInstance();
289 g->EtaPhiFromIndex(id,eta,phi);
293 //____________________________________________________________________________
294 Bool_t AliEMCALDigit::GetFALTROSample(const Int_t iSample, Int_t& timeBin, Int_t& amp) const
296 //Get FALTRO sample in time bin iSample
297 if (iSample >= fNSamples || iSample < 0 || fDigitType==kTrigger) return kFALSE;
299 amp = fSamples[iSample] & 0xFFF;
300 timeBin = (fSamples[iSample] >> 12) & 0xFF;
304 //____________________________________________________________________________
305 Bool_t AliEMCALDigit::GetALTROSampleLG(const Int_t iSample, Int_t& timeBin, Int_t& amp) const
307 //Get Low Gain ALTRO sample in time bin iSample
308 if (iSample >= fNSamples || iSample < 0 || fDigitType==kLG) return kFALSE;
310 amp = fSamples[iSample] & 0xFFF;
311 timeBin = (fSamples[iSample] >> 12) & 0xFF;
316 //____________________________________________________________________________
317 void AliEMCALDigit::SetALTROSamplesLG(const Int_t nSamples, Int_t *samples)
319 //Set array of ALTRO samples, Low Gain or FALTRO
320 fNSamples = nSamples;
321 fSamples = new Int_t[fNSamples];
322 for (Int_t i=0; i < fNSamples; i++) fSamples[i] = samples[i];
325 //____________________________________________________________________________
326 void AliEMCALDigit::SetALTROSamplesHG(const Int_t nSamples, Int_t *samples)
328 //Set array of ALTRO samples, High Gain.
329 fNSamplesHG = nSamples;
330 fSamplesHG = new Int_t[fNSamplesHG];
331 for (Int_t i=0; i < fNSamplesHG; i++) fSamplesHG[i] = samples[i];
335 //____________________________________________________________________________
336 Bool_t AliEMCALDigit::GetALTROSampleHG(const Int_t iSample, Int_t& timeBin, Int_t& amp) const
338 //Get High Gain ALTRO sample in time bin iSample
339 if (iSample >= fNSamplesHG || iSample < 0 || fDigitType==kHG) return kFALSE;
341 amp = fSamplesHG[iSample] & 0xFFF;
342 timeBin = (fSamplesHG[iSample] >> 12) & 0xFF;
348 //____________________________________________________________________________
349 Int_t AliEMCALDigit::GetPrimary(Int_t index) const
351 // retrieves the primary particle number given its index in the list
352 if ( (index <= fNprimary) && (index > 0)){
353 return fPrimary[index-1] ;
359 //____________________________________________________________________________
360 Float_t AliEMCALDigit::GetDEPrimary(Int_t index) const
362 // retrieves the primary particle energy contribution
363 // given its index in the list
364 if ( (index <= fNprimary) && (index > 0)){
365 return fDEPrimary[index-1] ;
372 //____________________________________________________________________________
373 Int_t AliEMCALDigit::GetIparent(Int_t index) const
375 // retrieves the primary particle number given its index in the list
376 if ( index <= fNiparent && index > 0){
377 return fIparent[index-1] ;
384 //____________________________________________________________________________
385 Float_t AliEMCALDigit::GetDEParent(Int_t index) const
387 // retrieves the parent particle energy contribution
388 // given its index in the list
389 if ( (index <= fNiparent) && (index > 0)){
390 return fDEParent[index-1] ;
396 //____________________________________________________________________________
397 void AliEMCALDigit::ShiftPrimary(Int_t shift){
398 //shifts primary number to BIG offset, to separate primary in different TreeK
400 for(index = 0; index <fNprimary; index++ ){
401 fPrimary[index] = fPrimary[index]+ shift * 10000000 ;}
402 for(index =0; index <fNiparent; index++){
403 fIparent[index] = fIparent[index] + shift * 10000000 ;}
407 //____________________________________________________________________________
408 AliEMCALDigit& AliEMCALDigit::operator= (const AliEMCALDigit &digit)
410 // assignment operator
412 if(&digit == this) return *this;
414 fAmpFloat = digit.fAmpFloat;
415 fNSamples = digit.fNSamples;
416 fNSamplesHG = digit.fNSamplesHG;
417 fNprimary = digit.fNprimary;
418 fNMaxPrimary = digit.fNMaxPrimary;
419 fNiparent = digit.fNiparent;
420 fNMaxiparent = digit.fNMaxiparent;
421 fMaxIter = digit.fMaxIter;
423 fTimeR = digit.fTimeR;
426 fDigitType = digit.fDigitType;
427 fAmpCalib = digit.fAmpCalib;
430 fIndexInList = digit.fIndexInList ;
433 if (fSamples ) delete [] fSamples ; fSamples = NULL ;
434 if (fSamplesHG ) delete [] fSamplesHG ; fSamplesHG = NULL ;
435 if (fPrimary ) delete [] fPrimary ; fPrimary = NULL ;
436 if (fDEPrimary) delete [] fDEPrimary ; fDEPrimary = NULL ;
437 if (fIparent ) delete [] fIparent ; fIparent = NULL ;
438 if (fDEParent) delete [] fDEParent ; fDEParent = NULL ;
441 fSamples = new Int_t[fNSamples];
442 for (Int_t i=0; i < digit.fNSamples; i++) fSamples[i] = digit.fSamples[i];
446 fSamplesHG = new Int_t[fNSamplesHG];
447 for (Int_t i=0; i < digit.fNSamplesHG; i++) fSamplesHG[i] = digit.fSamplesHG[i];
452 fPrimary = new Int_t [fNMaxPrimary] ;
453 fDEPrimary = new Float_t[fNMaxPrimary] ;
454 for ( Int_t i = 0; i < fNMaxPrimary ; i++) {
455 fPrimary[i] = digit.fPrimary[i] ;
456 fDEPrimary[i] = digit.fDEPrimary[i] ;
461 fIparent = new Int_t [fNMaxiparent] ;
462 fDEParent = new Float_t[fNMaxiparent] ;
463 for (Int_t j = 0; j< fNMaxiparent ; j++) {
464 fIparent[j] = digit.fIparent[j] ;
465 fDEParent[j] = digit.fDEParent[j] ;
473 //____________________________________________________________________________
474 Bool_t AliEMCALDigit::operator==(AliEMCALDigit const & digit) const
476 // Two digits are equal if they have the same Id
478 if ( fId == digit.fId )
484 //____________________________________________________________________________
485 AliEMCALDigit AliEMCALDigit::operator+(const AliEMCALDigit &digit)
487 // Adds the amplitude of digits and completes the list of primary particles
488 // if amplitude is larger than
490 fAmpFloat += digit.fAmpFloat ;
491 for (Int_t i=0; i < fNSamples ; i++) fSamples[i] += digit.fSamples[i];
492 for (Int_t i=0; i < fNSamplesHG; i++) fSamplesHG[i] += digit.fSamplesHG[i];
495 if(fTime > digit.fTime)
496 fTime = digit.fTime ;
497 if (digit.fTimeR < fTimeR)
498 fTimeR = digit.fTimeR ;
500 Int_t max1 = fNprimary ;
501 Int_t max2 = fNiparent ;
503 for (index = 0 ; index < digit.fNprimary ; index++){
504 Bool_t newPrim = kTRUE ;
506 for ( old = 0 ; (old < max1) && newPrim; old++) { //already have this primary?
507 if(fPrimary[old] == digit.fPrimary[index]) {
509 fDEPrimary[old] += digit.fDEPrimary[index];
513 if(max1<fNMaxPrimary){
514 fPrimary[max1] = digit.fPrimary[index] ;
515 fDEPrimary[max1] = digit.fDEPrimary[index] ;
519 if(fNprimary==fNMaxPrimary) {
521 TString mess = " NMaxPrimary = " ;
522 mess += fNMaxPrimary ;
523 mess += " is too small" ;
524 AliFatal(mess.Data()) ;
530 for (index = 0 ; index < digit.fNiparent ; index++){
531 Bool_t newParent = kTRUE ;
533 for ( old = 0 ; (old < max2) && newParent; old++) { //already have this primary?
534 if(fIparent[old] == digit.fIparent[index]) {
536 fDEParent[old] += digit.fDEParent[index];
540 if(max2<fNMaxiparent) {
541 fIparent[max2] = digit.fIparent[index] ;
542 fDEParent[max2] = digit.fDEParent[index] ;
546 if(fNiparent==fNMaxiparent) {
548 TString mess = " NMaxiparent = " ;
549 mess += fNMaxiparent ;
550 mess += " is too small" ;
551 AliFatal(mess.Data()) ;
560 //____________________________________________________________________________
561 AliEMCALDigit AliEMCALDigit::operator*(Float_t factor)
563 // Multiplies the amplitude by a factor
565 //Float_t tempo = static_cast<Float_t>(fAmp) ;
567 //fAmp = static_cast<Int_t>(TMath::Floor(tempo)) ;
570 for (Int_t i=0; i < fNSamples ; i++) fSamples[i] = Int_t(factor*fSamples[i]);
571 for (Int_t i=0; i < fNSamplesHG; i++) fSamplesHG[i] = Int_t(factor*fSamplesHG[i]);
573 for(Int_t i=0; i < fNprimary; i++)
574 fDEPrimary[i] *= factor;
575 for(Int_t i=0; i < fNiparent; i++)
576 fDEParent[i] *= factor;
581 //____________________________________________________________________________
582 ostream& operator << ( ostream& out , const AliEMCALDigit & digit)
584 // Prints the data of the digit
586 out << "ID " << digit.fId << " Energy = " << digit.fAmp << " Time = " << digit.fTime << endl ;
587 for(Int_t i=0;i<digit.fNprimary;i++)
588 out << "Primary " << i+1 << " = " << digit.fPrimary[i]
589 << " : DE " << digit.fDEPrimary[i] << endl ;
591 for(Int_t j=0;j<digit.fNiparent;j++)
592 out << "Iparent " << j+1 << " = " << digit.fIparent[j]
593 << " : DE " << digit.fDEParent[j] << endl ;
594 out << "Position in list = " << digit.fIndexInList << endl ;
598 //____________________________________________________________________________
599 void AliEMCALDigit::Print(const Option_t* /*opt*/) const
602 printf("===\nDigit id: %4d / Energy %2.3f ; Time %e ; Time samples %d ; Chi2 %2.3f, NDF %d, Type? %d \n",
603 fId, fAmpFloat,fTime, fNSamples, fChi2, fNDF, fDigitType);
604 if(fDigitType==kTrigger){
606 for (Int_t i=0; i < GetNFALTROSamples(); i++)
609 GetFALTROSample(i, timeBin, amp);
610 printf(" (%d,%d) ",timeBin,amp);
615 printf("ALTRO, Low Gain: ");
616 for (Int_t i=0; i < GetNALTROSamplesLG(); i++)
619 GetALTROSampleLG(i, timeBin, amp);
620 printf(" (%d,%d) ",timeBin,amp);
623 printf("ALTRO, High Gain: ");
624 for (Int_t i=0; i < GetNALTROSamplesHG(); i++)
627 GetALTROSampleHG(i, timeBin, amp);
628 printf(" (%d,%d) ",timeBin,amp);