]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PHOS/AliPHOSRawDecoder.cxx
AddRunType(..) added to constructor.
[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.SetOldRCUFormat(kTRUE);
26 //       dc.SubtractPedestals(kTRUE);
27 //       while ( dc.NextDigit() ) {
28 //         Int_t module = dc.GetModule();
29 //         Int_t column = dc.GetColumn();
30 //         Int_t row = dc.GetRow();
31 //         Double_t amplitude = dc.GetEnergy();
32 //         Double_t time = dc.GetTime();
33 //         Bool_t IsLowGain = dc.IsLowGain();
34 //            ..........
35 //       }
36 //     }
37
38 // Author: Boris Polichtchouk
39
40 // --- ROOT system ---
41 #include "TArrayI.h"
42
43 // --- AliRoot header files ---
44 #include "AliPHOSRawDecoder.h"
45 #include "AliRawReader.h"
46
47 ClassImp(AliPHOSRawDecoder)
48
49 //-----------------------------------------------------------------------------
50 AliPHOSRawDecoder::AliPHOSRawDecoder():
51   fRawReader(0),fCaloStream(0),fPedSubtract(kFALSE),fEnergy(-111),fTime(-111),fQuality(0.),
52   fModule(-1),fColumn(-1),fRow(-1),fNewModule(-1),fNewColumn(-1),fNewRow(-1),fNewAmp(0),fNewTime(0), 
53   fLowGainFlag(kFALSE),fNewLowGainFlag(kFALSE),fOverflow(kFALSE),fSamples(0),fTimes(0)
54 {
55   //Default constructor.
56 }
57
58 //-----------------------------------------------------------------------------
59 AliPHOSRawDecoder::AliPHOSRawDecoder(AliRawReader* rawReader,  AliAltroMapping **mapping):
60   fRawReader(0),fCaloStream(0),fPedSubtract(kFALSE),fEnergy(-111),fTime(-111),fQuality(0.),
61   fModule(-1),fColumn(-1),fRow(-1),fNewModule(-1),fNewColumn(-1),fNewRow(-1),fNewAmp(0),fNewTime(0),
62   fLowGainFlag(kFALSE),fNewLowGainFlag(kFALSE),fOverflow(kFALSE),fSamples(0),fTimes(0)
63 {
64   //Construct a decoder object.
65   //Is is user responsibility to provide next raw event 
66   //using AliRawReader::NextEvent().
67
68   fRawReader =  rawReader;
69   fCaloStream = new AliCaloRawStream(rawReader,"PHOS",mapping);
70   fCaloStream->SetOldRCUFormat(kFALSE);
71   fSamples = new TArrayI(100);
72   fTimes = new TArrayI(100);
73 }
74
75 //-----------------------------------------------------------------------------
76 AliPHOSRawDecoder::~AliPHOSRawDecoder()
77 {
78   //Destructor.
79
80   if(fCaloStream){ delete fCaloStream; fCaloStream=0;}
81   if(fSamples){ delete fSamples; fSamples=0 ;}
82   if(fTimes){ delete fTimes; fTimes=0 ;}
83 }
84
85 //-----------------------------------------------------------------------------
86 AliPHOSRawDecoder::AliPHOSRawDecoder(const AliPHOSRawDecoder &phosDecoder ):
87   fRawReader(phosDecoder.fRawReader),fCaloStream(phosDecoder.fCaloStream),
88   fPedSubtract(phosDecoder.fPedSubtract),
89   fEnergy(phosDecoder.fEnergy),fTime(phosDecoder.fTime),fQuality(phosDecoder.fQuality),
90   fModule(phosDecoder.fModule),fColumn(phosDecoder.fColumn),
91   fRow(phosDecoder.fRow),fNewModule(phosDecoder.fNewModule),fNewColumn(phosDecoder.fNewColumn),
92   fNewRow(phosDecoder.fNewRow),fNewAmp(phosDecoder.fNewAmp),fNewTime(phosDecoder.fNewTime),
93   fLowGainFlag(phosDecoder.fLowGainFlag),fNewLowGainFlag(phosDecoder.fNewLowGainFlag),
94   fOverflow(phosDecoder.fOverflow),fSamples(phosDecoder.fSamples),
95   fTimes(phosDecoder.fTimes)
96 {
97   //Copy constructor.
98 }
99
100 //-----------------------------------------------------------------------------
101 AliPHOSRawDecoder& AliPHOSRawDecoder::operator = (const AliPHOSRawDecoder &phosDecode)
102 {
103   //Assignment operator.
104
105   if(this != &phosDecode) {
106     fRawReader = phosDecode.fRawReader;
107
108     if(fCaloStream) delete fCaloStream;
109     fCaloStream = phosDecode.fCaloStream;
110
111     fEnergy = phosDecode.fEnergy;
112     fTime = phosDecode.fTime;
113     fQuality = phosDecode.fQuality ;
114     fModule = phosDecode.fModule;
115     fColumn = phosDecode.fColumn;
116     fRow = phosDecode.fRow;
117     fNewModule = phosDecode.fNewModule;
118     fNewColumn = phosDecode.fNewColumn;
119     fNewRow = phosDecode.fNewRow;
120     fNewAmp = phosDecode.fNewAmp ;
121     fNewTime= phosDecode.fNewTime ;
122     fLowGainFlag = phosDecode.fLowGainFlag;
123     fNewLowGainFlag = phosDecode.fNewLowGainFlag;
124     fOverflow = phosDecode.fOverflow ;
125     
126     if(fSamples) delete fSamples;
127     fSamples = phosDecode.fSamples;
128
129     if(fTimes) delete fTimes;
130     fTimes = phosDecode.fTimes;
131   }
132
133   return *this;
134 }
135
136 //-----------------------------------------------------------------------------
137
138 Bool_t AliPHOSRawDecoder::NextDigit()
139 {
140   //Extract an energy deposited in the crystal,
141   //crystal' position (module,column,row),
142   //time and gain (high or low).
143   
144   AliCaloRawStream* in = fCaloStream;
145   
146   Int_t    iBin     = 0;
147   Int_t    mxSmps   = fSamples->GetSize();
148   Int_t    tLength  = 0;
149   fEnergy = -111;
150   Float_t pedMean = 0;
151   Int_t   nPed = 0;
152   Float_t baseLine = 1.0;
153   const Int_t kPreSamples = 10;
154   
155   fSamples->Reset();
156   while ( in->Next() ) { 
157
158      if(!tLength) {
159        tLength = in->GetTimeLength();
160        if(tLength>mxSmps) {
161          fSamples->Set(tLength);
162        }
163      }
164      
165      // Fit the full sample
166      if(in->IsNewHWAddress() && iBin>0) {
167        
168        iBin=0;
169        //First remember new sample
170        fNewLowGainFlag = in->IsLowGain();
171        fNewModule = in->GetModule()+1;
172        fNewRow    = in->GetRow()   +1;
173        fNewColumn = in->GetColumn()+1;
174        fNewAmp = in->GetSignal() ;
175        fNewTime=in->GetTime() ;                                                                                                                               
176        
177        // Temporarily we take the energy as a maximum amplitude
178        // and the pedestal from the 0th point (30 Aug 2006).
179        // Time is not evaluated for the moment (12.01.2007). 
180        // Take is as a first time bin multiplied by the sample tick time
181        
182        if(fPedSubtract) 
183          if (nPed > 0)
184            fEnergy -= (Double_t)(pedMean/nPed); // pedestal subtraction
185          else
186            return kFALSE;
187        if (fEnergy < baseLine) fEnergy = 0;
188
189        pedMean = 0;
190        return kTRUE;
191      }
192
193      fLowGainFlag = in->IsLowGain();
194 //     fTime =   in->GetTime();
195      fModule = in->GetModule()+1;
196      fRow    = in->GetRow()   +1;
197      fColumn = in->GetColumn()+1;
198
199     if(fLowGainFlag==fNewLowGainFlag && fModule==fNewModule &&
200        fRow==fNewRow && fColumn==fNewColumn ){
201        if(fNewAmp>fEnergy)  fEnergy = (Double_t)fNewAmp ;
202        fNewModule=-1 ;
203     } 
204
205      //Calculate pedestal if necessary
206      if(fPedSubtract && in->GetTime() < kPreSamples) {
207        pedMean += in->GetSignal();
208        nPed++;
209      }
210      if((Double_t)in->GetSignal() > fEnergy) fEnergy = (Double_t)in->GetSignal();
211      iBin++ ;
212      
213    } // in.Next()
214    
215    return kFALSE;
216 }