]> git.uio.no Git - u/mrichter/AliRoot.git/blame - EMCAL/AliCaloRawAnalyzerPeakFinder.cxx
new NN tune from Paola
[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
40AliCaloRawAnalyzerPeakFinder::AliCaloRawAnalyzerPeakFinder() :AliCaloRawAnalyzer("Peak-Finder")
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];
54
55 for(int k=0; k < 100; k++ )
56 {
57 fPFAmpVectors[i][j][k] = 0;
58 fPFTofVectors[i][j][k] = 0;
59 }
60 }
61 }
62 LoadVectors();
63}
64
65
57839add 66AliCaloRawAnalyzerPeakFinder::~AliCaloRawAnalyzerPeakFinder()
d655d7dd 67{
68 //comment
69 for(int i=0; i < MAXSTART; i++)
70 {
71 for(int j=0; j < SAMPLERANGE; j++ )
72 {
73 delete[] fPFAmpVectors[i][j];
74 delete[] fPFTofVectors[i][j];
75 }
76 }
77}
78
79
57839add 80AliCaloFitResults
81AliCaloRawAnalyzerPeakFinder::Evaluate( const vector<AliCaloBunchInfo> &bunchvector, const UInt_t altrocfg1, const UInt_t altrocfg2 )
d655d7dd 82{
83 // Extracting the amplitude using the Peak-Finder algorithm
84 // The amplitude is a weighted sum of the samples using
85 // optimum weights.
86
87 short maxampindex; //index of maximum amplitude
88 short maxamp; //Maximum amplitude
e37e3c84 89 // fAmp = 0;
8ffb0474 90 fAmpA[0] = 0;
91 fAmpA[1] = 0;
92 fAmpA[2] = 0;
93
d655d7dd 94 int index = SelectBunch( bunchvector, &maxampindex, &maxamp );
95
96 if( index >= 0)
97 {
98 Float_t ped = ReverseAndSubtractPed( &(bunchvector.at(index)) , altrocfg1, altrocfg2, fReversed );
99 Float_t maxf = TMath::MaxElement( bunchvector.at(index).GetLength(), fReversed );
100
101 if( maxf < fAmpCut || ( maxamp - ped) > 900 ) // (maxamp - ped) > 900 = Close to saturation (use low gain then)
102 {
103 // cout << __FILE__ << __LINE__ <<":, maxamp = " << maxamp << ", ped = "<< ped << ",. maxf = "<< maxf << ", maxampindex = "<< maxampindex << endl;
57839add 104 return AliCaloFitResults( maxamp, ped, -1, maxf, maxampindex, -1, -1 );
d655d7dd 105 }
106
107 int first;
108 int last;
109
110 if ( maxf > fAmpCut )
111 {
112 SelectSubarray( fReversed, bunchvector.at(index).GetLength(), maxampindex - bunchvector.at(index).GetStartBin(), &first, &last);
113 int nsamples = last - first;
114 if( ( nsamples ) >= fNsampleCut )
115 {
116 int startbin = bunchvector.at(index).GetStartBin();
117 int n = last -first;
118 int pfindex = n - fNsampleCut;
119 pfindex = pfindex > SAMPLERANGE ? SAMPLERANGE : pfindex;
120
8ffb0474 121 int dt = maxampindex - startbin -2;
d655d7dd 122 for(int i=0; i < SAMPLERANGE; i++ )
123 {
8ffb0474 124
e37e3c84 125 // int dt = maxampindex - startbin -2;
8ffb0474 126 // double tmp[3];
e37e3c84 127 // tmp[0] = fReversed[ dt +i -1];
8ffb0474 128 // tmp[1] = fReversed[ dt +i];
129 // tmp[2] = fReversed[ dt +i +1];
130
131 for(int j = 0; j < 3; j++)
132 {
133 // fAmpA[j] += fPFAmpVectors[0][pfindex][i]*tmp[j];
134 fAmpA[j] += fPFAmpVectors[0][pfindex][i]*fReversed[ dt +i +j -1];
135
136 }
137 }
138
139 double diff = 9999;
8ffb0474 140 int tmpindex = 0;
141
142 for(int k=0; k < 3; k ++)
143 {
144 // cout << __FILE__ << __LINE__ << "amp[="<< k <<"] = " << fAmpA[k] << endl;
145 if( TMath::Abs(fAmpA[k] - ( maxamp - ped) ) < diff)
146 {
147 diff = TMath::Abs(fAmpA[k] - ( maxamp - ped));
148 tmpindex = k;
149 }
d655d7dd 150 }
151
8ffb0474 152 double tof = 0;
153
154 for(int k=0; k < SAMPLERANGE; k++ )
155 {
156 tof += fPFTofVectors[0][pfindex][k]*fReversed[ dt +k + tmpindex -1 ];
157 }
158
159 tof = tof / fAmpA[tmpindex];
160
8ffb0474 161 return AliCaloFitResults( maxamp, ped , -1, fAmpA[tmpindex], tof, -2, -3 );
d655d7dd 162 }
8ffb0474 163
d655d7dd 164 else
165 {
8ffb0474 166 return AliCaloFitResults( maxamp, ped , -5, maxf, -6, -7, -8 );
d655d7dd 167 }
168 }
169 }
170
171 // cout << __FILE__ << __LINE__ << "WARNING, returning amp = -1 " << endl;
172
57839add 173 return AliCaloFitResults(-1, -1);
d655d7dd 174}
175
176
177void
57839add 178AliCaloRawAnalyzerPeakFinder::LoadVectors()
d655d7dd 179{
180 //Read in the Peak finder vecors from file
181 for(int i = 0; i < MAXSTART ; i++)
182 {
183 for( int j=0; j < SAMPLERANGE; j++)
184 {
185 char filename[256];
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");
190
191 if(fp == 0)
192 {
193 AliFatal( Form( "could not open file: %s", filename ) );
194 }
195 else
196 {
197 for(int m = 0; m < n ; m++ )
198 {
199 fscanf(fp, "%lf\t", &fPFAmpVectors[i][j][m] );
200 }
201 fscanf(fp, "\n");
202
203 for(int m = 0; m < n ; m++ )
204 {
8ffb0474 205 fPFTofVectors[i][j][m] = 1;
206 // fscanf(fp, "%lf\t", &fPFTofVectors[i][j][m] );
d655d7dd 207 }
208
209 fclose (fp);
210 }
211 }
212 }
213}