]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/CALO/AliHLTCaloFourier.cxx
Fixing comments
[u/mrichter/AliRoot.git] / HLT / CALO / AliHLTCaloFourier.cxx
1 // $Id: AliHLTPHOSFourier.cxx 34951 2009-09-23 14:35:38Z phille $
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 "AliHLTCaloFourier.h"
21
22 //#include "AliHLTCaloRcuFFTDataStruct.h"
23
24 ClassImp(AliHLTCaloFourier);
25
26 AliHLTCaloFourier::AliHLTCaloFourier() :  fFFT_own(0),
27                                           fFFTInputArray(0),
28                                           fFFTOutputArray(0),
29                                           fIsFirstChannel(true),
30                                           fFixedDataSize(0), 
31                                           fFFTOupuStruct(),
32                                           fCurrentEvent(0)
33 {
34   
35
36 }
37
38
39 AliHLTCaloFourier::AliHLTCaloFourier(const AliHLTCaloFourier&) : fFFT_own(0),
40                                                                  fFFTInputArray(0),
41                                                                  fFFTOutputArray(0),
42                                                                  fIsFirstChannel(true),
43                                                                  fFixedDataSize(0),
44                                                                  fFFTOupuStruct(), 
45                                                                  fCurrentEvent(0)
46
47 {
48   
49 }
50
51
52 AliHLTCaloFourier::~AliHLTCaloFourier()
53 {
54
55 }
56
57
58  
59 AliHLTCaloRcuFFTDataStruct 
60 AliHLTCaloFourier::GetPSD()
61 {
62   return fFFTOupuStruct;
63 }
64
65
66
67 void 
68 AliHLTCaloFourier::ProcessFourier(const Int_t *data, const int length, const int /*z*/, const int /*x*/, const int gain, const int event)
69 {
70   Double_t  re = 0;
71   Double_t  im = 0;
72
73   if( (event > 0 ) && (event != fCurrentEvent ))
74     {
75       fCurrentEvent = event;
76       ResetEventPSD(gain);
77     }
78
79   if(fIsFirstChannel == true)
80     {
81       fCurrentEvent = event;
82       fIsFirstChannel = false;
83       fFixedDataSize = length;
84       Int_t n_size = fFixedDataSize +1;
85       fFFT_own = TVirtualFFT::FFT(1, &n_size, "R2C ES K"); 
86       Init();
87   }
88
89   if( CheckSignal(data, length) == true)
90     {
91       Int2Double(data, fFFTInputArray,  fFixedDataSize );
92       fFFT_own->SetPoints( fFFTInputArray );     
93       fFFT_own->Transform();
94
95       for(int j=0; j < length; j++)
96         {
97           fFFT_own->GetPointComplex(j,  re,  im);
98           fFFTOupuStruct.fGlobalAccumulatedPSD[gain][j] +=  EvaluateMagnitude(re, im);
99           fFFTOupuStruct.fGlobalLastPSD[gain][j] +=  EvaluateMagnitude(re, im);
100
101         }
102     }
103   //  printf("AliHLTCaloFourier::ProcessFourier;  (z, x, gain)  =  (%d, %d, %d),  length = %d",  z,  x,  gain, length);
104 }
105
106 void 
107 AliHLTCaloFourier::ResetEventPSD(const int gain)
108 {
109   cout << " AliHLTCaloFourier::ResetEventPS, resetting event PSD "<< endl;
110   for(int i = 0;  i < fFixedDataSize; i++ )
111     {
112       fFFTOupuStruct.fGlobalLastPSD[gain][i] = 0;
113     }
114 }
115
116
117 bool 
118 //AliHLTCaloFourier::CheckSignal(const UInt_t *data, const int length)
119 AliHLTCaloFourier::CheckSignal(const Int_t *data, const int length)
120 {
121   //  UInt_t tmpMax =  Max(  const_cast< UInt_t *>(data), length);
122   //  UInt_t tmpMin =  Min(  const_cast< UInt_t *>(data), length);
123
124
125   Int_t tmpMax =  Max(  const_cast< Int_t *>(data), length);
126   Int_t tmpMin =  Min(  const_cast< Int_t *>(data), length);
127
128
129   // if( (tmpMax -tmpMin) > 200)
130   if( (tmpMax -tmpMin) > 100)
131    {
132       cout << "FourierAna::CheckSignal min = "<< tmpMin << "  max =  " << tmpMax << endl;
133     }
134   
135   if( (tmpMax >= MAXBINVALUE) || tmpMin < 1 )
136     {
137       cout << "ERROR, FourierAna::CheckSignal failed, signal out of range, min= "<< tmpMin << "max = " << tmpMax << endl;
138       return false;
139     }
140   else
141     {
142       return true;
143     }
144   
145   //return true;
146 }
147
148
149 void 
150 AliHLTCaloFourier::Init()
151 {
152   fFFTInputArray = new double[fFixedDataSize];
153   fFFTOutputArray = new double[fFixedDataSize];
154   
155   for(int gain = 0; gain < NGAINS; gain ++)
156     {
157       fFFTOupuStruct.fDataLength = fFixedDataSize;
158  
159       for(int k= 0; k <fFixedDataSize; k++ )
160         {
161           fFFTInputArray[k] = 0;
162           fFFTOutputArray[k] = 0;
163
164         }
165       for(int i=0; i <  ALTROMAXSAMPLES  ; i++)
166         {
167           fFFTOupuStruct.fGlobalAccumulatedPSD[gain][i] = 0;
168           fFFTOupuStruct.fGlobalLastPSD[gain][i] = 0;
169         }
170     }
171 }
172
173
174 double 
175 AliHLTCaloFourier::EvaluateMagnitude(const double re, const double im)
176 {
177   return re*re + im*im;
178 }
179
180
181 void 
182 AliHLTCaloFourier::Int2Double(const Int_t *inputarray, double *outputarray, const int size)
183 {
184   for(int i=0; i< size; i++)
185     {
186       outputarray[i] = (double)inputarray[i];
187     }
188 }