]> git.uio.no Git - u/mrichter/AliRoot.git/blame - EMCAL/AliCaloRawAnalyzerPeakFinder.cxx
add new class to hold info on bins used in fitting + standardize result return codes...
[u/mrichter/AliRoot.git] / EMCAL / AliCaloRawAnalyzerPeakFinder.cxx
CommitLineData
d655d7dd 1/**************************************************************************
e37e3c84 2 * This file is property of and copyright by *
3 * the Relativistic Heavy Ion Group (RHIG), Yale University, US, 2009 *
4 * *
5 * Primary Author: Per Thomas Hille <perthomas.hille@yale.edu> *
d655d7dd 6 * *
d655d7dd 7 * Contributors are mentioned in the code where appropriate. *
e37e3c84 8 * Please report bugs to p.t.hille@fys.uio.no *
d655d7dd 9 * *
10 * Permission to use, copy, modify and distribute this software and its *
11 * documentation strictly for non-commercial purposes is hereby granted *
12 * without fee, provided that the above copyright notice appears in all *
13 * copies and that both the copyright notice and this permission notice *
14 * appear in the supporting documentation. The authors make no claims *
15 * about the suitability of this software for any purpose. It is *
16 * provided "as is" without express or implied warranty. *
17 **************************************************************************/
18
19// The Peak-Finder algorithm
20// The amplitude is extracted as a
21// weighted sum of the samples using the
22// best possible weights.
23// The wights is calculated only once and the
24// Actual extraction of amplitude and peak position
25// Is done with a simple vector multiplication, allowing for
26// Extreemely fast computations.
27
57839add 28#include "AliCaloRawAnalyzerPeakFinder.h"
29#include "AliCaloBunchInfo.h"
30#include "AliCaloFitResults.h"
d655d7dd 31#include <iostream>
32#include "unistd.h"
33#include "TMath.h"
34#include "AliLog.h"
35
36using namespace std;
37
e37e3c84 38ClassImp( AliCaloRawAnalyzerPeakFinder )
39
48a2e3eb 40AliCaloRawAnalyzerPeakFinder::AliCaloRawAnalyzerPeakFinder() :AliCaloRawAnalyzer("Peak-Finder", "PF")
e37e3c84 41// fTof(0),
42// fAmp(0)
d655d7dd 43{
44 //comment
45
46 fNsampleCut = 5;
47
48 for(int i=0; i < MAXSTART; i++)
49 {
50 for(int j=0; j < SAMPLERANGE; j++ )
51 {
52 fPFAmpVectors[i][j] = new double[100];
53 fPFTofVectors[i][j] = new double[100];
48a2e3eb 54 fPFAmpVectorsCoarse[i][j] = new double[100];
55 fPFTofVectorsCoarse[i][j] = new double[100];
56
d655d7dd 57 for(int k=0; k < 100; k++ )
58 {
59 fPFAmpVectors[i][j][k] = 0;
60 fPFTofVectors[i][j][k] = 0;
48a2e3eb 61 fPFAmpVectorsCoarse[i][j][k] = 0;
62 fPFTofVectorsCoarse[i][j][k] = 0;
d655d7dd 63 }
64 }
65 }
48a2e3eb 66
d655d7dd 67 LoadVectors();
48a2e3eb 68
d655d7dd 69}
70
71
57839add 72AliCaloRawAnalyzerPeakFinder::~AliCaloRawAnalyzerPeakFinder()
d655d7dd 73{
74 //comment
75 for(int i=0; i < MAXSTART; i++)
76 {
77 for(int j=0; j < SAMPLERANGE; j++ )
78 {
79 delete[] fPFAmpVectors[i][j];
80 delete[] fPFTofVectors[i][j];
48a2e3eb 81 delete[] fPFAmpVectorsCoarse[i][j];
82 delete[] fPFTofVectorsCoarse[i][j];
d655d7dd 83 }
84 }
85}
86
87
48a2e3eb 88Double_t
89AliCaloRawAnalyzerPeakFinder::ScanCoarse(const Double_t *const array, const int length ) const
90{
91 Double_t tmpTof = 0;
92 Double_t tmpAmp= 0;
93
94 for(int i=0; i < length; i++)
95 {
96 tmpTof += fPFTofVectorsCoarse[0][length][i]*array[i];
97 tmpAmp += fPFAmpVectorsCoarse[0][length][i]*array[i];
98 }
99
100 tmpTof = tmpTof / tmpAmp ;
101 return tmpTof;
102}
103
104
57839add 105AliCaloFitResults
106AliCaloRawAnalyzerPeakFinder::Evaluate( const vector<AliCaloBunchInfo> &bunchvector, const UInt_t altrocfg1, const UInt_t altrocfg2 )
d655d7dd 107{
108 // Extracting the amplitude using the Peak-Finder algorithm
109 // The amplitude is a weighted sum of the samples using
110 // optimum weights.
111
112 short maxampindex; //index of maximum amplitude
113 short maxamp; //Maximum amplitude
e37e3c84 114 // fAmp = 0;
48a2e3eb 115
116
8ffb0474 117 fAmpA[0] = 0;
118 fAmpA[1] = 0;
119 fAmpA[2] = 0;
48a2e3eb 120
121
122 // cout << __FILE__ << __LINE__ << "\tendbin = " << bunchvector.at(index).GetEndBin() << "\tstartbin = " << bunchvector.at(index).GetStartBin() << endl;
123
d655d7dd 124 int index = SelectBunch( bunchvector, &maxampindex, &maxamp );
48a2e3eb 125
d655d7dd 126 if( index >= 0)
127 {
128 Float_t ped = ReverseAndSubtractPed( &(bunchvector.at(index)) , altrocfg1, altrocfg2, fReversed );
129 Float_t maxf = TMath::MaxElement( bunchvector.at(index).GetLength(), fReversed );
f57baa2d 130 short maxrev = maxampindex - bunchvector.at(index).GetStartBin();
131 short timebinOffset = maxampindex - (bunchvector.at( index ).GetLength()-1);
132
d655d7dd 133 if( maxf < fAmpCut || ( maxamp - ped) > 900 ) // (maxamp - ped) > 900 = Close to saturation (use low gain then)
134 {
135 // cout << __FILE__ << __LINE__ <<":, maxamp = " << maxamp << ", ped = "<< ped << ",. maxf = "<< maxf << ", maxampindex = "<< maxampindex << endl;
f57baa2d 136 return AliCaloFitResults( maxamp, ped, AliCaloFitResults::kNoFit, maxf, maxrev+timebinOffset, AliCaloFitResults::kNoFit, AliCaloFitResults::kNoFit );
d655d7dd 137 }
138
139 int first;
140 int last;
141
142 if ( maxf > fAmpCut )
f57baa2d 143 {
144 SelectSubarray( fReversed, bunchvector.at(index).GetLength(), maxrev, &first, &last);
d655d7dd 145 int nsamples = last - first;
146 if( ( nsamples ) >= fNsampleCut )
147 {
148 int startbin = bunchvector.at(index).GetStartBin();
48a2e3eb 149 int n = last - first;
d655d7dd 150 int pfindex = n - fNsampleCut;
151 pfindex = pfindex > SAMPLERANGE ? SAMPLERANGE : pfindex;
152
8ffb0474 153 int dt = maxampindex - startbin -2;
48a2e3eb 154
155 // cout << __FILE__ << __LINE__ <<"\t The coarse estimated t0 is " << ScanCoarse( &fReversed[dt] , n ) << endl;
156
157
158 // Float_t tmptof = ScanCoarse( &fReversed[dt] , n );
159
160 // cout << __FILE__ << __LINE__ << ", dt = " << dt << ",\tmaxamindex = " << maxampindex << "\tstartbin = "<< startbin << endl;
161
162 for( int i=0; i < SAMPLERANGE; i++ )
d655d7dd 163 {
48a2e3eb 164 for( int j = 0; j < 3; j++ )
8ffb0474 165 {
166 // fAmpA[j] += fPFAmpVectors[0][pfindex][i]*tmp[j];
48a2e3eb 167 fAmpA[j] += fPFAmpVectors[0][pfindex][i]*fReversed[ dt +i +j -1 ];
8ffb0474 168 }
169 }
170
171 double diff = 9999;
8ffb0474 172 int tmpindex = 0;
173
174 for(int k=0; k < 3; k ++)
175 {
176 // cout << __FILE__ << __LINE__ << "amp[="<< k <<"] = " << fAmpA[k] << endl;
177 if( TMath::Abs(fAmpA[k] - ( maxamp - ped) ) < diff)
178 {
179 diff = TMath::Abs(fAmpA[k] - ( maxamp - ped));
180 tmpindex = k;
181 }
d655d7dd 182 }
183
48a2e3eb 184 Float_t tmptof = ScanCoarse( &fReversed[dt] , n );
185
186 if( tmptof < -1 )
187 {
188 tmpindex = 0;
189 }
190 else
191 if( tmptof > -1 && tmptof < 100 )
192 {
193 tmpindex =1;
194 }
195 else
196 {
197 tmpindex = 2;
198 }
8ffb0474 199 double tof = 0;
48a2e3eb 200
8ffb0474 201 for(int k=0; k < SAMPLERANGE; k++ )
202 {
203 tof += fPFTofVectors[0][pfindex][k]*fReversed[ dt +k + tmpindex -1 ];
204 }
205
48a2e3eb 206 // cout << __FILE__ << __LINE__ << "tofRaw = "<< tof / fAmpA[tmpindex] << endl;
207
208 // tof = tof / fAmpA[tmpindex] + (dt + startbin)*100;
209
210 if( TMath::Abs( (maxf - fAmpA[tmpindex])/maxf ) > 0.1 )
211 {
212 fAmpA[tmpindex] = maxf;
213 }
214
215 // timebinOffset
216
217 // tof = (dt + startbin + tmpindex )*100 - tof/fAmpA[tmpindex];
218 // tof = ( timebinOffset )*100 - tof/fAmpA[tmpindex]; // ns
219 tof = timebinOffset - 0.01*tof/fAmpA[tmpindex]; // clock ticks
220
221 // tof = tof/fAmpA[tmpindex];
8ffb0474 222
f57baa2d 223
224 return AliCaloFitResults( maxamp, ped , AliCaloFitResults::kDummy, fAmpA[tmpindex], tof, AliCaloFitResults::kDummy, AliCaloFitResults::kDummy,
225 AliCaloFitResults::kDummy, AliCaloFitSubarray(index, maxrev, first, last) );
d655d7dd 226 }
227 else
228 {
f57baa2d 229 return AliCaloFitResults( maxamp, ped , AliCaloFitResults::kNoFit, maxf, maxrev+timebinOffset, AliCaloFitResults::kNoFit, AliCaloFitResults::kNoFit,
230 AliCaloFitResults::kNoFit, AliCaloFitSubarray(index, maxrev, first, last) );
d655d7dd 231 }
232 }
f57baa2d 233 else
234 {
235 return AliCaloFitResults( maxamp , ped, AliCaloFitResults::kNoFit, maxf, maxrev+timebinOffset, AliCaloFitResults::kNoFit, AliCaloFitResults::kNoFit);
236 }
d655d7dd 237 }
48a2e3eb 238 // cout << __FILE__ << __LINE__ << "WARNING, returning amp = -1 " << endl;
f57baa2d 239 return AliCaloFitResults(AliCaloFitResults::kInvalid, AliCaloFitResults::kInvalid);
d655d7dd 240}
241
242
243void
57839add 244AliCaloRawAnalyzerPeakFinder::LoadVectors()
d655d7dd 245{
246 //Read in the Peak finder vecors from file
247 for(int i = 0; i < MAXSTART ; i++)
248 {
249 for( int j=0; j < SAMPLERANGE; j++)
250 {
48a2e3eb 251 char filenameCoarse[256];
d655d7dd 252 char filename[256];
d655d7dd 253
48a2e3eb 254 int n = j+fNsampleCut;
255
256 // double start = (double)i+0.5;
257 double start = (double)i+0;
258
259 sprintf(filename, "%s/EMCAL/vectors-emcal/start%.1fN%dtau0.235fs10dt1.0.txt", getenv("ALICE_ROOT"), start, n);
260 sprintf(filenameCoarse, "%s/EMCAL/vectors-emcal/start%.1fN%dtau0.235fs10dt3.0.txt", getenv("ALICE_ROOT"), start, n);
261
262 FILE *fp = fopen(filename, "r");
263 FILE *fpc = fopen(filenameCoarse, "r");
264
265 if( fp == 0 )
d655d7dd 266 {
267 AliFatal( Form( "could not open file: %s", filename ) );
268 }
48a2e3eb 269
270 if(fpc == 0)
271 {
272 AliFatal( Form( "could not open file: %s", filenameCoarse ) );
273 }
d655d7dd 274 else
275 {
276 for(int m = 0; m < n ; m++ )
277 {
f57baa2d 278 // cout << __FILE__ << __LINE__ << "i="<<i <<"\tj=" <<j << "\tm=" << m << endl;
48a2e3eb 279
d655d7dd 280 fscanf(fp, "%lf\t", &fPFAmpVectors[i][j][m] );
48a2e3eb 281 // fPFAmpVectorsCoarse[i][j][m] = 1;
282 fscanf(fpc, "%lf\t", &fPFAmpVectorsCoarse[i][j][m] );
d655d7dd 283 }
48a2e3eb 284
285 fscanf(fp, "\n" );
286 fscanf(fpc, "\n" );
d655d7dd 287
288 for(int m = 0; m < n ; m++ )
289 {
48a2e3eb 290 // fPFTofVectors[i][j][m] = 1;
291
292 fscanf(fp, "%lf\t", &fPFTofVectors[i][j][m] );
293 fscanf(fpc, "%lf\t", &fPFTofVectorsCoarse[i][j][m] );
294 // fPFTofVectorsCoarse[i][j][m] = 1;
d655d7dd 295 }
296
48a2e3eb 297
d655d7dd 298 fclose (fp);
48a2e3eb 299 fclose (fpc);
d655d7dd 300 }
301 }
302 }
303}
48a2e3eb 304
305
306
307/*
308void
309AliCaloRawAnalyzerPeakFinder::PolTof( const double rectof ) const
310//
311{
312 static Double_t p0 = -55.69;
313 static Double_t p1 = 3.178;
314 static Double_t p2 = -0.05587;
315 static Double_t p3 = 0.0003185;
316 static Double_t p4 = -7.91E-7;
317 static Double_t p5 = 7.576E-10;
318}
319*/