source: trunk/MagicSoft/Mars/mpointing/MPointing.cc@ 7395

Last change on this file since 7395 was 4966, checked in by tbretz, 20 years ago
*** empty log message ***
File size: 19.6 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, 2003 <mailto:tbretz@astro.uni-wuerzburg.de>
19!
20! Copyright: MAGIC Software Development, 2000-2004
21!
22!
23\* ======================================================================== */
24
25/////////////////////////////////////////////////////////////////////////////
26//
27// MPointing
28// =========
29//
30// This is the class used for the pointing correction done in the MAGIC
31// drive software cosy. NEVER CHANGE IT WITHOUT CONTACTING THE AUTHOR FIRST!
32//
33// Variables/Coefficients
34// ----------------------
35//
36// Double_t fIe ; // [rad] Index Error in Elevation
37// Double_t fIa ; // [rad] Index Error in Azimuth
38//
39// Double_t fFlop ; // [rad] Vertical Sag
40// * do not use if not data: Zd<0
41//
42// Double_t fNpae ; // [rad] Az-El Nonperpendicularity
43//
44// Double_t fCa ; // [rad] Left-Right Collimation Error
45//
46// Double_t fAn ; // [rad] Azimuth Axis Misalignment (N-S)
47// Double_t fAw ; // [rad] Azimuth Axis Misalignment (E-W)
48//
49// Double_t fTf ; // [rad] Tube fluxture (sin)
50// * same as ecec if no data: Zd<0
51// Double_t fTx ; // [rad] Tube fluxture (tan)
52// * do not use with NPAE if no data: Zd<0
53//
54// Double_t fNrx ; // [rad] Nasmyth rotator displacement, horizontan
55// Double_t fNry ; // [rad] Nasmyth rotator displacement, vertical
56//
57// Double_t fCrx ; // [rad] Alt/Az Coude Displacement (N-S)
58// Double_t fCry ; // [rad] Alt/Az Coude Displacement (E-W)
59//
60// Double_t fEces ; // [rad] Elevation Centering Error (sin)
61// Double_t fAces ; // [rad] Azimuth Centering Error (sin)
62// Double_t fEcec ; // [rad] Elevation Centering Error (cos)
63// Double_t fAcec ; // [rad] Azimuth Centering Error (cos)
64//
65// Double_t fMagic1;// [rad] ZA Hysteresis
66// Double_t fMagic2;// [rad] undefined
67//
68////////////////////////////////////////////////////////////////////////////
69#include "MPointing.h"
70
71#include <fstream>
72
73#include <TVector3.h>
74
75#include <TMinuit.h>
76
77#include "MLog.h"
78#include "MLogManip.h"
79
80#include "MTime.h"
81
82ClassImp(AltAz);
83ClassImp(ZdAz);
84ClassImp(MPointing);
85
86using namespace std;
87
88#undef DEBUG
89//#define DEBUG(txt) txt
90#define DEBUG(txt)
91
92const Int_t MPointing::fNumPar=19;
93
94void MPointing::Init(const char *name, const char *title)
95{
96 fName = name ? name : "MPointing";
97 fTitle = title ? title : "Pointing correction model for the MAGIC telescope";
98
99 fCoeff = new Double_t*[fNumPar];
100 fNames = new TString[fNumPar];
101 fDescr = new TString[fNumPar];
102
103 fCoeff[ 0] = &fIa; fNames[ 0] = "IA";
104 fCoeff[ 1] = &fIe; fNames[ 1] = "IE";
105 fCoeff[ 2] = &fFlop; fNames[ 2] = "FLOP";
106 fCoeff[ 3] = &fAn; fNames[ 3] = "AN";
107 fCoeff[ 4] = &fAw; fNames[ 4] = "AW";
108 fCoeff[ 5] = &fNpae; fNames[ 5] = "NPAE";
109 fCoeff[ 6] = &fCa; fNames[ 6] = "CA";
110 fCoeff[ 7] = &fTf; fNames[ 7] = "TF";
111 fCoeff[ 8] = &fTx; fNames[ 8] = "TX";
112 fCoeff[ 9] = &fEces; fNames[ 9] = "ECES";
113 fCoeff[10] = &fAces; fNames[10] = "ACES";
114 fCoeff[11] = &fEcec; fNames[11] = "ECEC";
115 fCoeff[12] = &fAcec; fNames[12] = "ACEC";
116 fCoeff[13] = &fNrx; fNames[13] = "NRX";
117 fCoeff[14] = &fNry; fNames[14] = "NRY";
118 fCoeff[15] = &fCrx; fNames[15] = "CRX";
119 fCoeff[16] = &fCry; fNames[16] = "CRY";
120 fCoeff[17] = &fMagic1; fNames[17] = "MAGIC1";
121 fCoeff[18] = &fMagic2; fNames[18] = "MAGIC2";
122
123 fDescr[ 0] = "Index Error Azimuth";
124 fDescr[ 1] = "Index Error Zenith Distance";
125 fDescr[ 2] = "Vertical Sag";
126 fDescr[ 3] = "Azimuth Axis Misalignment (N-S)";
127 fDescr[ 4] = "Azimuth Axis Misalignment (E-W)";
128 fDescr[ 5] = "Az-El Nonperpendicularity";
129 fDescr[ 6] = "Left-Right Collimation Error";
130 fDescr[ 7] = "Tube fluxture (sin)";
131 fDescr[ 8] = "Tube fluxture (tan)";
132 fDescr[ 9] = "Elevation Centering Error (sin)";
133 fDescr[10] = "Azimuth Centering Error (sin)";
134 fDescr[11] = "Elevation Centering Error (cos)";
135 fDescr[12] = "Azimuth Centering Error (cos)";
136 fDescr[13] = "Nasmyth rotator displacement (horizontal)";
137 fDescr[14] = "Nasmyth rotator displacement (vertical)";
138 fDescr[15] = "Alt/Az Coude Displacement (N-S)";
139 fDescr[16] = "Alt/Az Coude Displacement (E-W)";
140 fDescr[17] = "n/a <ZA Hysteresis>";
141 fDescr[18] = "n/a";
142}
143void MPointing::Reset()
144{
145 Clear();
146}
147
148void MPointing::Load(const char *name)
149{
150 /*
151 ! MMT 1987 July 8
152 ! T 36 7.3622 41.448 -0.0481
153 ! IA -37.5465 20.80602
154 ! IE -13.9180 1.25217
155 ! NPAE +7.0751 26.44763
156 ! CA -6.9149 32.05358
157 ! AN +0.5053 1.40956
158 ! AW -2.2016 1.37480
159 ! END
160 */
161
162 ifstream fin(name);
163 if (!fin)
164 {
165 *fLog << err << "ERROR - Cannot open file '" << name << "'" << endl;
166 return;
167 }
168
169 char c;
170 while (fin && fin.get()!='\n');
171 fin >> c;
172
173 if (c!='S' && c!='s')
174 {
175 *fLog << err << "Error: This in not a model correcting the star position (" << c << ")" << endl;
176 return;
177 }
178
179 Clear();
180
181 cout << endl;
182
183 Double_t val;
184 fin >> val;
185 *fLog << inf << "Number of observed stars: " << val << endl;
186 fin >> val;
187 *fLog << inf << "Sky RMS: " << val << "\"" << endl;
188 fin >> val;
189 *fLog << inf << "Refraction Constant A: " << val << "\"" << endl;
190 fin >> val;
191 *fLog << inf << "Refraction Constant B: " << val << "\"" << endl;
192
193 *fLog << inf << endl;
194
195 *fLog << inf << " & = Name Value Sigma" << endl;
196 *fLog << inf << "--------------------------------------------------" << endl;
197
198 while (fin)
199 {
200 TString str;
201 fin >> str;
202
203 if (str=="END")
204 break;
205
206 if (str[0]=='&')
207 {
208 *fLog << inf << " & ";
209 str.Remove(0);
210 }
211 else
212 cout << " ";
213
214 if (str[1]=='=')
215 {
216 *fLog << inf << "= ";
217 str.Remove(0);
218 }
219 else
220 *fLog << inf << " ";
221
222 fin >> val;
223 *fLog << inf << str << "\t" << setw(11) << val << "° \t";
224 val *= TMath::DegToRad();
225
226 // Find parameter
227 Int_t n = -1;
228 for (int i=0; i<fNumPar; i++)
229 if (str==fNames[i])
230 {
231 n = i;
232 *fCoeff[i] = val;
233 break;
234 }
235
236 fin >> val;
237 *fLog << inf << setw(9) << val << "°" << endl;
238
239 // corresponding error
240 fError[n] = val*TMath::DegToRad();
241 }
242 *fLog << inf << endl;
243}
244
245void MPointing::Save(const char *name)
246{
247 /*
248 ! MMT 1987 July 8
249 ! T 36 7.3622 41.448 -0.0481
250 ! IA -37.5465 20.80602
251 ! IE -13.9180 1.25217
252 ! NPAE +7.0751 26.44763
253 ! CA -6.9149 32.05358
254 ! AN +0.5053 1.40956
255 ! AW -2.2016 1.37480
256 ! END
257 */
258
259 ofstream fout(name);
260 if (!fout)
261 {
262 cout << "Error: Cannot open file '" << name << "'" << endl;
263 return;
264 }
265
266 MTime t;
267 t.Now();
268
269 fout << "MAGIC1 " << t << endl;
270 fout << "S 00 000000 000000 0000000" << endl;
271 fout << setprecision(8);
272 for (int i=0; i<fNumPar; i++)
273 {
274 fout << " " << setw(6) << GetVarName(i) << " ";
275 fout << setw(13) << *fCoeff[i]*kRad2Deg << " ";
276 fout << setw(11) << fError[i]*kRad2Deg << endl;
277 }
278 fout << "END" << endl;
279}
280
281Double_t MPointing::Sign(Double_t val, Double_t alt)
282{
283 // Some pointing corrections are defined as Delta ZA, which
284 // is (P. Wallace) defined [0,90]deg while Alt is defined
285 // [0,180]deg
286 return (TMath::Pi()/2-alt < 0 ? -val : val);
287}
288
289AltAz MPointing::AddOffsets(const AltAz &aa) const
290{
291 // Correct [rad]
292 // zdaz [rad]
293 AltAz p = aa;
294
295 const AltAz I(fIe, fIa);
296 p += I;
297
298 return p;
299}
300
301AltAz MPointing::SubtractOffsets(const AltAz &aa) const
302{
303 // Correct [rad]
304 // zdaz [rad]
305 AltAz p = aa;
306
307 const AltAz I(fIe, fIa);
308 p -= I;
309
310 return p;
311}
312
313AltAz MPointing::CalcAnAw(const AltAz &p, Int_t sign) const
314{
315 // Corrections for AN and AW without approximations
316 // as done by Patrick Wallace. The approximation cannot
317 // be used for MAGIC because the correctioon angle
318 // AW (~1.5deg) is not small enough.
319
320 // Vector in cartesian coordinates
321 TVector3 v1;
322
323 // Set Azimuth and Elevation
324 v1.SetMagThetaPhi(1, TMath::Pi()/2-p.Alt(), p.Az());
325
326
327 TVector3 v2(v1);
328// cout << sign << endl;
329
330// cout << "v1: " << v1.Theta()*TMath::RadToDeg() << " " << v1.Phi()*TMath::RadToDeg() << endl;
331
332 // Rotate around the x- and y-axis
333 v1.RotateY(sign*fAn);
334 v1.RotateX(sign*fAw);
335
336// cout << "v1: " << v1.Theta()*TMath::RadToDeg() << " " << v1.Phi()*TMath::RadToDeg() << endl;
337// cout << "v2: " << v2.Theta()*TMath::RadToDeg() << " " << v2.Theta()*TMath::RadToDeg() << endl;
338
339 // cout << "dv: " << (v2.Theta()-v1.Theta())*TMath::RadToDeg() << " " << (v2.Phi()-v1.Phi())*TMath::RadToDeg() << endl;
340
341 Double_t dalt = v1.Theta()-v2.Theta();
342 Double_t daz = v1.Phi() -v2.Phi();
343
344 //cout << dalt*TMath::RadToDeg() << " " << daz*TMath::RadToDeg() << endl;
345
346 if (daz>TMath::Pi())
347 daz -= TMath::TwoPi();
348 if (daz<-TMath::Pi())
349 daz += TMath::TwoPi();
350
351// if (daz>TMath::Pi()/2)
352// {
353// }
354
355 AltAz d(dalt, daz);
356 return d;
357
358 // Calculate Delta Azimuth and Delta Elevation
359 /*
360 AltAz d(TMath::Pi()/2-v1.Theta(), v1.Phi());
361
362 cout << "p : " << p.Alt()*TMath::RadToDeg() << " " << p.Az()*TMath::RadToDeg() << endl;
363 cout << "d : " << d.Alt()*TMath::RadToDeg() << " " << d.Az()*TMath::RadToDeg() << endl;
364 d -= p;
365 cout << "d-p: " << d.Alt()*TMath::RadToDeg() << " " << d.Az()*TMath::RadToDeg() << endl;
366 d *= sign;
367 cout << "d* : " << d.Alt()*TMath::RadToDeg() << " " << d.Az()*TMath::RadToDeg() << endl;
368
369
370 cout << "p2: " << 90-p.Alt()*TMath::RadToDeg() << " " << p.Az()*TMath::RadToDeg() << endl;
371 cout << "d2: " << 90-d.Alt()*TMath::RadToDeg() << " " << d.Az()*TMath::RadToDeg() << endl;
372
373 Int_t s1 = 90-d.Alt()*TMath::RadToDeg() < 0 ? -1 : 1;
374 Int_t s2 = 90-p.Alt()*TMath::RadToDeg() < 0 ? -1 : 1;
375
376
377 if (s1 != s2)
378 {
379 //90-d.Alt() <-- -90+d.Alt()
380
381 d.Alt(d.Alt()-TMath::Pi());
382 cout << "Alt-" << endl;
383 }
384 cout << "d': " << 90-d.Alt()*TMath::RadToDeg() << " " << d.Az()*TMath::RadToDeg() << endl;*/
385 /*
386 // Fix 'direction' of output depending on input vector
387 if (TMath::Pi()/2-sign*p.Alt()<0)
388 {
389 d.Alt(d.Alt()-TMath::Pi());
390 cout << "Alt-" << endl;
391 }
392 //if (TMath::Pi()/2-sign*p.Alt()>TMath::Pi())
393 //{
394 // d.Alt(TMath::Pi()-d.Alt());
395 // cout << "Alt+" << endl;
396 //}
397
398 // Align correction into [-180,180]
399 while (d.Az()>TMath::Pi())
400 {
401 d.Az(d.Az()-TMath::Pi()*2);
402 cout << "Az-" << endl;
403 }
404 while (d.Az()<-TMath::Pi())
405 {
406 d.Az(d.Az()+TMath::Pi()*2);
407 cout << "Az+" << endl;
408 }
409 */
410 return d;
411}
412
413
414AltAz MPointing::Correct(const AltAz &aa) const
415{
416 // Correct [rad]
417 // zdaz [rad]
418 AltAz p = aa;
419
420 DEBUG(cout << setprecision(16));
421 DEBUG(cout << "Bend7: " << 90-p.Alt()*180/TMath::Pi() << " " << p.Az()*180/TMath::Pi() << endl);
422
423 const AltAz CRX(-fCrx*sin(p.Az()-p.Alt()), fCrx*cos(p.Az()-p.Alt())/cos(p.Alt()));
424 const AltAz CRY(-fCry*cos(p.Az()-p.Alt()), -fCry*sin(p.Az()-p.Alt())/cos(p.Alt()));
425 p += CRX;
426 p += CRY;
427
428 DEBUG(cout << "Bend6: " << 90-p.Alt()*180/TMath::Pi() << " " << p.Az()*180/TMath::Pi() << endl);
429
430 const AltAz NRX(fNrx*sin(p.Alt()), -fNrx);
431 const AltAz NRY(fNry*cos(p.Alt()), -fNry*tan(p.Alt()));
432 p += NRX;
433 p += NRY;
434
435 DEBUG(cout << "Bend5: " << 90-p.Alt()*180/TMath::Pi() << " " << p.Az()*180/TMath::Pi() << endl);
436
437 const AltAz CES(-fEces*sin(p.Alt()), -fAces*sin(p.Az()));
438 const AltAz CEC(-fEcec*cos(p.Alt()), -fAcec*cos(p.Az()));
439 p += CES;
440 p += CEC;
441
442 DEBUG(cout << "Bend4: " << 90-p.Alt()*180/TMath::Pi() << " " << p.Az()*180/TMath::Pi() << endl);
443
444 const AltAz TX(Sign(fTx/tan(p.Alt()), p.Alt()), 0);
445 const AltAz TF(Sign(fTf*cos(p.Alt()), p.Alt()), 0);
446 //p += TX;
447 p += TF;
448
449
450 DEBUG(cout << "Bend3: " << 90-p.Alt()*180/TMath::Pi() << " " << p.Az()*180/TMath::Pi() << endl);
451
452 /*
453 //New Corrections for NPAE and CA:
454 TVector3 v(1.,1.,1.); // Vector in cartesian coordinates
455
456 //Set Azimuth and Elevation
457 v.SetPhi(p.Az());
458 v.SetTheta(TMath::Pi()/2-p.Alt());
459 //Rotation Vectors:
460 TVector3 vNpae( cos(p.Az()), sin(p.Az()), 0);
461 TVector3 vCa( -cos(p.Az())*cos(p.Alt()), -sin(p.Az())*cos(p.Alt()), sin(p.Alt()));
462 //Rotate around the vectors vNpae and vCa
463 v.Rotate(fNpae, vNpae);
464 v.Rotate(fCa, vCa);
465
466 p.Az(v.Phi());
467 p.Alt(TMath::Pi()/2-v.Theta());
468 */
469
470 //Old correction terms for Npae and Ca:
471 const AltAz CA(0, -fCa/cos(p.Alt()));
472 p += CA;
473
474 const AltAz NPAE(0, -fNpae*tan(p.Alt()));
475 p += NPAE;
476
477 DEBUG(cout << "Bend2: " << 90-p.Alt()*180/TMath::Pi() << " " << p.Az()*180/TMath::Pi() << endl);
478
479 const AltAz ANAW(CalcAnAw(p, -1));
480 p += ANAW;
481
482 /* Old correction terms for An and Aw:
483 const AltAz AW( fAw*sin(p.Az()), -fAw*cos(p.Az())*tan(p.Alt()));
484 const AltAz AN(-fAn*cos(p.Az()), -fAn*sin(p.Az())*tan(p.Alt()));
485 p += AW;
486 p += AN;
487 */
488
489 DEBUG(cout << "Bend1: " << 90-p.Alt()*180/TMath::Pi() << " " << p.Az()*180/TMath::Pi() << endl);
490
491 const AltAz FLOP(Sign(fFlop, p.Alt()), 0);
492 p += FLOP;
493
494 const AltAz MAGIC1(fMagic1*TMath::Sign(1., sin(p.Az())), 0);
495 p += MAGIC1;
496
497 const AltAz I(fIe, fIa);
498 p += I;
499
500 DEBUG(cout << "Bend0: " << 90-p.Alt()*180/TMath::Pi() << " " << p.Az()*180/TMath::Pi() << endl);
501
502 return p;
503}
504
505AltAz MPointing::CorrectBack(const AltAz &aa) const
506{
507 // Correct [rad]
508 // zdaz [rad]
509 AltAz p = aa;
510
511 DEBUG(cout << setprecision(16));
512 DEBUG(cout << "Back0: " << 90-p.Alt()*180/TMath::Pi() << " " << p.Az()*180/TMath::Pi() << endl);
513
514 const AltAz I(fIe, fIa);
515 p -= I;
516
517 const AltAz MAGIC1(fMagic1*TMath::Sign(1., sin(p.Az())), 0);
518 p -= MAGIC1;
519
520 //const AltAz MAGIC1(fMagic1*sin(p.Az()), 0);
521 //p -= MAGIC1;
522
523 const AltAz FLOP(Sign(fFlop, p.Alt()), 0);
524 p -= FLOP;
525
526 DEBUG(cout << "Back1: " << 90-p.Alt()*180/TMath::Pi() << " " << p.Az()*180/TMath::Pi() << endl);
527
528 /* Old correction terms for An and Aw:
529 const AltAz AN(-fAn*cos(p.Az()), -fAn*sin(p.Az())*tan(p.Alt()));
530 const AltAz AW( fAw*sin(p.Az()), -fAw*cos(p.Az())*tan(p.Alt()));
531 p -= AN;
532 p -= AW;
533 */
534
535 const AltAz ANAW(CalcAnAw(p, -1));
536 p -= ANAW;
537
538 DEBUG(cout << "Back2: " << 90-p.Alt()*180/TMath::Pi() << " " << p.Az()*180/TMath::Pi() << endl);
539
540 //Old Correction terms for Npae and Ca:
541 const AltAz NPAE(0, -fNpae*tan(p.Alt()));
542 p -= NPAE;
543
544 const AltAz CA(0, -fCa/cos(p.Alt()));
545 p -= CA;
546
547 /*
548 //New Correction term for Npae and Ca:
549 TVector3 v2(1.,1.,1.); // Vector in cartesian coordinates
550 //Set Azimuth and Elevation
551 v2.SetPhi(p.Az());
552 v2.SetTheta(TMath::Pi()/2-p.Alt());
553 //Rotation Vectors:
554 TVector3 vNpae( cos(p.Az()), sin(p.Az()), 0);
555 TVector3 vCa( -cos(p.Az())*cos(p.Alt()), -sin(p.Az())*cos(p.Alt()), sin(p.Alt()));
556 //Rotate around the vectors vCa and vNpae
557 v2.Rotate(-fCa, vCa);
558 v2.Rotate(-fNpae, vNpae);
559
560 p.Az(v2.Phi());
561 p.Alt(TMath::Pi()/2-v2.Theta());
562 */
563
564 DEBUG(cout << "Back3: " << 90-p.Alt()*180/TMath::Pi() << " " << p.Az()*180/TMath::Pi() << endl);
565
566 const AltAz TF(Sign(fTf*cos(p.Alt()), p.Alt()), 0);
567 const AltAz TX(Sign(fTx/tan(p.Alt()), p.Alt()), 0);
568 p -= TF;
569 //p -= TX;
570
571 DEBUG(cout << "Back4: " << 90-p.Alt()*180/TMath::Pi() << " " << p.Az()*180/TMath::Pi() << endl);
572
573 const AltAz CEC(-fEcec*cos(p.Alt()), -fAcec*cos(p.Az()));
574 const AltAz CES(-fEces*sin(p.Alt()), -fAces*sin(p.Az()));
575 p -= CEC;
576 p -= CES;
577
578 DEBUG(cout << "Back5: " << 90-p.Alt()*180/TMath::Pi() << " " << p.Az()*180/TMath::Pi() << endl);
579
580 const AltAz NRY(fNry*cos(p.Alt()), -fNry*tan(p.Alt()));
581 const AltAz NRX(fNrx*sin(p.Alt()), -fNrx);
582 p -= NRY;
583 p -= NRX;
584
585 DEBUG(cout << "Back6: " << 90-p.Alt()*180/TMath::Pi() << " " << p.Az()*180/TMath::Pi() << endl);
586
587 const AltAz CRY(-fCry*cos(p.Az()-p.Alt()), -fCry*sin(p.Az()-p.Alt())/cos(p.Alt()));
588 const AltAz CRX(-fCrx*sin(p.Az()-p.Alt()), fCrx*cos(p.Az()-p.Alt())/cos(p.Alt()));
589 p -= CRY;
590 p -= CRX;
591
592 DEBUG(cout << "Back7: " << 90-p.Alt()*180/TMath::Pi() << " " << p.Az()*180/TMath::Pi() << endl);
593
594 return p;
595}
596
597ZdAz MPointing::Correct(const ZdAz &zdaz) const
598{
599 // Correct [rad]
600 // zdaz [rad]
601 AltAz p(TMath::Pi()/2-zdaz.Zd(), zdaz.Az());
602 AltAz c = Correct(p);
603 return ZdAz(TMath::Pi()/2-c.Alt(), c.Az());
604}
605
606TVector3 MPointing::Correct(const TVector3 &v) const
607{
608 // Correct [rad]
609 // zdaz [rad]
610 AltAz p(TMath::Pi()/2-v.Theta(), v.Phi());
611 AltAz c = Correct(p);
612 TVector3 rc;
613 rc.SetMagThetaPhi(1, TMath::Pi()/2-c.Alt(), c.Az());
614 return rc;
615}
616
617ZdAz MPointing::CorrectBack(const ZdAz &zdaz) const
618{
619 // Correct [rad]
620 // zdaz [rad]
621 AltAz p(TMath::Pi()/2-zdaz.Zd(), zdaz.Az());
622 AltAz c = CorrectBack(p);
623 return ZdAz(TMath::Pi()/2-c.Alt(), c.Az());
624}
625
626TVector3 MPointing::CorrectBack(const TVector3 &v) const
627{
628 // Correct [rad]
629 // zdaz [rad]
630 AltAz p(TMath::Pi()/2-v.Theta(), v.Phi());
631 AltAz c = CorrectBack(p);
632 TVector3 rc;
633 rc.SetMagThetaPhi(1, TMath::Pi()/2-c.Alt(), c.Az());
634 return rc;
635}
636
637void MPointing::SetParameters(const Double_t *par, Int_t n)
638{
639 Clear();
640
641 while (n--)
642 *fCoeff[n] = par[n]/kRad2Deg;
643}
644
645void MPointing::GetParameters(Double_t *par, Int_t n) const
646{
647 while (n--)
648 par[n] = *fCoeff[n]*kRad2Deg;
649}
650
651void MPointing::SetMinuitParameters(TMinuit &m, Int_t n) const
652{
653 if (n<0)
654 n = fNumPar;
655
656 Int_t ierflg = 0;
657
658 while (n--)
659 m.mnparm(n, fNames[n], *fCoeff[n]*kRad2Deg, 1, -360, 360, ierflg);
660}
661
662void MPointing::GetMinuitParameters(TMinuit &m, Int_t n)
663{
664 if (n<0 || n>m.GetNumPars())
665 n = m.GetNumPars();
666
667 while (n--)
668 {
669 m.GetParameter(n, *fCoeff[n], fError[n]);
670 *fCoeff[n] /= kRad2Deg;
671 fError[n] /= kRad2Deg;
672 }
673}
674/*
675void FormatPar(TMinuit &m, Int_t n)
676{
677 Double_t par, err;
678 m.GetParameter(n, par, err);
679
680 int expp = (int)log10(par);
681 int expe = (int)log10(err);
682
683 if (err<2*pow(10, expe))
684 expe--;
685
686 Int_t exp = expe>expp ? expp : expe;
687
688 par = (int)(par/pow(10, exp)) * pow(10, exp);
689 err = (int)(err/pow(10, exp)) * pow(10, exp);
690
691 cout << par << " +- " << err << flush;
692}
693*/
694void MPointing::PrintMinuitParameters(TMinuit &m, Int_t n) const
695{
696 if (n<0)
697 n = m.GetNumPars();
698
699 cout << setprecision(3);
700
701 Double_t par, err;
702
703 while (n--)
704 {
705 m.GetParameter(n, par, err);
706 cout << Form(" %2d %6s: ", n, (const char*)fNames[n]);
707 cout << setw(8) << par << " \xb1 " << setw(6) << err << endl;
708 }
709}
Note: See TracBrowser for help on using the repository browser.