source: trunk/MagicSoft/Mars/manalysis/MGeomApply.cc@ 8113

Last change on this file since 8113 was 7972, checked in by tbretz, 18 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 <fstream>
67
68#include <TObjString.h>
69
70#include "MLog.h"
71#include "MLogManip.h"
72
73#include "MParList.h"
74
75#include "MGeomCam.h"
76#include "MCamEvent.h"
77
78ClassImp(MGeomApply);
79
80using namespace std;
81
82// --------------------------------------------------------------------------
83//
84// Default constructor. MGeomCamMagic is the default geometry.
85//
86MGeomApply::MGeomApply(const char *name, const char *title)
87 : fGeomName("MGeomCamMagic"), fNamesList(0), fList(0)
88{
89 fName = name ? name : "MGeomApply";
90 fTitle = title ? title : "Task to apply geometry settings";
91}
92
93// --------------------------------------------------------------------------
94//
95// Delete fList if available.
96//
97MGeomApply::~MGeomApply()
98{
99 if (fList)
100 delete fList;
101 if (fNamesList)
102 delete fNamesList;
103}
104
105// --------------------------------------------------------------------------
106//
107// Try to find 'MGeomCam' in the Parameter List. If it is not found,
108// try to create a fGeomName object.
109//
110Int_t MGeomApply::PreProcess(MParList *pList)
111{
112 MGeomCam *cam = (MGeomCam*)pList->FindObject(AddSerialNumber("MGeomCam"));
113 if (cam)
114 return kTRUE;
115
116 cam = (MGeomCam*)pList->FindCreateObj(AddSerialNumber(fGeomName), "MGeomCam");
117
118 return cam ? kTRUE : kFALSE;
119}
120
121// --------------------------------------------------------------------------
122//
123// Check the whole parameter list for MCamEvent. For all MCamEvent
124// MCamEvent::Init(MGeomCam&) is called.
125//
126void MGeomApply::ProcessAutomatic(MParList &list, const MGeomCam &geom) const
127{
128 TIter Next(list);
129 TObject *o = 0;
130
131 while ((o=Next()))
132 {
133 MCamEvent *cam = dynamic_cast<MCamEvent*>(o);
134 if (!cam)
135 continue;
136
137 // If the MGeomApply task has a serial number >0 (indicating most likely
138 // a specific telescope in a multi-telescope file), then apply the
139 // geometry only to objects with the same serial number. This is important
140 // for stereo setups in which the telescopes have cameras with different
141 // numbers of pixels. If the MGeomApply task has serial number 0 (default),
142 // it will apply the geometry to all found objects as it used to do.
143 const TString name(o->GetName());
144
145 // Extract serial number from name:
146 const Int_t serial = atoi(name.Data()+name.Last(';')+1);
147
148 // Compare with the serial number of this task:
149 if (serial>0 && serial!=GetSerialNumber())
150 continue;
151
152 // Initialize object according to camera geometry:
153 cam->Init(geom);
154 }
155}
156
157// --------------------------------------------------------------------------
158//
159// Check all containers in fNamesList and fList. For all MCamEvent
160// MCamEvent::Init(MGeomCam&) is called.
161//
162Bool_t MGeomApply::ProcessManual(MParList &list, const MGeomCam &geom) const
163{
164 TIter NextN(fNamesList);
165 TObject *o = 0;
166
167 while ((o=NextN()))
168 {
169 TObject *cont = list.FindObject(o->GetName(), "MCamEvent");
170 if (!cont)
171 {
172 *fLog << err << o->GetName() << " [MCamEvent] not found... abort." << endl;
173 return kFALSE;
174 }
175
176 MCamEvent *cam = dynamic_cast<MCamEvent*>(o);
177 cam->Init(geom);
178 }
179
180 TIter NextL(fList);
181 while ((o=NextL()))
182 {
183 MCamEvent *cam = dynamic_cast<MCamEvent*>(o);
184 cam->Init(geom);
185 }
186
187 return kTRUE;
188}
189
190// --------------------------------------------------------------------------
191//
192// Try to find 'MGeomCam' in the Parameter List. If it is not found,
193// processing is stopped.
194//
195Bool_t MGeomApply::ReInit(MParList *pList)
196{
197 MGeomCam *geom = (MGeomCam*)pList->FindObject(AddSerialNumber("MGeomCam"));
198 if (!geom)
199 {
200 *fLog << err << GetDescriptor() << ": No MGeomCam found... aborting." << endl;
201 return kFALSE;
202 }
203
204 // FIXME, workaround: this call to CalcPixRatio is here just to allow
205 // the use of some MC camera files from the 0.7 beta version in which the
206 // array containing pixel ratios is not initialized.
207 geom->CalcPixRatio();
208
209 if (fList)
210 return ProcessManual(*pList, *geom);
211
212 ProcessAutomatic(*pList, *geom);
213
214 return kTRUE;
215}
216
217// --------------------------------------------------------------------------
218//
219// Implementation of SavePrimitive. Used to write the call to a constructor
220// to a macro. In the original root implementation it is used to write
221// gui elements to a macro-file.
222//
223void MGeomApply::StreamPrimitive(ostream &out) const
224{
225 out << " " << ClassName() << " " << GetUniqueName() << "(\"";
226 out << "\"" << fName << "\", \"" << fTitle << "\");" << endl;
227
228 if (fGeomName.IsNull())
229 return;
230
231 out << " " << GetUniqueName() << ".SetGeometry(\"";
232 out << fGeomName << "\");" << endl;
233}
234
235// --------------------------------------------------------------------------
236//
237// Add a MCamEvent to be processed. This switches off the automatic
238// processing of all MCamEvent in the parameter list completely!
239//
240void MGeomApply::AddCamEvent(TObject *obj)
241{
242 if (!obj->InheritsFrom(MCamEvent::Class()))
243 {
244 *fLog << warn << "MGeomApply::AddCamEvent - WARNING: Object doesn't inherit from MCamEvent... ignored." << endl;
245 return;
246 }
247
248 if (!fList)
249 {
250 fList = new TList;
251 fNamesList = new TList;
252
253 fNamesList->SetOwner();
254 }
255
256 fList->Add(obj);
257}
258
259// --------------------------------------------------------------------------
260//
261// Add a MCamEvent to be processed. This switches off the automatic
262// processing of all MCamEvent in the parameter list completely!
263//
264void MGeomApply::AddCamEvent(const char *name)
265{
266 if (!fList)
267 {
268 fList = new TList;
269 fNamesList = new TList;
270
271 fNamesList->SetOwner();
272 }
273
274 fNamesList->Add(new TObjString(name));
275}
Note: See TracBrowser for help on using the repository browser.