]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PHOS/AliPHOSRawDecoder.cxx
Using AliGeomManager in the macros (Raffaele)
[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),fModule(-1),fColumn(-1),fRow(-1),fSamples(0),fPulseGenerator(0)
52 {
53   //Default constructor.
54 }
55
56 //-----------------------------------------------------------------------------
57 AliPHOSRawDecoder::AliPHOSRawDecoder(AliRawReader* rawReader):
58   fRawReader(0),fCaloStream(0),fPedSubtract(kFALSE),fEnergy(-111),fTime(-111),fModule(-1),fColumn(-1),fRow(-1),fSamples(0),fPulseGenerator(0)
59 {
60   //Construct a decoder object.
61   //Is is user responsibility to provide next raw event 
62   //using AliRawReader::NextEvent().
63
64   fRawReader =  rawReader;
65   fCaloStream = new AliCaloRawStream(rawReader,"PHOS");
66   fCaloStream->SetOldRCUFormat(kFALSE);
67   fSamples = new TArrayI(100);
68   fPulseGenerator = new AliPHOSPulseGenerator();
69 }
70
71 //-----------------------------------------------------------------------------
72 AliPHOSRawDecoder::~AliPHOSRawDecoder()
73 {
74   //Destructor.
75
76   if(fCaloStream) delete fCaloStream;
77   if(fSamples) delete fSamples;
78   if(fPulseGenerator) delete fPulseGenerator;
79 }
80
81 //-----------------------------------------------------------------------------
82 AliPHOSRawDecoder::AliPHOSRawDecoder(const AliPHOSRawDecoder &phosDecoder ):
83   fRawReader(phosDecoder.fRawReader),fCaloStream(phosDecoder.fCaloStream),
84   fPedSubtract(phosDecoder.fPedSubtract),
85   fEnergy(phosDecoder.fEnergy),fTime(phosDecoder.fTime),
86   fModule(phosDecoder.fModule),fColumn(phosDecoder.fColumn),
87   fRow(phosDecoder.fRow),fSamples(phosDecoder.fSamples),
88   fPulseGenerator(phosDecoder.fPulseGenerator)
89 {
90   //Copy constructor.
91 }
92
93 //-----------------------------------------------------------------------------
94 AliPHOSRawDecoder& AliPHOSRawDecoder::operator = (const AliPHOSRawDecoder &phosDecode)
95 {
96   //Assignment operator.
97
98   if(this != &phosDecode) {
99     fRawReader = phosDecode.fRawReader;
100
101     if(fCaloStream) delete fCaloStream;
102     fCaloStream = phosDecode.fCaloStream;
103
104     fEnergy = phosDecode.fEnergy;
105     fTime = phosDecode.fTime;
106     fModule = phosDecode.fModule;
107     fColumn = phosDecode.fColumn;
108     fRow = phosDecode.fRow;
109
110     if(fSamples) delete fSamples;
111     fSamples = phosDecode.fSamples;
112
113     if(fPulseGenerator) delete fPulseGenerator;
114     fPulseGenerator = phosDecode.fPulseGenerator;
115   }
116
117   return *this;
118 }
119
120 //-----------------------------------------------------------------------------
121
122 Bool_t AliPHOSRawDecoder::NextDigit()
123 {
124   //Extract an energy deposited in the crystal,
125   //crystal' position (module,column,row),
126   //time and gain (high or low).
127   
128   AliCaloRawStream* in = fCaloStream;
129   
130   Bool_t   lowGainFlag = kFALSE ; 
131   Int_t    iBin     = 0;
132   Int_t    mxSmps   = fSamples->GetSize();
133   Int_t    tLength  = -1;
134   fEnergy = -111;
135   
136   fSamples->Reset();
137   
138   while ( in->Next() ) { 
139
140     tLength = in->GetTimeLength();
141     if(tLength>mxSmps) { 
142       fSamples->Set(tLength);
143       mxSmps = fSamples->GetSize();
144     }
145
146     lowGainFlag = in->IsLowGain();
147     
148     // Fill array with samples
149     fSamples->AddAt(in->GetSignal(),tLength-iBin-1);
150     if((Double_t)in->GetSignal() > fEnergy) fEnergy = (Double_t)in->GetSignal();
151     iBin++;
152
153     // Fit the full sample
154     if(iBin==tLength) {
155       iBin=0;
156
157       // Temporarily we take the energy as a maximum amplitude
158       // and the pedestal from the 0th point (30 Aug 2006).
159       // Time is not evaluated for the moment (12.01.2007). 
160       // Take is as a first time bin multiplied by the sample tick time
161
162       fTime = fPulseGenerator->GetRawFormatTimeTrigger() * in->GetTime();
163
164       fModule = in->GetModule()+1;
165       fRow = in->GetRow()   +1;
166       fColumn = in->GetColumn()+1;
167
168       if(fPedSubtract) 
169         fEnergy -= (Double_t)fSamples->At(0); // "pedestal subtraction"
170       
171       if(lowGainFlag)
172         fEnergy *= fPulseGenerator->GetRawFormatHighLowGainFactor(); // *16 
173       
174       return kTRUE;
175     }
176
177   } // in.Next()
178   
179   
180   return kFALSE;
181 }