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

Last change on this file since 2535 was 2525, checked in by gaug, 22 years ago
*** empty log message ***
File size: 14.5 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// - MRawRunHeader
126// - MRawEvtData
127// - MPedestalCam
128//
129// The following output containers are also searched and created if
130// they were not found:
131//
132// - MHCalibrationBlindPixel
133// - MCalibrationCam
134// - MTime
135//
136Int_t MCalibrationCalc::PreProcess(MParList *pList)
137{
138
139 fOverFlow = 0;
140 fNrEvents = 0;
141
142 fRunHeader = (MRawRunHeader*)pList->FindObject("MRawRunHeader");
143 if (!fRunHeader)
144 {
145 *fLog << dbginf << "MRawRunHeader not found... aborting." << endl;
146 return kFALSE;
147 }
148
149 fRawEvt = (MRawEvtData*)pList->FindObject("MRawEvtData");
150 if (!fRawEvt)
151 {
152 *fLog << dbginf << "MRawEvtData not found... aborting." << endl;
153 return kFALSE;
154 }
155
156 const MRawRunHeader *runheader = (MRawRunHeader*)pList->FindObject("MRawRunHeader");
157 if (!runheader)
158 *fLog << warn << dbginf << "Warning - cannot check file type, MRawRunHeader not found." << endl;
159 else
160 if (runheader->GetRunType() == kRTMonteCarlo)
161 {
162 return kTRUE;
163 }
164
165 fCalibrations = (MCalibrationCam*)pList->FindCreateObj("MCalibrationCam");
166 if (!fCalibrations)
167 {
168 *fLog << err << dbginf << "MCalibrationCam could not be created ... aborting." << endl;
169 return kFALSE;
170 }
171
172 //
173 // fRawEvt->GetNumPixels() does not work !!!!!!!!!!
174 //
175 fCalibrations->InitSize(577);
176
177 switch (fColor)
178 {
179 case kEBlue:
180 fCalibrations->SetColor(MCalibrationCam::kECBlue);
181 break;
182 case kEGreen:
183 fCalibrations->SetColor(MCalibrationCam::kECGreen);
184 break;
185 case kEUV:
186 fCalibrations->SetColor(MCalibrationCam::kECUV);
187 }
188
189
190
191 fPedestals = (MPedestalCam*)pList->FindObject("MPedestalCam");
192 if (!fPedestals)
193 {
194 *fLog << err << dbginf << "Cannot find MPedestalCam ... aborting" << endl;
195 return kFALSE;
196 }
197
198
199 // MTime does not work!!!!
200
201 // fEvtTime = (MTime*)pList->FindObject("MRawEvtTime");
202 // if (!fEvtTime)
203 // {
204 // *fLog << dbginf << "MTime could not be created ... ¡!¡!¡!¡!" << endl;
205 // }
206
207 // fEvtTime->SetTime(0.);
208
209
210 return kTRUE;
211}
212
213// --------------------------------------------------------------------------
214//
215// Calculate the integral of the FADC time slices and store them as a new
216// pixel in the MCerPhotEvt container.
217//
218Int_t MCalibrationCalc::Process()
219{
220
221 fNrEvents++;
222
223 MCalibrationBlindPix &blindpixel = *(fCalibrations->GetBlindPixel());
224 MCalibrationPINDiode &pindiode = *(fCalibrations->GetPINDiode());
225
226 MRawEvtPixelIter pixel(fRawEvt);
227
228 while (pixel.Next())
229 {
230
231 UShort_t sat = 0;
232 const Int_t pixid = pixel.GetPixelId();
233
234 if (!fCalibrations->IsPixelUsed(pixid))
235 if (!fCalibrations->AddPixel(pixid))
236 *fLog << err << dbginf << "MCalibrationPix(" << pixid << ") could not be created !!" << endl;
237
238 Byte_t *ptr = pixel.GetHiGainSamples();
239 Byte_t mid = pixel.GetIdxMaxHiGainSample();
240 UInt_t max = pixel.GetMaxHiGainSample();
241
242 Int_t sum = (max > gkSaturationLimit // overflow ?
243 ? sat++, pixel.GetSumLoGainSamples() // take Low Gain
244 : pixel.GetSumHiGainSamples()); // no overflow
245
246 if (sat)
247 {
248
249 ptr = pixel.GetLoGainSamples();
250 max = pixel.GetMaxLoGainSample();
251 mid = pixel.GetIdxMaxLoGainSample();
252
253 sum = (max == gkSaturationLimit // overflow of LoGain ??? -> GimmeABreak!!!
254 ? fOverFlow++, gkLoGainOverFlow // OUCH (Florian was maybe right)
255 : sum*gkConversionHiLo ); // OUFF (Florian was wrong) !!
256
257 // *fLog << warn << "Warning: Saturation of HiGain reached in slice " << (int)mid << " !!! " << endl;
258 // *fLog << warn << "Max = " << max << endl;
259
260 if (fOverFlow)
261 *fLog << err << dbginf << "Warning: Saturation of LoGain reached! "
262 << err << dbginf << "sum = " << sum << endl;
263
264 }
265
266 //
267 // sanity check (old MC files sometimes have pixids>577)
268 //
269 if (fPedestals && !fPedestals->CheckBounds(pixid))
270 {
271 *fLog << inf << "Pixel ID larger than camera... skipping event." << endl;
272 return kCONTINUE;
273 }
274
275 MPedestalPix &ped = (*fPedestals)[pixid];
276 MCalibrationPix &pix = (*fCalibrations)[pixid];
277
278 Float_t pedes = ped.GetPedestal();
279
280 //
281 // FIXME: This is preliminary, we will change to pedestals per slice!!!
282 // Assume pedestals per time slice ==> multiply with number of slices
283 //
284 pedes *= (sat ? fRawEvt->GetNumLoGainSamples() : fRawEvt->GetNumHiGainSamples() );
285
286 Float_t rsum = (float)sum - pedes;
287
288 switch(pixid)
289 {
290
291 case gkCalibrationBlindPixelId:
292 if (!blindpixel.FillQ(sum))
293 *fLog << warn <<
294 "Overflow or Underflow occurred filling Blind Pixel means = " << sum << endl;
295 if (!blindpixel.FillT((int)mid))
296 *fLog << warn <<
297 "Overflow or Underflow occurred filling Blind Pixel time = " << (int)mid << endl;
298 if (!blindpixel.FillRQvsT(rsum,fNrEvents))
299 *fLog << warn <<
300 "Overflow or Underflow occurred filling Blind Pixel eventnr = " << fNrEvents << endl;
301
302 case gkCalibrationPINDiodeId:
303 if (!pindiode.FillQ(sum))
304 *fLog << warn <<
305 "Overflow or Underflow occurred filling HQ: means = " << sum << endl;
306 if (!pindiode.FillT((int)mid))
307 *fLog << warn <<
308 "Overflow or Underflow occurred filling HT: time = " << (int)mid << endl;
309 if (!pindiode.FillRQvsT(rsum,fNrEvents))
310 *fLog << warn <<
311 "Overflow or Underflow occurred filling HQvsN: eventnr = " << fNrEvents << endl;
312
313 default:
314
315 if (!pix.FillQ(sum))
316 *fLog << warn << "Could not fill Q of pixel: " << pixid
317 << " signal = " << sum << endl;
318
319 //
320 // Fill the reduced charge into the control histo for better visibility
321 //
322 if (!pix.FillRQvsT(rsum,fNrEvents))
323 *fLog << warn << "Could not fill red. Q vs. EvtNr of pixel: " << pixid
324 << " signal = " << rsum << " event Nr: " << fNrEvents << endl;
325
326
327 if (!pix.FillT((int)mid))
328 *fLog << warn << "Could not fill T of pixel: " << pixid << " time = " << (int)mid << endl;
329
330
331 } /* switch(pixid) */
332
333 } /* while (pixel.Next()) */
334
335 fCalibrations->SetReadyToSave();
336
337 return kTRUE;
338}
339
340Int_t MCalibrationCalc::PostProcess()
341{
342
343 *fLog << inf << endl;
344 *fLog << GetDescriptor() << " Cut Histogram Edges" << endl;
345 //
346 // Cut edges to make fits and viewing of the hists easier
347 //
348 fCalibrations->CutEdges();
349
350 //
351 // Get pointer to blind pixel
352 //
353 MCalibrationBlindPix &blindpixel = *(fCalibrations->GetBlindPixel());
354
355 *fLog << GetDescriptor() << " Fitting the Blind Pixel" << endl;
356
357 //
358 // Fit the blind pixel
359 //
360 if (TESTBIT(fFlags,kUseBPFit))
361 {
362 if (!blindpixel.FitQ())
363 *fLog << err << dbginf << "Could not fit the blind pixel " << endl;
364
365 if (!blindpixel.FitT())
366 *fLog << warn << "Could not the Times of the blind pixel " << endl;
367
368 blindpixel.Draw();
369
370 }
371
372 *fLog << GetDescriptor() << " Fitting the Normal Pixels" << endl;
373 //
374 // loop over the pedestal events and check if we have calibration
375 //
376 for (Int_t pixid=0; pixid<fPedestals->GetSize(); pixid++)
377 {
378
379 if (fCalibrations->IsPixelUsed(pixid))
380 {
381
382 MCalibrationPix &pix = (*fCalibrations)[pixid];
383
384
385 if (TESTBIT(fFlags,kUseTFits))
386 pix.FitT();
387
388 if (!pix.FitQ())
389 continue;
390
391 const Float_t ped = (*fPedestals)[pixid].GetPedestal();
392 const Float_t prms = (*fPedestals)[pixid].GetPedestalRms();
393 pix.SetPedestal(ped,prms);
394 }
395 }
396
397 fCalibrations->SetReadyToSave();
398
399 if (GetNumExecutions()==0 || fOverFlow==0)
400 return kTRUE;
401
402 *fLog << inf << endl;
403 *fLog << GetDescriptor() << " execution statistics:" << endl;
404 *fLog << dec << setfill(' ');
405 *fLog << " " << setw(7) << fOverFlow << " (" << setw(3) << (int)(fOverFlow*100/GetNumExecutions()) << "%) Evts skipped due to: lo gain saturated." << endl;
406
407 return kTRUE;
408}
Note: See TracBrowser for help on using the repository browser.