]> git.uio.no Git - u/mrichter/AliRoot.git/blame - EMCAL/AliCaloRawAnalyzerNN.cxx
Merge remote-tracking branch 'origin/master' into mergingFlat
[u/mrichter/AliRoot.git] / EMCAL / AliCaloRawAnalyzerNN.cxx
CommitLineData
e37e3c84 1/**************************************************************************
2 * This file is property of and copyright by the Experimental Nuclear *
3 * Physics Group, Dep. of Physics *
4 * University of Oslo, Norway, 2007 *
5 * *
6 * Author: Per Thomas Hille <perthomas.hille@yale.edu> *
7 * 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// Evaluation of peak position
21// and amplitude using Neural Networks (NN)
22// ------------------
23// ------------------
24// ------------------
25
26
27#include "AliCaloRawAnalyzerNN.h"
28#include "AliCaloNeuralFit.h"
29#include "AliCaloFitResults.h"
30#include "AliCaloBunchInfo.h"
e37e3c84 31#include <iostream>
e37e3c84 32using namespace std;
33
168c7b3c 34#include "AliCaloConstants.h"
35
e37e3c84 36ClassImp( AliCaloRawAnalyzerNN )
37
48a2e3eb 38AliCaloRawAnalyzerNN::AliCaloRawAnalyzerNN() : AliCaloRawAnalyzer("Neural Network", "NN"), fNeuralNet(0)
e37e3c84 39{
6656f267 40 // Ctor
41
168c7b3c 42 fAlgo=Algo::kNeuralNet;
e37e3c84 43
44 fNeuralNet = new AliCaloNeuralFit();
45
46 for(int i=0; i < 5 ; i++)
47 {
48 fNNInput[i] = 0;
49 }
50
51}
52
53
54AliCaloRawAnalyzerNN::~AliCaloRawAnalyzerNN()
55{
6656f267 56 // Dtor
e37e3c84 57 delete fNeuralNet;
58}
59
60
61AliCaloFitResults
62AliCaloRawAnalyzerNN::Evaluate( const vector<AliCaloBunchInfo> &bunchvector,
6656f267 63 UInt_t altrocfg1, UInt_t altrocfg2 )
e37e3c84 64{
65 // The eveluation of Peak position and amplitude using the Neural Network
66 if( bunchvector.size() <= 0 )
67 {
92d9f317 68 // cout << __FILE__ << __LINE__<< " INVALID "<< endl;
69
168c7b3c 70 return AliCaloFitResults( Ret::kInvalid, Ret::kInvalid);
e37e3c84 71 }
72
f57baa2d 73 short maxampindex;
e37e3c84 74 short maxamp;
75
f57baa2d 76 int index = SelectBunch( bunchvector, &maxampindex , &maxamp ) ;
e37e3c84 77
f57baa2d 78 if( index < 0 )
e37e3c84 79 {
92d9f317 80 // cout << __FILE__ << __LINE__<< "INVALID !!!!!!" << endl;
168c7b3c 81 return AliCaloFitResults( Ret::kInvalid, Ret::kInvalid);
e37e3c84 82 }
83
2cd0ffda 84 Float_t ped = ReverseAndSubtractPed( &(bunchvector.at( index ) ) , altrocfg1, altrocfg2, fReversed );
f57baa2d 85 short timebinOffset = maxampindex - (bunchvector.at(index).GetLength()-1);
86 double maxf = maxamp - ped;
87
2cd0ffda 88 if( maxf < fAmpCut || ( maxamp - ped) > fOverflowCut ) // (maxamp - ped) > fOverflowCut = Close to saturation (use low gain then)
89 {
92d9f317 90 // cout << __FILE__ << __LINE__<< ": timebinOffset = " << timebinOffset << " maxf "<< maxf << endl;
168c7b3c 91 return AliCaloFitResults( maxamp, ped, Ret::kCrude, maxf, timebinOffset);
2cd0ffda 92 }
93
94 int first = 0;
95 int last = 0;
96 short maxrev = maxampindex - bunchvector.at(index).GetStartBin();
92d9f317 97 SelectSubarray( fReversed, bunchvector.at(index).GetLength(), maxrev , &first, &last, fFitArrayCut );
e37e3c84 98
2cd0ffda 99 Float_t chi2 = 0;
100 Int_t ndf = 0;
e37e3c84 101 if(maxrev < 1000 )
102 {
103 if ( ( maxrev - first) < 2 && (last - maxrev ) < 2)
104 {
2cd0ffda 105 chi2 = CalculateChi2(maxf, maxrev, first, last);
106 ndf = last - first - 1; // nsamples - 2
92d9f317 107 // cout << __FILE__ << __LINE__<< ": timebinOffset = " << timebinOffset << " maxf\t"<< maxf <<endl;
168c7b3c 108 return AliCaloFitResults( maxamp, ped, Ret::kCrude, maxf, timebinOffset,
109 timebinOffset, chi2, ndf, Ret::kDummy, AliCaloFitSubarray(index, maxrev, first, last) );
e37e3c84 110 }
111 else
112 {
e37e3c84 113
114 for(int i=0; i < 5 ; i++)
115 {
116 fNNInput[i] = fReversed[maxrev-2 +i]/(maxamp -ped);
117 }
118
3b8fd9fe 119
a9ebbc7a 120 double amp = (maxamp - ped)*fNeuralNet->Value( 0, fNNInput[0], fNNInput[1], fNNInput[2], fNNInput[3], fNNInput[4]);
3b8fd9fe 121 double tof = (fNeuralNet->Value( 1, fNNInput[0], fNNInput[1], fNNInput[2], fNNInput[3], fNNInput[4]) + timebinOffset ) ;
e37e3c84 122
2cd0ffda 123 // use local-array time for chi2 estimate
124 chi2 = CalculateChi2(amp, tof-timebinOffset+maxrev, first, last);
125 ndf = last - first - 1; // nsamples - 2
92d9f317 126 //cout << __FILE__ << __LINE__<< ": tof = " << tof << " amp" << amp <<endl;
168c7b3c 127 return AliCaloFitResults( maxamp, ped , Ret::kFitPar, amp , tof, timebinOffset, chi2, ndf,
128 Ret::kDummy, AliCaloFitSubarray(index, maxrev, first, last) );
e37e3c84 129
130 }
131 }
2cd0ffda 132 chi2 = CalculateChi2(maxf, maxrev, first, last);
133 ndf = last - first - 1; // nsamples - 2
92d9f317 134
135 // cout << __FILE__ << __LINE__<< ": timebinOffset = " << timebinOffset << " maxf ="<< maxf << endl;
168c7b3c 136 return AliCaloFitResults( maxamp, ped, Ret::kCrude, maxf, timebinOffset,
137 timebinOffset, chi2, ndf, Ret::kDummy, AliCaloFitSubarray(index, maxrev, first, last) );
2cd0ffda 138
e37e3c84 139}
140
e37e3c84 141