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 perthomas.hille@yale.edu *
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 **************************************************************************/
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.
29 #include "AliCaloRawAnalyzerPeakFinder.h"
30 #include "AliCaloBunchInfo.h"
31 #include "AliCaloFitResults.h"
34 #include "AliCDBEntry.h"
35 #include "AliCDBManager.h"
37 #include "AliCaloPeakFinderVectors.h"
42 ClassImp( AliCaloRawAnalyzerPeakFinder )
45 AliCaloRawAnalyzerPeakFinder::AliCaloRawAnalyzerPeakFinder() :AliCaloRawAnalyzer("Peak-Finder", "PF"),
47 fPeakFinderVectors(0),
51 InitOCDB(fRunOnAlien);
52 fPeakFinderVectors = new AliCaloPeakFinderVectors() ;
59 AliCaloRawAnalyzerPeakFinder::InitOCDB(bool alien) const
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);
68 AliCaloRawAnalyzerPeakFinder::ResetVectors()
71 for(int i=0; i < MAXSTART; i++)
73 for(int j=0; j < SAMPLERANGE; j++ )
75 for(int k=0; k < 100; k++ )
77 fPFAmpVectors[i][j][k] = 0;
78 fPFTofVectors[i][j][k] = 0;
79 fPFAmpVectorsCoarse[i][j][k] = 0;
80 fPFTofVectorsCoarse[i][j][k] = 0;
87 AliCaloRawAnalyzerPeakFinder::~AliCaloRawAnalyzerPeakFinder()
90 for(int i=0; i < MAXSTART; i++)
92 for(int j=0; j < SAMPLERANGE; j++ )
94 delete[] fPFAmpVectors[i][j];
95 delete[] fPFTofVectors[i][j];
96 delete[] fPFAmpVectorsCoarse[i][j];
97 delete[] fPFTofVectorsCoarse[i][j];
105 AliCaloRawAnalyzerPeakFinder::ScanCoarse(const Double_t *const array, const int length ) const
107 // Fisrt (coarce) estimate of Amplitude using the Peak-Finder.
108 // The output of the first iteration is sued to select vectors
109 // for the second iteration.
114 for(int i=0; i < length; i++)
116 tmpTof += fPFTofVectorsCoarse[0][length][i]*array[i];
117 tmpAmp += fPFAmpVectorsCoarse[0][length][i]*array[i];
120 tmpTof = tmpTof / tmpAmp ;
126 AliCaloRawAnalyzerPeakFinder::Evaluate( const vector<AliCaloBunchInfo> &bunchvector, const UInt_t altrocfg1, const UInt_t altrocfg2 )
128 // Extracting the amplitude using the Peak-Finder algorithm
129 // The amplitude is a weighted sum of the samples using
132 short maxampindex; //index of maximum amplitude
133 short maxamp; //Maximum amplitude
135 int index = SelectBunch( bunchvector, &maxampindex, &maxamp );
139 Float_t ped = ReverseAndSubtractPed( &(bunchvector.at(index)) , altrocfg1, altrocfg2, fReversed );
140 Float_t maxf = TMath::MaxElement( bunchvector.at(index).GetLength(), fReversed );
141 short timebinOffset = maxampindex - (bunchvector.at( index ).GetLength()-1);
143 if( maxf < fAmpCut || ( maxamp - ped) > fOverflowCut ) // (maxamp - ped) > fOverflowCut = Close to saturation (use low gain then)
145 return AliCaloFitResults( maxamp, ped, AliCaloFitResults::kCrude, maxf, timebinOffset);
147 else if ( maxf >= fAmpCut )
151 short maxrev = maxampindex - bunchvector.at(index).GetStartBin();
152 SelectSubarray( fReversed, bunchvector.at(index).GetLength(), maxrev, &first, &last);
153 int nsamples = last - first;
155 if( ( nsamples ) >= fNsampleCut ) // no if statement needed really; keep for readability
157 int startbin = bunchvector.at(index).GetStartBin();
158 int n = last - first;
159 int pfindex = n - fNsampleCut;
160 pfindex = pfindex > SAMPLERANGE ? SAMPLERANGE : pfindex;
162 int dt = maxampindex - startbin -2;
165 Float_t tmptof = ScanCoarse( &fReversed[dt] , n );
172 if( tmptof > -1 && tmptof < 100 )
183 for(int k=0; k < SAMPLERANGE; k++ )
185 tof += fPFTofVectors[0][pfindex][k]*fReversed[ dt +k + tmpindex -1 ];
188 for( int i=0; i < SAMPLERANGE; i++ )
191 fAmp += fPFAmpVectors[0][pfindex][i]*fReversed[ dt +i +tmpindex -1 ];
194 if( TMath::Abs( (maxf - fAmp )/maxf ) > 0.1 )
199 tof = timebinOffset - 0.01*tof/fAmp; // clock ticks
201 // use local-array time for chi2 estimate
202 Float_t chi2 = CalculateChi2(fAmp, tof-timebinOffset+maxrev, first, last);
203 Int_t ndf = last - first - 1; // nsamples - 2
204 return AliCaloFitResults( maxamp, ped , AliCaloFitResults::kFitPar, fAmp, tof,
205 timebinOffset, chi2, ndf,
206 AliCaloFitResults::kDummy, AliCaloFitSubarray(index, maxrev, first, last) );
210 Float_t chi2 = CalculateChi2(maxf, maxrev, first, last);
211 Int_t ndf = last - first - 1; // nsamples - 2
212 return AliCaloFitResults( maxamp, ped , AliCaloFitResults::kCrude, maxf, timebinOffset,
213 timebinOffset, chi2, ndf, AliCaloFitResults::kDummy, AliCaloFitSubarray(index, maxrev, first, last) );
217 return AliCaloFitResults(AliCaloFitResults::kInvalid, AliCaloFitResults::kInvalid);
222 AliCaloRawAnalyzerPeakFinder::CopyVectors(const AliCaloPeakFinderVectors *const pfv )
228 for(int i = 0; i < MAXSTART ; i++)
230 for( int j=0; j < SAMPLERANGE; j++)
232 pfv->GetVector( i, j, fPFAmpVectors[i][j] , fPFTofVectors[i][j],
233 fPFAmpVectorsCoarse[i][j] , fPFTofVectorsCoarse[i][j] );
234 fPeakFinderVectors->SetVector( i, j, fPFAmpVectors[i][j], fPFTofVectors[i][j],
235 fPFAmpVectorsCoarse[i][j], fPFTofVectorsCoarse[i][j] );
241 AliFatal( "pfv = ZERO !!!!!!!");
248 AliCaloRawAnalyzerPeakFinder::LoadVectorsOCDB()
250 //Loading of Peak-Finder vectors from the
251 //Offline Condition Database (OCDB)
252 AliCDBEntry* entry = AliCDBManager::Instance()->Get("EMCAL/Calib/PeakFinder/");
256 AliCaloPeakFinderVectors *pfv = (AliCaloPeakFinderVectors *)entry->GetObject();
263 AliCaloRawAnalyzerPeakFinder::LoadVectorsASCII()
265 //Read in the Peak finder vecors from ASCI files
266 for(int i = 0; i < MAXSTART ; i++)
268 for( int j=0; j < SAMPLERANGE; j++)
270 char filenameCoarse[256];
272 int n = j+fNsampleCut;
273 double start = (double)i+0;
275 sprintf(filename, "%s/EMCAL/vectors-emcal/start%.1fN%dtau0.235fs10dt1.0.txt", getenv("ALICE_ROOT"), start, n);
276 sprintf(filenameCoarse, "%s/EMCAL/vectors-emcal/start%.1fN%dtau0.235fs10dt3.0.txt", getenv("ALICE_ROOT"), start, n);
278 FILE *fp = fopen(filename, "r");
279 FILE *fpc = fopen(filenameCoarse, "r");
283 AliFatal( Form( "could not open file: %s", filename ) );
288 AliFatal( Form( "could not open file: %s", filenameCoarse ) );
292 for(int m = 0; m < n ; m++ )
294 fscanf(fp, "%lf\t", &fPFAmpVectors[i][j][m] );
295 fscanf(fpc, "%lf\t", &fPFAmpVectorsCoarse[i][j][m] );
299 for(int m = 0; m < n ; m++ )
301 fscanf(fp, "%lf\t", &fPFTofVectors[i][j][m] );
302 fscanf(fpc, "%lf\t", &fPFTofVectorsCoarse[i][j][m] );
305 fPeakFinderVectors->SetVector( i, j, fPFAmpVectors[i][j], fPFTofVectors[i][j],
306 fPFAmpVectorsCoarse[i][j], fPFTofVectorsCoarse[i][j] );
317 AliCaloRawAnalyzerPeakFinder::WriteRootFile() const
319 // Utility function to write Peak-Finder vectors to an root file
320 // The output is used to create an OCDB entry.
321 fPeakFinderVectors->PrintVectors();
322 TFile *f = new TFile("peakfindervectors2.root", "recreate" );
323 fPeakFinderVectors->Write();