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