]> git.uio.no Git - u/mrichter/AliRoot.git/blame - EMCAL/AliCaloRawAnalyzerPeakFinder.cxx
This is a backward incompatible change in AliRoot. The following methods have been...
[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;
507751ce 136 return AliCaloFitResults( maxamp, ped, AliCaloFitResults::kCrude, maxf, timebinOffset);
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
507751ce 224 return AliCaloFitResults( maxamp, ped , AliCaloFitResults::kFitPar, fAmpA[tmpindex], tof, timebinOffset, AliCaloFitResults::kDummy, AliCaloFitResults::kDummy,
f57baa2d 225 AliCaloFitResults::kDummy, AliCaloFitSubarray(index, maxrev, first, last) );
d655d7dd 226 }
227 else
228 {
507751ce 229 return AliCaloFitResults( maxamp, ped , AliCaloFitResults::kCrude, maxf, timebinOffset);
d655d7dd 230 }
231 }
f57baa2d 232 else
233 {
507751ce 234 return AliCaloFitResults( maxamp , ped, AliCaloFitResults::kCrude, maxf, timebinOffset);
f57baa2d 235 }
d655d7dd 236 }
48a2e3eb 237 // cout << __FILE__ << __LINE__ << "WARNING, returning amp = -1 " << endl;
f57baa2d 238 return AliCaloFitResults(AliCaloFitResults::kInvalid, AliCaloFitResults::kInvalid);
d655d7dd 239}
240
241
242void
57839add 243AliCaloRawAnalyzerPeakFinder::LoadVectors()
d655d7dd 244{
245 //Read in the Peak finder vecors from file
246 for(int i = 0; i < MAXSTART ; i++)
247 {
248 for( int j=0; j < SAMPLERANGE; j++)
249 {
48a2e3eb 250 char filenameCoarse[256];
d655d7dd 251 char filename[256];
d655d7dd 252
48a2e3eb 253 int n = j+fNsampleCut;
254
255 // double start = (double)i+0.5;
256 double start = (double)i+0;
257
258 sprintf(filename, "%s/EMCAL/vectors-emcal/start%.1fN%dtau0.235fs10dt1.0.txt", getenv("ALICE_ROOT"), start, n);
259 sprintf(filenameCoarse, "%s/EMCAL/vectors-emcal/start%.1fN%dtau0.235fs10dt3.0.txt", getenv("ALICE_ROOT"), start, n);
260
261 FILE *fp = fopen(filename, "r");
262 FILE *fpc = fopen(filenameCoarse, "r");
263
264 if( fp == 0 )
d655d7dd 265 {
266 AliFatal( Form( "could not open file: %s", filename ) );
267 }
48a2e3eb 268
269 if(fpc == 0)
270 {
271 AliFatal( Form( "could not open file: %s", filenameCoarse ) );
272 }
d655d7dd 273 else
274 {
275 for(int m = 0; m < n ; m++ )
276 {
f57baa2d 277 // cout << __FILE__ << __LINE__ << "i="<<i <<"\tj=" <<j << "\tm=" << m << endl;
48a2e3eb 278
d655d7dd 279 fscanf(fp, "%lf\t", &fPFAmpVectors[i][j][m] );
48a2e3eb 280 // fPFAmpVectorsCoarse[i][j][m] = 1;
281 fscanf(fpc, "%lf\t", &fPFAmpVectorsCoarse[i][j][m] );
d655d7dd 282 }
48a2e3eb 283
284 fscanf(fp, "\n" );
285 fscanf(fpc, "\n" );
d655d7dd 286
287 for(int m = 0; m < n ; m++ )
288 {
48a2e3eb 289 // fPFTofVectors[i][j][m] = 1;
290
291 fscanf(fp, "%lf\t", &fPFTofVectors[i][j][m] );
292 fscanf(fpc, "%lf\t", &fPFTofVectorsCoarse[i][j][m] );
293 // fPFTofVectorsCoarse[i][j][m] = 1;
d655d7dd 294 }
295
48a2e3eb 296
d655d7dd 297 fclose (fp);
48a2e3eb 298 fclose (fpc);
d655d7dd 299 }
300 }
301 }
302}
48a2e3eb 303
304
305
306/*
307void
308AliCaloRawAnalyzerPeakFinder::PolTof( const double rectof ) const
309//
310{
311 static Double_t p0 = -55.69;
312 static Double_t p1 = 3.178;
313 static Double_t p2 = -0.05587;
314 static Double_t p3 = 0.0003185;
315 static Double_t p4 = -7.91E-7;
316 static Double_t p5 = 7.576E-10;
317}
318*/