]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - EMCAL/AliCaloRawAnalyzerCrude.cxx
fix coverity 24283
[u/mrichter/AliRoot.git] / EMCAL / AliCaloRawAnalyzerCrude.cxx
index 0ddd36e25961f0b0e2e3b70913c33410715faaff..a753498dba0645ffcf99c4246148cdae101ef0e9 100644 (file)
  * about the suitability of this software for any purpose. It is          *
  * provided "as is" without express or implied warranty.                  *
  **************************************************************************/
+
+// Evaluation of amplitude
+// as max sample value - pedestal
+// Not veru accurate, but very robust
+// --------------
+// --------------
+
 #include "AliCaloRawAnalyzerCrude.h"
 #include "AliCaloFitResults.h"
 #include "AliCaloBunchInfo.h"
+#include "TMath.h"
+using namespace std;
 
+ClassImp(AliCaloRawAnalyzerCrude)  
 
-AliCaloRawAnalyzerCrude::AliCaloRawAnalyzerCrude()
-{
 
+AliCaloRawAnalyzerCrude::AliCaloRawAnalyzerCrude() : AliCaloRawAnalyzer("Crude", "Crude")
+{
+  //Comment
+  fAlgo=Algo::kCrude;
 }
 
 
 AliCaloRawAnalyzerCrude::~AliCaloRawAnalyzerCrude()
 {
-
+  //Comment
 }
 
 
 AliCaloFitResults
-AliCaloRawAnalyzerCrude::Evaluate(const vector<AliCaloBunchInfo> &bunchvector, const UInt_t /*altrocfg1*/,  const UInt_t /*altrocfg2*/)
+AliCaloRawAnalyzerCrude::Evaluate(const vector<AliCaloBunchInfo> &bunchvector, const UInt_t altrocfg1,  const UInt_t altrocfg2)
 {
-  if( bunchvector.size()  <=  0 )
+  // Evaluation of signal parameters
+  short maxampindex; //index of maximum amplitude
+  short maxamp; //Maximum amplitude
+  int index = SelectBunch( bunchvector,  &maxampindex,  &maxamp );
+  if( index >= 0)
     {
-      return AliCaloFitResults(-1, -1, -1, -1 , -1, -1, -1 );
-    }
+      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);
 
-  Int_t amp = 0;
-  Float_t tof = -99;
-  const UShort_t *sig;
-  
-  double ped = EvaluatePedestal( bunchvector.at(0).GetData(), bunchvector.at(0).GetLength() ) ;
+      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 );
 
-  for( unsigned int i= 0; i < bunchvector.size(); ++i)
-    {
-      sig = bunchvector.at(i).GetData();
-      int length = bunchvector.at(i).GetLength(); 
-      
-      for(int j = 0; j < length; j ++)
-       if( sig[j] > amp  )
-         {
-           amp   = sig[j];
-           tof   = i;               
-         }
-    }
+         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);
 
-  //:EvaluatePedestal(const UShort_t * const data, const int length )
-  //  double ped = EvaluatePedestal(sig, length) ;
-  return  AliCaloFitResults(amp, ped, -1, amp - ped, tof, -1, -1 );
-  
 } //end Crude