| 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 8/2004 <mailto:tbretz@astro.uni-wuerzburg.de>
|
|---|
| 19 | !
|
|---|
| 20 | ! Copyright: MAGIC Software Development, 2000-2004
|
|---|
| 21 | !
|
|---|
| 22 | !
|
|---|
| 23 | \* ======================================================================== */
|
|---|
| 24 |
|
|---|
| 25 | //////////////////////////////////////////////////////////////////////////////
|
|---|
| 26 | //
|
|---|
| 27 | // MSrcPosFromModel
|
|---|
| 28 | //
|
|---|
| 29 | //
|
|---|
| 30 | //////////////////////////////////////////////////////////////////////////////
|
|---|
| 31 | #include "MSrcPosFromModel.h"
|
|---|
| 32 |
|
|---|
| 33 | #include "MParList.h"
|
|---|
| 34 |
|
|---|
| 35 | #include "MLog.h"
|
|---|
| 36 | #include "MLogManip.h"
|
|---|
| 37 |
|
|---|
| 38 | #include "MRawRunHeader.h"
|
|---|
| 39 | #include "MPointing.h"
|
|---|
| 40 | #include "MSrcPosCam.h"
|
|---|
| 41 | #include "MAstroSky2Local.h"
|
|---|
| 42 | #include "MPointingPos.h"
|
|---|
| 43 | #include "MGeomCam.h"
|
|---|
| 44 | #include "MReportDrive.h"
|
|---|
| 45 |
|
|---|
| 46 | ClassImp(MSrcPosFromModel);
|
|---|
| 47 |
|
|---|
| 48 | using namespace std;
|
|---|
| 49 |
|
|---|
| 50 | // --------------------------------------------------------------------------
|
|---|
| 51 | //
|
|---|
| 52 | // Initialize fY and fY with 0
|
|---|
| 53 | //
|
|---|
| 54 | MSrcPosFromModel::MSrcPosFromModel(const char *name, const char *title)
|
|---|
| 55 | {
|
|---|
| 56 | fName = name ? name : "MSrcPosFromModel";
|
|---|
| 57 | fTitle = title ? title : "";
|
|---|
| 58 |
|
|---|
| 59 | fPoint0401 = new MPointing("bending0401.txt");
|
|---|
| 60 | fPoint0405 = new MPointing("bending0405.txt");
|
|---|
| 61 | fPointOld = new MPointing("bending-old.txt");
|
|---|
| 62 | fPointNew = new MPointing("bending0408.txt");
|
|---|
| 63 | }
|
|---|
| 64 |
|
|---|
| 65 | MSrcPosFromModel::~MSrcPosFromModel()
|
|---|
| 66 | {
|
|---|
| 67 | delete fPoint0401;
|
|---|
| 68 | delete fPoint0405;
|
|---|
| 69 | delete fPointOld;
|
|---|
| 70 | delete fPointNew;
|
|---|
| 71 | }
|
|---|
| 72 |
|
|---|
| 73 | // --------------------------------------------------------------------------
|
|---|
| 74 | //
|
|---|
| 75 | // Search and if necessary create MSrcPosCam in the parameter list
|
|---|
| 76 | //
|
|---|
| 77 | Int_t MSrcPosFromModel::PreProcess(MParList *pList)
|
|---|
| 78 | {
|
|---|
| 79 | fGeom = (MGeomCam*)pList->FindObject("MGeomCam");
|
|---|
| 80 | if (!fGeom)
|
|---|
| 81 | {
|
|---|
| 82 | *fLog << err << "MGeomCam not found... aborting." << endl;
|
|---|
| 83 | return kFALSE;
|
|---|
| 84 | }
|
|---|
| 85 |
|
|---|
| 86 | fPointPos = (MPointingPos*)pList->FindObject("MPointingPos");
|
|---|
| 87 | if (!fPointPos)
|
|---|
| 88 | {
|
|---|
| 89 | *fLog << err << "MPointPos not found... aborting." << endl;
|
|---|
| 90 | return kFALSE;
|
|---|
| 91 | }
|
|---|
| 92 |
|
|---|
| 93 | fRun = (MRawRunHeader*)pList->FindObject("MRawRunHeader");
|
|---|
| 94 | if (!fRun)
|
|---|
| 95 | {
|
|---|
| 96 | *fLog << err << "MRawRunHeader not found... aborting." << endl;
|
|---|
| 97 | return kFALSE;
|
|---|
| 98 | }
|
|---|
| 99 | /*
|
|---|
| 100 | fReport = (MReportDrive*)pList->FindObject("MReportDrive");
|
|---|
| 101 | if (!fReport)
|
|---|
| 102 | {
|
|---|
| 103 | *fLog << err << "MReportDrive not found... aborting." << endl;
|
|---|
| 104 | return kFALSE;
|
|---|
| 105 | }
|
|---|
| 106 |
|
|---|
| 107 | fObservatory = (MObservatory*)pList->FindObject("MObservatory");
|
|---|
| 108 | if (!fObservatory)
|
|---|
| 109 | {
|
|---|
| 110 | *fLog << err << "MObservatory not found... aborting." << endl;
|
|---|
| 111 | return kFALSE;
|
|---|
| 112 | }
|
|---|
| 113 |
|
|---|
| 114 | fTime = (MTime*)pList->FindObject("MTime");
|
|---|
| 115 | if (!fTime)
|
|---|
| 116 | {
|
|---|
| 117 | *fLog << err << "MTime not found... aborting." << endl;
|
|---|
| 118 | return kFALSE;
|
|---|
| 119 | }
|
|---|
| 120 |
|
|---|
| 121 | fTime2 = (MTime*)pList->FindObject("MTimeDrive", "MTime");
|
|---|
| 122 | if (!fTime2)
|
|---|
| 123 | {
|
|---|
| 124 | *fLog << err << "MTimeDrive not found... aborting." << endl;
|
|---|
| 125 | return kFALSE;
|
|---|
| 126 | }
|
|---|
| 127 | */
|
|---|
| 128 | fSrcPos = (MSrcPosCam*)pList->FindCreateObj("MSrcPosCam");
|
|---|
| 129 | if (!fSrcPos)
|
|---|
| 130 | return kFALSE;
|
|---|
| 131 |
|
|---|
| 132 | return kTRUE;
|
|---|
| 133 | }
|
|---|
| 134 | /*
|
|---|
| 135 | TVector2 MSrcPosFromModel::CalcXYinCamera(const ZdAz &pos0, const ZdAz &pos1) const
|
|---|
| 136 | {
|
|---|
| 137 | MVector3 p0, p1;
|
|---|
| 138 | p0.SetZdAz(pos0.X(), pos0.Y());
|
|---|
| 139 | p1.SetZdAz(pos1.X(), pos1.Y());
|
|---|
| 140 |
|
|---|
| 141 | return CalcXYinCamera(p0, p1);
|
|---|
| 142 | }
|
|---|
| 143 |
|
|---|
| 144 | // --------------------------------------------------------------------------
|
|---|
| 145 | //
|
|---|
| 146 | // Loc0LocToCam
|
|---|
| 147 | //
|
|---|
| 148 | // Input : (theta0, phi0) direction for the position (0,0) in the camera
|
|---|
| 149 | // ( theta, phi) some other direction
|
|---|
| 150 | //
|
|---|
| 151 | // Output : (X, Y) position in the camera corresponding to (theta, phi)
|
|---|
| 152 | //
|
|---|
| 153 | TVector2 MSrcPosFromModel::CalcXYinCamera(const MVector3 &pos0, const MVector3 &pos) const
|
|---|
| 154 | {
|
|---|
| 155 | const Double_t theta0 = pos0.Theta();
|
|---|
| 156 | const Double_t phi0 = pos0.Phi();
|
|---|
| 157 |
|
|---|
| 158 | const Double_t theta = pos.Theta();
|
|---|
| 159 | const Double_t phi = pos.Phi();
|
|---|
| 160 |
|
|---|
| 161 | //--------------------------------------------
|
|---|
| 162 |
|
|---|
| 163 | // pos0[3] = TMath::Cos(theta0)
|
|---|
| 164 |
|
|---|
| 165 | const Double_t YC0 = TMath::Cos(theta0)*TMath::Tan(theta)*TMath::Cos(phi-phi0) - TMath::Sin(theta0);
|
|---|
| 166 | const Double_t YC1 = TMath::Cos(theta0) + TMath::Sin(theta0)*TMath::Tan(theta);
|
|---|
| 167 | const Double_t YC = YC0 / YC1;
|
|---|
| 168 |
|
|---|
| 169 | //--------------------------------------------
|
|---|
| 170 |
|
|---|
| 171 | const Double_t XC0 = TMath::Cos(theta0) - YC*TMath::Sin(theta0);
|
|---|
| 172 | const Double_t XC = -TMath::Sin(phi-phi0) * TMath::Tan(theta) * XC0;
|
|---|
| 173 |
|
|---|
| 174 | //--------------------------------------------
|
|---|
| 175 | return TVector2(XC, -YC);
|
|---|
| 176 | }
|
|---|
| 177 | */
|
|---|
| 178 | // --------------------------------------------------------------------------
|
|---|
| 179 | //
|
|---|
| 180 | // Derotate fX/fY by the current rotation angle, set MSrcPosCam
|
|---|
| 181 | //
|
|---|
| 182 | Int_t MSrcPosFromModel::Process()
|
|---|
| 183 | {
|
|---|
| 184 | MPointing *conv1 = 0;
|
|---|
| 185 | MPointing *conv2 = 0;
|
|---|
| 186 |
|
|---|
| 187 | if (!conv1 && fRun->GetRunNumber()<26237)
|
|---|
| 188 | {
|
|---|
| 189 | conv1 = fPoint0401;
|
|---|
| 190 | conv2 = fPointOld;
|
|---|
| 191 | }
|
|---|
| 192 | if (!conv1 && fRun->GetRunNumber()<31684)
|
|---|
| 193 | {
|
|---|
| 194 | conv1 = fPoint0405;
|
|---|
| 195 | conv2 = fPointOld;
|
|---|
| 196 | }
|
|---|
| 197 | /*
|
|---|
| 198 | MVector3 sky;
|
|---|
| 199 | sky.SetRaDec(fPointPos->GetRaRad(), fPointPos->GetDecRad());
|
|---|
| 200 | MVector3 loc = MAstroSky2Local(*fTime2, *fObservatory)*sky;
|
|---|
| 201 | ZdAz za(loc.Theta(), loc.Phi());
|
|---|
| 202 | */
|
|---|
| 203 |
|
|---|
| 204 | // Get current pointing position from Drive system
|
|---|
| 205 | ZdAz za(fPointPos->GetZd(), fPointPos->GetAz());
|
|---|
| 206 | za *= TMath::DegToRad();
|
|---|
| 207 |
|
|---|
| 208 | // Get corresponding Shaftencoder positions for 'Used-Mode'
|
|---|
| 209 | const ZdAz za2 = conv1->Correct(za); // [deg] --> [se]
|
|---|
| 210 | // Get corresponding Shaftencoder positions for 'Correct-Mode'
|
|---|
| 211 | const ZdAz za1 = conv2->Correct(za); // [deg] --> [se]
|
|---|
| 212 |
|
|---|
| 213 | // The difference of the shaftencoder positions for both model
|
|---|
| 214 | // correspond in a first order approximation to the misspointing
|
|---|
| 215 | TVector2 v0 = TVector2(za2.Y()-za1.Y(), za2.X()-za1.X());
|
|---|
| 216 |
|
|---|
| 217 | // Convert misspointing to millimeters
|
|---|
| 218 | v0 *= TMath::RadToDeg()/fGeom->GetConvMm2Deg();
|
|---|
| 219 |
|
|---|
| 220 | // Set Source position
|
|---|
| 221 | fSrcPos->SetXY(v0);
|
|---|
| 222 |
|
|---|
| 223 | /*
|
|---|
| 224 | TVector2 v0 = CalcXYinCamera(za1, za0)*fGeom->GetCameraDist()*(-1000);
|
|---|
| 225 | TVector2 v1 = CalcXYinCamera(za0, za1)*fGeom->GetCameraDist()*(+1000);
|
|---|
| 226 |
|
|---|
| 227 | fSrcPos->SetXY(TVector2(0,0)); // v1
|
|---|
| 228 |
|
|---|
| 229 | za0 *= TMath::RadToDeg();
|
|---|
| 230 | za1 *= TMath::RadToDeg();
|
|---|
| 231 |
|
|---|
| 232 | *fLog << warn << endl;
|
|---|
| 233 | *fLog << "-1-> " << za0.X() << " " << za0.Y() << " " << v0.X() << " " << v0.Y() << " " << v0.X()*fGeom->GetConvMm2Deg() << " " << v0.Y()*fGeom->GetConvMm2Deg() << endl;
|
|---|
| 234 | *fLog << "-2-> " << za1.X() << " " << za1.Y() << " " << v1.X() << " " << v1.Y() << " " << v1.X()*fGeom->GetConvMm2Deg() << " " << v1.Y()*fGeom->GetConvMm2Deg() << endl;
|
|---|
| 235 |
|
|---|
| 236 | Double_t rho = fPointPos->RotationAngle(*fObservatory, *fTime2);
|
|---|
| 237 | *fLog << "-3-> " << rho*TMath::RadToDeg() << endl;
|
|---|
| 238 |
|
|---|
| 239 | v1=v1.Rotate(-rho);
|
|---|
| 240 | *fLog << "-4-> " << " " << " " << " " << " " << v1.X() << " " << v1.Y() << " " << v1.X()*fGeom->GetConvMm2Deg() << " " << v1.Y()*fGeom->GetConvMm2Deg() << endl;
|
|---|
| 241 |
|
|---|
| 242 | */
|
|---|
| 243 | /*
|
|---|
| 244 | *fLog << dbg << endl;
|
|---|
| 245 | *fLog << "Time: " << setprecision(12) << fTime2->GetMjd() << " " << *fTime2 << endl;
|
|---|
| 246 | *fLog << setprecision(6);
|
|---|
| 247 | */
|
|---|
| 248 |
|
|---|
| 249 | return kTRUE;
|
|---|
| 250 | }
|
|---|