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 | //
|
---|
34 | // Input Containers:
|
---|
35 | // MGeomCam
|
---|
36 | // MAnalogChannels
|
---|
37 | // TriggerPos [MParameterD]
|
---|
38 | // IntendedPulsePos [MParameterD]
|
---|
39 | // MRawRunHeader
|
---|
40 | //
|
---|
41 | // Output Containers:
|
---|
42 | // MRawEvtData
|
---|
43 | // MRawEvtHeader
|
---|
44 | //
|
---|
45 | //////////////////////////////////////////////////////////////////////////////
|
---|
46 | #include "MSimReadout.h"
|
---|
47 |
|
---|
48 | #include "MLog.h"
|
---|
49 | #include "MLogManip.h"
|
---|
50 |
|
---|
51 | #include "MArrayI.h"
|
---|
52 |
|
---|
53 | #include "MParList.h"
|
---|
54 | #include "MParameters.h"
|
---|
55 |
|
---|
56 | #include "MGeomCam.h"
|
---|
57 |
|
---|
58 | #include "MRawRunHeader.h"
|
---|
59 | #include "MRawEvtHeader.h"
|
---|
60 | #include "MRawEvtData.h"
|
---|
61 |
|
---|
62 | #include "MAnalogSignal.h"
|
---|
63 | #include "MAnalogChannels.h"
|
---|
64 |
|
---|
65 | ClassImp(MSimReadout);
|
---|
66 |
|
---|
67 | using namespace std;
|
---|
68 |
|
---|
69 |
|
---|
70 | // ------------------------------------------------------------------------
|
---|
71 | //
|
---|
72 | // Default constructor
|
---|
73 | //
|
---|
74 | MSimReadout::MSimReadout(const char* name, const char *title)
|
---|
75 | : fRunHeader(0), fCamera(0), fPulsePos(0), fTrigger(0), fData(0)
|
---|
76 | {
|
---|
77 | fName = name ? name : "MSimReadout";
|
---|
78 | fTitle = title ? title : "Task to simulate the analog readout (FADCs)";
|
---|
79 | }
|
---|
80 |
|
---|
81 | // ------------------------------------------------------------------------
|
---|
82 | //
|
---|
83 | // Look for the needed parameter containers.
|
---|
84 | // Initialize MRawEvtData from MRawEvtRunHeader.
|
---|
85 | //
|
---|
86 | Int_t MSimReadout::PreProcess(MParList *pList)
|
---|
87 | {
|
---|
88 | fCamera = (MAnalogChannels*)pList->FindObject("MAnalogChannels");
|
---|
89 | if (!fCamera)
|
---|
90 | {
|
---|
91 | *fLog << err << "MAnalogChannels not found... aborting." << endl;
|
---|
92 | return kFALSE;
|
---|
93 | }
|
---|
94 |
|
---|
95 | fTrigger = (MParameterD*)pList->FindObject("TriggerPos", "MParameterD");
|
---|
96 | if (!fTrigger)
|
---|
97 | {
|
---|
98 | *fLog << err << "TriggerPos [MParameterD] not found... aborting." << endl;
|
---|
99 | return kFALSE;
|
---|
100 | }
|
---|
101 |
|
---|
102 | fPulsePos = (MParameterD*)pList->FindObject("IntendedPulsePos", "MParameterD");
|
---|
103 | if (!fPulsePos)
|
---|
104 | {
|
---|
105 | *fLog << err << "IntendedPulsePos [MParameterD] not found... aborting." << endl;
|
---|
106 | return kFALSE;
|
---|
107 | }
|
---|
108 |
|
---|
109 | fRunHeader = (MRawRunHeader*)pList->FindObject("MRawRunHeader");
|
---|
110 | if (!fRunHeader)
|
---|
111 | {
|
---|
112 | *fLog << err << "MRawRunHeader not found... aborting." << endl;
|
---|
113 | return kFALSE;
|
---|
114 | }
|
---|
115 |
|
---|
116 | fData = (MRawEvtData*)pList->FindCreateObj("MRawEvtData");
|
---|
117 | if (!fData)
|
---|
118 | return kFALSE;
|
---|
119 |
|
---|
120 | return kTRUE;
|
---|
121 | }
|
---|
122 |
|
---|
123 | Bool_t MSimReadout::ReInit(MParList *plist)
|
---|
124 | {
|
---|
125 | MGeomCam *cam = (MGeomCam*)plist->FindObject("MGeomCam");
|
---|
126 | if (!cam)
|
---|
127 | {
|
---|
128 | *fLog << err << "MGeomCam not found... aborting." << endl;
|
---|
129 | return kFALSE;
|
---|
130 | }
|
---|
131 |
|
---|
132 | fRunHeader->InitPixels(cam->GetNumPixels());
|
---|
133 | fRunHeader->SetValidMagicNumber();
|
---|
134 | fRunHeader->SetSourceInfo("MonteCarlo"); // "Muon" from first event??
|
---|
135 | fRunHeader->SetReadyToSave();
|
---|
136 |
|
---|
137 | fData->InitRead(fRunHeader);
|
---|
138 | fData->ResetPixels();
|
---|
139 | fData->SetIndices();
|
---|
140 |
|
---|
141 | return kTRUE;
|
---|
142 | }
|
---|
143 |
|
---|
144 | // ------------------------------------------------------------------------
|
---|
145 | //
|
---|
146 | // Convert (digitize) the analog channels into digital (FADC) data.
|
---|
147 | //
|
---|
148 | Int_t MSimReadout::Process()
|
---|
149 | {
|
---|
150 | // Sanity checks
|
---|
151 | if (fData->GetNumLoGainSamples()>0)
|
---|
152 | {
|
---|
153 | *fLog << err << "ERROR - MSimReadout: Lo-gains not implemented yet." << endl;
|
---|
154 | return kERROR;
|
---|
155 | }
|
---|
156 |
|
---|
157 | // Get Number of pixels
|
---|
158 | const UInt_t npix = fData->GetNumPixels();
|
---|
159 |
|
---|
160 | if (npix!=fCamera->GetNumChannels())
|
---|
161 | {
|
---|
162 | *fLog << err;
|
---|
163 | *fLog << "ERROR - Number of analog channels " << fCamera->GetNumChannels();
|
---|
164 | *fLog << " doesn't match number of pixels " << fData->GetNumPixels() << endl;
|
---|
165 | return kERROR;
|
---|
166 | }
|
---|
167 |
|
---|
168 | if (fTrigger->GetVal()<0)
|
---|
169 | {
|
---|
170 | *fLog << err << "ERROR - MSimReadout: MSimReadout executed for an event which has no trigger." << endl;
|
---|
171 | return kERROR;
|
---|
172 | }
|
---|
173 |
|
---|
174 | // Get the intended pulse position and convert it to slices
|
---|
175 | const Float_t pulpos = fPulsePos->GetVal()*fRunHeader->GetFreqSampling()/1000.;
|
---|
176 |
|
---|
177 | // Get trigger position and correct for intended pulse position
|
---|
178 | const Int_t trig = TMath::CeilNint(fTrigger->GetVal()-pulpos);
|
---|
179 |
|
---|
180 | // Check if the position is valid
|
---|
181 | if (trig<0)
|
---|
182 | {
|
---|
183 | *fLog << err;
|
---|
184 | *fLog << "ERROR - Trigger position before analog signal." << endl;
|
---|
185 | *fLog << " Trigger: " << fTrigger->GetVal() << endl;
|
---|
186 | *fLog << " PulsePos: " << pulpos << endl;
|
---|
187 | return kERROR;
|
---|
188 | }
|
---|
189 |
|
---|
190 | // Get Number of samples in analog channels
|
---|
191 | const Int_t nsamp = fCamera->GetNumSamples();
|
---|
192 |
|
---|
193 | // Get number of samples to be digitized
|
---|
194 | const Int_t nslices = fData->GetNumSamples();
|
---|
195 |
|
---|
196 | // Check if the whole requested signal can be digitized
|
---|
197 | if (trig+nslices>=nsamp)
|
---|
198 | {
|
---|
199 | *fLog << err << "ERROR - Trigger position beyond valid analog signal range." << endl;
|
---|
200 | *fLog << " Trigger: " << fTrigger->GetVal() << endl;
|
---|
201 | *fLog << " PulsePos: " << pulpos << endl;
|
---|
202 | *fLog << " SamplesIn: " << nsamp << endl;
|
---|
203 | *fLog << " SamplesOut: " << nslices << endl;
|
---|
204 | return kERROR;
|
---|
205 | }
|
---|
206 |
|
---|
207 | const Float_t gain = 64./1;
|
---|
208 | const Float_t offset = 128;
|
---|
209 | const UInt_t max = fData->GetMax();
|
---|
210 |
|
---|
211 | // FIXME: Take this into account
|
---|
212 | // const UInt_t scale = 16;
|
---|
213 | // const UInt_t resolution = 12;
|
---|
214 |
|
---|
215 | // Digitize into a buffer
|
---|
216 | MArrayI buffer(nslices*npix);
|
---|
217 |
|
---|
218 | // Loop over all channels/pixels
|
---|
219 | for (UInt_t i=0; i<npix; i++)
|
---|
220 | {
|
---|
221 | // Get i-th canalog hannel
|
---|
222 | const MAnalogSignal &sig = (*fCamera)[i];
|
---|
223 |
|
---|
224 | // Digitize all slices
|
---|
225 | for (Int_t j=0; j<nslices; j++)
|
---|
226 | {
|
---|
227 | Float_t slice = j+trig>=(Int_t)sig.GetSize() ? offset :
|
---|
228 | sig[j+trig] * gain + offset;
|
---|
229 |
|
---|
230 | // FIXME: Handle/Implement saturation!
|
---|
231 | if (slice>max)
|
---|
232 | slice = max;
|
---|
233 | if (slice<0)
|
---|
234 | slice = 0;
|
---|
235 |
|
---|
236 | // We have a 16 bit FADC. The resolution of the DRS4 is just about 11.5 bit.
|
---|
237 | // Therefore the last 4.5 bits (~22.5) are gaussian noise (is this right?)
|
---|
238 | buffer[nslices*i + j] = TMath::Nint(slice);
|
---|
239 | }
|
---|
240 | }
|
---|
241 |
|
---|
242 | // Set samples as raw-data
|
---|
243 | fData->Set(buffer);
|
---|
244 | fData->SetReadyToSave();
|
---|
245 |
|
---|
246 | // FIMXE: This will never be stored correctly :(
|
---|
247 | fRunHeader->SetNumEvents(fRunHeader->GetNumEvents()+1);
|
---|
248 |
|
---|
249 | return kTRUE;
|
---|
250 | }
|
---|