source: tags/Mars-V2.2/msimcamera/MSimCamera.cc

Last change on this file was 9274, checked in by tbretz, 16 years ago
*** empty log message ***
File size: 6.4 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// MSimCamera
28//
29// This task initializes the analog channels with analog noise and simulated
30// the analog pulses from the photon signal.
31//
32// Input Containers:
33// MPhotonEvent
34// MPhotonStatistics
35// MRawRunHeader
36//
37// Output Containers:
38// MAnalogChannels
39//
40//////////////////////////////////////////////////////////////////////////////
41#include "MSimCamera.h"
42
43#include <TF1.h>
44
45#include "MLog.h"
46#include "MLogManip.h"
47
48#include "MSpline3.h"
49#include "MPulseShape.h"
50
51#include "MParList.h"
52//#include "MParameters.h"
53
54#include "MPhotonEvent.h"
55#include "MPhotonData.h"
56
57#include "MAnalogSignal.h"
58#include "MAnalogChannels.h"
59
60#include "MRawRunHeader.h"
61
62ClassImp(MSimCamera);
63
64using namespace std;
65
66// --------------------------------------------------------------------------
67//
68// Default Constructor.
69//
70MSimCamera::MSimCamera(const char* name, const char *title)
71: fEvt(0), fStat(0), fRunHeader(0), fCamera(0), fSpline(0)//, fPulsePos(0)
72{
73 fName = name ? name : "MSimCamera";
74 fTitle = title ? title : "Task to simulate the electronic noise and to convert photons into pulses";
75}
76
77// --------------------------------------------------------------------------
78//
79// Search for the necessayr parameter containers.
80// Setup spline for pulse shape.
81//
82Int_t MSimCamera::PreProcess(MParList *pList)
83{
84 fCamera = (MAnalogChannels*)pList->FindCreateObj("MAnalogChannels");
85 if (!fCamera)
86 return kFALSE;
87
88 fEvt = (MPhotonEvent*)pList->FindObject("MPhotonEvent");
89 if (!fEvt)
90 {
91 *fLog << err << "MPhotonEvent not found... aborting." << endl;
92 return kFALSE;
93 }
94
95 fStat = (MPhotonStatistics*)pList->FindObject("MPhotonStatistics");
96 if (!fStat)
97 {
98 *fLog << err << "MPhotonStatistics not found... aborting." << endl;
99 return kFALSE;
100 }
101
102 fRunHeader = (MRawRunHeader *)pList->FindObject("MRawRunHeader");
103 if (!fRunHeader)
104 {
105 *fLog << err << "MRawRunHeader 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 MPulseShape *pulse = (MPulseShape*)pList->FindObject("MPulseShape");
117 if (!pulse)
118 {
119 *fLog << err << "MPulseShape not found... aborting." << endl;
120 return kFALSE;
121 }
122
123 *fLog << warn << "FIXME - SCALE WITH THE SAMPLING FREQUENCY." << endl;
124
125 fSpline = pulse->GetSpline();
126 if (!fSpline)
127 {
128 *fLog << err << "No spline initialized." << endl;
129 return kFALSE;
130 }
131
132 return kTRUE;
133}
134
135// --------------------------------------------------------------------------
136//
137// fStat->GetMaxIndex must return the maximum index possible
138// (equiv. number of pixels) not just the maximum index stored!
139//
140Int_t MSimCamera::Process()
141{
142 // Calculate start time, end time and corresponding number of samples
143 const Double_t freq = fRunHeader->GetFreqSampling()/1000.;
144
145 const Double_t start = fStat->GetTimeFirst()*freq;
146 const Double_t end = fStat->GetTimeLast() *freq;
147
148 const UInt_t nlen = TMath::CeilNint(end-start);
149
150 // FIXME: Jitter the start point of digitization by one sample [0;1]
151 // FIXME: TAKE PULSE WIDTH out of the calculation and start at TimeFirst
152
153 // Get number of pixels/channels
154 const UInt_t npix = fStat->GetMaxIndex()+1;
155
156 const Double_t pl = fSpline->GetXmin()*freq;
157 const Double_t pr = fSpline->GetXmax()*freq;
158
159 // Init the arrays and set the range which will contain valid data
160 fCamera->Init(npix, nlen);
161 fCamera->SetValidRange(TMath::FloorNint(pr), TMath::CeilNint(nlen+pl));
162
163 // Add electronic noise to empty channels
164 for (UInt_t i=0; i<npix; i++)
165 {
166 // FIXME: We might add the base line here already.
167 (*fCamera)[i].AddGaussianNoise(22.5/64);
168 }
169
170 // FIXME: Simulate correlations with neighboring pixels
171
172 const Int_t num = fEvt->GetNumPhotons();
173
174 // Simulate pulses
175 for (Int_t i=0; i<num; i++)
176 {
177 const MPhotonData &ph = (*fEvt)[i];
178
179 const UInt_t idx = ph.GetTag();
180 const Double_t t = (ph.GetTime()-fStat->GetTimeFirst())*freq;// - fSpline->GetXmin();
181
182 // FIXME: Time jitter?
183 // FIXME: Add additional routing here?
184
185 // === FIXME === FIXME === FIXME === Frequency!!!!
186 (*fCamera)[idx].AddPulse(*fSpline, t, ph.GetWeight());
187 }
188
189 return kTRUE;
190}
191
192/*
193MSimCameraFiles::Process()
194{
195 // fCorsikaHeader->GetEvtNumber() --> fMcEvt->SetEvtNumber()
196 // fCorsikaHeader->GetTotalEnergy() --> fMcEvt->SetEnergy()
197 // fCorsikaHeader->GetParticleID() --> fMcEvt->SetParticleID()
198 // fCorsikaHeader->GetImpact() --> fMcEvt->SetImpact()
199 // fCorsikaHeader->GetTheta() --> fMcEvt->SetTheta()
200 // fCorsikaHeader->GetPhi() --> fMcEvt->SetPhi()
201 // fPointingPos->GetTheta() --> fMcEvt->SetTelescopeTheta()
202 // fPointingPos->GetPhi() --> fMcEvt->SetTelescopePhi()
203 // fStats->GetTimeFirst() --> fMcEvt->SetTimeFirst()
204 // fStats->GetTimeLast() --> fMcEvt->SetTimeLast()
205 // fMcEvt->SetReuse()
206 // MMcCorsikaRunHeader: fSlopeSpec, fELowLim, fEUppLim;
207
208 fMcEvt->Fill(*fCorsikaHeader, *fPointingPos, *fStats);
209
210 return kTRUE;
211}
212*/
213
Note: See TracBrowser for help on using the repository browser.