- // add the noise now
- energy += TMath::Abs(gRandom->Gaus(0., fPinNoise)) ;
- // JLK 26-June-2008
- //Now digitize the energy according to the sDigitizer method,
- //which merely converts the energy to an integer. Later we will
- //check that the stored value matches our allowed dynamic ranges
- digit->SetAmp(sDigitizer->Digitize(energy)) ;
- AliDebug(10,Form(" absID %5i energy %f nextSig %5i\n",
- absID, energy, nextSig));
- } // for(absID = 0; absID < nEMC; absID++)
-
- //ticks->Delete() ;
- //delete ticks ;
-
- //JLK is it better to call Clear() here?
- delete sdigArray ; //We should not delete its contents
-
- //remove digits below thresholds
- for(i = 0 ; i < nEMC ; i++){
- digit = dynamic_cast<AliEMCALDigit*>( digits->At(i) ) ;
- Float_t threshold = fDigitThreshold ; //this is in GeV
- //need to calibrate digit amplitude to energy in GeV for comparison
- if(sDigitizer->Calibrate( digit->GetAmp() ) < threshold)
- digits->RemoveAt(i) ;
- else
- digit->SetTime(gRandom->Gaus(digit->GetTime(),fTimeResolution) ) ;
- }
-
- digits->Compress() ;
-
- Int_t ndigits = digits->GetEntriesFast() ;
-
- //JLK 26-June-2008
- //After we have done the summing and digitizing to create the
- //digits, now we want to calibrate the resulting amplitude to match
- //the dynamic range of our real data.
- Float_t energy=0;
- for (i = 0 ; i < ndigits ; i++) {
- digit = dynamic_cast<AliEMCALDigit *>( digits->At(i) ) ;
- digit->SetIndexInList(i) ;
- energy = sDigitizer->Calibrate(digit->GetAmp()) ;
- digit->SetAmp(DigitizeEnergy(energy, digit->GetId()) ) ;
+
+ //Find the first tower with signal
+ Int_t nextSig = nEMC + 1 ;
+ TClonesArray * sdigits ;
+ for(i = 0 ; i < fInput ; i++){
+
+ sdigits = dynamic_cast<TClonesArray *>(sdigArray->At(i)) ;
+ if(sdigits){
+ if (sdigits->GetEntriesFast() ){
+ AliEMCALDigit *sd = dynamic_cast<AliEMCALDigit *>(sdigits->At(0));
+ if(sd){
+ Int_t curNext = sd->GetId() ;
+ if(curNext < nextSig)
+ nextSig = curNext ;
+ AliDebug(1,Form("input %i : #sdigits %i \n",
+ i, sdigits->GetEntriesFast()));
+
+ }//First entry is not NULL
+ else {
+ Info("Digitize", "NULL sdigit pointer");
+ continue;
+ }
+ }//There is at least one entry
+ else {
+ Info("Digitize", "NULL sdigits array");
+ continue;
+ }
+ }// SDigits array exists
+ else {
+ Info("Digitizer","Null sdigit pointer");
+ continue;
+ }
+ }// input loop
+ AliDebug(1,Form("FIRST tower with signal %i \n", nextSig));
+
+ TArrayI index(fInput) ;
+ index.Reset() ; //Set all indexes to zero
+
+ AliEMCALDigit * digit ;
+ AliEMCALDigit * curSDigit ;
+
+ // TClonesArray * ticks = new TClonesArray("AliEMCALTick",1000) ;
+
+ //Put Noise contribution
+ for(absID = 0; absID < nEMC; absID++){ // Nov 30, 2006 by PAI; was from 1 to nEMC
+ Float_t energy = 0 ;
+ // amplitude set to zero, noise will be added later
+ new((*digits)[absID]) AliEMCALDigit( -1, -1, absID, 0., TimeOfNoise(),kFALSE); // absID-1->absID
+ //look if we have to add signal?
+
+ digit = dynamic_cast<AliEMCALDigit *>(digits->At(absID)); // absID-1->absID
+
+ if (digit) {
+
+ if(absID==nextSig){
+ //Add SDigits from all inputs
+ // ticks->Clear() ;
+ //Int_t contrib = 0 ;
+
+ //Follow PHOS and comment out this timing model til a better one
+ //can be developed - JLK 28-Apr-2008
+
+ //Float_t a = digit->GetAmplitude() ;
+ //Float_t b = TMath::Abs( a /fTimeSignalLength) ;
+ //Mark the beginning of the signal
+ //new((*ticks)[contrib++]) AliEMCALTick(digit->GetTime(),0, b);
+ //Mark the end of the signal
+ //new((*ticks)[contrib++]) AliEMCALTick(digit->GetTime()+fTimeSignalLength, -a, -b);
+
+ // Calculate time as time of the largest digit
+ Float_t time = digit->GetTime() ;
+ Float_t aTime= digit->GetAmplitude() ;
+
+ // loop over input
+ for(i = 0; i< fInput ; 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(fManager)
+ primaryoffset = fManager->GetMask(i) ;
+ else
+ primaryoffset = i ;
+ curSDigit->ShiftPrimary(primaryoffset) ;
+
+ //Remove old timing model - JLK 28-April-2008
+ //a = curSDigit->GetAmplitude() ;
+ //b = a /fTimeSignalLength ;
+ //new((*ticks)[contrib++]) AliEMCALTick(curSDigit->GetTime(),0, b);
+ //new((*ticks)[contrib++]) AliEMCALTick(curSDigit->GetTime()+fTimeSignalLength, -a, -b);
+ 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
+ energy = sDigitizer->Calibrate(digit->GetAmplitude()) ; // GeV
+ // add fluctuations for photo-electron creation
+ energy *= static_cast<Float_t>(gRandom->Poisson(fMeanPhotonElectron)) / static_cast<Float_t>(fMeanPhotonElectron) ;
+
+ //calculate and set time
+ //New timing model needed - JLK 28-April-2008
+ //Float_t time = FrontEdgeTime(ticks) ;
+ digit->SetTime(time) ;
+
+ //Find next signal module
+ nextSig = nEMC + 1 ;
+ for(i = 0 ; i < fInput ; i++){
+ sdigits = dynamic_cast<TClonesArray *>(sdigArray->At(i)) ;
+ if(sdigits){
+ Int_t curNext = nextSig ;
+ AliEMCALDigit * tmpdigit = dynamic_cast<AliEMCALDigit *>(sdigits->At(index[i]));
+ if(sdigits->GetEntriesFast() > index[i] && tmpdigit){
+ curNext = tmpdigit->GetId() ;
+ }
+ if(curNext < nextSig) nextSig = curNext ;
+ }// sdigits exist
+ } // input loop
+
+ }//absID==nextSig
+
+ // add the noise now
+ energy += TMath::Abs(gRandom->Gaus(0., fPinNoise)) ;
+ // JLK 26-June-2008
+ //Now digitize the energy according to the sDigitizer method,
+ //which merely converts the energy to an integer. Later we will
+ //check that the stored value matches our allowed dynamic ranges
+ digit->SetAmplitude(sDigitizer->Digitize(energy)) ;
+ AliDebug(10,Form(" absID %5i energy %f nextSig %5i\n",
+ absID, energy, nextSig));
+ }// Digit pointer exists
+ else{
+ Info("Digitizer","Digit pointer is null");
+ }
+ } // for(absID = 0; absID < nEMC; absID++)
+
+ //ticks->Delete() ;
+ //delete ticks ;
+
+ //JLK is it better to call Clear() here?
+ delete sdigArray ; //We should not delete its contents
+
+ //remove digits below thresholds
+ // until 10-02-2010 remove digits with energy smaller than fDigitThreshold 3*fPinNoise
+ // now, remove digits with Digitized ADC smaller than fDigitThreshold = 3
+ Float_t energy=0;
+ for(i = 0 ; i < nEMC ; i++){
+ digit = dynamic_cast<AliEMCALDigit*>( digits->At(i) ) ;
+ if(digit){
+ //First get the energy in GeV units.
+ energy = sDigitizer->Calibrate(digit->GetAmplitude()) ;
+ //Then digitize using the calibration constants of the ocdb
+ Float_t ampADC = DigitizeEnergy(energy, digit->GetId()) ;
+ //if(ampADC>2)printf("Digit energy %f, amp %d, amp cal %d, threshold %d\n",energy,digit->GetAmplitude(),ampADC,fDigitThreshold);
+ if(ampADC < fDigitThreshold)
+ digits->RemoveAt(i) ;
+ else
+ digit->SetTime(gRandom->Gaus(digit->GetTime(),fTimeResolution) ) ;
+ }// digit exists
+ } // digit loop
+
+ digits->Compress() ;
+
+ Int_t ndigits = digits->GetEntriesFast() ;
+
+ //JLK 26-June-2008
+ //After we have done the summing and digitizing to create the
+ //digits, now we want to calibrate the resulting amplitude to match
+ //the dynamic range of our real data.
+ for (i = 0 ; i < ndigits ; i++) {
+ digit = dynamic_cast<AliEMCALDigit *>( digits->At(i) ) ;
+ if(digit){
+ digit->SetIndexInList(i) ;
+ energy = sDigitizer->Calibrate(digit->GetAmplitude()) ;
+ digit->SetAmplitude(DigitizeEnergy(energy, digit->GetId()) ) ;
+ //Add delay to time
+ digit->SetTime(digit->GetTime()+fTimeDelay) ;
+ // printf("digit amplitude set at end: i %d, amp %f\n",i,digit->GetAmplitude());
+ }// digit exists
+ }//Digit loop
+
+ }//SDigitizer not null