source: trunk/MagicSoft/Mars/msimcamera/MSimSignalCam.cc@ 9483

Last change on this file since 9483 was 9347, checked in by tbretz, 16 years ago
*** empty log message ***
File size: 5.4 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// MSimSignalCam
28//
29// This task takes a photon list (MPhotonEvent) and converts it into
30// a MSignalCam container. Photons with kNightSky as source are not
31// considered. The arrival time is just the average arrival time
32// of the photons minus the one of the first.
33//
34// Input Containers:
35// MPhotonEvent
36// MPhotonStatistics
37// [TriggerPos [MParameterD]]
38//
39// Output Containers:
40// MSignalCam
41//
42//////////////////////////////////////////////////////////////////////////////
43#include "MSimSignalCam.h"
44
45#include "MLog.h"
46#include "MLogManip.h"
47
48#include "MParList.h"
49#include "MParameters.h"
50
51#include "MSignalCam.h"
52#include "MSignalPix.h"
53
54#include "MPhotonEvent.h"
55#include "MPhotonData.h"
56
57ClassImp(MSimSignalCam);
58
59using namespace std;
60
61// --------------------------------------------------------------------------
62//
63// Default Constructor.
64//
65MSimSignalCam::MSimSignalCam(const char* name, const char *title)
66 : fEvt(0), fStat(0), fSignal(0), fTrigger(0)
67{
68 fName = name ? name : "MSimSignalCam";
69 fTitle = title ? title : "Task to convert a tagged MPhotonEvent list into MSignalCam";
70}
71
72// --------------------------------------------------------------------------
73//
74// Search for the necessary parameter containers
75//
76Int_t MSimSignalCam::PreProcess(MParList *pList)
77{
78 fEvt = (MPhotonEvent*)pList->FindObject("MPhotonEvent");
79 if (!fEvt)
80 {
81 *fLog << err << "MPhotonEvent not found... aborting." << endl;
82 return kFALSE;
83 }
84
85 fStat = (MPhotonStatistics*)pList->FindObject("MPhotonStatistics");
86 if (!fStat)
87 {
88 *fLog << err << "MPhotonStatistics not found... aborting." << endl;
89 return kFALSE;
90 }
91
92 fTrigger = (MParameterD*)pList->FindObject("TriggerPos", "MParameterD");
93/*
94 if (!fTrigger)
95 {
96 *fLog << err << "TriggerPos [MParameterD] not found... aborting." << endl;
97 return kFALSE;
98 }
99*/
100 fSignal = (MSignalCam*)pList->FindCreateObj("MSignalCam");
101 if (!fSignal)
102 return kFALSE;
103
104 return kTRUE;
105}
106
107// --------------------------------------------------------------------------
108//
109// Set the size, i.e. the number of pixels, from MSignalCam. It has to be
110// preset e.g. by MGeomApply in a preceeding ReInit.
111//
112Bool_t MSimSignalCam::ReInit(MParList *plist)
113{
114 const UInt_t npix = fSignal->GetNumPixels();
115
116 if (npix==0)
117 {
118 *fLog << err << "ERROR - MSignalCam has 0 entries. Presumably MGeomApply::ReInit not done." << endl;
119 return kFALSE;
120 }
121
122 if (fCont.GetSize()!=npix)
123 {
124 fCont.Set(npix);
125 fTime.Set(npix);
126 }
127
128 return kTRUE;
129}
130
131// --------------------------------------------------------------------------
132//
133// Loop over all photons to sum the photons and determine the average
134// arrival time. Write the result into the MSignalCam.
135//
136// Photons from the NSB are ignored.
137//
138Int_t MSimSignalCam::Process()
139{
140 // FIXME: Check the maximum index in GetTag from the statistics container
141 fCont.Reset();
142 fTime.Reset();
143
144 // Loop over all photons in the event
145 const UInt_t num = fEvt->GetNumPhotons();
146 for (UInt_t i=0; i<num; i++)
147 {
148 // Get i-th photon
149 const MPhotonData &ph = (*fEvt)[i];
150
151 // Reject photons from the night sky
152 if (ph.GetPrimary()==MMcEvtBasic::kNightSky)
153 continue;
154
155 // Get tag (must be the index tag!)
156 const Int_t idx = ph.GetTag();
157
158 // Reject untagged photons
159 if (idx<0)
160 continue;
161
162 // Calculate sum of time and photons
163 fCont[idx] += ph.GetWeight();
164 fTime[idx] += ph.GetTime()*ph.GetWeight();
165 }
166
167 // Get time of start point from the statistics container
168 // FIXME: Should be the real time of the first photon
169
170 // ====> Distance to trigger position! (if TrigPos found!)
171 // What about events with trigger<0?
172 const Float_t trig = fTrigger && fTrigger->GetVal()>=0 ? fTrigger->GetVal() : 0;
173 const Float_t first = fStat->GetTimeFirst()+trig;
174
175 // Loop over all pixels and set signal and arrival time.
176 // Set the pixels valid.
177 const UInt_t npix = fSignal->GetNumPixels();
178 for (UInt_t idx=0; idx<npix; idx++)
179 {
180 MSignalPix &pix = (*fSignal)[idx];
181
182 pix.SetNumPhotons(fCont[idx]);
183 pix.SetArrivalTime(fCont[idx]<=0 ? -1 : fTime[idx]/fCont[idx]-first);
184 pix.SetRing(fCont[idx]>0); // Used==1, Unused==0
185 pix.SetPixelCore(kFALSE);
186 }
187 fSignal->SetReadyToSave();
188
189 return kTRUE;
190}
Note: See TracBrowser for help on using the repository browser.