]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PHOS/AliPHOSRawDecoder.cxx
Compilation warning in CreateInputs is fixed
[u/mrichter/AliRoot.git] / PHOS / AliPHOSRawDecoder.cxx
CommitLineData
a29c28b6 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
7bc140a5 16/* $Id$ */
17
a29c28b6 18// This class decodes the stream of ALTRO samples to extract
19// the PHOS "digits" of current event.
20//
21// Typical use case:
22// AliRawReader* rf = new AliRawReaderDate("2006run2211.raw");
b1a8a9cb 23// AliPHOSRawDecoder dc(rf);
a29c28b6 24// while (rf->NextEvent()) {
a29c28b6 25// dc.SubtractPedestals(kTRUE);
26// while ( dc.NextDigit() ) {
27// Int_t module = dc.GetModule();
28// Int_t column = dc.GetColumn();
29// Int_t row = dc.GetRow();
30// Double_t amplitude = dc.GetEnergy();
31// Double_t time = dc.GetTime();
32// Bool_t IsLowGain = dc.IsLowGain();
33// ..........
34// }
35// }
36
37// Author: Boris Polichtchouk
38
39// --- ROOT system ---
b1a8a9cb 40#include "TArrayI.h"
3876e91d 41#include "TMath.h"
a29c28b6 42
43// --- AliRoot header files ---
44#include "AliPHOSRawDecoder.h"
c5d477f8 45#include "AliRawReader.h"
bafc1087 46#include "AliPHOSCalibData.h"
47#include "AliLog.h"
c5d477f8 48
a29c28b6 49ClassImp(AliPHOSRawDecoder)
50
51//-----------------------------------------------------------------------------
52AliPHOSRawDecoder::AliPHOSRawDecoder():
6d1f3e73 53 TObject(),
54 fRawReader(0),
55 fCaloStream(0),
56 fPedSubtract(kFALSE),
57 fEnergy(-111),
58 fTime(-111),
59 fQuality(0.),
60 fPedestalRMS(0.),
61 fAmpOffset(0),
62 fAmpThreshold(0),
63 fModule(-1),
64 fColumn(-1),
65 fRow(-1),
66 fNewModule(-1),
67 fNewColumn(-1),
68 fNewRow(-1),
69 fNewAmp(0),
70 fNewTime(0),
71 fLowGainFlag(kFALSE),
72 fNewLowGainFlag(kFALSE),
73 fOverflow(kFALSE),
74 fSamples(0),
75 fTimes(0),
76 fCalibData(0)
a29c28b6 77{
78 //Default constructor.
79}
80
81//-----------------------------------------------------------------------------
467957dc 82AliPHOSRawDecoder::AliPHOSRawDecoder(AliRawReader* rawReader, AliAltroMapping **mapping):
6d1f3e73 83 TObject(),
84 fRawReader(0),
85 fCaloStream(0),
86 fPedSubtract(kFALSE),
87 fEnergy(-111),
88 fTime(-111),
89 fQuality(0.),
90 fPedestalRMS(0.),
91 fAmpOffset(0),
92 fAmpThreshold(0),
93 fModule(-1),
94 fColumn(-1),
95 fRow(-1),
96 fNewModule(-1),
97 fNewColumn(-1),
98 fNewRow(-1),
99 fNewAmp(0),
100 fNewTime(0),
101 fLowGainFlag(kFALSE),
102 fNewLowGainFlag(kFALSE),
103 fOverflow(kFALSE),
104 fSamples(0),
105 fTimes(0),
106 fCalibData(0)
a29c28b6 107{
108 //Construct a decoder object.
109 //Is is user responsibility to provide next raw event
110 //using AliRawReader::NextEvent().
111
112 fRawReader = rawReader;
467957dc 113 fCaloStream = new AliCaloRawStream(rawReader,"PHOS",mapping);
b1a8a9cb 114 fSamples = new TArrayI(100);
14100b90 115 fTimes = new TArrayI(100);
a29c28b6 116}
117
118//-----------------------------------------------------------------------------
119AliPHOSRawDecoder::~AliPHOSRawDecoder()
120{
121 //Destructor.
122
14100b90 123 if(fCaloStream){ delete fCaloStream; fCaloStream=0;}
124 if(fSamples){ delete fSamples; fSamples=0 ;}
125 if(fTimes){ delete fTimes; fTimes=0 ;}
a29c28b6 126}
127
128//-----------------------------------------------------------------------------
129AliPHOSRawDecoder::AliPHOSRawDecoder(const AliPHOSRawDecoder &phosDecoder ):
6d1f3e73 130 TObject(),
131 fRawReader(phosDecoder.fRawReader),
132 fCaloStream(phosDecoder.fCaloStream),
a29c28b6 133 fPedSubtract(phosDecoder.fPedSubtract),
6d1f3e73 134 fEnergy(phosDecoder.fEnergy),
135 fTime(phosDecoder.fTime),
136 fQuality(phosDecoder.fQuality),
137 fPedestalRMS(phosDecoder.fPedestalRMS),
138 fAmpOffset(phosDecoder.fAmpOffset),
139 fAmpThreshold(phosDecoder.fAmpThreshold),
140 fModule(phosDecoder.fModule),
141 fColumn(phosDecoder.fColumn),
142 fRow(phosDecoder.fRow),
143 fNewModule(phosDecoder.fNewModule),
144 fNewColumn(phosDecoder.fNewColumn),
145 fNewRow(phosDecoder.fNewRow),
146 fNewAmp(phosDecoder.fNewAmp),
147 fNewTime(phosDecoder.fNewTime),
148 fLowGainFlag(phosDecoder.fLowGainFlag),
149 fNewLowGainFlag(phosDecoder.fNewLowGainFlag),
150 fOverflow(phosDecoder.fOverflow),
151 fSamples(phosDecoder.fSamples),
152 fTimes(phosDecoder.fTimes),
153 fCalibData(phosDecoder.fCalibData)
a29c28b6 154{
155 //Copy constructor.
156}
157
158//-----------------------------------------------------------------------------
159AliPHOSRawDecoder& AliPHOSRawDecoder::operator = (const AliPHOSRawDecoder &phosDecode)
160{
7bc140a5 161 //Assignment operator.
162
a29c28b6 163 if(this != &phosDecode) {
164 fRawReader = phosDecode.fRawReader;
165
166 if(fCaloStream) delete fCaloStream;
167 fCaloStream = phosDecode.fCaloStream;
168
169 fEnergy = phosDecode.fEnergy;
170 fTime = phosDecode.fTime;
70d93620 171 fQuality = phosDecode.fQuality ;
60144e5f 172 fPedestalRMS = phosDecode.fPedestalRMS ;
173 fAmpOffset = phosDecode.fAmpOffset ;
a29c28b6 174 fModule = phosDecode.fModule;
175 fColumn = phosDecode.fColumn;
176 fRow = phosDecode.fRow;
39569d36 177 fNewModule = phosDecode.fNewModule;
178 fNewColumn = phosDecode.fNewColumn;
179 fNewRow = phosDecode.fNewRow;
180 fNewAmp = phosDecode.fNewAmp ;
181 fNewTime= phosDecode.fNewTime ;
56c9f64a 182 fLowGainFlag = phosDecode.fLowGainFlag;
39569d36 183 fNewLowGainFlag = phosDecode.fNewLowGainFlag;
14100b90 184 fOverflow = phosDecode.fOverflow ;
56c9f64a 185
b1a8a9cb 186 if(fSamples) delete fSamples;
187 fSamples = phosDecode.fSamples;
188
14100b90 189 if(fTimes) delete fTimes;
190 fTimes = phosDecode.fTimes;
bafc1087 191 fCalibData = phosDecode.fCalibData;
a29c28b6 192 }
193
194 return *this;
195}
196
197//-----------------------------------------------------------------------------
198
199Bool_t AliPHOSRawDecoder::NextDigit()
200{
201 //Extract an energy deposited in the crystal,
202 //crystal' position (module,column,row),
203 //time and gain (high or low).
b1a8a9cb 204
a29c28b6 205 AliCaloRawStream* in = fCaloStream;
b1a8a9cb 206
b1a8a9cb 207 fEnergy = -111;
1267d56d 208 Float_t pedMean = 0;
3876e91d 209 Float_t pedRMS = 0;
1267d56d 210 Int_t nPed = 0;
211 Float_t baseLine = 1.0;
c5d477f8 212 const Int_t kPreSamples = 10;
b1a8a9cb 213
14100b90 214 while ( in->Next() ) {
23e312da 215 // Evaluate previous sample
216 if(in->IsNewHWAddress() && fEnergy!=-111){ //Do not return at first sample
56c9f64a 217
39569d36 218 //First remember new sample
219 fNewLowGainFlag = in->IsLowGain();
220 fNewModule = in->GetModule()+1;
221 fNewRow = in->GetRow() +1;
222 fNewColumn = in->GetColumn()+1;
223 fNewAmp = in->GetSignal() ;
224 fNewTime=in->GetTime() ;
23e312da 225 // We take the energy as a maximum amplitude
56c9f64a 226 // and the pedestal from the 0th point (30 Aug 2006).
23e312da 227 // Time is not evaluated
228 // Take it as a first time bin multiplied by the sample tick time
56c9f64a 229
60144e5f 230 if(fPedSubtract) {
3876e91d 231 if (nPed > 0){
232 fPedestalRMS=(pedRMS-pedMean*pedMean/nPed)/nPed ;
233 if(fPedestalRMS > 0.)
234 fPedestalRMS = TMath::Sqrt(fPedestalRMS) ;
7b02b945 235 fEnergy -= (Double_t)(pedMean/nPed); // pedestal subtraction
3876e91d 236 }
7b02b945 237 else
238 return kFALSE;
60144e5f 239 }
240 else{
bafc1087 241 //take pedestals from DB
242 Double_t pedestal = (Double_t) fAmpOffset ;
243 if(fCalibData){
244 Float_t truePed = fCalibData->GetADCpedestalEmc(fModule, fColumn, fRow) ;
245 Int_t altroSettings = fCalibData->GetAltroOffsetEmc(fModule, fColumn, fRow) ;
246 pedestal += truePed - altroSettings ;
247 }
248 else{
23e312da 249 printf("AliPHOSRawDecoder::NextDigit() Can not read data from OCDB \n") ;
bafc1087 250 }
251 fEnergy-=pedestal ;
60144e5f 252 }
1267d56d 253 if (fEnergy < baseLine) fEnergy = 0;
254
56c9f64a 255 return kTRUE;
256 }
257
258 fLowGainFlag = in->IsLowGain();
7f612eef 259 fTime = 1;
56c9f64a 260 fModule = in->GetModule()+1;
1267d56d 261 fRow = in->GetRow() +1;
56c9f64a 262 fColumn = in->GetColumn()+1;
263
39569d36 264 if(fLowGainFlag==fNewLowGainFlag && fModule==fNewModule &&
265 fRow==fNewRow && fColumn==fNewColumn ){
266 if(fNewAmp>fEnergy) fEnergy = (Double_t)fNewAmp ;
23e312da 267 fNewModule=-1 ; //copyed, do not copy more
39569d36 268 }
269
14100b90 270 //Calculate pedestal if necessary
23e312da 271 if(fPedSubtract && (in->GetTime() < kPreSamples)) {
1267d56d 272 pedMean += in->GetSignal();
3876e91d 273 pedRMS+=in->GetSignal()*in->GetSignal() ;
1267d56d 274 nPed++;
275 }
23e312da 276 if((Double_t)in->GetSignal() > fEnergy)
277 fEnergy = (Double_t)in->GetSignal();
56c9f64a 278
279 } // in.Next()
280
281 return kFALSE;
a29c28b6 282}