]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PHOS/AliPHOSRawDecoder.cxx
sample quality check added
[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 "AliPHOSPulseGenerator.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), fLowGainFlag(kFALSE),fOverflow(kFALSE),fSamples(0),
53   fTimes(0),fPulseGenerator(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),fLowGainFlag(kFALSE),fOverflow(kFALSE),fSamples(0),
62   fTimes(0),fPulseGenerator(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   fPulseGenerator = new AliPHOSPulseGenerator();
74 }
75
76 //-----------------------------------------------------------------------------
77 AliPHOSRawDecoder::~AliPHOSRawDecoder()
78 {
79   //Destructor.
80
81   if(fCaloStream){ delete fCaloStream; fCaloStream=0;}
82   if(fSamples){ delete fSamples; fSamples=0 ;}
83   if(fTimes){ delete fTimes; fTimes=0 ;}
84   if(fPulseGenerator){ delete fPulseGenerator; fPulseGenerator=0 ;}
85 }
86
87 //-----------------------------------------------------------------------------
88 AliPHOSRawDecoder::AliPHOSRawDecoder(const AliPHOSRawDecoder &phosDecoder ):
89   fRawReader(phosDecoder.fRawReader),fCaloStream(phosDecoder.fCaloStream),
90   fPedSubtract(phosDecoder.fPedSubtract),
91   fEnergy(phosDecoder.fEnergy),fTime(phosDecoder.fTime),fQuality(phosDecoder.fQuality),
92   fModule(phosDecoder.fModule),fColumn(phosDecoder.fColumn),
93   fRow(phosDecoder.fRow),fLowGainFlag(phosDecoder.fLowGainFlag),
94   fOverflow(phosDecoder.fOverflow),fSamples(phosDecoder.fSamples),
95   fTimes(phosDecoder.fTimes),fPulseGenerator(phosDecoder.fPulseGenerator)
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     fLowGainFlag = phosDecode.fLowGainFlag;
118     fOverflow = phosDecode.fOverflow ;
119     
120     if(fSamples) delete fSamples;
121     fSamples = phosDecode.fSamples;
122
123     if(fTimes) delete fTimes;
124     fTimes = phosDecode.fTimes;
125
126     if(fPulseGenerator) delete fPulseGenerator;
127     fPulseGenerator = phosDecode.fPulseGenerator;
128   }
129
130   return *this;
131 }
132
133 //-----------------------------------------------------------------------------
134
135 Bool_t AliPHOSRawDecoder::NextDigit()
136 {
137   //Extract an energy deposited in the crystal,
138   //crystal' position (module,column,row),
139   //time and gain (high or low).
140   
141   AliCaloRawStream* in = fCaloStream;
142   
143   Int_t    iBin     = 0;
144   Int_t    mxSmps   = fSamples->GetSize();
145   Int_t    tLength  = 0;
146   fEnergy = -111;
147   Float_t pedMean = 0;
148   Int_t   nPed = 0;
149   Float_t baseLine = 1.0;
150   const Int_t nPreSamples = 10;
151   
152   fSamples->Reset();
153   while ( in->Next() ) { 
154
155      if(!tLength) {
156        tLength = in->GetTimeLength();
157        if(tLength>mxSmps) {
158          fSamples->Set(tLength);
159        }
160      }
161      
162      // Fit the full sample
163      if(in->IsNewHWAddress() && iBin>0) {
164        
165        iBin=0;
166        
167        // Temporarily we take the energy as a maximum amplitude
168        // and the pedestal from the 0th point (30 Aug 2006).
169        // Time is not evaluated for the moment (12.01.2007). 
170        // Take is as a first time bin multiplied by the sample tick time
171        
172        if(fPedSubtract) 
173          if (nPed > 0)
174            fEnergy -= (Double_t)(pedMean/nPed); // pedestal subtraction
175          else
176            return kFALSE;
177        
178        if (fEnergy < baseLine) fEnergy = 0;
179
180        pedMean = 0;
181        return kTRUE;
182      }
183
184      fLowGainFlag = in->IsLowGain();
185      fTime = fPulseGenerator->GetRawFormatTimeTrigger() * in->GetTime();
186      fModule = in->GetModule()+1;
187      fRow    = in->GetRow()   +1;
188      fColumn = in->GetColumn()+1;
189
190      //Calculate pedestal if necessary
191      if(fPedSubtract && in->GetTime() < nPreSamples) {
192        pedMean += in->GetSignal();
193        nPed++;
194      }
195      if((Double_t)in->GetSignal() > fEnergy) fEnergy = (Double_t)in->GetSignal();
196      iBin++ ;
197      
198    } // in.Next()
199    
200    return kFALSE;
201 }