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 |
|
---|
41 | ClassImp(MRawEvtData)
|
---|
42 |
|
---|
43 | MRawEvtData::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 |
|
---|
51 | MRawEvtData::~MRawEvtData()
|
---|
52 | {
|
---|
53 | DeleteArrays();
|
---|
54 | }
|
---|
55 |
|
---|
56 | void 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 |
|
---|
73 | Byte_t MRawEvtData::GetNumHiGainSamples() const
|
---|
74 | {
|
---|
75 | return fHiGainPixId->GetSize() ? fHiGainFadcSamples->GetSize()/fHiGainPixId->GetSize() : 0;
|
---|
76 | }
|
---|
77 |
|
---|
78 | Byte_t MRawEvtData::GetNumLoGainSamples() const
|
---|
79 | {
|
---|
80 | return fLoGainPixId->GetSize() ? fLoGainFadcSamples->GetSize()/fLoGainPixId->GetSize() : 0;
|
---|
81 | }
|
---|
82 |
|
---|
83 | Byte_t MRawEvtData::GetNumPixels() const
|
---|
84 | {
|
---|
85 | return fHiGainPixId->GetSize();
|
---|
86 | }
|
---|
87 |
|
---|
88 |
|
---|
89 | void 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 |
|
---|
127 | void 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->SetMaximum (256) ;
|
---|
158 | graph->SetMinimum (0) ;
|
---|
159 |
|
---|
160 | graph->Draw("AC*");
|
---|
161 |
|
---|
162 | return;
|
---|
163 | }
|
---|
164 |
|
---|
165 | if (str.BeginsWith("HIST", TString::kIgnoreCase))
|
---|
166 | {
|
---|
167 | cout << "Length: " << str.Length() << endl;
|
---|
168 |
|
---|
169 | if (str.Length()>4)
|
---|
170 | sscanf(&str[4], "%d", &num);
|
---|
171 |
|
---|
172 | if (num>=GetNumPixels())
|
---|
173 | num= GetNumPixels();
|
---|
174 |
|
---|
175 | cout << "Drawing Histogram of Pixel " << num << endl;
|
---|
176 |
|
---|
177 | const Int_t n = GetNumHiGainSamples();
|
---|
178 |
|
---|
179 | char *name = new char[16];
|
---|
180 |
|
---|
181 | sprintf(name, "Pixel No.%d", (*fHiGainPixId)[num]);
|
---|
182 |
|
---|
183 | TH1F *hist = new TH1F(name, "Hi Gain Samples FADC", n, 0, n);
|
---|
184 |
|
---|
185 | for (int i=0; i<n; i++)
|
---|
186 | hist->Fill(0.5+i, (*fHiGainFadcSamples)[i + num*GetNumHiGainSamples()]);
|
---|
187 |
|
---|
188 | hist->Draw();
|
---|
189 |
|
---|
190 | return;
|
---|
191 | }
|
---|
192 |
|
---|
193 | cout << "MRawEvtData::Draw: Warning: You must specify either 'GRAPH' or 'HIST'" << endl;
|
---|
194 | }
|
---|
195 |
|
---|
196 | void MRawEvtData::DeletePixels()
|
---|
197 | {
|
---|
198 | //
|
---|
199 | // Deletes all arrays describing the pixel Id and Samples in pixels
|
---|
200 | //
|
---|
201 | DeleteArrays();
|
---|
202 | InitArrays();
|
---|
203 | }
|
---|
204 |
|
---|
205 | void MRawEvtData::DeleteArrays()
|
---|
206 | {
|
---|
207 | delete fHiGainPixId;
|
---|
208 | delete fLoGainPixId;
|
---|
209 | delete fHiGainFadcSamples;
|
---|
210 | delete fLoGainFadcSamples;
|
---|
211 | }
|
---|
212 |
|
---|
213 | void MRawEvtData::InitArrays()
|
---|
214 | {
|
---|
215 | fHiGainPixId = new MArrayS(0); //UShort_t[0];
|
---|
216 | fLoGainPixId = new MArrayS(0); //new UShort_t[0];
|
---|
217 | fHiGainFadcSamples = new MArrayB(0); //new Byte_t[0];
|
---|
218 | fLoGainFadcSamples = new MArrayB(0); //new Byte_t[0];
|
---|
219 | }
|
---|
220 |
|
---|
221 | void MRawEvtData::AddPixel(UShort_t nOfPixel, TArrayC *data, Bool_t lflag)
|
---|
222 | {
|
---|
223 | //
|
---|
224 | // This is to fill the data of one pixel to the MRawEvtHeader Class.
|
---|
225 | // The parameters are the pixelnumber and the FADC_SLICES values of ADCs
|
---|
226 | // Add to lo gains if lflag = 1
|
---|
227 | //
|
---|
228 |
|
---|
229 | MArrayS *arrpix = lflag ? fLoGainPixId : fHiGainPixId;
|
---|
230 | MArrayB *arrsam = lflag ? fLoGainFadcSamples : fHiGainFadcSamples;
|
---|
231 |
|
---|
232 | //
|
---|
233 | // check whether we got the right number of new samples
|
---|
234 | // if there are no samples already stored: this is the new number of samples
|
---|
235 | //
|
---|
236 | const Byte_t ns = data->GetSize();
|
---|
237 | const Byte_t nSamp = lflag ? GetNumLoGainSamples() : GetNumHiGainSamples();
|
---|
238 | if (nSamp && ns!=nSamp)
|
---|
239 | {
|
---|
240 | cout << "RawEvtData::FillPixel: Error, number of samples in ";
|
---|
241 | cout << "TArrayC doesn't match actual number" << endl;
|
---|
242 | return;
|
---|
243 | }
|
---|
244 |
|
---|
245 | //
|
---|
246 | // enhance pixel array by one
|
---|
247 | //
|
---|
248 | arrpix->Set(arrpix->GetSize()+1);
|
---|
249 |
|
---|
250 | //
|
---|
251 | // add the number of the new pixel to the array as last entry
|
---|
252 | //
|
---|
253 | arrpix->AddAt(nOfPixel, arrpix->GetSize()-1);
|
---|
254 |
|
---|
255 | //
|
---|
256 | // enhance the array by the number of new samples
|
---|
257 | //
|
---|
258 | arrsam->Set(arrsam->GetSize()+ns);
|
---|
259 |
|
---|
260 | //
|
---|
261 | // add the new slices as last entries to array
|
---|
262 | //
|
---|
263 | arrsam->AddAt((Byte_t*)data->GetArray(), arrsam->GetSize()-ns, ns);
|
---|
264 | }
|
---|
265 |
|
---|
266 | /*
|
---|
267 | void MRawEvtData::AddPixelLo(UShort_t nOfPixel, TArrayC *data, int nr, int pos)
|
---|
268 | {
|
---|
269 | //
|
---|
270 | // add the number of the new pixel to the array as last entry
|
---|
271 | //
|
---|
272 | fLoGainPixId->AddAt(nOfPixel, nr);
|
---|
273 |
|
---|
274 | //
|
---|
275 | // add the new slices as last entries to array
|
---|
276 | //
|
---|
277 | fLoGainFadcSamples->AddAt((Byte_t*)data->GetArray(), pos, data->GetSize());
|
---|
278 | }
|
---|
279 |
|
---|
280 | void MRawEvtData::AddPixelHi(UShort_t nOfPixel, TArrayC *data, int nr, int pos)
|
---|
281 | {
|
---|
282 | // check whether we got the right number of new samples
|
---|
283 | // if there are no samples already stored: this is the new number of samples
|
---|
284 | //
|
---|
285 | const Byte_t ns = data->GetSize();
|
---|
286 |
|
---|
287 | //
|
---|
288 | // add the number of the new pixel to the array as last entry
|
---|
289 | //
|
---|
290 | fHiGainPixId->AddAt(nOfPixel, nr);
|
---|
291 |
|
---|
292 | //
|
---|
293 | // add the new slices as last entries to array
|
---|
294 | //
|
---|
295 | fHiGainFadcSamples->AddAt((Byte_t*)data->GetArray(), arrsam->GetSize()-ns, ns);
|
---|
296 | }
|
---|
297 | */
|
---|
298 | void MRawEvtData::ReadEvt(ifstream &fin)
|
---|
299 | {
|
---|
300 | //
|
---|
301 | // Fills members with information from a magic binary file.
|
---|
302 | // WARNING: you have to use Init() before you can do this
|
---|
303 | //
|
---|
304 | const UShort_t nlo = fRunHeader->GetNumSamplesLoGain();
|
---|
305 | const UShort_t nhi = fRunHeader->GetNumSamplesHiGain();
|
---|
306 |
|
---|
307 | TArrayC lo(nlo);
|
---|
308 | TArrayC hi(nhi);
|
---|
309 |
|
---|
310 | const UShort_t npic = fRunHeader->GetNumPixInCrate();
|
---|
311 |
|
---|
312 | for (int i=0; i<npic; i++)
|
---|
313 | {
|
---|
314 | //
|
---|
315 | // get the spiral pixel number from the run header
|
---|
316 | //
|
---|
317 | const UShort_t npix = fRunHeader->GetPixAssignment(i);
|
---|
318 |
|
---|
319 | // FIXME: Not implemented in the raw files yet
|
---|
320 | //if (IsLoGainOn(i, j))
|
---|
321 | //{
|
---|
322 | fin.read((Byte_t*)lo.GetArray(), nlo);
|
---|
323 | AddPixel(npix, &lo, kTRUE);
|
---|
324 | //}
|
---|
325 |
|
---|
326 | fin.read((Byte_t*)hi.GetArray(), nhi);
|
---|
327 | AddPixel(npix, &hi, kFALSE);
|
---|
328 | }
|
---|
329 | }
|
---|
330 |
|
---|