]> git.uio.no Git - u/mrichter/AliRoot.git/blame - EMCAL/AliCaloRawAnalyzerLMS.cxx
updates for Reaction Plane and coverity fix
[u/mrichter/AliRoot.git] / EMCAL / AliCaloRawAnalyzerLMS.cxx
CommitLineData
d655d7dd 1/**************************************************************************
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 <p.t.hille@fys.uio.no> *
6 * *
7 * Contributors are mentioned in the code where appropriate. *
8 * Please report bugs to p.t.hille@fys.uio.no *
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
20// Extraction of amplitude and peak position
57839add 21// FRom CALO raw data using
d655d7dd 22// least square fit for the
23// Moment assuming identical and
24// independent errors (equivalent with chi square)
25//
26
57839add 27#include "AliCaloRawAnalyzerLMS.h"
28#include "AliCaloBunchInfo.h"
29#include "AliCaloFitResults.h"
d655d7dd 30#include "AliLog.h"
31#include "TMath.h"
507751ce 32#include <stdexcept>
d655d7dd 33#include <iostream>
34#include "TF1.h"
35#include "TGraph.h"
36
37using namespace std;
38
e37e3c84 39ClassImp( AliCaloRawAnalyzerLMS )
d655d7dd 40
396baaf6 41AliCaloRawAnalyzerLMS::AliCaloRawAnalyzerLMS() : AliCaloRawAnalyzerFitter("Chi Square Fit", "LMS")
d655d7dd 42{
168c7b3c 43 fAlgo = Algo::kLMS;
d655d7dd 44}
45
46
57839add 47AliCaloRawAnalyzerLMS::~AliCaloRawAnalyzerLMS()
d655d7dd 48{
396baaf6 49 // delete fTf1;
d655d7dd 50}
51
52
57839add 53AliCaloFitResults
54AliCaloRawAnalyzerLMS::Evaluate( const vector<AliCaloBunchInfo> &bunchvector, const UInt_t altrocfg1, const UInt_t altrocfg2 )
d655d7dd 55{
56 // Extracting signal parameters using fitting
57 short maxampindex; //index of maximum amplitude
58 short maxamp; //Maximum amplitude
59 int index = SelectBunch( bunchvector, &maxampindex, &maxamp );
60
61 if( index >= 0)
62 {
63 Float_t ped = ReverseAndSubtractPed( &(bunchvector.at(index)) , altrocfg1, altrocfg2, fReversed );
d655d7dd 64 Float_t maxf = TMath::MaxElement( bunchvector.at(index).GetLength(), fReversed );
f57baa2d 65 short maxrev = maxampindex - bunchvector.at(index).GetStartBin();
507751ce 66 // timebinOffset is timebin value at maximum (maxrev)
f57baa2d 67 short timebinOffset = maxampindex - (bunchvector.at(index).GetLength()-1);
2cd0ffda 68 if( maxf < fAmpCut || ( maxamp - ped) > fOverflowCut ) // (maxamp - ped) > fOverflowCut = Close to saturation (use low gain then)
d655d7dd 69 {
168c7b3c 70 return AliCaloFitResults( maxamp, ped, Ret::kCrude, maxf, timebinOffset);
2cd0ffda 71 }
72 else if ( maxf >= fAmpCut )
73 {
74 int first = 0;
75 int last = 0;
92d9f317 76 SelectSubarray( fReversed, bunchvector.at(index).GetLength(), maxrev, &first, &last, fFitArrayCut);
3b8fd9fe 77 int nsamples = last - first + 1;
d655d7dd 78
f57baa2d 79 if( ( nsamples ) >= fNsampleCut )
d655d7dd 80 {
507751ce 81 Float_t tmax = (maxrev - first); // local tmax estimate
3b8fd9fe 82 TGraph *graph = new TGraph( nsamples, fXaxis, &fReversed[first] );
d655d7dd 83 fTf1->SetParameter(0, maxf*fkEulerSquared );
507751ce 84 fTf1->SetParameter(1, tmax - fTau);
85 // set rather loose parameter limits
86 fTf1->SetParLimits(0, 0.5*maxf*fkEulerSquared, 2*maxf*fkEulerSquared );
87 fTf1->SetParLimits(1, tmax - fTau - 4, tmax - fTau + 4);
f57baa2d 88
89 if (fFixTau) {
90 fTf1->FixParameter(2, fTau);
91 }
92 else {
93 fTf1->ReleaseParameter(2); // allow par. to vary
94 fTf1->SetParameter(2, fTau);
95 }
d655d7dd 96
507751ce 97 Short_t tmpStatus = 0;
98 try {
99 tmpStatus = graph->Fit(fTf1, "Q0RW");
100 }
101 catch (const std::exception & e) {
102 AliError( Form("TGraph Fit exception %s", e.what()) );
168c7b3c 103 return AliCaloFitResults( maxamp, ped, Ret::kNoFit, maxf, timebinOffset,
104 timebinOffset, Ret::kDummy, Ret::kDummy, Ret::kDummy, AliCaloFitSubarray(index, maxrev, first, last) );
507751ce 105 }
106
d655d7dd 107 if( fVerbose == true )
108 {
57839add 109 AliCaloRawAnalyzer::PrintBunch( bunchvector.at(index) );
d655d7dd 110 PrintFitResult( fTf1 ) ;
111 }
507751ce 112 // global tmax
113 tmax = fTf1->GetParameter(1) + timebinOffset - (maxrev - first) // abs. t0
114 + fTf1->GetParameter(2); // +tau, makes sum tmax
d655d7dd 115
116 delete graph;
168c7b3c 117 return AliCaloFitResults( maxamp, ped , Ret::kFitPar,
f57baa2d 118 fTf1->GetParameter(0)/fkEulerSquared,
507751ce 119 tmax,
120 timebinOffset,
f57baa2d 121 fTf1->GetChisquare(),
122 fTf1->GetNDF(),
168c7b3c 123 Ret::kDummy, AliCaloFitSubarray(index, maxrev, first, last) );
d655d7dd 124 // delete graph;
125
126 }
127 else
128 {
92d9f317 129
2cd0ffda 130 Float_t chi2 = CalculateChi2(maxf, maxrev, first, last);
131 Int_t ndf = last - first - 1; // nsamples - 2
168c7b3c 132 return AliCaloFitResults( maxamp, ped, Ret::kCrude, maxf, timebinOffset,
133 timebinOffset, chi2, ndf, Ret::kDummy, AliCaloFitSubarray(index, maxrev, first, last) );
d655d7dd 134 }
2cd0ffda 135 } // ampcut
d655d7dd 136 }
168c7b3c 137 return AliCaloFitResults( Ret::kInvalid, Ret::kInvalid );
d655d7dd 138
139}
140