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

Last change on this file since 10805 was 9425, checked in by tbretz, 16 years ago
*** empty log message ***
File size: 6.3 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 Int_t ns = fHeader->GetNumSamplesHiGain()+1;
187
188 const Float_t first = cnt>0 ? fEvt->GetTimeFirst() : 0;
189 const Float_t last = cnt>0 ? fEvt->GetTimeLast() : ns*freq;
190
191 // Length (ns), Pulse position (Units ns)
192 const Float_t pp = fPulsePos ? fPulsePos->GetVal() : 0;
193 const Float_t pw = fPulse ? fPulse->GetWidth() : 0;
194
195 fStat->SetTimeMedDev(fEvt->GetTimeMedianDev());
196 fStat->SetTime(first-pp-pw, last-pp+pw + ns*freq);
197 fStat->SetLength(last-first);
198 fStat->SetMaxIndex(fGeom->GetNumPixels()-1);
199 fStat->SetReadyToSave();
200
201 // ----------------------------------------------------------------------
202
203 return kTRUE;
204}
205
206// --------------------------------------------------------------------------
207//
208// Read the parameters from the resource file.
209//
210// NameGeometry: MGeomCamDwarf
211//
212Int_t MSimGeomCam::ReadEnv(const TEnv &env, TString prefix, Bool_t print)
213{
214 Bool_t rc = kFALSE;
215 if (IsEnvDefined(env, prefix, "NameGeometry", print))
216 {
217 rc = kTRUE;
218 SetNameGeomCam(GetEnvValue(env, prefix, "NameGeometry", fNameGeomCam));
219 // FIXME: What about setup of this container?
220 }
221
222 return rc;
223}
Note: See TracBrowser for help on using the repository browser.