AliRoot Core  3dc7879 (3dc7879)
AliCaloRawAnalyzerNN.cxx
Go to the documentation of this file.
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 
21 #include "AliCaloRawAnalyzerNN.h"
22 #include "AliCaloNeuralFit.h"
23 #include "AliCaloFitResults.h"
24 #include "AliCaloBunchInfo.h"
25 
26 #include <iostream>
27 using namespace std;
28 
29 #include "AliCaloConstants.h"
30 
32 ClassImp( AliCaloRawAnalyzerNN ) ;
34 
37 //____________________________________________
38 AliCaloRawAnalyzerNN::AliCaloRawAnalyzerNN() : AliCaloRawAnalyzer("Neural Network", "NN"), fNeuralNet(0)
39 {
41 
43 
44  for(int i=0; i < 5 ; i++)
45  {
46  fNNInput[i] = 0;
47  }
48 
49 }
50 
53 //____________________________________________
55 {
56  // Dtor
57  delete fNeuralNet;
58 }
59 
62 //____________________________________________
64 AliCaloRawAnalyzerNN::Evaluate( const vector<AliCaloBunchInfo> &bunchvector,
65  UInt_t altrocfg1, UInt_t altrocfg2 )
66 {
67  if( bunchvector.size() <= 0 )
68  {
69  // cout << __FILE__ << __LINE__<< " INVALID "<< endl;
70 
72  }
73 
74  short maxampindex;
75  short maxamp;
76 
77  int index = SelectBunch( bunchvector, &maxampindex , &maxamp ) ;
78 
79  if( index < 0 )
80  {
81  // cout << __FILE__ << __LINE__<< "INVALID !!!!!!" << endl;
83  }
84 
85  Float_t ped = ReverseAndSubtractPed( &(bunchvector.at( index ) ) , altrocfg1, altrocfg2, fReversed );
86  short timebinOffset = maxampindex - (bunchvector.at(index).GetLength()-1);
87  double maxf = maxamp - ped;
88  Float_t time = (timebinOffset*TIMEBINWITH)-fL1Phase;
89 
90  if( maxf < fAmpCut || maxamp > fOverflowCut ) // (maxamp - ped) > fOverflowCut = Close to saturation (use low gain then)
91  {
92  // cout << __FILE__ << __LINE__<< ": timebinOffset = " << timebinOffset << " maxf "<< maxf << endl;
93  return AliCaloFitResults( maxamp, ped, Ret::kCrude, maxf, time, (int)time, 0, 0, Ret::kDummy);
94  }
95 
96  int first = 0;
97  int last = 0;
98  short maxrev = maxampindex - bunchvector.at(index).GetStartBin();
99 
100  SelectSubarray( fReversed, bunchvector.at(index).GetLength(), maxrev , &first, &last, fFitArrayCut );
101 
102  Float_t chi2 = 0;
103  Int_t ndf = 0;
104  if(maxrev < 1000 )
105  {
106  if ( ( maxrev - first) < 2 && (last - maxrev ) < 2)
107  {
108  chi2 = CalculateChi2(maxf, maxrev, first, last);
109  ndf = last - first - 1; // nsamples - 2
110  // cout << __FILE__ << __LINE__<< ": timebinOffset = " << timebinOffset << " maxf\t"<< maxf <<endl;
111  return AliCaloFitResults( maxamp, ped, Ret::kCrude, maxf, time,
112  (int)time, chi2, ndf, Ret::kDummy, AliCaloFitSubarray(index, maxrev, first, last) );
113  }
114  else
115  {
116  for(int i=0; i < 5 ; i++)
117  {
118  fNNInput[i] = fReversed[maxrev-2 +i]/(maxamp -ped);
119  }
120 
121 
122  double amp = (maxamp - ped)*fNeuralNet->Value( 0, fNNInput[0], fNNInput[1], fNNInput[2], fNNInput[3], fNNInput[4]);
123  double tof = (fNeuralNet->Value( 1, fNNInput[0], fNNInput[1], fNNInput[2], fNNInput[3], fNNInput[4]) + timebinOffset ) ;
124 
125  // use local-array time for chi2 estimate
126  chi2 = CalculateChi2(amp, tof-timebinOffset+maxrev, first, last);
127  ndf = last - first - 1; // nsamples - 2
128  //cout << __FILE__ << __LINE__<< ": tof = " << tof << " amp" << amp <<endl;
129  Float_t toftime = (tof*TIMEBINWITH)-fL1Phase;
130  return AliCaloFitResults( maxamp, ped , Ret::kFitPar, amp , toftime, (int)toftime, chi2, ndf,
131  Ret::kDummy, AliCaloFitSubarray(index, maxrev, first, last) );
132  }
133  }
134 
135  chi2 = CalculateChi2(maxf, maxrev, first, last);
136  ndf = last - first - 1; // nsamples - 2
137 
138  // cout << __FILE__ << __LINE__<< ": timebinOffset = " << timebinOffset << " maxf ="<< maxf << endl;
139  return AliCaloFitResults( maxamp, ped, Ret::kCrude, maxf, time,
140  (int)time, chi2, ndf, Ret::kDummy, AliCaloFitSubarray(index, maxrev, first, last) );
141 
142 }
143 
144 
int fFitArrayCut
Cut on ADC value (after ped. subtraction) for signals used for fit.
Double_t Value(int index, Double_t in0, Double_t in1, Double_t in2, Double_t in3, Double_t in4)
Base class for extraction of signal amplitude and peak position.
int fOverflowCut
Value when ADC starts to saturate.
Container class to hold info from bunches/samples.
virtual AliCaloFitResults Evaluate(const std::vector< AliCaloBunchInfo > &bunchvector, UInt_t altrocfg1, UInt_t altrocfg2)
The evaluation of Peak position and amplitude using the Neural Network.
int SelectBunch(const std::vector< AliCaloBunchInfo > &bunchvector, short *maxampbin, short *maxamplitude)
We select the bunch with the highest amplitude unless any time constraints is set.
const double TIMEBINWITH
each sample is 100 ns
Container class to hold results from fitting.
Raw data fitting: Neural network.
Double_t chi2
Definition: AnalyzeLaser.C:7
Utility Class for Neural Network fit.
AliCaloNeuralFit * fNeuralNet
Pointer to the class whick actually implements the Neural Network for EMCAL.
Algo::fitAlgorithm fAlgo
Which algorithm to use.
void SelectSubarray(const Double_t *date, int length, short maxindex, int *first, int *last, int cut) const
Float_t ReverseAndSubtractPed(const AliCaloBunchInfo *bunch, UInt_t altrocfg1, UInt_t altrocfg2, double *outarray) const
Double_t fReversed[ALTROMAXSAMPLES]
Reversed sequence of samples (pedestalsubtracted)
Double_t CalculateChi2(const Double_t amp, const Double_t time, const Int_t first, const Int_t last, const Double_t adcErr=1, const Double_t tau=2.35) const
AliCaloRawAnalyzerNN()
Constructor.
Double_t fNNInput[5]
The 5 input Neurons to the network ( mix bin + to samples on each side )
Double_t fL1Phase
Phase of the ADC sampling clock relative to the LHC clock.
virtual ~AliCaloRawAnalyzerNN()
Destructor.