source: trunk/Mars/manalysis/MGeomApply.cc@ 10113

Last change on this file since 10113 was 9473, checked in by tbretz, 15 years ago
*** empty log message ***
File size: 8.0 KB
Line 
1/* ======================================================================== *\
2!
3! *
4! * This file is part of MARS, the MAGIC 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 appear 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, 09/2003 <mailto:tbretz@astro.uni-wuerzburg.de>
19! Markus Gaug, 03/2004 <mailto:markus@ifae.es>
20! Hendrik Bartko, 07/2003 <mailto:hbartko@mppmu.mpg.de>
21!
22! Copyright: MAGIC Software Development, 2000-2004
23!
24!
25\* ======================================================================== */
26//////////////////////////////////////////////////////////////////////////////
27//
28// MGeomApply
29//
30// Applies the geometry to geometry dependant containers.
31//
32// It changes the size of the arrays in the containers to a size
33// matching the number of pixels, eg:
34//
35// MPedestalCam
36// MCalibrationChargeCam
37// MCalibrationRelTimeCam
38// MCalibrationQECam
39// MCalibrationPedCam
40// MPedPhotCam
41// MExtractedSignalCam
42// MArrivalTime
43//
44// It uses the geometry (MGeomCam) found in the parameter list.
45// If it is not found the task tries to create the geometry
46// specified in the constructor. The default geometry is
47// MGeomCamMagic.
48//
49// In a standard setup all containers in the parameter list which derive
50// from MCamEvent are processed automatically in ReInit. To allow having
51// two parallel geometries in the parameter list or for MCamEvent in the
52// parameter list you can switch off the automatic procedure by adding
53// the containers to be processed using AddCamEvent().
54//
55//
56// Input Containers:
57// [MGeomCam]
58// [all MCamEvent]
59//
60// Output Containers:
61// [all MCamEvent]
62//
63//////////////////////////////////////////////////////////////////////////////
64#include "MGeomApply.h"
65
66#include <stdlib.h> // atoi (Ubuntu 8.10)
67
68#include <fstream>
69
70#include <TObjString.h>
71
72#include "MLog.h"
73#include "MLogManip.h"
74
75#include "MParList.h"
76
77#include "MGeomCam.h"
78#include "MCamEvent.h"
79
80ClassImp(MGeomApply);
81
82using namespace std;
83
84// --------------------------------------------------------------------------
85//
86// Default constructor. MGeomCamMagic is the default geometry.
87//
88MGeomApply::MGeomApply(const char *name, const char *title)
89 : fGeomName("MGeomCamMagic"), fNamesList(0), fList(0)
90{
91 fName = name ? name : "MGeomApply";
92 fTitle = title ? title : "Task to apply geometry settings";
93}
94
95// --------------------------------------------------------------------------
96//
97// Delete fList if available.
98//
99MGeomApply::~MGeomApply()
100{
101 if (fList)
102 delete fList;
103 if (fNamesList)
104 delete fNamesList;
105}
106
107// --------------------------------------------------------------------------
108//
109// Try to find 'MGeomCam' in the Parameter List. If it is not found,
110// try to create a fGeomName object.
111//
112Int_t MGeomApply::PreProcess(MParList *pList)
113{
114 MGeomCam *cam = (MGeomCam*)pList->FindObject(AddSerialNumber("MGeomCam"));
115 if (cam)
116 return kTRUE;
117
118 cam = (MGeomCam*)pList->FindCreateObj(AddSerialNumber(fGeomName), "MGeomCam");
119
120 return cam ? kTRUE : kFALSE;
121}
122
123// --------------------------------------------------------------------------
124//
125// Check the whole parameter list for MCamEvent. For all MCamEvent
126// MCamEvent::Init(MGeomCam&) is called.
127//
128void MGeomApply::ProcessAutomatic(MParList &list, const MGeomCam &geom) const
129{
130 TIter Next(list);
131 TObject *o = 0;
132
133 while ((o=Next()))
134 {
135 MCamEvent *cam = dynamic_cast<MCamEvent*>(o);
136 if (!cam)
137 continue;
138
139 // If the MGeomApply task has a serial number >0 (indicating most likely
140 // a specific telescope in a multi-telescope file), then apply the
141 // geometry only to objects with the same serial number. This is important
142 // for stereo setups in which the telescopes have cameras with different
143 // numbers of pixels. If the MGeomApply task has serial number 0 (default),
144 // it will apply the geometry to all found objects as it used to do.
145 const TString name(o->GetName());
146
147 // Extract serial number from name:
148 const Int_t serial = atoi(name.Data()+name.Last(';')+1);
149
150 // Compare with the serial number of this task:
151 if (serial>0 && serial!=GetSerialNumber())
152 continue;
153
154 // Initialize object according to camera geometry:
155 cam->Init(geom);
156 }
157}
158
159// --------------------------------------------------------------------------
160//
161// Check all containers in fNamesList and fList. For all MCamEvent
162// MCamEvent::Init(MGeomCam&) is called.
163//
164Bool_t MGeomApply::ProcessManual(MParList &list, const MGeomCam &geom) const
165{
166 TIter NextN(fNamesList);
167 TObject *o = 0;
168
169 while ((o=NextN()))
170 {
171 TObject *cont = list.FindObject(o->GetName(), "MCamEvent");
172 if (!cont)
173 {
174 *fLog << err << o->GetName() << " [MCamEvent] not found... abort." << endl;
175 return kFALSE;
176 }
177
178 MCamEvent *cam = dynamic_cast<MCamEvent*>(o);
179 cam->Init(geom);
180 }
181
182 TIter NextL(fList);
183 while ((o=NextL()))
184 {
185 MCamEvent *cam = dynamic_cast<MCamEvent*>(o);
186 cam->Init(geom);
187 }
188
189 return kTRUE;
190}
191
192// --------------------------------------------------------------------------
193//
194// Try to find 'MGeomCam' in the Parameter List. If it is not found,
195// processing is stopped.
196//
197Bool_t MGeomApply::ReInit(MParList *pList)
198{
199 MGeomCam *geom = (MGeomCam*)pList->FindObject(AddSerialNumber("MGeomCam"));
200 if (!geom)
201 {
202 *fLog << err << GetDescriptor() << ": No MGeomCam found... aborting." << endl;
203 return kFALSE;
204 }
205
206 // FIXME (workaround): this call to CalcPixRatio is here just to allow
207 // the use of some MC camera files from the 0.7 beta version in which the
208 // array containing pixel ratios is not initialized.
209 geom->StreamerWorkaround();
210 geom->CalcPixRatio();
211
212 if (fList)
213 return ProcessManual(*pList, *geom);
214
215 ProcessAutomatic(*pList, *geom);
216
217 return kTRUE;
218}
219
220// --------------------------------------------------------------------------
221//
222// Implementation of SavePrimitive. Used to write the call to a constructor
223// to a macro. In the original root implementation it is used to write
224// gui elements to a macro-file.
225//
226void MGeomApply::StreamPrimitive(ostream &out) const
227{
228 out << " " << ClassName() << " " << GetUniqueName() << "(\"";
229 out << "\"" << fName << "\", \"" << fTitle << "\");" << endl;
230
231 if (fGeomName.IsNull())
232 return;
233
234 out << " " << GetUniqueName() << ".SetGeometry(\"";
235 out << fGeomName << "\");" << endl;
236}
237
238// --------------------------------------------------------------------------
239//
240// Add a MCamEvent to be processed. This switches off the automatic
241// processing of all MCamEvent in the parameter list completely!
242//
243void MGeomApply::AddCamEvent(TObject *obj)
244{
245 if (!obj->InheritsFrom(MCamEvent::Class()))
246 {
247 *fLog << warn << "MGeomApply::AddCamEvent - WARNING: Object doesn't inherit from MCamEvent... ignored." << endl;
248 return;
249 }
250
251 if (!fList)
252 {
253 fList = new TList;
254 fNamesList = new TList;
255
256 fNamesList->SetOwner();
257 }
258
259 fList->Add(obj);
260}
261
262// --------------------------------------------------------------------------
263//
264// Add a MCamEvent to be processed. This switches off the automatic
265// processing of all MCamEvent in the parameter list completely!
266//
267void MGeomApply::AddCamEvent(const char *name)
268{
269 if (!fList)
270 {
271 fList = new TList;
272 fNamesList = new TList;
273
274 fNamesList->SetOwner();
275 }
276
277 fNamesList->Add(new TObjString(name));
278}
Note: See TracBrowser for help on using the repository browser.