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(),
44 fIsZerosupressed( false ),
48 sprintf(fName, "%s", name);
49 sprintf(fNameShort, "%s", nameshort);
51 for(int i=0; i < MAXSAMPLES; i++ )
57 AliCaloRawAnalyzer::~AliCaloRawAnalyzer()
64 AliCaloRawAnalyzer::SetTimeConstraint(const int min, const int max )
66 //Require that the bin if the maximum ADC value is between min and max (timebin)
67 if( ( min > max ) || min > MAXSAMPLES || max > MAXSAMPLES )
69 AliWarning( Form( "Attempt to set Invalid time bin range (Min , Max) = (%d, %d), Ingored", min, max ) );
80 AliCaloRawAnalyzer::Max(const UShort_t *data, const int length ) const
83 UShort_t tmpmax = data[0];
85 for(int i=0; i < length; i++)
87 if( tmpmax < data[i] )
97 AliCaloRawAnalyzer::SelectSubarray( const Double_t *fData, const int length, const short maxindex, int *const first, int *const last ) const
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 //Until the ADC value is less that fFitArrayCut, or derivative changes sign (data jump)
102 int tmpfirst = maxindex;
103 int tmplast = maxindex;
104 Double_t valFirst = fData[maxindex];
105 Double_t valLast = fData[maxindex];
107 while( (tmpfirst >= 0) && (fData[tmpfirst] >= fFitArrayCut) &&
108 (fData[tmpfirst]<valFirst || tmpfirst==maxindex) )
110 valFirst = fData[tmpfirst];
114 while( (tmplast < length) && (fData[tmplast] >= fFitArrayCut) &&
115 (fData[tmplast]<valLast || tmplast==maxindex) )
117 valLast = fData[tmplast];
121 *first = tmpfirst +1;
129 AliCaloRawAnalyzer::ReverseAndSubtractPed( const AliCaloBunchInfo *bunch, const UInt_t /*altrocfg1*/, const UInt_t /*altrocfg2*/, double *outarray ) const
131 //Time sample comes in reversed order, revers them back
132 //Subtract the baseline based on content of altrocfg1 and altrocfg2.
133 Int_t length = bunch->GetLength();
134 const UShort_t *sig = bunch->GetData();
136 double ped = EvaluatePedestal( sig , length);
138 for( int i=0; i < length; i++ )
140 outarray[i] = sig[length -i -1] - ped;
149 AliCaloRawAnalyzer::EvaluatePedestal(const UShort_t * const data, const int /*length*/ ) const
154 if( fIsZerosupressed == false )
156 for(int i=0; i < fNsamplePed; i++ )
162 return tmp/fNsamplePed;
167 AliCaloRawAnalyzer::Max( const AliCaloBunchInfo *const bunch , int *const maxindex ) const
172 const UShort_t *sig = bunch->GetData();
174 for(int i=0; i < bunch->GetLength(); i++ )
176 if( sig[i] > tmpmax )
185 // *maxindex = bunch->GetLength() -1 - tmpindex + bunch->GetStartBin();
186 *maxindex = bunch->GetLength() -1 - tmpindex + bunch->GetStartBin();
194 AliCaloRawAnalyzer::CheckBunchEdgesForMax( const AliCaloBunchInfo *const bunch ) const
196 // a bunch is considered invalid if the maximum is in the first or last time-bin
199 const UShort_t *sig = bunch->GetData();
201 for(int i=0; i < bunch->GetLength(); i++ )
203 if( sig[i] > tmpmax )
211 if (tmpindex == 0 || tmpindex == (bunch->GetLength()-1) )
221 AliCaloRawAnalyzer::SelectBunch( const vector<AliCaloBunchInfo> &bunchvector,short *const maxampbin, short *const maxamplitude ) const
223 //We select the bunch with the highest amplitude unless any time constraints is set
225 short bunchindex = -1;
229 for(unsigned int i=0; i < bunchvector.size(); i++ )
231 max = Max( &bunchvector.at(i), &indx ); // CRAP PTH, bug fix, trouble if more than one bunches
232 if( IsInTimeRange( indx) )
244 if (bunchindex >= 0) {
245 bool bunchOK = CheckBunchEdgesForMax( &bunchvector.at(bunchindex) );
256 AliCaloRawAnalyzer::IsInTimeRange( const int maxindex ) const
258 // Ckeck if the index of the max ADC vaue is consistent with trigger.
259 if( ( fMinTimeIndex < 0 && fMaxTimeIndex < 0) ||fMaxTimeIndex < 0 )
263 return ( maxindex < fMaxTimeIndex ) && ( maxindex > fMinTimeIndex ) ? true : false;
268 AliCaloRawAnalyzer::PrintBunches( const vector<AliCaloBunchInfo> &bvctr ) const
271 cout << __FILE__ << __LINE__<< "*************** Printing Bunches *******************" << endl;
272 cout << __FILE__ << __LINE__<< "*** There are " << bvctr.size() << ", bunches" << endl;
274 for(unsigned int i=0; i < bvctr.size() ; i++ )
276 PrintBunch( bvctr.at(i) );
277 cout << " bunch = " << i << endl;
279 cout << __FILE__ << __LINE__<< "*************** Done ... *******************" << endl;
284 AliCaloRawAnalyzer::PrintBunch( const AliCaloBunchInfo &bunch ) const
287 cout << __FILE__ << ":" << __LINE__ << endl;
288 cout << __FILE__ << __LINE__ << ", startimebin = " << bunch.GetStartBin() << ", length =" << bunch.GetLength() << endl;
289 const UShort_t *sig = bunch.GetData();
291 for ( Int_t j = 0; j < bunch.GetLength(); j++)
293 printf("%d\t", sig[j] );
300 AliCaloRawAnalyzer::Evaluate( const vector<AliCaloBunchInfo> &/*bunchvector*/, const UInt_t /*altrocfg1*/, const UInt_t /*altrocfg2*/)
301 { // method to do the selection of what should possibly be fitted
302 // not implemented for base class
303 return AliCaloFitResults( 0, 0 );
308 AliCaloRawAnalyzer::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)
309 { // method to do the selection of what should possibly be fitted
311 short maxampindex = 0;
312 index = SelectBunch( bunchvector, &maxampindex, &maxamp ); // select the bunch with the highest amplitude unless any time constraints is set
315 if( index >= 0 && maxamp > fAmpCut) // something valid was found, and non-zero amplitude
317 // use more convenient numbering and possibly subtract pedestal
318 ped = ReverseAndSubtractPed( &(bunchvector.at(index)), altrocfg1, altrocfg2, fReversed );
319 maxf = TMath::MaxElement( bunchvector.at(index).GetLength(), fReversed );
321 if ( maxf > fAmpCut ) // possibly significant signal
323 // select array around max to possibly be used in fit
324 maxrev = maxampindex - bunchvector.at(index).GetStartBin();
325 SelectSubarray( fReversed, bunchvector.at(index).GetLength(), maxrev, &first, &last);
327 // sanity check: maximum should not be in first or last bin
328 // if we should do a fit
329 if (first!=maxrev && last!=maxrev) {
330 // calculate how many samples we have
331 nsamples = last - first + 1;