source: trunk/MagicSoft/Mars/manalysis/MCalibrationCalc.cc@ 2635

Last change on this file since 2635 was 2634, checked in by gaug, 22 years ago
*** empty log message ***
File size: 14.7 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 "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 "MExtractedSignalCam.h"
96#include "MExtractedSignalPix.h"
97
98#include "MTime.h"
99#include "TMath.h"
100
101ClassImp(MCalibrationCalc);
102
103using namespace std;
104// --------------------------------------------------------------------------
105//
106// Default constructor. b is the number of slices before the maximum slice,
107// a the number of slices behind the maximum slice which is taken as signal.
108//
109MCalibrationCalc::MCalibrationCalc(const char *name, const char *title)
110 : fColor(kEBlue)
111{
112
113 fName = name ? name : "MCalibrationCalc";
114 fTitle = title ? title : "Task to calculate the calibration constants and MCalibrationCam ";
115
116 AddToBranchList("MRawEvtData.fHiGainPixId");
117 AddToBranchList("MRawEvtData.fLoGainPixId");
118 AddToBranchList("MRawEvtData.fHiGainFadcSamples");
119 AddToBranchList("MRawEvtData.fLoGainFadcSamples");
120
121 SETBIT(fFlags, kUseTimeFits);
122 SETBIT(fFlags, kUseBlindPixelFit);
123 SETBIT(fFlags, kUsePinDiodeFit);
124}
125
126// --------------------------------------------------------------------------
127//
128// The PreProcess searches for the following input containers:
129// - MRawEvtData
130// - MPedestalCam
131//
132// The following output containers are also searched and created if
133// they were not found:
134//
135// - MHCalibrationBlindPixel
136// - MCalibrationCam
137// - MTime
138//
139Int_t MCalibrationCalc::PreProcess(MParList *pList)
140{
141
142 fHistOverFlow = 0;
143 fEvents = 0;
144 fCosmics = 0;
145
146 fRawEvt = (MRawEvtData*)pList->FindObject("MRawEvtData");
147 if (!fRawEvt)
148 {
149 *fLog << dbginf << "MRawEvtData not found... aborting." << endl;
150 return kFALSE;
151 }
152
153 const MRawRunHeader *runheader = (MRawRunHeader*)pList->FindObject("MRawRunHeader");
154 if (!runheader)
155 *fLog << warn << dbginf << "Warning - cannot check file type, MRawRunHeader not found." << endl;
156 else
157 if (runheader->GetRunType() == kRTMonteCarlo)
158 {
159 return kTRUE;
160 }
161
162 fCalibrations = (MCalibrationCam*)pList->FindCreateObj("MCalibrationCam");
163 if (!fCalibrations)
164 {
165 *fLog << err << dbginf << "MCalibrationCam could not be created ... aborting." << endl;
166 return kFALSE;
167 }
168
169
170 switch (fColor)
171 {
172 case kEBlue:
173 fCalibrations->SetColor(MCalibrationCam::kECBlue);
174 break;
175 case kEGreen:
176 fCalibrations->SetColor(MCalibrationCam::kECGreen);
177 break;
178 case kEUV:
179 fCalibrations->SetColor(MCalibrationCam::kECUV);
180 break;
181 case kECT1:
182 fCalibrations->SetColor(MCalibrationCam::kECCT1);
183 break;
184 default:
185 fCalibrations->SetColor(MCalibrationCam::kECCT1);
186 }
187
188 fPedestals = (MPedestalCam*)pList->FindObject("MPedestalCam");
189 if (!fPedestals)
190 {
191 *fLog << err << dbginf << "Cannot find MPedestalCam ... aborting" << endl;
192 return kFALSE;
193 }
194
195
196 fSignals = (MExtractedSignalCam*)pList->FindObject("MExtractedSignalCam");
197 if (!fSignals)
198 {
199 *fLog << err << dbginf << "Cannot find MExtractedSignalCam ... aborting" << endl;
200 return kFALSE;
201 }
202
203 return kTRUE;
204}
205
206
207// --------------------------------------------------------------------------
208//
209// The ReInit searches for the following input containers:
210// - MRawRunHeader
211//
212Bool_t MCalibrationCalc::ReInit(MParList *pList )
213{
214
215 fRunHeader = (MRawRunHeader*)pList->FindObject("MRawRunHeader");
216 if (!fRunHeader)
217 {
218 *fLog << dbginf << "MRawRunHeader not found... aborting." << endl;
219 return kFALSE;
220 }
221
222 fNumHiGainSamples = fRunHeader->GetNumSamplesHiGain();
223 fNumLoGainSamples = fRunHeader->GetNumSamplesLoGain();
224
225 //
226 // FIXME: The next statement simply does not work:
227 // fRawEvt->GetNumPixels() returns always 0
228 // fCalibrations->InitSize(fRawEvt->GetNumPixels());
229 //
230
231 fCalibrations->InitSize(577);
232
233 for (Int_t i=0;i<577;i++)
234 {
235 MCalibrationPix &pix = (*fCalibrations)[i];
236 pix.DefinePixId(i);
237 }
238
239 return kTRUE;
240
241}
242
243
244// --------------------------------------------------------------------------
245//
246// Calculate the integral of the FADC time slices and store them as a new
247// pixel in the MCerPhotEvt container.
248//
249Int_t MCalibrationCalc::Process()
250{
251
252 fEvents++;
253
254 Int_t cosmicpix = 0;
255
256 MCalibrationBlindPix &blindpixel = *(fCalibrations->GetBlindPixel());
257 MCalibrationPINDiode &pindiode = *(fCalibrations->GetPINDiode());
258
259 MRawEvtPixelIter pixel(fRawEvt);
260
261 //
262 // Create a first loop to sort out the cosmics ...
263 //
264 // This is a very primitive check for the number of cosmicpixs
265 // The cut will be applied in the fit, but for the blind pixel,
266 // we need to remove this event
267 //
268 // FIXME: In the future need a much more sophisticated one!!!
269 //
270
271 while (pixel.Next())
272 {
273
274 const Int_t pixid = pixel.GetPixelId();
275
276 Int_t sum = pixel.GetSumHiGainSamples();
277
278 MPedestalPix &ped = (*fPedestals)[pixid];
279
280 Float_t pedes = ped.GetPedestal();
281 Float_t pedrms = ped.GetPedestalRms();
282
283 if ((float)sum < ((pedes*fNumHiGainSamples)+(30.*pedrms)) )
284 cosmicpix++;
285 }
286
287
288 if (cosmicpix > 50.)
289 {
290 fCosmics++;
291 return kCONTINUE;
292 }
293
294 pixel.Reset();
295
296 //
297 // Create a second loop to do fill the calibration histograms
298 //
299
300 while (pixel.Next())
301 {
302
303 const UInt_t pixid = pixel.GetPixelId();
304
305 MExtractedSignalPix &sig = (*fSignals)[pixid];
306
307 Float_t sum = sig.GetExtractedSignal();
308 Bool_t logain = sig.IsLoGainUsed();
309
310 Byte_t mid;
311
312 if (logain)
313 mid = pixel.GetIdxMaxLoGainSample();
314 else
315 mid = pixel.GetIdxMaxHiGainSample();
316
317 MCalibrationPix &pix = (*fCalibrations)[pixid];
318
319 switch(pixid)
320 {
321
322 case gkCalibrationBlindPixelId:
323
324 if (!blindpixel.FillCharge(sum))
325 *fLog << warn <<
326 "Overflow or Underflow occurred filling Blind Pixel sum = " << sum << endl;
327
328 if (!blindpixel.FillTime((int)mid))
329 *fLog << warn <<
330 "Overflow or Underflow occurred filling Blind Pixel time = " << (int)mid << endl;
331
332 if (!blindpixel.FillRChargevsTime(sum,fEvents))
333 *fLog << warn <<
334 "Overflow or Underflow occurred filling Blind Pixel eventnr = " << fEvents << endl;
335
336 case gkCalibrationPINDiodeId:
337 if (!pindiode.FillCharge(sum))
338 *fLog << warn <<
339 "Overflow or Underflow occurred filling HCharge: means = " << sum << endl;
340 if (!pindiode.FillTime((int)mid))
341 *fLog << warn <<
342 "Overflow or Underflow occurred filling HTime: time = " << (int)mid << endl;
343 if (!pindiode.FillRChargevsTime(sum,fEvents))
344 *fLog << warn <<
345 "Overflow or Underflow occurred filling HChargevsN: eventnr = " << fEvents << endl;
346
347 default:
348
349 if (logain)
350 {
351
352 if (!pix.FillChargeLoGain(sum))
353 *fLog << warn << "Could not fill Lo Gain Charge of pixel: " << pixid
354 << " signal = " << sum << endl;
355
356 if (!pix.FillTimeLoGain((int)mid))
357 *fLog << warn << "Could not fill Lo Gain Time of pixel: "
358 << pixid << " time = " << (int)mid << endl;
359
360 //
361 // Fill the reduced charge into the control histo for better visibility
362 //
363 if (!pix.FillRChargevsTimeLoGain(sum,fEvents))
364 *fLog << warn << "Could not fill Lo Gain Charge vs. EvtNr of pixel: "
365 << pixid << " signal = " << sum << " event Nr: " << fEvents << endl;
366
367 }
368 else
369 {
370 if (!pix.FillChargeHiGain(sum))
371 *fLog << warn << "Could not fill Hi Gain Charge of pixel: " << pixid
372 << " signal = " << sum << endl;
373
374 if (!pix.FillTimeHiGain((int)mid))
375 *fLog << warn << "Could not fill Hi Gain Time of pixel: "
376 << pixid << " time = " << (int)mid << endl;
377
378 if (!pix.FillRChargevsTimeHiGain(sum,fEvents))
379 *fLog << warn << "Could not fill Hi Gain Charge vs. EvtNr of pixel: "
380 << pixid << " signal = " << sum << " event Nr: " << fEvents << endl;
381 }
382
383 } /* switch(pixid) */
384
385 } /* while (pixel.Next()) */
386
387 return kTRUE;
388}
389
390Int_t MCalibrationCalc::PostProcess()
391{
392
393
394 *fLog << inf << endl;
395 *fLog << GetDescriptor() << " Cut Histogram Edges" << endl;
396
397 //
398 // Cut edges to make fits and viewing of the hists easier
399 //
400 fCalibrations->CutEdges();
401
402 //
403 // Get pointer to blind pixel
404 //
405 MCalibrationBlindPix &blindpixel = *(fCalibrations->GetBlindPixel());
406
407 *fLog << GetDescriptor() << " Fitting the Blind Pixel" << endl;
408
409 //
410 // Fit the blind pixel
411 //
412 if (TESTBIT(fFlags,kUseBlindPixelFit))
413 {
414 if (blindpixel.FitCharge())
415 {
416 if (!fCalibrations->CalcNrPhotInnerPixel())
417 *fLog << err << dbginf << "Could not calculate Number of photons from the blind pixel " << endl;
418 }
419 else
420 {
421 *fLog << err << dbginf << "Could not fit the blind pixel " << endl;
422 }
423
424 if (!blindpixel.FitTime())
425 *fLog << warn << "Could not the Times of the blind pixel " << endl;
426
427 blindpixel.Draw();
428
429 }
430
431 *fLog << GetDescriptor() << " Fitting the Normal Pixels" << endl;
432
433 //
434 // loop over the pedestal events and check if we have calibration
435 //
436 for (Int_t pixid=0; pixid<fPedestals->GetSize(); pixid++)
437 {
438
439 MCalibrationPix &pix = (*fCalibrations)[pixid];
440
441 const Float_t ped = (*fPedestals)[pixid].GetPedestal() * fNumHiGainSamples;
442 const Float_t prms = (*fPedestals)[pixid].GetPedestalRms() * TMath::Sqrt((float)fNumHiGainSamples);
443
444 pix.SetPedestal(ped,prms);
445
446 if (TESTBIT(fFlags,kUseTimeFits))
447 pix.FitTime();
448
449 pix.FitCharge();
450 }
451
452 fCalibrations->SetReadyToSave();
453
454 if (GetNumExecutions()==0)
455 return kTRUE;
456
457 *fLog << endl;
458 *fLog << dec << setfill(' ') << fCosmics << " Events presumably cosmics" << endl;
459
460 return kTRUE;
461}
Note: See TracBrowser for help on using the repository browser.