1 | /* ======================================================================== *\
|
---|
2 | !
|
---|
3 | ! *
|
---|
4 | ! * This file is part of MARS, the MAGIC Analysis and Reconstruction
|
---|
5 | ! * Software. It is distributed to you in the hope that it can be a useful
|
---|
6 | ! * and timesaving tool in analysing Data of imaging Cerenkov telescopes.
|
---|
7 | ! * It is distributed WITHOUT ANY WARRANTY.
|
---|
8 | ! *
|
---|
9 | ! * Permission to use, copy, modify and distribute this software and its
|
---|
10 | ! * documentation for any purpose is hereby granted without fee,
|
---|
11 | ! * provided that the above copyright notice appear in all copies and
|
---|
12 | ! * that both that copyright notice and this permission notice appear
|
---|
13 | ! * in supporting documentation. It is provided "as is" without express
|
---|
14 | ! * or implied warranty.
|
---|
15 | ! *
|
---|
16 | !
|
---|
17 | !
|
---|
18 | ! Author(s): Markus Gaug 09/2003 <mailto:markus@ifae.es>
|
---|
19 | !
|
---|
20 | ! Copyright: MAGIC Software Development, 2000-2001
|
---|
21 | !
|
---|
22 | !
|
---|
23 | \* ======================================================================== */
|
---|
24 |
|
---|
25 | //////////////////////////////////////////////////////////////////////////////
|
---|
26 | // //
|
---|
27 | // MCalibrationCalc //
|
---|
28 | // //
|
---|
29 | // This is a task which calculates the number of photons from the FADC //
|
---|
30 | // time slices. At the moment it integrates simply the FADC values. //
|
---|
31 | // //
|
---|
32 | // Input Containers: //
|
---|
33 | // MRawEvtData //
|
---|
34 | // //
|
---|
35 | // Output Containers: //
|
---|
36 | // MCalibrationCam //
|
---|
37 | // //
|
---|
38 | // //
|
---|
39 | // The class MCalibrationCam hold one entry of type MCalibrationPix for //
|
---|
40 | // every pixel. It is filled in the following way: //
|
---|
41 | // PreParocess: MalibrationCam::InitSize(577) is called which allocates //
|
---|
42 | // memory in an TClonesArray of type MCalibrationPix and //
|
---|
43 | // all pointers to NULL. //
|
---|
44 | // //
|
---|
45 | // Process: The NULL pointer is tested on every pixel via //
|
---|
46 | // MalibrationCam::IsPixelUsed(npix). //
|
---|
47 | // //
|
---|
48 | // In case, IsPixelUsed returns NULL, //
|
---|
49 | // MalibrationCam::AddPixel(npix) is invoked which creates a //
|
---|
50 | // new MCalibrationPix(npix) in the npix's entry //
|
---|
51 | // of the TClonesArray. //
|
---|
52 | // //
|
---|
53 | // Every MCalibrationPix holds a histogram class, //
|
---|
54 | // MHCalibrationPixel which itself hold histograms of type: //
|
---|
55 | // HQ(npix) (distribution of summed FADC time slice entries) //
|
---|
56 | // HT(npix) (distribution of position of maximum) //
|
---|
57 | // HQvsN(npix) (distribution of charges vs. event number. //
|
---|
58 | // //
|
---|
59 | // PostProcess: All histograms HQ(npix) are fitted to a Gaussian //
|
---|
60 | // All histograms HT(npix) are fitted to a Gaussian //
|
---|
61 | // The histogram HBPQ (blind pixel) is fitted to a single //
|
---|
62 | // PhE fit //
|
---|
63 | // The histogram HBPT (blind pixel) is fitted to a Gaussian //
|
---|
64 | // The histograms of the PIN Diode are fitted to Gaussians //
|
---|
65 | // //
|
---|
66 | // Fits can be excluded via the commands: //
|
---|
67 | // MalibrationCam::SetSkipTFits() (skip all time fits) //
|
---|
68 | // MalibrationCam::SetSkipBPFits() (skip all blind pixel fits) //
|
---|
69 | // MalibrationCam::SetSkipPDFits() (skip all PIN Diode fits) //
|
---|
70 | // //
|
---|
71 | //////////////////////////////////////////////////////////////////////////////
|
---|
72 |
|
---|
73 | #include "MCalibrationCalc.h"
|
---|
74 | #include "MCalibrationConfig.h"
|
---|
75 | #include "MCalibrationFits.h"
|
---|
76 |
|
---|
77 | #include "MCalibrationCam.h"
|
---|
78 | #include "MCalibrationPix.h"
|
---|
79 | #include "MCalibrationBlindPix.h"
|
---|
80 | #include "MCalibrationPINDiode.h"
|
---|
81 |
|
---|
82 | #include "MPedestalCam.h"
|
---|
83 | #include "MPedestalPix.h"
|
---|
84 |
|
---|
85 | #include "MLog.h"
|
---|
86 | #include "MLogManip.h"
|
---|
87 |
|
---|
88 | #include "MParList.h"
|
---|
89 | #include "MH.h"
|
---|
90 |
|
---|
91 | #include "MRawRunHeader.h"
|
---|
92 | #include "MRawEvtData.h" // MRawEvtData::GetNumPixels
|
---|
93 | #include "MRawEvtPixelIter.h"
|
---|
94 |
|
---|
95 | #include "MTime.h"
|
---|
96 |
|
---|
97 | ClassImp(MCalibrationCalc);
|
---|
98 |
|
---|
99 | using namespace std;
|
---|
100 | // --------------------------------------------------------------------------
|
---|
101 | //
|
---|
102 | // Default constructor. b is the number of slices before the maximum slice,
|
---|
103 | // a the number of slices behind the maximum slice which is taken as signal.
|
---|
104 | //
|
---|
105 | MCalibrationCalc::MCalibrationCalc(const char *name, const char *title)
|
---|
106 | : fColor(kEBlue)
|
---|
107 | {
|
---|
108 |
|
---|
109 | fName = name ? name : "MCalibrationCalc";
|
---|
110 | fTitle = title ? title : "Task to calculate the calibration constants and MCalibrationCam ";
|
---|
111 |
|
---|
112 | AddToBranchList("MRawEvtData.fHiGainPixId");
|
---|
113 | AddToBranchList("MRawEvtData.fLoGainPixId");
|
---|
114 | AddToBranchList("MRawEvtData.fHiGainFadcSamples");
|
---|
115 | AddToBranchList("MRawEvtData.fLoGainFadcSamples");
|
---|
116 |
|
---|
117 | SETBIT(fFlags, kUseTFits);
|
---|
118 | SETBIT(fFlags, kUseBPFit);
|
---|
119 | SETBIT(fFlags, kUsePDFit);
|
---|
120 | }
|
---|
121 |
|
---|
122 | // --------------------------------------------------------------------------
|
---|
123 | //
|
---|
124 | // The PreProcess searches for the following input containers:
|
---|
125 | // - MRawEvtData
|
---|
126 | // - MPedestalCam
|
---|
127 | //
|
---|
128 | // The following output containers are also searched and created if
|
---|
129 | // they were not found:
|
---|
130 | //
|
---|
131 | // - MHCalibrationBlindPixel
|
---|
132 | // - MCalibrationCam
|
---|
133 | // - MTime
|
---|
134 | //
|
---|
135 | Int_t MCalibrationCalc::PreProcess(MParList *pList)
|
---|
136 | {
|
---|
137 |
|
---|
138 | fOverFlow = 0;
|
---|
139 | fNrEvents = 0;
|
---|
140 |
|
---|
141 | fRawEvt = (MRawEvtData*)pList->FindObject("MRawEvtData");
|
---|
142 | if (!fRawEvt)
|
---|
143 | {
|
---|
144 | *fLog << dbginf << "MRawEvtData not found... aborting." << endl;
|
---|
145 | return kFALSE;
|
---|
146 | }
|
---|
147 |
|
---|
148 | const MRawRunHeader *runheader = (MRawRunHeader*)pList->FindObject("MRawRunHeader");
|
---|
149 | if (!runheader)
|
---|
150 | *fLog << warn << dbginf << "Warning - cannot check file type, MRawRunHeader not found." << endl;
|
---|
151 | else
|
---|
152 | if (runheader->GetRunType() == kRTMonteCarlo)
|
---|
153 | {
|
---|
154 | return kTRUE;
|
---|
155 | }
|
---|
156 |
|
---|
157 | fCalibrations = (MCalibrationCam*)pList->FindCreateObj("MCalibrationCam");
|
---|
158 | if (!fCalibrations)
|
---|
159 | {
|
---|
160 | *fLog << err << dbginf << "MCalibrationCam could not be created ... aborting." << endl;
|
---|
161 | return kFALSE;
|
---|
162 | }
|
---|
163 |
|
---|
164 | //
|
---|
165 | // fRawEvt->GetNumPixels() does not work !!!!!!!!!!
|
---|
166 | //
|
---|
167 | fCalibrations->InitSize(577);
|
---|
168 |
|
---|
169 | switch (fColor)
|
---|
170 | {
|
---|
171 | case kEBlue:
|
---|
172 | fCalibrations->SetColor(MCalibrationCam::kECBlue);
|
---|
173 | break;
|
---|
174 | case kEGreen:
|
---|
175 | fCalibrations->SetColor(MCalibrationCam::kECGreen);
|
---|
176 | break;
|
---|
177 | case kEUV:
|
---|
178 | fCalibrations->SetColor(MCalibrationCam::kECUV);
|
---|
179 | }
|
---|
180 |
|
---|
181 |
|
---|
182 |
|
---|
183 | fPedestals = (MPedestalCam*)pList->FindObject("MPedestalCam");
|
---|
184 | if (!fPedestals)
|
---|
185 | {
|
---|
186 | *fLog << err << dbginf << "Cannot find MPedestalCam ... aborting" << endl;
|
---|
187 | return kFALSE;
|
---|
188 | }
|
---|
189 |
|
---|
190 |
|
---|
191 | // MTime does not work!!!!
|
---|
192 |
|
---|
193 | // fEvtTime = (MTime*)pList->FindObject("MRawEvtTime");
|
---|
194 | // if (!fEvtTime)
|
---|
195 | // {
|
---|
196 | // *fLog << dbginf << "MTime could not be created ... ¡!¡!¡!¡!" << endl;
|
---|
197 | // }
|
---|
198 |
|
---|
199 | // fEvtTime->SetTime(0.);
|
---|
200 |
|
---|
201 |
|
---|
202 | return kTRUE;
|
---|
203 | }
|
---|
204 |
|
---|
205 |
|
---|
206 | // --------------------------------------------------------------------------
|
---|
207 | //
|
---|
208 | // The ReInit searches for the following input containers:
|
---|
209 | // - MRawRunHeader
|
---|
210 | //
|
---|
211 | Bool_t MCalibrationCalc::ReInit(MParList *pList )
|
---|
212 | {
|
---|
213 |
|
---|
214 | fRunHeader = (MRawRunHeader*)pList->FindObject("MRawRunHeader");
|
---|
215 | if (!fRunHeader)
|
---|
216 | {
|
---|
217 | *fLog << dbginf << "MRawRunHeader not found... aborting." << endl;
|
---|
218 | return kFALSE;
|
---|
219 | }
|
---|
220 |
|
---|
221 | fNumHiGainSamples = fRunHeader->GetNumSamplesHiGain();
|
---|
222 | fNumLoGainSamples = fRunHeader->GetNumSamplesLoGain();
|
---|
223 |
|
---|
224 | return kTRUE;
|
---|
225 |
|
---|
226 | }
|
---|
227 |
|
---|
228 |
|
---|
229 | // --------------------------------------------------------------------------
|
---|
230 | //
|
---|
231 | // Calculate the integral of the FADC time slices and store them as a new
|
---|
232 | // pixel in the MCerPhotEvt container.
|
---|
233 | //
|
---|
234 | Int_t MCalibrationCalc::Process()
|
---|
235 | {
|
---|
236 |
|
---|
237 | fNrEvents++;
|
---|
238 |
|
---|
239 | MCalibrationBlindPix &blindpixel = *(fCalibrations->GetBlindPixel());
|
---|
240 | MCalibrationPINDiode &pindiode = *(fCalibrations->GetPINDiode());
|
---|
241 |
|
---|
242 | MRawEvtPixelIter pixel(fRawEvt);
|
---|
243 |
|
---|
244 | while (pixel.Next())
|
---|
245 | {
|
---|
246 |
|
---|
247 | UShort_t sat = 0;
|
---|
248 | const Int_t pixid = pixel.GetPixelId();
|
---|
249 |
|
---|
250 | if (!fCalibrations->IsPixelUsed(pixid))
|
---|
251 | if (!fCalibrations->AddPixel(pixid))
|
---|
252 | *fLog << err << dbginf << "MCalibrationPix(" << pixid << ") could not be created !!" << endl;
|
---|
253 |
|
---|
254 | Byte_t *ptr = pixel.GetHiGainSamples();
|
---|
255 | Byte_t mid = pixel.GetIdxMaxHiGainSample();
|
---|
256 | UInt_t max = pixel.GetMaxHiGainSample();
|
---|
257 |
|
---|
258 | Int_t sum = (max > gkSaturationLimit // overflow ?
|
---|
259 | ? sat++, pixel.GetSumLoGainSamples() // take Low Gain
|
---|
260 | : pixel.GetSumHiGainSamples()); // no overflow
|
---|
261 |
|
---|
262 | if (sat)
|
---|
263 | {
|
---|
264 |
|
---|
265 | ptr = pixel.GetLoGainSamples();
|
---|
266 | max = pixel.GetMaxLoGainSample();
|
---|
267 | mid = pixel.GetIdxMaxLoGainSample();
|
---|
268 |
|
---|
269 | sum = (max == gkSaturationLimit // overflow of LoGain ??? -> GimmeABreak!!!
|
---|
270 | ? fOverFlow++, gkLoGainOverFlow // OUCH (Florian was maybe right)
|
---|
271 | : sum*gkConversionHiLo ); // OUFF (Florian was wrong) !!
|
---|
272 |
|
---|
273 | // *fLog << warn << "Warning: Saturation of HiGain reached in slice " << (int)mid << " !!! " << endl;
|
---|
274 | // *fLog << warn << "Max = " << max << endl;
|
---|
275 |
|
---|
276 | if (fOverFlow)
|
---|
277 | *fLog << err << dbginf << "Warning: Saturation of LoGain reached! "
|
---|
278 | << err << dbginf << "sum = " << sum << endl;
|
---|
279 |
|
---|
280 | }
|
---|
281 |
|
---|
282 | //
|
---|
283 | // sanity check (old MC files sometimes have pixids>577)
|
---|
284 | //
|
---|
285 | if (fPedestals && !fPedestals->CheckBounds(pixid))
|
---|
286 | {
|
---|
287 | *fLog << inf << "Pixel ID larger than camera... skipping event." << endl;
|
---|
288 | return kCONTINUE;
|
---|
289 | }
|
---|
290 |
|
---|
291 | MPedestalPix &ped = (*fPedestals)[pixid];
|
---|
292 | MCalibrationPix &pix = (*fCalibrations)[pixid];
|
---|
293 |
|
---|
294 | Float_t pedes = ped.GetPedestal();
|
---|
295 |
|
---|
296 | //
|
---|
297 | // FIXME: This is preliminary, we will change to pedestals per slice!!!
|
---|
298 | // Assume pedestals per time slice ==> multiply with number of slices
|
---|
299 | //
|
---|
300 | pedes *= (sat ? fNumLoGainSamples : fNumHiGainSamples );
|
---|
301 |
|
---|
302 | Float_t rsum = (float)sum - pedes;
|
---|
303 |
|
---|
304 | switch(pixid)
|
---|
305 | {
|
---|
306 |
|
---|
307 | case gkCalibrationBlindPixelId:
|
---|
308 | if (!blindpixel.FillQ(sum))
|
---|
309 | *fLog << warn <<
|
---|
310 | "Overflow or Underflow occurred filling Blind Pixel means = " << sum << endl;
|
---|
311 | if (!blindpixel.FillT((int)mid))
|
---|
312 | *fLog << warn <<
|
---|
313 | "Overflow or Underflow occurred filling Blind Pixel time = " << (int)mid << endl;
|
---|
314 | if (!blindpixel.FillRQvsT(rsum,fNrEvents))
|
---|
315 | *fLog << warn <<
|
---|
316 | "Overflow or Underflow occurred filling Blind Pixel eventnr = " << fNrEvents << endl;
|
---|
317 |
|
---|
318 | case gkCalibrationPINDiodeId:
|
---|
319 | if (!pindiode.FillQ(sum))
|
---|
320 | *fLog << warn <<
|
---|
321 | "Overflow or Underflow occurred filling HQ: means = " << sum << endl;
|
---|
322 | if (!pindiode.FillT((int)mid))
|
---|
323 | *fLog << warn <<
|
---|
324 | "Overflow or Underflow occurred filling HT: time = " << (int)mid << endl;
|
---|
325 | if (!pindiode.FillRQvsT(rsum,fNrEvents))
|
---|
326 | *fLog << warn <<
|
---|
327 | "Overflow or Underflow occurred filling HQvsN: eventnr = " << fNrEvents << endl;
|
---|
328 |
|
---|
329 | default:
|
---|
330 |
|
---|
331 | if (!pix.FillQ(sum))
|
---|
332 | *fLog << warn << "Could not fill Q of pixel: " << pixid
|
---|
333 | << " signal = " << sum << endl;
|
---|
334 |
|
---|
335 | //
|
---|
336 | // Fill the reduced charge into the control histo for better visibility
|
---|
337 | //
|
---|
338 | if (!pix.FillRQvsT(rsum,fNrEvents))
|
---|
339 | *fLog << warn << "Could not fill red. Q vs. EvtNr of pixel: " << pixid
|
---|
340 | << " signal = " << rsum << " event Nr: " << fNrEvents << endl;
|
---|
341 |
|
---|
342 |
|
---|
343 | if (!pix.FillT((int)mid))
|
---|
344 | *fLog << warn << "Could not fill T of pixel: " << pixid << " time = " << (int)mid << endl;
|
---|
345 |
|
---|
346 |
|
---|
347 | } /* switch(pixid) */
|
---|
348 |
|
---|
349 | } /* while (pixel.Next()) */
|
---|
350 |
|
---|
351 | fCalibrations->SetReadyToSave();
|
---|
352 |
|
---|
353 | return kTRUE;
|
---|
354 | }
|
---|
355 |
|
---|
356 | Int_t MCalibrationCalc::PostProcess()
|
---|
357 | {
|
---|
358 |
|
---|
359 | *fLog << inf << endl;
|
---|
360 | *fLog << GetDescriptor() << " Cut Histogram Edges" << endl;
|
---|
361 | //
|
---|
362 | // Cut edges to make fits and viewing of the hists easier
|
---|
363 | //
|
---|
364 | fCalibrations->CutEdges();
|
---|
365 |
|
---|
366 | //
|
---|
367 | // Get pointer to blind pixel
|
---|
368 | //
|
---|
369 | MCalibrationBlindPix &blindpixel = *(fCalibrations->GetBlindPixel());
|
---|
370 |
|
---|
371 | *fLog << GetDescriptor() << " Fitting the Blind Pixel" << endl;
|
---|
372 |
|
---|
373 | //
|
---|
374 | // Fit the blind pixel
|
---|
375 | //
|
---|
376 | if (TESTBIT(fFlags,kUseBPFit))
|
---|
377 | {
|
---|
378 | if (!blindpixel.FitQ())
|
---|
379 | *fLog << err << dbginf << "Could not fit the blind pixel " << endl;
|
---|
380 |
|
---|
381 | if (!blindpixel.FitT())
|
---|
382 | *fLog << warn << "Could not the Times of the blind pixel " << endl;
|
---|
383 |
|
---|
384 | blindpixel.Draw();
|
---|
385 |
|
---|
386 | }
|
---|
387 |
|
---|
388 | *fLog << GetDescriptor() << " Fitting the Normal Pixels" << endl;
|
---|
389 | //
|
---|
390 | // loop over the pedestal events and check if we have calibration
|
---|
391 | //
|
---|
392 | for (Int_t pixid=0; pixid<fPedestals->GetSize(); pixid++)
|
---|
393 | {
|
---|
394 |
|
---|
395 | if (fCalibrations->IsPixelUsed(pixid))
|
---|
396 | {
|
---|
397 |
|
---|
398 | MCalibrationPix &pix = (*fCalibrations)[pixid];
|
---|
399 |
|
---|
400 |
|
---|
401 | if (TESTBIT(fFlags,kUseTFits))
|
---|
402 | pix.FitT();
|
---|
403 |
|
---|
404 | if (!pix.FitQ())
|
---|
405 | continue;
|
---|
406 |
|
---|
407 | const Float_t ped = (*fPedestals)[pixid].GetPedestal();
|
---|
408 | const Float_t prms = (*fPedestals)[pixid].GetPedestalRms();
|
---|
409 | pix.SetPedestal(ped,prms);
|
---|
410 | }
|
---|
411 | }
|
---|
412 |
|
---|
413 | fCalibrations->SetReadyToSave();
|
---|
414 |
|
---|
415 | if (GetNumExecutions()==0 || fOverFlow==0)
|
---|
416 | return kTRUE;
|
---|
417 |
|
---|
418 | *fLog << inf << endl;
|
---|
419 | *fLog << GetDescriptor() << " execution statistics:" << endl;
|
---|
420 | *fLog << dec << setfill(' ');
|
---|
421 | *fLog << " " << setw(7) << fOverFlow << " (" << setw(3) << (int)(fOverFlow*100/GetNumExecutions()) << "%) Evts skipped due to: lo gain saturated." << endl;
|
---|
422 |
|
---|
423 | return kTRUE;
|
---|
424 | }
|
---|