]> git.uio.no Git - u/mrichter/AliRoot.git/blob - EMCAL/AliCaloRawAnalyzerLMS.cxx
Fix in the file open option
[u/mrichter/AliRoot.git] / EMCAL / AliCaloRawAnalyzerLMS.cxx
1 /**************************************************************************
2  * This file is property of and copyright by                              *
3  * the Relativistic Heavy Ion Group (RHIG), Yale University, US, 2009     *
4  *                                                                        *
5  * Primary Author: Per Thomas Hille <p.t.hille@fys.uio.no>                *
6  *                                                                        *
7  * Contributors are mentioned in the code where appropriate.              *
8  * Please report bugs to p.t.hille@fys.uio.no                             *
9  *                                                                        *
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  **************************************************************************/
18
19
20 // Extraction of amplitude and peak position
21 // FRom CALO raw data using
22 // least square fit for the
23 // Moment assuming identical and 
24 // independent errors (equivalent with chi square)
25 // 
26
27 #include "AliCaloRawAnalyzerLMS.h"
28 #include "AliCaloBunchInfo.h"
29 #include "AliCaloFitResults.h"
30 #include "AliLog.h"
31 #include "TMath.h"
32 #include <iostream>
33 #include "TF1.h"
34 #include "TGraph.h"
35
36 using namespace std;
37
38
39 #define BAD 4  //CRAP PTH
40
41
42 AliCaloRawAnalyzerLMS::AliCaloRawAnalyzerLMS() : AliCaloRawAnalyzer(),
43                                                  fkEulerSquared(7.389056098930650227),
44                                                  fSig(0),
45                                                  fTf1(0)
46 {
47   //comment
48   for(int i=0; i < MAXSAMPLES; i++)
49     {
50       fXaxis[i] = i;
51     }
52   
53   fTf1 = new TF1( "myformula", "[0]*((x - [1])/2.35)^2*exp(-2*(x -[1])/2.35)",  0, 30 ); 
54   //  fTf1 = new TF1( "myformula", "[0]*((x - [1])/[2])^[3]*exp(-[3]*(x -[1])/[2])",  0, 30 ); 
55
56 }
57
58
59 AliCaloRawAnalyzerLMS::~AliCaloRawAnalyzerLMS()
60 {
61   delete fTf1;
62 }
63
64
65
66 AliCaloFitResults
67 AliCaloRawAnalyzerLMS::Evaluate( const vector<AliCaloBunchInfo>  &bunchvector, const UInt_t altrocfg1,  const UInt_t altrocfg2 )
68 {
69   // Extracting signal parameters using fitting
70   short maxampindex; //index of maximum amplitude
71   short maxamp; //Maximum amplitude
72   int index = SelectBunch( bunchvector,  &maxampindex,  &maxamp );
73   
74   if( index >= 0)
75     {
76       Float_t  ped  = ReverseAndSubtractPed( &(bunchvector.at(index))  ,  altrocfg1, altrocfg2, fReversed  );
77       int first;
78       int last;
79       Float_t maxf = TMath::MaxElement( bunchvector.at(index).GetLength(),  fReversed );
80
81       if ( maxf > fAmpCut )
82         {
83           SelectSubarray( fReversed,  bunchvector.at(index).GetLength(),  maxampindex -  bunchvector.at(index).GetStartBin(), &first, &last);
84           int nsamples =  last - first;
85           
86           if( ( nsamples  )  > fNsampleCut )
87             {
88               
89               TGraph *graph =  new TGraph(  last - first, fXaxis,  &fReversed[first] );
90               fTf1->SetParameter(0, maxf*fkEulerSquared );
91               fTf1->SetParameter(1, 0.2);
92               //              fTf1->SetParameter(2,  2);
93               //              fTf1->SetParameter(2,  3); 
94             
95               //     return   AliCaloFitResults( -1 , -1 , -1, -1, -1, -1 , -1); 
96
97               Short_t tmpStatus =  graph->Fit(fTf1, "Q0RW");
98              
99               //       return   AliCaloFitResults( -1 , -1 , -1, -1, -1, -1 , -1); 
100  
101               if( fVerbose == true )
102                 {
103                   AliCaloRawAnalyzer::PrintBunch( bunchvector.at(index) ); 
104                   PrintFitResult( fTf1 ) ;
105                 }  
106               
107                 delete graph;
108                 return AliCaloFitResults( maxamp, ped ,    tmpStatus,  
109                                          fTf1->GetParameter(0)/fkEulerSquared, 
110                                          fTf1->GetParameter(1) + maxampindex,  
111                                          fTf1->GetChisquare(), 
112                                          fTf1->GetNDF());
113                 
114                 
115                 //     delete graph;
116         
117             }
118           else
119             {
120               return AliCaloFitResults( maxamp, ped, -1, maxf, -1, -1, -1 );
121             }
122         }
123       else
124         {
125           return AliCaloFitResults( maxamp , ped, -1, maxf, -1, -1, -1 );
126         }       
127     }
128   else
129     {
130       return AliCaloFitResults( -99, -99 );
131     }
132
133   return AliCaloFitResults( -99, -99 );
134   
135 }
136
137
138 void 
139 AliCaloRawAnalyzerLMS::PrintFitResult(const TF1 *f) const
140 {
141   //comment
142   cout << endl;
143   cout << __FILE__ << __LINE__ << "Using this samplerange we get" << endl;
144   cout << __FILE__ << __LINE__ << "AMPLITUDE = " << f->GetParameter(0)/fkEulerSquared << ",.. !!!!" << endl;
145   cout << __FILE__ << __LINE__ << "TOF = " << f->GetParameter(1) << ",.. !!!!" << endl;
146   cout << __FILE__ << __LINE__ << "NDF = " << f->GetNDF() << ",.. !!!!" << endl;
147   //  cout << __FILE__ << __LINE__ << "STATUS = " << f->GetStatus()  << ",.. !!!!" << endl << endl;
148   cout << endl << endl;
149 }