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 decodes the stream of ALTRO samples to extract
19 // the PHOS "digits" of current event.
22 // AliRawReader* rf = new AliRawReaderDate("2006run2211.raw");
23 // AliPHOSRawDecoder dc(rf);
24 // while (rf->NextEvent()) {
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();
37 // Author: Boris Polichtchouk
39 // --- ROOT system ---
43 // --- AliRoot header files ---
44 #include "AliPHOSRawDecoder.h"
45 #include "AliRawReader.h"
46 #include "AliPHOSCalibData.h"
49 ClassImp(AliPHOSRawDecoder)
51 //-----------------------------------------------------------------------------
52 AliPHOSRawDecoder::AliPHOSRawDecoder():
72 fNewLowGainFlag(kFALSE),
78 //Default constructor.
81 //-----------------------------------------------------------------------------
82 AliPHOSRawDecoder::AliPHOSRawDecoder(AliRawReader* rawReader, AliAltroMapping **mapping):
101 fLowGainFlag(kFALSE),
102 fNewLowGainFlag(kFALSE),
108 //Construct a decoder object.
109 //Is is user responsibility to provide next raw event
110 //using AliRawReader::NextEvent().
112 fRawReader = rawReader;
113 fCaloStream = new AliCaloRawStream(rawReader,"PHOS",mapping);
114 fSamples = new TArrayI(100);
115 fTimes = new TArrayI(100);
118 //-----------------------------------------------------------------------------
119 AliPHOSRawDecoder::~AliPHOSRawDecoder()
123 if(fCaloStream){ delete fCaloStream; fCaloStream=0;}
124 if(fSamples){ delete fSamples; fSamples=0 ;}
125 if(fTimes){ delete fTimes; fTimes=0 ;}
128 //-----------------------------------------------------------------------------
129 AliPHOSRawDecoder::AliPHOSRawDecoder(const AliPHOSRawDecoder &phosDecoder ):
131 fRawReader(phosDecoder.fRawReader),
132 fCaloStream(phosDecoder.fCaloStream),
133 fPedSubtract(phosDecoder.fPedSubtract),
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)
158 //-----------------------------------------------------------------------------
159 AliPHOSRawDecoder& AliPHOSRawDecoder::operator = (const AliPHOSRawDecoder &phosDecode)
161 //Assignment operator.
163 if(this != &phosDecode) {
164 fRawReader = phosDecode.fRawReader;
166 if(fCaloStream) delete fCaloStream;
167 fCaloStream = phosDecode.fCaloStream;
169 fEnergy = phosDecode.fEnergy;
170 fTime = phosDecode.fTime;
171 fQuality = phosDecode.fQuality ;
172 fPedestalRMS = phosDecode.fPedestalRMS ;
173 fAmpOffset = phosDecode.fAmpOffset ;
174 fModule = phosDecode.fModule;
175 fColumn = phosDecode.fColumn;
176 fRow = phosDecode.fRow;
177 fNewModule = phosDecode.fNewModule;
178 fNewColumn = phosDecode.fNewColumn;
179 fNewRow = phosDecode.fNewRow;
180 fNewAmp = phosDecode.fNewAmp ;
181 fNewTime= phosDecode.fNewTime ;
182 fLowGainFlag = phosDecode.fLowGainFlag;
183 fNewLowGainFlag = phosDecode.fNewLowGainFlag;
184 fOverflow = phosDecode.fOverflow ;
186 if(fSamples) delete fSamples;
187 fSamples = phosDecode.fSamples;
189 if(fTimes) delete fTimes;
190 fTimes = phosDecode.fTimes;
191 fCalibData = phosDecode.fCalibData;
197 //-----------------------------------------------------------------------------
199 Bool_t AliPHOSRawDecoder::NextDigit()
201 //Extract an energy deposited in the crystal,
202 //crystal' position (module,column,row),
203 //time and gain (high or low).
205 AliCaloRawStream* in = fCaloStream;
211 Float_t baseLine = 1.0;
212 const Int_t kPreSamples = 10;
214 while ( in->Next() ) {
215 // Evaluate previous sample
216 if(in->IsNewHWAddress() && fEnergy!=-111){ //Do not return at first sample
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() ;
225 // We take the energy as a maximum amplitude
226 // and the pedestal from the 0th point (30 Aug 2006).
227 // Time is not evaluated
228 // Take it as a first time bin multiplied by the sample tick time
232 fPedestalRMS=(pedRMS-pedMean*pedMean/nPed)/nPed ;
233 if(fPedestalRMS > 0.)
234 fPedestalRMS = TMath::Sqrt(fPedestalRMS) ;
235 fEnergy -= (Double_t)(pedMean/nPed); // pedestal subtraction
241 //take pedestals from DB
242 Double_t pedestal = (Double_t) fAmpOffset ;
244 Float_t truePed = fCalibData->GetADCpedestalEmc(fModule, fColumn, fRow) ;
245 Int_t altroSettings = fCalibData->GetAltroOffsetEmc(fModule, fColumn, fRow) ;
246 pedestal += truePed - altroSettings ;
249 printf("AliPHOSRawDecoder::NextDigit() Can not read data from OCDB \n") ;
253 if (fEnergy < baseLine) fEnergy = 0;
258 fLowGainFlag = in->IsLowGain();
260 fModule = in->GetModule()+1;
261 fRow = in->GetRow() +1;
262 fColumn = in->GetColumn()+1;
264 if(fLowGainFlag==fNewLowGainFlag && fModule==fNewModule &&
265 fRow==fNewRow && fColumn==fNewColumn ){
266 if(fNewAmp>fEnergy) fEnergy = (Double_t)fNewAmp ;
267 fNewModule=-1 ; //copyed, do not copy more
270 //Calculate pedestal if necessary
271 if(fPedSubtract && (in->GetTime() < kPreSamples)) {
272 pedMean += in->GetSignal();
273 pedRMS+=in->GetSignal()*in->GetSignal() ;
276 if((Double_t)in->GetSignal() > fEnergy)
277 fEnergy = (Double_t)in->GetSignal();