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

Last change on this file since 2679 was 2679, checked in by gaug, 21 years ago
*** empty log message ***
File size: 14.8 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" // MRawEvtData::GetNumPixels
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. b is the number of slices before the maximum slice,
109// a the number of slices behind the maximum slice which is taken as signal.
110//
111MCalibrationCalc::MCalibrationCalc(const char *name, const char *title)
112 : fColor(kEBlue)
113{
114
115 fName = name ? name : "MCalibrationCalc";
116 fTitle = title ? title : "Task to calculate the calibration constants and MCalibrationCam ";
117
118 AddToBranchList("MRawEvtData.fHiGainPixId");
119 AddToBranchList("MRawEvtData.fLoGainPixId");
120 AddToBranchList("MRawEvtData.fHiGainFadcSamples");
121 AddToBranchList("MRawEvtData.fLoGainFadcSamples");
122
123 SETBIT(fFlags, kUseTimeFits);
124 SETBIT(fFlags, kUseBlindPixelFit);
125 SETBIT(fFlags, kUsePinDiodeFit);
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
236 fCalibrations->InitSize(cam->GetNumPixels());
237
238 for (UInt_t i=0;i<cam->GetNumPixels();i++)
239 {
240 MCalibrationPix &pix = (*fCalibrations)[i];
241 pix.DefinePixId(i);
242 }
243
244 return kTRUE;
245
246}
247
248
249// --------------------------------------------------------------------------
250//
251// Calculate the integral of the FADC time slices and store them as a new
252// pixel in the MCerPhotEvt container.
253//
254Int_t MCalibrationCalc::Process()
255{
256
257 Int_t cosmicpix = 0;
258
259 MCalibrationBlindPix &blindpixel = *(fCalibrations->GetBlindPixel());
260 MCalibrationPINDiode &pindiode = *(fCalibrations->GetPINDiode());
261
262 MRawEvtPixelIter pixel(fRawEvt);
263
264 //
265 // Create a first loop to sort out the cosmics ...
266 //
267 // This is a very primitive check for the number of cosmicpixs
268 // The cut will be applied in the fit, but for the blind pixel,
269 // we need to remove this event
270 //
271 // FIXME: In the future need a much more sophisticated one!!!
272 //
273
274 while (pixel.Next())
275 {
276
277 const UInt_t pixid = pixel.GetPixelId();
278
279 MExtractedSignalPix &sig = (*fSignals)[pixid];
280 MPedestalPix &ped = (*fPedestals)[pixid];
281 Float_t pedrms = ped.GetPedestalRms();
282 Float_t sumhi = sig.GetExtractedSignalHiGain();
283
284 if (sumhi < 15.*pedrms ) // cut at 3.5 sigma
285 cosmicpix++;
286 }
287
288 if (cosmicpix > 100.)
289 {
290 fCosmics++;
291 return kCONTINUE;
292 }
293
294 pixel.Reset();
295 fEvents++;
296
297 //
298 // Create a second loop to do fill the calibration histograms
299 //
300
301 while (pixel.Next())
302 {
303
304 const UInt_t pixid = pixel.GetPixelId();
305
306 MExtractedSignalPix &sig = (*fSignals)[pixid];
307
308 Float_t sumhi = sig.GetExtractedSignalHiGain();
309 Float_t sumlo = sig.GetExtractedSignalLoGain();
310 Bool_t logain = sig.IsLoGainUsed();
311
312 Float_t mtime = sig.GetMeanArrivalTime();
313
314 MCalibrationPix &pix = (*fCalibrations)[pixid];
315
316 switch(pixid)
317 {
318
319 case gkCalibrationBlindPixelId:
320
321 if (!blindpixel.FillCharge(sumhi))
322 *fLog << warn <<
323 "Overflow or Underflow occurred filling Blind Pixel sum = " << sumhi << endl;
324
325 if (!blindpixel.FillTime((int)mtime))
326 *fLog << warn <<
327 "Overflow or Underflow occurred filling Blind Pixel time = " << mtime << endl;
328
329 if (!blindpixel.FillRChargevsTime(sumhi,fEvents))
330 *fLog << warn <<
331 "Overflow or Underflow occurred filling Blind Pixel eventnr = " << fEvents << endl;
332 break;
333
334 case gkCalibrationPINDiodeId:
335 if (!pindiode.FillCharge(sumhi))
336 *fLog << warn <<
337 "Overflow or Underflow occurred filling HCharge: means = " << sumhi << endl;
338 if (!pindiode.FillTime((int)mtime))
339 *fLog << warn <<
340 "Overflow or Underflow occurred filling HTime: time = " << mtime << endl;
341 if (!pindiode.FillRChargevsTime(sumhi,fEvents))
342 *fLog << warn <<
343 "Overflow or Underflow occurred filling HChargevsN: eventnr = " << fEvents << endl;
344 break;
345
346 default:
347
348 pix.SetChargesInGraph(sumhi,sumlo);
349
350 if (!pix.FillRChargevsTimeLoGain(sumlo,fEvents))
351 *fLog << warn << "Could not fill Lo Gain Charge vs. EvtNr of pixel: "
352 << pixid << " signal = " << sumlo << " event Nr: " << fEvents << endl;
353
354 if (!pix.FillRChargevsTimeHiGain(sumhi,fEvents))
355 *fLog << warn << "Could not fill Hi Gain Charge vs. EvtNr of pixel: "
356 << pixid << " signal = " << sumhi << " event Nr: " << fEvents << endl;
357
358 if (logain)
359 {
360
361 if (!pix.FillChargeLoGain(sumlo))
362 *fLog << warn << "Could not fill Lo Gain Charge of pixel: " << pixid
363 << " signal = " << sumlo << endl;
364
365 if (!pix.FillTimeLoGain((int)mtime))
366 *fLog << warn << "Could not fill Lo Gain Time of pixel: "
367 << pixid << " time = " << mtime << endl;
368
369 }
370 else
371 {
372 if (!pix.FillChargeHiGain(sumhi))
373 *fLog << warn << "Could not fill Hi Gain Charge of pixel: " << pixid
374 << " signal = " << sumhi << endl;
375
376 if (!pix.FillTimeHiGain((int)mtime))
377 *fLog << warn << "Could not fill Hi Gain Time of pixel: "
378 << pixid << " time = " << mtime << endl;
379
380 }
381 break;
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 *fLog << err << dbginf << "Could not fit the blind pixel " << endl;
416 else
417 *fLog << err << dbginf << "Could not fit the blind pixel " << endl;
418
419 if (!blindpixel.FitTime())
420 *fLog << warn << "Could not the Times of the blind pixel " << endl;
421
422 blindpixel.Draw();
423 }
424
425 *fLog << GetDescriptor() << " Fitting the Normal Pixels" << endl;
426
427 //
428 // loop over the pedestal events and check if we have calibration
429 //
430 for (Int_t pixid=0; pixid<fPedestals->GetSize(); pixid++)
431 {
432
433 MCalibrationPix &pix = (*fCalibrations)[pixid];
434
435 const Float_t ped = (*fPedestals)[pixid].GetPedestal() * fNumHiGainSamples;
436 const Float_t prms = (*fPedestals)[pixid].GetPedestalRms() * TMath::Sqrt((float)fNumHiGainSamples);
437
438 pix.SetPedestal(ped,prms);
439
440 pix.FitCharge();
441
442 if (TESTBIT(fFlags,kUseTimeFits))
443 pix.FitTime();
444
445 }
446
447 if (!fCalibrations->CalcNumPhotInsidePlexiglass())
448 *fLog << err << dbginf << "Could not calculate the number of photons from the blind pixel " << endl;
449
450 fCalibrations->SetReadyToSave();
451
452 if (GetNumExecutions()==0)
453 return kTRUE;
454
455 *fLog << endl;
456 *fLog << dec << setfill(' ') << fCosmics << " Events presumably cosmics" << endl;
457
458 return kTRUE;
459}
Note: See TracBrowser for help on using the repository browser.