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)
172 // data memebrs of the base class (AliNewDigit)
175 fIndexInList = digit.fIndexInList ;
179 fSamples = new Int_t[fNSamples];
180 for (Int_t i=0; i < digit.fNSamples; i++) fSamples[i] = digit.fSamples[i];
185 fSamplesHG = new Int_t[fNSamplesHG];
186 for (Int_t i=0; i < digit.fNSamplesHG; i++) fSamplesHG[i] = digit.fSamplesHG[i];
188 else fNSamplesHG = 0;
191 fPrimary = new Int_t [fNMaxPrimary] ;
192 fDEPrimary = new Float_t[fNMaxPrimary] ;
193 for ( Int_t i = 0; i < fNMaxPrimary ; i++) {
194 fPrimary[i] = digit.fPrimary[i] ;
195 fDEPrimary[i] = digit.fDEPrimary[i] ;
204 fIparent = new Int_t [fNMaxiparent] ;
205 fDEParent = new Float_t[fNMaxiparent] ;
206 for (Int_t j = 0; j< fNMaxiparent ; j++) {
207 fIparent[j] = digit.fIparent[j] ;
208 fDEParent[j] = digit.fDEParent[j] ;
217 //____________________________________________________________________________
218 AliEMCALDigit::~AliEMCALDigit()
220 // Delete array of primiries if any
222 delete [] fDEPrimary ;
224 delete [] fDEParent ;
226 delete [] fSamplesHG;
230 //____________________________________________________________________________
231 Int_t AliEMCALDigit::Compare(const TObject * obj) const
233 // Compares two digits with respect to its Id
234 // to sort according increasing Id
238 AliEMCALDigit * digit = (AliEMCALDigit *)obj ;
240 Int_t iddiff = fId - digit->GetId() ;
244 else if ( iddiff < 0 )
253 //____________________________________________________________________________
254 Float_t AliEMCALDigit::GetEta() const
256 //return pseudorapidity for this digit
257 // should be change in EMCALGeometry - 19-nov-04
258 Float_t eta=-10., phi=-10.;
260 const AliEMCALGeometry *g = AliEMCALGeometry::GetInstance();
261 g->EtaPhiFromIndex(id,eta,phi);
265 //____________________________________________________________________________
266 Float_t AliEMCALDigit::GetPhi() const
268 //return phi coordinate of digit
269 // should be change in EMCALGeometry - 19-nov-04
270 Float_t eta=-10., phi=-10.;
272 const AliEMCALGeometry *g = AliEMCALGeometry::GetInstance();
273 g->EtaPhiFromIndex(id,eta,phi);
277 //____________________________________________________________________________
278 Bool_t AliEMCALDigit::GetFALTROSample(const Int_t iSample, Int_t& timeBin, Int_t& amp) const
280 //Get FALTRO sample in time bin iSample
281 if (iSample >= fNSamples || iSample < 0 || fDigitType==kTrigger) return kFALSE;
283 amp = fSamples[iSample] & 0xFFF;
284 timeBin = (fSamples[iSample] >> 12) & 0xFF;
288 //____________________________________________________________________________
289 Bool_t AliEMCALDigit::GetALTROSampleLG(const Int_t iSample, Int_t& timeBin, Int_t& amp) const
291 //Get Low Gain ALTRO sample in time bin iSample
292 if (iSample >= fNSamples || iSample < 0 || fDigitType==kLG) return kFALSE;
294 amp = fSamples[iSample] & 0xFFF;
295 timeBin = (fSamples[iSample] >> 12) & 0xFF;
300 //____________________________________________________________________________
301 void AliEMCALDigit::SetALTROSamplesLG(const Int_t nSamples, Int_t *samples)
303 //Set array of ALTRO samples, Low Gain or FALTRO
304 fNSamples = nSamples;
305 fSamples = new Int_t[fNSamples];
306 for (Int_t i=0; i < fNSamples; i++) fSamples[i] = samples[i];
309 //____________________________________________________________________________
310 void AliEMCALDigit::SetALTROSamplesHG(const Int_t nSamples, Int_t *samples)
312 //Set array of ALTRO samples, High Gain.
313 fNSamplesHG = nSamples;
314 fSamplesHG = new Int_t[fNSamplesHG];
315 for (Int_t i=0; i < fNSamplesHG; i++) fSamplesHG[i] = samples[i];
319 //____________________________________________________________________________
320 Bool_t AliEMCALDigit::GetALTROSampleHG(const Int_t iSample, Int_t& timeBin, Int_t& amp) const
322 //Get High Gain ALTRO sample in time bin iSample
323 if (iSample >= fNSamplesHG || iSample < 0 || fDigitType==kHG) return kFALSE;
325 amp = fSamplesHG[iSample] & 0xFFF;
326 timeBin = (fSamplesHG[iSample] >> 12) & 0xFF;
332 //____________________________________________________________________________
333 Int_t AliEMCALDigit::GetPrimary(Int_t index) const
335 // retrieves the primary particle number given its index in the list
336 if ( (index <= fNprimary) && (index > 0)){
337 return fPrimary[index-1] ;
343 //____________________________________________________________________________
344 Float_t AliEMCALDigit::GetDEPrimary(Int_t index) const
346 // retrieves the primary particle energy contribution
347 // given its index in the list
348 if ( (index <= fNprimary) && (index > 0)){
349 return fDEPrimary[index-1] ;
356 //____________________________________________________________________________
357 Int_t AliEMCALDigit::GetIparent(Int_t index) const
359 // retrieves the primary particle number given its index in the list
360 if ( index <= fNiparent && index > 0){
361 return fIparent[index-1] ;
368 //____________________________________________________________________________
369 Float_t AliEMCALDigit::GetDEParent(Int_t index) const
371 // retrieves the parent particle energy contribution
372 // given its index in the list
373 if ( (index <= fNiparent) && (index > 0)){
374 return fDEParent[index-1] ;
380 //____________________________________________________________________________
381 void AliEMCALDigit::ShiftPrimary(Int_t shift){
382 //shifts primary number to BIG offset, to separate primary in different TreeK
384 for(index = 0; index <fNprimary; index++ ){
385 fPrimary[index] = fPrimary[index]+ shift * 10000000 ;}
386 for(index =0; index <fNiparent; index++){
387 fIparent[index] = fIparent[index] + shift * 10000000 ;}
389 //____________________________________________________________________________
390 Bool_t AliEMCALDigit::operator==(AliEMCALDigit const & digit) const
392 // Two digits are equal if they have the same Id
394 if ( fId == digit.fId )
400 //____________________________________________________________________________
401 AliEMCALDigit AliEMCALDigit::operator+(const AliEMCALDigit &digit)
403 // Adds the amplitude of digits and completes the list of primary particles
404 // if amplitude is larger than
406 fAmpFloat += digit.fAmpFloat ;
407 for (Int_t i=0; i < fNSamples ; i++) fSamples[i] += digit.fSamples[i];
408 for (Int_t i=0; i < fNSamplesHG; i++) fSamplesHG[i] += digit.fSamplesHG[i];
411 if(fTime > digit.fTime)
412 fTime = digit.fTime ;
413 if (digit.fTimeR < fTimeR)
414 fTimeR = digit.fTimeR ;
416 Int_t max1 = fNprimary ;
417 Int_t max2 = fNiparent ;
419 for (index = 0 ; index < digit.fNprimary ; index++){
420 Bool_t newPrim = kTRUE ;
422 for ( old = 0 ; (old < max1) && newPrim; old++) { //already have this primary?
423 if(fPrimary[old] == digit.fPrimary[index]) {
425 fDEPrimary[old] += digit.fDEPrimary[index];
429 if(max1<fNMaxPrimary){
430 fPrimary[max1] = digit.fPrimary[index] ;
431 fDEPrimary[max1] = digit.fDEPrimary[index] ;
435 if(fNprimary==fNMaxPrimary) {
437 TString mess = " NMaxPrimary = " ;
438 mess += fNMaxPrimary ;
439 mess += " is too small" ;
440 Fatal("AliEMCALDigit::Operator+ -->" , mess.Data()) ;
446 for (index = 0 ; index < digit.fNiparent ; index++){
447 Bool_t newParent = kTRUE ;
449 for ( old = 0 ; (old < max2) && newParent; old++) { //already have this primary?
450 if(fIparent[old] == digit.fIparent[index]) {
452 fDEParent[old] += digit.fDEParent[index];
456 if(max2<fNMaxiparent) {
457 fIparent[max2] = digit.fIparent[index] ;
458 fDEParent[max2] = digit.fDEParent[index] ;
462 if(fNiparent==fNMaxiparent) {
464 TString mess = " NMaxiparent = " ;
465 mess += fNMaxiparent ;
466 mess += " is too small" ;
467 Fatal("AliEMCALDigit::Operator+ -->", mess.Data()) ;
476 //____________________________________________________________________________
477 AliEMCALDigit AliEMCALDigit::operator*(Float_t factor)
479 // Multiplies the amplitude by a factor
481 //Float_t tempo = static_cast<Float_t>(fAmp) ;
483 //fAmp = static_cast<Int_t>(TMath::Floor(tempo)) ;
486 for (Int_t i=0; i < fNSamples ; i++) fSamples[i] = Int_t(factor*fSamples[i]);
487 for (Int_t i=0; i < fNSamplesHG; i++) fSamplesHG[i] = Int_t(factor*fSamplesHG[i]);
489 for(Int_t i=0; i < fNprimary; i++)
490 fDEPrimary[i] *= factor;
491 for(Int_t i=0; i < fNiparent; i++)
492 fDEParent[i] *= factor;
497 //____________________________________________________________________________
498 ostream& operator << ( ostream& out , const AliEMCALDigit & digit)
500 // Prints the data of the digit
502 out << "ID " << digit.fId << " Energy = " << digit.fAmp << " Time = " << digit.fTime << endl ;
504 for(i=0;i<digit.fNprimary;i++)
505 out << "Primary " << i+1 << " = " << digit.fPrimary[i]
506 << " : DE " << digit.fDEPrimary[i] << endl ;
508 for(j=0;j<digit.fNiparent;j++)
509 out << "Iparent " << j+1 << " = " << digit.fIparent[j]
510 << " : DE " << digit.fDEParent[j] << endl ;
511 out << "Position in list = " << digit.fIndexInList << endl ;
515 //____________________________________________________________________________
516 void AliEMCALDigit::Print(const Option_t* /*opt*/) const
519 printf("===\nDigit id: %4d / Energy %2.3f ; Time %e ; Time samples %d ; Chi2 %2.3f, NDF %d, Type? %d \n",
520 fId, fAmpFloat,fTime, fNSamples, fChi2, fNDF, fDigitType);
521 if(fDigitType==kTrigger){
523 for (Int_t i=0; i < GetNFALTROSamples(); i++)
526 GetFALTROSample(i, timeBin, amp);
527 printf(" (%d,%d) ",timeBin,amp);
532 printf("ALTRO, Low Gain: ");
533 for (Int_t i=0; i < GetNALTROSamplesLG(); i++)
536 GetALTROSampleLG(i, timeBin, amp);
537 printf(" (%d,%d) ",timeBin,amp);
540 printf("ALTRO, High Gain: ");
541 for (Int_t i=0; i < GetNALTROSamplesHG(); i++)
544 GetALTROSampleHG(i, timeBin, amp);
545 printf(" (%d,%d) ",timeBin,amp);