1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
19 Author: R. GUERNANE LPSC Grenoble CNRS/IN2P3
22 #include "AliCaloRawAnalyzerFakeALTRO.h"
23 #include "AliCaloBunchInfo.h"
24 #include "AliCaloFitResults.h"
31 #include "AliCaloConstants.h"
36 #define BAD 4 //CRAP PTH
38 ClassImp( AliCaloRawAnalyzerFakeALTRO )
41 AliCaloRawAnalyzerFakeALTRO::AliCaloRawAnalyzerFakeALTRO() : AliCaloRawAnalyzer("Chi Square Fit", "LMS"),
42 fkEulerSquared(7.389056098930650227),
48 for(int i=0; i < MAXSAMPLES; i++)
53 fTf1 = new TF1( "myformula", "[0]*((x - [1])/[2])^2*exp(-2*(x -[1])/[2])", 0, 30 );
55 fTf1->FixParameter(2, fTau);
58 fTf1->ReleaseParameter(2); // allow par. to vary
59 fTf1->SetParameter(2, fTau);
65 AliCaloRawAnalyzerFakeALTRO::~AliCaloRawAnalyzerFakeALTRO()
73 AliCaloRawAnalyzerFakeALTRO::Evaluate( const vector<AliCaloBunchInfo> &bunchvector, const UInt_t altrocfg1, const UInt_t altrocfg2 )
75 // Extracting signal parameters using fitting
76 short maxampindex; //index of maximum amplitude
77 short maxamp; //Maximum amplitude
78 int index = SelectBunch( bunchvector, &maxampindex, &maxamp );
82 Float_t ped = ReverseAndSubtractPed( &(bunchvector.at(index)) , altrocfg1, altrocfg2, fReversed );
83 Float_t maxf = TMath::MaxElement( bunchvector.at(index).GetLength(), fReversed );
84 short maxrev = maxampindex - bunchvector.at(index).GetStartBin();
85 // timebinOffset is timebin value at maximum (maxrev)
86 short timebinOffset = maxampindex - (bunchvector.at(index).GetLength()-1);
87 if( maxf < fAmpCut || ( maxamp - ped) > fOverflowCut ) // (maxamp - ped) > fOverflowCut = Close to saturation (use low gain then)
89 return AliCaloFitResults( maxamp, ped, Ret::kCrude, maxf, timebinOffset);
91 else if ( maxf >= fAmpCut )
95 SelectSubarray( fReversed, bunchvector.at(index).GetLength(), maxrev, &first, &last);
96 int nsamples = last - first + 1;
98 if( ( nsamples ) >= fNsampleCut )
100 Float_t tmax = (maxrev - first); // local tmax estimate
101 TGraph *graph = new TGraph( nsamples, fXaxis, &fReversed[first] );
102 fTf1->SetParameter(0, maxf*fkEulerSquared );
103 fTf1->SetParameter(1, tmax - fTau);
104 // set rather loose parameter limits
105 fTf1->SetParLimits(0, 0.5*maxf*fkEulerSquared, 2*maxf*fkEulerSquared );
106 fTf1->SetParLimits(1, tmax - fTau - 4, tmax - fTau + 4);
109 fTf1->FixParameter(2, fTau);
112 fTf1->ReleaseParameter(2); // allow par. to vary
113 fTf1->SetParameter(2, fTau);
116 Short_t tmpStatus = 0;
118 tmpStatus = graph->Fit(fTf1, "Q0RW");
120 catch (const std::exception & e) {
121 AliError( Form("TGraph Fit exception %s", e.what()) );
122 return AliCaloFitResults( maxamp, ped, Ret::kNoFit, maxf, timebinOffset,
123 timebinOffset, Ret::kDummy, Ret::kDummy, Ret::kDummy, AliCaloFitSubarray(index, maxrev, first, last) );
126 if( fVerbose == true )
128 AliCaloRawAnalyzer::PrintBunch( bunchvector.at(index) );
129 PrintFitResult( fTf1 ) ;
132 tmax = fTf1->GetParameter(1) + timebinOffset - (maxrev - first) // abs. t0
133 + fTf1->GetParameter(2); // +tau, makes sum tmax
136 return AliCaloFitResults( maxamp, ped , Ret::kFitPar,
137 fTf1->GetParameter(0)/fkEulerSquared,
140 fTf1->GetChisquare(),
142 Ret::kDummy, AliCaloFitSubarray(index, maxrev, first, last) );
149 Float_t chi2 = CalculateChi2(maxf, maxrev, first, last);
150 Int_t ndf = last - first - 1; // nsamples - 2
151 return AliCaloFitResults( maxamp, ped, Ret::kCrude, maxf, timebinOffset,
152 timebinOffset, chi2, ndf, Ret::kDummy, AliCaloFitSubarray(index, maxrev, first, last) );
156 return AliCaloFitResults( Ret::kInvalid, Ret::kInvalid );
162 AliCaloRawAnalyzerFakeALTRO::PrintFitResult(const TF1 *f) const
166 cout << __FILE__ << __LINE__ << "Using this samplerange we get" << endl;
167 cout << __FILE__ << __LINE__ << "AMPLITUDE = " << f->GetParameter(0)/fkEulerSquared << ",.. !!!!" << endl;
168 cout << __FILE__ << __LINE__ << "TOF = " << f->GetParameter(1) << ",.. !!!!" << endl;
169 cout << __FILE__ << __LINE__ << "NDF = " << f->GetNDF() << ",.. !!!!" << endl;
170 // cout << __FILE__ << __LINE__ << "STATUS = " << f->GetStatus() << ",.. !!!!" << endl << endl;
171 cout << endl << endl;