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

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