source: trunk/MagicSoft/Mars/msimcamera/MSimGeomCam.cc@ 9374

Last change on this file since 9374 was 9374, 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 "MRawRunHeader.h"
63
64#include "MPulseShape.h"
65
66ClassImp(MSimGeomCam);
67
68using namespace std;
69
70// --------------------------------------------------------------------------
71//
72// Default Constructor.
73//
74MSimGeomCam::MSimGeomCam(const char* name, const char *title)
75 : fGeom(0), fEvt(0), fStat(0), fPulsePos(0), fHeader(0), fPulse(0),
76 fNameGeomCam("MGeomCam")
77{
78 fName = name ? name : "MSimGeomCam";
79 fTitle = title ? title : "Task to tag each photon in a MPhotonEvent with a pixel index from a MGeomCam";
80}
81
82// --------------------------------------------------------------------------
83//
84// Search for the needed parameter containers.
85//
86Int_t MSimGeomCam::PreProcess(MParList *pList)
87{
88 fGeom = (MGeomCam*)pList->FindObject(fNameGeomCam, "MGeomCam");
89 if (!fGeom)
90 {
91 *fLog << inf << fNameGeomCam << " [MGeomCam] not found..." << endl;
92
93 fGeom = (MGeomCam*)pList->FindObject("MGeomCam");
94 if (!fGeom)
95 {
96 *fLog << err << "MGeomCam not found... aborting." << endl;
97 return kFALSE;
98 }
99 }
100
101 fEvt = (MPhotonEvent*)pList->FindObject("MPhotonEvent");
102 if (!fEvt)
103 {
104 *fLog << err << "MPhotonEvent not found... aborting." << endl;
105 return kFALSE;
106 }
107
108 fPulse = (MPulseShape*)pList->FindObject("MPulseShape");
109/*
110 if (!fPulse)
111 {
112 *fLog << err << "MPulsShape not found... aborting." << endl;
113 return kFALSE;
114 }
115 */
116 fPulsePos = (MParameterD*)pList->FindObject("IntendedPulsePos", "MParameterD");
117/*
118 if (!fPulsePos)
119 {
120 *fLog << err << "IntendedPulsePos [MParameterD] not found... aborting." << endl;
121 return kFALSE;
122 }
123*/
124 fHeader = (MRawRunHeader*)pList->FindObject("MRawRunHeader");
125 if (!fHeader)
126 {
127 *fLog << err << "MRawRunHeader not found... aborting." << endl;
128 return kFALSE;
129 }
130
131 fStat = (MPhotonStatistics*)pList->FindCreateObj("MPhotonStatistics");
132 if (!fStat)
133 return kFALSE;
134
135 return kTRUE;
136}
137
138
139// --------------------------------------------------------------------------
140//
141Int_t MSimGeomCam::Process()
142{
143 const Int_t num = fEvt->GetNumPhotons();
144
145 Int_t cnt = 0;
146 for (Int_t i=0; i<num; i++)
147 {
148 MPhotonData &ph = (*fEvt)[i];
149
150 //
151 // sum the photons content in each pixel
152 //
153 for (UInt_t idx=0; idx<fGeom->GetNumPixels(); idx++)
154 {
155 // FIXME: Improve search algorithm (2D Binary search?)
156 // Here we convert the photons from the ceres-coordinate
157 // system which is viewed from the camera to the mirror
158 // into the camera coordinates which are viewed from
159 // the mirror to the camera.
160 // (x on the right, y upwards, right-handed)
161 if (!(*fGeom)[idx].IsInside(-ph.GetPosX()*10, ph.GetPosY()*10))
162 continue;
163
164 ph.SetTag(idx);
165
166 (*fEvt)[cnt++] = ph;
167
168 break;
169 }
170 }
171
172 fEvt->Shrink(cnt);
173 //fEvt->Sort();
174
175 // ------ FIXME: Move somewhere else? MSimCalibrationSignal ------
176/*
177 if (!fEvt->IsSorted())
178 {
179 *fLog << err << "ERROR - MSimGeomCam: MPhotonEvent must be sorted!" << endl;
180 return kERROR;
181 }
182 */
183 const Float_t freq = fHeader->GetFreqSampling()/1000.;
184
185 // We add an additional sample at the end to support a possible shift
186 // of the start time of the first event by 0 to 1 sample.
187 const Int_t ns = fHeader->GetNumSamplesHiGain()+1;
188
189 const Float_t first = cnt>0 ? fEvt->GetTimeFirst() : 0;
190 const Float_t last = cnt>0 ? fEvt->GetTimeLast() : ns*freq;
191
192 // Length (ns), Pulse position (Units ns)
193 const Float_t pp = fPulsePos ? fPulsePos->GetVal() : 0;
194 const Float_t pw = fPulse ? fPulse->GetPulseWidth() : 0;
195
196 fStat->SetTimeMedDev(fEvt->GetTimeMedianDev());
197 fStat->SetTime(first-pp-pw, last-pp+pw + ns*freq);
198 fStat->SetLength(last-first);
199 fStat->SetMaxIndex(fGeom->GetNumPixels()-1);
200 fStat->SetReadyToSave();
201
202 // ----------------------------------------------------------------------
203
204 return kTRUE;
205}
206
207// --------------------------------------------------------------------------
208//
209// Read the parameters from the resource file.
210//
211// NameGeometry: MGeomCamDwarf
212//
213Int_t MSimGeomCam::ReadEnv(const TEnv &env, TString prefix, Bool_t print)
214{
215 Bool_t rc = kFALSE;
216 if (IsEnvDefined(env, prefix, "NameGeometry", print))
217 {
218 rc = kTRUE;
219 SetNameGeomCam(GetEnvValue(env, prefix, "NameGeometry", fNameGeomCam));
220 // FIXME: What about setup of this container?
221 }
222
223 return rc;
224}
Note: See TracBrowser for help on using the repository browser.