2 /**************************************************************************
3 * This file is property of and copyright by *
4 * the Relativistic Heavy Ion Group (RHIG), Yale University, US, 2009 *
6 * Primary Author: Per Thomas Hille <perthomas.hille@yale.edu> *
8 * Contributors are mentioned in the code where appropriate. *
9 * Please report bugs to perthomas.hille@yale.edu *
11 * Permission to use, copy, modify and distribute this software and its *
12 * documentation strictly for non-commercial purposes is hereby granted *
13 * without fee, provided that the above copyright notice appears in all *
14 * copies and that both the copyright notice and this permission notice *
15 * appear in the supporting documentation. The authors make no claims *
16 * about the suitability of this software for any purpose. It is *
17 * provided "as is" without express or implied warranty. *
18 **************************************************************************/
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 weights are calculated only once and the
25 // actual extraction of amplitude and peak position
26 // is done with a simple vector multiplication, allowing
27 // extremely 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"),
46 fPeakFinderVectors(0),
51 fAlgo= Algo::kPeakFinder;
52 fPeakFinderVectors = new AliCaloPeakFinderVectors() ;
58 AliCaloRawAnalyzerPeakFinder::ResetVectors()
61 for(int i=0; i < PF::MAXSTART; i++)
63 for(int j=0; j < PF::SAMPLERANGE; j++ )
65 for(int k=0; k < 100; k++ )
67 fPFAmpVectors[i][j][k] = 0;
68 fPFTofVectors[i][j][k] = 0;
69 fPFAmpVectorsCoarse[i][j][k] = 0;
70 fPFTofVectorsCoarse[i][j][k] = 0;
78 AliCaloRawAnalyzerPeakFinder::ScanCoarse(const Double_t *const array, const int length ) const
80 // Fisrt (coarce) estimate of Amplitude using the Peak-Finder.
81 // The output of the first iteration is sued to select vectors
82 // for the second iteration.
87 for(int i=0; i < length; i++)
89 tmpTof += fPFTofVectorsCoarse[0][length][i]*array[i];
90 tmpAmp += fPFAmpVectorsCoarse[0][length][i]*array[i];
93 tmpTof = tmpTof / tmpAmp ;
99 AliCaloRawAnalyzerPeakFinder::Evaluate( const vector<AliCaloBunchInfo> &bunchvector, const UInt_t altrocfg1, const UInt_t altrocfg2 )
101 // Evaluation of amplitude and TOF
102 if( fIsInitialized == false )
104 cout << __FILE__ << ":" << __LINE__ << "ERROR, peakfinder vectors not loaded" << endl;
105 return AliCaloFitResults(kInvalid, kInvalid);
108 // Extracting the amplitude using the Peak-Finder algorithm
109 // The amplitude is a weighted sum of the samples using
112 short maxampindex; //index of maximum amplitude
113 short maxamp; //Maximum amplitude
115 int index = SelectBunch( bunchvector, &maxampindex, &maxamp );
119 Float_t ped = ReverseAndSubtractPed( &(bunchvector.at(index)) , altrocfg1, altrocfg2, fReversed );
120 Float_t maxf = TMath::MaxElement( bunchvector.at(index).GetLength(), fReversed );
121 short timebinOffset = maxampindex - (bunchvector.at( index ).GetLength()-1);
123 if( maxf < fAmpCut || ( maxamp - ped) > fOverflowCut ) // (maxamp - ped) > fOverflowCut = Close to saturation (use low gain then)
125 return AliCaloFitResults( maxamp, ped, Ret::kCrude, maxf, timebinOffset);
127 else if ( maxf >= fAmpCut )
131 short maxrev = maxampindex - bunchvector.at(index).GetStartBin();
132 SelectSubarray( fReversed, bunchvector.at(index).GetLength(), maxrev, &first, &last, fFitArrayCut);
133 int nsamples = last - first;
135 if( ( nsamples ) >= fNsampleCut ) // no if statement needed really; keep for readability
137 int startbin = bunchvector.at(index).GetStartBin();
138 int n = last - first;
139 int pfindex = n - fNsampleCut;
140 pfindex = pfindex > PF::SAMPLERANGE ? PF::SAMPLERANGE : pfindex;
141 int dt = maxampindex - startbin -2;
143 Float_t tmptof = ScanCoarse( &fReversed[dt] , n );
150 if( tmptof > -1 && tmptof < 100 )
160 for(int k=0; k < PF::SAMPLERANGE; k++ )
162 tof += fPFTofVectors[0][pfindex][k]*fReversed[ dt +k + tmpindex -1 ];
164 for( int i=0; i < PF::SAMPLERANGE; i++ )
168 fAmp += fPFAmpVectors[0][pfindex][i]*fReversed[ dt +i +tmpindex -1 ];
172 if( TMath::Abs( (maxf - fAmp )/maxf ) > 0.1 )
177 tof = timebinOffset - 0.01*tof/fAmp - fL1Phase/TIMEBINWITH; // clock
178 Float_t chi2 = CalculateChi2(fAmp, tof-timebinOffset+maxrev, first, last);
179 Int_t ndf = last - first - 1; // nsamples - 2
180 return AliCaloFitResults( maxamp, ped , Ret::kFitPar, fAmp, tof,
181 timebinOffset, chi2, ndf,
182 Ret::kDummy, AliCaloFitSubarray(index, maxrev, first, last) );
186 Float_t chi2 = CalculateChi2(maxf, maxrev, first, last);
187 Int_t ndf = last - first - 1; // nsamples - 2
188 return AliCaloFitResults( maxamp, ped , Ret::kCrude, maxf, timebinOffset,
189 timebinOffset, chi2, ndf, Ret::kDummy, AliCaloFitSubarray(index, maxrev, first, last) );
193 return AliCaloFitResults(kInvalid, kInvalid);
198 AliCaloRawAnalyzerPeakFinder::CopyVectors( const AliCaloPeakFinderVectors *const pfv )
203 for(int i = 0; i < PF::MAXSTART ; i++)
205 for( int j=0; j < PF::SAMPLERANGE; j++)
207 pfv->GetVector( i, j, fPFAmpVectors[i][j] , fPFTofVectors[i][j],
208 fPFAmpVectorsCoarse[i][j] , fPFTofVectorsCoarse[i][j] );
210 fPeakFinderVectors->SetVector( i, j, fPFAmpVectors[i][j], fPFTofVectors[i][j],
211 fPFAmpVectorsCoarse[i][j], fPFTofVectorsCoarse[i][j] );
217 AliFatal( "pfv = ZERO !!!!!!!");
223 AliCaloRawAnalyzerPeakFinder::LoadVectorsOCDB()
225 //Loading of Peak-Finder vectors from the
226 //Offline Condition Database (OCDB)
227 AliCDBEntry* entry = AliCDBManager::Instance()->Get("EMCAL/Calib/PeakFinder/");
231 //cout << __FILE__ << ":" << __LINE__ << ": Printing metadata !! " << endl;
232 //entry->PrintMetaData();
233 AliCaloPeakFinderVectors *pfv = (AliCaloPeakFinderVectors *)entry->GetObject();
236 cout << __FILE__ << ":" << __LINE__ << "_ ERRROR " << endl;
242 fIsInitialized = true;
249 AliCaloRawAnalyzerPeakFinder::WriteRootFile() const
250 { // Utility function to write Peak-Finder vectors to an root file
251 // The output is used to create an OCDB entry.
252 fPeakFinderVectors->PrintVectors();
253 TFile *f = new TFile("peakfindervectors2.root", "recreate" );
254 fPeakFinderVectors->Write();
261 AliCaloRawAnalyzerPeakFinder::PrintVectors()
262 { // Utility function to write Peak-Finder vectors
263 for(int i=0; i < 20; i++)
265 for( int j = 0; j < PF::MAXSTART; j ++ )
267 for( int k=0; k < PF::SAMPLERANGE; k++ )
269 cout << fPFAmpVectors[j][k][i] << "\t" ;
274 cout << __FILE__ << ":" << __LINE__ << ":.... DONE !!" << endl;