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) : TObject(),
43 fIsZerosupressed( false ),
47 sprintf(fName, "%s", name);
48 for(int i=0; i < MAXSAMPLES; i++ )
54 AliCaloRawAnalyzer::~AliCaloRawAnalyzer()
61 AliCaloRawAnalyzer::SetTimeConstraint(const int min, const int max )
63 //Require that the bin if the maximum ADC value is between min and max (timebin)
64 if( ( min > max ) || min > MAXSAMPLES || max > MAXSAMPLES )
66 AliWarning( Form( "Attempt to set Invalid time bin range (Min , Max) = (%d, %d), Ingored", min, max ) );
77 AliCaloRawAnalyzer::Max(const UShort_t *data, const int length ) const
80 UShort_t tmpmax = data[0];
82 for(int i=0; i < length; i++)
84 if( tmpmax < data[i] )
94 AliCaloRawAnalyzer::SelectSubarray( const Double_t *fData, const int length, const short maxindex, int *const first, int *const last ) const
96 //Selection of subset of data from one bunch that will be used for fitting or
97 //Peak finding. Go to the left and right of index of the maximum time bin
98 //Untile the ADC value is less that fFitArrayCut
99 int tmpfirst = maxindex;
100 int tmplast = maxindex;
102 while(( tmpfirst ) > 0 && ( fData[tmpfirst] > fFitArrayCut ))
107 while(( tmplast ) < length && ( fData [tmplast] > fFitArrayCut ))
112 *first = tmpfirst +1;
119 AliCaloRawAnalyzer::ReverseAndSubtractPed( const AliCaloBunchInfo *bunch, const UInt_t /*altrocfg1*/, const UInt_t /*altrocfg2*/, double *outarray ) const
121 //Time sample comes in reversed order, revers them back
122 //Subtract the baseline based on content of altrocfg1 and altrocfg2.
123 Int_t length = bunch->GetLength();
124 const UShort_t *sig = bunch->GetData();
126 double ped = EvaluatePedestal( sig , length);
128 for( int i=0; i < length; i++ )
130 outarray[i] = sig[length -i -1] - ped;
139 AliCaloRawAnalyzer::EvaluatePedestal(const UShort_t * const data, const int /*length*/ ) const
144 if( fIsZerosupressed == false )
146 for(int i=0; i < 5; i++ )
152 // cout << __FILE__ << __LINE__ << "XXXXXXXXXXX returning " << tmp/5 << endl;
159 AliCaloRawAnalyzer::Max( const AliCaloBunchInfo *const bunch , int *const maxindex ) const
164 const UShort_t *sig = bunch->GetData();
166 for(int i=0; i < bunch->GetLength(); i++ )
168 if( sig[i] > tmpmax )
177 *maxindex = bunch->GetLength() -1 - tmpindex + bunch->GetStartBin();
185 AliCaloRawAnalyzer::SelectBunch( const vector<AliCaloBunchInfo> &bunchvector,short *const maxampbin, short *const maxamplitude ) const
187 //We select the bunch with the highest amplitude unless any time constraints is set
189 short bunchindex = -1;
193 for(unsigned int i=0; i < bunchvector.size(); i++ )
195 max = Max( &bunchvector.at(i), &indx );
196 if( IsInTimeRange( indx) )
213 AliCaloRawAnalyzer::IsInTimeRange( const int maxindex ) const
215 // Ckeck if the index of the max ADC vaue is consistent with trigger.
216 if( ( fMinTimeIndex < 0 && fMaxTimeIndex < 0) ||fMaxTimeIndex < 0 )
220 return ( maxindex < fMaxTimeIndex ) && ( maxindex > fMinTimeIndex ) ? true : false;
225 AliCaloRawAnalyzer::PrintBunches( const vector<AliCaloBunchInfo> &bvctr ) const
228 cout << __FILE__ << __LINE__<< "*************** Printing Bunches *******************" << endl;
229 cout << __FILE__ << __LINE__<< "*** There are " << bvctr.size() << ", bunches" << endl;
231 for(unsigned int i=0; i < bvctr.size() ; i++ )
233 PrintBunch( bvctr.at(i) );
234 cout << " bunch = " << i << endl;
236 cout << __FILE__ << __LINE__<< "*************** Done ... *******************" << endl;
241 AliCaloRawAnalyzer::PrintBunch( const AliCaloBunchInfo &bunch ) const
244 cout << __FILE__ << ":" << __LINE__ << endl;
245 cout << __FILE__ << __LINE__ << ", startimebin = " << bunch.GetStartBin() << ", length =" << bunch.GetLength() << endl;
246 const UShort_t *sig = bunch.GetData();
248 for ( Int_t j = 0; j < bunch.GetLength(); j++)
250 printf("%d\t", sig[j] );
256 AliCaloRawAnalyzer::Evaluate( const vector<AliCaloBunchInfo> &/*bunchvector*/, const UInt_t /*altrocfg1*/, const UInt_t /*altrocfg2*/)
257 { // method to do the selection of what should possibly be fitted
258 // not implemented for base class
259 return AliCaloFitResults( 0, 0, 0, 0, 0, 0, 0 );
263 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)
264 { // method to do the selection of what should possibly be fitted
266 index = SelectBunch( bunchvector, &maxampindex, &maxamp ); // select the bunch with the highest amplitude unless any time constraints is set
269 if( index >= 0 && maxamp > fAmpCut) // something valid was found, and non-zero amplitude
271 // use more convenient numbering and possibly subtract pedestal
272 ped = ReverseAndSubtractPed( &(bunchvector.at(index)), altrocfg1, altrocfg2, fReversed );
273 maxf = TMath::MaxElement( bunchvector.at(index).GetLength(), fReversed );
275 if ( maxf > fAmpCut ) // possibly significant signal
277 // select array around max to possibly be used in fit
278 maxampindex -= bunchvector.at(index).GetStartBin(); // PTH - why isn't this index also reversed for call below?
279 SelectSubarray( fReversed, bunchvector.at(index).GetLength(), maxampindex , &first, &last);
281 // sanity check: maximum should not be in first or last bin
282 // if we should do a fit
283 if (first!=maxampindex && last!=maxampindex) {
284 // calculate how many samples we have
285 nsamples = last - first + 1;