1 /**************************************************************************
2 * Copyright(c) 2007, 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 **************************************************************************/
18 // This class extracts the signal parameters (energy, time, quality)
19 // from ALTRO samples. Energy is in ADC counts, time is in time bin units.
20 // A fitting algorithm evaluates the energy and the time from Minuit minimization
23 // AliPHOSRawFitter *fitter=new AliPHOSRawFitter();
24 // fitter->SetSamples(sig,sigStart,sigLength);
25 // fitter->SetNBunches(nBunches);
26 // fitter->SetChannelGeo(module,cellX,cellZ,caloFlag);
27 // fitter->SetCalibData(fgCalibData) ;
29 // Double_t amplitude = fitter.GetEnergy();
30 // Double_t time = fitter.GetTime();
31 // Bool_t isLowGain = fitter.GetCaloFlag()==0;
33 // Author: Dmitri Peressounko (Oct.2008)
34 // Modified: Yuri Kharlov (Jul.2009)
36 // --- ROOT system ---
47 // --- AliRoot header files ---
49 #include "AliPHOSCalibData.h"
50 #include "AliPHOSRawFitterv1.h"
51 #include "AliPHOSPulseGenerator.h"
53 ClassImp(AliPHOSRawFitterv1)
55 //-----------------------------------------------------------------------------
56 AliPHOSRawFitterv1::AliPHOSRawFitterv1():
58 fSampleParamsLow(0x0),
59 fSampleParamsHigh(0x0),
62 //Default constructor.
64 gMinuit = new TMinuit(100);
65 fSampleParamsHigh =new TArrayD(7) ;
66 fSampleParamsHigh->AddAt(2.174,0) ;
67 fSampleParamsHigh->AddAt(0.106,1) ;
68 fSampleParamsHigh->AddAt(0.173,2) ;
69 fSampleParamsHigh->AddAt(0.06106,3) ;
70 //last two parameters are pedestal and overflow
71 fSampleParamsLow=new TArrayD(7) ;
72 fSampleParamsLow->AddAt(2.456,0) ;
73 fSampleParamsLow->AddAt(0.137,1) ;
74 fSampleParamsLow->AddAt(2.276,2) ;
75 fSampleParamsLow->AddAt(0.08246,3) ;
76 fToFit = new TList() ;
79 //-----------------------------------------------------------------------------
80 AliPHOSRawFitterv1::~AliPHOSRawFitterv1()
84 delete fSampleParamsLow ;
87 if(fSampleParamsHigh){
88 delete fSampleParamsHigh ;
97 //-----------------------------------------------------------------------------
98 AliPHOSRawFitterv1::AliPHOSRawFitterv1(const AliPHOSRawFitterv1 &phosFitter ):
99 AliPHOSRawFitterv0(phosFitter),
100 fSampleParamsLow(0x0),
101 fSampleParamsHigh(0x0),
105 fToFit = new TList() ;
106 fSampleParamsLow =new TArrayD(*(phosFitter.fSampleParamsLow)) ;
107 fSampleParamsHigh=new TArrayD(*(phosFitter.fSampleParamsHigh)) ;
110 //-----------------------------------------------------------------------------
111 AliPHOSRawFitterv1& AliPHOSRawFitterv1::operator = (const AliPHOSRawFitterv1 &phosFitter)
113 //Assignment operator.
115 fToFit = new TList() ;
116 if(fSampleParamsLow){
117 fSampleParamsLow = phosFitter.fSampleParamsLow ;
118 fSampleParamsHigh= phosFitter.fSampleParamsHigh ;
121 fSampleParamsLow =new TArrayD(*(phosFitter.fSampleParamsLow)) ;
122 fSampleParamsHigh=new TArrayD(*(phosFitter.fSampleParamsHigh)) ;
127 //-----------------------------------------------------------------------------
128 Bool_t AliPHOSRawFitterv1::Eval()
130 //Extract an energy deposited in the crystal,
131 //crystal' position (module,column,row),
132 //time and gain (high or low).
133 //First collects sample, then evaluates it and if it has
134 //reasonable shape, fits it with Gamma2 function and extracts
145 const Float_t kBaseLine = 1.0;
146 const Int_t kPreSamples = 10;
148 TArrayI *fSamples = new TArrayI(fLength); // array of samples
149 TArrayI *fTimes = new TArrayI(fLength); // array of times corresponding to samples
150 for (Int_t i=0; i<fLength; i++) {
153 pedMean += fSignal[i];
154 pedRMS += fSignal[i]*fSignal[i] ;
156 fSamples->AddAt(fSignal[i],i);
157 fTimes ->AddAt( i ,i);
160 Int_t iBin = fSamples->GetSize() ;
163 const Float_t sampleMaxHG=102.332 ; //maximal height of HG sample with given parameterization
164 const Float_t sampleMaxLG=277.196 ; //maximal height of LG sample with given parameterization
165 const Float_t maxEtoFit=5 ; //fit only samples above this energy, accept all samples (with good aRMS) below it
166 Double_t pedestal = 0;
170 fPedestalRMS=(pedRMS - pedMean*pedMean/nPed)/nPed ;
171 if(fPedestalRMS > 0.)
172 fPedestalRMS = TMath::Sqrt(fPedestalRMS) ;
173 fEnergy -= (Double_t)(pedMean/nPed); // pedestal subtraction
179 //take pedestals from DB
180 pedestal = (Double_t) fAmpOffset ;
182 Float_t truePed = fCalibData->GetADCpedestalEmc(fModule, fCellZ, fCellX) ;
183 Int_t altroSettings = fCalibData->GetAltroOffsetEmc(fModule, fCellZ, fCellX) ;
184 pedestal += truePed - altroSettings ;
187 AliWarning(Form("Can not read data from OCDB")) ;
192 if (fEnergy < kBaseLine) fEnergy = 0;
194 //calculate time and energy
201 for(Int_t i=0; i<fSamples->GetSize(); i++){
202 if(fSamples->At(i) > pedestal){
203 Double_t de=fSamples->At(i)-pedestal ;
209 if(de>2 && tStart==0)
211 if(maxAmp<fSamples->At(i)){
213 maxAmp=fSamples->At(i) ;
217 if(maxBin==fSamples->GetSize()-1){//bad "rising" sample
223 fEnergy=Double_t(maxAmp)-pedestal ;
224 fOverflow =0 ; //look for plato on the top of sample
225 if(fEnergy>500 && //this is not fluctuation of soft sample
226 maxBin<fSamples->GetSize()-1 && fSamples->At(maxBin+1)==maxAmp){ //and there is a plato
232 aRMS=aRMS/wts-aMean*aMean;
235 //do not take too small energies
236 if(fEnergy < kBaseLine)
239 //do not test quality of too soft samples
240 if(fEnergy<maxEtoFit){
241 fTime=fTimes->At(tStart);
242 if(aRMS<2.) //sigle peak
249 //IF sample has reasonable mean and RMS, try to fit it with gamma2
251 gMinuit->mncler(); // Reset Minuit's list of paramters
252 gMinuit->SetPrintLevel(-1) ; // No Printout
253 gMinuit->SetFCN(AliPHOSRawFitterv1::UnfoldingChiSquare) ;
254 // To set the address of the minimization function
256 fToFit->Clear("nodelete") ;
257 Double_t b=0,bmin=0,bmax=0 ;
258 if(fCaloFlag == 0){ // Low gain
259 fSampleParamsLow->AddAt(pedestal,4) ;
261 fSampleParamsLow->AddAt(double(maxAmp),5) ;
263 fSampleParamsLow->AddAt(double(1023),5) ;
264 fSampleParamsLow->AddAt(double(iBin),6) ;
265 fToFit->AddFirst((TObject*)fSampleParamsLow) ;
266 b=fSampleParamsLow->At(2) ;
270 else if(fCaloFlag == 1){ // High gain
271 fSampleParamsHigh->AddAt(pedestal,4) ;
273 fSampleParamsHigh->AddAt(double(maxAmp),5) ;
275 fSampleParamsHigh->AddAt(double(1023),5);
276 fSampleParamsHigh->AddAt(double(iBin),6);
277 fToFit->AddFirst((TObject*)fSampleParamsHigh) ;
278 b=fSampleParamsHigh->At(2) ;
282 fToFit->AddLast((TObject*)fSamples) ;
283 fToFit->AddLast((TObject*)fTimes) ;
285 gMinuit->SetObjectFit((TObject*)fToFit) ; // To tranfer pointer to UnfoldingChiSquare
287 gMinuit->mnparm(0, "t0", 1.*tStart, 0.01, -500., 500., ierflg) ;
289 // AliWarning(Form("Unable to set initial value for fit procedure : t0=%e\n",1.*tStart) ) ;
293 return kTRUE ; //will scan further
296 if(fCaloFlag == 0) // Low gain
297 amp0=fEnergy/sampleMaxLG;
298 else if(fCaloFlag == 1) // High gain
299 amp0=fEnergy/sampleMaxHG;
301 gMinuit->mnparm(1, "Energy", amp0 , 0.01*amp0, 0, 0, ierflg) ;
303 // AliWarning(Form("Unable to set initial value for fit procedure : E=%e\n", amp0)) ;
307 return kTRUE ; //will scan further
310 gMinuit->mnparm(2, "p2", b, 0.01*b, bmin, bmax, ierflg) ;
312 // AliWarning(Form("Unable to set initial value for fit procedure : E=%e\n", amp0)) ;
316 return kTRUE ; //will scan further
320 Double_t p0 = 0.0001 ; // "Tolerance" Evaluation stops when EDM = 0.0001*p0 ; The number of function call slightly
324 gMinuit->mnexcm("SET STR", &p2, 0, ierflg) ; // force TMinuit to reduce function calls
325 gMinuit->mnexcm("SET GRA", &p1, 1, ierflg) ; // force TMinuit to use my gradient
326 // gMinuit->SetMaxIterations(100);
327 gMinuit->mnexcm("SET NOW", &p2 , 0, ierflg) ; // No Warnings
329 gMinuit->mnexcm("MIGRAD", &p0, 0, ierflg) ; // minimize
333 gMinuit->GetParameter(0,t0, t0err) ;
334 gMinuit->GetParameter(1,efit, err) ;
336 Double_t bfit, berr ;
337 gMinuit->GetParameter(2,bfit,berr) ;
339 //Calculate total energy
340 //this isparameterization of depetendence of pulse height on parameter b
341 if(fCaloFlag == 0) // Low gain
342 efit*=99.54910 + 78.65038*bfit ;
343 else if(fCaloFlag == 1) // High gain
344 efit*=80.33109+128.6433*bfit ;
346 if(efit<0. || efit > 10000.){
347 //set energy to previously found max
353 //evaluate fit quality
354 Double_t fmin,fedm,errdef ;
355 Int_t npari,nparx,istat;
356 gMinuit->mnstat(fmin,fedm,errdef,npari,nparx,istat) ;
357 fQuality=fmin/(fSamples->GetSize()-iBin) ;
358 //compare quality with some parameterization
359 if(fCaloFlag == 0) // Low gain
360 fQuality/=2.+0.002*fEnergy ;
361 else if(fCaloFlag == 1) // High gain
362 fQuality/=0.75+0.0025*fEnergy ;
365 fTime=t0-4.024*bfit ; //-10.402*bfit+4.669*bfit*bfit ; //Correction for 70 samples
371 //_____________________________________________________________________________
372 void AliPHOSRawFitterv1::UnfoldingChiSquare(Int_t & /*nPar*/, Double_t * Grad, Double_t & fret, Double_t * x, Int_t iflag)
374 // Number of parameters, Gradient, Chi squared, parameters, what to do
376 TList * toFit= (TList*)gMinuit->GetObjectFit() ;
377 TArrayD * params=(TArrayD*)toFit->At(0) ;
378 TArrayI * samples = (TArrayI*)toFit->At(1) ;
379 TArrayI * times = (TArrayI*)toFit->At(2) ;
383 for(Int_t iparam = 0 ; iparam < 3 ; iparam++)
384 Grad[iparam] = 0 ; // Will evaluate gradient
389 Double_t n=params->At(0) ;
390 Double_t alpha=params->At(1) ;
391 Double_t beta=params->At(3) ;
392 Double_t ped=params->At(4) ;
394 Double_t overflow=params->At(5) ;
395 Int_t iBin = (Int_t) params->At(6) ;
396 Int_t nSamples=TMath::Min(iBin+70,samples->GetSize()) ; //Here we set number of points to fit (70)
397 // iBin - first non-zero sample
398 Int_t tStep=times->At(iBin+1)-times->At(iBin) ;
399 Double_t ddt=times->At(iBin)-t0-tStep ;
400 Double_t exp1=TMath::Exp(-alpha*ddt) ;
401 Double_t exp2=TMath::Exp(-beta*ddt) ;
402 Double_t dexp1=TMath::Exp(-alpha*tStep) ;
403 Double_t dexp2=TMath::Exp(-beta*tStep) ;
404 for(Int_t i = iBin; i<nSamples ; i++) {
405 Double_t dt=double(times->At(i))-t0 ;
406 Double_t fsample = double(samples->At(i)) ;
407 if(fsample>=overflow)
417 Double_t dtn=TMath::Power(dt,n) ;
418 Double_t dtnE=dtn*exp1 ;
419 Double_t dt2E=dt*dt*exp2 ;
420 Double_t fit=ped+en*(dtnE + b*dt2E) ;
421 diff = fsample - fit ;
423 if(iflag == 2){ // calculate gradient
424 Grad[0] += en*diff*(dtnE*(n/dt-alpha)+b*dt2E*(2./dt-beta)) ; //derivative over t0
425 Grad[1] -= diff*(dtnE+b*dt2E) ;
426 Grad[2] -= en*diff*dt2E ;
430 for(Int_t iparam = 0 ; iparam < 3 ; iparam++)
433 //-----------------------------------------------------------------------------
434 Double_t AliPHOSRawFitterv1::Gamma2(Double_t dt,Double_t en,Double_t b,TArrayD * params){ //Function for fitting samples
436 //dt-time after start
438 //function parameters
440 Double_t ped=params->At(4) ;
442 return ped ; //pedestal
444 return ped+en*(TMath::Power(dt,params->At(0))*TMath::Exp(-dt*params->At(1))+b*dt*dt*TMath::Exp(-dt*params->At(3))) ;