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

Last change on this file since 9308 was 9308, checked in by tbretz, 16 years ago
*** empty log message ***
File size: 5.8 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 if (!(*fGeom)[idx].IsInside(ph.GetPosX()*10, ph.GetPosY()*10))
151 continue;
152
153 ph.SetTag(idx);
154
155 (*fEvt)[cnt++] = ph;
156
157 break;
158 }
159 }
160
161 fEvt->Shrink(cnt);
162 //fEvt->Sort();
163
164 // ------ FIXME: Move somewhere else? MSimCalibrationSignal ------
165
166 if (!fEvt->IsSorted())
167 {
168 *fLog << err << "ERROR - MPhotonEvent must be sorted!" << endl;
169 return kERROR;
170 }
171
172 const Float_t freq = fHeader->GetFreqSampling()/1000.;
173
174 // We add an additional sample at the end to support a possible shift
175 // of the start time of the first event by 0 to 1 sample.
176 const Int_t ns = fHeader->GetNumSamplesHiGain()+1;
177
178 const Float_t first = cnt>0 ? fEvt->GetFirst()->GetTime() : 0;
179 const Float_t last = cnt>0 ? fEvt->GetLast()->GetTime() : ns*freq;
180
181 // Length (ns), Pulse position (Units ns)
182 const Float_t pp = fPulsePos->GetVal();
183 const Float_t pw = fPulse->GetPulseWidth();
184
185 fStat->SetTime(first-pp-pw, last-pp+pw + ns*freq);
186 fStat->SetMaxIndex(fGeom->GetNumPixels()-1);
187 fStat->SetReadyToSave();
188
189 // ----------------------------------------------------------------------
190
191 return kTRUE;
192}
193
194// --------------------------------------------------------------------------
195//
196// Read the parameters from the resource file.
197//
198// NameGeometry: MGeomCamDwarf
199//
200Int_t MSimGeomCam::ReadEnv(const TEnv &env, TString prefix, Bool_t print)
201{
202 Bool_t rc = kFALSE;
203 if (IsEnvDefined(env, prefix, "NameGeometry", print))
204 {
205 rc = kTRUE;
206 SetNameGeomCam(GetEnvValue(env, prefix, "NameGeometry", fNameGeomCam));
207 // FIXME: What about setup of this container?
208 }
209
210 return rc;
211}
Note: See TracBrowser for help on using the repository browser.