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

Last change on this file since 711 was 658, checked in by tbretz, 24 years ago
*** empty log message ***
File size: 8.6 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
83Byte_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 TString str(opt);
154
155 UInt_t num = 0;
156
157 if (str.BeginsWith("GRAPH", TString::kIgnoreCase))
158 {
159 if (str.Length()>5)
160 sscanf(&str[5], "%d", &num);
161
162 if (num>=GetNumPixels())
163 num= GetNumPixels();
164
165 *fLog << "Drawing Graph of Pixel " << num << endl;
166
167 const Int_t n = GetNumHiGainSamples();
168
169 Float_t *x = new Float_t[n];
170 Float_t *y = new Float_t[n];
171
172 for (int i=0; i<n; i++)
173 {
174 x[i] = i;
175 y[i] = (*fHiGainFadcSamples)[i + num*GetNumHiGainSamples()];
176 }
177
178 TGraph *graph = new TGraph(n, x, y);
179 graph->SetMaximum (256) ;
180 graph->SetMinimum (0) ;
181
182 graph->Draw("AC*");
183
184 return;
185 }
186
187 if (str.BeginsWith("HIST", TString::kIgnoreCase))
188 {
189 *fLog << "Length: " << str.Length() << endl;
190
191 if (str.Length()>4)
192 sscanf(&str[4], "%d", &num);
193
194 if (num>=GetNumPixels())
195 num= GetNumPixels();
196
197 *fLog << "Drawing Histogram of Pixel " << num << endl;
198
199 const Int_t n = GetNumHiGainSamples();
200
201 char *name = new char[16];
202
203 sprintf(name, "Pixel No.%d", (*fHiGainPixId)[num]);
204
205 TH1F *hist = new TH1F(name, "Hi Gain Samples FADC", n, 0, n);
206
207 for (int i=0; i<n; i++)
208 hist->Fill(0.5+i, (*fHiGainFadcSamples)[i + num*GetNumHiGainSamples()]);
209
210 hist->Draw();
211
212 return;
213 }
214
215 *fLog << "MRawEvtData::Draw: Warning: You must specify either 'GRAPH' or 'HIST'" << endl;
216}
217
218void MRawEvtData::DeletePixels(Bool_t flag)
219{
220 //
221 // Deletes all arrays describing the pixel Id and Samples in pixels
222 //
223 DeleteArrays();
224 InitArrays(flag);
225}
226
227void MRawEvtData::DeleteArrays()
228{
229 delete fHiGainPixId;
230 delete fLoGainPixId;
231 delete fHiGainFadcSamples;
232 delete fLoGainFadcSamples;
233}
234
235void MRawEvtData::InitArrays(Bool_t flag)
236{
237 // const int npix = !flag ? 0 : fRunHeader->GetNumCrates()*fRunHeader->GetNumPixInCrate();
238
239 fHiGainPixId = new MArrayS(0);//npix);
240 fLoGainPixId = new MArrayS(0);//npix);
241 fHiGainFadcSamples = new MArrayB(0);//npix*fRunHeader->GetNumSamplesHiGain());
242 fLoGainFadcSamples = new MArrayB(0);//npix*fRunHeader->GetNumSamplesLoGain());
243}
244
245void MRawEvtData::AddPixel(UShort_t nOfPixel, TArrayC *data, Bool_t lflag)
246{
247 //
248 // This is to fill the data of one pixel to the MRawEvtHeader Class.
249 // The parameters are the pixelnumber and the FADC_SLICES values of ADCs
250 // Add to lo gains if lflag = 1
251 //
252 MArrayS *arrpix = lflag ? fLoGainPixId : fHiGainPixId;
253 MArrayB *arrsam = lflag ? fLoGainFadcSamples : fHiGainFadcSamples;
254
255 //
256 // check whether we got the right number of new samples
257 // if there are no samples already stored: this is the new number of samples
258 //
259 const Byte_t ns = data->GetSize();
260 const Byte_t nSamp = lflag ? GetNumLoGainSamples() : GetNumHiGainSamples();
261 if (nSamp && ns!=nSamp)
262 {
263 *fLog << "RawEvtData::FillPixel: Error, number of samples in ";
264 *fLog << "TArrayC doesn't match actual number" << endl;
265 return;
266 }
267
268 //
269 // enhance pixel array by one
270 //
271 arrpix->Set(arrpix->GetSize()+1);
272
273 //
274 // add the number of the new pixel to the array as last entry
275 //
276 arrpix->AddAt(nOfPixel, arrpix->GetSize()-1);
277
278 //
279 // enhance the array by the number of new samples
280 //
281 arrsam->Set(arrsam->GetSize()+ns);
282
283 //
284 // add the new slices as last entries to array
285 //
286 arrsam->AddAt((Byte_t*)data->GetArray(), arrsam->GetSize()-ns, ns);
287}
288
289void MRawEvtData::ReadEvt(istream &fin)
290{
291 //
292 // Fills members with information from a magic binary file.
293 // WARNING: you have to use Init() before you can do this
294 //
295 const UShort_t nlo = fRunHeader->GetNumSamplesLoGain();
296 const UShort_t nhi = fRunHeader->GetNumSamplesHiGain();
297
298 const UShort_t npic = fRunHeader->GetNumPixInCrate();
299
300 //
301 // Enhance array by the size which we'll read now
302 //
303 const int npixhi = fHiGainPixId->GetSize();
304 const int npixlo = fLoGainPixId->GetSize();
305
306 fHiGainPixId->Set(npixhi+npic);
307 fLoGainPixId->Set(npixlo+npic);
308
309 const int nsamhi = fHiGainFadcSamples->GetSize();
310 const int nsamlo = fLoGainFadcSamples->GetSize();
311
312 fHiGainFadcSamples->Set(nsamhi+nhi*npic);
313 fLoGainFadcSamples->Set(nsamlo+nlo*npic);
314
315 Byte_t *higainsam = fHiGainFadcSamples->GetArray()+nsamhi;
316 Byte_t *logainsam = fLoGainFadcSamples->GetArray()+nsamlo;
317
318 for (int i=0; i<npic; i++)
319 {
320 //
321 // get the spiral pixel number from the run header
322 //
323 const UShort_t npix = fRunHeader->GetPixAssignment(i);
324
325 //
326 // This is to fill the data of one pixel to the MRawEvtHeader Class.
327 // The parameters are the pixelnumber and the FADC_SLICES values of ADCs
328 // Add to lo gains if lflag = 1
329 //
330 fHiGainPixId->AddAt(npix, npixhi+i);
331 fin.read(higainsam, nhi);
332 higainsam += nhi;
333
334 // FIXME: Not implemented in the raw files yet
335 //if (IsLoGainOn(i, j))
336 //{
337 fLoGainPixId->AddAt(npix, npixlo+i);
338 fin.read(logainsam, nlo);
339 logainsam += nlo;
340 //}
341 }
342}
343
Note: See TracBrowser for help on using the repository browser.