1 /**************************************************************************
2 * This file is property of and copyright by *
3 * the Relativistic Heavy Ion Group (RHIG), Yale University, US, 2009 *
5 * Primary Author: Per Thomas Hille <p.t.hille@fys.uio.no> *
7 * Contributors are mentioned in the code where appropriate. *
8 * Please report bugs to p.t.hille@fys.uio.no *
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 **************************************************************************/
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)
27 #include "AliCaloRawAnalyzerKStandard.h"
28 #include "AliCaloBunchInfo.h"
29 #include "AliCaloFitResults.h"
38 #include "AliEMCALRawResponse.h"
43 ClassImp( AliCaloRawAnalyzerKStandard )
46 AliCaloRawAnalyzerKStandard::AliCaloRawAnalyzerKStandard() : AliCaloRawAnalyzerFitter("Chi Square ( kStandard )", "KStandard")
49 fAlgo = Algo::kStandard;
53 AliCaloRawAnalyzerKStandard::~AliCaloRawAnalyzerKStandard()
60 AliCaloRawAnalyzerKStandard::Evaluate( const vector<AliCaloBunchInfo> &bunchlist, const UInt_t altrocfg1, const UInt_t altrocfg2 )
62 //Evaluation Amplitude and TOF
63 Float_t pedEstimate = 0;
68 Float_t ampEstimate = 0;
69 short timeEstimate = 0;
74 Bool_t fitDone = kFALSE;
75 int nsamples = PreFitEvaluateSamples( bunchlist, altrocfg1, altrocfg2, bunchIndex, ampEstimate,
76 maxADC, timeEstimate, pedEstimate, first, last, (int)fAmpCut );
79 if (ampEstimate >= fAmpCut )
82 Int_t timebinOffset = bunchlist.at(bunchIndex).GetStartBin() - (bunchlist.at(bunchIndex).GetLength()-1);
85 if ( nsamples > 1 && maxADC< OVERFLOWCUT )
87 FitRaw(first, last, amp, time, chi2, fitDone);
88 time += timebinOffset;
89 timeEstimate += timebinOffset;
95 Float_t ampAsymm = (amp - ampEstimate)/(amp + ampEstimate);
96 Float_t timeDiff = time - timeEstimate;
98 if ( (TMath::Abs(ampAsymm) > 0.1) || (TMath::Abs(timeDiff) > 2) )
109 amp += (0.5 - gRandom->Rndm());
111 time = time * TIMEBINWITH;
114 return AliCaloFitResults( -99, -99, fAlgo , amp, time,
115 (int)time, chi2, ndf, Ret::kDummy );
117 return AliCaloFitResults( Ret::kInvalid, Ret::kInvalid );
122 AliCaloRawAnalyzerKStandard::FitRaw(const Int_t firstTimeBin, const Int_t lastTimeBin, Float_t & amp, Float_t & time, Float_t & chi2, Bool_t & fitDone) const
124 // Fits the raw signal time distribution
125 int nsamples = lastTimeBin - firstTimeBin + 1;
127 if (nsamples < 3) { return; }
129 TGraph *gSig = new TGraph( nsamples);
131 for (int i=0; i<nsamples; i++)
133 Int_t timebin = firstTimeBin + i;
134 gSig->SetPoint(i, timebin, GetReversed(timebin));
137 TF1 * signalF = new TF1("signal", AliEMCALRawResponse::RawResponseFunction, 0, TIMEBINS , 5);
139 signalF->SetParameters(10.,5., TAU ,ORDER,0.); //set all defaults once, just to be safe
140 signalF->SetParNames("amp","t0","tau","N","ped");
141 signalF->FixParameter(2,TAU);
142 signalF->FixParameter(3,ORDER);
143 signalF->FixParameter(4, 0);
144 signalF->SetParameter(1, time);
145 signalF->SetParameter(0, amp);
146 signalF->SetParLimits(0, 0.5*amp, 2*amp );
147 signalF->SetParLimits(1, time - 4, time + 4);
150 gSig->Fit(signalF, "QROW"); // Note option 'W': equal errors on all points
151 amp = signalF->GetParameter(0);
152 time = signalF->GetParameter(1);
153 chi2 = signalF->GetChisquare();
156 catch (const std::exception & e)
158 AliError( Form("TGraph Fit exception %s", e.what()) );
159 // stay with default amp and time in case of exception, i.e. no special action required
164 delete gSig; // delete TGraph