1 /**************************************************************************
2 * This file is property of and copyright by *
3 * the Relativistic Heavy Ion Group (RHIG), Yale University, US, 2009 *
5 * Primary Author: Per Thomas Hille <perthomas.hille@yale.edu> *
7 * Contributors are mentioned in the code where appropriate. *
8 * Please report bugs to p.t.hille@fys.uio.no *
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 **************************************************************************/
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.
28 #include "AliCaloRawAnalyzerPeakFinder.h"
29 #include "AliCaloBunchInfo.h"
30 #include "AliCaloFitResults.h"
38 ClassImp( AliCaloRawAnalyzerPeakFinder )
40 AliCaloRawAnalyzerPeakFinder::AliCaloRawAnalyzerPeakFinder() :AliCaloRawAnalyzer("Peak-Finder")
48 for(int i=0; i < MAXSTART; i++)
50 for(int j=0; j < SAMPLERANGE; j++ )
52 fPFAmpVectors[i][j] = new double[100];
53 fPFTofVectors[i][j] = new double[100];
55 for(int k=0; k < 100; k++ )
57 fPFAmpVectors[i][j][k] = 0;
58 fPFTofVectors[i][j][k] = 0;
66 AliCaloRawAnalyzerPeakFinder::~AliCaloRawAnalyzerPeakFinder()
69 for(int i=0; i < MAXSTART; i++)
71 for(int j=0; j < SAMPLERANGE; j++ )
73 delete[] fPFAmpVectors[i][j];
74 delete[] fPFTofVectors[i][j];
81 AliCaloRawAnalyzerPeakFinder::Evaluate( const vector<AliCaloBunchInfo> &bunchvector, const UInt_t altrocfg1, const UInt_t altrocfg2 )
83 // Extracting the amplitude using the Peak-Finder algorithm
84 // The amplitude is a weighted sum of the samples using
87 short maxampindex; //index of maximum amplitude
88 short maxamp; //Maximum amplitude
94 int index = SelectBunch( bunchvector, &maxampindex, &maxamp );
98 Float_t ped = ReverseAndSubtractPed( &(bunchvector.at(index)) , altrocfg1, altrocfg2, fReversed );
99 Float_t maxf = TMath::MaxElement( bunchvector.at(index).GetLength(), fReversed );
101 if( maxf < fAmpCut || ( maxamp - ped) > 900 ) // (maxamp - ped) > 900 = Close to saturation (use low gain then)
103 // cout << __FILE__ << __LINE__ <<":, maxamp = " << maxamp << ", ped = "<< ped << ",. maxf = "<< maxf << ", maxampindex = "<< maxampindex << endl;
104 return AliCaloFitResults( maxamp, ped, -1, maxf, maxampindex, -1, -1 );
110 if ( maxf > fAmpCut )
112 SelectSubarray( fReversed, bunchvector.at(index).GetLength(), maxampindex - bunchvector.at(index).GetStartBin(), &first, &last);
113 int nsamples = last - first;
114 if( ( nsamples ) >= fNsampleCut )
116 int startbin = bunchvector.at(index).GetStartBin();
118 int pfindex = n - fNsampleCut;
119 pfindex = pfindex > SAMPLERANGE ? SAMPLERANGE : pfindex;
121 int dt = maxampindex - startbin -2;
122 for(int i=0; i < SAMPLERANGE; i++ )
125 // int dt = maxampindex - startbin -2;
127 // tmp[0] = fReversed[ dt +i -1];
128 // tmp[1] = fReversed[ dt +i];
129 // tmp[2] = fReversed[ dt +i +1];
131 for(int j = 0; j < 3; j++)
133 // fAmpA[j] += fPFAmpVectors[0][pfindex][i]*tmp[j];
134 fAmpA[j] += fPFAmpVectors[0][pfindex][i]*fReversed[ dt +i +j -1];
142 for(int k=0; k < 3; k ++)
144 // cout << __FILE__ << __LINE__ << "amp[="<< k <<"] = " << fAmpA[k] << endl;
145 if( TMath::Abs(fAmpA[k] - ( maxamp - ped) ) < diff)
147 diff = TMath::Abs(fAmpA[k] - ( maxamp - ped));
154 for(int k=0; k < SAMPLERANGE; k++ )
156 tof += fPFTofVectors[0][pfindex][k]*fReversed[ dt +k + tmpindex -1 ];
159 tof = tof / fAmpA[tmpindex];
161 return AliCaloFitResults( maxamp, ped , -1, fAmpA[tmpindex], tof, -2, -3 );
166 return AliCaloFitResults( maxamp, ped , -5, maxf, -6, -7, -8 );
171 // cout << __FILE__ << __LINE__ << "WARNING, returning amp = -1 " << endl;
173 return AliCaloFitResults(-1, -1);
178 AliCaloRawAnalyzerPeakFinder::LoadVectors()
180 //Read in the Peak finder vecors from file
181 for(int i = 0; i < MAXSTART ; i++)
183 for( int j=0; j < SAMPLERANGE; j++)
186 int n = j+fNsampleCut;
187 double start = (double)i+0.5;
188 sprintf(filename, "%s/EMCAL/vectors-emcal/start%.1fN%dtau0.235fs10dt1.0.txt", getenv("ALICE_ROOT"), start, n);
189 FILE *fp = fopen(filename, "r");
193 AliFatal( Form( "could not open file: %s", filename ) );
197 for(int m = 0; m < n ; m++ )
199 fscanf(fp, "%lf\t", &fPFAmpVectors[i][j][m] );
203 for(int m = 0; m < n ; m++ )
205 fPFTofVectors[i][j][m] = 1;
206 // fscanf(fp, "%lf\t", &fPFTofVectors[i][j][m] );