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

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