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

Last change on this file since 1547 was 1545, checked in by bigongia, 22 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 (moralejo@pd.infn.it)
19!
20! Copyright: MAGIC Software Development, 2002
21!
22!
23\* ======================================================================== */
24
25//////////////////////////////////////////////////////////////////////////////
26// //
27// MCerPhotCalc //
28// //
29// This is a task which calculates the number of photons from the FADC //
30// time slices. It weights the each slice according to the numbers in //
31// the array fWeight (default: all slices added up with weight 1).
32// //
33// Input Containers: //
34// MRawRunHeader, MRawEvtData, MPedestalCam //
35// //
36// Output Containers: //
37// MCerPhotEvt //
38// //
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 {
106 *fLog << dbginf << "MPedestalCam not found... aborting." << endl;
107 return kFALSE;
108 }
109
110 fCerPhotEvt = (MCerPhotEvt*)pList->FindCreateObj("MCerPhotEvt");
111 if (!fCerPhotEvt)
112 return kFALSE;
113
114 // Calculate quadratic sum of weights:
115 fSumQuadWeights = 0.;
116 for (Int_t i = 0; i < fWeight.GetSize(); i++)
117 fSumQuadWeights += fWeight[i]*fWeight[i];
118
119 fSumQuadWeights = sqrt(fSumQuadWeights);
120
121 return kTRUE;
122}
123
124// --------------------------------------------------------------------------
125//
126// Check for the run type and camera version.
127// If the file is a MC file and the used camera version is <= 40
128// we enable a fix for truncated pedestal means in this version.
129//
130Bool_t MCerPhotCalc::ReInit(MParList *pList)
131{
132 const MRawRunHeader *runheader = (MRawRunHeader*)pList->FindObject("MRawRunHeader");
133 if (!runheader)
134 {
135 *fLog << warn << dbginf << "Warning - cannot check file type, MRawRunHeader not found." << endl;
136 return kTRUE;
137 }
138
139 if (fRunHeader->GetNumSamplesHiGain() != fWeight.GetSize())
140 {
141 *fLog << dbginf << "Number of FADC slices (" << fRunHeader->GetNumSamplesHiGain() <<") is different from assumed one (" << fWeight.GetSize() << ")... aborting." << endl;
142 return kFALSE;
143 }
144
145 if (runheader->GetRunType() != kRTMonteCarlo)
146 return kTRUE;
147
148 MMcRunHeader *mcrunheader = (MMcRunHeader*)pList->FindObject("MMcRunHeader");
149 if (!mcrunheader)
150 {
151 *fLog << warn << dbginf << "Warning - cannot check for camera version, MC run header not found." << endl;
152 return kTRUE;
153 }
154
155 fEnableFix = kFALSE;
156 if (mcrunheader->GetCamVersion() <= 40)
157 fEnableFix = kTRUE;
158
159 return kTRUE;
160}
161
162// --------------------------------------------------------------------------
163//
164// Calculate the integral of the FADC time slices and store them as a new
165// pixel in the MCerPhotEvt container.
166//
167Bool_t MCerPhotCalc::Process()
168{
169 fCerPhotEvt->InitSize(fRawEvt->GetNumPixels());
170
171 MRawEvtPixelIter pixel(fRawEvt);
172
173 TArrayF BinSignal(fWeight.GetSize());
174
175 while (pixel.Next())
176 {
177 const UInt_t pixid = pixel.GetPixelId();
178 const MPedestalPix &ped = (*fPedestals)[pixid];
179
180 //
181 // sanity check (old MC files sometimes have pixids>577)
182 //
183 if (!fPedestals->CheckBounds(pixid))
184 {
185 *fLog << inf << "Pixel ID larger than camera... skipping event." << endl;
186 return kCONTINUE;
187 }
188
189 // Mean pedestal:
190 const Double_t mean = fEnableFix ? ped.GetMean()-0.5 : ped.GetMean();
191
192 Byte_t *ptr = pixel.GetHiGainSamples();
193
194 Float_t nphot = 0.;
195
196 for(Int_t i = 0; i<fWeight.GetSize(); i++)
197 {
198 BinSignal[i] = (Float_t) ptr[i] - mean;
199 nphot += BinSignal[i] * fWeight[i];
200 }
201
202 Float_t nphoterr = ped.GetSigma()* fSumQuadWeights;
203
204 fCerPhotEvt->AddPixel(pixid, nphot, nphoterr);
205
206 // FIXME! Handling of Lo Gains is missing!
207 }
208
209 fCerPhotEvt->SetReadyToSave();
210
211 return kTRUE;
212}
213
214//
215// Set default values for the number of slices and weights:
216//
217
218void MCerPhotCalc::SetDefaultWeights()
219{
220 const Float_t dummy[15] = {1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1.,};
221
222 fWeight.Set(15,dummy);
223 return;
224}
225
226
227
228
Note: See TracBrowser for help on using the repository browser.