]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PHOS/AliPHOSRawDecoder.cxx
DAs upgraded to AliZDCRawStream class
[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():
3876e91d 53 fRawReader(0),fCaloStream(0),fPedSubtract(kFALSE),fEnergy(-111),fTime(-111),fQuality(0.),fPedestalRMS(0.),
60144e5f 54 fAmpOffset(0),fModule(-1),fColumn(-1),fRow(-1),fNewModule(-1),fNewColumn(-1),fNewRow(-1),fNewAmp(0),fNewTime(0),
bafc1087 55 fLowGainFlag(kFALSE),fNewLowGainFlag(kFALSE),fOverflow(kFALSE),fSamples(0),fTimes(0),fCalibData(0)
a29c28b6 56{
57 //Default constructor.
58}
59
60//-----------------------------------------------------------------------------
467957dc 61AliPHOSRawDecoder::AliPHOSRawDecoder(AliRawReader* rawReader, AliAltroMapping **mapping):
3876e91d 62 fRawReader(0),fCaloStream(0),fPedSubtract(kFALSE),fEnergy(-111),fTime(-111),fQuality(0.),fPedestalRMS(0.),
60144e5f 63 fAmpOffset(0),fModule(-1),fColumn(-1),fRow(-1),fNewModule(-1),fNewColumn(-1),fNewRow(-1),fNewAmp(0),fNewTime(0),
bafc1087 64 fLowGainFlag(kFALSE),fNewLowGainFlag(kFALSE),fOverflow(kFALSE),fSamples(0),fTimes(0),fCalibData(0)
a29c28b6 65{
66 //Construct a decoder object.
67 //Is is user responsibility to provide next raw event
68 //using AliRawReader::NextEvent().
69
70 fRawReader = rawReader;
467957dc 71 fCaloStream = new AliCaloRawStream(rawReader,"PHOS",mapping);
b1a8a9cb 72 fSamples = new TArrayI(100);
14100b90 73 fTimes = new TArrayI(100);
a29c28b6 74}
75
76//-----------------------------------------------------------------------------
77AliPHOSRawDecoder::~AliPHOSRawDecoder()
78{
79 //Destructor.
80
14100b90 81 if(fCaloStream){ delete fCaloStream; fCaloStream=0;}
82 if(fSamples){ delete fSamples; fSamples=0 ;}
83 if(fTimes){ delete fTimes; fTimes=0 ;}
a29c28b6 84}
85
86//-----------------------------------------------------------------------------
87AliPHOSRawDecoder::AliPHOSRawDecoder(const AliPHOSRawDecoder &phosDecoder ):
88 fRawReader(phosDecoder.fRawReader),fCaloStream(phosDecoder.fCaloStream),
89 fPedSubtract(phosDecoder.fPedSubtract),
3876e91d 90 fEnergy(phosDecoder.fEnergy),fTime(phosDecoder.fTime),fQuality(phosDecoder.fQuality),fPedestalRMS(phosDecoder.fPedestalRMS),
60144e5f 91 fAmpOffset(phosDecoder.fAmpOffset),fModule(phosDecoder.fModule),fColumn(phosDecoder.fColumn),
39569d36 92 fRow(phosDecoder.fRow),fNewModule(phosDecoder.fNewModule),fNewColumn(phosDecoder.fNewColumn),
93 fNewRow(phosDecoder.fNewRow),fNewAmp(phosDecoder.fNewAmp),fNewTime(phosDecoder.fNewTime),
94 fLowGainFlag(phosDecoder.fLowGainFlag),fNewLowGainFlag(phosDecoder.fNewLowGainFlag),
14100b90 95 fOverflow(phosDecoder.fOverflow),fSamples(phosDecoder.fSamples),
bafc1087 96 fTimes(phosDecoder.fTimes),fCalibData(phosDecoder.fCalibData)
a29c28b6 97{
98 //Copy constructor.
99}
100
101//-----------------------------------------------------------------------------
102AliPHOSRawDecoder& AliPHOSRawDecoder::operator = (const AliPHOSRawDecoder &phosDecode)
103{
7bc140a5 104 //Assignment operator.
105
a29c28b6 106 if(this != &phosDecode) {
107 fRawReader = phosDecode.fRawReader;
108
109 if(fCaloStream) delete fCaloStream;
110 fCaloStream = phosDecode.fCaloStream;
111
112 fEnergy = phosDecode.fEnergy;
113 fTime = phosDecode.fTime;
70d93620 114 fQuality = phosDecode.fQuality ;
60144e5f 115 fPedestalRMS = phosDecode.fPedestalRMS ;
116 fAmpOffset = phosDecode.fAmpOffset ;
a29c28b6 117 fModule = phosDecode.fModule;
118 fColumn = phosDecode.fColumn;
119 fRow = phosDecode.fRow;
39569d36 120 fNewModule = phosDecode.fNewModule;
121 fNewColumn = phosDecode.fNewColumn;
122 fNewRow = phosDecode.fNewRow;
123 fNewAmp = phosDecode.fNewAmp ;
124 fNewTime= phosDecode.fNewTime ;
56c9f64a 125 fLowGainFlag = phosDecode.fLowGainFlag;
39569d36 126 fNewLowGainFlag = phosDecode.fNewLowGainFlag;
14100b90 127 fOverflow = phosDecode.fOverflow ;
56c9f64a 128
b1a8a9cb 129 if(fSamples) delete fSamples;
130 fSamples = phosDecode.fSamples;
131
14100b90 132 if(fTimes) delete fTimes;
133 fTimes = phosDecode.fTimes;
bafc1087 134 fCalibData = phosDecode.fCalibData;
a29c28b6 135 }
136
137 return *this;
138}
139
140//-----------------------------------------------------------------------------
141
142Bool_t AliPHOSRawDecoder::NextDigit()
143{
144 //Extract an energy deposited in the crystal,
145 //crystal' position (module,column,row),
146 //time and gain (high or low).
b1a8a9cb 147
a29c28b6 148 AliCaloRawStream* in = fCaloStream;
b1a8a9cb 149
a29c28b6 150 Int_t iBin = 0;
b1a8a9cb 151 Int_t mxSmps = fSamples->GetSize();
56c9f64a 152 Int_t tLength = 0;
b1a8a9cb 153 fEnergy = -111;
1267d56d 154 Float_t pedMean = 0;
3876e91d 155 Float_t pedRMS = 0;
1267d56d 156 Int_t nPed = 0;
157 Float_t baseLine = 1.0;
c5d477f8 158 const Int_t kPreSamples = 10;
b1a8a9cb 159
160 fSamples->Reset();
14100b90 161 while ( in->Next() ) {
56c9f64a 162
163 if(!tLength) {
164 tLength = in->GetTimeLength();
165 if(tLength>mxSmps) {
166 fSamples->Set(tLength);
167 }
168 }
169
170 // Fit the full sample
171 if(in->IsNewHWAddress() && iBin>0) {
172
173 iBin=0;
39569d36 174 //First remember new sample
175 fNewLowGainFlag = in->IsLowGain();
176 fNewModule = in->GetModule()+1;
177 fNewRow = in->GetRow() +1;
178 fNewColumn = in->GetColumn()+1;
179 fNewAmp = in->GetSignal() ;
180 fNewTime=in->GetTime() ;
56c9f64a 181
182 // Temporarily we take the energy as a maximum amplitude
183 // and the pedestal from the 0th point (30 Aug 2006).
184 // Time is not evaluated for the moment (12.01.2007).
185 // Take is as a first time bin multiplied by the sample tick time
186
60144e5f 187 if(fPedSubtract) {
3876e91d 188 if (nPed > 0){
189 fPedestalRMS=(pedRMS-pedMean*pedMean/nPed)/nPed ;
190 if(fPedestalRMS > 0.)
191 fPedestalRMS = TMath::Sqrt(fPedestalRMS) ;
7b02b945 192 fEnergy -= (Double_t)(pedMean/nPed); // pedestal subtraction
3876e91d 193 }
7b02b945 194 else
195 return kFALSE;
60144e5f 196 }
197 else{
bafc1087 198 //take pedestals from DB
199 Double_t pedestal = (Double_t) fAmpOffset ;
200 if(fCalibData){
201 Float_t truePed = fCalibData->GetADCpedestalEmc(fModule, fColumn, fRow) ;
202 Int_t altroSettings = fCalibData->GetAltroOffsetEmc(fModule, fColumn, fRow) ;
203 pedestal += truePed - altroSettings ;
204 }
205 else{
206// printf("AliPHOSRawDecoder::NextDigit() Can not read data from OCDB \n") ;
207 }
208 fEnergy-=pedestal ;
60144e5f 209 }
1267d56d 210 if (fEnergy < baseLine) fEnergy = 0;
211
56c9f64a 212 return kTRUE;
213 }
214
215 fLowGainFlag = in->IsLowGain();
39569d36 216// fTime = in->GetTime();
7f612eef 217 fTime = 1;
56c9f64a 218 fModule = in->GetModule()+1;
1267d56d 219 fRow = in->GetRow() +1;
56c9f64a 220 fColumn = in->GetColumn()+1;
221
39569d36 222 if(fLowGainFlag==fNewLowGainFlag && fModule==fNewModule &&
223 fRow==fNewRow && fColumn==fNewColumn ){
224 if(fNewAmp>fEnergy) fEnergy = (Double_t)fNewAmp ;
225 fNewModule=-1 ;
226 }
227
14100b90 228 //Calculate pedestal if necessary
c5d477f8 229 if(fPedSubtract && in->GetTime() < kPreSamples) {
1267d56d 230 pedMean += in->GetSignal();
3876e91d 231 pedRMS+=in->GetSignal()*in->GetSignal() ;
1267d56d 232 nPed++;
233 }
56c9f64a 234 if((Double_t)in->GetSignal() > fEnergy) fEnergy = (Double_t)in->GetSignal();
14100b90 235 iBin++ ;
56c9f64a 236
237 } // in.Next()
238
239 return kFALSE;
a29c28b6 240}