ROOT logo
// -*- mode: c++ -*-

/**************************************************************************
 * This file is property of and copyright by the Experimental Nuclear     *
 * Physics Group, Dep. of Physics                                         *
 * University of Oslo, Norway, 2007                                       *
 *                                                                        *
 * Author: Per Thomas Hille <perthi@fys.uio.no> for the ALICE HLT Project.*
 * Contributors are mentioned in the code where appropriate.              *
 * Please report bugs to perthi@fys.uio.no                                *
 *                                                                        *
 * Permission to use, copy, modify and distribute this software and its   *
 * documentation strictly for non-commercial purposes is hereby granted   *
 * without fee, provided that the above copyright notice appears in all   *
 * copies and that both the copyright notice and this permission notice   *
 * appear in the supporting documentation. The authors make no claims     *
 * about the suitability of this software for any purpose. It is          *
 * provided "as is" without express or implied warranty.                  *
 **************************************************************************/

#include "TF1.h"
#include "TMath.h"
#include <TRandom.h>

#include "AliEMCALRawResponse.h"
#include "AliCaloConstants.h"

using namespace CALO;
using namespace EMCAL;
using namespace ALTRO;

Double_t AliEMCALRawResponse::fgTimeTrigger  = 600E-9 ;   // the time of the trigger as approximately seen in the data
Int_t    AliEMCALRawResponse::fgThreshold         = 1;
Int_t    AliEMCALRawResponse::fgPedestalValue     = 0;  // pedestal value for digits2raw, default generate ZS data
Double_t AliEMCALRawResponse::fgFEENoise          = 3.; // 3 ADC channels of noise (sampled)



ClassImp(AliEMCALRawResponse)


AliEMCALRawResponse::AliEMCALRawResponse()
{
  //comment
}

AliEMCALRawResponse::~AliEMCALRawResponse()
{

}


Double_t 
AliEMCALRawResponse::RawResponseFunction(Double_t *x, Double_t *par)
{
  // step response of the emcal electronincs
  Double_t signal = 0.;
  Double_t tau    = par[2];
  Double_t n      = par[3];
  Double_t ped    = par[4];
  Double_t xx     = ( x[0] - par[1] + tau ) / tau ;
  if (xx <= 0) 
    signal = ped ;  
  else 
    {  
      signal = ped + par[0] * TMath::Power(xx , n) * TMath::Exp(n * (1 - xx )) ; 
    }
  return signal ;  
}


