+ // Calculate time as time of the largest digit
+ Float_t time = digit->GetTime() ;
+ Float_t aTime= digit->GetAmplitude() ;
+
+ // loop over input
+ Int_t nInputs = fInput;
+ if(embed) nInputs = 1; // In case of embedding, merge later real digits, do not smear energy and time of data
+ for(i = 0; i< nInputs ; i++){ //loop over (possible) merge sources
+ TClonesArray* sdtclarr = dynamic_cast<TClonesArray *>(sdigArray->At(i));
+ if(sdtclarr) {
+ Int_t sDigitEntries = sdtclarr->GetEntriesFast();
+
+ if(sDigitEntries > index[i] )
+ curSDigit = dynamic_cast<AliEMCALDigit*>(sdtclarr->At(index[i])) ;
+ else
+ curSDigit = 0 ;
+
+ //May be several digits will contribute from the same input
+ while(curSDigit && (curSDigit->GetId() == absID)){
+ //Shift primary to separate primaries belonging different inputs
+ Int_t primaryoffset ;
+ if(fDigInput)
+ primaryoffset = fDigInput->GetMask(i) ;
+ else
+ primaryoffset = i ;
+ curSDigit->ShiftPrimary(primaryoffset) ;
+
+ if(curSDigit->GetAmplitude()>aTime) {
+ aTime = curSDigit->GetAmplitude();
+ time = curSDigit->GetTime();
+ }
+
+ *digit = *digit + *curSDigit ; //adds amplitudes of each digit
+
+ index[i]++ ;
+
+ if( sDigitEntries > index[i] )
+ curSDigit = dynamic_cast<AliEMCALDigit*>(sdtclarr->At(index[i])) ;
+ else
+ curSDigit = 0 ;
+ }// while
+ }// source exists
+ }// loop over merging sources
+
+
+ //Here we convert the summed amplitude to an energy in GeV only for simulation or mixing of simulations
+ energy = fSDigitizer->Calibrate(digit->GetAmplitude()) ; // GeV
+
+ // add fluctuations for photo-electron creation
+ // corrected fluctuations after comparison with beam test, Paraskevi Ganoti (06/11/2011)
+ Float_t fluct = static_cast<Float_t>((energy*fMeanPhotonElectron)/fGainFluctuations);
+ energy *= static_cast<Float_t>(gRandom->Poisson(fluct)) / fluct ;
+
+ //calculate and set time
+ digit->SetTime(time) ;
+
+ //Find next signal module
+ nextSig = nEMC + 1 ;
+ for(i = 0 ; i < nInputs ; i++){
+ sdigits = dynamic_cast<TClonesArray *>(sdigArray->At(i)) ;
+
+ if(sdigits){
+ Int_t curNext = nextSig ;
+ if(sdigits->GetEntriesFast() > index[i])
+ {
+ AliEMCALDigit * tmpdigit = dynamic_cast<AliEMCALDigit *>(sdigits->At(index[i]));
+ if(tmpdigit)
+ {
+ curNext = tmpdigit->GetId() ;
+ }
+ }
+ if(curNext < nextSig) nextSig = curNext ;
+ }// sdigits exist
+ } // input loop
+
+ }//absID==nextSig
+
+ // add the noise now, no need for embedded events with real data
+ if(!embed)
+ energy += gRandom->Gaus(0., fPinNoise) ;
+
+
+ // JLK 26-June-2008
+ //Now digitize the energy according to the fSDigitizer method,
+ //which merely converts the energy to an integer. Later we will
+ //check that the stored value matches our allowed dynamic ranges
+ digit->SetAmplitude(fSDigitizer->Digitize(energy)) ;
+
+ //Set time resolution with final energy
+ timeResolution = GetTimeResolution(energy);
+ digit->SetTime(gRandom->Gaus(digit->GetTime(),timeResolution) ) ;
+ AliDebug(10,Form(" absID %5i energy %f nextSig %5i\n",
+ absID, energy, nextSig));
+ //Add delay to time
+ digit->SetTime(digit->GetTime()+fTimeDelay) ;
+
+ }// Digit pointer exists
+ else{
+ Info("Digitizer","Digit pointer is null");