source: trunk/Mars/mpedestal/MPedPhotCalc.cc@ 10503

Last change on this file since 10503 was 6857, checked in by tbretz, 20 years ago
*** empty log message ***
File size: 4.9 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): Josep Flix 1/2004 <mailto:jflix@ifae.es>
19! Author(s): Javier Rico 1/2004 <mailto:jrico@ifae.es>
20! Author(s): Markus Gaug 4/2004 <mailto:markus@ifae.es>
21!
22! Copyright: MAGIC Software Development, 2000-2005
23!
24!
25\* ======================================================================== */
26
27/////////////////////////////////////////////////////////////////////////////
28//
29// MPedPhotCalc
30//
31// This is a Task class to compute, for each pixel, the signal mean and
32// rms from a pedestal run file that has undergone the standard signal
33// extration and calibration procedure. The signal rms can be used as
34// reference to compute the significance of the measured signals in the
35// following data runs (e.g. during the image cleaning).
36//
37// Input Containers:
38// MSignalCam
39//
40// Output Containers:
41// MPedPhotCam
42//
43/////////////////////////////////////////////////////////////////////////////
44#include "MPedPhotCalc.h"
45
46#include "MLog.h"
47#include "MLogManip.h"
48
49#include "MParList.h"
50#include "MRawRunHeader.h"
51
52#include "MSignalPix.h"
53#include "MSignalCam.h"
54
55#include "MPedPhotPix.h"
56#include "MPedPhotCam.h"
57
58#include "MBadPixelsPix.h"
59#include "MBadPixelsCam.h"
60
61ClassImp(MPedPhotCalc);
62
63using namespace std;
64
65//
66// Default constructor
67//
68MPedPhotCalc::MPedPhotCalc(const char *name, const char *title)
69 : fPedestals(NULL), fCerPhot(NULL), fBadPixels(NULL)
70{
71 fName = name ? name : "MPedPhotCalc";
72 fTitle = title ? title : "Task to calculate pedestals in units of photons";
73}
74
75// --------------------------------------------------------------------------
76//
77// Look for the following input containers:
78//
79// - MSignalCam
80// - MBadPixelsCam
81//
82// The following output containers are also searched and created if
83// they were not found:
84//
85// - MPedPhotCam
86//
87Int_t MPedPhotCalc::PreProcess( MParList *pList )
88{
89 // Look for input container
90 fCerPhot = (MSignalCam*)pList->FindObject("MSignalCam");
91 if (!fCerPhot)
92 {
93 *fLog << err << "MSignalCam not found... aborting." << endl;
94 return kFALSE;
95 }
96
97
98 fBadPixels = (MBadPixelsCam*)pList->FindObject("MBadPixelsCam");
99 if (!fBadPixels)
100 *fLog << warn << "WARNING - MBadPixelsCam not found... ignored." << endl;
101
102 // Create output container
103 fPedestals = (MPedPhotCam*)pList->FindCreateObj("MPedPhotCam");
104 if (!fPedestals)
105 return kFALSE;
106
107 return kTRUE;
108}
109
110// --------------------------------------------------------------------------
111//
112// The ReInit searches for the following input containers:
113// - MRawRunHeader
114//
115// It also initializes the data arrays fSumx and fSumx2
116// (only for the first read file)
117//
118Bool_t MPedPhotCalc::ReInit(MParList *pList)
119{
120 // Initialize arrays
121 if(fSumx.GetSize()==0)
122 {
123 const UShort_t num = fPedestals->GetSize();
124
125 fSumx.Set(num);
126 fSumx2.Set(num);
127
128 memset(fSumx.GetArray(), 0, sizeof(Float_t)*num);
129 memset(fSumx2.GetArray(), 0, sizeof(Float_t)*num);
130 }
131
132
133 return kTRUE;
134}
135
136// --------------------------------------------------------------------------
137//
138// Store the measured number of photons in arrays fSumx and fSumx2
139// so that we can calculate the mean and rms in the PostProcess()
140//
141Int_t MPedPhotCalc::Process()
142{
143 const UInt_t n = fCerPhot->GetNumPixels();
144 for(UInt_t idx=0; idx<n; idx++)
145 {
146 const Float_t nphot = (*fCerPhot)[idx].GetNumPhotons();
147
148 fSumx[idx] += nphot;
149 fSumx2[idx] += nphot*nphot;
150 }
151
152 fPedestals->SetReadyToSave();
153
154 return kTRUE;
155}
156
157// --------------------------------------------------------------------------
158//
159// Compute mean and rms of the measured charge distribution (in photons)
160//
161Int_t MPedPhotCalc::PostProcess()
162{
163 // Compute pedestals and rms from fSumx and fSumx2 arrays
164 const Int_t n = GetNumExecutions();
165 const Int_t npix = fSumx.GetSize();
166
167 for(Int_t i=0; i<npix; i++)
168 {
169
170 if (fBadPixels)
171 {
172 const MBadPixelsPix &bad = (*fBadPixels)[i];
173 if (bad.IsBad())
174 continue;
175 }
176
177 const Float_t sum = fSumx[i];
178 const Float_t sum2 = fSumx2[i];
179
180 const Float_t photped = sum/n;
181 const Float_t photrms = TMath::Sqrt((sum2-sum*sum/n)/(n-1.));
182
183 (*fPedestals)[i].Set(photped,photrms);
184 }
185
186 return kTRUE;
187}
Note: See TracBrowser for help on using the repository browser.