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 | // HCharge(npix) (distribution of summed FADC time slice entries)
|
---|
56 | // HTime(npix) (distribution of position of maximum)
|
---|
57 | // HChargevsN(npix) (distribution of charges vs. event number.
|
---|
58 | //
|
---|
59 | // PostProcess: All histograms HCharge(npix) are fitted to a Gaussian
|
---|
60 | // All histograms HTime(npix) are fitted to a Gaussian
|
---|
61 | // The histogram HBlindPixelCharge (blind pixel) is fitted to a single
|
---|
62 | // PhE fit
|
---|
63 | // The histogram HBlindPixelTime (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::SetSkipTimeFits() (skip all time fits)
|
---|
68 | // MalibrationCam::SetSkipBlindPixelFits() (skip all blind pixel fits)
|
---|
69 | // MalibrationCam::SetSkipPinDiodeFits() (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 "MGeomCam.h"
|
---|
86 |
|
---|
87 | #include "MLog.h"
|
---|
88 | #include "MLogManip.h"
|
---|
89 |
|
---|
90 | #include "MParList.h"
|
---|
91 | #include "MH.h"
|
---|
92 |
|
---|
93 | #include "MRawRunHeader.h"
|
---|
94 | #include "MRawEvtData.h"
|
---|
95 | #include "MRawEvtPixelIter.h"
|
---|
96 |
|
---|
97 | #include "MExtractedSignalCam.h"
|
---|
98 | #include "MExtractedSignalPix.h"
|
---|
99 |
|
---|
100 | #include "MTime.h"
|
---|
101 | #include "TMath.h"
|
---|
102 |
|
---|
103 | ClassImp(MCalibrationCalc);
|
---|
104 |
|
---|
105 | using namespace std;
|
---|
106 | // --------------------------------------------------------------------------
|
---|
107 | //
|
---|
108 | // Default constructor.
|
---|
109 | //
|
---|
110 | MCalibrationCalc::MCalibrationCalc(const char *name, const char *title)
|
---|
111 | : fColor(kEBlue)
|
---|
112 | {
|
---|
113 |
|
---|
114 | fName = name ? name : "MCalibrationCalc";
|
---|
115 | fTitle = title ? title : "Task to calculate the calibration constants and MCalibrationCam ";
|
---|
116 |
|
---|
117 | AddToBranchList("MRawEvtData.fHiGainPixId");
|
---|
118 | AddToBranchList("MRawEvtData.fLoGainPixId");
|
---|
119 | AddToBranchList("MRawEvtData.fHiGainFadcSamples");
|
---|
120 | AddToBranchList("MRawEvtData.fLoGainFadcSamples");
|
---|
121 |
|
---|
122 | SETBIT(fFlags, kUseTimeFits);
|
---|
123 | SETBIT(fFlags, kUseBlindPixelFit);
|
---|
124 | SETBIT(fFlags, kUsePinDiodeFit);
|
---|
125 |
|
---|
126 | }
|
---|
127 |
|
---|
128 | // --------------------------------------------------------------------------
|
---|
129 | //
|
---|
130 | // The PreProcess searches for the following input containers:
|
---|
131 | // - MRawEvtData
|
---|
132 | // - MPedestalCam
|
---|
133 | //
|
---|
134 | // The following output containers are also searched and created if
|
---|
135 | // they were not found:
|
---|
136 | //
|
---|
137 | // - MHCalibrationBlindPixel
|
---|
138 | // - MCalibrationCam
|
---|
139 | // - MTime
|
---|
140 | //
|
---|
141 | Int_t MCalibrationCalc::PreProcess(MParList *pList)
|
---|
142 | {
|
---|
143 |
|
---|
144 | fHistOverFlow = 0;
|
---|
145 | fEvents = 0;
|
---|
146 | fCosmics = 0;
|
---|
147 |
|
---|
148 | fRawEvt = (MRawEvtData*)pList->FindObject("MRawEvtData");
|
---|
149 | if (!fRawEvt)
|
---|
150 | {
|
---|
151 | *fLog << dbginf << "MRawEvtData not found... aborting." << endl;
|
---|
152 | return kFALSE;
|
---|
153 | }
|
---|
154 |
|
---|
155 | const MRawRunHeader *runheader = (MRawRunHeader*)pList->FindObject("MRawRunHeader");
|
---|
156 | if (!runheader)
|
---|
157 | *fLog << warn << dbginf << "Warning - cannot check file type, MRawRunHeader not found." << endl;
|
---|
158 | else
|
---|
159 | if (runheader->GetRunType() == kRTMonteCarlo)
|
---|
160 | {
|
---|
161 | return kTRUE;
|
---|
162 | }
|
---|
163 |
|
---|
164 | fCalibrations = (MCalibrationCam*)pList->FindCreateObj("MCalibrationCam");
|
---|
165 | if (!fCalibrations)
|
---|
166 | {
|
---|
167 | *fLog << err << dbginf << "MCalibrationCam could not be created ... aborting." << endl;
|
---|
168 | return kFALSE;
|
---|
169 | }
|
---|
170 |
|
---|
171 |
|
---|
172 | switch (fColor)
|
---|
173 | {
|
---|
174 | case kEBlue:
|
---|
175 | fCalibrations->SetColor(MCalibrationCam::kECBlue);
|
---|
176 | break;
|
---|
177 | case kEGreen:
|
---|
178 | fCalibrations->SetColor(MCalibrationCam::kECGreen);
|
---|
179 | break;
|
---|
180 | case kEUV:
|
---|
181 | fCalibrations->SetColor(MCalibrationCam::kECUV);
|
---|
182 | break;
|
---|
183 | case kECT1:
|
---|
184 | fCalibrations->SetColor(MCalibrationCam::kECCT1);
|
---|
185 | break;
|
---|
186 | default:
|
---|
187 | fCalibrations->SetColor(MCalibrationCam::kECCT1);
|
---|
188 | }
|
---|
189 |
|
---|
190 | fPedestals = (MPedestalCam*)pList->FindObject("MPedestalCam");
|
---|
191 | if (!fPedestals)
|
---|
192 | {
|
---|
193 | *fLog << err << dbginf << "Cannot find MPedestalCam ... aborting" << endl;
|
---|
194 | return kFALSE;
|
---|
195 | }
|
---|
196 |
|
---|
197 |
|
---|
198 | fSignals = (MExtractedSignalCam*)pList->FindObject("MExtractedSignalCam");
|
---|
199 | if (!fSignals)
|
---|
200 | {
|
---|
201 | *fLog << err << dbginf << "Cannot find MExtractedSignalCam ... aborting" << endl;
|
---|
202 | return kFALSE;
|
---|
203 | }
|
---|
204 |
|
---|
205 | return kTRUE;
|
---|
206 | }
|
---|
207 |
|
---|
208 |
|
---|
209 | // --------------------------------------------------------------------------
|
---|
210 | //
|
---|
211 | // The ReInit searches for the following input containers:
|
---|
212 | // - MRawRunHeader
|
---|
213 | //
|
---|
214 | Bool_t MCalibrationCalc::ReInit(MParList *pList )
|
---|
215 | {
|
---|
216 |
|
---|
217 | fRunHeader = (MRawRunHeader*)pList->FindObject("MRawRunHeader");
|
---|
218 | if (!fRunHeader)
|
---|
219 | {
|
---|
220 | *fLog << dbginf << "MRawRunHeader not found... aborting." << endl;
|
---|
221 | return kFALSE;
|
---|
222 | }
|
---|
223 |
|
---|
224 |
|
---|
225 | MGeomCam *cam = (MGeomCam*)pList->FindObject("MGeomCam");
|
---|
226 | if (!cam)
|
---|
227 | {
|
---|
228 | *fLog << err << GetDescriptor() << ": No MGeomCam found... aborting." << endl;
|
---|
229 | return kFALSE;
|
---|
230 | }
|
---|
231 |
|
---|
232 |
|
---|
233 | fNumHiGainSamples = fSignals->GetNumUsedHiGainFADCSlices();
|
---|
234 | fNumLoGainSamples = fSignals->GetNumUsedLoGainFADCSlices();
|
---|
235 | fSqrtHiGainSamples = TMath::Sqrt((Float_t)fNumHiGainSamples);
|
---|
236 |
|
---|
237 | fCalibrations->InitSize(cam->GetNumPixels());
|
---|
238 |
|
---|
239 | for (UInt_t i=0;i<cam->GetNumPixels();i++)
|
---|
240 | {
|
---|
241 | MCalibrationPix &pix = (*fCalibrations)[i];
|
---|
242 | pix.DefinePixId(i);
|
---|
243 | }
|
---|
244 |
|
---|
245 | return kTRUE;
|
---|
246 |
|
---|
247 | }
|
---|
248 |
|
---|
249 |
|
---|
250 | // --------------------------------------------------------------------------
|
---|
251 | //
|
---|
252 | // Calculate the integral of the FADC time slices and store them as a new
|
---|
253 | // pixel in the MCerPhotEvt container.
|
---|
254 | //
|
---|
255 | Int_t MCalibrationCalc::Process()
|
---|
256 | {
|
---|
257 |
|
---|
258 | Int_t cosmicpix = 0;
|
---|
259 |
|
---|
260 | MCalibrationBlindPix &blindpixel = *(fCalibrations->GetBlindPixel());
|
---|
261 | MCalibrationPINDiode &pindiode = *(fCalibrations->GetPINDiode());
|
---|
262 |
|
---|
263 | MRawEvtPixelIter pixel(fRawEvt);
|
---|
264 |
|
---|
265 | //
|
---|
266 | // Create a first loop to sort out the cosmics ...
|
---|
267 | //
|
---|
268 | // This is a very primitive check for the number of cosmicpixs
|
---|
269 | // The cut will be applied in the fit, but for the blind pixel,
|
---|
270 | // we need to remove this event
|
---|
271 | //
|
---|
272 | // FIXME: In the future need a much more sophisticated one!!!
|
---|
273 | //
|
---|
274 |
|
---|
275 | while (pixel.Next())
|
---|
276 | {
|
---|
277 |
|
---|
278 | const UInt_t pixid = pixel.GetPixelId();
|
---|
279 |
|
---|
280 | MExtractedSignalPix &sig = (*fSignals)[pixid];
|
---|
281 | MPedestalPix &ped = (*fPedestals)[pixid];
|
---|
282 | Float_t pedrms = ped.GetPedestalRms()*fSqrtHiGainSamples;
|
---|
283 | Float_t sumhi = sig.GetExtractedSignalHiGain();
|
---|
284 |
|
---|
285 | //
|
---|
286 | // We consider a pixel as presumably due to cosmics
|
---|
287 | // if its sum of FADC slices is lower than 3 pedestal RMS
|
---|
288 | //
|
---|
289 | if (sumhi < 3.*pedrms )
|
---|
290 | cosmicpix++;
|
---|
291 | }
|
---|
292 |
|
---|
293 | //
|
---|
294 | // If the camera contains more than 230
|
---|
295 | // (this is the number of outer pixels plus about 50 inner ones)
|
---|
296 | // presumed pixels due to cosmics, then the event is discarted.
|
---|
297 | // This procedure is more or less equivalent to keeping only events
|
---|
298 | // with at least 350 pixels with high signals.
|
---|
299 | //
|
---|
300 | if (cosmicpix > 230.)
|
---|
301 | {
|
---|
302 | fCosmics++;
|
---|
303 | return kCONTINUE;
|
---|
304 | }
|
---|
305 |
|
---|
306 | pixel.Reset();
|
---|
307 | fEvents++;
|
---|
308 |
|
---|
309 | //
|
---|
310 | // Create a second loop to do fill the calibration histograms
|
---|
311 | //
|
---|
312 |
|
---|
313 | while (pixel.Next())
|
---|
314 | {
|
---|
315 |
|
---|
316 | const UInt_t pixid = pixel.GetPixelId();
|
---|
317 |
|
---|
318 | MExtractedSignalPix &sig = (*fSignals)[pixid];
|
---|
319 |
|
---|
320 | Float_t sumhi = sig.GetExtractedSignalHiGain();
|
---|
321 | Float_t sumlo = sig.GetExtractedSignalLoGain();
|
---|
322 | Float_t mtime = sig.GetMeanArrivalTime();
|
---|
323 |
|
---|
324 | MCalibrationPix &pix = (*fCalibrations)[pixid];
|
---|
325 |
|
---|
326 | switch(pixid)
|
---|
327 | {
|
---|
328 |
|
---|
329 | case gkCalibrationBlindPixelId:
|
---|
330 |
|
---|
331 | if (!blindpixel.FillCharge(sumhi))
|
---|
332 | *fLog << err <<
|
---|
333 | "Overflow or Underflow occurred filling Blind Pixel sum = " << sumhi << endl;
|
---|
334 |
|
---|
335 | if (!blindpixel.FillTime((int)mtime))
|
---|
336 | *fLog << err <<
|
---|
337 | "Overflow or Underflow occurred filling Blind Pixel time = " << mtime << endl;
|
---|
338 |
|
---|
339 | if (!blindpixel.FillRChargevsTime(sumhi,fEvents))
|
---|
340 | *fLog << warn <<
|
---|
341 | "Overflow or Underflow occurred filling Blind Pixel eventnr = " << fEvents << endl;
|
---|
342 |
|
---|
343 | case gkCalibrationPINDiodeId:
|
---|
344 | if (!pindiode.FillCharge(sumhi))
|
---|
345 | *fLog << warn <<
|
---|
346 | "Overflow or Underflow occurred filling HCharge: means = " << sumhi << endl;
|
---|
347 | if (!pindiode.FillTime((int)mtime))
|
---|
348 | *fLog << warn <<
|
---|
349 | "Overflow or Underflow occurred filling HTime: time = " << mtime << endl;
|
---|
350 | if (!pindiode.FillRChargevsTime(sumhi,fEvents))
|
---|
351 | *fLog << warn <<
|
---|
352 | "Overflow or Underflow occurred filling HChargevsN: eventnr = " << fEvents << endl;
|
---|
353 | break;
|
---|
354 |
|
---|
355 | default:
|
---|
356 |
|
---|
357 | pix.SetChargesInGraph(sumhi,sumlo);
|
---|
358 |
|
---|
359 | if (!pix.FillRChargevsTimeLoGain(sumlo,fEvents))
|
---|
360 | *fLog << warn << "Could not fill Lo Gain Charge vs. EvtNr of pixel: "
|
---|
361 | << pixid << " signal = " << sumlo << " event Nr: " << fEvents << endl;
|
---|
362 |
|
---|
363 | if (!pix.FillRChargevsTimeHiGain(sumhi,fEvents))
|
---|
364 | *fLog << warn << "Could not fill Hi Gain Charge vs. EvtNr of pixel: "
|
---|
365 | << pixid << " signal = " << sumhi << " event Nr: " << fEvents << endl;
|
---|
366 |
|
---|
367 | if (sig.IsLoGainUsed())
|
---|
368 | {
|
---|
369 |
|
---|
370 | if (!pix.FillChargeLoGain(sumlo))
|
---|
371 | *fLog << warn << "Could not fill Lo Gain Charge of pixel: " << pixid
|
---|
372 | << " signal = " << sumlo << endl;
|
---|
373 |
|
---|
374 | if (!pix.FillTimeLoGain((int)mtime))
|
---|
375 | *fLog << warn << "Could not fill Lo Gain Time of pixel: "
|
---|
376 | << pixid << " time = " << mtime << endl;
|
---|
377 |
|
---|
378 | }
|
---|
379 | else
|
---|
380 | {
|
---|
381 | if (!pix.FillChargeHiGain(sumhi))
|
---|
382 | *fLog << warn << "Could not fill Hi Gain Charge of pixel: " << pixid
|
---|
383 | << " signal = " << sumhi << endl;
|
---|
384 |
|
---|
385 | if (!pix.FillTimeHiGain((int)mtime))
|
---|
386 | *fLog << warn << "Could not fill Hi Gain Time of pixel: "
|
---|
387 | << pixid << " time = " << mtime << endl;
|
---|
388 |
|
---|
389 | }
|
---|
390 | break;
|
---|
391 |
|
---|
392 | } /* switch(pixid) */
|
---|
393 |
|
---|
394 | } /* while (pixel.Next()) */
|
---|
395 |
|
---|
396 | return kTRUE;
|
---|
397 | }
|
---|
398 |
|
---|
399 | Int_t MCalibrationCalc::PostProcess()
|
---|
400 | {
|
---|
401 |
|
---|
402 |
|
---|
403 | *fLog << inf << endl;
|
---|
404 |
|
---|
405 | if (fEvents == 0)
|
---|
406 | {
|
---|
407 |
|
---|
408 | *fLog << err << GetDescriptor()
|
---|
409 | << ": This run contains only cosmics or pedestals, "
|
---|
410 | << "cannot find events with more than 350 illuminated pixels. " << endl;
|
---|
411 | return kFALSE;
|
---|
412 | }
|
---|
413 |
|
---|
414 | if (fEvents < fCosmics)
|
---|
415 | *fLog << warn << GetDescriptor()
|
---|
416 | << ": WARNING: Run contains more cosmics or pedestals than calibration events " << endl;
|
---|
417 |
|
---|
418 |
|
---|
419 | *fLog << GetDescriptor() << " Cut Histogram Edges" << endl;
|
---|
420 |
|
---|
421 | //
|
---|
422 | // Cut edges to make fits and viewing of the hists easier
|
---|
423 | //
|
---|
424 | fCalibrations->CutEdges();
|
---|
425 |
|
---|
426 | //
|
---|
427 | // Get pointer to blind pixel
|
---|
428 | //
|
---|
429 | MCalibrationBlindPix &blindpixel = *(fCalibrations->GetBlindPixel());
|
---|
430 |
|
---|
431 | *fLog << GetDescriptor() << " Fitting the Blind Pixel" << endl;
|
---|
432 |
|
---|
433 | //
|
---|
434 | // Fit the blind pixel
|
---|
435 | //
|
---|
436 | if (TESTBIT(fFlags,kUseBlindPixelFit))
|
---|
437 | {
|
---|
438 |
|
---|
439 | if (!blindpixel.FitCharge())
|
---|
440 | *fLog << err << dbginf << "Could not fit the blind pixel " << endl;
|
---|
441 |
|
---|
442 | blindpixel.Draw();
|
---|
443 | }
|
---|
444 |
|
---|
445 | *fLog << GetDescriptor() << " Fitting the Normal Pixels" << endl;
|
---|
446 |
|
---|
447 | //
|
---|
448 | // loop over the pedestal events and check if we have calibration
|
---|
449 | //
|
---|
450 | for (Int_t pixid=0; pixid<fPedestals->GetSize(); pixid++)
|
---|
451 | {
|
---|
452 |
|
---|
453 | MCalibrationPix &pix = (*fCalibrations)[pixid];
|
---|
454 |
|
---|
455 | const Float_t ped = (*fPedestals)[pixid].GetPedestal() * fNumHiGainSamples;
|
---|
456 | const Float_t prms = (*fPedestals)[pixid].GetPedestalRms() * TMath::Sqrt((float)fNumHiGainSamples);
|
---|
457 |
|
---|
458 | pix.SetPedestal(ped,prms);
|
---|
459 |
|
---|
460 | pix.FitCharge();
|
---|
461 |
|
---|
462 | if (TESTBIT(fFlags,kUseTimeFits))
|
---|
463 | pix.FitTime();
|
---|
464 |
|
---|
465 | }
|
---|
466 |
|
---|
467 | if (!fCalibrations->CalcNumPhotInsidePlexiglass())
|
---|
468 | *fLog << err << dbginf << "Could not calculate the number of photons from the blind pixel " << endl;
|
---|
469 |
|
---|
470 | fCalibrations->SetReadyToSave();
|
---|
471 |
|
---|
472 | if (GetNumExecutions()==0)
|
---|
473 | return kTRUE;
|
---|
474 |
|
---|
475 | *fLog << endl;
|
---|
476 | *fLog << dec << setfill(' ') << fCosmics << " Events presumably cosmics" << endl;
|
---|
477 |
|
---|
478 | return kTRUE;
|
---|
479 | }
|
---|