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

Last change on this file since 2599 was 2599, checked in by gaug, 22 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// 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
97ClassImp(MCalibrationCalc);
98
99using 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//
105MCalibrationCalc::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//
135Int_t MCalibrationCalc::PreProcess(MParList *pList)
136{
137
138 fHistOverFlow = 0;
139 fEvents = 0;
140 fCosmics = 0;
141
142 fRawEvt = (MRawEvtData*)pList->FindObject("MRawEvtData");
143 if (!fRawEvt)
144 {
145 *fLog << dbginf << "MRawEvtData not found... aborting." << endl;
146 return kFALSE;
147 }
148
149 const MRawRunHeader *runheader = (MRawRunHeader*)pList->FindObject("MRawRunHeader");
150 if (!runheader)
151 *fLog << warn << dbginf << "Warning - cannot check file type, MRawRunHeader not found." << endl;
152 else
153 if (runheader->GetRunType() == kRTMonteCarlo)
154 {
155 return kTRUE;
156 }
157
158 fCalibrations = (MCalibrationCam*)pList->FindCreateObj("MCalibrationCam");
159 if (!fCalibrations)
160 {
161 *fLog << err << dbginf << "MCalibrationCam could not be created ... aborting." << endl;
162 return kFALSE;
163 }
164
165
166 switch (fColor)
167 {
168 case kEBlue:
169 fCalibrations->SetColor(MCalibrationCam::kECBlue);
170 break;
171 case kEGreen:
172 fCalibrations->SetColor(MCalibrationCam::kECGreen);
173 break;
174 case kEUV:
175 fCalibrations->SetColor(MCalibrationCam::kECUV);
176 }
177
178
179
180 fPedestals = (MPedestalCam*)pList->FindObject("MPedestalCam");
181 if (!fPedestals)
182 {
183 *fLog << err << dbginf << "Cannot find MPedestalCam ... aborting" << endl;
184 return kFALSE;
185 }
186
187
188 return kTRUE;
189}
190
191
192// --------------------------------------------------------------------------
193//
194// The ReInit searches for the following input containers:
195// - MRawRunHeader
196//
197Bool_t MCalibrationCalc::ReInit(MParList *pList )
198{
199
200 fRunHeader = (MRawRunHeader*)pList->FindObject("MRawRunHeader");
201 if (!fRunHeader)
202 {
203 *fLog << dbginf << "MRawRunHeader not found... aborting." << endl;
204 return kFALSE;
205 }
206
207 fNumHiGainSamples = fRunHeader->GetNumSamplesHiGain();
208 fNumLoGainSamples = fRunHeader->GetNumSamplesLoGain();
209
210 //
211 // FIXME: The next statement simply does not work:
212 // fRawEvt->GetNumPixels() returns always 0
213 // fCalibrations->InitSize(fRawEvt->GetNumPixels());
214 //
215
216 fCalibrations->InitSize(577);
217
218 for (Int_t i=0;i<577;i++)
219 {
220 MCalibrationPix &pix = (*fCalibrations)[i];
221 pix.ChangePixId(i);
222 }
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//
234Int_t MCalibrationCalc::Process()
235{
236
237 fEvents++;
238
239 Int_t cosmicpix = 0;
240
241 MCalibrationBlindPix &blindpixel = *(fCalibrations->GetBlindPixel());
242 MCalibrationPINDiode &pindiode = *(fCalibrations->GetPINDiode());
243
244 MRawEvtPixelIter pixel(fRawEvt);
245
246 while (pixel.Next())
247 {
248
249 UShort_t sat = 0;
250 const Int_t pixid = pixel.GetPixelId();
251
252 Byte_t *ptr = pixel.GetHiGainSamples();
253 Byte_t mid = pixel.GetIdxMaxHiGainSample();
254 UInt_t max = pixel.GetMaxHiGainSample();
255
256 Int_t sum = (max > gkSaturationLimit // overflow ?
257 ? sat++, pixel.GetSumLoGainSamples() // take Low Gain
258 : pixel.GetSumHiGainSamples()); // no overflow
259
260 if (sat)
261 {
262
263 ptr = pixel.GetLoGainSamples();
264 max = pixel.GetMaxLoGainSample();
265 mid = pixel.GetIdxMaxLoGainSample();
266
267 //
268 // FIXME: It seems the conversion HiGain LoGain is already
269 // performed in the data?!?
270 //
271 sum = (max > gkSaturationLimit // overflow of LoGain ??? -> GimmeABreak!!!
272 ? fHistOverFlow++, gkLoGainOverFlow // OUCH (Florian was maybe right)
273 : sum ); // OUFF (Florian was wrong) !!
274 // : sum*gkConversionHiLo ); // OUFF (Florian was wrong) !!
275
276 if (fHistOverFlow)
277 *fLog << err << dbginf << "Warning: Saturation of LoGain reached! "
278 << err << dbginf << "sum = " << sum << endl;
279
280 }
281
282 MPedestalPix &ped = (*fPedestals)[pixid];
283 MCalibrationPix &pix = (*fCalibrations)[pixid];
284
285 Float_t pedes = ped.GetPedestal();
286 Float_t pedrms = ped.GetPedestalRms();
287
288 //
289 // FIXME: This is preliminary, we will change to pedestals per slice!!!
290 // Assume pedestals per time slice ==> multiply with number of slices
291 //
292 pedes *= (sat ? fNumLoGainSamples : fNumHiGainSamples );
293 pedrms *= (sat ? fNumLoGainSamples : fNumHiGainSamples );
294
295 //
296 // This is a very primitive check for the number of cosmicpixs
297 // The cut will be applied in the fit, but for the blind pixel,
298 // we need to remove this event
299 //
300 // FIXME: In the future need a much more sophisticated one!!!
301 //
302
303 if ((float)sum < pedes+4.*pedrms)
304 cosmicpix++;
305
306 Float_t rsum = (float)sum - pedes;
307
308 switch(pixid)
309 {
310
311 case gkCalibrationBlindPixelId:
312
313 //
314 // FIXME: This works only when the blind pixel ID is much larger than
315 // the rest of the pixels (which is the case right now)
316 //
317 if (cosmicpix < 100.)
318 {
319 if (!blindpixel.FillQ(sum))
320 *fLog << warn <<
321 "Overflow or Underflow occurred filling Blind Pixel sum = " << sum << endl;
322
323 if (!blindpixel.FillT((int)mid))
324 *fLog << warn <<
325 "Overflow or Underflow occurred filling Blind Pixel time = " << (int)mid << endl;
326
327 if (!blindpixel.FillRQvsT(rsum,fEvents))
328 *fLog << warn <<
329 "Overflow or Underflow occurred filling Blind Pixel eventnr = " << fEvents << endl;
330 }
331
332 case gkCalibrationPINDiodeId:
333 if (!pindiode.FillQ(sum))
334 *fLog << warn <<
335 "Overflow or Underflow occurred filling HQ: means = " << sum << endl;
336 if (!pindiode.FillT((int)mid))
337 *fLog << warn <<
338 "Overflow or Underflow occurred filling HT: time = " << (int)mid << endl;
339 if (!pindiode.FillRQvsT(rsum,fEvents))
340 *fLog << warn <<
341 "Overflow or Underflow occurred filling HQvsN: eventnr = " << fEvents << endl;
342
343 default:
344
345 if (!pix.FillQ(sum))
346 *fLog << warn << "Could not fill Q of pixel: " << pixid
347 << " signal = " << sum << endl;
348
349 //
350 // Fill the reduced charge into the control histo for better visibility
351 //
352 if (!pix.FillRQvsT(rsum,fEvents))
353 *fLog << warn << "Could not fill red. Q vs. EvtNr of pixel: " << pixid
354 << " signal = " << rsum << " event Nr: " << fEvents << endl;
355
356
357 if (!pix.FillT((int)mid))
358 *fLog << warn << "Could not fill T of pixel: " << pixid << " time = " << (int)mid << endl;
359
360
361 } /* switch(pixid) */
362
363 } /* while (pixel.Next()) */
364
365 if (cosmicpix > 300.)
366 fCosmics++;
367
368 return kTRUE;
369}
370
371Int_t MCalibrationCalc::PostProcess()
372{
373
374 *fLog << inf << endl;
375 *fLog << GetDescriptor() << " Cut Histogram Edges" << endl;
376 //
377 // Cut edges to make fits and viewing of the hists easier
378 //
379 fCalibrations->CutEdges();
380
381 //
382 // Get pointer to blind pixel
383 //
384 MCalibrationBlindPix &blindpixel = *(fCalibrations->GetBlindPixel());
385
386 *fLog << GetDescriptor() << " Fitting the Blind Pixel" << endl;
387
388 //
389 // Fit the blind pixel
390 //
391 if (TESTBIT(fFlags,kUseBPFit))
392 {
393 if (!blindpixel.FitQ())
394 *fLog << err << dbginf << "Could not fit the blind pixel " << endl;
395
396 if (!blindpixel.FitT())
397 *fLog << warn << "Could not the Times of the blind pixel " << endl;
398
399 blindpixel.Draw();
400
401 }
402
403 *fLog << GetDescriptor() << " Fitting the Normal Pixels" << endl;
404
405 //
406 // loop over the pedestal events and check if we have calibration
407 //
408 for (Int_t pixid=0; pixid<fPedestals->GetSize(); pixid++)
409 {
410
411 MCalibrationPix &pix = (*fCalibrations)[pixid];
412
413 const Float_t ped = (*fPedestals)[pixid].GetPedestal() * fNumHiGainSamples;
414 const Float_t prms = (*fPedestals)[pixid].GetPedestalRms() * fNumHiGainSamples;
415
416 pix.SetPedestal(ped,prms);
417
418 if (TESTBIT(fFlags,kUseTFits))
419 pix.FitT();
420
421 pix.FitQ();
422 }
423
424 fCalibrations->SetReadyToSave();
425
426 if (GetNumExecutions()==0)
427 return kTRUE;
428
429 *fLog << endl;
430 *fLog << dec << setfill(' ') << fCosmics << " Events presumably cosmics" << endl;
431
432 return kTRUE;
433}
Note: See TracBrowser for help on using the repository browser.