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 | #include "MAstroCatalog.h"
|
---|
78 | Int_t MSrcPosFromModel::PreProcess(MParList *pList)
|
---|
79 | {
|
---|
80 | fGeom = (MGeomCam*)pList->FindObject("MGeomCam");
|
---|
81 | if (!fGeom)
|
---|
82 | {
|
---|
83 | *fLog << err << "MGeomCam not found... aborting." << endl;
|
---|
84 | return kFALSE;
|
---|
85 | }
|
---|
86 |
|
---|
87 | fPointPos = (MPointingPos*)pList->FindObject("MPointingPos");
|
---|
88 | if (!fPointPos)
|
---|
89 | {
|
---|
90 | *fLog << err << "MPointPos not found... aborting." << endl;
|
---|
91 | return kFALSE;
|
---|
92 | }
|
---|
93 |
|
---|
94 | fRun = (MRawRunHeader*)pList->FindObject("MRawRunHeader");
|
---|
95 | if (!fRun)
|
---|
96 | {
|
---|
97 | *fLog << err << "MRawRunHeader not found... aborting." << endl;
|
---|
98 | return kFALSE;
|
---|
99 | }
|
---|
100 | /*
|
---|
101 | fReport = (MReportDrive*)pList->FindObject("MReportDrive");
|
---|
102 | if (!fReport)
|
---|
103 | {
|
---|
104 | *fLog << err << "MReportDrive not found... aborting." << endl;
|
---|
105 | return kFALSE;
|
---|
106 | }
|
---|
107 |
|
---|
108 | fObservatory = (MObservatory*)pList->FindObject("MObservatory");
|
---|
109 | if (!fObservatory)
|
---|
110 | {
|
---|
111 | *fLog << err << "MObservatory not found... aborting." << endl;
|
---|
112 | return kFALSE;
|
---|
113 | }
|
---|
114 |
|
---|
115 | fTime = (MTime*)pList->FindObject("MTime");
|
---|
116 | if (!fTime)
|
---|
117 | {
|
---|
118 | *fLog << err << "MTime not found... aborting." << endl;
|
---|
119 | return kFALSE;
|
---|
120 | }
|
---|
121 |
|
---|
122 | fTime2 = (MTime*)pList->FindObject("MTimeDrive", "MTime");
|
---|
123 | if (!fTime2)
|
---|
124 | {
|
---|
125 | *fLog << err << "MTimeDrive not found... aborting." << endl;
|
---|
126 | return kFALSE;
|
---|
127 | }
|
---|
128 | */
|
---|
129 | fSrcPos = (MSrcPosCam*)pList->FindCreateObj("MSrcPosCam");
|
---|
130 | if (!fSrcPos)
|
---|
131 | return kFALSE;
|
---|
132 |
|
---|
133 | return kTRUE;
|
---|
134 | }
|
---|
135 | /*
|
---|
136 | TVector2 MSrcPosFromModel::CalcXYinCamera(const ZdAz &pos0, const ZdAz &pos1) const
|
---|
137 | {
|
---|
138 | MVector3 p0, p1;
|
---|
139 | p0.SetZdAz(pos0.X(), pos0.Y());
|
---|
140 | p1.SetZdAz(pos1.X(), pos1.Y());
|
---|
141 |
|
---|
142 | return CalcXYinCamera(p0, p1);
|
---|
143 | }
|
---|
144 |
|
---|
145 | // --------------------------------------------------------------------------
|
---|
146 | //
|
---|
147 | // Loc0LocToCam
|
---|
148 | //
|
---|
149 | // Input : (theta0, phi0) direction for the position (0,0) in the camera
|
---|
150 | // ( theta, phi) some other direction
|
---|
151 | //
|
---|
152 | // Output : (X, Y) position in the camera corresponding to (theta, phi)
|
---|
153 | //
|
---|
154 | TVector2 MSrcPosFromModel::CalcXYinCamera(const MVector3 &pos0, const MVector3 &pos) const
|
---|
155 | {
|
---|
156 | const Double_t theta0 = pos0.Theta();
|
---|
157 | const Double_t phi0 = pos0.Phi();
|
---|
158 |
|
---|
159 | const Double_t theta = pos.Theta();
|
---|
160 | const Double_t phi = pos.Phi();
|
---|
161 |
|
---|
162 | //--------------------------------------------
|
---|
163 |
|
---|
164 | // pos0[3] = TMath::Cos(theta0)
|
---|
165 |
|
---|
166 | const Double_t YC0 = TMath::Cos(theta0)*TMath::Tan(theta)*TMath::Cos(phi-phi0) - TMath::Sin(theta0);
|
---|
167 | const Double_t YC1 = TMath::Cos(theta0) + TMath::Sin(theta0)*TMath::Tan(theta);
|
---|
168 | const Double_t YC = YC0 / YC1;
|
---|
169 |
|
---|
170 | //--------------------------------------------
|
---|
171 |
|
---|
172 | const Double_t XC0 = TMath::Cos(theta0) - YC*TMath::Sin(theta0);
|
---|
173 | const Double_t XC = -TMath::Sin(phi-phi0) * TMath::Tan(theta) * XC0;
|
---|
174 |
|
---|
175 | //--------------------------------------------
|
---|
176 | return TVector2(XC, -YC);
|
---|
177 | }
|
---|
178 | */
|
---|
179 | // --------------------------------------------------------------------------
|
---|
180 | //
|
---|
181 | // Derotate fX/fY by the current rotation angle, set MSrcPosCam
|
---|
182 | //
|
---|
183 | Int_t MSrcPosFromModel::Process()
|
---|
184 | {
|
---|
185 | MPointing *conv1 = 0;
|
---|
186 | MPointing *conv2 = 0;
|
---|
187 |
|
---|
188 | if (!conv1 && fRun->GetRunNumber()<26237)
|
---|
189 | {
|
---|
190 | conv1 = fPoint0401;
|
---|
191 | conv2 = fPointOld;
|
---|
192 | }
|
---|
193 | if (!conv1 && fRun->GetRunNumber()<31684)
|
---|
194 | {
|
---|
195 | conv1 = fPoint0405;
|
---|
196 | conv2 = fPointOld;
|
---|
197 | }
|
---|
198 | /*
|
---|
199 | MVector3 sky;
|
---|
200 | sky.SetRaDec(fPointPos->GetRaRad(), fPointPos->GetDecRad());
|
---|
201 | MVector3 loc = MAstroSky2Local(*fTime2, *fObservatory)*sky;
|
---|
202 | ZdAz za(loc.Theta(), loc.Phi());
|
---|
203 | */
|
---|
204 |
|
---|
205 | // Get current pointing position from Drive system
|
---|
206 | ZdAz za(fPointPos->GetZd(), fPointPos->GetAz());
|
---|
207 | za *= TMath::DegToRad();
|
---|
208 |
|
---|
209 | // Get corresponding Shaftencoder positions for 'Used-Mode'
|
---|
210 | const ZdAz za2 = conv1->Correct(za); // [deg] --> [se]
|
---|
211 | // Get corresponding Shaftencoder positions for 'Correct-Mode'
|
---|
212 | const ZdAz za1 = conv2->Correct(za); // [deg] --> [se]
|
---|
213 |
|
---|
214 | // The difference of the shaftencoder positions for both model
|
---|
215 | // correspond in a first order approximation to the misspointing
|
---|
216 | TVector2 v0 = TVector2(za2.Y()-za1.Y(), za2.X()-za1.X());
|
---|
217 |
|
---|
218 | // Convert misspointing to millimeters
|
---|
219 | v0 *= TMath::RadToDeg()/fGeom->GetConvMm2Deg();
|
---|
220 |
|
---|
221 | // Set Source position
|
---|
222 | fSrcPos->SetXY(v0);
|
---|
223 |
|
---|
224 | /*
|
---|
225 | TVector2 v0 = CalcXYinCamera(za1, za0)*fGeom->GetCameraDist()*(-1000);
|
---|
226 | TVector2 v1 = CalcXYinCamera(za0, za1)*fGeom->GetCameraDist()*(+1000);
|
---|
227 |
|
---|
228 | fSrcPos->SetXY(TVector2(0,0)); // v1
|
---|
229 |
|
---|
230 | za0 *= TMath::RadToDeg();
|
---|
231 | za1 *= TMath::RadToDeg();
|
---|
232 |
|
---|
233 | *fLog << warn << endl;
|
---|
234 | *fLog << "-1-> " << za0.X() << " " << za0.Y() << " " << v0.X() << " " << v0.Y() << " " << v0.X()*fGeom->GetConvMm2Deg() << " " << v0.Y()*fGeom->GetConvMm2Deg() << endl;
|
---|
235 | *fLog << "-2-> " << za1.X() << " " << za1.Y() << " " << v1.X() << " " << v1.Y() << " " << v1.X()*fGeom->GetConvMm2Deg() << " " << v1.Y()*fGeom->GetConvMm2Deg() << endl;
|
---|
236 |
|
---|
237 | Double_t rho = fPointPos->RotationAngle(*fObservatory, *fTime2);
|
---|
238 | *fLog << "-3-> " << rho*TMath::RadToDeg() << endl;
|
---|
239 |
|
---|
240 | v1=v1.Rotate(-rho);
|
---|
241 | *fLog << "-4-> " << " " << " " << " " << " " << v1.X() << " " << v1.Y() << " " << v1.X()*fGeom->GetConvMm2Deg() << " " << v1.Y()*fGeom->GetConvMm2Deg() << endl;
|
---|
242 |
|
---|
243 | */
|
---|
244 | /*
|
---|
245 | *fLog << dbg << endl;
|
---|
246 | *fLog << "Time: " << setprecision(12) << fTime2->GetMjd() << " " << *fTime2 << endl;
|
---|
247 | *fLog << setprecision(6);
|
---|
248 | */
|
---|
249 |
|
---|
250 | return kTRUE;
|
---|
251 | }
|
---|