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