source: trunk/MagicSoft/Mars/manalysis/MCerPhotCalc2.cc@ 1542

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