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"
43 ClassImp(AliEMCALDigit)
45 //____________________________________________________________________________
46 AliEMCALDigit::AliEMCALDigit() :
71 // Need to initialise for reading old files
72 fPrimary = new Int_t[fNMaxPrimary] ;
73 fDEPrimary = new Float_t[fNMaxPrimary] ;
74 fIparent = new Int_t[fNMaxiparent] ;
75 fDEParent = new Float_t[fNMaxiparent] ;
76 for ( Int_t i = 0; i < fNMaxPrimary ; i++) {
81 for ( Int_t i = 0; i < fNMaxiparent ; i++) {
87 //____________________________________________________________________________
88 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)
111 // ctor with all data
113 // data memebrs of the base class (AliNewDigit)
116 fIndexInList = index ;
119 fPrimary = new Int_t[fNMaxPrimary] ;
120 fDEPrimary = new Float_t[fNMaxPrimary] ;
121 fIparent = new Int_t[fNMaxiparent] ;
122 fDEParent = new Float_t[fNMaxiparent] ;
125 fPrimary[0] = primary ;
128 fIparent[0] = iparent ;
131 else{ //If the contribution of this primary smaller than fDigitThreshold (AliEMCALv1)
140 for ( i = 1; i < fNMaxPrimary ; i++) {
145 for ( i = 1; i< fNMaxiparent ; i++) {
151 //____________________________________________________________________________
152 AliEMCALDigit::AliEMCALDigit(const AliEMCALDigit & digit)
153 : AliDigitNew(digit),
154 fAmpFloat(digit.fAmpFloat),
155 fNSamples(digit.fNSamples),
157 fNSamplesHG(digit.fNSamplesHG),
159 fNprimary(digit.fNprimary),
160 fNMaxPrimary(digit.fNMaxPrimary),
163 fNiparent(digit.fNiparent),
164 fNMaxiparent(digit.fNMaxiparent),
167 fMaxIter(digit.fMaxIter),
169 fTimeR(digit.fTimeR),
172 fDigitType(digit.fDigitType),
173 fAmpCalib(digit.fAmpCalib)
176 // data memebrs of the base class (AliNewDigit)
179 fIndexInList = digit.fIndexInList ;
182 if (fSamples ) delete [] fSamples ; fSamples = NULL ;
183 if (fSamplesHG ) delete [] fSamplesHG ; fSamplesHG = NULL ;
184 if (fPrimary ) delete [] fPrimary ; fPrimary = NULL ;
185 if (fDEPrimary) delete [] fDEPrimary ; fDEPrimary = NULL ;
186 if (fIparent ) delete [] fIparent ; fIparent = NULL ;
187 if (fDEParent) delete [] fDEParent ; fDEParent = NULL ;
190 fSamples = new Int_t[fNSamples];
191 for (Int_t i=0; i < digit.fNSamples; i++) fSamples[i] = digit.fSamples[i];
195 fSamplesHG = new Int_t[fNSamplesHG];
196 for (Int_t i=0; i < digit.fNSamplesHG; i++) fSamplesHG[i] = digit.fSamplesHG[i];
201 fPrimary = new Int_t [fNMaxPrimary] ;
202 fDEPrimary = new Float_t[fNMaxPrimary] ;
203 for ( Int_t i = 0; i < fNMaxPrimary ; i++) {
204 fPrimary[i] = digit.fPrimary[i] ;
205 fDEPrimary[i] = digit.fDEPrimary[i] ;
210 fIparent = new Int_t [fNMaxiparent] ;
211 fDEParent = new Float_t[fNMaxiparent] ;
212 for (Int_t j = 0; j< fNMaxiparent ; j++) {
213 fIparent[j] = digit.fIparent[j] ;
214 fDEParent[j] = digit.fDEParent[j] ;
220 //____________________________________________________________________________
221 AliEMCALDigit::~AliEMCALDigit()
223 // Delete array of primaries if any
225 if (fSamples ) delete [] fSamples ; fSamples = NULL ;
226 if (fSamplesHG ) delete [] fSamplesHG ; fSamplesHG = NULL ;
227 if (fPrimary ) delete [] fPrimary ; fPrimary = NULL ;
228 if (fDEPrimary) delete [] fDEPrimary ; fDEPrimary = NULL ;
229 if (fIparent ) delete [] fIparent ; fIparent = NULL ;
230 if (fDEParent) delete [] fDEParent ; fDEParent = NULL ;
235 //____________________________________________________________________________
236 void AliEMCALDigit::Clear(const Option_t*)
238 // Delete array of primaries if any
239 if (fSamples ) delete [] fSamples ; fSamples = NULL ;
240 if (fSamplesHG ) delete [] fSamplesHG ; fSamplesHG = NULL ;
241 if (fPrimary ) delete [] fPrimary ; fPrimary = NULL ;
242 if (fDEPrimary) delete [] fDEPrimary ; fDEPrimary = NULL ;
243 if (fIparent ) delete [] fIparent ; fIparent = NULL ;
244 if (fDEParent) delete [] fDEParent ; fDEParent = NULL ;
248 //____________________________________________________________________________
249 Int_t AliEMCALDigit::Compare(const TObject * obj) const
251 // Compares two digits with respect to its Id
252 // to sort according increasing Id
256 AliEMCALDigit * digit = (AliEMCALDigit *)obj ;
258 Int_t iddiff = fId - digit->GetId() ;
262 else if ( iddiff < 0 )
271 //____________________________________________________________________________
272 Float_t AliEMCALDigit::GetEta() const
274 //return pseudorapidity for this digit
275 // should be change in EMCALGeometry - 19-nov-04
276 Float_t eta=-10., phi=-10.;
278 const AliEMCALGeometry *g = AliEMCALGeometry::GetInstance();
279 g->EtaPhiFromIndex(id,eta,phi);
283 //____________________________________________________________________________
284 Float_t AliEMCALDigit::GetPhi() const
286 //return phi coordinate of digit
287 // should be change in EMCALGeometry - 19-nov-04
288 Float_t eta=-10., phi=-10.;
290 const AliEMCALGeometry *g = AliEMCALGeometry::GetInstance();
291 g->EtaPhiFromIndex(id,eta,phi);
295 //____________________________________________________________________________
296 Bool_t AliEMCALDigit::GetFALTROSample(const Int_t iSample, Int_t& timeBin, Int_t& amp) const
298 //Get FALTRO sample in time bin iSample
299 if (iSample >= fNSamples || iSample < 0 || fDigitType==kTrigger) return kFALSE;
301 amp = fSamples[iSample] & 0xFFF;
302 timeBin = (fSamples[iSample] >> 12) & 0xFF;
306 //____________________________________________________________________________
307 Bool_t AliEMCALDigit::GetALTROSampleLG(const Int_t iSample, Int_t& timeBin, Int_t& amp) const
309 //Get Low Gain ALTRO sample in time bin iSample
310 if (iSample >= fNSamples || iSample < 0 || fDigitType==kLG) return kFALSE;
312 amp = fSamples[iSample] & 0xFFF;
313 timeBin = (fSamples[iSample] >> 12) & 0xFF;
318 //____________________________________________________________________________
319 void AliEMCALDigit::SetALTROSamplesLG(const Int_t nSamples, Int_t *samples)
321 //Set array of ALTRO samples, Low Gain or FALTRO
322 fNSamples = nSamples;
323 fSamples = new Int_t[fNSamples];
324 for (Int_t i=0; i < fNSamples; i++) fSamples[i] = samples[i];
327 //____________________________________________________________________________
328 void AliEMCALDigit::SetALTROSamplesHG(const Int_t nSamples, Int_t *samples)
330 //Set array of ALTRO samples, High Gain.
331 fNSamplesHG = nSamples;
332 fSamplesHG = new Int_t[fNSamplesHG];
333 for (Int_t i=0; i < fNSamplesHG; i++) fSamplesHG[i] = samples[i];
337 //____________________________________________________________________________
338 Bool_t AliEMCALDigit::GetALTROSampleHG(const Int_t iSample, Int_t& timeBin, Int_t& amp) const
340 //Get High Gain ALTRO sample in time bin iSample
341 if (iSample >= fNSamplesHG || iSample < 0 || fDigitType==kHG) return kFALSE;
343 amp = fSamplesHG[iSample] & 0xFFF;
344 timeBin = (fSamplesHG[iSample] >> 12) & 0xFF;
350 //____________________________________________________________________________
351 Int_t AliEMCALDigit::GetPrimary(Int_t index) const
353 // retrieves the primary particle number given its index in the list
354 if ( (index <= fNprimary) && (index > 0)){
355 return fPrimary[index-1] ;
361 //____________________________________________________________________________
362 Float_t AliEMCALDigit::GetDEPrimary(Int_t index) const
364 // retrieves the primary particle energy contribution
365 // given its index in the list
366 if ( (index <= fNprimary) && (index > 0)){
367 return fDEPrimary[index-1] ;
374 //____________________________________________________________________________
375 Int_t AliEMCALDigit::GetIparent(Int_t index) const
377 // retrieves the primary particle number given its index in the list
378 if ( index <= fNiparent && index > 0){
379 return fIparent[index-1] ;
386 //____________________________________________________________________________
387 Float_t AliEMCALDigit::GetDEParent(Int_t index) const
389 // retrieves the parent particle energy contribution
390 // given its index in the list
391 if ( (index <= fNiparent) && (index > 0)){
392 return fDEParent[index-1] ;
398 //____________________________________________________________________________
399 void AliEMCALDigit::ShiftPrimary(Int_t shift){
400 //shifts primary number to BIG offset, to separate primary in different TreeK
402 for(index = 0; index <fNprimary; index++ ){
403 fPrimary[index] = fPrimary[index]+ shift * 10000000 ;}
404 for(index =0; index <fNiparent; index++){
405 fIparent[index] = fIparent[index] + shift * 10000000 ;}
409 //____________________________________________________________________________
410 AliEMCALDigit& AliEMCALDigit::operator= (const AliEMCALDigit &digit)
412 // assignment operator
414 if(&digit == this) return *this;
416 fAmpFloat = digit.fAmpFloat;
417 fNSamples = digit.fNSamples;
418 fNSamplesHG = digit.fNSamplesHG;
419 fNprimary = digit.fNprimary;
420 fNMaxPrimary = digit.fNMaxPrimary;
421 fNiparent = digit.fNiparent;
422 fNMaxiparent = digit.fNMaxiparent;
423 fMaxIter = digit.fMaxIter;
425 fTimeR = digit.fTimeR;
428 fDigitType = digit.fDigitType;
429 fAmpCalib = digit.fAmpCalib;
432 fIndexInList = digit.fIndexInList ;
435 if (fSamples ) delete [] fSamples ; fSamples = NULL ;
436 if (fSamplesHG ) delete [] fSamplesHG ; fSamplesHG = NULL ;
437 if (fPrimary ) delete [] fPrimary ; fPrimary = NULL ;
438 if (fDEPrimary) delete [] fDEPrimary ; fDEPrimary = NULL ;
439 if (fIparent ) delete [] fIparent ; fIparent = NULL ;
440 if (fDEParent) delete [] fDEParent ; fDEParent = NULL ;
443 fSamples = new Int_t[fNSamples];
444 for (Int_t i=0; i < digit.fNSamples; i++) fSamples[i] = digit.fSamples[i];
448 fSamplesHG = new Int_t[fNSamplesHG];
449 for (Int_t i=0; i < digit.fNSamplesHG; i++) fSamplesHG[i] = digit.fSamplesHG[i];
454 fPrimary = new Int_t [fNMaxPrimary] ;
455 fDEPrimary = new Float_t[fNMaxPrimary] ;
456 for ( Int_t i = 0; i < fNMaxPrimary ; i++) {
457 fPrimary[i] = digit.fPrimary[i] ;
458 fDEPrimary[i] = digit.fDEPrimary[i] ;
463 fIparent = new Int_t [fNMaxiparent] ;
464 fDEParent = new Float_t[fNMaxiparent] ;
465 for (Int_t j = 0; j< fNMaxiparent ; j++) {
466 fIparent[j] = digit.fIparent[j] ;
467 fDEParent[j] = digit.fDEParent[j] ;
475 //____________________________________________________________________________
476 Bool_t AliEMCALDigit::operator==(AliEMCALDigit const & digit) const
478 // Two digits are equal if they have the same Id
480 if ( fId == digit.fId )
486 //____________________________________________________________________________
487 AliEMCALDigit AliEMCALDigit::operator+(const AliEMCALDigit &digit)
489 // Adds the amplitude of digits and completes the list of primary particles
490 // if amplitude is larger than
492 fAmpFloat += digit.fAmpFloat ;
493 for (Int_t i=0; i < fNSamples ; i++) fSamples[i] += digit.fSamples[i];
494 for (Int_t i=0; i < fNSamplesHG; i++) fSamplesHG[i] += digit.fSamplesHG[i];
497 if(fTime > digit.fTime)
498 fTime = digit.fTime ;
499 if (digit.fTimeR < fTimeR)
500 fTimeR = digit.fTimeR ;
502 Int_t max1 = fNprimary ;
503 Int_t max2 = fNiparent ;
505 for (index = 0 ; index < digit.fNprimary ; index++){
506 Bool_t newPrim = kTRUE ;
508 for ( old = 0 ; (old < max1) && newPrim; old++) { //already have this primary?
509 if(fPrimary[old] == digit.fPrimary[index]) {
511 fDEPrimary[old] += digit.fDEPrimary[index];
515 if(max1<fNMaxPrimary){
516 fPrimary[max1] = digit.fPrimary[index] ;
517 fDEPrimary[max1] = digit.fDEPrimary[index] ;
521 if(fNprimary==fNMaxPrimary) {
523 TString mess = " NMaxPrimary = " ;
524 mess += fNMaxPrimary ;
525 mess += " is too small" ;
526 AliFatal(mess.Data()) ;
532 for (index = 0 ; index < digit.fNiparent ; index++){
533 Bool_t newParent = kTRUE ;
535 for ( old = 0 ; (old < max2) && newParent; old++) { //already have this primary?
536 if(fIparent[old] == digit.fIparent[index]) {
538 fDEParent[old] += digit.fDEParent[index];
542 if(max2<fNMaxiparent) {
543 fIparent[max2] = digit.fIparent[index] ;
544 fDEParent[max2] = digit.fDEParent[index] ;
548 if(fNiparent==fNMaxiparent) {
550 TString mess = " NMaxiparent = " ;
551 mess += fNMaxiparent ;
552 mess += " is too small" ;
553 AliFatal(mess.Data()) ;
562 //____________________________________________________________________________
563 AliEMCALDigit AliEMCALDigit::operator*(Float_t factor)
565 // Multiplies the amplitude by a factor
567 //Float_t tempo = static_cast<Float_t>(fAmp) ;
569 //fAmp = static_cast<Int_t>(TMath::Floor(tempo)) ;
572 for (Int_t i=0; i < fNSamples ; i++) fSamples[i] = Int_t(factor*fSamples[i]);
573 for (Int_t i=0; i < fNSamplesHG; i++) fSamplesHG[i] = Int_t(factor*fSamplesHG[i]);
575 for(Int_t i=0; i < fNprimary; i++)
576 fDEPrimary[i] *= factor;
577 for(Int_t i=0; i < fNiparent; i++)
578 fDEParent[i] *= factor;
583 //____________________________________________________________________________
584 ostream& operator << ( ostream& out , const AliEMCALDigit & digit)
586 // Prints the data of the digit
588 out << "ID " << digit.fId << " Energy = " << digit.fAmp << " Time = " << digit.fTime << endl ;
589 for(Int_t i=0;i<digit.fNprimary;i++)
590 out << "Primary " << i+1 << " = " << digit.fPrimary[i]
591 << " : DE " << digit.fDEPrimary[i] << endl ;
593 for(Int_t j=0;j<digit.fNiparent;j++)
594 out << "Iparent " << j+1 << " = " << digit.fIparent[j]
595 << " : DE " << digit.fDEParent[j] << endl ;
596 out << "Position in list = " << digit.fIndexInList << endl ;
600 //____________________________________________________________________________
601 void AliEMCALDigit::Print(const Option_t* /*opt*/) const
604 printf("===\nDigit id: %4d / Energy %2.3f ; Time %e ; Time samples %d ; Chi2 %2.3f, NDF %d, Type? %d \n",
605 fId, fAmpFloat,fTime, fNSamples, fChi2, fNDF, fDigitType);
606 if(fDigitType==kTrigger){
608 for (Int_t i=0; i < GetNFALTROSamples(); i++)
611 GetFALTROSample(i, timeBin, amp);
612 printf(" (%d,%d) ",timeBin,amp);
617 printf("ALTRO, Low Gain: ");
618 for (Int_t i=0; i < GetNALTROSamplesLG(); i++)
621 GetALTROSampleLG(i, timeBin, amp);
622 printf(" (%d,%d) ",timeBin,amp);
625 printf("ALTRO, High Gain: ");
626 for (Int_t i=0; i < GetNALTROSamplesHG(); i++)
629 GetALTROSampleHG(i, timeBin, amp);
630 printf(" (%d,%d) ",timeBin,amp);