source: branches/Mars_MC/msimcamera/MSimReadout.cc@ 17207

Last change on this file since 17207 was 17011, checked in by ftemme, 11 years ago
added the writing of several Header Keys to the fitsoutput of Ceres in MJSimulation.cc, the values of the HeaderKeys are mainly hardcoded; changed the name of the columns in the fitsoutput for MMcEvt.fEvtNumber, MRawEvtData.fStartCells to the corresponding name in real data files; removed the vetoing of several columns in the fitsout in MJSimulation.cc; implemented the substraction of the accoupling in MSimCamera.cc
File size: 8.2 KB
Line 
1/* ======================================================================== *\
2!
3! *
4! * This file is part of CheObs, the Modular 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 appears 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): Thomas Bretz, 1/2009 <mailto:tbretz@astro.uni-wuerzburg.de>
19!
20! Copyright: CheObs Software Development, 2000-2009
21!
22!
23\* ======================================================================== */
24
25//////////////////////////////////////////////////////////////////////////////
26//
27// MSimReadout
28//
29// Task to convert the analog channels into a digital signal. This should
30// simulate the conversion and saturation bahaviour of the FADC/readout
31// system.
32//
33// You can give a conversion factor from the unitx of your analog signal
34// to the units of your adc. This is a fixed factor because it is just
35// a matter of what the meaning of an adc count is, nothing which could
36// jitter or is a real part of the electronics. Such effects should
37// be simulated somewhere else.
38//
39//
40// Input Containers:
41// MGeomCam
42// MAnalogChannels
43// TriggerPos [MParameterD]
44// IntendedPulsePos [MParameterD]
45// MRawRunHeader
46//
47// Output Containers:
48// MRawEvtData
49// MRawEvtHeader
50//
51//////////////////////////////////////////////////////////////////////////////
52#include "MSimReadout.h"
53
54#include "MLog.h"
55#include "MLogManip.h"
56
57#include "MArrayI.h"
58
59#include "MParList.h"
60#include "MParameters.h"
61
62#include "MGeomCam.h"
63
64#include "MRawRunHeader.h"
65#include "MRawEvtHeader.h"
66#include "MRawEvtData.h"
67
68#include "MAnalogSignal.h"
69#include "MAnalogChannels.h"
70
71ClassImp(MSimReadout);
72
73using namespace std;
74
75
76// ------------------------------------------------------------------------
77//
78// Default constructor
79//
80MSimReadout::MSimReadout(const char* name, const char *title)
81 : fRunHeader(0), fEvtHeader(0), fCamera(0), fPulsePos(0), fTrigger(0), fData(0),
82 fConversionFactor(1)
83{
84 fName = name ? name : "MSimReadout";
85 fTitle = title ? title : "Task to simulate the analog readout (FADCs)";
86}
87
88// ------------------------------------------------------------------------
89//
90// Look for the needed parameter containers.
91// Initialize MRawEvtData from MRawEvtRunHeader.
92//
93Int_t MSimReadout::PreProcess(MParList *pList)
94{
95 fCamera = (MAnalogChannels*)pList->FindObject("MAnalogChannels");
96 if (!fCamera)
97 {
98 *fLog << err << "MAnalogChannels not found... aborting." << endl;
99 return kFALSE;
100 }
101
102 fTrigger = (MParameterD*)pList->FindObject("TriggerPos", "MParameterD");
103 if (!fTrigger)
104 {
105 *fLog << err << "TriggerPos [MParameterD] not found... aborting." << endl;
106 return kFALSE;
107 }
108
109 fPulsePos = (MParameterD*)pList->FindObject("IntendedPulsePos", "MParameterD");
110 if (!fPulsePos)
111 {
112 *fLog << err << "IntendedPulsePos [MParameterD] not found... aborting." << endl;
113 return kFALSE;
114 }
115
116 fRunHeader = (MRawRunHeader*)pList->FindObject("MRawRunHeader");
117 if (!fRunHeader)
118 {
119 *fLog << err << "MRawRunHeader not found... aborting." << endl;
120 return kFALSE;
121 }
122
123 fEvtHeader = (MRawEvtHeader*)pList->FindCreateObj("MRawEvtHeader");
124 if (!fEvtHeader)
125 return kFALSE;
126
127 fData = (MRawEvtData*)pList->FindCreateObj("MRawEvtData");
128 if (!fData)
129 return kFALSE;
130
131 return kTRUE;
132}
133
134Bool_t MSimReadout::ReInit(MParList *plist)
135{
136 MGeomCam *cam = (MGeomCam*)plist->FindObject("MGeomCam");
137 if (!cam)
138 {
139 *fLog << err << "MGeomCam not found... aborting." << endl;
140 return kFALSE;
141 }
142
143 fRunHeader->InitPixels(cam->GetNumPixels());
144
145 fData->InitRead(fRunHeader);
146 fData->ResetPixels();
147 fData->InitStartCells();
148 fData->SetIndices();
149
150 return kTRUE;
151}
152
153// ------------------------------------------------------------------------
154//
155// Convert (digitize) the analog channels into digital (FADC) data.
156//
157Int_t MSimReadout::Process()
158{
159 // Sanity checks
160 if (fData->GetNumLoGainSamples()>0)
161 {
162 *fLog << err << "ERROR - MSimReadout: Lo-gains not implemented yet." << endl;
163 return kERROR;
164 }
165
166 // Make sure that we have not more analog channels than pixels
167 // FIXME: Is this really necessary?
168 if (fCamera->GetNumChannels()>fData->GetNumPixels())
169 {
170 *fLog << err;
171 *fLog << "ERROR - Number of analog channels " << fCamera->GetNumChannels();
172 *fLog << " exceeds number of pixels " << fData->GetNumPixels() << endl;
173 return kERROR;
174 }
175
176 if (fTrigger->GetVal()<0)
177 {
178 *fLog << err << "ERROR - MSimReadout: MSimReadout executed for an event which has no trigger." << endl;
179 return kERROR;
180 }
181
182 // Get the intended pulse position and convert it to slices
183 const Float_t pulpos = fPulsePos->GetVal()*fRunHeader->GetFreqSampling()/1000.;
184
185 // Get trigger position and correct for intended pulse position
186 const Int_t trig = TMath::CeilNint(fTrigger->GetVal()-pulpos);
187
188 // Check if the position is valid
189 if (trig<0)
190 {
191 *fLog << err;
192 *fLog << "ERROR - Trigger position before analog signal." << endl;
193 *fLog << " Trigger: " << fTrigger->GetVal() << endl;
194 *fLog << " PulsePos: " << pulpos << endl;
195 return kERROR;
196 }
197
198 // Get Number of samples in analog channels
199 const Int_t nsamp = fCamera->GetNumSamples();
200
201 // Get number of samples to be digitized
202 const Int_t nslices = fData->GetNumSamples();
203
204 // Check if the whole requested signal can be digitized
205 if (trig+nslices>nsamp)
206 {
207 *fLog << err << "ERROR - Trigger position beyond valid analog signal range." << endl;
208 *fLog << " Trigger: " << fTrigger->GetVal() << endl;
209 *fLog << " PulsePos: " << pulpos << endl;
210 *fLog << " SamplesIn: " << nsamp << endl;
211 *fLog << " SamplesOut: " << nslices << endl;
212 return kERROR;
213 }
214
215 const Float_t offset = 0;//128;
216 const UInt_t max = fData->GetMax();
217
218 // FIXME: Take this into account
219// const UInt_t scale = 16;
220// const UInt_t resolution = 12;
221
222 // Digitize into a buffer
223 MArrayI buffer(nslices*fData->GetNumPixels());
224
225 // Loop over all channels/pixels
226 for (UInt_t i=0; i<fCamera->GetNumChannels(); i++)
227 {
228 // Get i-th canalog hannel
229 const MAnalogSignal &sig = (*fCamera)[i];
230
231 // Digitize all slices
232 for (Int_t j=0; j<nslices; j++)
233 {
234 Float_t slice = j+trig>=(Int_t)sig.GetSize() ? offset :
235 sig[j+trig] * fConversionFactor + offset;
236
237 // FIXME: Handle/Implement saturation!
238 if (slice>max)
239 slice = max;
240 if (slice<0)
241 slice = 0;
242
243 // We have a 16 bit FADC. The resolution of the DRS4 is just about 11.5 bit.
244 // Therefore the last 4.5 bits (~22.5) are gaussian noise (is this right?)
245 buffer[nslices*i + j] = TMath::Nint(slice);
246 }
247 }
248
249 // Set samples as raw-data
250 fData->Set(buffer);
251 fData->SetReadyToSave();
252
253 // Set the trigger/daq event number
254 fEvtHeader->SetDAQEvtNumber(GetNumExecutions());
255 fEvtHeader->SetReadyToSave();
256
257 // FIMXE: This will never be stored correctly :(
258 fRunHeader->SetNumEvents(fRunHeader->GetNumEvents()+1);
259
260 return kTRUE;
261}
262
263// --------------------------------------------------------------------------
264//
265// Read the parameters from the resource file.
266//
267// ConversionFactor: 1
268//
269Int_t MSimReadout::ReadEnv(const TEnv &env, TString prefix, Bool_t print)
270{
271 Bool_t rc = kFALSE;
272 if (IsEnvDefined(env, prefix, "ConversionFactor", print))
273 {
274 rc = kTRUE;
275 fConversionFactor = GetEnvValue(env, prefix, "ConversionFactor", fConversionFactor);
276 }
277
278 return rc;
279}
Note: See TracBrowser for help on using the repository browser.