source: trunk/MagicSoft/Mars/mpedestal/MPedPhotCalc.cc@ 4693

Last change on this file since 4693 was 4160, checked in by rico, 20 years ago
*** empty log message ***
File size: 5.3 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-2004
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// MCerPhotEvt
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 "MCerPhotPix.h"
53#include "MCerPhotEvt.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// - MCerPhotEvt
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 = (MCerPhotEvt*)pList->FindObject("MCerPhotEvt");
91 if (!fCerPhot)
92 {
93 *fLog << err << "MPedPhotCalc::PreProcess Error: MCerPhotEvt not found... aborting." << endl;
94 return kFALSE;
95 }
96
97
98 fBadPixels = (MBadPixelsCam*)pList->FindObject("MBadPixelsCam");
99 if (!fBadPixels)
100 {
101 *fLog << warn << "MPedPhotCalc::PreProcess Warning: No MBadPixelsCam found." << endl;
102 }
103
104 // Create output container
105 fPedestals = (MPedPhotCam*)pList->FindCreateObj("MPedPhotCam");
106 if (!fPedestals)
107 return kFALSE;
108
109 return kTRUE;
110}
111
112// --------------------------------------------------------------------------
113//
114// The ReInit searches for the following input containers:
115// - MRawRunHeader
116//
117// It also initializes the data arrays fSumx and fSumx2
118// (only for the first read file)
119//
120Bool_t MPedPhotCalc::ReInit(MParList *pList)
121{
122 const MRawRunHeader *runheader = (MRawRunHeader*)pList->FindObject("MRawRunHeader");
123 if (!runheader)
124 {
125 *fLog << warn << dbginf;
126 *fLog << "Warning - cannot check file type, MRawRunHeader not found." << endl;
127 }
128 else
129 if (runheader->IsMonteCarloRun())
130 return kTRUE;
131
132
133 // Initialize arrays
134 if(fSumx.GetSize()==0)
135 {
136 const UShort_t num = fPedestals->GetSize();
137
138 fSumx.Set(num);
139 fSumx2.Set(num);
140
141 memset(fSumx.GetArray(), 0, sizeof(Float_t)*num);
142 memset(fSumx2.GetArray(), 0, sizeof(Float_t)*num);
143 }
144
145
146 return kTRUE;
147}
148
149// --------------------------------------------------------------------------
150//
151// Store the measured number of photons in arrays fSumx and fSumx2
152// so that we can calculate the mean and rms in the PostProcess()
153//
154Int_t MPedPhotCalc::Process()
155{
156 for(UInt_t i=0;i<fCerPhot->GetNumPixels();i++)
157 {
158
159 const MCerPhotPix &pix = (*fCerPhot)[i];
160 const Int_t pixidx = pix.GetPixId();
161
162 const Float_t nphot = pix.GetNumPhotons();
163
164 fSumx[pixidx] += nphot;
165 fSumx2[pixidx] += nphot*nphot;
166 }
167
168 fPedestals->SetReadyToSave();
169
170 return kTRUE;
171}
172
173// --------------------------------------------------------------------------
174//
175// Compute mean and rms of the measured charge distribution (in photons)
176//
177Int_t MPedPhotCalc::PostProcess()
178{
179 // Compute pedestals and rms from fSumx and fSumx2 arrays
180 const Int_t n = GetNumExecutions();
181 const Int_t npix = fSumx.GetSize();
182
183 for(Int_t i=0; i<npix; i++)
184 {
185
186 if (fBadPixels)
187 {
188 const MBadPixelsPix &bad = (*fBadPixels)[i];
189 if (bad.IsBad())
190 continue;
191 }
192
193 const Float_t sum = fSumx[i];
194 const Float_t sum2 = fSumx2[i];
195
196 const Float_t photped = sum/n;
197 const Float_t photrms = TMath::Sqrt((sum2-sum*sum/n)/(n-1.));
198
199 (*fPedestals)[i].Set(photped,photrms);
200 }
201
202 return kTRUE;
203}
Note: See TracBrowser for help on using the repository browser.