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

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