source: trunk/MagicSoft/Mars/manalysis/MCerPhotCalc.cc@ 2273

Last change on this file since 2273 was 2253, checked in by tbretz, 21 years ago
*** empty log message ***
File size: 6.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): Abelardo Moralejo 7/2002 <mailto:moralejo@pd.infn.it>
19! Author(s): Thomas Bretz 2002 <mailto:tbretz@astro.uni-wuerzburg.de>
20!
21! Copyright: MAGIC Software Development, 2002-2003
22!
23!
24\* ======================================================================== */
25
26//////////////////////////////////////////////////////////////////////////////
27//
28// MCerPhotCalc
29//
30// This is a task which calculates the number of photons from the FADC
31// time slices. It weights the each slice according to the numbers in
32// the array fWeight (default: all slices added up with weight 1).
33//
34// The weights are rescaled, such that sum(weigths)=num slices
35//
36// Input Containers:
37// MRawRunHeader, MRawEvtData, MPedestalCam
38//
39// Output Containers:
40// MCerPhotEvt
41//
42//////////////////////////////////////////////////////////////////////////////
43#include "MCerPhotCalc.h"
44
45#include "MParList.h"
46
47#include "MLog.h"
48#include "MLogManip.h"
49
50#include "MMcRunHeader.hxx"
51
52#include "MRawRunHeader.h"
53#include "MRawEvtData.h" // MRawEvtData::GetNumPixels
54#include "MCerPhotEvt.h"
55#include "MPedestalPix.h"
56#include "MPedestalCam.h"
57#include "MRawEvtPixelIter.h"
58
59ClassImp(MCerPhotCalc);
60
61using namespace std;
62
63// --------------------------------------------------------------------------
64//
65// Default constructor.
66//
67MCerPhotCalc::MCerPhotCalc(const char *name, const char *title)
68{
69 fName = name ? name : "MCerPhotCalc";
70 fTitle = title ? title : "Calculate pixel signal from FADC data";
71
72 AddToBranchList("MRawEvtData.fHiGainPixId");
73 AddToBranchList("MRawEvtData.fLoGainPixId");
74 AddToBranchList("MRawEvtData.fHiGainFadcSamples");
75 AddToBranchList("MRawEvtData.fLoGainFadcSamples");
76
77 SetDefaultWeights();
78}
79
80// --------------------------------------------------------------------------
81//
82// The PreProcess searches for the following input containers:
83// - MRawRunHeader
84// - MRawEvtData
85// - MPedestalCam
86//
87// The following output containers are also searched and created if
88// they were not found:
89// - MCerPhotEvt
90//
91Int_t MCerPhotCalc::PreProcess(MParList *pList)
92{
93 fRunHeader = (MRawRunHeader*)pList->FindObject("MRawRunHeader");
94 if (!fRunHeader)
95 {
96 *fLog << dbginf << "MRawRunHeader not found... aborting." << endl;
97 return kFALSE;
98 }
99
100 fRawEvt = (MRawEvtData*)pList->FindObject("MRawEvtData");
101 if (!fRawEvt)
102 {
103 *fLog << dbginf << "MRawEvtData not found... aborting." << endl;
104 return kFALSE;
105 }
106
107 fPedestals = (MPedestalCam*)pList->FindCreateObj("MPedestalCam");
108 if (!fPedestals)
109 {
110 *fLog << dbginf << "MPedestalCam not found... aborting." << endl;
111 return kFALSE;
112 }
113
114 fCerPhotEvt = (MCerPhotEvt*)pList->FindCreateObj("MCerPhotEvt");
115 if (!fCerPhotEvt)
116 return kFALSE;
117
118 // Calculate quadratic sum of weights:
119 Double_t sum = 0;
120
121 fSumQuadWeights = 0;
122 for (Int_t i=0; i<fWeight.GetSize(); i++)
123 sum += fWeight[i];
124
125 for (Int_t i=0; i<fWeight.GetSize(); i++)
126 {
127 fWeight[i] /= sum;
128 fSumQuadWeights += fWeight[i]*fWeight[i];
129 }
130
131 return kTRUE;
132}
133
134// --------------------------------------------------------------------------
135//
136// Check for the run type and camera version.
137// If the file is a MC file and the used camera version is <= 40
138// we enable a fix for truncated pedestal means in this version.
139//
140Bool_t MCerPhotCalc::ReInit(MParList *pList)
141{
142 const MRawRunHeader *runheader = (MRawRunHeader*)pList->FindObject("MRawRunHeader");
143 if (!runheader)
144 {
145 *fLog << warn << dbginf << "Warning - cannot check file type, MRawRunHeader not found." << endl;
146 return kTRUE;
147 }
148
149 if (fRunHeader->GetNumSamplesHiGain() != fWeight.GetSize())
150 {
151 *fLog << dbginf << "Number of FADC slices (" << fRunHeader->GetNumSamplesHiGain() <<") is different from assumed one (" << fWeight.GetSize() << ")... aborting." << endl;
152 return kFALSE;
153 }
154
155 Bool_t fIsMcFile = runheader->GetRunType() == kRTMonteCarlo;
156 if (!fIsMcFile)
157 return kTRUE;
158
159 ScalePedestals();
160
161 MMcRunHeader *mcrunheader = (MMcRunHeader*)pList->FindObject("MMcRunHeader");
162 if (!mcrunheader)
163 {
164 *fLog << warn << dbginf << "Warning - cannot check for camera version, MC run header not found." << endl;
165 return kTRUE;
166 }
167
168 fEnableFix = kFALSE;
169 if (mcrunheader->GetCamVersion() <= 40)
170 fEnableFix = kTRUE;
171
172 return kTRUE;
173}
174
175void MCerPhotCalc::ScalePedestals()
176{
177 Int_t n = 577; //FIXME: fPedestals->GetNumPixel();
178
179 for (int idx=0; idx<n; idx++)
180 {
181 MPedestalPix &ped = (*fPedestals)[idx];
182
183 const Double_t offset = fEnableFix ? ped.GetPedestal()-0.5 : ped.GetPedestal();
184 ped.Set(offset, ped.GetPedestalRms()*sqrt(fSumQuadWeights));
185 }
186
187 fPedestals->SetReadyToSave();
188}
189
190// --------------------------------------------------------------------------
191//
192// Calculate the integral of the FADC time slices and store them as a new
193// pixel in the MCerPhotEvt container.
194//
195Int_t MCerPhotCalc::Process()
196{
197 //fCerPhotEvt->InitSize(fRawEvt->GetNumPixels());
198
199// if (fIsMcFile)
200// ScalePedestals();
201
202 MRawEvtPixelIter pixel(fRawEvt);
203
204 while (pixel.Next())
205 {
206 const UInt_t idx = pixel.GetPixelId();
207 MPedestalPix &ped = (*fPedestals)[idx];
208
209 //
210 // sanity check (old MC files sometimes have pixids>577)
211 //
212 if (!fPedestals->CheckBounds(idx))
213 {
214 *fLog << inf << "Pixel Index larger than camera... skipping event." << endl;
215 return kCONTINUE;
216 }
217
218 //
219 // Calculate pixel signal unless it has all FADC slices empty:
220 //
221 Byte_t *ptr = pixel.GetHiGainSamples();
222
223 Float_t nphot = 0;
224 for(Int_t i=0; i<fWeight.GetSize(); i++)
225 nphot += ptr[i]*fWeight[i];
226
227 nphot -= ped.GetPedestal();
228
229 fCerPhotEvt->AddPixel(idx, nphot, 0);
230
231 // FIXME! Handling of Lo Gains is missing!
232 }
233
234 fCerPhotEvt->FixSize();
235 fCerPhotEvt->SetReadyToSave();
236
237 return kTRUE;
238}
239
240// --------------------------------------------------------------------------
241//
242// Set default values for the number of slices and weights:
243//
244void MCerPhotCalc::SetDefaultWeights()
245{
246 const Float_t dummy[15] = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 };
247 fWeight.Set(15, dummy);
248}
Note: See TracBrowser for help on using the repository browser.