source: trunk/MagicSoft/include-Classes/MRawFormat/MRawEvtData.cc@ 9620

Last change on this file since 9620 was 498, checked in by magicsol, 24 years ago
*** empty log message ***
  • Property svn:executable set to *
File size: 8.0 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 <iostream.h>
29#include <iomanip.h>
30
31#include <fstream.h>
32
33#include <TH1.h>
34#include <TGraph.h>
35#include <TArrayC.h>
36
37#include "../MBase/MArrayS.h"
38#include "../MBase/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 *)
90{
91 //
92 // print fadc inforation to screen
93 //
94 const Byte_t nHiSamp = GetNumHiGainSamples();
95 const Byte_t nLoSamp = GetNumLoGainSamples();
96
97 const UShort_t nHiPix = fHiGainPixId->GetSize();;
98 const UShort_t nLoPix = fLoGainPixId->GetSize();;
99
100 cout << dec;
101 cout << "HiGain: " << nHiPix << " Pixels with " << (Int_t)nHiSamp << " Samples" << endl;
102 cout << "LoGain: " << nLoPix << " Pixels with " << (Int_t)nLoSamp << " Samples" << endl;
103
104 Int_t l=0;
105 for (int i=0; i<nHiPix; i++)
106 {
107 cout << " " << setfill(' ') << setw(3) << i << ": " << hex << flush;
108
109 cout << setfill('0');
110
111 for (int j=0; j<nHiSamp; j++)
112 cout << setw(2)
113 << ((UShort_t)(*fHiGainFadcSamples)[j+i*nHiSamp]&0xff) << flush;
114
115 if (l<nLoPix && (*fLoGainPixId)[l]==(*fHiGainPixId)[i])
116 {
117 for (int j=0; j<nLoSamp; j++)
118 cout << setw(2)
119 <<((UShort_t)(*fLoGainFadcSamples)[j+i*nLoSamp]&0xff) << flush;
120 l++;
121 }
122 cout << dec << endl;
123 }
124 cout << endl;
125}
126
127void MRawEvtData::Draw(Option_t *opt)
128{
129 TString str(opt);
130
131 UInt_t num = 0;
132
133 if (str.BeginsWith("GRAPH", TString::kIgnoreCase))
134 {
135 if (str.Length()>5)
136 sscanf(&str[5], "%d", &num);
137
138 if (num>=GetNumPixels())
139 num= GetNumPixels();
140
141 cout << "Drawing Graph of Pixel " << num << endl;
142
143 const Int_t n = GetNumHiGainSamples();
144
145 Float_t *x = new Float_t[n];
146 Float_t *y = new Float_t[n];
147
148 for (int i=0; i<n; i++)
149 {
150 x[i] = i;
151 y[i] = (*fHiGainFadcSamples)[i + num*GetNumHiGainSamples()];
152 }
153
154 TGraph *graph = new TGraph(n, x, y);
155 graph->Draw("AC*");
156
157 return;
158 }
159
160 if (str.BeginsWith("HIST", TString::kIgnoreCase))
161 {
162 cout << "Length: " << str.Length() << endl;
163
164 if (str.Length()>4)
165 sscanf(&str[4], "%d", &num);
166
167 if (num>=GetNumPixels())
168 num= GetNumPixels();
169
170 cout << "Drawing Histogram of Pixel " << num << endl;
171
172 const Int_t n = GetNumHiGainSamples();
173
174 char *name = new char[16];
175
176 sprintf(name, "Pixel No.%d", (*fHiGainPixId)[num]);
177
178 TH1F *hist = new TH1F(name, "Hi Gain Samples FADC", n, 0, n);
179
180 for (int i=0; i<n; i++)
181 hist->Fill(0.5+i, (*fHiGainFadcSamples)[i + num*GetNumHiGainSamples()]);
182
183 hist->Draw();
184
185 return;
186 }
187
188 cout << "MRawEvtData::Draw: Warning: You must specify either 'GRAPH' or 'HIST'" << endl;
189}
190
191void MRawEvtData::DeletePixels()
192{
193 //
194 // Deletes all arrays describing the pixel Id and Samples in pixels
195 //
196 DeleteArrays();
197 InitArrays();
198}
199
200void MRawEvtData::DeleteArrays()
201{
202 delete fHiGainPixId;
203 delete fLoGainPixId;
204 delete fHiGainFadcSamples;
205 delete fLoGainFadcSamples;
206}
207
208void MRawEvtData::InitArrays()
209{
210 fHiGainPixId = new MArrayS(0); //UShort_t[0];
211 fLoGainPixId = new MArrayS(0); //new UShort_t[0];
212 fHiGainFadcSamples = new MArrayB(0); //new Byte_t[0];
213 fLoGainFadcSamples = new MArrayB(0); //new Byte_t[0];
214}
215
216void MRawEvtData::AddPixel(UShort_t nOfPixel, TArrayC *data, Bool_t lflag)
217{
218 //
219 // This is to fill the data of one pixel to the MRawEvtHeader Class.
220 // The parameters are the pixelnumber and the FADC_SLICES values of ADCs
221 // Add to lo gains if lflag = 1
222 //
223
224 MArrayS *arrpix = lflag ? fLoGainPixId : fHiGainPixId;
225 MArrayB *arrsam = lflag ? fLoGainFadcSamples : fHiGainFadcSamples;
226
227 //
228 // check whether we got the right number of new samples
229 // if there are no samples already stored: this is the new number of samples
230 //
231 const Byte_t ns = data->GetSize();
232 const Byte_t nSamp = lflag ? GetNumLoGainSamples() : GetNumHiGainSamples();
233 if (nSamp && ns!=nSamp)
234 {
235 cout << "RawEvtData::FillPixel: Error, number of samples in ";
236 cout << "TArrayC doesn't match actual number" << endl;
237 return;
238 }
239
240 //
241 // enhance pixel array by one
242 //
243 arrpix->Set(arrpix->GetSize()+1);
244
245 //
246 // add the number of the new pixel to the array as last entry
247 //
248 arrpix->AddAt(nOfPixel, arrpix->GetSize()-1);
249
250 //
251 // enhance the array by the number of new samples
252 //
253 arrsam->Set(arrsam->GetSize()+ns);
254
255 //
256 // add the new slices as last entries to array
257 //
258 arrsam->AddAt((Byte_t*)data->GetArray(), arrsam->GetSize()-ns, ns);
259}
260
261/*
262void MRawEvtData::AddPixelLo(UShort_t nOfPixel, TArrayC *data, int nr, int pos)
263{
264 //
265 // add the number of the new pixel to the array as last entry
266 //
267 fLoGainPixId->AddAt(nOfPixel, nr);
268
269 //
270 // add the new slices as last entries to array
271 //
272 fLoGainFadcSamples->AddAt((Byte_t*)data->GetArray(), pos, data->GetSize());
273}
274
275void MRawEvtData::AddPixelHi(UShort_t nOfPixel, TArrayC *data, int nr, int pos)
276{
277 // check whether we got the right number of new samples
278 // if there are no samples already stored: this is the new number of samples
279 //
280 const Byte_t ns = data->GetSize();
281
282 //
283 // add the number of the new pixel to the array as last entry
284 //
285 fHiGainPixId->AddAt(nOfPixel, nr);
286
287 //
288 // add the new slices as last entries to array
289 //
290 fHiGainFadcSamples->AddAt((Byte_t*)data->GetArray(), arrsam->GetSize()-ns, ns);
291}
292*/
293void MRawEvtData::ReadEvt(ifstream &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 TArrayC lo(nlo);
303 TArrayC hi(nhi);
304
305 const UShort_t npic = fRunHeader->GetNumPixInCrate();
306
307 for (int i=0; i<npic; i++)
308 {
309 //
310 // get the spiral pixel number from the run header
311 //
312 const UShort_t npix = fRunHeader->GetPixAssignment(i);
313
314 // FIXME: Not implemented in the raw files yet
315 //if (IsLoGainOn(i, j))
316 //{
317 fin.read((Byte_t*)lo.GetArray(), nlo);
318 AddPixel(npix, &lo, kTRUE);
319 //}
320
321 fin.read((Byte_t*)hi.GetArray(), nhi);
322 AddPixel(npix, &hi, kFALSE);
323 }
324}
325
Note: See TracBrowser for help on using the repository browser.