AliRoot Core  3dc7879 (3dc7879)
AliCaloRawAnalyzerKStandardFast.cxx
Go to the documentation of this file.
1 /**************************************************************************
2 //* This file is property of and copyright by the ALICE HLT Project *
3 //* ALICE Experiment at CERN, All rights reserved. *
4 //* *
5 //* Primary Authors: Rudiger Haake <ruediger.haake@cern.ch>, Yale *
6 //* for The ALICE HLT Project. *
7 //* *
8 //* Permission to use, copy, modify and distribute this software and its *
9 //* documentation strictly for non-commercial purposes is hereby granted *
10 //* without fee, provided that the above copyright notice appears in all *
11 //* copies and that both the copyright notice and this permission notice *
12 //* appear in the supporting documentation. The authors make no claims *
13 //* about the suitability of this software for any purpose. It is *
14 //* provided "as is" without express or implied warranty. *
15 //**************************************************************************/
16 
17 
18 // AliRoot/EMCal system
20 #include "AliCaloBunchInfo.h"
21 #include "AliCaloFitResults.h"
22 #include "AliLog.h"
23 
24 // Standard libraries
25 #include <stdexcept>
26 #include <Math/MinimizerOptions.h>
27 
28 
29 // Root system
30 #include "TF1.h"
31 #include "TGraph.h"
32 #include "TRandom.h"
33 #include "TMath.h"
34 
35 #include "AliEMCALRawResponse.h"
36 
37 using namespace std;
38 
42 
45 //_______________________________________________________________________
47 {
49 
50  // Define fitter function
51  fTf1 = new TF1("signalFit", RawResponseFunction, 0, TIMEBINS , 2);
52  fTf1->SetParameters(10.,5.); //set all defaults once, just to be safe
53  fTf1->SetParNames("amp","t0");
54  ROOT::Math::MinimizerOptions::SetDefaultStrategy(0);
55 
56  fSignal = new TGraph(TIMEBINS);
57 }
58 
61 //_______________________________________________________________________
63 {
64  //delete fTf1; // already done in base class
65  if(fSignal)
66  delete fSignal;
67 }
68 
71 //_______________________________________________________________________
73 AliCaloRawAnalyzerKStandardFast::Evaluate( const vector<AliCaloBunchInfo> &bunchlist,
74  UInt_t altrocfg1, UInt_t altrocfg2 )
75 {
76  Float_t pedEstimate = 0;
77  short maxADC = 0;
78  Int_t first = 0;
79  Int_t last = 0;
80  Int_t bunchIndex = 0;
81  Float_t ampEstimate = 0;
82  short timeEstimate = 0;
83  Float_t time = 0;
84  Float_t amp=0;
85  Float_t chi2 = 0;
86  Int_t ndf = 0;
87  Bool_t fitDone = kFALSE;
88 
89  int nsamples = PreFitEvaluateSamples( bunchlist, altrocfg1, altrocfg2, bunchIndex, ampEstimate,
90  maxADC, timeEstimate, pedEstimate, first, last, (int)fAmpCut );
91 
92 
93  if (ampEstimate >= fAmpCut )
94  {
95  time = timeEstimate;
96  Int_t timebinOffset = bunchlist.at(bunchIndex).GetStartBin() - (bunchlist.at(bunchIndex).GetLength()-1);
97  amp = ampEstimate;
98 
99  if ( nsamples > 1 && maxADC< OVERFLOWCUT )
100  {
101  FitRaw(first, last, amp, time, chi2, fitDone);
102  time += timebinOffset;
103  timeEstimate += timebinOffset;
104  ndf = nsamples - 2;
105  }
106  }
107  if ( fitDone )
108  {
109  Float_t ampAsymm = (amp - ampEstimate)/(amp + ampEstimate);
110  Float_t timeDiff = time - timeEstimate;
111 
112  if ( (TMath::Abs(ampAsymm) > 0.1) || (TMath::Abs(timeDiff) > 2) )
113  {
114  amp = ampEstimate;
115  time = timeEstimate;
116  fitDone = kFALSE;
117  }
118  }
119 
120  if (amp >= fAmpCut )
121  {
122  if ( ! fitDone)
123  {
124  amp += (0.5 - gRandom->Rndm());
125  }
126  time = time * TIMEBINWITH;
127  time -= fL1Phase;
128 
129  return AliCaloFitResults( -99, -99, fAlgo , amp, time,
130  (int)time, chi2, ndf, Ret::kDummy );
131  }
133 }
134 
135 
138 //_______________________________________________________________________
139 void
140  AliCaloRawAnalyzerKStandardFast::FitRaw( Int_t firstTimeBin, Int_t lastTimeBin,
141  Float_t & amp, Float_t & time, Float_t & chi2, Bool_t & fitDone) const
142 {
143  // Changes wrt to kStandard fitter:
144  // * Fit function not created in each FitRaw() call
145  // * Signal histogram fSignal not created in each FitRaw() call
146  // * Adjusted fit range to datapoints
147  // * Fit function simplification
148  // * Use fit option N0
149  // * Minimizer strategy adjusted
150 
151  Int_t nsamples = lastTimeBin - firstTimeBin + 1;
152  fitDone = kFALSE;
153  if ( nsamples < 3 ) return;
154 
155  fSignal->Set(nsamples);
156  for (int i=0; i<nsamples; i++)
157  {
158  Int_t timebin = firstTimeBin + i;
159  fSignal->SetPoint(i, timebin, GetReversed(timebin));
160  }
161 
162  // Initial fit function
163  fTf1->SetRange(lastTimeBin, firstTimeBin);
164  fTf1->SetParameter(1, time);
165  fTf1->SetParameter(0, amp);
166  fTf1->SetParLimits(0, 0.5*amp, 2*amp );
167  fTf1->SetParLimits(1, time - 4, time + 4);
168 
169  try
170  {
171  fSignal->Fit(fTf1, "QROW N0"); // Note option 'W': equal errors on all points, 'R': Use range we set earlier, N0: Do not plot result, Q: quite mode
172  amp = fTf1->GetParameter(0);
173  time = fTf1->GetParameter(1);
174  chi2 = fTf1->GetChisquare();
175 
176  fitDone = kTRUE;
177  }
178  catch (const std::exception & e)
179  {
180  AliError( Form("TH1 Fit exception %s", e.what()) );
181  // stay with default amp and time in case of exception, i.e. no special action required
182  fitDone = kFALSE;
183  }
184 
185  return;
186 }
187 
191 //_______________________________________________________________________
192 Double_t AliCaloRawAnalyzerKStandardFast::RawResponseFunction(Double_t *x, Double_t *par)
193 {
194  Double_t signal = 0.;
195  Double_t xx = ( x[0] - par[1] + TAU ) / TAU;
196 
197  if(xx > 0)
198  signal = par[0] * TMath::Power(xx , ORDER) * TMath::Exp(ORDER * (1 - xx )) ;
199 
200  return signal;
201 }
202 
Raw data fitting: standard TMinuit fit.
Float_t fAmpCut
Max ADC - pedestal must be higher than this befor attemting to extract the amplitude.
void FitRaw(Int_t firstTimeBin, Int_t lastTimeBin, Float_t &amp, Float_t &time, Float_t &chi2, Bool_t &fitDone) const
Fits the raw signal time distribution.
const double TIMEBINWITH
each sample is 100 ns
Container class to hold results from fitting.
const double TAU
Approximate shaping time.
TGraph * fSignal
histogram for signal that will be fit
Double_t chi2
Definition: AnalyzeLaser.C:7
Raw data fitters base class.
Algo::fitAlgorithm fAlgo
Which algorithm to use.
Double_t GetReversed(const int i) const
int PreFitEvaluateSamples(const std::vector< AliCaloBunchInfo > &bunchvector, UInt_t altrocfg1, UInt_t altrocfg2, Int_t &index, Float_t &maxf, short &maxamp, short &maxampindex, Float_t &ped, int &first, int &last, int acut)
Method to do the selection of what should possibly be fitted.
TF1 * fTf1
Analytical formula of the Semi Gaussian to be fitted.
const int ORDER
Order of shaping stages of the signal conditioning unit.
static Double_t RawResponseFunction(Double_t *x, Double_t *par)
Approximate response function of the EMCal electronics. Simplified version, adapted from AliEMCALRawR...
Double_t fL1Phase
Phase of the ADC sampling clock relative to the LHC clock.
const int TIMEBINS
number of sampling bins of the raw RO signal (we typically use 15-50; max is 1k+) ...
virtual AliCaloFitResults Evaluate(const std::vector< AliCaloBunchInfo > &bunchvector, UInt_t altrocfg1, UInt_t altrocfg2)
Evaluation Amplitude and TOF.
#define AliError(message)
Definition: AliLog.h:591
const int OVERFLOWCUT
sample overflow