1 /**************************************************************************
2 * Copyright(c) 2007, 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 // The class which simulates the pulse shape from the PHOS FEE shaper,
19 // make sampled amplitudes, digitize them.
21 // AliPHOSPulseGenerator *pulse = new AliPHOSPulseGenerator(energy,time);
22 // Int_t *adcHG = new Int_t[pulse->GetRawFormatTimeBins()];
23 // Int_t *adcLG= new Int_t[pulse->GetRawFormatTimeBins()];
24 // pulse->AddNoise(1.);
25 // pulse->MakeSamples();
26 // pulse->GetSamples(adcHG, adcHG) ;
30 // Author: Yuri Kharlov, after Yves Schutz and Per Thomas Hille
32 // --- ROOT system ---
39 // --- AliRoot header files ---
41 #include "AliPHOSPulseGenerator.h"
43 // --- Standard library ---
50 ClassImp(AliPHOSPulseGenerator)
52 Double_t AliPHOSPulseGenerator::fgCapa = 1.; // 1pF
53 Int_t AliPHOSPulseGenerator::fgOrder = 2 ; // order of the Gamma function
54 Double_t AliPHOSPulseGenerator::fgTimeMax = 2.56E-5 ; // each sample is over 100 ns fTimeMax/fTimeBins
55 Double_t AliPHOSPulseGenerator::fgTimePeak = 4.1E-6 ; // 4 micro seconds
56 Double_t AliPHOSPulseGenerator::fgTimeTrigger = 100E-9 ; // 100ns, just for a reference
57 Double_t AliPHOSPulseGenerator::fgHighCharge = 8.2; // adjusted for a high gain range of 5.12 GeV (10 bits)
58 Double_t AliPHOSPulseGenerator::fgHighGain = 6.64;
59 Double_t AliPHOSPulseGenerator::fgHighLowGainFactor = 16.; // adjusted for a low gain range of 82 GeV (10 bits)
61 //-----------------------------------------------------------------------------
62 AliPHOSPulseGenerator::AliPHOSPulseGenerator(Double_t a, Double_t t0)
63 : TObject(), fAmplitude(a), fTZero(t0), fDataHG(0), fDataLG(0), fDigitize(kTRUE)
65 // Contruct a pulsegenrator object and initializes all necessary parameters
66 // @param a digit amplitude in GeV
67 // @param t0 time delay in nanoseconds of signal relative the first sample.
68 // This value should be between 0 and Ts, where Ts is the sample interval
70 fDataHG = new Double_t[fkTimeBins];
71 fDataLG = new Double_t[fkTimeBins];
75 //-----------------------------------------------------------------------------
76 AliPHOSPulseGenerator::AliPHOSPulseGenerator(const AliPHOSPulseGenerator & pulse)
77 : TObject(), fAmplitude(pulse.fAmplitude), fTZero(pulse.fTZero), fDataHG(0), fDataLG(0), fDigitize(kTRUE)
79 fDataHG = new Double_t[pulse.fkTimeBins];
80 fDataLG = new Double_t[pulse.fkTimeBins];
81 for (Int_t i=0; i<pulse.fkTimeBins; i++) {
82 fDataHG[i] = pulse.fDataHG[i];
83 fDataLG[i] = pulse.fDataHG[i];
87 //-----------------------------------------------------------------------------
88 AliPHOSPulseGenerator::~AliPHOSPulseGenerator()
90 // Destructor: delete arrays of samples
98 //-----------------------------------------------------------------------------
99 void AliPHOSPulseGenerator::Reset()
101 // Reset all sample amplitudes to 0
103 for (Int_t i=0; i<fkTimeBins; i++) {
109 //-----------------------------------------------------------------------------
110 void AliPHOSPulseGenerator::AddBaseline(Double_t baselineLevel)
112 // Adds a baseline offset to the signal
113 // @param baselineLevel The basline level to add
114 for (Int_t i=0; i<fkTimeBins; i++) {
115 fDataHG[i] += baselineLevel;
116 fDataLG[i] += baselineLevel;
118 // Digitize floating point amplitudes to integers
119 if (fDigitize) Digitize();
122 //-----------------------------------------------------------------------------
123 void AliPHOSPulseGenerator::AddNoise(Double_t sigma)
125 // Adds Gaussian uncorrelated to the sample array
126 // @param sigma the noise amplitude in entities of ADC levels
128 for (Int_t i=0; i<fkTimeBins; i++) {
129 fDataHG[i] = gRandom->Gaus(0., sigma) ;
130 fDataLG[i] = gRandom->Gaus(0., sigma) ;
134 //-----------------------------------------------------------------------------
135 void AliPHOSPulseGenerator::AddNoise(Double_t * /* sigma */, Double_t /* cutoff */)
137 //Adds correlated Gaussian noise with cutof frequency "cutoff"
138 // @param sigma noise amplitude in entities of ADC levels
139 // @param -30DB cutoff frequency of the noise in entities of sampling frequency
141 AliError("not implemented yet");
144 //-----------------------------------------------------------------------------
145 void AliPHOSPulseGenerator::AddPretriggerSamples(Int_t nPresamples)
147 // Adds pretrigger samples to the sample arrays and replace them
148 // with concatinated and truncated arrays
150 Double_t *tmpDataHG = new Double_t[fkTimeBins];
151 Double_t *tmpDataLG = new Double_t[fkTimeBins];
153 for (i=0; i<fkTimeBins; i++) {
154 tmpDataHG[i] = fDataHG[i];
155 tmpDataLG[i] = fDataLG[i];
157 for (i=0; i<fkTimeBins; i++) {
163 fDataHG[i] = tmpDataHG[i-nPresamples];
164 fDataLG[i] = tmpDataLG[i-nPresamples];
171 //-----------------------------------------------------------------------------
172 void AliPHOSPulseGenerator::Digitize()
174 // Emulates ADC: rounds down to nearest integer value all amplitudes
175 for (Int_t i=0; i<fkTimeBins; i++) {
176 fDataHG[i] = (Double_t) ((Int_t)(fDataHG[i] + 0.5));
177 fDataLG[i] = (Double_t) ((Int_t)(fDataLG[i] + 0.5));
181 //-----------------------------------------------------------------------------
182 Double_t AliPHOSPulseGenerator::RawResponseFunction(Double_t *x, Double_t *par)
184 // Shape of the electronics raw reponse:
185 // It is a semi-gaussian, 2nd order Gamma function of the general form
186 // v(t) = n**n * Q * A**n / C *(t/tp)**n * exp(-n * t/tp) with
187 // tp : peaking time par[0]
188 // n : order of the function
189 // C : integrating capacitor in the preamplifier
190 // A : open loop gain of the preamplifier
191 // Q : the total APD charge to be measured Q = C * energy
194 Double_t xx = x[0] - ( fgTimeTrigger + par[3] ) ;
196 if (xx < 0 || xx > fgTimeMax)
199 Double_t fac = par[0] * TMath::Power(fgOrder, fgOrder) * TMath::Power(par[1], fgOrder)/fgCapa ;
200 signal = fac * par[2] * TMath::Power(xx/fgTimePeak, fgOrder) * TMath::Exp(-fgOrder*(xx/fgTimePeak)) ;
205 //__________________________________________________________________
206 Double_t AliPHOSPulseGenerator::RawResponseFunctionMax(Double_t charge, Double_t gain)
208 // Maximum value of the shaper response function
209 return ( charge * TMath::Power(fgOrder, fgOrder) * TMath::Power(gain, fgOrder)
210 / ( fgCapa * TMath::Exp(fgOrder) ) );
213 //__________________________________________________________________
214 Bool_t AliPHOSPulseGenerator::MakeSamples()
216 // for a start time fTZero and an amplitude fAmplitude given by digit,
217 // calculates the raw sampled response AliPHOSPulseGenerator::RawResponseFunction
219 const Int_t kRawSignalOverflow = 0x3FF ; // decimal 1023
220 Bool_t lowGain = kFALSE ;
222 TF1 signalF("signal", RawResponseFunction, 0, GetRawFormatTimeMax(), 4);
224 for (Int_t iTime = 0; iTime < GetRawFormatTimeBins(); iTime++) {
225 signalF.SetParameter(0, fgHighCharge) ;
226 signalF.SetParameter(1, fgHighGain) ;
227 signalF.SetParameter(2, fAmplitude) ;
228 signalF.SetParameter(3, fTZero) ;
229 Double_t time = iTime * GetRawFormatTimeMax() / GetRawFormatTimeBins() ;
230 Double_t signal = signalF.Eval(time) ;
231 fDataHG[iTime] += signal;
232 if ( static_cast<Int_t>(fDataHG[iTime]+0.5) > kRawSignalOverflow ){ // larger than 10 bits
233 fDataHG[iTime] = kRawSignalOverflow ;
237 signalF.SetParameter(0, GetRawFormatLowCharge() ) ;
238 signalF.SetParameter(1, GetRawFormatLowGain() ) ;
239 signal = signalF.Eval(time) ;
240 fDataLG[iTime] += signal;
241 if ( static_cast<Int_t>(fDataLG[iTime]+0.5) > kRawSignalOverflow) // larger than 10 bits
242 fDataLG[iTime] = kRawSignalOverflow ;
245 // Digitize floating point amplitudes to integers
246 if (fDigitize) Digitize();
250 //__________________________________________________________________
251 void AliPHOSPulseGenerator::GetSamples(Int_t *adcHG, Int_t *adcLG) const
253 // Return integer sample arrays adcHG and adcLG
254 for (Int_t iTime = 0; iTime < GetRawFormatTimeBins(); iTime++) {
255 adcHG[iTime] = static_cast<Int_t>(fDataHG[iTime]) ;
256 adcLG[iTime] = static_cast<Int_t>(fDataLG[iTime]) ;
260 //__________________________________________________________________
261 void AliPHOSPulseGenerator::Print(Option_t*) const
263 // Prints sampled amplitudes to stdout
265 cout << "High gain: ";
266 for (i=0; i<fkTimeBins; i++)
267 cout << (Int_t)fDataHG[i] << " ";
270 cout << "Low gain: ";
271 for (i=0; i<fkTimeBins; i++)
272 cout << (Int_t)fDataLG[i] << " ";
276 //__________________________________________________________________
277 void AliPHOSPulseGenerator::Draw(Option_t*)
279 // Draw graphs with high and low gain samples
281 Double_t *time = new Double_t[fkTimeBins];
282 for (Int_t iTime = 0; iTime < GetRawFormatTimeBins(); iTime++) {
283 time[iTime] = iTime * GetRawFormatTimeMax() / GetRawFormatTimeBins() ;
285 Int_t nPoints = fkTimeBins;
286 TGraph *graphHG = new TGraph(nPoints,time,fDataHG);
287 TGraph *graphLG = new TGraph(nPoints,time,fDataLG);
288 graphHG->SetMarkerStyle(20);
289 graphLG->SetMarkerStyle(20);
290 graphHG->SetMarkerSize(0.4);
291 graphLG->SetMarkerSize(0.4);
292 graphHG->SetTitle("High gain samples");
293 graphLG->SetTitle("Low gain samples");
295 TCanvas *c1 = new TCanvas("c1","Raw ALTRO samples",10,10,700,500);
299 gPad->SetLeftMargin(0.15);
301 graphHG->GetHistogram()->SetTitleOffset(1.6,"Y");
302 graphHG->GetHistogram()->SetXTitle("time, #musec");
303 graphHG->GetHistogram()->SetYTitle("Amplitude, ADC counts");
305 gPad->SetLeftMargin(0.15);
307 graphLG->GetHistogram()->SetTitleOffset(1.6,"Y");
308 graphLG->GetHistogram()->SetXTitle("time, #musec");
309 graphLG->GetHistogram()->SetYTitle("Amplitude, ADC counts");