source: trunk/MagicSoft/Mars/manalysis/MPedPhotCalc.cc@ 2876

Last change on this file since 2876 was 2850, checked in by rico, 21 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!
21! Copyright: MAGIC Software Development, 2000-2004
22!
23!
24\* ======================================================================== */
25
26/////////////////////////////////////////////////////////////////////////////
27//
28// MPedPhotCalc
29//
30// This is a Task class to compute, for each pixel, the signal mean and
31// rms from a pedestal run file that has undergone the standard signal
32// extration and calibration procedure. The signal rms can be used as
33// reference to compute the significance of the measured signals in the
34// following data runs (e.g. during the image cleaning).
35//
36// Input Containers:
37// MCerPhotEvt
38//
39// Output Containers:
40// MPedPhotCam
41//
42/////////////////////////////////////////////////////////////////////////////
43#include "MPedPhotCalc.h"
44
45#include "MLog.h"
46#include "MLogManip.h"
47
48#include "MParList.h"
49#include "MRawRunHeader.h"
50
51#include "MCerPhotPix.h"
52#include "MCerPhotEvt.h"
53
54#include "MPedPhotPix.h"
55#include "MPedPhotCam.h"
56
57ClassImp(MPedPhotCalc);
58
59using namespace std;
60
61//
62// Default constructor
63//
64MPedPhotCalc::MPedPhotCalc(const char *name, const char *title)
65{
66 fName = name ? name : "MPedPhotCalc";
67 fTitle = title ? title : "Task to calculate pedestals from the charge computed from pedestal runs (in units of photons)";
68}
69
70// --------------------------------------------------------------------------
71//
72// Look for the following input containers:
73//
74// - MCerPhotEvt
75//
76// The following output containers are also searched and created if
77// they were not found:
78//
79// - MPedPhotCam
80//
81Int_t MPedPhotCalc::PreProcess( MParList *pList )
82{
83 // Look for input container
84 fCerPhot = (MCerPhotEvt*)pList->FindObject("MCerPhotEvt");
85 if (!fCerPhot)
86 {
87 *fLog << err << "MPedPhotCalc::PreProcess Error: MCerPhotEvt not found... aborting." << endl;
88 return kFALSE;
89 }
90
91 // Create output container
92 fPedestals = (MPedPhotCam*)pList->FindCreateObj("MPedPhotCam");
93 if (!fPedestals)
94 return kFALSE;
95
96 return kTRUE;
97}
98
99// --------------------------------------------------------------------------
100//
101// The ReInit searches for the following input containers:
102// - MRawRunHeader
103//
104// It also initializes the data arrays fSumx and fSumx2
105// (only for the first read file)
106//
107Bool_t MPedPhotCalc::ReInit(MParList *pList)
108{
109 const MRawRunHeader *runheader = (MRawRunHeader*)pList->FindObject("MRawRunHeader");
110 if (!runheader)
111 {
112 *fLog << warn << dbginf;
113 *fLog << "Warning - cannot check file type, MRawRunHeader not found." << endl;
114 }
115 else
116 if (runheader->GetRunType() == kRTMonteCarlo)
117 return kTRUE;
118
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 return kTRUE;
133}
134
135// --------------------------------------------------------------------------
136//
137// Store the measured number of photons in arrays fSumx and fSumx2
138// so that we can calculate the mean and rms in the PostProcess()
139//
140Int_t MPedPhotCalc::Process()
141{
142 for(UInt_t i=0;i<fCerPhot->GetNumPixels();i++)
143 {
144 const MCerPhotPix &pix = (*fCerPhot)[i];
145
146 const Float_t nphot = pix.GetNumPhotons();
147 const Int_t idx = pix.GetPixId();
148
149 fSumx[idx] += nphot;
150 fSumx2[idx] += nphot*nphot;
151 }
152
153 fPedestals->SetReadyToSave();
154
155 return kTRUE;
156}
157
158// --------------------------------------------------------------------------
159//
160// Compute mean and rms of the measured charge distribution (in photons)
161//
162Int_t MPedPhotCalc::PostProcess()
163 {
164 // Compute pedestals and rms from fSumx and fSumx2 arrays
165 const Int_t n = GetNumExecutions();
166 const Int_t npix = fSumx.GetSize();
167
168 for(Int_t i=0; i<npix; i++)
169 {
170 const Float_t sum = fSumx[i];
171 const Float_t sum2 = fSumx2[i];
172
173 const Float_t photped = sum/n;
174 const Float_t photrms = TMath::Sqrt((sum2-sum*sum/n)/(n-1.));
175
176 (*fPedestals)[i].Set(photped,photrms);
177 }
178
179 return kTRUE;
180}
Note: See TracBrowser for help on using the repository browser.