]> git.uio.no Git - u/mrichter/AliRoot.git/blame - EMCAL/AliCaloRawAnalyzerPeakFinder.cxx
- switching MultFinder depending on 'ITS' in reconstruction recraw-local.C
[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. *
bab48e74 8 * Please report bugs to perthomas.hille@yale.edu *
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
bab48e74 19
d655d7dd 20// The Peak-Finder algorithm
21// The amplitude is extracted as a
22// weighted sum of the samples using the
23// best possible weights.
24// The wights is calculated only once and the
25// Actual extraction of amplitude and peak position
26// Is done with a simple vector multiplication, allowing for
27// Extreemely fast computations.
28
57839add 29#include "AliCaloRawAnalyzerPeakFinder.h"
30#include "AliCaloBunchInfo.h"
31#include "AliCaloFitResults.h"
d655d7dd 32#include "TMath.h"
33#include "AliLog.h"
bab48e74 34#include "AliCDBEntry.h"
35#include "AliCDBManager.h"
36#include "TFile.h"
37#include "AliCaloPeakFinderVectors.h"
d655d7dd 38
39using namespace std;
40
bab48e74 41
e37e3c84 42ClassImp( AliCaloRawAnalyzerPeakFinder )
43
bab48e74 44
45AliCaloRawAnalyzerPeakFinder::AliCaloRawAnalyzerPeakFinder() :AliCaloRawAnalyzer("Peak-Finder", "PF"),
46 fAmp(0),
fc7cd737 47 fPeakFinderVectors(0),
48 fRunOnAlien(false)
d655d7dd 49{
fc7cd737 50 //Comment
bab48e74 51 InitOCDB(fRunOnAlien);
52 fPeakFinderVectors = new AliCaloPeakFinderVectors() ;
53 ResetVectors();
54 LoadVectorsOCDB();
bab48e74 55}
56
57
58void
59AliCaloRawAnalyzerPeakFinder::InitOCDB(bool alien) const
60{
61 // Setting the default OCDB pathe depending on wether we work locally or on the GRID.
62 AliCDBManager::Instance()->SetDefaultStorage( alien == true ? "alien://$ALICE_ROOT/OCDB" : "local://$ALICE_ROOT/OCDB");
63 AliCDBManager::Instance()->SetRun(100);
64}
d655d7dd 65
d655d7dd 66
bab48e74 67void
68AliCaloRawAnalyzerPeakFinder::ResetVectors()
69{
fc7cd737 70 //As name implies
d655d7dd 71 for(int i=0; i < MAXSTART; i++)
72 {
73 for(int j=0; j < SAMPLERANGE; j++ )
74 {
d655d7dd 75 for(int k=0; k < 100; k++ )
76 {
77 fPFAmpVectors[i][j][k] = 0;
78 fPFTofVectors[i][j][k] = 0;
48a2e3eb 79 fPFAmpVectorsCoarse[i][j][k] = 0;
80 fPFTofVectorsCoarse[i][j][k] = 0;
d655d7dd 81 }
82 }
83 }
d655d7dd 84}
85
86
57839add 87AliCaloRawAnalyzerPeakFinder::~AliCaloRawAnalyzerPeakFinder()
d655d7dd 88{
89 //comment
d655d7dd 90}
91
92
bab48e74 93
48a2e3eb 94Double_t
95AliCaloRawAnalyzerPeakFinder::ScanCoarse(const Double_t *const array, const int length ) const
96{
bab48e74 97 // Fisrt (coarce) estimate of Amplitude using the Peak-Finder.
98 // The output of the first iteration is sued to select vectors
99 // for the second iteration.
100
48a2e3eb 101 Double_t tmpTof = 0;
102 Double_t tmpAmp= 0;
103
104 for(int i=0; i < length; i++)
105 {
106 tmpTof += fPFTofVectorsCoarse[0][length][i]*array[i];
107 tmpAmp += fPFAmpVectorsCoarse[0][length][i]*array[i];
108 }
109
110 tmpTof = tmpTof / tmpAmp ;
111 return tmpTof;
112}
113
114
57839add 115AliCaloFitResults
116AliCaloRawAnalyzerPeakFinder::Evaluate( const vector<AliCaloBunchInfo> &bunchvector, const UInt_t altrocfg1, const UInt_t altrocfg2 )
d655d7dd 117{
118 // Extracting the amplitude using the Peak-Finder algorithm
119 // The amplitude is a weighted sum of the samples using
120 // optimum weights.
121
122 short maxampindex; //index of maximum amplitude
123 short maxamp; //Maximum amplitude
bab48e74 124 fAmp = 0;
d655d7dd 125 int index = SelectBunch( bunchvector, &maxampindex, &maxamp );
48a2e3eb 126
d655d7dd 127 if( index >= 0)
128 {
129 Float_t ped = ReverseAndSubtractPed( &(bunchvector.at(index)) , altrocfg1, altrocfg2, fReversed );
130 Float_t maxf = TMath::MaxElement( bunchvector.at(index).GetLength(), fReversed );
f57baa2d 131 short timebinOffset = maxampindex - (bunchvector.at( index ).GetLength()-1);
132
2cd0ffda 133 if( maxf < fAmpCut || ( maxamp - ped) > fOverflowCut ) // (maxamp - ped) > fOverflowCut = Close to saturation (use low gain then)
d655d7dd 134 {
507751ce 135 return AliCaloFitResults( maxamp, ped, AliCaloFitResults::kCrude, maxf, timebinOffset);
2cd0ffda 136 }
137 else if ( maxf >= fAmpCut )
138 {
139 int first = 0;
140 int last = 0;
141 short maxrev = maxampindex - bunchvector.at(index).GetStartBin();
f57baa2d 142 SelectSubarray( fReversed, bunchvector.at(index).GetLength(), maxrev, &first, &last);
d655d7dd 143 int nsamples = last - first;
2cd0ffda 144
145 if( ( nsamples ) >= fNsampleCut ) // no if statement needed really; keep for readability
d655d7dd 146 {
147 int startbin = bunchvector.at(index).GetStartBin();
48a2e3eb 148 int n = last - first;
d655d7dd 149 int pfindex = n - fNsampleCut;
150 pfindex = pfindex > SAMPLERANGE ? SAMPLERANGE : pfindex;
151
8ffb0474 152 int dt = maxampindex - startbin -2;
8ffb0474 153 int tmpindex = 0;
154
48a2e3eb 155 Float_t tmptof = ScanCoarse( &fReversed[dt] , n );
156
157 if( tmptof < -1 )
158 {
159 tmpindex = 0;
160 }
161 else
162 if( tmptof > -1 && tmptof < 100 )
163 {
bab48e74 164 tmpindex = 1;
48a2e3eb 165 }
166 else
167 {
168 tmpindex = 2;
169 }
bab48e74 170
8ffb0474 171 double tof = 0;
48a2e3eb 172
8ffb0474 173 for(int k=0; k < SAMPLERANGE; k++ )
174 {
175 tof += fPFTofVectors[0][pfindex][k]*fReversed[ dt +k + tmpindex -1 ];
176 }
bab48e74 177
178 for( int i=0; i < SAMPLERANGE; i++ )
179 {
180 {
181 fAmp += fPFAmpVectors[0][pfindex][i]*fReversed[ dt +i +tmpindex -1 ];
182 }
183 }
bab48e74 184 if( TMath::Abs( (maxf - fAmp )/maxf ) > 0.1 )
48a2e3eb 185 {
bab48e74 186 fAmp = maxf;
48a2e3eb 187 }
48a2e3eb 188
bab48e74 189 tof = timebinOffset - 0.01*tof/fAmp; // clock ticks
f57baa2d 190
2cd0ffda 191 // use local-array time for chi2 estimate
192 Float_t chi2 = CalculateChi2(fAmp, tof-timebinOffset+maxrev, first, last);
193 Int_t ndf = last - first - 1; // nsamples - 2
bab48e74 194 return AliCaloFitResults( maxamp, ped , AliCaloFitResults::kFitPar, fAmp, tof,
2cd0ffda 195 timebinOffset, chi2, ndf,
f57baa2d 196 AliCaloFitResults::kDummy, AliCaloFitSubarray(index, maxrev, first, last) );
d655d7dd 197 }
198 else
199 {
2cd0ffda 200 Float_t chi2 = CalculateChi2(maxf, maxrev, first, last);
201 Int_t ndf = last - first - 1; // nsamples - 2
202 return AliCaloFitResults( maxamp, ped , AliCaloFitResults::kCrude, maxf, timebinOffset,
203 timebinOffset, chi2, ndf, AliCaloFitResults::kDummy, AliCaloFitSubarray(index, maxrev, first, last) );
d655d7dd 204 }
2cd0ffda 205 } // ampcut
d655d7dd 206 }
f57baa2d 207 return AliCaloFitResults(AliCaloFitResults::kInvalid, AliCaloFitResults::kInvalid);
d655d7dd 208}
209
210
bab48e74 211void
212AliCaloRawAnalyzerPeakFinder::CopyVectors(const AliCaloPeakFinderVectors *const pfv )
213{
214 // As name implies
215
216 if ( pfv != 0)
217 {
218 for(int i = 0; i < MAXSTART ; i++)
219 {
220 for( int j=0; j < SAMPLERANGE; j++)
221 {
222 pfv->GetVector( i, j, fPFAmpVectors[i][j] , fPFTofVectors[i][j],
223 fPFAmpVectorsCoarse[i][j] , fPFTofVectorsCoarse[i][j] );
224 fPeakFinderVectors->SetVector( i, j, fPFAmpVectors[i][j], fPFTofVectors[i][j],
225 fPFAmpVectorsCoarse[i][j], fPFTofVectorsCoarse[i][j] );
226 }
227 }
228 }
229 else
230 {
231 AliFatal( "pfv = ZERO !!!!!!!");
bab48e74 232 }
233}
234
235
236
237void
238AliCaloRawAnalyzerPeakFinder::LoadVectorsOCDB()
239{
240 //Loading of Peak-Finder vectors from the
241 //Offline Condition Database (OCDB)
bab48e74 242 AliCDBEntry* entry = AliCDBManager::Instance()->Get("EMCAL/Calib/PeakFinder/");
bab48e74 243
244 if( entry != 0 )
245 {
246 AliCaloPeakFinderVectors *pfv = (AliCaloPeakFinderVectors *)entry->GetObject();
247 CopyVectors( pfv );
fc7cd737 248 }
bab48e74 249}
250
251
d655d7dd 252void
bab48e74 253AliCaloRawAnalyzerPeakFinder::LoadVectorsASCII()
d655d7dd 254{
bab48e74 255 //Read in the Peak finder vecors from ASCI files
d655d7dd 256 for(int i = 0; i < MAXSTART ; i++)
257 {
258 for( int j=0; j < SAMPLERANGE; j++)
259 {
48a2e3eb 260 char filenameCoarse[256];
d655d7dd 261 char filename[256];
48a2e3eb 262 int n = j+fNsampleCut;
48a2e3eb 263 double start = (double)i+0;
bab48e74 264
48a2e3eb 265 sprintf(filename, "%s/EMCAL/vectors-emcal/start%.1fN%dtau0.235fs10dt1.0.txt", getenv("ALICE_ROOT"), start, n);
266 sprintf(filenameCoarse, "%s/EMCAL/vectors-emcal/start%.1fN%dtau0.235fs10dt3.0.txt", getenv("ALICE_ROOT"), start, n);
bab48e74 267
48a2e3eb 268 FILE *fp = fopen(filename, "r");
269 FILE *fpc = fopen(filenameCoarse, "r");
270
271 if( fp == 0 )
d655d7dd 272 {
273 AliFatal( Form( "could not open file: %s", filename ) );
274 }
48a2e3eb 275
276 if(fpc == 0)
277 {
278 AliFatal( Form( "could not open file: %s", filenameCoarse ) );
279 }
d655d7dd 280 else
281 {
282 for(int m = 0; m < n ; m++ )
283 {
bab48e74 284 fscanf(fp, "%lf\t", &fPFAmpVectors[i][j][m] );
48a2e3eb 285 fscanf(fpc, "%lf\t", &fPFAmpVectorsCoarse[i][j][m] );
d655d7dd 286 }
48a2e3eb 287 fscanf(fp, "\n" );
288 fscanf(fpc, "\n" );
d655d7dd 289 for(int m = 0; m < n ; m++ )
290 {
48a2e3eb 291 fscanf(fp, "%lf\t", &fPFTofVectors[i][j][m] );
292 fscanf(fpc, "%lf\t", &fPFTofVectorsCoarse[i][j][m] );
d655d7dd 293 }
294
bab48e74 295 fPeakFinderVectors->SetVector( i, j, fPFAmpVectors[i][j], fPFTofVectors[i][j],
296 fPFAmpVectorsCoarse[i][j], fPFTofVectorsCoarse[i][j] );
297
d655d7dd 298 fclose (fp);
48a2e3eb 299 fclose (fpc);
d655d7dd 300 }
301 }
302 }
303}
48a2e3eb 304
305
bab48e74 306void
307AliCaloRawAnalyzerPeakFinder::WriteRootFile() const
48a2e3eb 308{
bab48e74 309 // Utility function to write Peak-Finder vectors to an root file
310 // The output is used to create an OCDB entry.
bab48e74 311 fPeakFinderVectors->PrintVectors();
bab48e74 312 TFile *f = new TFile("peakfindervectors2.root", "recreate" );
313 fPeakFinderVectors->Write();
314 f->Close();
315 delete f;
48a2e3eb 316}