Raw data decoder is migrated from AliCaloRawStream to AliCaloRawStreamV3
[u/mrichter/AliRoot.git] / PHOS / AliPHOSRawFitterv0.cxx
CommitLineData
379c5c09 1/**************************************************************************
2 * Copyright(c) 2007, ALICE Experiment at CERN, All rights reserved. *
3 * *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
6 * *
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 **************************************************************************/
15
16/* $Id: $ */
17
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 coarse algorithm takes the energy as the maximum
21// sample, time is the first sample index, and the quality is the number
22// of bunches in the signal.
23//
24// AliPHOSRawFitterv0 *fitterv0=new AliPHOSRawFitterv0();
25// fitterv0->SetSamples(sig,sigStart,sigLength);
26// fitterv0->SetNBunches(nBunches);
27// fitterv0->SetChannelGeo(module,cellX,cellZ,caloFlag);
28// fitterv0->SetCalibData(fgCalibData) ;
29// fitterv0->Eval();
30// Double_t amplitude = fitterv0.GetEnergy();
31// Double_t time = fitterv0.GetTime();
32// Bool_t isLowGain = fitterv0.GetCaloFlag()==0;
33
34// Author: Yuri Kharlov
35
36// --- ROOT system ---
37#include "TArrayI.h"
38#include "TMath.h"
39#include "TObject.h"
40
41// --- AliRoot header files ---
42#include "AliPHOSRawFitterv0.h"
43#include "AliPHOSCalibData.h"
44#include "AliLog.h"
45
46ClassImp(AliPHOSRawFitterv0)
47
48//-----------------------------------------------------------------------------
49AliPHOSRawFitterv0::AliPHOSRawFitterv0():
50 TObject(),
51 fSignal(0),
52 fModule(0),
53 fCellX(0),
54 fCellZ(0),
55 fCaloFlag(0),
56 fStart(0),
57 fLength(0),
58 fNBunches(0),
59 fPedSubtract(kFALSE),
60 fEnergy(-111),
61 fTime(-111),
62 fQuality(0.),
63 fPedestalRMS(0.),
64 fAmpOffset(0),
65 fAmpThreshold(0),
66 fOverflow(kFALSE),
67 fCalibData(0)
68{
69 //Default constructor
70}
71
72//-----------------------------------------------------------------------------
73AliPHOSRawFitterv0::~AliPHOSRawFitterv0()
74{
75 //Destructor
76 delete [] fSignal;
77}
78
79//-----------------------------------------------------------------------------
80AliPHOSRawFitterv0::AliPHOSRawFitterv0(const AliPHOSRawFitterv0 &phosFitter ):
81 TObject(),
82 fSignal (phosFitter.fSignal),
83 fModule (phosFitter.fModule),
84 fCellX (phosFitter.fCellX),
85 fCellZ (phosFitter.fCellZ),
86 fCaloFlag (phosFitter.fCaloFlag),
87 fStart (phosFitter.fStart),
88 fLength (phosFitter.fLength),
89 fNBunches (phosFitter.fNBunches),
90 fPedSubtract (phosFitter.fPedSubtract),
91 fEnergy (phosFitter.fEnergy),
92 fTime (phosFitter.fTime),
93 fQuality (phosFitter.fQuality),
94 fPedestalRMS (phosFitter.fPedestalRMS),
95 fAmpOffset (phosFitter.fAmpOffset),
96 fAmpThreshold(phosFitter.fAmpThreshold),
97 fOverflow (phosFitter.fOverflow),
98 fCalibData (phosFitter.fCalibData)
99{
100 //Copy constructor
101}
102
103//-----------------------------------------------------------------------------
104AliPHOSRawFitterv0& AliPHOSRawFitterv0::operator = (const AliPHOSRawFitterv0 &phosFitter)
105{
106 //Assignment operator.
107
108 if(this != &phosFitter) {
109 fSignal = phosFitter.fSignal;
110 fModule = phosFitter.fModule;
111 fCellX = phosFitter.fCellX;
112 fCellZ = phosFitter.fCellZ;
113 fCaloFlag = phosFitter.fCaloFlag;
114 fStart = phosFitter.fStart;
115 fLength = phosFitter.fLength;
116 fNBunches = phosFitter.fNBunches;
117 fPedSubtract = phosFitter.fPedSubtract;
118 fEnergy = phosFitter.fEnergy;
119 fTime = phosFitter.fTime;
120 fQuality = phosFitter.fQuality;
121 fPedestalRMS = phosFitter.fPedestalRMS;
122 fAmpOffset = phosFitter.fAmpOffset;
123 fAmpThreshold = phosFitter.fAmpThreshold;
124 fOverflow = phosFitter.fOverflow;
125 fCalibData = phosFitter.fCalibData;
126 }
127
128 return *this;
129}
130
131//-----------------------------------------------------------------------------
132
133void AliPHOSRawFitterv0::SetSamples(const UShort_t *sig, Int_t sigStart, Int_t sigLength)
134{
135 // Set the sample array, its start and length in time bin units
136
137 fStart = sigStart;
138 fLength = sigLength;
139 fSignal = new UShort_t[fLength];
140 for (Int_t i=0; i<fLength; i++) {
141 fSignal[i] = sig[i];
142 }
143}
144//-----------------------------------------------------------------------------
145
146void AliPHOSRawFitterv0::SetChannelGeo(const Int_t module, const Int_t cellX,
147 const Int_t cellZ, const Int_t caloFlag)
148{
149 // Set geometry address of the channel
150 // (for a case if fitting parameters are different for different channels)
151
152 fModule = module;
153 fCellX = cellX;
154 fCellZ = cellZ;
155 fCaloFlag = caloFlag;
156}
157//-----------------------------------------------------------------------------
158
159Bool_t AliPHOSRawFitterv0::Eval()
160{
161 // Calculate signal parameters (energy, time, quality) from array of samples
162 // Energy is a maximum sample minus pedestal 9
163 // Time is the first time bin
164 // Signal overflows is there are at least 3 samples of the same amplitude above 900
165
166 fEnergy = 0;
167 if (fNBunches > 1) {
168 fQuality = 1000;
169 return kTRUE;
170 }
171
172 const Float_t kBaseLine = 1.0;
173 const Int_t kPreSamples = 10;
174
175 Float_t pedMean = 0;
176 Float_t pedRMS = 0;
177 Int_t nPed = 0;
178 UShort_t maxSample = 0;
179 Int_t nMax = 0;
180
181 for (Int_t i=0; i<fLength; i++) {
182 if (i<kPreSamples) {
183 nPed++;
184 pedMean += fSignal[i];
185 pedRMS += fSignal[i]*fSignal[i] ;
186 }
187 if(fSignal[i] > maxSample) maxSample = fSignal[i];
188 if(fSignal[i] == maxSample) nMax++;
189 }
190 fEnergy = (Double_t)maxSample;
191 if (maxSample > 900 && nMax > 2) fOverflow = kTRUE;
192
193 if (fPedSubtract) {
194 if (nPed > 0) {
195 fPedestalRMS=(pedRMS - pedMean*pedMean/nPed)/nPed ;
196 if(fPedestalRMS > 0.)
197 fPedestalRMS = TMath::Sqrt(fPedestalRMS) ;
198 fEnergy -= (Double_t)(pedMean/nPed); // pedestal subtraction
199 }
200 else
201 return kFALSE;
202 }
203 else {
204 //take pedestals from DB
205 Double_t pedestal = (Double_t) fAmpOffset ;
206 if (fCalibData) {
207 Float_t truePed = fCalibData->GetADCpedestalEmc(fModule, fCellZ, fCellX) ;
208 Int_t altroSettings = fCalibData->GetAltroOffsetEmc(fModule, fCellZ, fCellX) ;
209 pedestal += truePed - altroSettings ;
210 }
211 else{
212 AliWarning(Form("Can not read data from OCDB")) ;
213 }
214 fEnergy-=pedestal ;
215 }
216 if (fEnergy < kBaseLine) fEnergy = 0;
217
218 return kTRUE;
219
220}