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