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

Last change on this file since 17010 was 9422, checked in by tbretz, 16 years ago
*** empty log message ***
File size: 8.1 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->SetIndices();
148
149 return kTRUE;
150}
151
152// ------------------------------------------------------------------------
153//
154// Convert (digitize) the analog channels into digital (FADC) data.
155//
156Int_t MSimReadout::Process()
157{
158 // Sanity checks
159 if (fData->GetNumLoGainSamples()>0)
160 {
161 *fLog << err << "ERROR - MSimReadout: Lo-gains not implemented yet." << endl;
162 return kERROR;
163 }
164
165 // Make sure that we have not more analog channels than pixels
166 // FIXME: Is this really necessary?
167 if (fCamera->GetNumChannels()>fData->GetNumPixels())
168 {
169 *fLog << err;
170 *fLog << "ERROR - Number of analog channels " << fCamera->GetNumChannels();
171 *fLog << " exceeds number of pixels " << fData->GetNumPixels() << endl;
172 return kERROR;
173 }
174
175 if (fTrigger->GetVal()<0)
176 {
177 *fLog << err << "ERROR - MSimReadout: MSimReadout executed for an event which has no trigger." << endl;
178 return kERROR;
179 }
180
181 // Get the intended pulse position and convert it to slices
182 const Float_t pulpos = fPulsePos->GetVal()*fRunHeader->GetFreqSampling()/1000.;
183
184 // Get trigger position and correct for intended pulse position
185 const Int_t trig = TMath::CeilNint(fTrigger->GetVal()-pulpos);
186
187 // Check if the position is valid
188 if (trig<0)
189 {
190 *fLog << err;
191 *fLog << "ERROR - Trigger position before analog signal." << endl;
192 *fLog << " Trigger: " << fTrigger->GetVal() << endl;
193 *fLog << " PulsePos: " << pulpos << endl;
194 return kERROR;
195 }
196
197 // Get Number of samples in analog channels
198 const Int_t nsamp = fCamera->GetNumSamples();
199
200 // Get number of samples to be digitized
201 const Int_t nslices = fData->GetNumSamples();
202
203 // Check if the whole requested signal can be digitized
204 if (trig+nslices>=nsamp)
205 {
206 *fLog << err << "ERROR - Trigger position beyond valid analog signal range." << endl;
207 *fLog << " Trigger: " << fTrigger->GetVal() << endl;
208 *fLog << " PulsePos: " << pulpos << endl;
209 *fLog << " SamplesIn: " << nsamp << endl;
210 *fLog << " SamplesOut: " << nslices << endl;
211 return kERROR;
212 }
213
214 const Float_t offset = 0;//128;
215 const UInt_t max = fData->GetMax();
216
217 // FIXME: Take this into account
218// const UInt_t scale = 16;
219// const UInt_t resolution = 12;
220
221 // Digitize into a buffer
222 MArrayI buffer(nslices*fData->GetNumPixels());
223
224 // Loop over all channels/pixels
225 for (UInt_t i=0; i<fCamera->GetNumChannels(); i++)
226 {
227 // Get i-th canalog hannel
228 const MAnalogSignal &sig = (*fCamera)[i];
229
230 // Digitize all slices
231 for (Int_t j=0; j<nslices; j++)
232 {
233 Float_t slice = j+trig>=(Int_t)sig.GetSize() ? offset :
234 sig[j+trig] * fConversionFactor + offset;
235
236 // FIXME: Handle/Implement saturation!
237 if (slice>max)
238 slice = max;
239 if (slice<0)
240 slice = 0;
241
242 // We have a 16 bit FADC. The resolution of the DRS4 is just about 11.5 bit.
243 // Therefore the last 4.5 bits (~22.5) are gaussian noise (is this right?)
244 buffer[nslices*i + j] = TMath::Nint(slice);
245 }
246 }
247
248 // Set samples as raw-data
249 fData->Set(buffer);
250 fData->SetReadyToSave();
251
252 // Set the trigger/daq event number
253 fEvtHeader->SetDAQEvtNumber(GetNumExecutions());
254 fEvtHeader->SetReadyToSave();
255
256 // FIMXE: This will never be stored correctly :(
257 fRunHeader->SetNumEvents(fRunHeader->GetNumEvents()+1);
258
259 return kTRUE;
260}
261
262// --------------------------------------------------------------------------
263//
264// Read the parameters from the resource file.
265//
266// ConversionFactor: 1
267//
268Int_t MSimReadout::ReadEnv(const TEnv &env, TString prefix, Bool_t print)
269{
270 Bool_t rc = kFALSE;
271 if (IsEnvDefined(env, prefix, "ConversionFactor", print))
272 {
273 rc = kTRUE;
274 fConversionFactor = GetEnvValue(env, prefix, "ConversionFactor", fConversionFactor);
275 }
276
277 return rc;
278}
Note: See TracBrowser for help on using the repository browser.