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