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

Last change on this file since 1963 was 1715, checked in by tbretz, 22 years ago
*** empty log message ***
File size: 6.6 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// Input Containers:
35// MRawRunHeader, MRawEvtData, MPedestalCam
36//
37// Output Containers:
38// MCerPhotEvt
39//
40//////////////////////////////////////////////////////////////////////////////
41#include "MCerPhotCalc.h"
42
43#include "MParList.h"
44
45#include "MLog.h"
46#include "MLogManip.h"
47
48#include "MMcRunHeader.hxx"
49
50#include "MRawRunHeader.h"
51#include "MRawEvtData.h" // MRawEvtData::GetNumPixels
52#include "MCerPhotEvt.h"
53#include "MPedestalPix.h"
54#include "MPedestalCam.h"
55#include "MRawEvtPixelIter.h"
56
57ClassImp(MCerPhotCalc);
58
59// --------------------------------------------------------------------------
60//
61// Default constructor.
62//
63MCerPhotCalc::MCerPhotCalc(const char *name, const char *title)
64{
65 fName = name ? name : "MCerPhotCalc";
66 fTitle = title ? title : "Task to calculate pixel signal from raw data";
67
68 AddToBranchList("MRawEvtData.fHiGainPixId");
69 AddToBranchList("MRawEvtData.fLoGainPixId");
70 AddToBranchList("MRawEvtData.fHiGainFadcSamples");
71 AddToBranchList("MRawEvtData.fLoGainFadcSamples");
72
73 SetDefaultWeights();
74}
75
76// --------------------------------------------------------------------------
77//
78// The PreProcess searches for the following input containers:
79// - MRawRunHeader
80// - MRawEvtData
81// - MPedestalCam
82//
83// The following output containers are also searched and created if
84// they were not found:
85// - MCerPhotEvt
86//
87Bool_t MCerPhotCalc::PreProcess(MParList *pList)
88{
89 fRunHeader = (MRawRunHeader*)pList->FindObject("MRawRunHeader");
90 if (!fRunHeader)
91 {
92 *fLog << dbginf << "MRawRunHeader not found... aborting." << endl;
93 return kFALSE;
94 }
95
96 fRawEvt = (MRawEvtData*)pList->FindObject("MRawEvtData");
97 if (!fRawEvt)
98 {
99 *fLog << dbginf << "MRawEvtData not found... aborting." << endl;
100 return kFALSE;
101 }
102
103 fPedestals = (MPedestalCam*)pList->FindCreateObj("MPedestalCam");
104 if (!fPedestals)
105 return kFALSE;
106
107 fCerPhotEvt = (MCerPhotEvt*)pList->FindCreateObj("MCerPhotEvt");
108 if (!fCerPhotEvt)
109 return kFALSE;
110
111 // Calculate quadratic sum of weights:
112 fSumQuadWeights = 0.;
113 for (Int_t i = 0; i < fWeight.GetSize(); i++)
114 fSumQuadWeights += fWeight[i]*fWeight[i];
115
116 fSumQuadWeights = sqrt(fSumQuadWeights);
117
118 return kTRUE;
119}
120
121// --------------------------------------------------------------------------
122//
123// Check for the run type and camera version.
124// If the file is a MC file and the used camera version is <= 40
125// we enable a fix for truncated pedestal means in this version.
126//
127Bool_t MCerPhotCalc::ReInit(MParList *pList)
128{
129 const MRawRunHeader *runheader = (MRawRunHeader*)pList->FindObject("MRawRunHeader");
130 if (!runheader)
131 {
132 *fLog << warn << dbginf << "Warning - cannot check file type, MRawRunHeader not found." << endl;
133 return kTRUE;
134 }
135
136 if (fRunHeader->GetNumSamplesHiGain() != fWeight.GetSize())
137 {
138 *fLog << dbginf << "Number of FADC slices (" << fRunHeader->GetNumSamplesHiGain() <<") is different from assumed one (" << fWeight.GetSize() << ")... aborting." << endl;
139 return kFALSE;
140 }
141
142 if (runheader->GetRunType() != kRTMonteCarlo)
143 return kTRUE;
144
145 MMcRunHeader *mcrunheader = (MMcRunHeader*)pList->FindObject("MMcRunHeader");
146 if (!mcrunheader)
147 {
148 *fLog << warn << dbginf << "Warning - cannot check for camera version, MC run header not found." << endl;
149 return kTRUE;
150 }
151
152 fEnableFix = kFALSE;
153 if (mcrunheader->GetCamVersion() <= 40)
154 fEnableFix = kTRUE;
155
156 return kTRUE;
157}
158
159// --------------------------------------------------------------------------
160//
161// Calculate the integral of the FADC time slices and store them as a new
162// pixel in the MCerPhotEvt container.
163//
164Bool_t MCerPhotCalc::Process()
165{
166 fCerPhotEvt->InitSize(fRawEvt->GetNumPixels());
167
168 MRawEvtPixelIter pixel(fRawEvt);
169
170 TArrayF binsignal(fWeight.GetSize());
171
172 while (pixel.Next())
173 {
174 const UInt_t pixid = pixel.GetPixelId();
175 const MPedestalPix &ped = (*fPedestals)[pixid];
176
177 //
178 // sanity check (old MC files sometimes have pixids>577)
179 //
180 if (!fPedestals->CheckBounds(pixid))
181 {
182 *fLog << inf << "Pixel ID larger than camera... skipping event." << endl;
183 return kCONTINUE;
184 }
185
186 //
187 // Mean pedestal:
188 //
189 const Double_t mean = fEnableFix ? ped.GetMean()-0.5 : ped.GetMean();
190
191 //
192 // Calculate pixel signal unless it has all FADC slices empty:
193 //
194 const Byte_t *ptr = pixel.GetHiGainSamples();
195
196 Float_t nphot = 0;
197 Float_t nphoterr = 0;
198
199 if (pixel.GetSumHiGainSamples()>0)
200 {
201 for (Int_t i=0; i<fWeight.GetSize(); i++)
202 {
203 binsignal[i] = ptr[i] - mean;
204 nphot += binsignal[i] * fWeight[i];
205 }
206 nphoterr = ped.GetSigma() * fSumQuadWeights;
207 }
208
209 fCerPhotEvt->AddPixel(pixid, nphot, nphoterr);
210
211 // FIXME! Handling of Lo Gains is missing!
212 }
213
214 fCerPhotEvt->SetReadyToSave();
215
216 return kTRUE;
217}
218
219// --------------------------------------------------------------------------
220//
221// Set default values for the number of slices and weights:
222//
223void MCerPhotCalc::SetDefaultWeights()
224{
225 const Float_t dummy[15] = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 };
226 fWeight.Set(15, dummy);
227}
Note: See TracBrowser for help on using the repository browser.