]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/PHOS/PeakFinderTest.cxx
completely re-worked TPC CA tracking code (Sergey/Ivan)
[u/mrichter/AliRoot.git] / HLT / PHOS / PeakFinderTest.cxx
1 #include "AliHLTPHOSPulseGenerator.h"
2 #include "AliHLTPHOSRawAnalyzerPeakFinder.h"
3 #include <stdio.h>
4 #include <cmath>
5
6 void setFileName(char *fName, int start, int length, double tau, double fs);
7
8 /**
9  * Testing of the Class AliPHOSFitter
10  **/
11 int main()
12 {
13   FILE *fp = 0;
14   int start  = 0;               // Start index of subarray of sample array
15   int N = 128;                  // Number of samples 
16   char fileName[100];           // Name of file containing Peakfinder vectors
17   double amplitude;             // Amplitude/energy in ADC levels
18   double t0;                    // timedelay in nanoseconds  
19
20   double tau = 2;               // risetime in microseconds
21   double fs = 20;               // sample frequency in Megahertz
22   double timeVector[N];         // Peakfinder vector for reconstruction of time
23   double amplitudeVector[N];    // Peakfinder vector for reconstruction of energy
24   double aSystError;
25   double tSystError;
26
27   int ts = (int)(1000/fs);  
28   printf("\nts=%d\n", ts);
29
30   printf("type amplitude in ADC levels (0-1023):");
31   scanf("%lf", &amplitude);
32   printf("type timedelay in nanoseconds (0-%d):", ts); 
33   scanf("%lf", &t0);
34
35   AliHLTPHOSPulseGenerator *pulseGenPtr = new AliHLTPHOSPulseGenerator(amplitude, t0, N, tau, fs);
36   double *data = pulseGenPtr->GetPulse(); 
37
38   setFileName(fileName, start, N, tau, fs);
39   fp = fopen(fileName,"r");
40
41   if(fp == 0)
42     {
43       printf("\nFile does not exist\n");
44     }
45   else
46     {
47       for(int i=0; i < N; i++)
48         {
49           fscanf(fp, "%lf", &amplitudeVector[i]);
50         }
51
52       fscanf(fp, "\n");
53
54      for(int i=0; i < N; i++)
55         {
56           fscanf(fp, "%lf", &timeVector[i]);
57         }
58
59      fscanf(fp, "%lf", &aSystError);
60      fscanf(fp, "%lf", &tSystError);
61      printf("\nPeakfinder vectors loaded from %s\n", fileName);
62     }
63
64
65    tSystError = tSystError*pow((double)10, (double)9); //to give systematic error of timing in nanoseconds
66    aSystError = aSystError*100;        //to give systematic error of amplitude in percent
67
68
69    //  AliHLTPHOSAnalyzerPeakFinder *fitPtr= new AliHLTPHOSAnalyzerPeakFinder(data, fs); 
70    AliHLTPHOSRawAnalyzerPeakFinder *fitPtr= new AliHLTPHOSRawAnalyzerPeakFinder(); 
71   
72    fitPtr->SetData(data);
73    fitPtr->SetSampleFreq(fs);
74    fitPtr->SetTVector(timeVector, 100);
75    fitPtr->SetAVector(amplitudeVector, 100);
76    //   fitPtr->Set
77    fitPtr->Evaluate(start, N);
78   
79   double energy;
80   double time;
81
82   time    = fitPtr->GetTiming();
83   energy  = fitPtr->GetEnergy();
84
85   printf("\nReal amplitude \t\t= %lf ADC counts \nReconstructed amplitude\t= %lf ADC counts\n", amplitude, energy);
86   printf("\nReal time \t\t= %lf nanoseconds \nReconstructed time\t= %lf nanoseconds\n", t0, time);
87   printf("\n\nMaximum systematic error in amplitude \t= %lf %%", aSystError);
88   printf("\nMaximum systematic error for timing \t= %lf nanoseconds\n\n", tSystError);
89   return 0;
90 }
91
92 void setFileName(char *fName, int start, int N, double tau, double fs)
93 {
94   sprintf(fName, "PFVectors/start%dN%dtau%.ffs%.f.txt", start, N, tau, fs);
95   //  printf("\nfilename: %s\n", fName);
96 }
97