]> git.uio.no Git - u/mrichter/AliRoot.git/commitdiff
update from Per Thomas
authordsilverm <dsilverm@f7af4fe6-9843-0410-8265-dc069ae4e863>
Mon, 1 Mar 2010 19:54:54 +0000 (19:54 +0000)
committerdsilverm <dsilverm@f7af4fe6-9843-0410-8265-dc069ae4e863>
Mon, 1 Mar 2010 19:54:54 +0000 (19:54 +0000)
12 files changed:
EMCAL/AliCaloRawAnalyzer.cxx
EMCAL/AliCaloRawAnalyzer.h
EMCAL/AliCaloRawAnalyzerComparison.cxx [new file with mode: 0644]
EMCAL/AliCaloRawAnalyzerComparison.h [new file with mode: 0644]
EMCAL/AliCaloRawAnalyzerCrude.cxx
EMCAL/AliCaloRawAnalyzerFastFit.cxx
EMCAL/AliCaloRawAnalyzerLMS.cxx
EMCAL/AliCaloRawAnalyzerNN.cxx
EMCAL/AliCaloRawAnalyzerPeakFinder.cxx
EMCAL/AliCaloRawAnalyzerPeakFinder.h
EMCAL/AliCaloRawAnalyzerPeakFinderV2.cxx [new file with mode: 0644]
EMCAL/AliCaloRawAnalyzerPeakFinderV2.h [new file with mode: 0644]

index 68105b359a192b1760131a0b95aab2916cf1deb7..cefad88182aa2773182e0371edc297fe64a4fb0d 100644 (file)
 #include <iostream>
 using namespace std;
 
 #include <iostream>
 using namespace std;
 
