]> git.uio.no Git - u/mrichter/AliRoot.git/blob - EMCAL/AliCaloRawAnalyzerFastFit.cxx
fix mem leak - Marcel
[u/mrichter/AliRoot.git] / EMCAL / AliCaloRawAnalyzerFastFit.cxx
1 // -*- mode: c++ -*-
2 /**************************************************************************
3  * This file is property of and copyright by the Experimental Nuclear     *
4  * Physics Group, Dep. of Physics                                         *
5  * University of Oslo, Norway, 2007                                       *
6  *                                                                        *
7  * Author: Per Thomas Hille <perthi@fys.uio.no> for the ALICE HLT Project.*
8  * Contributors are mentioned in the code where appropriate.              *
9  * Please report bugs to perthi@fys.uio.no                                *
10  *                                                                        *
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  **************************************************************************/
19
20
21 // Extraction of Amplitude and peak
22 // position using specila algorithm
23 // from Alexei Pavlinov
24 // ----------------
25 // ----------------
26
27 #include "AliCaloRawAnalyzerFastFit.h"
28 #include "AliCaloFastAltroFitv0.h"
29 #include "AliCaloFitResults.h"
30 #include "AliCaloBunchInfo.h"
31 #include "TMath.h"
32 #include <iostream>
33
34 using namespace std;
35 #include "AliCaloConstants.h"
36
37 ClassImp( AliCaloRawAnalyzerFastFit )
38
39
40 AliCaloRawAnalyzerFastFit::AliCaloRawAnalyzerFastFit() : AliCaloRawAnalyzerFitter("Fast Fit (Alexei)", "FF")
41 {
42   // Comment
43   fAlgo= Algo::kFastFit;
44 }
45
46
47 AliCaloRawAnalyzerFastFit::~AliCaloRawAnalyzerFastFit()
48 {
49
50 }
51
52
53 AliCaloFitResults 
54 AliCaloRawAnalyzerFastFit::Evaluate( const vector<AliCaloBunchInfo> &bunchvector, 
55                                     const UInt_t altrocfg1,  const UInt_t altrocfg2 )
56 {
57   // Comment
58
59   short maxampindex; //index of maximum amplitude
60   short maxamp; //Maximum amplitude
61   int index = SelectBunch( bunchvector,  &maxampindex,  &maxamp );
62  
63   if( index >= 0)
64     {
65       Float_t ped = ReverseAndSubtractPed( &(bunchvector.at(index))  ,  altrocfg1, altrocfg2, fReversed  );
66       Float_t maxf = TMath::MaxElement( bunchvector.at(index).GetLength(),  fReversed );
67       short timebinOffset = maxampindex - (bunchvector.at(index).GetLength()-1);
68
69       if(  maxf < fAmpCut  ||  ( maxamp - ped) > fOverflowCut  ) // (maxamp - ped) > fOverflowCut = Close to saturation (use low gain then)
70         {
71           return  AliCaloFitResults( maxamp, ped, Algo::kCrude, maxf, timebinOffset);
72         }
73       else if ( maxf >= fAmpCut ) // no if statement needed really; keep for readability
74         {
75           int first = 0;
76           int last = 0;
77           int maxrev =  maxampindex -  bunchvector.at(index).GetStartBin();
78
79           SelectSubarray( fReversed,  bunchvector.at(index).GetLength(), maxrev , &first, &last, fFitArrayCut);
80
81           int nsamples =  last - first + 1;
82
83           if( ( nsamples  )  >= fNsampleCut )  
84             {
85               Double_t ordered[1008];
86
87               for(int i=0; i < nsamples ; i++ )
88                 {
89                   ordered[i] = fReversed[first + i];
90                 }
91
92               Double_t eSignal = 1; // nominal 1 ADC error
93               Double_t dAmp = maxf; 
94               Double_t eAmp = 0;
95               Double_t dTime0 = 0;
96               Double_t eTime = 0;
97               Double_t chi2 = 0;
98               Double_t dTau = 2.35; // time-bin units
99               
100               AliCaloFastAltroFitv0::FastFit(fXaxis, ordered , nsamples,
101                                              eSignal, dTau, dAmp, eAmp, dTime0, eTime, chi2);
102            
103               Double_t dTimeMax = dTime0 + timebinOffset - (maxrev - first) // abs. t0
104                 + dTau; // +tau, makes sum tmax
105               return AliCaloFitResults(maxamp, ped, Ret::kFitPar,  dAmp, dTimeMax, timebinOffset, chi2,  Ret::kDummy,
106                                        Ret::kDummy, AliCaloFitSubarray(index, maxrev, first, last) );
107             } // samplecut
108           else 
109             {
110               Float_t chi2 = CalculateChi2(maxf, maxrev, first, last);
111               Int_t ndf = last - first - 1; // nsamples - 2
112               return AliCaloFitResults( maxamp, ped, Ret::kCrude, maxf, timebinOffset,
113                                         timebinOffset, chi2, ndf, Ret::kDummy, AliCaloFitSubarray(index, maxrev, first, last) ); 
114             }
115         } // ampcut
116     } // bunch index    
117
118   return AliCaloFitResults( Ret::kInvalid , Ret::kInvalid );
119 }