]>
Commit | Line | Data |
---|---|---|
c51c5c6c | 1 | // $Id$ |
2 | ||
3 | /************************************************************************** | |
4 | * This file is property of and copyright by the Experimental Nuclear * | |
5 | * Physics Group, Dep. of Physics * | |
6 | * University of Oslo, Norway, 2007 * | |
7 | * * | |
8 | * Author: Per Thomas Hille <perthi@fys.uio.no> for the ALICE HLT Project.* | |
9 | * Contributors are mentioned in the code where appropriate. * | |
10 | * Please report bugs to perthi@fys.uio.no * | |
11 | * * | |
12 | * Permission to use, copy, modify and distribute this software and its * | |
13 | * documentation strictly for non-commercial purposes is hereby granted * | |
14 | * without fee, provided that the above copyright notice appears in all * | |
15 | * copies and that both the copyright notice and this permission notice * | |
16 | * appear in the supporting documentation. The authors make no claims * | |
17 | * about the suitability of this software for any purpose. It is * | |
18 | * provided "as is" without express or implied warranty. * | |
19 | **************************************************************************/ | |
20 | #include "AliHLTPHOSFourier.h" | |
21 | ||
22 | //#include "AliHLTPHOSRcuFFTDataStruct.h" | |
23 | ||
24 | AliHLTPHOSFourier::AliHLTPHOSFourier() : fFFT_own(0), | |
25 | fFFTInputArray(0), | |
26 | fFFTOutputArray(0), | |
27 | fIsFirstChannel(true), | |
28 | fFixedDataSize(0), | |
29 | fFFTOupuStruct(), | |
30 | fCurrentEvent(0) | |
31 | { | |
32 | ||
33 | ||
34 | } | |
35 | ||
36 | ||
37 | AliHLTPHOSFourier::AliHLTPHOSFourier(const AliHLTPHOSFourier&) : fFFT_own(0), | |
38 | fFFTInputArray(0), | |
39 | fFFTOutputArray(0), | |
40 | fIsFirstChannel(true), | |
41 | fFixedDataSize(0), | |
42 | fFFTOupuStruct(), | |
43 | fCurrentEvent(0) | |
44 | ||
45 | { | |
46 | ||
47 | } | |
48 | ||
49 | ||
50 | AliHLTPHOSFourier::~AliHLTPHOSFourier() | |
51 | { | |
52 | ||
53 | } | |
54 | ||
55 | ||
56 | ||
57 | AliHLTPHOSRcuFFTDataStruct | |
58 | AliHLTPHOSFourier::GetPSD() | |
59 | { | |
60 | return fFFTOupuStruct; | |
61 | } | |
62 | ||
63 | ||
64 | ||
65 | void | |
66 | AliHLTPHOSFourier::ProcessFourier(const Int_t *data, const int length, const int /*z*/, const int /*x*/, const int gain, const int event) | |
67 | { | |
68 | Double_t re = 0; | |
69 | Double_t im = 0; | |
70 | ||
71 | if( (event > 0 ) && (event != fCurrentEvent )) | |
72 | { | |
73 | fCurrentEvent = event; | |
74 | ResetEventPSD(gain); | |
75 | } | |
76 | ||
77 | if(fIsFirstChannel == true) | |
78 | { | |
79 | fCurrentEvent = event; | |
80 | fIsFirstChannel = false; | |
81 | fFixedDataSize = length; | |
82 | Int_t n_size = fFixedDataSize +1; | |
83 | fFFT_own = TVirtualFFT::FFT(1, &n_size, "R2C ES K"); | |
84 | Init(); | |
85 | } | |
86 | ||
87 | if( CheckSignal(data, length) == true) | |
88 | { | |
89 | Int2Double(data, fFFTInputArray, fFixedDataSize ); | |
90 | fFFT_own->SetPoints( fFFTInputArray ); | |
91 | fFFT_own->Transform(); | |
92 | ||
93 | for(int j=0; j < length; j++) | |
94 | { | |
95 | fFFT_own->GetPointComplex(j, re, im); | |
96 | fFFTOupuStruct.fGlobalAccumulatedPSD[gain][j] += EvaluateMagnitude(re, im); | |
97 | fFFTOupuStruct.fGlobalLastPSD[gain][j] += EvaluateMagnitude(re, im); | |
98 | ||
99 | } | |
100 | } | |
101 | // printf("AliHLTPHOSFourier::ProcessFourier; (z, x, gain) = (%d, %d, %d), length = %d", z, x, gain, length); | |
102 | } | |
103 | ||
104 | void | |
105 | AliHLTPHOSFourier::ResetEventPSD(const int gain) | |
106 | { | |
107 | cout << " AliHLTPHOSFourier::ResetEventPS, resetting event PSD "<< endl; | |
108 | for(int i = 0; i < fFixedDataSize; i++ ) | |
109 | { | |
110 | fFFTOupuStruct.fGlobalLastPSD[gain][i] = 0; | |
111 | } | |
112 | } | |
113 | ||
114 | ||
115 | bool | |
116 | //AliHLTPHOSFourier::CheckSignal(const UInt_t *data, const int length) | |
117 | AliHLTPHOSFourier::CheckSignal(const Int_t *data, const int length) | |
118 | { | |
119 | // UInt_t tmpMax = Max( const_cast< UInt_t *>(data), length); | |
120 | // UInt_t tmpMin = Min( const_cast< UInt_t *>(data), length); | |
121 | ||
122 | ||
123 | Int_t tmpMax = Max( const_cast< Int_t *>(data), length); | |
124 | Int_t tmpMin = Min( const_cast< Int_t *>(data), length); | |
125 | ||
126 | ||
127 | // if( (tmpMax -tmpMin) > 200) | |
128 | if( (tmpMax -tmpMin) > 100) | |
129 | { | |
130 | cout << "FourierAna::CheckSignal min = "<< tmpMin << " max = " << tmpMax << endl; | |
131 | } | |
132 | ||
133 | if( (tmpMax >= MAXBINVALUE) || tmpMin < 1 ) | |
134 | { | |
135 | cout << "ERROR, FourierAna::CheckSignal failed, signal out of range, min= "<< tmpMin << "max = " << tmpMax << endl; | |
136 | return false; | |
137 | } | |
138 | else | |
139 | { | |
140 | return true; | |
141 | } | |
142 | ||
143 | //return true; | |
144 | } | |
145 | ||
146 | ||
147 | void | |
148 | AliHLTPHOSFourier::Init() | |
149 | { | |
150 | fFFTInputArray = new double[fFixedDataSize]; | |
151 | fFFTOutputArray = new double[fFixedDataSize]; | |
152 | ||
153 | for(int gain = 0; gain < NGAINS; gain ++) | |
154 | { | |
155 | fFFTOupuStruct.fDataLength = fFixedDataSize; | |
156 | ||
157 | for(int k= 0; k <fFixedDataSize; k++ ) | |
158 | { | |
159 | fFFTInputArray[k] = 0; | |
160 | fFFTOutputArray[k] = 0; | |
161 | ||
162 | } | |
163 | for(int i=0; i < ALTROMAXSAMPLES ; i++) | |
164 | { | |
165 | fFFTOupuStruct.fGlobalAccumulatedPSD[gain][i] = 0; | |
166 | fFFTOupuStruct.fGlobalLastPSD[gain][i] = 0; | |
167 | } | |
168 | } | |
169 | } | |
170 | ||
171 | ||
172 | double | |
173 | AliHLTPHOSFourier::EvaluateMagnitude(const double re, const double im) | |
174 | { | |
175 | return re*re + im*im; | |
176 | } | |
177 | ||
178 | ||
179 | void | |
180 | AliHLTPHOSFourier::Int2Double(const Int_t *inputarray, double *outputarray, const int size) | |
181 | { | |
182 | for(int i=0; i< size; i++) | |
183 | { | |
184 | outputarray[i] = (double)inputarray[i]; | |
185 | } | |
186 | } |