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

Last change on this file since 5478 was 5354, checked in by moralejo, 20 years ago
*** empty log message ***
File size: 5.0 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 // Initialize arrays
123 if(fSumx.GetSize()==0)
124 {
125 const UShort_t num = fPedestals->GetSize();
126
127 fSumx.Set(num);
128 fSumx2.Set(num);
129
130 memset(fSumx.GetArray(), 0, sizeof(Float_t)*num);
131 memset(fSumx2.GetArray(), 0, sizeof(Float_t)*num);
132 }
133
134
135 return kTRUE;
136}
137
138// --------------------------------------------------------------------------
139//
140// Store the measured number of photons in arrays fSumx and fSumx2
141// so that we can calculate the mean and rms in the PostProcess()
142//
143Int_t MPedPhotCalc::Process()
144{
145 for(UInt_t i=0;i<fCerPhot->GetNumPixels();i++)
146 {
147 const MCerPhotPix &pix = (*fCerPhot)[i];
148 const Int_t pixidx = pix.GetPixId();
149
150 const Float_t nphot = pix.GetNumPhotons();
151
152 fSumx[pixidx] += nphot;
153 fSumx2[pixidx] += nphot*nphot;
154 }
155
156 fPedestals->SetReadyToSave();
157
158 return kTRUE;
159}
160
161// --------------------------------------------------------------------------
162//
163// Compute mean and rms of the measured charge distribution (in photons)
164//
165Int_t MPedPhotCalc::PostProcess()
166{
167 // Compute pedestals and rms from fSumx and fSumx2 arrays
168 const Int_t n = GetNumExecutions();
169 const Int_t npix = fSumx.GetSize();
170
171 for(Int_t i=0; i<npix; i++)
172 {
173
174 if (fBadPixels)
175 {
176 const MBadPixelsPix &bad = (*fBadPixels)[i];
177 if (bad.IsBad())
178 continue;
179 }
180
181 const Float_t sum = fSumx[i];
182 const Float_t sum2 = fSumx2[i];
183
184 const Float_t photped = sum/n;
185 const Float_t photrms = TMath::Sqrt((sum2-sum*sum/n)/(n-1.));
186
187 (*fPedestals)[i].Set(photped,photrms);
188 }
189
190 return kTRUE;
191}
Note: See TracBrowser for help on using the repository browser.