]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/PHOS/AliHLTPHOSPulseGenerator.cxx
New class structure
[u/mrichter/AliRoot.git] / HLT / PHOS / AliHLTPHOSPulseGenerator.cxx
1 /**************************************************************************
2  * Copyright(c) 2006, ALICE Experiment at CERN, All rights reserved.      *
3  *                                                                        *
4  * Author: Per Thomas Hille for the ALICE HLT Project.                    *
5  * Contributors are mentioned in the code where appropriate.              *
6  *                                                                        *
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  **************************************************************************/
15
16 #include "AliHLTPHOSPulseGenerator.h"
17 #include <cmath>
18 #include <iostream>
19
20 using std::cout;
21 using std::endl; 
22
23 ClassImp(AliHLTPHOSPulseGenerator) 
24
25 //______________________________________________________________________________________________________
26 AliHLTPHOSPulseGenerator::AliHLTPHOSPulseGenerator(): fAmplitude(0), fNSamples(0),fTau(0), fSampleFreq(0), fTZero(0), fDataPtr(0), fDT(0)
27 {
28   cout << "You cannot invoke the Pulsgenerator without parameters" << endl;
29 }
30
31
32 //______________________________________________________________________________________________________
33 AliHLTPHOSPulseGenerator::AliHLTPHOSPulseGenerator(const AliHLTPHOSPulseGenerator &): fAmplitude(0), fNSamples(0),fTau(0), fSampleFreq(0), fTZero(0), fDataPtr(0), fDT(0)
34 {
35   
36 }
37
38
39 //______________________________________________________________________________________________________
40 AliHLTPHOSPulseGenerator::~AliHLTPHOSPulseGenerator()
41 {
42   delete fDataPtr;
43   fDataPtr=0;
44 }
45
46 /**
47  * Contruct a pulsegenrator object an initializes all necessary parameters
48  * @param a Amplitude in ADC levels (0 -1023)
49  * @param t0 Timedelay in nanoseconds of signal relative the first sample. This value should be between 0 and Ts
50  * @param N the number of samples
51  * @param tau Rise time of the semi Gaussian signal
52  * @param fs samling rate
53  **/
54 AliHLTPHOSPulseGenerator::AliHLTPHOSPulseGenerator(double a, double t0, int N, double tau, double fs): fAmplitude(a), fNSamples(N),fTau(0), fSampleFreq(fs), fTZero(0), fDataPtr(0), fDT(0)
55 {
56   fDataPtr = new double[100];
57   SetAmplitude(a);
58   SetDT(fs);
59   SetTZero(t0);
60   fNSamples=N;
61   fTau=tau;
62   fSampleFreq=fs;
63   //  MakePulse(fDataPtr,a);
64   MakePulse(fDataPtr);
65 }
66
67
68 /**
69  * Adds a baseline offset to the signal
70  * @param baselineLevel The basline level to add
71  * @param *samples The sample array for which to add te basline offset
72  **/
73 void 
74 AliHLTPHOSPulseGenerator::AddBaseline(double baselineLevel, double *samples)
75 {
76   double *tmpSamples;
77   tmpSamples = samples;
78   printf("\nbaselineLevel = %f\n", baselineLevel);
79   cout << "AddBaseline not implemented yet" << endl;
80 }
81
82 /**
83  * Adds Gaussian white noise to the sample array given by *dataPtr.
84  * @param dataPtr array of samples
85  * @param sigma the noise amplitude in entities of ADC levels  
86  **/
87 void 
88 AliHLTPHOSPulseGenerator::AddNoise(double *dataPtr, double *sigma)
89 {
90   printf("\ndataPtr = %f, sigma = %f\n", *dataPtr, *sigma);
91   cout << "AddNoise is not implemented yet" << endl;
92 }
93
94
95 /**
96  * Adds correlated Gaussian noise with cutof frequency "cutoff"
97  * @param dataPtr array of values
98  * @param sigma noise amplitude in entities of ADC levels
99  * @param cutoff -30DB cutoff frequency of the noise in entities of sampling frequency
100  **/
101 void 
102 AliHLTPHOSPulseGenerator::AddNoise(double *dataPtr, double *sigma, double cutoff)
103 {
104   printf("\ndataPtr = %f, sigma = %f, cutoff = %f\n", *dataPtr, *sigma, cutoff);
105   cout << "AddNoise is not implemeted yet" << endl;
106 }
107
108
109
110 /**
111  * Adds pretrigger samples to the sample array and returns 
112  * a new array containing the pretrigger samples concatenatet
113  * in front of the samples given by "samples"
114  * @param baselineLevel The baseline value of the pretrigger samples
115  * @param samples The sample array for which to add the pretrigger samples
116  **/
117 double *
118 AliHLTPHOSPulseGenerator::AddPretriggerSamples(double baselineLevel, double *samples)
119 {
120   printf("\nbaslinelevel = %f, samples = %f\n", baselineLevel, *samples);
121   cout << "AddPretriggerSamples not implemented yet" << endl;
122   return 0;
123 }
124
125
126 /**
127  * Returns a Pulse with new amplidude and t0
128  * @param a new amplidude, overriding the one given in the constructor
129  * @param t0 start time of the pulse relative to the sampling clock.
130  **/
131 double *
132 AliHLTPHOSPulseGenerator::GetPulse(double a, double t0)
133 {
134   return fDataPtr;
135 }
136
137 /**
138  * Emulates the ADC. Rounds down to nearest Integerevalue all entries given by
139  * dataPtr
140  **/
141 void 
142 AliHLTPHOSPulseGenerator::Quantisize(double *dataPtr)
143 {
144   double *dtaPtr;
145   dtaPtr = new double[100];
146   dtaPtr = dataPtr;
147   //  cout << "Quantisize is not implemented yet" << endl;
148 }
149
150
151 //______________________________________________________________________________________________________
152 void
153 AliHLTPHOSPulseGenerator::SetAmplitude(double a)
154 {
155   fAmplitude=a;
156 }
157
158
159 //______________________________________________________________________________________________________
160 void 
161 AliHLTPHOSPulseGenerator::SetDT(double fs)
162 {
163   fDT=1/fs;  
164 }
165
166 //______________________________________________________________________________________________________
167 void
168 AliHLTPHOSPulseGenerator::SetTZero(double t0)
169 {
170   fTZero = -t0/1000; // Since time is in nanoseconds and the samplingfrequency is in MHz -> divide by 1000
171 }
172
173
174 //______________________________________________________________________________________________________
175 void
176 AliHLTPHOSPulseGenerator::MakePulse(double *dtaPtr)
177 {
178 for(int i=0; i<fNSamples; i++)
179   {
180     dtaPtr[i]=fAmplitude*exp((Double_t)2)*pow((i*fDT-fTZero)/fTau, 2)*exp(-2*(i*fDT-fTZero)/fTau);
181   }  
182 }