source: trunk/MagicSoft/Mars/mcalib/MCalibrationCalc.cc@ 2777

Last change on this file since 2777 was 2766, checked in by gaug, 21 years ago
*** empty log message ***
File size: 16.0 KB
Line 
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
103ClassImp(MCalibrationCalc);
104
105using namespace std;
106// --------------------------------------------------------------------------
107//
108// Default constructor.
109//
110MCalibrationCalc::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//
141Int_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//
214Bool_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
242 MCalibrationPix &pix = (*fCalibrations)[i];
243 pix.DefinePixId(i);
244 MHCalibrationPixel *hist = pix.GetHist();
245
246 hist->SetTimeFitRangesHiGain(fSignals->GetFirstUsedSliceHiGain(),
247 fSignals->GetLastUsedSliceHiGain());
248 hist->SetTimeFitRangesLoGain(fSignals->GetFirstUsedSliceLoGain(),
249 fSignals->GetLastUsedSliceLoGain());
250
251 }
252
253 return kTRUE;
254
255}
256
257
258// --------------------------------------------------------------------------
259//
260// Calculate the integral of the FADC time slices and store them as a new
261// pixel in the MCerPhotEvt container.
262//
263Int_t MCalibrationCalc::Process()
264{
265
266 Int_t cosmicpix = 0;
267
268 MCalibrationBlindPix &blindpixel = *(fCalibrations->GetBlindPixel());
269 MCalibrationPINDiode &pindiode = *(fCalibrations->GetPINDiode());
270
271 MRawEvtPixelIter pixel(fRawEvt);
272
273 //
274 // Create a first loop to sort out the cosmics ...
275 //
276 // This is a very primitive check for the number of cosmicpixs
277 // The cut will be applied in the fit, but for the blind pixel,
278 // we need to remove this event
279 //
280 // FIXME: In the future need a much more sophisticated one!!!
281 //
282
283 while (pixel.Next())
284 {
285
286 const UInt_t pixid = pixel.GetPixelId();
287
288 MExtractedSignalPix &sig = (*fSignals)[pixid];
289 MPedestalPix &ped = (*fPedestals)[pixid];
290 Float_t pedrms = ped.GetPedestalRms()*fSqrtHiGainSamples;
291 Float_t sumhi = sig.GetExtractedSignalHiGain();
292
293 //
294 // We consider a pixel as presumably due to cosmics
295 // if its sum of FADC slices is lower than 3 pedestal RMS
296 //
297 if (sumhi < 3.*pedrms )
298 cosmicpix++;
299 }
300
301 //
302 // If the camera contains more than 230
303 // (this is the number of outer pixels plus about 50 inner ones)
304 // presumed pixels due to cosmics, then the event is discarted.
305 // This procedure is more or less equivalent to keeping only events
306 // with at least 350 pixels with high signals.
307 //
308 if (cosmicpix > 230.)
309 {
310 fCosmics++;
311 return kCONTINUE;
312 }
313
314 pixel.Reset();
315 fEvents++;
316
317 //
318 // Create a second loop to do fill the calibration histograms
319 //
320
321 while (pixel.Next())
322 {
323
324 const UInt_t pixid = pixel.GetPixelId();
325
326 MExtractedSignalPix &sig = (*fSignals)[pixid];
327
328 Float_t sumhi = sig.GetExtractedSignalHiGain();
329 Float_t sumlo = sig.GetExtractedSignalLoGain();
330 Float_t mtime = sig.GetMeanArrivalTime();
331
332 MCalibrationPix &pix = (*fCalibrations)[pixid];
333
334 switch(pixid)
335 {
336
337 case gkCalibrationBlindPixelId:
338
339 if (!blindpixel.FillCharge(sumhi))
340 *fLog << err <<
341 "Overflow or Underflow occurred filling Blind Pixel sum = " << sumhi << endl;
342
343 if (!blindpixel.FillTime((int)mtime))
344 *fLog << err <<
345 "Overflow or Underflow occurred filling Blind Pixel time = " << mtime << endl;
346
347 if (!blindpixel.FillRChargevsTime(sumhi,fEvents))
348 *fLog << warn <<
349 "Overflow or Underflow occurred filling Blind Pixel eventnr = " << fEvents << endl;
350
351 case gkCalibrationPINDiodeId:
352 if (!pindiode.FillCharge(sumhi))
353 *fLog << warn <<
354 "Overflow or Underflow occurred filling HCharge: means = " << sumhi << endl;
355 if (!pindiode.FillTime((int)mtime))
356 *fLog << warn <<
357 "Overflow or Underflow occurred filling HTime: time = " << mtime << endl;
358 if (!pindiode.FillRChargevsTime(sumhi,fEvents))
359 *fLog << warn <<
360 "Overflow or Underflow occurred filling HChargevsN: eventnr = " << fEvents << endl;
361 break;
362
363 default:
364
365 pix.SetChargesInGraph(sumhi,sumlo);
366
367 if (!pix.FillRChargevsTimeLoGain(sumlo,fEvents))
368 *fLog << warn << "Could not fill Lo Gain Charge vs. EvtNr of pixel: "
369 << pixid << " signal = " << sumlo << " event Nr: " << fEvents << endl;
370
371 if (!pix.FillRChargevsTimeHiGain(sumhi,fEvents))
372 *fLog << warn << "Could not fill Hi Gain Charge vs. EvtNr of pixel: "
373 << pixid << " signal = " << sumhi << " event Nr: " << fEvents << endl;
374
375 if (sig.IsLoGainUsed())
376 {
377
378 if (!pix.FillChargeLoGain(sumlo))
379 *fLog << warn << "Could not fill Lo Gain Charge of pixel: " << pixid
380 << " signal = " << sumlo << endl;
381
382 if (!pix.FillTimeLoGain((int)mtime))
383 *fLog << warn << "Could not fill Lo Gain Time of pixel: "
384 << pixid << " time = " << mtime << endl;
385
386 }
387 else
388 {
389 if (!pix.FillChargeHiGain(sumhi))
390 *fLog << warn << "Could not fill Hi Gain Charge of pixel: " << pixid
391 << " signal = " << sumhi << endl;
392
393 if (!pix.FillTimeHiGain((int)mtime))
394 *fLog << warn << "Could not fill Hi Gain Time of pixel: "
395 << pixid << " time = " << mtime << endl;
396
397 }
398 break;
399
400 } /* switch(pixid) */
401
402 } /* while (pixel.Next()) */
403
404 return kTRUE;
405}
406
407Int_t MCalibrationCalc::PostProcess()
408{
409
410
411 *fLog << inf << endl;
412
413 if (fEvents == 0)
414 {
415
416 *fLog << err << GetDescriptor()
417 << ": This run contains only cosmics or pedestals, "
418 << "cannot find events with more than 350 illuminated pixels. " << endl;
419 return kFALSE;
420 }
421
422 if (fEvents < fCosmics)
423 *fLog << warn << GetDescriptor()
424 << ": WARNING: Run contains more cosmics or pedestals than calibration events " << endl;
425
426
427 *fLog << GetDescriptor() << " Cut Histogram Edges" << endl;
428
429 //
430 // Cut edges to make fits and viewing of the hists easier
431 //
432 fCalibrations->CutEdges();
433
434 //
435 // Get pointer to blind pixel
436 //
437 MCalibrationBlindPix &blindpixel = *(fCalibrations->GetBlindPixel());
438
439 *fLog << GetDescriptor() << " Fitting the Blind Pixel" << endl;
440
441 //
442 // Fit the blind pixel
443 //
444 if (TESTBIT(fFlags,kUseBlindPixelFit))
445 {
446
447 if (!blindpixel.FitCharge())
448 *fLog << err << dbginf << "Could not fit the blind pixel " << endl;
449
450 blindpixel.Draw();
451 }
452
453 *fLog << GetDescriptor() << " Fitting the Normal Pixels" << endl;
454
455 //
456 // loop over the pedestal events and check if we have calibration
457 //
458 for (Int_t pixid=0; pixid<fPedestals->GetSize(); pixid++)
459 {
460
461 MCalibrationPix &pix = (*fCalibrations)[pixid];
462
463 //
464 // get the pedestals
465 //
466 const Float_t ped = (*fPedestals)[pixid].GetPedestal() * fNumHiGainSamples;
467 const Float_t prms = (*fPedestals)[pixid].GetPedestalRms() * fSqrtHiGainSamples;
468
469 //
470 // set them in the calibration camera
471 //
472 pix.SetPedestal(ped,prms);
473
474 //
475 // perform the Gauss fits to the charges
476 //
477 pix.FitCharge();
478
479 //
480 // Perform the Gauss fits to the arrival times
481 //
482 if (TESTBIT(fFlags,kUseTimeFits))
483 pix.FitTime();
484
485 }
486
487 if (!fCalibrations->CalcNumPhotInsidePlexiglass())
488 *fLog << err << dbginf << "Could not calculate the number of photons from the blind pixel " << endl;
489
490 fCalibrations->SetReadyToSave();
491
492 if (GetNumExecutions()==0)
493 return kTRUE;
494
495 *fLog << endl;
496 *fLog << dec << setfill(' ') << fCosmics << " Events presumably cosmics" << endl;
497
498 return kTRUE;
499}
Note: See TracBrowser for help on using the repository browser.