]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PHOS/AliPHOSRawDecoder.cxx
Initialization of fAmpThreshold is added to ctors.
[u/mrichter/AliRoot.git] / PHOS / AliPHOSRawDecoder.cxx
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 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");
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();
33 //            ..........
34 //       }
35 //     }
36
37 // Author: Boris Polichtchouk
38
39 // --- ROOT system ---
40 #include "TArrayI.h"
41 #include "TMath.h"
42
43 // --- AliRoot header files ---
44 #include "AliPHOSRawDecoder.h"
45 #include "AliRawReader.h"
46 #include "AliPHOSCalibData.h"
47 #include "AliLog.h"
48
49 ClassImp(AliPHOSRawDecoder)
50
51 //-----------------------------------------------------------------------------
52 AliPHOSRawDecoder::AliPHOSRawDecoder():
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)
77 {
78   //Default constructor.
79 }
80
81 //-----------------------------------------------------------------------------
82 AliPHOSRawDecoder::AliPHOSRawDecoder(AliRawReader* rawReader,  AliAltroMapping **mapping):
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)
107 {
108   //Construct a decoder object.
109   //Is is user responsibility to provide next raw event 
110   //using AliRawReader::NextEvent().
111
112   fRawReader =  rawReader;
113   fCaloStream = new AliCaloRawStream(rawReader,"PHOS",mapping);
114   fSamples = new TArrayI(100);
115   fTimes = new TArrayI(100);
116 }
117
118 //-----------------------------------------------------------------------------
119 AliPHOSRawDecoder::~AliPHOSRawDecoder()
120 {
121   //Destructor.
122
123   if(fCaloStream){ delete fCaloStream; fCaloStream=0;}
124   if(fSamples){ delete fSamples; fSamples=0 ;}
125   if(fTimes){ delete fTimes; fTimes=0 ;}
126 }
127
128 //-----------------------------------------------------------------------------
129 AliPHOSRawDecoder::AliPHOSRawDecoder(const AliPHOSRawDecoder &phosDecoder ):
130   TObject(),
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) 
154 {
155   //Copy constructor.
156 }
157
158 //-----------------------------------------------------------------------------
159 AliPHOSRawDecoder& AliPHOSRawDecoder::operator = (const AliPHOSRawDecoder &phosDecode)
160 {
161   //Assignment operator.
162
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;
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 ;
185     
186     if(fSamples) delete fSamples;
187     fSamples = phosDecode.fSamples;
188
189     if(fTimes) delete fTimes;
190     fTimes = phosDecode.fTimes;
191     fCalibData = phosDecode.fCalibData; 
192   }
193
194   return *this;
195 }
196
197 //-----------------------------------------------------------------------------
198
199 Bool_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).
204   
205   AliCaloRawStream* in = fCaloStream;
206   
207   fEnergy = -111;
208   Float_t pedMean = 0;
209   Float_t pedRMS = 0;
210   Int_t   nPed = 0;
211   Float_t baseLine = 1.0;
212   const Int_t kPreSamples = 10;
213   
214   while ( in->Next() ) { 
215     // Evaluate previous sample
216     if(in->IsNewHWAddress() && fEnergy!=-111){ //Do not return at first sample
217        
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
229        
230        if(fPedSubtract) {
231          if (nPed > 0){
232            fPedestalRMS=(pedRMS-pedMean*pedMean/nPed)/nPed ;
233            if(fPedestalRMS > 0.) 
234             fPedestalRMS = TMath::Sqrt(fPedestalRMS) ;
235            fEnergy -= (Double_t)(pedMean/nPed); // pedestal subtraction
236          }
237          else
238            return kFALSE;
239        }
240        else{
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{
249            printf("AliPHOSRawDecoder::NextDigit() Can not read data from OCDB \n") ;
250          }
251          fEnergy-=pedestal ;
252        }
253        if (fEnergy < baseLine) fEnergy = 0;
254
255        return kTRUE;
256      }
257
258      fLowGainFlag = in->IsLowGain();
259      fTime = 1;
260      fModule = in->GetModule()+1;
261      fRow    = in->GetRow()   +1;
262      fColumn = in->GetColumn()+1;
263
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
268     } 
269
270      //Calculate pedestal if necessary
271      if(fPedSubtract && (in->GetTime() < kPreSamples)) {
272        pedMean += in->GetSignal();
273        pedRMS+=in->GetSignal()*in->GetSignal() ;
274        nPed++;
275      }
276      if((Double_t)in->GetSignal() > fEnergy)
277        fEnergy = (Double_t)in->GetSignal();
278      
279    } // in.Next()
280    
281    return kFALSE;
282 }