1 /**************************************************************************
2 * This file is property of and copyright by *
3 * the Relativistic Heavy Ion Group (RHIG), Yale University, US, 2009 *
5 * Primary Author: Per Thomas Hille <perthomas.hille@yale.edu> *
7 * Contributors are mentioned in the code where appropriate. *
8 * Please report bugs to p.t.hille@fys.uio.no *
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 **************************************************************************/
20 // Base class for extraction
21 // of signal amplitude and peak position
22 // From CALO Calorimeter RAW data (from the RCU)
23 // Contains some utilities for preparing / selecting
24 // Signals suitable for signal extraction
28 #include "AliCaloRawAnalyzer.h"
29 #include "AliCaloBunchInfo.h"
30 #include "AliCaloFitResults.h"
35 //ClassImp(AliCaloRawAnalyzer)
37 AliCaloRawAnalyzer::AliCaloRawAnalyzer(const char *name, const char *nameshort) : TObject(),
43 fIsZerosupressed( false ),
47 sprintf(fName, "%s", name);
48 sprintf(fNameShort, "%s", nameshort);
50 for(int i=0; i < MAXSAMPLES; i++ )
56 AliCaloRawAnalyzer::~AliCaloRawAnalyzer()
63 AliCaloRawAnalyzer::SetTimeConstraint(const int min, const int max )
65 //Require that the bin if the maximum ADC value is between min and max (timebin)
66 if( ( min > max ) || min > MAXSAMPLES || max > MAXSAMPLES )
68 AliWarning( Form( "Attempt to set Invalid time bin range (Min , Max) = (%d, %d), Ingored", min, max ) );
79 AliCaloRawAnalyzer::Max(const UShort_t *data, const int length ) const
82 UShort_t tmpmax = data[0];
84 for(int i=0; i < length; i++)
86 if( tmpmax < data[i] )
96 AliCaloRawAnalyzer::SelectSubarray( const Double_t *fData, const int length, const short maxindex, int *const first, int *const last ) const
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;
104 while(( tmpfirst ) > 0 && ( fData[tmpfirst] > fFitArrayCut ))
109 while(( tmplast ) < length && ( fData [tmplast] > fFitArrayCut ))
114 *first = tmpfirst +1;
121 AliCaloRawAnalyzer::ReverseAndSubtractPed( const AliCaloBunchInfo *bunch, const UInt_t /*altrocfg1*/, const UInt_t /*altrocfg2*/, double *outarray ) const
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();
128 double ped = EvaluatePedestal( sig , length);
130 for( int i=0; i < length; i++ )
132 outarray[i] = sig[length -i -1] - ped;
141 AliCaloRawAnalyzer::EvaluatePedestal(const UShort_t * const data, const int /*length*/ ) const
146 if( fIsZerosupressed == false )
148 for(int i=0; i < 5; i++ )
154 // cout << __FILE__ << __LINE__ << "XXXXXXXXXXX returning " << tmp/5 << endl;
161 AliCaloRawAnalyzer::Max( const AliCaloBunchInfo *const bunch , int *const maxindex ) const
166 const UShort_t *sig = bunch->GetData();
168 for(int i=0; i < bunch->GetLength(); i++ )
170 if( sig[i] > tmpmax )
179 // *maxindex = bunch->GetLength() -1 - tmpindex + bunch->GetStartBin();
180 *maxindex = bunch->GetLength() -1 - tmpindex + bunch->GetStartBin();
188 AliCaloRawAnalyzer::SelectBunch( const vector<AliCaloBunchInfo> &bunchvector,short *const maxampbin, short *const maxamplitude ) const
190 //We select the bunch with the highest amplitude unless any time constraints is set
192 short bunchindex = -1;
196 for(unsigned int i=0; i < bunchvector.size(); i++ )
198 max = Max( &bunchvector.at(i), &indx ); // CRAP PTH, bug fix, trouble if more than one bunches
199 if( IsInTimeRange( indx) )
212 // *maxampbin = indx;
213 // *maxamplitude = max;
220 AliCaloRawAnalyzer::IsInTimeRange( const int maxindex ) const
222 // Ckeck if the index of the max ADC vaue is consistent with trigger.
223 if( ( fMinTimeIndex < 0 && fMaxTimeIndex < 0) ||fMaxTimeIndex < 0 )
227 return ( maxindex < fMaxTimeIndex ) && ( maxindex > fMinTimeIndex ) ? true : false;
232 AliCaloRawAnalyzer::PrintBunches( const vector<AliCaloBunchInfo> &bvctr ) const
235 cout << __FILE__ << __LINE__<< "*************** Printing Bunches *******************" << endl;
236 cout << __FILE__ << __LINE__<< "*** There are " << bvctr.size() << ", bunches" << endl;
238 for(unsigned int i=0; i < bvctr.size() ; i++ )
240 PrintBunch( bvctr.at(i) );
241 cout << " bunch = " << i << endl;
243 cout << __FILE__ << __LINE__<< "*************** Done ... *******************" << endl;
248 AliCaloRawAnalyzer::PrintBunch( const AliCaloBunchInfo &bunch ) const
251 cout << __FILE__ << ":" << __LINE__ << endl;
252 cout << __FILE__ << __LINE__ << ", startimebin = " << bunch.GetStartBin() << ", length =" << bunch.GetLength() << endl;
253 const UShort_t *sig = bunch.GetData();
255 for ( Int_t j = 0; j < bunch.GetLength(); j++)
257 printf("%d\t", sig[j] );
264 AliCaloRawAnalyzer::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 );
272 AliCaloRawAnalyzer::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
275 index = SelectBunch( bunchvector, &maxampindex, &maxamp ); // select the bunch with the highest amplitude unless any time constraints is set
278 if( index >= 0 && maxamp > fAmpCut) // something valid was found, and non-zero amplitude
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 );
284 if ( maxf > fAmpCut ) // possibly significant signal
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);
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;