Bool_t  
AliEMCALRawResponse::RawSampledResponse(const Double_t dtime, const Double_t damp, Int_t * adcH, 
					    Int_t * adcL, const Int_t keyErr)
{
  // step response of the emcal electronincs
  Bool_t lowGain = kFALSE ; 
  TF1 signalF("signal", RawResponseFunction, 0, TIMEBINS, 5);
  signalF.SetParameter(0, damp) ; 
  signalF.SetParameter(1, (dtime + fgTimeTrigger)/ TIMEBINWITH) ; 
  signalF.SetParameter(2, TAU) ; 
  signalF.SetParameter(3, ORDER);
  signalF.SetParameter(4, fgPedestalValue);
	
  Double_t signal=0.0, noise=0.0;
  for (Int_t iTime = 0; iTime <  TIMEBINS; iTime++) {
    signal = signalF.Eval(iTime) ;  
    
    if(keyErr>0) {
      noise = gRandom->Gaus(0.,fgFEENoise);
      signal += noise; 
    }
	  
    adcH[iTime] =  static_cast<Int_t>(signal + 0.5) ;
    if ( adcH[iTime] > MAXBINVALUE ){  // larger than 10 bits 
      adcH[iTime] = MAXBINVALUE ;
      lowGain = kTRUE ; 
    }
    signal /= HGLGFACTOR;
    adcL[iTime] =  static_cast<Int_t>(signal + 0.5) ;
    if ( adcL[iTime] > MAXBINVALUE )  // larger than 10 bits 
      adcL[iTime] = MAXBINVALUE ;
  }
  return lowGain ; 
}

 AliEMCALRawResponse.cxx:1
 AliEMCALRawResponse.cxx:2
 AliEMCALRawResponse.cxx:3
 AliEMCALRawResponse.cxx:4
 AliEMCALRawResponse.cxx:5
 AliEMCALRawResponse.cxx:6
 AliEMCALRawResponse.cxx:7
 AliEMCALRawResponse.cxx:8
 AliEMCALRawResponse.cxx:9
 AliEMCALRawResponse.cxx:10
 AliEMCALRawResponse.cxx:11
 AliEMCALRawResponse.cxx:12
 AliEMCALRawResponse.cxx:13
 AliEMCALRawResponse.cxx:14
 AliEMCALRawResponse.cxx:15
 AliEMCALRawResponse.cxx:16
 AliEMCALRawResponse.cxx:17
 AliEMCALRawResponse.cxx:18
 AliEMCALRawResponse.cxx:19
 AliEMCALRawResponse.cxx:20
 AliEMCALRawResponse.cxx:21
 AliEMCALRawResponse.cxx:22
 AliEMCALRawResponse.cxx:23
 AliEMCALRawResponse.cxx:24
 AliEMCALRawResponse.cxx:25
 AliEMCALRawResponse.cxx:26
 AliEMCALRawResponse.cxx:27
 AliEMCALRawResponse.cxx:28
 AliEMCALRawResponse.cxx:29
 AliEMCALRawResponse.cxx:30
 AliEMCALRawResponse.cxx:31
 AliEMCALRawResponse.cxx:32
 AliEMCALRawResponse.cxx:33
 AliEMCALRawResponse.cxx:34
 AliEMCALRawResponse.cxx:35
 AliEMCALRawResponse.cxx:36
 AliEMCALRawResponse.cxx:37
 AliEMCALRawResponse.cxx:38
 AliEMCALRawResponse.cxx:39
 AliEMCALRawResponse.cxx:40
 AliEMCALRawResponse.cxx:41
 AliEMCALRawResponse.cxx:42
 AliEMCALRawResponse.cxx:43
 AliEMCALRawResponse.cxx:44
 AliEMCALRawResponse.cxx:45
 AliEMCALRawResponse.cxx:46
 AliEMCALRawResponse.cxx:47
 AliEMCALRawResponse.cxx:48
 AliEMCALRawResponse.cxx:49
 AliEMCALRawResponse.cxx:50
 AliEMCALRawResponse.cxx:51
 AliEMCALRawResponse.cxx:52
 AliEMCALRawResponse.cxx:53
 AliEMCALRawResponse.cxx:54
 AliEMCALRawResponse.cxx:55
 AliEMCALRawResponse.cxx:56
 AliEMCALRawResponse.cxx:57
 AliEMCALRawResponse.cxx:58
 AliEMCALRawResponse.cxx:59
 AliEMCALRawResponse.cxx:60
 AliEMCALRawResponse.cxx:61
 AliEMCALRawResponse.cxx:62
 AliEMCALRawResponse.cxx:63
 AliEMCALRawResponse.cxx:64
 AliEMCALRawResponse.cxx:65
 AliEMCALRawResponse.cxx:66
 AliEMCALRawResponse.cxx:67
 AliEMCALRawResponse.cxx:68
 AliEMCALRawResponse.cxx:69
 AliEMCALRawResponse.cxx:70
 AliEMCALRawResponse.cxx:71
 AliEMCALRawResponse.cxx:72
 AliEMCALRawResponse.cxx:73
 AliEMCALRawResponse.cxx:74
 AliEMCALRawResponse.cxx:75
 AliEMCALRawResponse.cxx:76
 AliEMCALRawResponse.cxx:77
 AliEMCALRawResponse.cxx:78
 AliEMCALRawResponse.cxx:79
 AliEMCALRawResponse.cxx:80
 AliEMCALRawResponse.cxx:81
 AliEMCALRawResponse.cxx:82
 AliEMCALRawResponse.cxx:83
 AliEMCALRawResponse.cxx:84
 AliEMCALRawResponse.cxx:85
 AliEMCALRawResponse.cxx:86
 AliEMCALRawResponse.cxx:87
 AliEMCALRawResponse.cxx:88
 AliEMCALRawResponse.cxx:89
 AliEMCALRawResponse.cxx:90
 AliEMCALRawResponse.cxx:91
 AliEMCALRawResponse.cxx:92
 AliEMCALRawResponse.cxx:93
 AliEMCALRawResponse.cxx:94
 AliEMCALRawResponse.cxx:95
 AliEMCALRawResponse.cxx:96
 AliEMCALRawResponse.cxx:97
 AliEMCALRawResponse.cxx:98
 AliEMCALRawResponse.cxx:99
 AliEMCALRawResponse.cxx:100
 AliEMCALRawResponse.cxx:101
 AliEMCALRawResponse.cxx:102
 AliEMCALRawResponse.cxx:103
 AliEMCALRawResponse.cxx:104
 AliEMCALRawResponse.cxx:105
 AliEMCALRawResponse.cxx:106