source: trunk/MagicSoft/Mars/msimcamera/MSimBundlePhotons.cc@ 9275

Last change on this file since 9275 was 9243, checked in by tbretz, 16 years ago
*** empty log message ***
File size: 5.7 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// MSimBundlePhotons
28//
29// This task sets a new tag (index) for all photons in a list MPhotonEvent
30// based on a look-up table.
31//
32// Input:
33// MPhotonEvent
34// MPhotonStatistics
35//
36// Output
37// MPhotonEvent
38//
39//////////////////////////////////////////////////////////////////////////////
40#include "MSimBundlePhotons.h"
41
42#include "MLog.h"
43#include "MLogManip.h"
44
45#include "MArrayI.h"
46
47#include "MParList.h"
48
49#include "MPhotonEvent.h"
50#include "MPhotonData.h"
51
52ClassImp(MSimBundlePhotons);
53
54using namespace std;
55
56// --------------------------------------------------------------------------
57//
58// Default Constructor.
59//
60MSimBundlePhotons::MSimBundlePhotons(const char* name, const char *title)
61: fEvt(0), fStat(0)//, fFileName("mreflector/dwarf-apdmap.txt")
62{
63 fName = name ? name : "MSimBundlePhotons";
64 fTitle = title ? title : "Task to bundle (re-index) photons according to a look-up table";
65}
66
67// --------------------------------------------------------------------------
68//
69// Check for the needed containers and read the oruting table.
70//
71Int_t MSimBundlePhotons::PreProcess(MParList *pList)
72{
73 fEvt = (MPhotonEvent*)pList->FindObject("MPhotonEvent");
74 if (!fEvt)
75 {
76 *fLog << err << "MPhotonEvent not found... aborting." << endl;
77 return kFALSE;
78 }
79
80 fStat = (MPhotonStatistics*)pList->FindObject("MPhotonStatistics");
81 if (!fStat)
82 {
83 *fLog << err << "MPhotonStatistics not found... aborting." << endl;
84 return kFALSE;
85 }
86
87 if (fFileName.IsNull())
88 return kSKIP;
89
90 // Read the look-up table
91 if (fLut.ReadFile(fFileName)<0)
92 return kFALSE;
93
94 // If the table is empty remove this task from the tasklist
95 if (fLut.IsEmpty())
96 return kSKIP;
97
98 // Now invert the tablee. Otherwise we have to do a lot of
99 // searching for every index.
100 fLut.Invert();
101
102 // Make sure that each line has exactly one row
103 if (!fLut.HasConstantLength() && fLut.GetMaxEntries()!=1)
104 return kFALSE;
105
106 return kTRUE;
107}
108
109// --------------------------------------------------------------------------
110//
111// Re-index all photons according to the look-up table.
112//
113Int_t MSimBundlePhotons::Process()
114{
115 // Make sure that we don't get a seg-fault
116 /*
117 if (fStat->GetMaxIndex()>=fLut.GetEntriesFast())
118 {
119 *fLog << err;
120 *fLog << "ERROR - MSimBundlePhotons::Process: Maximum pixel index stored" << endl;
121 *fLog << " in tag of MPhotonData exceeds the look-up table length." << endl;
122 return kERROR;
123 }*/
124
125 // FIXME: Add a range check comparing the min and max tag with
126 // the number of entries in the routing table
127
128 // Get total number of photons
129 const Int_t num = fEvt->GetNumPhotons();
130
131 // If there are no photons we can do nothing
132 if (num==0)
133 return kTRUE;
134
135 // Get maximum index allowed
136 const Int_t max = fLut.GetEntriesFast();
137
138 // Initialize a counter for the final number of photons.
139 Int_t cnt=0;
140
141 // Loop over all photons
142 for (Int_t i=0; i<num; i++)
143 {
144 // Get i-th photon from array
145 MPhotonData &ph = (*fEvt)[i];
146
147 // Get pixel index (tag) from photon
148 const Int_t tag = ph.GetTag();
149
150 // Check if the photon was tagged at all and
151 // whether the corresponding lut entry exists
152 if (tag<0 || tag>=max)
153 continue;
154
155 // Get the routing assigned to this index
156 const MArrayI &row = fLut.GetRow(tag);
157
158 // Sanity check: Check if we were routed to a
159 // valid entry if not throw away this photon.
160 if (row.GetSize()==0)
161 continue;
162
163 // Get corresponding entry from routing table
164 const Int_t &idx = row[0];
165
166 // Check if we were routed to a valid entry
167 // if not throw away this photon.
168 if (idx<0)
169 continue;
170
171 // Set Tag to new index
172 ph.SetTag(idx);
173
174 // Copy photon to its now position in array and increade counter
175 (*fEvt)[cnt++] = ph;
176 }
177
178 // Shrink the list of photons to its new size
179 fEvt->Shrink(cnt);
180
181 // Set new maximum index (Note, that this is the maximum index
182 // available in the LUT, which does not necessarily correspond
183 // to, e.g., the number of pixels although it should)
184 fStat->SetMaxIndex(fLut.GetMaxIndex());
185
186 return kTRUE;
187}
188
189// --------------------------------------------------------------------------
190//
191// FileName: lut.txt
192//
193Int_t MSimBundlePhotons::ReadEnv(const TEnv &env, TString prefix, Bool_t print)
194{
195 Bool_t rc = kFALSE;
196 if (IsEnvDefined(env, prefix, "FileName", print))
197 {
198 rc = kTRUE;
199 fFileName = GetEnvValue(env, prefix, "FileName", fFileName);
200 }
201
202 return rc;
203}
Note: See TracBrowser for help on using the repository browser.