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

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