source: trunk/Mars/msimcamera/MSimGeomCam.cc@ 20026

Last change on this file since 20026 was 19663, checked in by tbretz, 5 years ago
last is the number of samples converted to nanoseconds, the conversion was wrong -- fixed. Renamed ns to win for a better readability. The pulse spline x-axis is samples, not nano-seconds, added the conversion factor. Added a longer comment about the calculation.
File size: 7.0 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// MSimGeomCam
28//
29// This task takes a photon list from a MPhotonEvent and checks which pixel
30// from a MGeomCam is hit. The photons are tagged with the corresponding
31// index.
32//
33// Additionally (and provisionally) it also calculates the photon event
34// statistics.
35//
36// Input Containers:
37// MPhotonEvent
38// fNameGeomCam [MGeomCam]
39// MRawRunHeader
40// [IntendedPulsePos [MParameterD]]
41// [MPulseShape]
42//
43// Output Containers:
44// MPhotonStatistics
45// -/-
46//
47//////////////////////////////////////////////////////////////////////////////
48#include "MSimGeomCam.h"
49
50#include "MLog.h"
51#include "MLogManip.h"
52
53#include "MParList.h"
54
55#include "MGeomCam.h"
56#include "MGeom.h"
57
58#include "MPhotonEvent.h"
59#include "MPhotonData.h"
60
61#include "MParameters.h"
62#include "MParSpline.h"
63#include "MRawRunHeader.h"
64
65ClassImp(MSimGeomCam);
66
67using namespace std;
68
69// --------------------------------------------------------------------------
70//
71// Default Constructor.
72//
73MSimGeomCam::MSimGeomCam(const char* name, const char *title)
74 : fGeom(0), fEvt(0), fStat(0), fPulsePos(0), fHeader(0), fPulse(0),
75 fNameGeomCam("MGeomCam")
76{
77 fName = name ? name : "MSimGeomCam";
78 fTitle = title ? title : "Task to tag each photon in a MPhotonEvent with a pixel index from a MGeomCam";
79}
80
81// --------------------------------------------------------------------------
82//
83// Search for the needed parameter containers.
84//
85Int_t MSimGeomCam::PreProcess(MParList *pList)
86{
87 fGeom = (MGeomCam*)pList->FindObject(fNameGeomCam, "MGeomCam");
88 if (!fGeom)
89 {
90 *fLog << inf << fNameGeomCam << " [MGeomCam] not found..." << endl;
91
92 fGeom = (MGeomCam*)pList->FindObject("MGeomCam");
93 if (!fGeom)
94 {
95 *fLog << err << "MGeomCam not found... aborting." << endl;
96 return kFALSE;
97 }
98 }
99
100 fEvt = (MPhotonEvent*)pList->FindObject("MPhotonEvent");
101 if (!fEvt)
102 {
103 *fLog << err << "MPhotonEvent not found... aborting." << endl;
104 return kFALSE;
105 }
106
107 fPulse = (MParSpline*)pList->FindObject("PulseShape", "MParSpline");
108/*
109 if (!fPulse)
110 {
111 *fLog << err << "MPulsShape not found... aborting." << endl;
112 return kFALSE;
113 }
114 */
115 fPulsePos = (MParameterD*)pList->FindObject("IntendedPulsePos", "MParameterD");
116/*
117 if (!fPulsePos)
118 {
119 *fLog << err << "IntendedPulsePos [MParameterD] not found... aborting." << endl;
120 return kFALSE;
121 }
122*/
123 fHeader = (MRawRunHeader*)pList->FindObject("MRawRunHeader");
124 if (!fHeader)
125 {
126 *fLog << err << "MRawRunHeader not found... aborting." << endl;
127 return kFALSE;
128 }
129
130 fStat = (MPhotonStatistics*)pList->FindCreateObj("MPhotonStatistics");
131 if (!fStat)
132 return kFALSE;
133
134 return kTRUE;
135}
136
137
138// --------------------------------------------------------------------------
139//
140Int_t MSimGeomCam::Process()
141{
142 const Int_t num = fEvt->GetNumPhotons();
143
144 Int_t cnt = 0;
145 for (Int_t i=0; i<num; i++)
146 {
147 MPhotonData &ph = (*fEvt)[i];
148
149 //
150 // sum the photons content in each pixel
151 //
152 for (UInt_t idx=0; idx<fGeom->GetNumPixels(); idx++)
153 {
154 // FIXME: Improve search algorithm (2D Binary search?)
155 // Here we convert the photons from the ceres-coordinate
156 // system which is viewed from the camera to the mirror
157 // into the camera coordinates which are viewed from
158 // the mirror to the camera.
159 // (x on the right, y upwards, right-handed)
160 if (!(*fGeom)[idx].IsInside(-ph.GetPosX()*10, ph.GetPosY()*10))
161 continue;
162
163 ph.SetTag(idx);
164
165 (*fEvt)[cnt++] = ph;
166
167 break;
168 }
169 }
170
171 fEvt->Shrink(cnt);
172 //fEvt->Sort();
173
174 // ------ FIXME: Move somewhere else? MSimCalibrationSignal ------
175/*
176 if (!fEvt->IsSorted())
177 {
178 *fLog << err << "ERROR - MSimGeomCam: MPhotonEvent must be sorted!" << endl;
179 return kERROR;
180 }
181 */
182 const Float_t freq = fHeader->GetFreqSampling()/1000.;
183
184 // We add an additional sample at the end to support a possible shift
185 // of the start time of the first event by 0 to 1 sample.
186 const Float_t win = (fHeader->GetNumSamplesHiGain()+1)/freq;
187
188 // First and last photon in event (in nano-seconds)
189 const Float_t first = cnt>0 ? fEvt->GetTimeFirst() : 0;
190 const Float_t last = cnt>0 ? fEvt->GetTimeLast() : win;
191
192 // Length (ns), Pulse position (Units ns)
193 const Float_t pp = fPulsePos ? fPulsePos->GetVal() : 0;
194 const Float_t pw = fPulse ? fPulse->GetWidth()/freq : 0;
195
196 // If the trigger is ssupposed to be at position (pp),
197 // then we have to start our sampling pp before
198 // the first photon (first-pp). To have the tail
199 // of a possible previous pulse at the beginning
200 // of the window properly samples, we have to start
201 // sampling (pw) nanoseconds earlier,
202 // thus at: first-pw-pp
203 //
204 // The last possible readout window starts pp before
205 // the last photon and lasts for a width corresponding
206 // to the number of samples (win). The last pulse
207 // that should be reaosnable added to the readout
208 // window is the one which comes at the end.
209
210 fStat->SetTimeMedDev(fEvt->GetTimeMedianDev());
211 fStat->SetTime(first-pp-pw, last-pp + win);
212 fStat->SetLength(last-first);
213 fStat->SetMaxIndex(fGeom->GetNumPixels()-1);
214 fStat->SetReadyToSave();
215
216 // ----------------------------------------------------------------------
217
218 return kTRUE;
219}
220
221// --------------------------------------------------------------------------
222//
223// Read the parameters from the resource file.
224//
225// NameGeometry: MGeomCamDwarf
226//
227Int_t MSimGeomCam::ReadEnv(const TEnv &env, TString prefix, Bool_t print)
228{
229 Bool_t rc = kFALSE;
230 if (IsEnvDefined(env, prefix, "NameGeometry", print))
231 {
232 rc = kTRUE;
233 SetNameGeomCam(GetEnvValue(env, prefix, "NameGeometry", fNameGeomCam));
234 // FIXME: What about setup of this container?
235 }
236
237 return rc;
238}
Note: See TracBrowser for help on using the repository browser.