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

Last change on this file since 1466 was 1443, 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 if (mcrunheader->GetCamVersion() <= 40)
159 fEnableFix = kTRUE;
160
161 return kTRUE;
162}
163
164// --------------------------------------------------------------------------
165//
166// Calculate the integral of the FADC time slices and store them as a new
167// pixel in the MCerPhotEvt container.
168//
169Bool_t MCerPhotCalc2::Process()
170{
171 fCerPhotEvt->InitSize(fRawEvt->GetNumPixels());
172
173 MRawEvtPixelIter pixel(fRawEvt);
174
175 TArrayF BinSignal(fWeight.GetSize());
176
177 while (pixel.Next())
178 {
179 const UInt_t pixid = pixel.GetPixelId();
180 const MPedestalPix &ped = (*fPedestals)[pixid];
181
182 //
183 // sanity check (old MC files sometimes have pixids>577)
184 //
185 if (!fPedestals->CheckBounds(pixid))
186 {
187 *fLog << inf << "Pixel ID larger than camera... skipping event." << endl;
188 return kCONTINUE;
189 }
190
191 // Mean pedestal:
192 const Double_t mean = fEnableFix ? ped.GetMean()-0.5 : ped.GetMean();
193
194 Byte_t *ptr = pixel.GetHiGainSamples();
195
196 Float_t nphot = 0.;
197
198 for(Int_t i = 0; i<fWeight.GetSize(); i++)
199 {
200 BinSignal[i] = (Float_t) ptr[i] - mean;
201 nphot += BinSignal[i] * fWeight[i];
202 }
203
204 Float_t nphoterr = ped.GetSigma()* fSumQuadWeights;
205
206 fCerPhotEvt->AddPixel(pixid, nphot, nphoterr);
207
208 // FIXME! Handling of Lo Gains is missing!
209 }
210
211 fCerPhotEvt->SetReadyToSave();
212
213 return kTRUE;
214}
215
216//
217// Set default values for the number of slices and weights:
218//
219
220void MCerPhotCalc2::SetDefaultWeights()
221{
222 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.};
223
224 fWeight.Set(15,dummy);
225 return;
226}
227
228
229
230
Note: See TracBrowser for help on using the repository browser.