-ClassImp(AliCaloRawAnalyzer)  
-
-AliCaloRawAnalyzer::AliCaloRawAnalyzer(const char *name) :  TObject(),
-                                                           fMinTimeIndex(-1),
-                                                           fMaxTimeIndex(-1),
-                                                           fFitArrayCut(5),
-                                                           fAmpCut(4),
-                                                           fNsampleCut(5),
-                                                           fIsZerosupressed( false ),
-                                                           fVerbose( false )
+//ClassImp(AliCaloRawAnalyzer)  
+
+AliCaloRawAnalyzer::AliCaloRawAnalyzer(const char *name, const char *nameshort) :  TObject(),
+                                                                                  fMinTimeIndex(-1),
+                                                                                  fMaxTimeIndex(-1),
+                                                                                  fFitArrayCut(5),
+                                                                                  fAmpCut(4),
+                                                                                  fNsampleCut(5),
+                                                                                  fIsZerosupressed( false ),
+                                                                                  fVerbose( false )
 {
   //Comment 
   sprintf(fName, "%s", name);
 {
   //Comment 
   sprintf(fName, "%s", name);
+  sprintf(fNameShort, "%s", nameshort);
+    
   for(int i=0; i < MAXSAMPLES; i++ )
     {
       fReversed[i] = 0;
   for(int i=0; i < MAXSAMPLES; i++ )
     {
       fReversed[i] = 0;
@@ -174,7 +176,8 @@ AliCaloRawAnalyzer::Max( const AliCaloBunchInfo *const bunch , int *const maxind
   
   if(maxindex != 0 )
     {
   
   if(maxindex != 0 )
     {
-      *maxindex =  bunch->GetLength() -1 - tmpindex + bunch->GetStartBin(); 
+      //   *maxindex =  bunch->GetLength() -1 - tmpindex + bunch->GetStartBin(); 
+       *maxindex =  bunch->GetLength() -1 - tmpindex + bunch->GetStartBin(); 
     }
   
   return  tmpmax;
     }
   
   return  tmpmax;
@@ -192,19 +195,23 @@ AliCaloRawAnalyzer::SelectBunch( const vector<AliCaloBunchInfo> &bunchvector,sho
 
   for(unsigned int i=0; i < bunchvector.size(); i++ )
     {
 
   for(unsigned int i=0; i < bunchvector.size(); i++ )
     {
-      max = Max(  &bunchvector.at(i), &indx );  
+      max = Max(  &bunchvector.at(i), &indx ); // CRAP PTH, bug fix, trouble if more than one bunches  
       if( IsInTimeRange( indx) )
        {
          if( max > maxall )
            {
              maxall = max;
              bunchindex = i;
       if( IsInTimeRange( indx) )
        {
          if( max > maxall )
            {
              maxall = max;
              bunchindex = i;
+             *maxampbin     = indx;
+             *maxamplitude  = max;
            }
        }
     }
  
            }
        }
     }
  
-  *maxampbin     = indx;
-  *maxamplitude  = max;
+  
+  //  *maxampbin     = indx;
+  //  *maxamplitude  = max;
   return  bunchindex;
 }
 
   return  bunchindex;
 }
 
@@ -252,6 +259,7 @@ AliCaloRawAnalyzer::PrintBunch( const AliCaloBunchInfo &bunch ) const
   cout << endl; 
 }
 
   cout << endl; 
 }
 
+
 AliCaloFitResults
 AliCaloRawAnalyzer::Evaluate( const vector<AliCaloBunchInfo>  &/*bunchvector*/, const UInt_t /*altrocfg1*/,  const UInt_t /*altrocfg2*/)
 { // method to do the selection of what should possibly be fitted
 AliCaloFitResults
 AliCaloRawAnalyzer::Evaluate( const vector<AliCaloBunchInfo>  &/*bunchvector*/, const UInt_t /*altrocfg1*/,  const UInt_t /*altrocfg2*/)
 { // method to do the selection of what should possibly be fitted
@@ -259,6 +267,7 @@ AliCaloRawAnalyzer::Evaluate( const vector<AliCaloBunchInfo>  &/*bunchvector*/,
   return AliCaloFitResults( 0, 0, 0, 0, 0, 0, 0 );
 }
 
   return AliCaloFitResults( 0, 0, 0, 0, 0, 0, 0 );
 }
 
+
 int
 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)
 { // method to do the selection of what should possibly be fitted
 int
 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)
 { // method to do the selection of what should possibly be fitted
index d755ac405bbe6179f601beb6aef8dde213368117..315a142acc80c5fdaacbce8a812e633ece577d68 100644 (file)
@@ -49,7 +49,7 @@ class AliCaloFitResults;
 class  AliCaloRawAnalyzer : public TObject
 {
  public:
 class  AliCaloRawAnalyzer : public TObject
 {
  public:
-  AliCaloRawAnalyzer(const char *name="AliCaloRawAnalyzer");
+  AliCaloRawAnalyzer(const char *name="AliCaloRawAnalyzer", const char *nameshort="RawAna");
   virtual ~AliCaloRawAnalyzer();
   virtual AliCaloFitResults Evaluate( const vector<AliCaloBunchInfo> &bunchvector, 
                                      const UInt_t altrocfg1,  const UInt_t altrocfg2 );
   virtual ~AliCaloRawAnalyzer();
   virtual AliCaloFitResults Evaluate( const vector<AliCaloBunchInfo> &bunchvector, 
                                      const UInt_t altrocfg1,  const UInt_t altrocfg2 );
@@ -70,6 +70,8 @@ class  AliCaloRawAnalyzer : public TObject
   // access to array info
   Double_t GetReversed(const int i) const { return fReversed[i]; }
   const char * GetAlgoName() const { return fName;  };
   // access to array info
   Double_t GetReversed(const int i) const { return fReversed[i]; }
   const char * GetAlgoName() const { return fName;  };
+  const char * GetAlgoAbbr() const { return fNameShort;  };
+  bool GetIsZeroSuppressed() const { return fIsZerosupressed;} ;
 
  protected:
   short Max( const AliCaloBunchInfo *const bunch, int *const maxindex) const;
 
  protected:
   short Max( const AliCaloBunchInfo *const bunch, int *const maxindex) const;
@@ -92,7 +94,7 @@ class  AliCaloRawAnalyzer : public TObject
   bool fVerbose;     //Print debug information to std out if set to true
 
   char fName[256]; // Name of the algorithm
   bool fVerbose;     //Print debug information to std out if set to true
 
   char fName[256]; // Name of the algorithm
-
+  char fNameShort[256]; // Abbrevation for the name
 
   ClassDef(AliCaloRawAnalyzer, 1)  
 
 
   ClassDef(AliCaloRawAnalyzer, 1)  
 
diff --git a/EMCAL/AliCaloRawAnalyzerComparison.cxx b/EMCAL/AliCaloRawAnalyzerComparison.cxx
new file mode 100644 (file)
index 0000000..512e36f
--- /dev/null
@@ -0,0 +1,240 @@
+/**************************************************************************
+ * This file is property of and copyright by the Experimental Nuclear     *
+ * Physics Group, Dep. of Physics                                         *
+ * University of Oslo, Norway, 2007                                       *
+ *                                                                        *
+ * Author: Per Thomas Hille <perthi@fys.uio.no> for the ALICE HLT Project.*
+ * Contributors are mentioned in the code where appropriate.              *
+ * Please report bugs to perthi@fys.uio.no                                *
+ *                                                                        *
+ * Permission to use, copy, modify and distribute this software and its   *
+ * documentation strictly for non-commercial purposes is hereby granted   *
+ * without fee, provided that the above copyright notice appears in all   *
+ * copies and that both the copyright notice and this permission notice   *
+ * appear in the supporting documentation. The authors make no claims     *
+ * about the suitability of this software for any purpose. It is          *
+ * provided "as is" without express or implied warranty.                  *
+ **************************************************************************/
+#include "AliCaloRawAnalyzerComparison.h"
+
+#include "AliCaloRawAnalyzerCrude.h"
+#include "AliCaloRawAnalyzerLMS.h"
+#include "AliCaloRawAnalyzerFastFit.h"
+#include "AliCaloRawAnalyzerNN.h"
+#include "AliCaloRawAnalyzerPeakFinder.h"
+
+#include "AliCaloFitResults.h"
+#include "TH2D.h"
+#include "TMath.h"
+#include "TFile.h"
+
+#include <iostream>
+
+using namespace std;
+
+AliCaloRawAnalyzerComparison::AliCaloRawAnalyzerComparison() : fMod(0),
+                                                              fMonCol1(1),
+                                                              fMonRow1(15),
+                                                              fMonCol2(1),
+                                                              fMonRow2(16)
+{
+  fReferenceAnalyzer = new  AliCaloRawAnalyzerLMS();
+
+  AliCaloRawAnalyzerCrude *crude = new AliCaloRawAnalyzerCrude();
+  AliCaloRawAnalyzerLMS *lms = new AliCaloRawAnalyzerLMS();
+  AliCaloRawAnalyzerFastFit *fastfit = new AliCaloRawAnalyzerFastFit();
+  AliCaloRawAnalyzerNN *neuralnet = new AliCaloRawAnalyzerNN();
+  AliCaloRawAnalyzerPeakFinder *peakfinder = new AliCaloRawAnalyzerPeakFinder();
+
+  fReferenceAnalyzer->SetIsZeroSuppressed();
+  peakfinder->SetIsZeroSuppressed();
+  lms->SetIsZeroSuppressed();
+  fastfit->SetIsZeroSuppressed();
+  neuralnet->SetIsZeroSuppressed();
+  crude->SetIsZeroSuppressed(); 
+  
+  fRawAnalyzers.push_back( (AliCaloRawAnalyzer*)crude);
+  fRawAnalyzers.push_back( (AliCaloRawAnalyzer*)lms);
+  fRawAnalyzers.push_back( (AliCaloRawAnalyzer*)fastfit);
+  fRawAnalyzers.push_back( (AliCaloRawAnalyzer*)neuralnet);
+  
+  fRawAnalyzers.push_back( (AliCaloRawAnalyzer*)peakfinder);
+  IntiHistograms( fRawAnalyzers, fReferenceAnalyzer );
+}
+
+
+AliCaloRawAnalyzerComparison::~AliCaloRawAnalyzerComparison()
+{
+
+}
+
+void 
+AliCaloRawAnalyzerComparison::Evaluate( const vector<AliCaloBunchInfo> &bunchvector, const UInt_t altrocfg1,  
+                                       const UInt_t altrocfg2, const int event, const int col, const int row )
+{
+  //  cout << __FILE__ << __LINE__ << endl;
+
+  AliCaloFitResults ref = fReferenceAnalyzer->Evaluate( bunchvector, altrocfg1, altrocfg2 );
+  //  AliCaloFitResults ref;
+
+  for(int i=0; i < fRawAnalyzers.size(); i++ )
+    {
+      AliCaloFitResults an = fRawAnalyzers.at(i)->Evaluate( bunchvector, altrocfg1,  altrocfg2 ); 
+      
+      //     cout << __FILE__ << __LINE__ << ":" << fRawAnalyzers.at(i)->GetAlgoAbbr() << "  col = " << col << " row " << row << "  amp= " <<  an.GetAmp() << endl ;
+
+      //   fAmplitudeVsEvent[i]->Fill( event, an.GetAmp() );
+      //   fTofVsEvent[i]->Fill( event, an.GetTof() );
+    
+      fRefAmpVsAnalyzers[i]->Fill(ref.GetAmp(), an.GetAmp() );
+      fRefTofVsAnalyzers[i]->Fill(ref.GetTof(), an.GetTof() ); 
+      fAmpDiff[i]->Fill(ref.GetAmp() - an.GetAmp() ); 
+      fTofDiff[i]->Fill(ref.GetTof() - an.GetTof() );  
+     
+      if(col  == fMonCol1 && fMonRow1 == row )
+       {
+         fAmplitudeVsEvent[i]->Fill( event, an.GetAmp() );
+         fTofVsEvent[i]->Fill( event, an.GetTof() );
+         fMon1[i] = an;
+       }
+      
+      if(col  == fMonCol2 &&  row == fMonRow2  )
+       {
+         fMon2[i] = an;
+       }
+      if(row >= 0 && col >= 0 )
+       {
+         fAmpHistograms[i][col][row]->Fill( an.GetAmp() );
+       }
+    }
+}  
+
+
+
+void 
+AliCaloRawAnalyzerComparison::EventChanged()
+{
+  for(int i=0; i < fRawAnalyzers.size(); i++ )
+    {
+      /*
+      if( ( fMon1[i].GetAmp() > 50 &&   fMon2[i].GetAmp() > 50 ) &&  (  fMon1[i].GetAmp() < 1023  &&   fMon2[i].GetAmp() < 1023 )  )
+       {
+         cout << __FILE__ << __LINE__ << fRawAnalyzers.at(i)->GetAlgoAbbr() << "\tamp1=" <<  fMon1[i].GetAmp()  << "\tamp2 = " <<  fMon2[i].GetAmp() << endl;
+       }
+      */
+
+      if( fMon1[i].GetAmp()  > 50  &&  fMon2[i].GetAmp() > 50  )
+       {
+         //  if(  fMon1[i].GetTof() != fMon2[i].GetTof())
+         {
+           //    fTofResDifferential[i]->Fill( ( fMon1[i].GetTof() - fMon2[i].GetTof())/TMath::Sqrt(2) );
+           fTofResDifferential[i]->Fill( ( fMon1[i].GetTof() - fMon2[i].GetTof()) );
+           fTofResAbsolute[i]->Fill(  fMon1[i].GetTof() ); 
+         }
+       }
+    }
+}
+
+
+void 
+AliCaloRawAnalyzerComparison::WriteHistograms()
+{
+  TFile *f = new TFile("comparison2.root", "recreate");
+  
+  /*
+  for(int col=0; col < NZCOLSSMOD; col ++ )
+    {
+      for(int row=0; row < NXROWSSMOD; row ++ )
+       {
+         fAmpHistograms[col][row]->Write();
+       }
+    }
+  */  
+
+  for(int i=0; i < fRawAnalyzers.size(); i++ )
+    {
+      for(int col=0; col < NZCOLSSMOD; col ++ )
+       {
+         for(int row=0; row < NXROWSSMOD; row ++ )
+           {
+             fAmpHistograms[i][col][row]->Write();
+           }
+       }
+      
+      fAmplitudeVsEvent[i]->Write();
+      fTofVsEvent[i]->Write();
+      fRefAmpVsAnalyzers[i]->Write();
+      fRefTofVsAnalyzers[i]->Write(); 
+      fAmpDiff[i]->Write(); 
+      fTofDiff[i]->Write();  
+      fTofResDifferential[i]->Write();
+      fTofResAbsolute[i]->Write(); 
+
+   }
+  f->Close();
+}
+
+
+void
+AliCaloRawAnalyzerComparison::IntiHistograms( vector <AliCaloRawAnalyzer*> analyzers, AliCaloRawAnalyzer* ref )
+{
+  char tmpname[256];
+  /* 
+  for(int col=0; col < NZCOLSSMOD; col ++ )
+    {
+      for(int row=0; row < NXROWSSMOD; row ++ )
+       {
+         sprintf(tmpname, "z(col)%d_x(row)%d_amplitude;Counts;Amplitude/ADC counts", col, row);
+         fAmpHistograms[col][row] = new TH1D(tmpname, tmpname, 1024, 0, 1023 );
+       }
+    }
+  */
+
+  // TH1D *fAmpHistograms[NZCOLSSMOD][NXROWSSMOD];
+
+  for(int i=0; i < analyzers.size(); i++ )
+    {
+      for(int col=0; col < NZCOLSSMOD; col ++ )
+       {
+         for(int row=0; row < NXROWSSMOD; row ++ )
+           {
+             sprintf(tmpname, "z(col)%d_x(row)%d_amplitude_%s;Amplitude/ADC counts;Counts", col, row,  analyzers.at(i)->GetAlgoAbbr() );
+             fAmpHistograms[i][col][row] = new TH1D(tmpname, tmpname, 1024, 0, 1023 );
+           }
+       }
+      
+      sprintf(tmpname, "%s_amplitude_vs_event_row%d_col%d;Event;Amplitude/ADC counts", analyzers.at(i)->GetAlgoAbbr(), fMonRow1, fMonCol1 );
+      fAmplitudeVsEvent[i]=new TH2D(tmpname, tmpname, 8000, 0, 7999, 1024, 0, 1023 ); 
+     
+      sprintf(tmpname, "%s_tof_vs_event_row%d_col%d;Event;Amplitude/ADC counts", analyzers.at(i)->GetAlgoAbbr(), fMonRow1, fMonCol1 );  
+      
+      //     fTofVsEvent[i]=new TH2D(tmpname, tmpname, 8000, 0, 7999, 2000, 3000, 5000); 
+      fTofVsEvent[i]=new TH2D(tmpname, tmpname, 8000, 0, 7999, 2000, 1000, 4000);  
+
+
+      sprintf(tmpname, "%s_vs_%s_ampltude; Amplitude_{%s}/ADC counts; Amplitude_{%s}/ADC counts", ref->GetAlgoAbbr(), 
+             analyzers.at(i)->GetAlgoAbbr(), ref->GetAlgoAbbr(), analyzers.at(i)->GetAlgoAbbr() );
+      fRefAmpVsAnalyzers[i] = new TH2D(tmpname, tmpname, 1024, 0, 1023, 1024, 0, 1023); 
+      sprintf(tmpname, "%s_vs_%s_tof; tof_{%s}/ns; tof_{%s}/ns", ref->GetAlgoAbbr(), analyzers.at(i)->GetAlgoAbbr(), ref->GetAlgoAbbr(), analyzers.at(i)->GetAlgoAbbr() );
+      fRefTofVsAnalyzers[i] = new TH2D(tmpname, tmpname, 500, 2000, 4999, 500, 2000, 4999 ); 
+      sprintf( tmpname, "%s-%s amplitude;counts;A_{%s} - A_{%s}",   ref->GetAlgoAbbr(), 
+              analyzers.at(i)->GetAlgoAbbr(), ref->GetAlgoAbbr(), analyzers.at(i)->GetAlgoAbbr());
+      fAmpDiff[i] = new TH1D(tmpname, tmpname, 100, -10, 10 );
+      sprintf( tmpname, "%s-%s tof;counts;A_{%s} - A_{%s}",   ref->GetAlgoAbbr(), 
+              analyzers.at(i)->GetAlgoAbbr(), ref->GetAlgoAbbr(), analyzers.at(i)->GetAlgoAbbr());
+      fTofDiff[i] = new TH1D(tmpname, tmpname, 1000, -5000, 5000 );
+      sprintf( tmpname, "%s Differential tof resolution (%d, %d) vs (%d, %d);#sigma_{tof}^{%s}/ns;Counts",  analyzers.at(i)->GetAlgoAbbr(), fMonCol1, fMonRow1, fMonCol2, fMonRow2, 
+              analyzers.at(i)->GetAlgoAbbr() );
+      fTofResDifferential[i] = new TH1D(tmpname, tmpname, 1000, -250, 250 );
+      sprintf( tmpname, "%s Absolute tof distribution (%d, %d);#sigma_{tof}^{%s}/ns;Counts",  analyzers.at(i)->GetAlgoAbbr(), fMonCol1, fMonRow1, analyzers.at(i)->GetAlgoAbbr() );
+      
+      fTofResAbsolute[i] = new TH1D(tmpname, tmpname, 2000 , -1000, 7000 );
+
+
+    }
+}
+
diff --git a/EMCAL/AliCaloRawAnalyzerComparison.h b/EMCAL/AliCaloRawAnalyzerComparison.h
new file mode 100644 (file)
index 0000000..c0f3f42
--- /dev/null
@@ -0,0 +1,79 @@
+#ifndef ALICALORAWANALYZERCOMPARISON_H
+#define ALICALORAWANALYZERCOMPARISON_H
+
+/**************************************************************************
+ * This file is property of and copyright by the Experimental Nuclear     *
+ * Physics Group, Dep. of Physics                                         *
+ * University of Oslo, Norway, 2007                                       *
+ *                                                                        *
+ * Author: Per Thomas Hille <perthi@fys.uio.no> for the ALICE HLT Project.*
+ * Contributors are mentioned in the code where appropriate.              *
+ * Please report bugs to perthi@fys.uio.no                                *
+ *                                                                        *
+ * Permission to use, copy, modify and distribute this software and its   *
+ * documentation strictly for non-commercial purposes is hereby granted   *
+ * without fee, provided that the above copyright notice appears in all   *
+ * copies and that both the copyright notice and this permission notice   *
+ * appear in the supporting documentation. The authors make no claims     *
+ * about the suitability of this software for any purpose. It is          *
+ * provided "as is" without express or implied warranty.                  *
+ **************************************************************************/
+
+#define NANALYZERS 5
+
+#include <vector>
+#include "AliCaloBunchInfo.h"
+#include "AliCaloFitResults.h"
+
+#define NZCOLSSMOD   48     
+#define NXROWSSMOD   24    
+
+using namespace std;
+
+class AliCaloRawAnalyzer;
+class TH2D;
+class TH1D;
+
+
+class  AliCaloRawAnalyzerComparison
+{
+ public:
+  AliCaloRawAnalyzerComparison();
+  virtual ~AliCaloRawAnalyzerComparison();
+  void Evaluate( const vector<AliCaloBunchInfo> &bunchvector, 
+                const UInt_t altrocfg1,  const UInt_t altrocfg2, const int event, const int col, const int row ); 
+  
+  void EventChanged();
+
+  void WriteHistograms();
+
+ private:
+  void IntiHistograms( vector <AliCaloRawAnalyzer*> analyzers, AliCaloRawAnalyzer* ref );
+
+  TH1D *fAmpHistograms[NANALYZERS][NZCOLSSMOD][NXROWSSMOD];
+
+  TH2D *fAmplitudeVsEvent[NANALYZERS];  // Amplitude vs envent number
+  TH2D *fTofVsEvent[NANALYZERS];        // Tof vs event number
+  TH2D *fRefAmpVsAnalyzers[NANALYZERS]; // Amplidue from give analyzer vs reference
+  TH2D *fRefTofVsAnalyzers[NANALYZERS]; // Amplidue from give analyzer vs reference
+  TH1D *fAmpDiff[NANALYZERS]; // Difference in amplitude between reference
+  TH1D *fTofDiff[NANALYZERS]; // Difference in tof between reference
+  TH1D *fTofResDifferential[NANALYZERS]; //differntial tof resolution 
+  TH1D *fTofResAbsolute[NANALYZERS]; //differntial tof resolution 
+  
+
+  vector <AliCaloRawAnalyzer*> fRawAnalyzers;
+  AliCaloRawAnalyzer *fReferenceAnalyzer;
+  
+  int fMod;
+  int fMonCol1;
+  int fMonRow1;
+  int fMonCol2;
+  int fMonRow2;
+
+  AliCaloFitResults fMon1[NANALYZERS];
+  AliCaloFitResults fMon2[NANALYZERS];
+
+};
+
+#endif
index d9f43f3098fafeb752755f39e4d023acd901cab5..d40f47125f45fc8ca7a846db9f094d5be89a2a36 100644 (file)
@@ -30,7 +30,7 @@
 ClassImp(AliCaloRawAnalyzerCrude)  
 
 
 ClassImp(AliCaloRawAnalyzerCrude)  
 
 
-AliCaloRawAnalyzerCrude::AliCaloRawAnalyzerCrude() : AliCaloRawAnalyzer("Crude")
+AliCaloRawAnalyzerCrude::AliCaloRawAnalyzerCrude() : AliCaloRawAnalyzer("Crude", "Crude")
 {
 
 }
 {
 
 }
index 56181eeb1f618af9c78da31f89764fa231096a51..d6d87382967689f8794e66dcc0b135a10a8734d7 100644 (file)
@@ -34,7 +34,7 @@ using namespace std;
 
 ClassImp( AliCaloRawAnalyzerFastFit )
 
 
 ClassImp( AliCaloRawAnalyzerFastFit )
 
-AliCaloRawAnalyzerFastFit::AliCaloRawAnalyzerFastFit() : AliCaloRawAnalyzer("Fast Fit (Alexei)")
+AliCaloRawAnalyzerFastFit::AliCaloRawAnalyzerFastFit() : AliCaloRawAnalyzer("Fast Fit (Alexei)", "FF")
 {
   // Comment
 
 {
   // Comment
 
index f6fa73b7a088d92d5ea8d48de000aa62afb091b7..88f577a783f504bf8aeddffb945632e268b30fda 100644 (file)
@@ -41,7 +41,7 @@ using namespace std;
 ClassImp( AliCaloRawAnalyzerLMS )
 
 
 ClassImp( AliCaloRawAnalyzerLMS )
 
 
-AliCaloRawAnalyzerLMS::AliCaloRawAnalyzerLMS() : AliCaloRawAnalyzer("Chi Square Fit"),
+AliCaloRawAnalyzerLMS::AliCaloRawAnalyzerLMS() : AliCaloRawAnalyzer("Chi Square Fit", "LMS"),
                                                 fkEulerSquared(7.389056098930650227),
                                                 fSig(0),
                                                 fTf1(0)
                                                 fkEulerSquared(7.389056098930650227),
                                                 fSig(0),
                                                 fTf1(0)
index a5516ce8f8d167ea65cc94b2e7a87f6c17650dc6..8e101d54c341dd88208f85dce7a805968a6bfa36 100644 (file)
@@ -35,7 +35,7 @@ using namespace std;
 
 ClassImp( AliCaloRawAnalyzerNN )
 
 
 ClassImp( AliCaloRawAnalyzerNN )
 
-AliCaloRawAnalyzerNN::AliCaloRawAnalyzerNN() : AliCaloRawAnalyzer("Neural Network"), fNeuralNet(0)
+AliCaloRawAnalyzerNN::AliCaloRawAnalyzerNN() : AliCaloRawAnalyzer("Neural Network", "NN"), fNeuralNet(0)
 {
   // Comment
 
 {
   // Comment
 
index b67a03ca6741d9dcff6af8c72c4656750f17113a..cd5cf733cd4233e72aed91928cebc44099ddbaf9 100644 (file)
@@ -37,7 +37,7 @@ using namespace std;
 
 ClassImp( AliCaloRawAnalyzerPeakFinder )
 
 
 ClassImp( AliCaloRawAnalyzerPeakFinder )
 
-AliCaloRawAnalyzerPeakFinder::AliCaloRawAnalyzerPeakFinder() :AliCaloRawAnalyzer("Peak-Finder")
+AliCaloRawAnalyzerPeakFinder::AliCaloRawAnalyzerPeakFinder() :AliCaloRawAnalyzer("Peak-Finder", "PF")
 //    fTof(0), 
 //                                                           fAmp(0)
 {
 //    fTof(0), 
 //                                                           fAmp(0)
 {
@@ -51,15 +51,21 @@ AliCaloRawAnalyzerPeakFinder::AliCaloRawAnalyzerPeakFinder() :AliCaloRawAnalyzer
        {
          fPFAmpVectors[i][j] = new double[100];
          fPFTofVectors[i][j] = new double[100];
        {
          fPFAmpVectors[i][j] = new double[100];
          fPFTofVectors[i][j] = new double[100];
-         
+         fPFAmpVectorsCoarse[i][j] = new double[100];
+         fPFTofVectorsCoarse[i][j] = new double[100];
+
          for(int k=0; k < 100; k++ )
            {
              fPFAmpVectors[i][j][k] = 0; 
              fPFTofVectors[i][j][k] = 0;
          for(int k=0; k < 100; k++ )
            {
              fPFAmpVectors[i][j][k] = 0; 
              fPFTofVectors[i][j][k] = 0;
+             fPFAmpVectorsCoarse[i][j][k] = 0;
+             fPFTofVectorsCoarse[i][j][k] = 0; 
            }
        }
     }
            }
        }
     }
+
   LoadVectors();
   LoadVectors();
+
 }
 
 
 }
 
 
@@ -72,11 +78,30 @@ AliCaloRawAnalyzerPeakFinder::~AliCaloRawAnalyzerPeakFinder()
        {
          delete[] fPFAmpVectors[i][j];
          delete[] fPFTofVectors[i][j];
        {
          delete[] fPFAmpVectors[i][j];
          delete[] fPFTofVectors[i][j];
+         delete[] fPFAmpVectorsCoarse[i][j];
+         delete[] fPFTofVectorsCoarse[i][j];
        }
     }
 }
 
 
        }
     }
 }
 
 
+Double_t  
+AliCaloRawAnalyzerPeakFinder::ScanCoarse(const Double_t *const array, const int length ) const
+{
+  Double_t tmpTof = 0;
+  Double_t tmpAmp= 0;
+
+  for(int i=0; i < length; i++)
+    {
+      tmpTof += fPFTofVectorsCoarse[0][length][i]*array[i]; 
+      tmpAmp += fPFAmpVectorsCoarse[0][length][i]*array[i]; 
+    }
+  
+  tmpTof = tmpTof / tmpAmp ;
+  return tmpTof;
+}
+
+
 AliCaloFitResults 
 AliCaloRawAnalyzerPeakFinder::Evaluate( const vector<AliCaloBunchInfo> &bunchvector, const UInt_t altrocfg1,  const UInt_t altrocfg2 )
 {
 AliCaloFitResults 
 AliCaloRawAnalyzerPeakFinder::Evaluate( const vector<AliCaloBunchInfo> &bunchvector, const UInt_t altrocfg1,  const UInt_t altrocfg2 )
 {
@@ -87,12 +112,17 @@ AliCaloRawAnalyzerPeakFinder::Evaluate( const vector<AliCaloBunchInfo> &bunchvec
   short maxampindex; //index of maximum amplitude
   short maxamp; //Maximum amplitude
   //  fAmp = 0;
   short maxampindex; //index of maximum amplitude
   short maxamp; //Maximum amplitude
   //  fAmp = 0;
+
+  
   fAmpA[0] = 0;
   fAmpA[1] = 0;
   fAmpA[2] = 0;
   fAmpA[0] = 0;
   fAmpA[1] = 0;
   fAmpA[2] = 0;
-
+  
+  
+  //  cout << __FILE__ << __LINE__ << "\tendbin = " << bunchvector.at(index).GetEndBin()  <<  "\tstartbin = " << bunchvector.at(index).GetStartBin()  << endl;
+  
   int index = SelectBunch( bunchvector,  &maxampindex,  &maxamp );
   int index = SelectBunch( bunchvector,  &maxampindex,  &maxamp );
+
   if( index >= 0)
     {
       Float_t ped = ReverseAndSubtractPed( &(bunchvector.at(index))  ,  altrocfg1, altrocfg2, fReversed  );
   if( index >= 0)
     {
       Float_t ped = ReverseAndSubtractPed( &(bunchvector.at(index))  ,  altrocfg1, altrocfg2, fReversed  );
@@ -109,30 +139,34 @@ AliCaloRawAnalyzerPeakFinder::Evaluate( const vector<AliCaloBunchInfo> &bunchvec
       
       if ( maxf > fAmpCut )
        {
       
       if ( maxf > fAmpCut )
        {
+         
+
          SelectSubarray( fReversed,  bunchvector.at(index).GetLength(),  maxampindex -  bunchvector.at(index).GetStartBin(), &first, &last);
          int nsamples =  last - first;
          if( ( nsamples  )  >= fNsampleCut )
            {
              int startbin = bunchvector.at(index).GetStartBin();  
          SelectSubarray( fReversed,  bunchvector.at(index).GetLength(),  maxampindex -  bunchvector.at(index).GetStartBin(), &first, &last);
          int nsamples =  last - first;
          if( ( nsamples  )  >= fNsampleCut )
            {
              int startbin = bunchvector.at(index).GetStartBin();  
-             int n = last -first;  
+             int n = last - first;  
              int pfindex = n - fNsampleCut; 
              pfindex = pfindex > SAMPLERANGE ? SAMPLERANGE : pfindex;
 
              int pfindex = n - fNsampleCut; 
              pfindex = pfindex > SAMPLERANGE ? SAMPLERANGE : pfindex;
 
+             short timebinOffset = maxampindex - (bunchvector.at( index ).GetLength()-1); 
+            
              int dt =  maxampindex - startbin -2; 
              int dt =  maxampindex - startbin -2; 
-             for(int i=0; i < SAMPLERANGE; i++ )
+
+             //    cout << __FILE__ << __LINE__ <<"\t The coarse estimated t0 is " << ScanCoarse( &fReversed[dt] , n ) << endl;
+           
+        
+             //     Float_t tmptof = ScanCoarse( &fReversed[dt] , n );
+             
+             //              cout << __FILE__ << __LINE__ << ",  dt = " << dt << ",\tmaxamindex = " << maxampindex << "\tstartbin = "<< startbin << endl;
+
+             for( int i=0; i < SAMPLERANGE; i++ )
                {
                {
-                 
-                 //      int dt =  maxampindex - startbin -2;
-                 //              double tmp[3];
-                 //      tmp[0]  =  fReversed[ dt  +i -1]; 
-                 //              tmp[1]  =  fReversed[ dt  +i];  
-                 //              tmp[2]  =  fReversed[ dt  +i +1]; 
-                 
-                 for(int j = 0; j < 3; j++)
+                 for( int j = 0; j < 3; j++ )
                    {
                      //    fAmpA[j] += fPFAmpVectors[0][pfindex][i]*tmp[j]; 
                    {
                      //    fAmpA[j] += fPFAmpVectors[0][pfindex][i]*tmp[j]; 
-                     fAmpA[j] += fPFAmpVectors[0][pfindex][i]*fReversed[ dt  +i +j -1];
-
+                     fAmpA[j] += fPFAmpVectors[0][pfindex][i]*fReversed[ dt  +i +j -1 ];
                    }
                }
              
                    }
                }
              
@@ -149,27 +183,55 @@ AliCaloRawAnalyzerPeakFinder::Evaluate( const vector<AliCaloBunchInfo> &bunchvec
                    }
                }
              
                    }
                }
              
+             Float_t tmptof = ScanCoarse( &fReversed[dt] , n );
+             
+             if( tmptof < -1 )
+               {
+                 tmpindex = 0;
+               }
+             else
+               if( tmptof  > -1 && tmptof < 100 )
+                 {
+                   tmpindex =1;
+                 }
+               else
+                 {
+                   tmpindex = 2;
+                 }
              double tof = 0;
              double tof = 0;
-
+             
              for(int k=0; k < SAMPLERANGE; k++   )
                {
                  tof +=  fPFTofVectors[0][pfindex][k]*fReversed[ dt  +k + tmpindex -1 ];   
                }
              
              for(int k=0; k < SAMPLERANGE; k++   )
                {
                  tof +=  fPFTofVectors[0][pfindex][k]*fReversed[ dt  +k + tmpindex -1 ];   
                }
              
-             tof = tof /  fAmpA[tmpindex];
+             //              cout << __FILE__ << __LINE__ <<  "tofRaw =   "<< tof /  fAmpA[tmpindex]  << endl;
+             
+             // tof = tof /  fAmpA[tmpindex] +  (dt + startbin)*100;
+             
+             if( TMath::Abs(  (maxf - fAmpA[tmpindex])/maxf )  >   0.1 )
+               {
+                 fAmpA[tmpindex] = maxf;
+               }
+
+             //              timebinOffset
+
+               //      tof = (dt + startbin + tmpindex )*100 - tof/fAmpA[tmpindex];
+               // tof = ( timebinOffset )*100 - tof/fAmpA[tmpindex]; // ns
+             tof = timebinOffset - 0.01*tof/fAmpA[tmpindex]; // clock ticks
+             
+             //      tof = tof/fAmpA[tmpindex];
 
 
+  
              return AliCaloFitResults( maxamp, ped , -1, fAmpA[tmpindex], tof, -2, -3 ); 
            }
              return AliCaloFitResults( maxamp, ped , -1, fAmpA[tmpindex], tof, -2, -3 ); 
            }
-
          else
            {
              return AliCaloFitResults( maxamp, ped , -5, maxf, -6, -7, -8 ); 
            }
        }
     }
          else
            {
              return AliCaloFitResults( maxamp, ped , -5, maxf, -6, -7, -8 ); 
            }
        }
     }
-  //  cout << __FILE__ << __LINE__ <<  "WARNING, returning amp = -1 "  <<  endl;
-
+   //  cout << __FILE__ << __LINE__ <<  "WARNING, returning amp = -1 "  <<  endl;
   return  AliCaloFitResults(-1, -1);
 }
 
   return  AliCaloFitResults(-1, -1);
 }
 
@@ -182,32 +244,72 @@ AliCaloRawAnalyzerPeakFinder::LoadVectors()
     {
       for( int j=0; j < SAMPLERANGE; j++)
        {
     {
       for( int j=0; j < SAMPLERANGE; j++)
        {
+         char filenameCoarse[256];
          char filename[256];
          char filename[256];
-         int n = j+fNsampleCut;
-         double start = (double)i+0.5;
-         sprintf(filename, "%s/EMCAL/vectors-emcal/start%.1fN%dtau0.235fs10dt1.0.txt", getenv("ALICE_ROOT"), start, n);
-         FILE *fp = fopen(filename, "r");
          
          
-         if(fp == 0)
+         int n = j+fNsampleCut;
+
+         //      double start = (double)i+0.5;
+         double start = (double)i+0;
+
+         sprintf(filename,        "%s/EMCAL/vectors-emcal/start%.1fN%dtau0.235fs10dt1.0.txt", getenv("ALICE_ROOT"), start, n);
+         sprintf(filenameCoarse,  "%s/EMCAL/vectors-emcal/start%.1fN%dtau0.235fs10dt3.0.txt", getenv("ALICE_ROOT"), start, n);
+
+         FILE *fp  =  fopen(filename, "r");
+         FILE *fpc =  fopen(filenameCoarse, "r");
+
+         if( fp == 0 )
            {
              AliFatal( Form( "could not open file: %s", filename ) );
            }
            {
              AliFatal( Form( "could not open file: %s", filename ) );
            }
+       
+         if(fpc == 0)
+           {
+             AliFatal( Form( "could not open file: %s", filenameCoarse ) );
+           }
          else
            {
              for(int m = 0; m < n ; m++ )
                {
          else
            {
              for(int m = 0; m < n ; m++ )
                {
+                 cout << __FILE__ << __LINE__ << "i="<<i <<"\tj=" <<j << "\tm=" << m << endl;
                  fscanf(fp, "%lf\t", &fPFAmpVectors[i][j][m] );
                  fscanf(fp, "%lf\t", &fPFAmpVectors[i][j][m] );
+                 //              fPFAmpVectorsCoarse[i][j][m] = 1;
+                 fscanf(fpc, "%lf\t", &fPFAmpVectorsCoarse[i][j][m] );
                }
                }
-             fscanf(fp, "\n");
+             
+             fscanf(fp,   "\n" );
+             fscanf(fpc,  "\n" );
              
              for(int m = 0; m < n ; m++ )
                {
              
              for(int m = 0; m < n ; m++ )
                {
-                 fPFTofVectors[i][j][m] = 1;
-        //       fscanf(fp, "%lf\t", &fPFTofVectors[i][j][m] );
+                 //  fPFTofVectors[i][j][m] = 1;
+
+                 fscanf(fp, "%lf\t",   &fPFTofVectors[i][j][m]  );
+                 fscanf(fpc, "%lf\t",  &fPFTofVectorsCoarse[i][j][m]  );  
+                 //  fPFTofVectorsCoarse[i][j][m] = 1;  
                }
              
                }
              
+            
              fclose (fp);
              fclose (fp);
+             fclose (fpc);
            }
        }
     }
 }
            }
        }
     }
 }
