source: trunk/MagicSoft/Mars/mraw/MRawEvtData.cc@ 745

Last change on this file since 745 was 718, checked in by tbretz, 24 years ago
*** empty log message ***
File size: 8.7 KB
Line 
1/////////////////////////////////////////////////////////////////////////////
2//
3// MRawEvtData
4//
5// Storage container to store the raw FADC values.
6//
7// MArrayS fHiGainPixId
8// ---------------------
9// Array of Pixel Numbers for their high voltage channel in the order the
10// FADC values are stored in fHiGainFadcSamples
11//
12// MArrayB fHiGainFadcSaples
13// -------------------------
14// FADC samples (hi gain) of all pixels
15//
16// MArrayS fLoGainPixId
17// --------------------
18// see fHiGainPixId
19//
20// MArrayB fLoGainFadcSamples
21// --------------------------
22// see fHiGainFadcSaples
23//
24/////////////////////////////////////////////////////////////////////////////
25
26#include "MRawEvtData.h"
27
28#include <iomanip.h>
29
30#include <fstream.h>
31
32#include <TH1.h>
33#include <TGraph.h>
34#include <TArrayC.h>
35
36#include "MLog.h"
37#include "MArrayS.h"
38#include "MArrayB.h"
39#include "MRawRunHeader.h"
40
41ClassImp(MRawEvtData)
42
43MRawEvtData::MRawEvtData(const char *name, const char *title)
44{
45 *fName = name ? name : "MRawEvtData";
46 *fTitle = title ? title : "Raw Event Data Information";
47
48 InitArrays();
49}
50
51MRawEvtData::~MRawEvtData()
52{
53 DeleteArrays();
54}
55
56void MRawEvtData::Clear(Option_t *)
57{
58 //
59 // reset all arrays
60 //
61
62 /*
63 FIXME:
64 Is Reset (set all entries to zero) what you want to do
65 or Set(0) (delete the array)
66 */
67 fHiGainPixId->Reset();
68 fLoGainPixId->Reset();
69 fHiGainFadcSamples->Reset();
70 fLoGainFadcSamples->Reset();
71}
72
73Byte_t MRawEvtData::GetNumHiGainSamples() const
74{
75 return fHiGainPixId->GetSize() ? fHiGainFadcSamples->GetSize()/fHiGainPixId->GetSize() : 0;
76}
77
78Byte_t MRawEvtData::GetNumLoGainSamples() const
79{
80 return fLoGainPixId->GetSize() ? fLoGainFadcSamples->GetSize()/fLoGainPixId->GetSize() : 0;
81}
82
83UShort_t MRawEvtData::GetNumPixels() const
84{
85 return fHiGainPixId->GetSize();
86}
87
88
89void MRawEvtData::Print(Option_t *opt)
90{
91 //
92 // print fadc inforation to screen
93 // Possible Options:
94 // - DEC: Print values decimal instead of hexadecimal (default)
95 //
96 const Byte_t nHiSamp = GetNumHiGainSamples();
97 const Byte_t nLoSamp = GetNumLoGainSamples();
98
99 const UShort_t nHiPix = fHiGainPixId->GetSize();;
100 const UShort_t nLoPix = fLoGainPixId->GetSize();;
101
102 fLog->unsetf(ios::showbase);
103
104 *fLog << dec;
105 *fLog << "HiGain: " << nHiPix << " Pixels with " << (Int_t)nHiSamp << " Samples" << endl;
106 *fLog << "LoGain: " << nLoPix << " Pixels with " << (Int_t)nLoSamp << " Samples";;
107
108 TString str(opt);
109 Int_t manip = str.Contains("dec", TString::kIgnoreCase);
110
111 Int_t l=0;
112 for (int i=0; i<nHiPix; i++)
113 {
114 *fLog << endl;
115 *fLog << " " << setfill(' ') << setw(3) << dec << i << ": ";
116 *fLog << (manip?dec:hex) << flush;
117
118 if (!manip)
119 *fLog << setfill('0');
120
121 for (int j=0; j<nHiSamp; j++)
122 {
123 *fLog << setw(manip?3:2);
124 *fLog << ((UShort_t)(*fHiGainFadcSamples)[j+i*nHiSamp]&0xff);
125 if (manip)
126 *fLog << ' ';
127 *fLog << flush;
128 }
129
130 if (!(l<nLoPix && (*fLoGainPixId)[l]==(*fHiGainPixId)[i]))
131 continue;
132
133 if (manip)
134 *fLog << "/ ";
135
136 for (int j=0; j<nLoSamp; j++)
137 {
138 *fLog << setw(manip?3:2);
139 *fLog << ((UShort_t)(*fLoGainFadcSamples)[j+i*nLoSamp]&0xff);
140 if (manip)
141 *fLog << ' ';
142 *fLog << flush;
143 }
144 l++;
145 }
146 *fLog << endl;
147}
148
149void MRawEvtData::Draw(Option_t *opt)
150{
151 // ----- AppendPad(opt);
152
153 //
154 // FIXME: BIG MEMORY LEAK!
155 //
156
157 TString str(opt);
158
159 UInt_t num = 0;
160
161 if (str.BeginsWith("GRAPH", TString::kIgnoreCase))
162 {
163 if (str.Length()>5)
164 sscanf(&str[5], "%d", &num);
165
166 if (num>=GetNumPixels())
167 num= GetNumPixels();
168
169 *fLog << "Drawing Graph: Pixel #" << num << " of " << (int)GetNumPixels() << endl;
170
171 const Int_t n = GetNumHiGainSamples();
172
173 Float_t *x = new Float_t[n];
174 Float_t *y = new Float_t[n];
175
176 for (int i=0; i<n; i++)
177 {
178 x[i] = i;
179 y[i] = (*fHiGainFadcSamples)[i + num*GetNumHiGainSamples()];
180 }
181
182 TGraph *graph = new TGraph(n, x, y);
183 graph->SetMaximum (256) ;
184 graph->SetMinimum (0) ;
185
186 graph->Draw("AC*");
187
188 return;
189 }
190
191 if (str.BeginsWith("HIST", TString::kIgnoreCase))
192 {
193 *fLog << "Length: " << str.Length() << endl;
194
195 if (str.Length()>4)
196 sscanf(&str[4], "%d", &num);
197
198 if (num>=GetNumPixels())
199 num= GetNumPixels();
200
201 *fLog << "Drawing Histogram of Pixel " << num << endl;
202
203 const Int_t n = GetNumHiGainSamples();
204
205 char *name = new char[16];
206
207 sprintf(name, "Pixel No.%d", (*fHiGainPixId)[num]);
208
209 TH1F *hist = new TH1F(name, "Hi Gain Samples FADC", n, 0, n);
210
211 for (int i=0; i<n; i++)
212 hist->Fill(0.5+i, (*fHiGainFadcSamples)[i + num*GetNumHiGainSamples()]);
213
214 hist->Draw();
215
216 return;
217 }
218
219 *fLog << "MRawEvtData::Draw: Warning: You must specify either 'GRAPH' or 'HIST'" << endl;
220}
221
222void MRawEvtData::DeletePixels(Bool_t flag)
223{
224 //
225 // Deletes all arrays describing the pixel Id and Samples in pixels
226 //
227 DeleteArrays();
228 InitArrays(flag);
229}
230
231void MRawEvtData::DeleteArrays()
232{
233 delete fHiGainPixId;
234 delete fLoGainPixId;
235 delete fHiGainFadcSamples;
236 delete fLoGainFadcSamples;
237}
238
239void MRawEvtData::InitArrays(Bool_t flag)
240{
241 // const int npix = !flag ? 0 : fRunHeader->GetNumCrates()*fRunHeader->GetNumPixInCrate();
242
243 fHiGainPixId = new MArrayS(0);//npix);
244 fLoGainPixId = new MArrayS(0);//npix);
245 fHiGainFadcSamples = new MArrayB(0);//npix*fRunHeader->GetNumSamplesHiGain());
246 fLoGainFadcSamples = new MArrayB(0);//npix*fRunHeader->GetNumSamplesLoGain());
247}
248
249void MRawEvtData::AddPixel(UShort_t nOfPixel, TArrayC *data, Bool_t lflag)
250{
251 //
252 // This is to fill the data of one pixel to the MRawEvtHeader Class.
253 // The parameters are the pixelnumber and the FADC_SLICES values of ADCs
254 // Add to lo gains if lflag = 1
255 //
256 MArrayS *arrpix = lflag ? fLoGainPixId : fHiGainPixId;
257 MArrayB *arrsam = lflag ? fLoGainFadcSamples : fHiGainFadcSamples;
258
259 //
260 // check whether we got the right number of new samples
261 // if there are no samples already stored: this is the new number of samples
262 //
263 const Byte_t ns = data->GetSize();
264 const Byte_t nSamp = lflag ? GetNumLoGainSamples() : GetNumHiGainSamples();
265 if (nSamp && ns!=nSamp)
266 {
267 *fLog << "RawEvtData::FillPixel: Error, number of samples in ";
268 *fLog << "TArrayC doesn't match actual number" << endl;
269 return;
270 }
271
272 //
273 // enhance pixel array by one
274 //
275 arrpix->Set(arrpix->GetSize()+1);
276
277 //
278 // add the number of the new pixel to the array as last entry
279 //
280 arrpix->AddAt(nOfPixel, arrpix->GetSize()-1);
281
282 //
283 // enhance the array by the number of new samples
284 //
285 arrsam->Set(arrsam->GetSize()+ns);
286
287 //
288 // add the new slices as last entries to array
289 //
290 arrsam->AddAt((Byte_t*)data->GetArray(), arrsam->GetSize()-ns, ns);
291}
292
293void MRawEvtData::ReadEvt(istream &fin)
294{
295 //
296 // Fills members with information from a magic binary file.
297 // WARNING: you have to use Init() before you can do this
298 //
299 const UShort_t nlo = fRunHeader->GetNumSamplesLoGain();
300 const UShort_t nhi = fRunHeader->GetNumSamplesHiGain();
301
302 const UShort_t npic = fRunHeader->GetNumPixInCrate();
303
304 //
305 // Enhance array by the size which we'll read now
306 //
307 const int npixhi = fHiGainPixId->GetSize();
308 const int npixlo = fLoGainPixId->GetSize();
309
310 fHiGainPixId->Set(npixhi+npic);
311 fLoGainPixId->Set(npixlo+npic);
312
313 const int nsamhi = fHiGainFadcSamples->GetSize();
314 const int nsamlo = fLoGainFadcSamples->GetSize();
315
316 fHiGainFadcSamples->Set(nsamhi+nhi*npic);
317 fLoGainFadcSamples->Set(nsamlo+nlo*npic);
318
319 Byte_t *higainsam = fHiGainFadcSamples->GetArray()+nsamhi;
320 Byte_t *logainsam = fLoGainFadcSamples->GetArray()+nsamlo;
321
322 for (int i=0; i<npic; i++)
323 {
324 //
325 // get the spiral pixel number from the run header
326 //
327 const UShort_t npix = fRunHeader->GetPixAssignment(i);
328
329 //
330 // This is to fill the data of one pixel to the MRawEvtHeader Class.
331 // The parameters are the pixelnumber and the FADC_SLICES values of ADCs
332 // Add to lo gains if lflag = 1
333 //
334 fHiGainPixId->AddAt(npix, npixhi+i);
335 fin.read(higainsam, nhi);
336 higainsam += nhi;
337
338 // FIXME: Not implemented in the raw files yet
339 //if (IsLoGainOn(i, j))
340 //{
341 fLoGainPixId->AddAt(npix, npixlo+i);
342 fin.read(logainsam, nlo);
343 logainsam += nlo;
344 //}
345 }
346}
347
Note: See TracBrowser for help on using the repository browser.