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

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