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 |
|
---|
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 *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 |
|
---|
149 | void 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 |
|
---|
218 | void MRawEvtData::DeletePixels()
|
---|
219 | {
|
---|
220 | //
|
---|
221 | // Deletes all arrays describing the pixel Id and Samples in pixels
|
---|
222 | //
|
---|
223 | DeleteArrays();
|
---|
224 | InitArrays();
|
---|
225 | }
|
---|
226 |
|
---|
227 | void MRawEvtData::DeleteArrays()
|
---|
228 | {
|
---|
229 | delete fHiGainPixId;
|
---|
230 | delete fLoGainPixId;
|
---|
231 | delete fHiGainFadcSamples;
|
---|
232 | delete fLoGainFadcSamples;
|
---|
233 | }
|
---|
234 |
|
---|
235 | void MRawEvtData::InitArrays()
|
---|
236 | {
|
---|
237 | fHiGainPixId = new MArrayS(0); //UShort_t[0];
|
---|
238 | fLoGainPixId = new MArrayS(0); //new UShort_t[0];
|
---|
239 | fHiGainFadcSamples = new MArrayB(0); //new Byte_t[0];
|
---|
240 | fLoGainFadcSamples = new MArrayB(0); //new Byte_t[0];
|
---|
241 | }
|
---|
242 |
|
---|
243 | void MRawEvtData::AddPixel(UShort_t nOfPixel, TArrayC *data, Bool_t lflag)
|
---|
244 | {
|
---|
245 | //
|
---|
246 | // This is to fill the data of one pixel to the MRawEvtHeader Class.
|
---|
247 | // The parameters are the pixelnumber and the FADC_SLICES values of ADCs
|
---|
248 | // Add to lo gains if lflag = 1
|
---|
249 | //
|
---|
250 |
|
---|
251 | MArrayS *arrpix = lflag ? fLoGainPixId : fHiGainPixId;
|
---|
252 | MArrayB *arrsam = lflag ? fLoGainFadcSamples : fHiGainFadcSamples;
|
---|
253 |
|
---|
254 | //
|
---|
255 | // check whether we got the right number of new samples
|
---|
256 | // if there are no samples already stored: this is the new number of samples
|
---|
257 | //
|
---|
258 | const Byte_t ns = data->GetSize();
|
---|
259 | const Byte_t nSamp = lflag ? GetNumLoGainSamples() : GetNumHiGainSamples();
|
---|
260 | if (nSamp && ns!=nSamp)
|
---|
261 | {
|
---|
262 | *fLog << "RawEvtData::FillPixel: Error, number of samples in ";
|
---|
263 | *fLog << "TArrayC doesn't match actual number" << endl;
|
---|
264 | return;
|
---|
265 | }
|
---|
266 |
|
---|
267 | //
|
---|
268 | // enhance pixel array by one
|
---|
269 | //
|
---|
270 | arrpix->Set(arrpix->GetSize()+1);
|
---|
271 |
|
---|
272 | //
|
---|
273 | // add the number of the new pixel to the array as last entry
|
---|
274 | //
|
---|
275 | arrpix->AddAt(nOfPixel, arrpix->GetSize()-1);
|
---|
276 |
|
---|
277 | //
|
---|
278 | // enhance the array by the number of new samples
|
---|
279 | //
|
---|
280 | arrsam->Set(arrsam->GetSize()+ns);
|
---|
281 |
|
---|
282 | //
|
---|
283 | // add the new slices as last entries to array
|
---|
284 | //
|
---|
285 | arrsam->AddAt((Byte_t*)data->GetArray(), arrsam->GetSize()-ns, ns);
|
---|
286 | }
|
---|
287 |
|
---|
288 | /*
|
---|
289 | void MRawEvtData::AddPixelLo(UShort_t nOfPixel, TArrayC *data, int nr, int pos)
|
---|
290 | {
|
---|
291 | //
|
---|
292 | // add the number of the new pixel to the array as last entry
|
---|
293 | //
|
---|
294 | fLoGainPixId->AddAt(nOfPixel, nr);
|
---|
295 |
|
---|
296 | //
|
---|
297 | // add the new slices as last entries to array
|
---|
298 | //
|
---|
299 | fLoGainFadcSamples->AddAt((Byte_t*)data->GetArray(), pos, data->GetSize());
|
---|
300 | }
|
---|
301 |
|
---|
302 | void MRawEvtData::AddPixelHi(UShort_t nOfPixel, TArrayC *data, int nr, int pos)
|
---|
303 | {
|
---|
304 | // check whether we got the right number of new samples
|
---|
305 | // if there are no samples already stored: this is the new number of samples
|
---|
306 | //
|
---|
307 | const Byte_t ns = data->GetSize();
|
---|
308 |
|
---|
309 | //
|
---|
310 | // add the number of the new pixel to the array as last entry
|
---|
311 | //
|
---|
312 | fHiGainPixId->AddAt(nOfPixel, nr);
|
---|
313 |
|
---|
314 | //
|
---|
315 | // add the new slices as last entries to array
|
---|
316 | //
|
---|
317 | fHiGainFadcSamples->AddAt((Byte_t*)data->GetArray(), arrsam->GetSize()-ns, ns);
|
---|
318 | }
|
---|
319 | */
|
---|
320 | void MRawEvtData::ReadEvt(ifstream &fin)
|
---|
321 | {
|
---|
322 | //
|
---|
323 | // Fills members with information from a magic binary file.
|
---|
324 | // WARNING: you have to use Init() before you can do this
|
---|
325 | //
|
---|
326 | const UShort_t nlo = fRunHeader->GetNumSamplesLoGain();
|
---|
327 | const UShort_t nhi = fRunHeader->GetNumSamplesHiGain();
|
---|
328 |
|
---|
329 | TArrayC lo(nlo);
|
---|
330 | TArrayC hi(nhi);
|
---|
331 |
|
---|
332 | const UShort_t npic = fRunHeader->GetNumPixInCrate();
|
---|
333 |
|
---|
334 | for (int i=0; i<npic; i++)
|
---|
335 | {
|
---|
336 | //
|
---|
337 | // get the spiral pixel number from the run header
|
---|
338 | //
|
---|
339 | const UShort_t npix = fRunHeader->GetPixAssignment(i);
|
---|
340 |
|
---|
341 | fin.read((Byte_t*)hi.GetArray(), nhi);
|
---|
342 | AddPixel(npix, &hi, kFALSE);
|
---|
343 |
|
---|
344 | // FIXME: Not implemented in the raw files yet
|
---|
345 | //if (IsLoGainOn(i, j))
|
---|
346 | //{
|
---|
347 | fin.read((Byte_t*)lo.GetArray(), nlo);
|
---|
348 | AddPixel(npix, &lo, kTRUE);
|
---|
349 | //}
|
---|
350 | }
|
---|
351 | }
|
---|
352 |
|
---|