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, Bool_t trigger, Int_t index, Float_t dE)
105 fTriggerDigit(trigger)
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 fTriggerDigit(digit.fTriggerDigit)
172 // data memebrs of the base class (AliNewDigit)
175 fIndexInList = digit.fIndexInList ;
178 fSamples = new Int_t[fNSamples];
179 for (Int_t i=0; i < digit.fNSamples; i++) fSamples[i] = digit.fSamples[i];
180 fSamplesHG = new Int_t[fNSamplesHG];
181 for (Int_t i=0; i < digit.fNSamplesHG; i++) fSamplesHG[i] = digit.fSamplesHG[i];
183 fPrimary = new Int_t[fNMaxPrimary] ;
184 fDEPrimary = new Float_t[fNMaxPrimary] ;
185 fIparent = new Int_t[fNMaxiparent] ;
186 fDEParent = new Float_t[fNMaxiparent] ;
188 for ( i = 0; i < fNMaxPrimary ; i++) {
189 fPrimary[i] = digit.fPrimary[i] ;
190 fDEPrimary[i] = digit.fDEPrimary[i] ;
193 for (j = 0; j< fNMaxiparent ; j++) {
194 fIparent[j] = digit.fIparent[j] ;
195 fDEParent[j] = digit.fDEParent[j] ;
199 //____________________________________________________________________________
200 AliEMCALDigit::~AliEMCALDigit()
202 // Delete array of primiries if any
204 delete [] fDEPrimary ;
206 delete [] fDEParent ;
208 delete [] fSamplesHG;
212 //____________________________________________________________________________
213 Int_t AliEMCALDigit::Compare(const TObject * obj) const
215 // Compares two digits with respect to its Id
216 // to sort according increasing Id
220 AliEMCALDigit * digit = (AliEMCALDigit *)obj ;
222 Int_t iddiff = fId - digit->GetId() ;
226 else if ( iddiff < 0 )
235 //____________________________________________________________________________
236 Float_t AliEMCALDigit::GetEta() const
238 //return pseudorapidity for this digit
239 // should be change in EMCALGeometry - 19-nov-04
240 Float_t eta=-10., phi=-10.;
242 const AliEMCALGeometry *g = AliEMCALGeometry::GetInstance();
243 g->EtaPhiFromIndex(id,eta,phi);
247 //____________________________________________________________________________
248 Float_t AliEMCALDigit::GetPhi() const
250 //return phi coordinate of digit
251 // should be change in EMCALGeometry - 19-nov-04
252 Float_t eta=-10., phi=-10.;
254 const AliEMCALGeometry *g = AliEMCALGeometry::GetInstance();
255 g->EtaPhiFromIndex(id,eta,phi);
259 //____________________________________________________________________________
260 Bool_t AliEMCALDigit::GetFALTROSample(const Int_t iSample, Int_t& timeBin, Int_t& amp) const
262 //Get FALTRO sample in time bin iSample
263 if (iSample >= fNSamples || iSample < 0 || !fTriggerDigit) return kFALSE;
265 amp = fSamples[iSample] & 0xFFF;
266 timeBin = (fSamples[iSample] >> 12) & 0xFF;
270 //____________________________________________________________________________
271 Bool_t AliEMCALDigit::GetALTROSampleLG(const Int_t iSample, Int_t& timeBin, Int_t& amp) const
273 //Get Low Gain ALTRO sample in time bin iSample
274 if (iSample >= fNSamples || iSample < 0 || fTriggerDigit) return kFALSE;
276 amp = fSamples[iSample] & 0xFFF;
277 timeBin = (fSamples[iSample] >> 12) & 0xFF;
282 //____________________________________________________________________________
283 void AliEMCALDigit::SetALTROSamplesLG(const Int_t nSamples, Int_t *samples)
285 //Set array of ALTRO samples, Low Gain or FALTRO
286 fNSamples = nSamples;
287 fSamples = new Int_t[fNSamples];
288 for (Int_t i=0; i < fNSamples; i++) fSamples[i] = samples[i];
291 //____________________________________________________________________________
292 void AliEMCALDigit::SetALTROSamplesHG(const Int_t nSamples, Int_t *samples)
294 //Set array of ALTRO samples, High Gain.
295 fNSamplesHG = nSamples;
296 fSamplesHG = new Int_t[fNSamplesHG];
297 for (Int_t i=0; i < fNSamplesHG; i++) fSamplesHG[i] = samples[i];
301 //____________________________________________________________________________
302 Bool_t AliEMCALDigit::GetALTROSampleHG(const Int_t iSample, Int_t& timeBin, Int_t& amp) const
304 //Get High Gain ALTRO sample in time bin iSample
305 if (iSample >= fNSamplesHG || iSample < 0 || fTriggerDigit) return kFALSE;
307 amp = fSamplesHG[iSample] & 0xFFF;
308 timeBin = (fSamplesHG[iSample] >> 12) & 0xFF;
314 //____________________________________________________________________________
315 Int_t AliEMCALDigit::GetPrimary(Int_t index) const
317 // retrieves the primary particle number given its index in the list
318 if ( (index <= fNprimary) && (index > 0)){
319 return fPrimary[index-1] ;
325 //____________________________________________________________________________
326 Float_t AliEMCALDigit::GetDEPrimary(Int_t index) const
328 // retrieves the primary particle energy contribution
329 // given its index in the list
330 if ( (index <= fNprimary) && (index > 0)){
331 return fDEPrimary[index-1] ;
338 //____________________________________________________________________________
339 Int_t AliEMCALDigit::GetIparent(Int_t index) const
341 // retrieves the primary particle number given its index in the list
342 if ( index <= fNiparent && index > 0){
343 return fIparent[index-1] ;
350 //____________________________________________________________________________
351 Float_t AliEMCALDigit::GetDEParent(Int_t index) const
353 // retrieves the parent particle energy contribution
354 // given its index in the list
355 if ( (index <= fNiparent) && (index > 0)){
356 return fDEParent[index-1] ;
362 //____________________________________________________________________________
363 void AliEMCALDigit::ShiftPrimary(Int_t shift){
364 //shifts primary number to BIG offset, to separate primary in different TreeK
366 for(index = 0; index <fNprimary; index++ ){
367 fPrimary[index] = fPrimary[index]+ shift * 10000000 ;}
368 for(index =0; index <fNiparent; index++){
369 fIparent[index] = fIparent[index] + shift * 10000000 ;}
371 //____________________________________________________________________________
372 Bool_t AliEMCALDigit::operator==(AliEMCALDigit const & digit) const
374 // Two digits are equal if they have the same Id
376 if ( fId == digit.fId )
382 //____________________________________________________________________________
383 AliEMCALDigit AliEMCALDigit::operator+(const AliEMCALDigit &digit)
385 // Adds the amplitude of digits and completes the list of primary particles
386 // if amplitude is larger than
388 fAmpFloat += digit.fAmpFloat ;
389 for (Int_t i=0; i < fNSamples ; i++) fSamples[i] += digit.fSamples[i];
390 for (Int_t i=0; i < fNSamplesHG; i++) fSamplesHG[i] += digit.fSamplesHG[i];
393 if(fTime > digit.fTime)
394 fTime = digit.fTime ;
395 if (digit.fTimeR < fTimeR)
396 fTimeR = digit.fTimeR ;
398 Int_t max1 = fNprimary ;
399 Int_t max2 = fNiparent ;
401 for (index = 0 ; index < digit.fNprimary ; index++){
402 Bool_t newPrim = kTRUE ;
404 for ( old = 0 ; (old < max1) && newPrim; old++) { //already have this primary?
405 if(fPrimary[old] == digit.fPrimary[index]) {
407 fDEPrimary[old] += digit.fDEPrimary[index];
411 if(max1<fNMaxPrimary){
412 fPrimary[max1] = digit.fPrimary[index] ;
413 fDEPrimary[max1] = digit.fDEPrimary[index] ;
417 if(fNprimary==fNMaxPrimary) {
419 TString mess = " NMaxPrimary = " ;
420 mess += fNMaxPrimary ;
421 mess += " is too small" ;
422 Fatal("AliEMCALDigit::Operator+ -->" , mess.Data()) ;
428 for (index = 0 ; index < digit.fNiparent ; index++){
429 Bool_t newParent = kTRUE ;
431 for ( old = 0 ; (old < max2) && newParent; old++) { //already have this primary?
432 if(fIparent[old] == digit.fIparent[index]) {
434 fDEParent[old] += digit.fDEParent[index];
438 if(max2<fNMaxiparent) {
439 fIparent[max2] = digit.fIparent[index] ;
440 fDEParent[max2] = digit.fDEParent[index] ;
444 if(fNiparent==fNMaxiparent) {
446 TString mess = " NMaxiparent = " ;
447 mess += fNMaxiparent ;
448 mess += " is too small" ;
449 Fatal("AliEMCALDigit::Operator+ -->", mess.Data()) ;
458 //____________________________________________________________________________
459 AliEMCALDigit AliEMCALDigit::operator*(Float_t factor)
461 // Multiplies the amplitude by a factor
463 //Float_t tempo = static_cast<Float_t>(fAmp) ;
465 //fAmp = static_cast<Int_t>(TMath::Floor(tempo)) ;
468 for (Int_t i=0; i < fNSamples ; i++) fSamples[i] = Int_t(factor*fSamples[i]);
469 for (Int_t i=0; i < fNSamplesHG; i++) fSamplesHG[i] = Int_t(factor*fSamplesHG[i]);
471 for(Int_t i=0; i < fNprimary; i++)
472 fDEPrimary[i] *= factor;
473 for(Int_t i=0; i < fNiparent; i++)
474 fDEParent[i] *= factor;
479 //____________________________________________________________________________
480 ostream& operator << ( ostream& out , const AliEMCALDigit & digit)
482 // Prints the data of the digit
484 out << "ID " << digit.fId << " Energy = " << digit.fAmp << " Time = " << digit.fTime << endl ;
486 for(i=0;i<digit.fNprimary;i++)
487 out << "Primary " << i+1 << " = " << digit.fPrimary[i]
488 << " : DE " << digit.fDEPrimary[i] << endl ;
490 for(j=0;j<digit.fNiparent;j++)
491 out << "Iparent " << j+1 << " = " << digit.fIparent[j]
492 << " : DE " << digit.fDEParent[j] << endl ;
493 out << "Position in list = " << digit.fIndexInList << endl ;
497 //____________________________________________________________________________
498 void AliEMCALDigit::Print(const Option_t* /*opt*/) const
501 printf("===\nDigit id: %4d / Energy %2.3f ; Time %e ; Time samples %d ; Chi2 %2.3f, NDF %d, Trigger? %d \n",
502 fId, fAmpFloat,fTime, fNSamples, fChi2, fNDF, fTriggerDigit);
505 for (Int_t i=0; i < GetNFALTROSamples(); i++)
508 GetFALTROSample(i, timeBin, amp);
509 printf(" (%d,%d) ",timeBin,amp);
514 printf("ALTRO, Low Gain: ");
515 for (Int_t i=0; i < GetNALTROSamplesLG(); i++)
518 GetALTROSampleLG(i, timeBin, amp);
519 printf(" (%d,%d) ",timeBin,amp);
522 printf("ALTRO, High Gain: ");
523 for (Int_t i=0; i < GetNALTROSamplesHG(); i++)
526 GetALTROSampleHG(i, timeBin, amp);
527 printf(" (%d,%d) ",timeBin,amp);