+
+
+
+/*
+void
+AliCaloRawAnalyzerPeakFinder::PolTof( const double rectof ) const
+//
+{
+  static Double_t p0 = -55.69;
+  static Double_t p1 = 3.178;
+  static Double_t p2 = -0.05587;
+  static Double_t p3 = 0.0003185;
+  static Double_t p4 = -7.91E-7;
+  static Double_t p5 = 7.576E-10;
+}
+*/
index 6d187f806d270440aa2dca41b4eb5aeba983aa37..5c239abce41b54f037ef17aa65fe56358f4e93fa 100644 (file)
@@ -47,9 +47,16 @@ class  AliCaloRawAnalyzerPeakFinder : public AliCaloRawAnalyzer
   AliCaloRawAnalyzerPeakFinder( const AliCaloRawAnalyzerPeakFinder   & );
   AliCaloRawAnalyzerPeakFinder   & operator = ( const  AliCaloRawAnalyzerPeakFinder  & );
 
   AliCaloRawAnalyzerPeakFinder( const AliCaloRawAnalyzerPeakFinder   & );
   AliCaloRawAnalyzerPeakFinder   & operator = ( const  AliCaloRawAnalyzerPeakFinder  & );
 
-  void LoadVectors();
-  double *fPFAmpVectors[MAXSTART][SAMPLERANGE]; // Vectors for Amplitude extraction 
-  double *fPFTofVectors[MAXSTART][SAMPLERANGE]; // Vectors for TOF extraction
+  void     LoadVectors();
+  Double_t  ScanCoarse(const Double_t *const array, const int length ) const ; // Find a rough estimate of peak position and t0
+
+  //  void PolTof( const double rectof ) const;
+  
+  double *fPFAmpVectorsCoarse[MAXSTART][SAMPLERANGE]; // Vectors for Amplitude extraction, first iteration 
+  double *fPFTofVectorsCoarse[MAXSTART][SAMPLERANGE]; // Vectors for TOF extraction, first iteration
+
+  double *fPFAmpVectors[MAXSTART][SAMPLERANGE]; // Vectors for Amplitude extraction, second iteration 
+  double *fPFTofVectors[MAXSTART][SAMPLERANGE]; // Vectors for TOF extraction, second iteration
 
   //  double fTof; 
   //  double fAmp;
 
   //  double fTof; 
   //  double fAmp;
