88 #include "MLogManip.h" 105 fX = TMath::Nint(fX);
106 fY = TMath::Nint(fY);
117 fName = name ? name :
"MPointing";
118 fTitle = title ? title :
"Pointing correction model for the MAGIC telescope";
120 fCoeff =
new Double_t*[kNumPar];
121 fNames =
new TString[kNumPar];
122 fDescr =
new TString[kNumPar];
124 fCoeff[kIA] = &fIa; fNames[kIA] =
"IA";
125 fCoeff[kIE] = &fIe; fNames[kIE] =
"IE";
126 fCoeff[kFLOP] = &fFlop; fNames[kFLOP] =
"FLOP";
127 fCoeff[kAN] = &fAn; fNames[kAN] =
"AN";
128 fCoeff[kAW] = &fAw; fNames[kAW] =
"AW";
129 fCoeff[kNPAE] = &fNpae; fNames[kNPAE] =
"NPAE";
130 fCoeff[kCA] = &fCa; fNames[kCA] =
"CA";
131 fCoeff[kTF] = &fTf; fNames[kTF] =
"TF";
132 fCoeff[kTX] = &fTx; fNames[kTX] =
"TX";
133 fCoeff[kECES] = &fEces; fNames[kECES] =
"ECES";
134 fCoeff[kACES] = &fAces; fNames[kACES] =
"ACES";
135 fCoeff[kECEC] = &fEcec; fNames[kECEC] =
"ECEC";
136 fCoeff[kACEC] = &fAcec; fNames[kACEC] =
"ACEC";
137 fCoeff[kNRX] = &fNrx; fNames[kNRX] =
"NRX";
138 fCoeff[kNRY] = &fNry; fNames[kNRY] =
"NRY";
139 fCoeff[kCRX] = &fCrx; fNames[kCRX] =
"CRX";
140 fCoeff[kCRY] = &fCry; fNames[kCRY] =
"CRY";
141 fCoeff[kMAGIC1] = &fMagic1; fNames[kMAGIC1] =
"MAGIC1";
142 fCoeff[kMAGIC2] = &fMagic2; fNames[kMAGIC2] =
"MAGIC2";
143 fCoeff[kPX] = &fPx; fNames[kPX] =
"PX";
144 fCoeff[kPY] = &fPy; fNames[kPY] =
"PY";
145 fCoeff[kDX] = &
fDx; fNames[kDX] =
"DX";
146 fCoeff[kDY] = &
fDy; fNames[kDY] =
"DY";
148 fDescr[kIA] =
"Index Error Azimuth";
149 fDescr[kIE] =
"Index Error Zenith Distance";
150 fDescr[kFLOP] =
"Vertical Sag";
151 fDescr[kAN] =
"Azimuth Axis Misalignment (N-S)";
152 fDescr[kAW] =
"Azimuth Axis Misalignment (E-W)";
153 fDescr[kNPAE] =
"Az-El Nonperpendicularity";
154 fDescr[kCA] =
"Left-Right Collimation Error";
155 fDescr[kTF] =
"Tube fluxture (sin)";
156 fDescr[kTX] =
"Tube fluxture (tan)";
157 fDescr[kECES] =
"Elevation Centering Error (sin)";
158 fDescr[kACES] =
"Azimuth Centering Error (sin)";
159 fDescr[kECEC] =
"Elevation Centering Error (cos)";
160 fDescr[kACEC] =
"Azimuth Centering Error (cos)";
161 fDescr[kNRX] =
"Nasmyth rotator displacement (horizontal)";
162 fDescr[kNRY] =
"Nasmyth rotator displacement (vertical)";
163 fDescr[kCRX] =
"Alt/Az Coude Displacement (N-S)";
164 fDescr[kCRY] =
"Alt/Az Coude Displacement (E-W)";
165 fDescr[kMAGIC1] =
"MAGIC culmination hysteresis";
166 fDescr[kMAGIC2] =
"n/a";
167 fDescr[kPX] =
"Starguider calibration fixed offset x";
168 fDescr[kPY] =
"Starguider calibration fixed offset y";
169 fDescr[kDX] =
"Starguider calibration additional offset dx";
170 fDescr[kDY] =
"Starguider calibration additional offset dy";
195 *fLog << err <<
"ERROR - Cannot open file '" << name <<
"'" << endl;
200 while (fin && fin.get()!=
'\n');
203 if (c!=
'S' && c!=
's')
205 *fLog << err <<
"Error: This in not a model correcting the star position (" << c <<
")" << endl;
226 *fLog <<
" & = Name Value Sigma " << endl;
227 *fLog <<
"--------------------------------------------------" << endl;
235 *fLog << err <<
"ERROR - Reading file " << name << endl;
239 str = str.Strip(TString::kBoth);
269 sout +=
Form(
"%11f", val);
272 val *= TMath::DegToRad();
276 for (
int i=0;
i<kNumPar;
i++)
285 sout +=
Form(
"%9f%s", val, UTF8::kDeg);
287 if (*fCoeff[n]!=0 || val>0)
288 *fLog << sout << endl;
292 *fLog << err <<
"ERROR - Reading line " << str << endl;
298 *fLog << warn <<
"WARNING - Parameter " << str <<
" unknown." << endl;
303 fError[n] = val*TMath::DegToRad();
329 cout <<
"Error: Cannot open file '" << name <<
"'" << endl;
336 fout <<
"MAGIC1 " << t << endl;
337 fout <<
"S 00 000000 000000 0000000" << endl;
338 fout << setprecision(8);
339 for (
int i=0;
i<kNumPar;
i++)
341 fout <<
" " << setw(6) << GetVarName(
i) <<
" ";
342 fout << setw(13) << *fCoeff[
i]*kRad2Deg <<
" ";
343 fout << setw(11) <<
fError[
i]*kRad2Deg << endl;
345 fout <<
"END" << endl;
357 return (TMath::Pi()/2-alt < 0 ? -val : val);
366 const AltAz I(fIe, fIa);
374 AltAz p(TMath::Pi()/2-zdaz.
Zd(), zdaz.
Az());
376 AltAz c = AddOffsets(p);
378 return ZdAz(TMath::Pi()/2-c.Alt(), c.Az());
383 AltAz p(TMath::Pi()/2-v.Theta(), v.Phi());
384 AltAz c = AddOffsets(p);
387 rc.SetMagThetaPhi(1, TMath::Pi()/2-c.Alt(), c.Az());
397 const AltAz I(fIe, fIa);
405 AltAz p(TMath::Pi()/2-zdaz.
Zd(), zdaz.
Az());
407 AltAz c = SubtractOffsets(p);
409 return ZdAz(TMath::Pi()/2-c.Alt(), c.Az());
414 AltAz p(TMath::Pi()/2-v.Theta(), v.Phi());
415 AltAz c = SubtractOffsets(p);
418 rc.SetMagThetaPhi(1, TMath::Pi()/2-c.Alt(), c.Az());
433 v1.SetMagThetaPhi(1, TMath::Pi()/2-p.
Alt(), p.
Az());
442 v1.RotateY(sign*fAn);
443 v1.RotateX(sign*fAw);
450 Double_t dalt = v1.Theta()-v2.Theta();
451 Double_t daz = v1.Phi() -v2.Phi();
456 daz -= TMath::TwoPi();
457 if (daz<-TMath::Pi())
458 daz += TMath::TwoPi();
529 DEBUG(cout << setprecision(16));
530 DEBUG(cout <<
"Bend7: " << 90-p.
Alt()*180/TMath::Pi() <<
" " << p.
Az()*180/TMath::Pi() << endl);
537 DEBUG(cout <<
"Bend6: " << 90-p.
Alt()*180/TMath::Pi() <<
" " << p.
Az()*180/TMath::Pi() << endl);
539 const AltAz NRX(fNrx*sin(p.
Alt()), -fNrx);
540 const AltAz NRY(fNry*cos(p.
Alt()), -fNry*tan(p.
Alt()));
544 DEBUG(cout <<
"Bend5: " << 90-p.
Alt()*180/TMath::Pi() <<
" " << p.
Az()*180/TMath::Pi() << endl);
546 const AltAz CES(-fEces*sin(p.
Alt()), -fAces*sin(p.
Az()));
547 const AltAz CEC(-fEcec*cos(p.
Alt()), -fAcec*cos(p.
Az()));
551 DEBUG(cout <<
"Bend4: " << 90-p.
Alt()*180/TMath::Pi() <<
" " << p.
Az()*180/TMath::Pi() << endl);
553 const AltAz TX(Sign(fTx/tan(p.
Alt()), p.
Alt()), 0);
554 const AltAz TF(Sign(fTf*cos(p.
Alt()), p.
Alt()), 0);
559 DEBUG(cout <<
"Bend3: " << 90-p.
Alt()*180/TMath::Pi() <<
" " << p.
Az()*180/TMath::Pi() << endl);
580 const AltAz CA(0, -fCa/cos(p.
Alt()));
583 const AltAz NPAE(0, -fNpae*tan(p.
Alt()));
586 DEBUG(cout <<
"Bend2: " << 90-p.
Alt()*180/TMath::Pi() <<
" " << p.
Az()*180/TMath::Pi() << endl);
588 const AltAz ANAW(CalcAnAw(p, -1));
598 DEBUG(cout <<
"Bend1: " << 90-p.
Alt()*180/TMath::Pi() <<
" " << p.
Az()*180/TMath::Pi() << endl);
600 const AltAz FLOP(Sign(fFlop, p.
Alt()), 0);
603 const AltAz MAGIC1(fMagic1*TMath::Sign(1., sin(p.
Az())), 0);
606 const AltAz I(fIe, fIa);
609 DEBUG(cout <<
"Bend0: " << 90-p.Alt()*180/TMath::Pi() <<
" " << p.Az()*180/TMath::Pi() << endl);
620 DEBUG(cout << setprecision(16));
621 DEBUG(cout <<
"Back0: " << 90-p.
Alt()*180/TMath::Pi() <<
" " << p.
Az()*180/TMath::Pi() << endl);
623 const AltAz I(fIe, fIa);
626 const AltAz MAGIC1(fMagic1*TMath::Sign(1., sin(p.
Az())), 0);
632 const AltAz FLOP(Sign(fFlop, p.Alt()), 0);
635 DEBUG(cout <<
"Back1: " << 90-p.Alt()*180/TMath::Pi() <<
" " << p.Az()*180/TMath::Pi() << endl);
644 const AltAz ANAW(CalcAnAw(p, -1));
647 DEBUG(cout <<
"Back2: " << 90-p.Alt()*180/TMath::Pi() <<
" " << p.Az()*180/TMath::Pi() << endl);
650 const AltAz NPAE(0, -fNpae*tan(p.Alt()));
653 const AltAz CA(0, -fCa/cos(p.Alt()));
673 DEBUG(cout <<
"Back3: " << 90-p.Alt()*180/TMath::Pi() <<
" " << p.Az()*180/TMath::Pi() << endl);
675 const AltAz TF(Sign(fTf*cos(p.Alt()), p.Alt()), 0);
676 const AltAz TX(Sign(fTx/tan(p.Alt()), p.Alt()), 0);
680 DEBUG(cout <<
"Back4: " << 90-p.Alt()*180/TMath::Pi() <<
" " << p.Az()*180/TMath::Pi() << endl);
682 const AltAz CEC(-fEcec*cos(p.Alt()), -fAcec*cos(p.Az()));
683 const AltAz CES(-fEces*sin(p.Alt()), -fAces*sin(p.Az()));
687 DEBUG(cout <<
"Back5: " << 90-p.Alt()*180/TMath::Pi() <<
" " << p.Az()*180/TMath::Pi() << endl);
689 const AltAz NRY(fNry*cos(p.Alt()), -fNry*tan(p.Alt()));
690 const AltAz NRX(fNrx*sin(p.Alt()), -fNrx);
694 DEBUG(cout <<
"Back6: " << 90-p.Alt()*180/TMath::Pi() <<
" " << p.Az()*180/TMath::Pi() << endl);
696 const AltAz CRY(-fCry*cos(p.Az()-p.Alt()), -fCry*sin(p.Az()-p.Alt())/cos(p.Alt()));
697 const AltAz CRX(-fCrx*sin(p.Az()-p.Alt()), fCrx*cos(p.Az()-p.Alt())/cos(p.Alt()));
701 DEBUG(cout <<
"Back7: " << 90-p.Alt()*180/TMath::Pi() <<
" " << p.Az()*180/TMath::Pi() << endl);
710 AltAz p(TMath::Pi()/2-zdaz.
Zd(), zdaz.
Az());
711 AltAz c = Correct(p);
712 return ZdAz(TMath::Pi()/2-c.Alt(), c.Az());
719 AltAz p(TMath::Pi()/2-v.Theta(), v.Phi());
720 AltAz c = Correct(p);
722 rc.SetMagThetaPhi(1, TMath::Pi()/2-c.Alt(), c.Az());
730 AltAz p(TMath::Pi()/2-zdaz.
Zd(), zdaz.
Az());
731 AltAz c = CorrectBack(p);
732 return ZdAz(TMath::Pi()/2-c.Alt(), c.Az());
739 AltAz p(TMath::Pi()/2-v.Theta(), v.Phi());
740 AltAz c = CorrectBack(p);
742 rc.SetMagThetaPhi(1, TMath::Pi()/2-c.Alt(), c.Az());
751 *fCoeff[n] = par[n]/kRad2Deg;
757 par[n] = *fCoeff[n]*kRad2Deg;
763 for (
int i=0;
i<kNumPar;
i++)
764 par[
i] *= TMath::RadToDeg();
769 return TVector2(
fDx,
fDy)*TMath::RadToDeg();
774 return fPx*TMath::RadToDeg();
779 return fPy*TMath::RadToDeg();
790 m.mnparm(n, fNames[n], *fCoeff[n]*kRad2Deg, 1, -360, 360, ierflg);
795 if (n<0 || n>m.GetNumPars())
800 m.GetParameter(n, *fCoeff[n],
fError[n]);
801 *fCoeff[n] /= kRad2Deg;
830 cout << setprecision(3);
836 m.GetParameter(n, par, er);
837 cout <<
Form(
" %2d %6s: ", n, (
const char*)fNames[n]);
838 cout << setw(8) << par <<
" \xb1 " << setw(6) << er << endl;
void GetParameters(Double_t *par, Int_t n=kNumPar) const
ZdAz Correct(const ZdAz &zdaz) const
AltAz SubtractOffsets(const AltAz &aa) const
static Double_t Sign(Double_t val, Double_t alt)
ZdAz CorrectBack(const ZdAz &zdaz) const
Bool_t Save(const char *name)
Bool_t Load(const char *name)
void SetParameters(const Double_t *par, Int_t n=kNumPar)
void GetMinuitParameters(TMinuit &m, Int_t n=-1)
AltAz AddOffsets(const AltAz &aa) const
void GetError(TArrayD &par) const
void SetMinuitParameters(TMinuit &m, Int_t n=-1) const
void Init(const char *name=0, const char *title=0)
AltAz CalcAnAw(const AltAz &p, Int_t sign) const
void PrintMinuitParameters(TMinuit &m, Int_t n=-1) const