row and col are correctly put in sigmaY
[u/mrichter/AliRoot.git] / EMCAL / AliCaloRawAnalyzer.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// Base class for extraction
21// of signal amplitude and peak position
57839add 22// From CALO Calorimeter RAW data (from the RCU)
d655d7dd 23// Contains some utilities for preparing / selecting
24// Signals suitable for signal extraction
25// By derived classes
26
27#include "AliLog.h"
57839add 28#include "AliCaloRawAnalyzer.h"
29#include "AliCaloBunchInfo.h"
30#include "AliCaloFitResults.h"
31#include "TMath.h"
d655d7dd 32#include <iostream>
33using namespace std;
34
35
57839add 36AliCaloRawAnalyzer::AliCaloRawAnalyzer() : TObject(),
d655d7dd 37 fMinTimeIndex(-1),
38 fMaxTimeIndex(-1),
39 fFitArrayCut(5),
40 fAmpCut(4),
41 fNsampleCut(5),
42 fIsZerosupressed( false ),
43 fVerbose( false )
44{
45 //Comment
46 for(int i=0; i < MAXSAMPLES; i++ )
47 {
48 fReversed[i] = 0;
49 }
50}
51
57839add 52AliCaloRawAnalyzer::~AliCaloRawAnalyzer()
d655d7dd 53{
54
55}
56
57
58void
57839add 59AliCaloRawAnalyzer::SetTimeConstraint(const int min, const int max )
d655d7dd 60{
61 //Require that the bin if the maximum ADC value is between min and max (timebin)
62 if( ( min > max ) || min > MAXSAMPLES || max > MAXSAMPLES )
63 {
64 AliWarning( Form( "Attempt to set Invalid time bin range (Min , Max) = (%d, %d), Ingored", min, max ) );
65 }
66 else
67 {
68 fMinTimeIndex = min;
69 fMaxTimeIndex = max;
70 }
71}
72
73
74UShort_t
57839add 75AliCaloRawAnalyzer::Max(const UShort_t *data, const int length ) const
d655d7dd 76{
77 //------------
78 UShort_t tmpmax = data[0];
79
80 for(int i=0; i < length; i++)
81 {
82 if( tmpmax < data[i] )
83 {
84 tmpmax = data[i];
85 }
86 }
87 return tmpmax;
88}
89
90
91void
57839add 92AliCaloRawAnalyzer::SelectSubarray( const Double_t *fData, const int length, const short maxindex, int *const first, int *const last ) const
d655d7dd 93{
94 //Selection of subset of data from one bunch that will be used for fitting or
95 //Peak finding. Go to the left and right of index of the maximum time bin
96 //Untile the ADC value is less that fFitArrayCut
97 int tmpfirst = maxindex;
98 int tmplast = maxindex;
99
100 while(( tmpfirst ) > 0 && ( fData[tmpfirst] > fFitArrayCut ))
101 {
102 tmpfirst -- ;
103 }
104
105 while(( tmplast ) < length && ( fData [tmplast] > fFitArrayCut ))
106 {
107 tmplast ++;
108 }
109
110 *first = tmpfirst +1;
111 *last = tmplast -1;
112}
113
114
115
116Float_t
57839add 117AliCaloRawAnalyzer::ReverseAndSubtractPed( const AliCaloBunchInfo *bunch, const UInt_t /*altrocfg1*/, const UInt_t /*altrocfg2*/, double *outarray ) const
d655d7dd 118{
119 //Time sample comes in reversed order, revers them back
120 //Subtract the baseline based on content of altrocfg1 and altrocfg2.
121 Int_t length = bunch->GetLength();
122 const UShort_t *sig = bunch->GetData();
123
57839add 124 double ped = EvaluatePedestal( sig , length);
125
126 for( int i=0; i < length; i++ )
127 {
128 outarray[i] = sig[length -i -1] - ped;
129 }
130
131 return ped;
132}
133
134
135
136Float_t
137AliCaloRawAnalyzer::EvaluatePedestal(const UShort_t * const data, const int /*length*/ ) const
138{
139 // double ped = 0;
d655d7dd 140 double tmp = 0;
141
142 if( fIsZerosupressed == false )
143 {
144 for(int i=0; i < 5; i++ )
145 {
57839add 146 tmp += data[i];
d655d7dd 147 }
148 }
57839add 149 return tmp/5;
d655d7dd 150}
151
152
153short
57839add 154AliCaloRawAnalyzer::Max( const AliCaloBunchInfo *const bunch , int *const maxindex ) const
d655d7dd 155{
156 //comment
157 short tmpmax = -1;
158 int tmpindex = -1;
159 const UShort_t *sig = bunch->GetData();
160
161 for(int i=0; i < bunch->GetLength(); i++ )
162 {
163 if( sig[i] > tmpmax )
164 {
165 tmpmax = sig[i];
166 tmpindex = i;
167 }
168 }
169
170 if(maxindex != 0 )
171 {
172 *maxindex = bunch->GetLength() -1 - tmpindex + bunch->GetStartBin();
173 }
174
175 return tmpmax;
176}
177
178
179int
57839add 180AliCaloRawAnalyzer::SelectBunch( const vector<AliCaloBunchInfo> &bunchvector,short *const maxampbin, short *const maxamplitude ) const
d655d7dd 181{
182 //We select the bunch with the highest amplitude unless any time constraints is set
183 short max = -1;
184 short bunchindex = -1;
185 short maxall = -1;
186 int indx = -1;
187
188 for(unsigned int i=0; i < bunchvector.size(); i++ )
189 {
190 max = Max( &bunchvector.at(i), &indx );
191 if( IsInTimeRange( indx) )
192 {
193 if( max > maxall )
194 {
195 maxall = max;
196 bunchindex = i;
197 }
198 }
199 }
200
201 *maxampbin = indx;
202 *maxamplitude = max;
203 return bunchindex;
204}
205
206
207bool
57839add 208AliCaloRawAnalyzer::IsInTimeRange( const int maxindex ) const
d655d7dd 209{
210 // Ckeck if the index of the max ADC vaue is consistent with trigger.
211 if( ( fMinTimeIndex < 0 && fMaxTimeIndex < 0) ||fMaxTimeIndex < 0 )
212 {
213 return true;
214 }
215 return ( maxindex < fMaxTimeIndex ) && ( maxindex > fMinTimeIndex ) ? true : false;
216}
217
218
219void
57839add 220AliCaloRawAnalyzer::PrintBunches( const vector<AliCaloBunchInfo> &bvctr ) const
d655d7dd 221{
222 //comment
223 cout << __FILE__ << __LINE__<< "*************** Printing Bunches *******************" << endl;
224 cout << __FILE__ << __LINE__<< "*** There are " << bvctr.size() << ", bunches" << endl;
225
226 for(unsigned int i=0; i < bvctr.size() ; i++ )
227 {
228 PrintBunch( bvctr.at(i) );
229 cout << " bunch = " << i << endl;
230 }
231 cout << __FILE__ << __LINE__<< "*************** Done ... *******************" << endl;
232}
233
234
235void
57839add 236AliCaloRawAnalyzer::PrintBunch( const AliCaloBunchInfo &bunch ) const
d655d7dd 237{
238 //comment
239 cout << __FILE__ << ":" << __LINE__ << endl;
240 cout << __FILE__ << __LINE__ << ", startimebin = " << bunch.GetStartBin() << ", length =" << bunch.GetLength() << endl;
241 const UShort_t *sig = bunch.GetData();
242
243 for ( Int_t j = 0; j < bunch.GetLength(); j++)
244 {
245 printf("%d\t", sig[j] );
246 }
247 cout << endl;
248}
249
250
57839add 251AliCaloFitResults
252AliCaloRawAnalyzer::Evaluate( const vector<AliCaloBunchInfo> &/*bunchvector*/, const UInt_t /*altrocfg1*/, const UInt_t /*altrocfg2*/)
253{ // method to do the selection of what should possibly be fitted
254 // not implemented for base class
255 return AliCaloFitResults( 0, 0, 0, 0, 0, 0, 0 );
256}
257
258
259int
260AliCaloRawAnalyzer::PreFitEvaluateSamples( const vector<AliCaloBunchInfo> &bunchvector, const UInt_t altrocfg1, const UInt_t altrocfg2, Int_t & index, Float_t & maxf, short & maxamp, short & maxampindex, Float_t & ped, int & first, int & last)
261{ // method to do the selection of what should possibly be fitted
262 int nsamples = 0;
263 index = SelectBunch( bunchvector, &maxampindex, &maxamp ); // select the bunch with the highest amplitude unless any time constraints is set
264
265
266 if( index >= 0 && maxamp > fAmpCut) // something valid was found, and non-zero amplitude
267 {
268 // use more convenient numbering and possibly subtract pedestal
269 ped = ReverseAndSubtractPed( &(bunchvector.at(index)), altrocfg1, altrocfg2, fReversed );
270 maxf = TMath::MaxElement( bunchvector.at(index).GetLength(), fReversed );
271
272 if ( maxf > fAmpCut ) // possibly significant signal
273 {
274 // select array around max to possibly be used in fit
275 maxampindex -= bunchvector.at(index).GetStartBin(); // PTH - why isn't this index also reversed for call below?
276 SelectSubarray( fReversed, bunchvector.at(index).GetLength(), maxampindex , &first, &last);
277
278 // sanity check: maximum should not be in first or last bin
279 // if we should do a fit
280 if (first!=maxampindex && last!=maxampindex) {
281 // calculate how many samples we have
282 nsamples = last - first + 1;
283 }
284 }
285 }
286
287 return nsamples;
288}
289