| 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): Eva Domingo , 12/2004 <mailto:domingo@ifae.es>
|
|---|
| 19 | ! Wolfgang Wittek, 12/2004 <mailto:wittek@mppmu.mpg.de>
|
|---|
| 20 | !
|
|---|
| 21 | ! Copyright: MAGIC Software Development, 2000-2005
|
|---|
| 22 | !
|
|---|
| 23 | !
|
|---|
| 24 | \* ======================================================================== */
|
|---|
| 25 |
|
|---|
| 26 | /////////////////////////////////////////////////////////////////////////////
|
|---|
| 27 | // //
|
|---|
| 28 | // MDispCalc //
|
|---|
| 29 | // //
|
|---|
| 30 | // This task calculates Disp //
|
|---|
| 31 | // (parameters are taken from the container MDisp) //
|
|---|
| 32 | // Also the matrix of variables to be used in the Disp optimization //
|
|---|
| 33 | // is defined //
|
|---|
| 34 | // //
|
|---|
| 35 | // //
|
|---|
| 36 | /////////////////////////////////////////////////////////////////////////////
|
|---|
| 37 | #include "MDispCalc.h"
|
|---|
| 38 |
|
|---|
| 39 | #include <math.h>
|
|---|
| 40 | #include <TArray.h>
|
|---|
| 41 |
|
|---|
| 42 | #include "MGeomCam.h"
|
|---|
| 43 | #include "MSrcPosCam.h"
|
|---|
| 44 | #include "MHillas.h"
|
|---|
| 45 | #include "MHillasExt.h"
|
|---|
| 46 | #include "MNewImagePar.h"
|
|---|
| 47 | #include "MMcEvt.hxx"
|
|---|
| 48 | #include "MPointingPos.h"
|
|---|
| 49 | #include "MImageParDisp.h"
|
|---|
| 50 | #include "MDisp.h"
|
|---|
| 51 |
|
|---|
| 52 | #include "MHMatrix.h"
|
|---|
| 53 |
|
|---|
| 54 | #include "MParList.h"
|
|---|
| 55 |
|
|---|
| 56 | #include "MLog.h"
|
|---|
| 57 | #include "MLogManip.h"
|
|---|
| 58 |
|
|---|
| 59 |
|
|---|
| 60 | ClassImp(MDispCalc);
|
|---|
| 61 |
|
|---|
| 62 | using namespace std;
|
|---|
| 63 |
|
|---|
| 64 | // --------------------------------------------------------------------------
|
|---|
| 65 | //
|
|---|
| 66 | // constructor
|
|---|
| 67 | //
|
|---|
| 68 | MDispCalc::MDispCalc(const char *imagepardispname, const char *dispname,
|
|---|
| 69 | const char *name, const char *title)
|
|---|
| 70 | : fImageParDispName(imagepardispname), fDispName(dispname)
|
|---|
| 71 | {
|
|---|
| 72 | fName = name ? name : "MDispCalc";
|
|---|
| 73 | fTitle = title ? title : "Class to calculate Disp";
|
|---|
| 74 |
|
|---|
| 75 | fMatrix = NULL;
|
|---|
| 76 |
|
|---|
| 77 | // initialize mapping array dimension to the number of columns of fMatrix
|
|---|
| 78 | fMap.Set(18);
|
|---|
| 79 | }
|
|---|
| 80 |
|
|---|
| 81 |
|
|---|
| 82 | // --------------------------------------------------------------------------
|
|---|
| 83 | //
|
|---|
| 84 | Int_t MDispCalc::PreProcess(MParList *pList)
|
|---|
| 85 | {
|
|---|
| 86 | // look for the defined camera geometry to get mm to deg conversion factor
|
|---|
| 87 | MGeomCam *cam = (MGeomCam*)pList->FindObject("MGeomCam");
|
|---|
| 88 | if (!cam)
|
|---|
| 89 | {
|
|---|
| 90 | *fLog << err << "MGeomCam (Camera Geometry) not found... aborting."
|
|---|
| 91 | << endl;
|
|---|
| 92 | return kFALSE;
|
|---|
| 93 | }
|
|---|
| 94 |
|
|---|
| 95 | fMm2Deg = cam->GetConvMm2Deg();
|
|---|
| 96 |
|
|---|
| 97 |
|
|---|
| 98 | // look for Disp related containers
|
|---|
| 99 | fImageParDisp = (MImageParDisp*)pList->FindCreateObj("MImageParDisp",
|
|---|
| 100 | fImageParDispName);
|
|---|
| 101 | if (!fImageParDisp)
|
|---|
| 102 | {
|
|---|
| 103 | *fLog << err << fImageParDispName
|
|---|
| 104 | << " [MImageParDisp] not found... aborting." << endl;
|
|---|
| 105 | return kFALSE;
|
|---|
| 106 | }
|
|---|
| 107 |
|
|---|
| 108 | fDisp = (MDisp*)pList->FindObject(fDispName, "MDisp");
|
|---|
| 109 | if (!fDisp)
|
|---|
| 110 | {
|
|---|
| 111 | *fLog << err << fDispName << " [MDisp] not found... aborting." << endl;
|
|---|
| 112 | return kFALSE;
|
|---|
| 113 | }
|
|---|
| 114 |
|
|---|
| 115 |
|
|---|
| 116 | //-----------------------------------------------------------
|
|---|
| 117 | // if fMatrix exists, skip preprocessing and just read events from matrix;
|
|---|
| 118 | // if doesn't exist, read variables values from containers, so look for them
|
|---|
| 119 | if (fMatrix)
|
|---|
| 120 | return kTRUE;
|
|---|
| 121 |
|
|---|
| 122 | fSrcPos = (MSrcPosCam*)pList->FindObject("MSrcPosCam");
|
|---|
| 123 | if (!fSrcPos)
|
|---|
| 124 | {
|
|---|
| 125 | *fLog << err << "MSrcPosCam not found... aborting." << endl;
|
|---|
| 126 | return kFALSE;
|
|---|
| 127 | }
|
|---|
| 128 |
|
|---|
| 129 | fHil = (MHillas*)pList->FindObject("MHillas");
|
|---|
| 130 | if (!fHil)
|
|---|
| 131 | {
|
|---|
| 132 | *fLog << err << "MHillas not found... aborting." << endl;
|
|---|
| 133 | return kFALSE;
|
|---|
| 134 | }
|
|---|
| 135 |
|
|---|
| 136 | fHilExt = (MHillasExt*)pList->FindObject("MHillasExt");
|
|---|
| 137 | if (!fHilExt)
|
|---|
| 138 | {
|
|---|
| 139 | *fLog << err << "MHillasExt not found... aborting." << endl;
|
|---|
| 140 | return kFALSE;
|
|---|
| 141 | }
|
|---|
| 142 |
|
|---|
| 143 | fNewPar = (MNewImagePar*)pList->FindObject("MNewImagePar");
|
|---|
| 144 | if (!fNewPar)
|
|---|
| 145 | {
|
|---|
| 146 | *fLog << err << "MNewImagePar not found... aborting." << endl;
|
|---|
| 147 | return kFALSE;
|
|---|
| 148 | }
|
|---|
| 149 |
|
|---|
| 150 | fMcEvt = (MMcEvt*)pList->FindObject("MMcEvt");
|
|---|
| 151 | if (!fMcEvt)
|
|---|
| 152 | {
|
|---|
| 153 | *fLog << err << "MMcEvt not found... This is not a MC file,"
|
|---|
| 154 | << " you are not trying to optimize Disp, just calculating it."
|
|---|
| 155 | << endl;
|
|---|
| 156 | // return kFALSE;
|
|---|
| 157 | }
|
|---|
| 158 |
|
|---|
| 159 | fPointing = (MPointingPos*)pList->FindObject("MPointingPos");
|
|---|
| 160 | if (!fPointing)
|
|---|
| 161 | {
|
|---|
| 162 | *fLog << err << "MPointingPos not found... "
|
|---|
| 163 | << "MMcEvt is going to be used to get Theta and Phi."
|
|---|
| 164 | << endl;
|
|---|
| 165 | // return kFALSE;
|
|---|
| 166 | }
|
|---|
| 167 |
|
|---|
| 168 | //------------------------------------------
|
|---|
| 169 |
|
|---|
| 170 | return kTRUE;
|
|---|
| 171 | }
|
|---|
| 172 |
|
|---|
| 173 |
|
|---|
| 174 | // --------------------------------------------------------------------------
|
|---|
| 175 | //
|
|---|
| 176 | // You can use this function if you want to use a MHMatrix instead of the
|
|---|
| 177 | // given containers for the Disp optimization. This function adds all
|
|---|
| 178 | // necessary columns to the given matrix. Afterwards, you should fill
|
|---|
| 179 | // the matrix with the corresponding data (eg from a file by using
|
|---|
| 180 | // MHMatrix::Fill). Then, if you loop through the matrix (eg using
|
|---|
| 181 | // MMatrixLoop), MDispCalc::Process will take the values from the matrix
|
|---|
| 182 | // instead of the containers.
|
|---|
| 183 | //
|
|---|
| 184 | void MDispCalc::InitMapping(MHMatrix *mat)
|
|---|
| 185 | {
|
|---|
| 186 | if (fMatrix)
|
|---|
| 187 | return;
|
|---|
| 188 |
|
|---|
| 189 | fMatrix = mat;
|
|---|
| 190 |
|
|---|
| 191 | fMap[0] = fMatrix->AddColumn("MSrcPosCam.fX");
|
|---|
| 192 | fMap[1] = fMatrix->AddColumn("MSrcPosCam.fY");
|
|---|
| 193 | fMap[2] = fMatrix->AddColumn("MHillas.fMeanX");
|
|---|
| 194 | fMap[3] = fMatrix->AddColumn("MHillas.fMeanY");
|
|---|
| 195 | fMap[4] = fMatrix->AddColumn("MHillas.fDelta");
|
|---|
| 196 |
|
|---|
| 197 | fMap[5] = fMatrix->AddColumn("MHillas.fSize");
|
|---|
| 198 | fMap[6] = fMatrix->AddColumn("MHillas.fWidth");
|
|---|
| 199 | fMap[7] = fMatrix->AddColumn("MHillas.fLength");
|
|---|
| 200 |
|
|---|
| 201 | fMap[8] = fMatrix->AddColumn("MNewImagePar.fConc");
|
|---|
| 202 | fMap[9] = fMatrix->AddColumn("MNewImagePar.fLeakage1");
|
|---|
| 203 | fMap[10] = fMatrix->AddColumn("MNewImagePar.fLeakage2");
|
|---|
| 204 |
|
|---|
| 205 | fMap[11] = fMatrix->AddColumn("MHillasExt.fM3Long");
|
|---|
| 206 | fMap[12] = fMatrix->AddColumn("MHillasExt.fAsym");
|
|---|
| 207 |
|
|---|
| 208 | fMap[13] = fMatrix->AddColumn("MMcEvt.fEnergy");
|
|---|
| 209 | fMap[14] = fMatrix->AddColumn("MMcEvt.fImpact");
|
|---|
| 210 | fMap[15] = fMatrix->AddColumn("MMcEvt.fLongitmax");
|
|---|
| 211 |
|
|---|
| 212 | if (fPointing)
|
|---|
| 213 | {
|
|---|
| 214 | fMap[16] = fMatrix->AddColumn("MPointingPos.fZd");
|
|---|
| 215 | fMap[17] = fMatrix->AddColumn("MPointingPos.fAz");
|
|---|
| 216 | }
|
|---|
| 217 | else
|
|---|
| 218 | {
|
|---|
| 219 | fMap[16] = fMatrix->AddColumn("MMcEvt.fTelescopeTheta*kRad2Deg");
|
|---|
| 220 | fMap[17] = fMatrix->AddColumn("MMcEvt.fTelescopePhi*kRad2Deg");
|
|---|
| 221 | }
|
|---|
| 222 | }
|
|---|
| 223 |
|
|---|
| 224 |
|
|---|
| 225 | // --------------------------------------------------------------------------
|
|---|
| 226 | //
|
|---|
| 227 | // Returns the Matrix and the mapped value for each Matrix column
|
|---|
| 228 | //
|
|---|
| 229 | MHMatrix* MDispCalc::GetMatrixMap(TArrayI &map)
|
|---|
| 230 | {
|
|---|
| 231 | map = fMap;
|
|---|
| 232 |
|
|---|
| 233 | return fMatrix;
|
|---|
| 234 | }
|
|---|
| 235 |
|
|---|
| 236 |
|
|---|
| 237 | // --------------------------------------------------------------------------
|
|---|
| 238 | //
|
|---|
| 239 | // Returns a mapped value from the Matrix
|
|---|
| 240 | //
|
|---|
| 241 | Double_t MDispCalc::GetVal(Int_t i) const
|
|---|
| 242 | {
|
|---|
| 243 | Double_t val = (*fMatrix)[fMap[i]];
|
|---|
| 244 |
|
|---|
| 245 | // *fLog << "MDispCalc::GetVal; i, fMatrix, fMap, val = "
|
|---|
| 246 | // << i << ", " << fMatrix << ", " << fMap[i] << ", " << val << endl;
|
|---|
| 247 |
|
|---|
| 248 | return val;
|
|---|
| 249 | }
|
|---|
| 250 |
|
|---|
| 251 |
|
|---|
| 252 | // ---------------------------------------------------------------------------
|
|---|
| 253 | //
|
|---|
| 254 | // Calculate Disp
|
|---|
| 255 | //
|
|---|
| 256 | //
|
|---|
| 257 | Int_t MDispCalc::Process()
|
|---|
| 258 | {
|
|---|
| 259 | // get variables needed to compute disp from the matrix or the containers
|
|---|
| 260 | const Double_t size = fMatrix ? GetVal(5) : fHil->GetSize();
|
|---|
| 261 | const Double_t width0 = fMatrix ? GetVal(6) : fHil->GetWidth();
|
|---|
| 262 | const Double_t length0 = fMatrix ? GetVal(7) : fHil->GetLength();
|
|---|
| 263 | const Double_t conc = fMatrix ? GetVal(8) : fNewPar->GetConc();
|
|---|
| 264 | const Double_t leakage1 = fMatrix ? GetVal(9) : fNewPar->GetLeakage1();
|
|---|
| 265 | const Double_t leakage2 = fMatrix ? GetVal(10) : fNewPar->GetLeakage2();
|
|---|
| 266 |
|
|---|
| 267 | // convert to deg
|
|---|
| 268 | const Double_t width = width0 * fMm2Deg;
|
|---|
| 269 | const Double_t length = length0 * fMm2Deg;
|
|---|
| 270 |
|
|---|
| 271 | // create an array to pass the variables to MDisp::Calc
|
|---|
| 272 | Int_t numimagevars = 6;
|
|---|
| 273 | TArrayD imagevars(numimagevars);
|
|---|
| 274 | imagevars[0] = log10(size);
|
|---|
| 275 | imagevars[1] = width;
|
|---|
| 276 | imagevars[2] = length;
|
|---|
| 277 | imagevars[3] = conc;
|
|---|
| 278 | imagevars[4] = leakage1;
|
|---|
| 279 | imagevars[5] = leakage2;
|
|---|
| 280 |
|
|---|
| 281 | // compute Disp
|
|---|
| 282 | Double_t disp = fDisp->Calc(imagevars);
|
|---|
| 283 |
|
|---|
| 284 | // save value into MImageParDisp container
|
|---|
| 285 | fImageParDisp->SetDisp(disp);
|
|---|
| 286 | fImageParDisp->SetReadyToSave();
|
|---|
| 287 |
|
|---|
| 288 | return kTRUE;
|
|---|
| 289 | }
|
|---|
| 290 | //===========================================================================
|
|---|
| 291 |
|
|---|
| 292 |
|
|---|
| 293 |
|
|---|
| 294 |
|
|---|