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

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