diff --git a/EMCAL/AliCaloRawAnalyzerPeakFinderV2.cxx b/EMCAL/AliCaloRawAnalyzerPeakFinderV2.cxx
new file mode 100644 (file)
index 0000000..879de67
--- /dev/null
@@ -0,0 +1,382 @@
+/**************************************************************************
+ * This file is property of and copyright by                              *
+ * the Relativistic Heavy Ion Group (RHIG), Yale University, US, 2009     *
+ *                                                                        *
+ * Primary Author: Per Thomas Hille  <perthomas.hille@yale.edu>           *
+ *                                                                        *
+ * Contributors are mentioned in the code where appropriate.              *
+ * Please report bugs to p.t.hille@fys.uio.no                             *
+ *                                                                        *
+ * Permission to use, copy, modify and distribute this software and its   *
+ * documentation strictly for non-commercial purposes is hereby granted   *
+ * without fee, provided that the above copyright notice appears in all   *
+ * copies and that both the copyright notice and this permission notice   *
+ * appear in the supporting documentation. The authors make no claims     *
+ * about the suitability of this software for any purpose. It is          *
+ * provided "as is" without express or implied warranty.                  *
+ **************************************************************************/
+
+// The Peak-Finder algorithm
+// The amplitude is extracted  as a
+// weighted sum of the samples using the 
+// best possible weights.
+// The wights is calculated only once and the
+// Actual extraction of amplitude and peak position
+// Is done with a simple vector multiplication, allowing for
+// Extreemely fast computations. 
+
+#include "AliCaloRawAnalyzerPeakFinderV2.h"
+#include "AliCaloBunchInfo.h"
+#include "AliCaloFitResults.h"
+#include <iostream>
+#include "unistd.h"
+#include "TMath.h"
+#include "AliLog.h"
+
+using namespace std;
+
+ClassImp( AliCaloRawAnalyzerPeakFinderV2 )
+
+AliCaloRawAnalyzerPeakFinderV2::AliCaloRawAnalyzerPeakFinderV2() :AliCaloRawAnalyzer("Peak-FinderV2", "PF")
+//    fTof(0), 
+//                                                           fAmp(0)
+{
+  //comment
+
+  fNsampleCut = 5;
+
+  for(int i=0; i < MAXSTART; i++)
+    {
+      for(int j=0; j < SAMPLERANGE; j++ )
+       {
+         fPFAmpVectors[i][j] = new double[100];
+         fPFTofVectors[i][j] = new double[100];
+         fPFAmpVectorsCoarse[i][j] = new double[100];
+         fPFTofVectorsCoarse[i][j] = new double[100];
+
+         
+         for(int k=0; k < 100; k++ )
+           {
+             fPFAmpVectors[i][j][k] = 0; 
+             fPFTofVectors[i][j][k] = 0;
+             fPFAmpVectorsCoarse[i][j][k] = 0;
+             fPFTofVectorsCoarse[i][j][k] = 0; 
+           }
+       }
+    }
+
+  LoadVectors();
+
+}
+
+
+AliCaloRawAnalyzerPeakFinderV2::~AliCaloRawAnalyzerPeakFinderV2()
+{
+  //comment
+  for(int i=0; i < MAXSTART; i++)
+    {
+      for(int j=0; j < SAMPLERANGE; j++ )
+       {
+         delete[] fPFAmpVectors[i][j];
+         delete[] fPFTofVectors[i][j];
+         delete[] fPFAmpVectorsCoarse[i][j];
+         delete[] fPFTofVectorsCoarse[i][j];
+       }
+    }
+}
+
+
+Double_t  
+AliCaloRawAnalyzerPeakFinderV2::ScanCoarse(const Double_t *const array, const int length ) const
+{
+  Double_t tmpTof = 0;
+  Double_t tmpAmp= 0;
+
+  for(int i=0; i < length; i++)
+    {
+      tmpTof += fPFTofVectorsCoarse[0][length][i]*array[i]; 
+      tmpAmp += fPFAmpVectorsCoarse[0][length][i]*array[i]; 
+    }
+  
+  tmpTof = tmpTof / tmpAmp ;
+  return tmpTof;
+}
+
+
+AliCaloFitResults 
+AliCaloRawAnalyzerPeakFinderV2::Evaluate( const vector<AliCaloBunchInfo> &bunchvector, const UInt_t altrocfg1,  const UInt_t altrocfg2 )
+{
+  // Extracting the amplitude using the Peak-FinderV2 algorithm
+  // The amplitude is a weighted sum of the samples using 
+  // optimum weights.
+
+  short maxampindex; //index of maximum amplitude
+  short maxamp; //Maximum amplitude
+  //  fAmp = 0;
+  fAmpA[0] = 0;
+  fAmpA[1] = 0;
+  fAmpA[2] = 0;
+
+  int index = SelectBunch( bunchvector,  &maxampindex,  &maxamp );
+  if( index >= 0)
+    {
+      Float_t ped = ReverseAndSubtractPed( &(bunchvector.at(index))  ,  altrocfg1, altrocfg2, fReversed  );
+      Float_t maxf = TMath::MaxElement(   bunchvector.at(index).GetLength(),  fReversed );
+      
+      if(  maxf < fAmpCut  ||  ( maxamp - ped) > 900  )         // (maxamp - ped) > 900 = Close to saturation (use low gain then)
+       {
+         //      cout << __FILE__ << __LINE__ <<":, maxamp = " << maxamp << ", ped = "<< ped  << ",. maxf = "<< maxf << ", maxampindex = "<< maxampindex  << endl;
+         return  AliCaloFitResults( maxamp, ped,  -1, maxf,   maxampindex, -1, -1 );
+       }
+      
+      int first;
+      int last;
+      
+      if ( maxf > fAmpCut )
+       {
+         SelectSubarray( fReversed,  bunchvector.at(index).GetLength(),  maxampindex -  bunchvector.at(index).GetStartBin(), &first, &last);
+         int nsamples =  last - first;
+         if( ( nsamples  )  >= fNsampleCut )
+           {
+             int startbin = bunchvector.at(index).GetStartBin();  
+             int n = last - first;  
+             int pfindex = n - fNsampleCut; 
+             pfindex = pfindex > SAMPLERANGE ? SAMPLERANGE : pfindex;
+            
+             int dt =  maxampindex - startbin -1; 
+          
+             
+             //    cout << __FILE__ << __LINE__ <<"\t The coarse estimated t0 is " << ScanCoarse( &fReversed[dt] , n ) << endl;
+           
+        
+             
+             //  Float_t tmptof = ScanCoarse( &fReversed[dt] , n );
+             //  cout << __FILE__ << __LINE__ << "\ttmptof = " << tmptof << endl;
+             
+
+             //              cout << __FILE__ << __LINE__ << ",  dt = " << dt << ",\tmaxamindex = " << maxampindex << "\tstartbin = "<< startbin << endl;
+
+             for( int i=0; i < SAMPLERANGE; i++ )
+               {
+                 for( int j = 0; j < 3; j++ )
+                   {
+                     //    fAmpA[j] += fPFAmpVectors[0][pfindex][i]*tmp[j]; 
+                     fAmpA[j] += fPFAmpVectors[0][pfindex][i]*fReversed[ dt  +i +j -1 ];
+                   }
+               }
+             
+             double diff = 9999;
+             int tmpindex = 0;
+
+             for(int k=0; k < 3; k ++)
+               {
+                 //              cout << __FILE__ << __LINE__ << "amp[="<< k <<"] = " << fAmpA[k] << endl;
+                 if(  TMath::Abs(fAmpA[k] - ( maxamp - ped) )  < diff)
+                   {
+                     diff = TMath::Abs(fAmpA[k] - ( maxamp - ped));
+                     tmpindex = k; 
+                   }
+               }
+             
+             Float_t tmptof = ScanCoarse( &fReversed[dt] , n );
+
+             //      Double_t tofnew = PolTof(tmptof) + ( dt + startbin  )*100  ;
+             //             int dt =  maxampindex - startbin -1;    
+           
+             //              Double_t tofnew = PolTof(tmptof) + startbin*100 ;
+
+             //      Double_t tofnew = PolTof(tmptof)  +  maxampindex*100 ;
+
+             
+             //              Double_t tofnew = PolTof(tmptof)  + (dt + startbin + tmpindex )*100 ; 
+             Double_t tofnew = PolTof(tmptof)  ; 
+
+             //              tmptof= tofnew;
+
+             //              Double_t tofnew = PolTof(tmptof) + maxampindex  ;
+
+
+             if(tmptof < 0 )
+               {
+                 cout << __FILE__ << __LINE__ << "\ttmptof = " << tmptof << endl;  
+               }
+
+  
+             if( tmptof < -1 )
+               {
+                 tmpindex = 0;
+               }
+             else
+               if( tmptof  > -1 && tmptof < 100 )
+                 {
+                   tmpindex =1;
+                 }
+               else
+                 {
+                   tmpindex = 2;
+                 }
+             
+
+
+             double tof = 0;
+             
+             for(int k=0; k < SAMPLERANGE; k++   )
+               {
+                 tof +=  fPFTofVectors[0][pfindex][k]*fReversed[ dt  +k + tmpindex -1 ];   
+               }
+             
+             //              cout << __FILE__ << __LINE__ <<  "tofRaw =   "<< tof /  fAmpA[tmpindex]  << endl;
+             
+             // tof = tof /  fAmpA[tmpindex] +  (dt + startbin)*100;
+             
+             if( TMath::Abs(  (maxf - fAmpA[tmpindex])/maxf )  >   0.1 )
+               {
+                 fAmpA[tmpindex] = maxf;
+               }
+
+             // tof = (dt + startbin + tmpindex )*100 - tof/fAmpA[tmpindex]; // ns
+             tof = dt + startbin + tmpindex - 0.01*tof/fAmpA[tmpindex]; // clock ticks
+         
+             
+             return AliCaloFitResults( maxamp, ped , -1, fAmpA[tmpindex], tof  , -2, -3 ); 
+           }
+         else
+           {
+             return AliCaloFitResults( maxamp, ped , -5, maxf, -6, -7, -8 ); 
+           }
+       }
+    }
+   //  cout << __FILE__ << __LINE__ <<  "WARNING, returning amp = -1 "  <<  endl;
+  return  AliCaloFitResults(-1, -1);
+}
+
+
+Double_t
+AliCaloRawAnalyzerPeakFinderV2::PolTof( const double fx1 ) const
+{
+  
+  //Newtons method
+  Double_t tolerance = 0.01;
+  //  cout << "************************"  << endl;
+  Double_t fx2 = PolValue( fx1 );
+  Double_t tmpfx1 = fx1; 
+
+  while(  TMath::Abs( fx2 - fx1  ) >  tolerance )
+    {
+      Double_t der = PolDerivative( tmpfx1 ); 
+      //     tmpx = der*( x - val) +x;
+      tmpfx1 = ( fx1 - fx2)/der  +tmpfx1;
+      
+      //    tmpx = der*( val - tmpx ) +tmpx;
+      fx2 = PolValue(  tmpfx1 );
+      //     cout << __FILE__ << __LINE__ <<  "Der =\t" << der << "  x=\t"<<x<<"\tval="<<val <<  endl;
+      //     cout << __FILE__ << __LINE__ <<  "Der =\t" << der << "  tmpx=\t"<< tmpfx1 <<"\tval="<< fx2 <<  endl;
+    }
+  
+  //  cout << __FILE__ << __LINE__ << "CONVERGED !! fx1 = "<< fx1 <<"  tmpfx1 = "<< tmpfx1  <<"  f(tmpfx1) = "<< fx2 << endl;  
+
+  //  cout << "************************"  << endl;
+  
+  return tmpfx1;
+
+}
+
+
+Double_t 
+AliCaloRawAnalyzerPeakFinderV2::PolValue(const Double_t x) const
+{
+  static Double_t p0 = -55.69;
+  static Double_t p1 = 4.718;
+  static Double_t p2 = -0.05587;
+  static Double_t p3 = 0.0003185;
+  static Double_t p4 = -7.91E-7;
+  static Double_t p5 = 7.576E-10;
+  
+  //  return  p0 + p1*x + p2*TMath::Power(x, 2) + p3*TMath::Power(x, 3) + p4*TMath::Power(x, 4)  + p5*TMath::Power(x, 5);
+  
+  return  p0 + p1*x + p2*x*x + p3*x*x*x + p4*x*x*x*x  + p5*x*x*x*x*x;
+  
+}
+
+
+Double_t 
+AliCaloRawAnalyzerPeakFinderV2::PolDerivative(const Double_t x) const
+{
+  static Double_t dp0 = 0;
+  static Double_t dp1 = 4.718;
+  static Double_t dp2 = -0.11174;
+  static Double_t dp3 = 0.0009555;
+  static Double_t dp4 = -3.164E-6;
+  static Double_t dp5 = 3.788E-9;
+
+  //  return  dp0 + dp1 + dp2*x + dp3*TMath::Power(x, 2) + dp4*TMath::Power(x, 3)  + dp5*TMath::Power(x, 4);
+  
+  
+
+  return  dp0 + dp1 + dp2*x + dp3*x*x + dp4*x*x*x  + dp5*x*x*x*x;
+  
+}
+
+
+void 
+AliCaloRawAnalyzerPeakFinderV2::LoadVectors()
+{
+  //Read in the Peak finder vecors from file
+  for(int i = 0;  i < MAXSTART ; i++)
+    {
+      for( int j=0; j < SAMPLERANGE; j++)
+       {
+         char filenameCoarse[256];
+         char filename[256];
+         
+         int n = j+fNsampleCut;
+
+         //      double start = (double)i+0.5;
+         double start = (double)i+0;
+
+         sprintf(filename,        "%s/EMCAL/vectors-emcal/start%.1fN%dtau0.235fs10dt1.0.txt", getenv("ALICE_ROOT"), start, n);
+         sprintf(filenameCoarse,  "%s/EMCAL/vectors-emcal/start%.1fN%dtau0.235fs10dt3.0.txt", getenv("ALICE_ROOT"), start, n);
+
+         FILE *fp  =  fopen(filename, "r");
+         FILE *fpc =  fopen(filenameCoarse, "r");
+
+         if( fp == 0 )
+           {
+             AliFatal( Form( "could not open file: %s", filename ) );
+           }
+       
+         if(fpc == 0)
+           {
+             AliFatal( Form( "could not open file: %s", filenameCoarse ) );
+           }
+         else
+           {
+             for(int m = 0; m < n ; m++ )
+               {
+                 cout << __FILE__ << __LINE__ << "i="<<i <<"\tj=" <<j << "\tm=" << m << endl;
+                 fscanf(fp, "%lf\t", &fPFAmpVectors[i][j][m] );
+                 //              fPFAmpVectorsCoarse[i][j][m] = 1;
+                 fscanf(fpc, "%lf\t", &fPFAmpVectorsCoarse[i][j][m] );
+               }
+             
+             fscanf(fp,   "\n" );
+             fscanf(fpc,  "\n" );
+             
+             for(int m = 0; m < n ; m++ )
+               {
+                 //  fPFTofVectors[i][j][m] = 1;
+
+                 fscanf(fp, "%lf\t",   &fPFTofVectors[i][j][m]  );
+                 fscanf(fpc, "%lf\t",  &fPFTofVectorsCoarse[i][j][m]  );  
+                 //  fPFTofVectorsCoarse[i][j][m] = 1;  
+               }
+             fclose (fp);
+             fclose (fpc);
+           }
+       }
+    }
+}
+
+
diff --git a/EMCAL/AliCaloRawAnalyzerPeakFinderV2.h b/EMCAL/AliCaloRawAnalyzerPeakFinderV2.h
new file mode 100644 (file)
index 0000000..407cf9e
--- /dev/null
@@ -0,0 +1,77 @@
+#ifndef ALICALORAWANALYZERPEAKFINDERV2_H
+#define ALICALORAWANALYZERPEAKFINDERV2_H
+
+
+/**************************************************************************
+ * This file is property of and copyright by                              *
+ * the Relativistic Heavy Ion Group (RHIG), Yale University, US, 2009     *
+ *                                                                        *
+ * Primary Author: Per Thomas Hille  <perthomas.hille@yale.edu>           *
+ *                                                                        *
+ * Contributors are mentioned in the code where appropriate.              *
+ * Please report bugs to p.t.hille@fys.uio.no                             *
+ *                                                                        *
+ * Permission to use, copy, modify and distribute this software and its   *
+ * documentation strictly for non-commercial purposes is hereby granted   *
+ * without fee, provided that the above copyright notice appears in all   *
+ * copies and that both the copyright notice and this permission notice   *
+ * appear in the supporting documentation. The authors make no claims     *
+ * about the suitability of this software for any purpose. It is          *
+ * provided "as is" without express or implied warranty.                  *
+ **************************************************************************/
+
+
+// The Peak-Finder algorithm
+// The amplitude is extracted  as a
+// weighted sum of the samples using the 
+// best possible weights.
+
+
+#include "AliCaloRawAnalyzer.h"
+
+#define MAXSTART 3
+#define SAMPLERANGE 15
+#define SHIF 0.5
+
+class AliCaloBunchInfo;
+
+
+class  AliCaloRawAnalyzerPeakFinderV2 : public AliCaloRawAnalyzer
+{
+ public:
+  AliCaloRawAnalyzerPeakFinderV2();
+  virtual ~AliCaloRawAnalyzerPeakFinderV2();
+  virtual AliCaloFitResults Evaluate( const vector<AliCaloBunchInfo> &bunchvector, const UInt_t altrocfg1,  const UInt_t altrocfg2 );
+
+ private:
+  AliCaloRawAnalyzerPeakFinderV2( const AliCaloRawAnalyzerPeakFinderV2   & );
+  AliCaloRawAnalyzerPeakFinderV2   & operator = ( const  AliCaloRawAnalyzerPeakFinderV2  & );
+
+  void     LoadVectors();
+  Double_t  ScanCoarse(const Double_t *const array, const int length ) const ; // Find a rough estimate of peak position and t0
+
+
+  Double_t PolTof(const Double_t x) const;
+  Double_t PolValue(const Double_t x) const;
+  Double_t PolDerivative(const Double_t x) const;
+
+
+
+  double *fPFAmpVectorsCoarse[MAXSTART][SAMPLERANGE]; // Vectors for Amplitude extraction, first iteration 
+  double *fPFTofVectorsCoarse[MAXSTART][SAMPLERANGE]; // Vectors for TOF extraction, first iteration
+
+  double *fPFAmpVectors[MAXSTART][SAMPLERANGE]; // Vectors for Amplitude extraction, second iteration 
+  double *fPFTofVectors[MAXSTART][SAMPLERANGE]; // Vectors for TOF extraction, second iteration
+
+  //  double fTof; 
+  //  double fAmp;
+
+  double fAmpA[3]; // The  amplitude of the signal (eveluate 3 times using 3 differtnt phase shifts of the input samples )
+  // double fAmp2;
+  // double fAmp3;
+
+  ClassDef( AliCaloRawAnalyzerPeakFinderV2, 1 )
+
+};
+
+#endif