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