- return AliCaloFitResults(9999, 9999, 9999, 9999 , 9999, 9999, 9999 );
- }
-
- Int_t amp = 0;
- Float_t tof = -99;
- const UShort_t *sig;
-
- double ped = EvaluatePedestal( bunchvector.at(0).GetData(), bunchvector.at(0).GetLength() ) ;
+ Float_t ped = ReverseAndSubtractPed( &(bunchvector.at(index)) , altrocfg1, altrocfg2, fReversed );
+ Float_t maxf = TMath::MaxElement( bunchvector.at(index).GetLength(), fReversed );
+ short timebinOffset = maxampindex - (bunchvector.at(index).GetLength()-1);
+
+ if( maxf < fAmpCut || ( maxamp - ped) > fOverflowCut ) // (maxamp - ped) > fOverflowCut = Close to saturation (use low gain then)
+ {
+ return AliCaloFitResults( maxamp, ped, Ret::kCrude, maxf, timebinOffset);
+ }
+ else if ( maxf >= fAmpCut ) // no if statement needed really; keep for readability
+ {
+ int first = 0;
+ int last = 0;
+ int maxrev = maxampindex - bunchvector.at(index).GetStartBin();
+ SelectSubarray( fReversed, bunchvector.at(index).GetLength(), maxrev , &first, &last, fFitArrayCut );
+
+ Float_t chi2 = CalculateChi2(maxf, maxrev, first, last);
+ Int_t ndf = last - first - 1; // nsamples - 2
+ return AliCaloFitResults( maxamp, ped, Ret::kCrude, maxf, timebinOffset,
+ timebinOffset, chi2, ndf, Ret::kDummy, AliCaloFitSubarray(index, maxrev, first, last) );
+ } // ampcut
+ } // bunch index
+
+ return AliCaloFitResults( Ret::kInvalid , Ret::kInvalid);