Changeset 2407 for trunk/MagicSoft/Cosy
- Timestamp:
- 10/20/03 15:54:10 (21 years ago)
- Location:
- trunk/MagicSoft/Cosy
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/MagicSoft/Cosy/Changelog
r2385 r2407 1 1 -*-*- END -*-*- 2 2003/10/20 - Thomas Bretz 3 4 * base/File.cc: 5 - only close file if f!=NULL 6 7 * base/MThread.cc: 8 - added debug output (depending on DEBUG macro) 9 10 * candrv/vmodican.cc: 11 - do not call exit in case the module couldn't be opened 12 - changes some comments 13 14 * catalog/StarCatalog.cc: 15 - do not exit in case the catalog was not found 16 - initialize fSao and fSrt with NULL 17 - only delete fSao and fSrt if != NULL 18 - only calculate stars if catalog was loaded successfully 19 20 * main/MBending.[h,cc]: 21 - added file header 22 - added class decription 23 - added FLOP, TF and TX 24 - changed such that adding new stuff is easier 25 - changed order in correction 26 - replaced all switch statement by simple loops 27 28 * tpoint/gui.C: 29 - full support for fitting a pointing correction 30 31 32 2 33 2003/10/15 - Thomas Bretz (La Palma) 3 34 -
trunk/MagicSoft/Cosy/base/File.cc
r748 r2407 12 12 File::~File() 13 13 { 14 fclose(f); 14 if (f) 15 fclose(f); 15 16 } 16 17 -
trunk/MagicSoft/Cosy/base/MThread.cc
r1953 r2407 7 7 8 8 #undef DEBUG 9 //#define DEBUG 9 10 10 11 // ---------------------------------------------------------------------- … … 91 92 fStop = false; 92 93 94 #ifdef DEBUG 95 cout << "MThread::RunThread" << endl; 96 #endif 97 93 98 void *rc = Thread(); 99 100 #ifdef DEBUG 101 cout << "MThread::RunThread...done." << endl; 102 #endif 94 103 95 104 fIsRunning = false; … … 106 115 { 107 116 MThread *thread = (MThread*)arg; 108 117 #ifdef DEBUG 118 cout << "MThread::MapThread" << endl; 119 #endif 109 120 return thread->RunThread(); 110 121 } -
trunk/MagicSoft/Cosy/candrv/vmodican.cc
r2278 r2407 762 762 // /* can_send - send message to standard host interface (mid priority) 763 763 // * 764 // * This function sends a complete message to the standard host interface of765 // * a VMOD-ICAN.764 // * This function sends a complete message to the standard host interface 765 // * of a VMOD-ICAN. 766 766 // * 767 767 // * The message <pm> will be queued to the middle prioritized of the three … … 951 951 cout << strerror(errno) << endl; 952 952 return; 953 // exit(1); // open module954 953 } 955 954 -
trunk/MagicSoft/Cosy/catalog/StarCatalog.cc
r2278 r2407 14 14 ClassImp(StarCatalog); 15 15 16 StarCatalog::StarCatalog(MObservatory::LocationName_t key) : SlaStars(key), f Entries(0), fSinAngle(0), fCosAngle(1)16 StarCatalog::StarCatalog(MObservatory::LocationName_t key) : SlaStars(key), fSao(NULL), fSrt(NULL), fEntries(0), fSinAngle(0), fCosAngle(1) 17 17 { 18 18 // p = pointer to MainFrame (not owner) … … 22 22 // 23 23 File idx("sao/sao-sort.idx", "r"); 24 25 24 if (!idx) 26 exit(0);25 return; 27 26 28 27 while (!idx.Eof()) … … 52 51 StarCatalog::~StarCatalog() 53 52 { 54 delete fSrt; 55 delete fSao; 53 if (fSrt) 54 delete fSrt; 55 if (fSao) 56 delete fSao; 56 57 } 57 58 … … 647 648 // --------- search for stars in catalog ---------- 648 649 // 650 if (fEntries==0) 651 return; 652 649 653 int count = 0; 650 654 int deleted = 0; -
trunk/MagicSoft/Cosy/main/MBending.cc
r1810 r2407 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-2003 21 ! 22 ! 23 \* ======================================================================== */ 24 25 ///////////////////////////////////////////////////////////////////////////// 26 // 27 // MBending 28 // 29 // Double_t fIe ; // [rad] Index Error in Elevation 30 // Double_t fIa ; // [rad] Index Error in Azimuth 31 // 32 // Double_t fFlop ; // [rad] Vertical Sag 33 // * do not use if not data: Zd<0 34 // 35 // Double_t fNpae ; // [rad] Az-El Nonperpendicularity 36 // 37 // Double_t fCa ; // [rad] Left-Right Collimation Error 38 // 39 // Double_t fAn ; // [rad] Azimuth Axis Misalignment (N-S) 40 // Double_t fAw ; // [rad] Azimuth Axis Misalignment (E-W) 41 // 42 // Double_t fTf ; // [rad] Tube fluxture (sin) 43 // * same as ecec if no data: Zd<0 44 // Double_t fTx ; // [rad] Tube fluxture (tan) 45 // * do not use with NPAE if no data: Zd<0 46 // 47 // Double_t fNrx ; // [rad] Nasmyth rotator displacement, horizontan 48 // Double_t fNry ; // [rad] Nasmyth rotator displacement, vertical 49 // 50 // Double_t fCrx ; // [rad] Alt/Az Coude Displacement (N-S) 51 // Double_t fCry ; // [rad] Alt/Az Coude Displacement (E-W) 52 // 53 // Double_t fEces ; // [rad] Elevation Centering Error (sin) 54 // Double_t fAces ; // [rad] Azimuth Centering Error (sin) 55 // Double_t fEcec ; // [rad] Elevation Centering Error (cos) 56 // Double_t fAcec ; // [rad] Azimuth Centering Error (cos) 57 // 58 //////////////////////////////////////////////////////////////////////////// 1 59 #include "MBending.h" 2 60 … … 10 68 ClassImp(MBending); 11 69 70 const Int_t MBending::fNumPar=19; 71 72 void MBending::Init() 73 { 74 fCoeff = new Double_t*[fNumPar]; 75 fName = new TString[fNumPar]; 76 fDescr = new TString[fNumPar]; 77 78 fCoeff[ 0] = &fIa; fName[ 0] = "IA"; 79 fCoeff[ 1] = &fIe; fName[ 1] = "IE"; 80 fCoeff[ 2] = &fFlop; fName[ 2] = "FLOP"; 81 fCoeff[ 3] = &fNpae; fName[ 3] = "NPAE"; 82 fCoeff[ 4] = &fCa; fName[ 4] = "CA"; 83 fCoeff[ 5] = &fAn; fName[ 5] = "AN"; 84 fCoeff[ 6] = &fAw; fName[ 6] = "AW"; 85 fCoeff[ 7] = &fTf; fName[ 7] = "TF"; 86 fCoeff[ 8] = &fTx; fName[ 8] = "TX"; 87 fCoeff[ 9] = &fEces; fName[ 9] = "ECES"; 88 fCoeff[10] = &fAces; fName[10] = "ACES"; 89 fCoeff[11] = &fEcec; fName[11] = "ECEC"; 90 fCoeff[12] = &fAcec; fName[12] = "ACEC"; 91 fCoeff[13] = &fNrx; fName[13] = "NRX"; 92 fCoeff[14] = &fNry; fName[14] = "NRY"; 93 fCoeff[15] = &fCrx; fName[15] = "CRX"; 94 fCoeff[16] = &fCry; fName[16] = "CRY"; 95 fCoeff[17] = &fMagic1; fName[17] = "MAGIC1"; 96 fCoeff[18] = &fMagic2; fName[18] = "MAGIC2"; 97 98 fDescr[ 0] = "Index Error Azimuth"; 99 fDescr[ 1] = "Index Error Zenith Distance"; 100 fDescr[ 2] = "Vertical Sag"; 101 fDescr[ 3] = "Az-El Nonperpendicularity"; 102 fDescr[ 4] = "Left-Right Collimation Error"; 103 fDescr[ 5] = "Azimuth Axis Misalignment (N-S)"; 104 fDescr[ 6] = "Azimuth Axis Misalignment (E-W)"; 105 fDescr[ 7] = "Tube fluxture (sin)"; 106 fDescr[ 8] = "Tube fluxture (tan)"; 107 fDescr[ 9] = "Elevation Centering Error (sin)"; 108 fDescr[10] = "Azimuth Centering Error (sin)"; 109 fDescr[11] = "Elevation Centering Error (cos)"; 110 fDescr[12] = "Azimuth Centering Error (cos)"; 111 fDescr[13] = "Nasmyth rotator displacement (horizontal)"; 112 fDescr[14] = "Nasmyth rotator displacement (vertical)"; 113 fDescr[15] = "Alt/Az Coude Displacement (N-S)"; 114 fDescr[16] = "Alt/Az Coude Displacement (E-W)"; 115 fDescr[17] = "n/a"; 116 fDescr[18] = "n/a"; 117 } 12 118 void MBending::Reset() 13 119 { … … 62 168 cout << endl; 63 169 64 cout << " & = Name ValueSigma" << endl;65 cout << "------------------------------------------ " << endl;170 cout << " & = Name Value Sigma" << endl; 171 cout << "--------------------------------------------------" << endl; 66 172 67 173 while (fin) … … 90 196 91 197 fin >> val; 92 cout << str << "\t" << val << "°\t";198 cout << str << "\t" << setw(11) << val << "° \t"; 93 199 val *= kDeg2Rad; 94 200 95 if (str=="IA") fIa = val; 96 if (str=="IE") fIe = val; 97 if (str=="CA") fCa = val; 98 if (str=="AN") fAn = val; 99 if (str=="AW") fAw = val; 100 if (str=="NRX") fNrx = val; 101 if (str=="NRY") fNry = val; 102 if (str=="CRX") fCrx = val; 103 if (str=="CRY") fCry = val; 104 if (str=="NPAE") fNpae = val; 105 if (str=="ECES") fEces = val; 106 if (str=="ACES") fAces = val; 107 if (str=="ECEC") fEcec = val; 108 if (str=="ACEC") fAcec = val; 109 //if (str=="MAGIC1") fMagic1 = val; 110 //if (str=="MAGIC2") fMagic2 = val; 201 Double_t *dest=NULL; 202 203 if (str=="IA") dest = &fIa; 204 if (str=="IE") dest = &fIe; 205 if (str=="FLOP") dest = &fFlop; 206 if (str=="NPAE") dest = &fNpae; 207 if (str=="CA") dest = &fCa; 208 if (str=="AN") dest = &fAn; 209 if (str=="AW") dest = &fAw; 210 if (str=="TF") dest = &fTf; 211 if (str=="TX") dest = &fTx; 212 if (str=="NRX") dest = &fNrx; 213 if (str=="NRY") dest = &fNry; 214 if (str=="CRX") dest = &fCrx; 215 if (str=="CRY") dest = &fCry; 216 if (str=="ECES") dest = &fEces; 217 if (str=="ACES") dest = &fAces; 218 if (str=="ECEC") dest = &fEcec; 219 if (str=="ACEC") dest = &fAcec; 220 221 if (dest) 222 *dest = val; 111 223 112 224 fin >> val; 113 cout << val*kDeg2Rad << endl; 225 cout << setw(9) << val << "°" << endl; 226 227 // Find corresponding error 228 for (int i=0; i<MBending::GetNumPar(); i++) 229 if (dest==fCoeff[i]) 230 { 231 fError[i] = val*kDeg2Rad; 232 break; 233 } 114 234 } 115 235 cout << endl; … … 143 263 fout << "S 00 000000 000000 0000000" << endl; 144 264 fout << setprecision(8); 145 fout << " IA " << kRad2Deg*fIa << " -1" << endl; 146 fout << " IE " << kRad2Deg*fIe << " -1" << endl; 147 fout << " CA " << kRad2Deg*fNpae << " -1" << endl; 148 fout << " NPAE " << kRad2Deg*fCa << " -1" << endl; 149 fout << " AN " << kRad2Deg*fAn << " -1" << endl; 150 fout << " AW " << kRad2Deg*fAw << " -1" << endl; 151 fout << " NRX " << kRad2Deg*fNrx << " -1" << endl; 152 fout << " NRY " << kRad2Deg*fNry << " -1" << endl; 153 fout << " CRX " << kRad2Deg*fCrx << " -1" << endl; 154 fout << " CRY " << kRad2Deg*fCry << " -1" << endl; 155 fout << " ECES " << kRad2Deg*fEces << " -1" << endl; 156 fout << " ACES " << kRad2Deg*fAces << " -1" << endl; 157 fout << " ECEC " << kRad2Deg*fEcec << " -1" << endl; 158 fout << " ACEC " << kRad2Deg*fAcec << " -1" << endl; 159 //fout << " MAGIC1 " << -kRad2Deg*fMagic1 << " -1" << endl; 160 //fout << " MAGIC2 " << -kRad2Deg*fMagic2 << " -1" << endl; 265 for (int i=0; i<fNumPar; i++) 266 { 267 fout << " " << setw(6) << GetName(i) << " "; 268 fout << setw(13) << *fCoeff[i]*kRad2Deg << " "; 269 fout << setw(11) << fError[i]*kRad2Deg << endl; 270 } 161 271 fout << "END" << endl; 272 } 273 274 Double_t MBending::Sign(Double_t val, Double_t alt) 275 { 276 // Some pointing corrections are defined as Delta ZA, which 277 // is (P. Wallace) defined [0,90]deg while Alt is defined 278 // [0,180]deg 279 return (TMath::Pi()/2-alt < 0 ? -val : val); 162 280 } 163 281 … … 167 285 // zdaz [rad] 168 286 AltAz p = aa; 287 288 const AltAz CRX(-fCrx*sin(p.Az()-p.Alt()), fCrx*cos(p.Az()-p.Alt())/cos(p.Alt())); 289 const AltAz CRY(-fCry*cos(p.Az()-p.Alt()), -fCry*sin(p.Az()-p.Alt())/cos(p.Alt())); 290 p += CRX; 291 p += CRY; 292 293 const AltAz NRX(fNrx*sin(p.Alt()), -fNrx); 294 const AltAz NRY(fNry*cos(p.Alt()), -fNry*tan(p.Alt())); 295 p += NRX; 296 p += NRY; 169 297 170 298 const AltAz CES(-fEces*sin(p.Alt()), -fAces*sin(p.Az())); … … 173 301 p += CEC; 174 302 175 // const AltAz MAGIC(0, -fMagic1*tan(p.Alt())-fMagic2); 176 // p += MAGIC; 177 178 const AltAz CRX(-fCrx*sin(p.Az()-p.Alt()), fCrx*cos(p.Az()-p.Alt())/cos(p.Alt())); 179 const AltAz CRY(-fCry*cos(p.Az()-p.Alt()), -fCry*sin(p.Az()-p.Alt())/cos(p.Alt())); 180 p += CRX; 181 p += CRY; 182 183 const AltAz NRX(fNrx*sin(p.Alt()), -fNrx); 184 const AltAz NRY(fNry*cos(p.Alt()), -fNry*tan(p.Alt())); 185 p += NRX; 186 p += NRY; 187 188 // const AltAz MAGIC(-fMagic1*sin(p.Az()-fMagic2), 0); 189 // p += MAGIC; 303 const AltAz TX(Sign(fTx/tan(p.Alt()), p.Alt()), 0); 304 const AltAz TF(Sign(fTf*cos(p.Alt()), p.Alt()), 0); 305 p += TX; 306 p += TF; 190 307 191 308 const AltAz AW( fAw*sin(p.Az()), -fAw*cos(p.Az())*tan(p.Alt())); … … 194 311 p += AN; 195 312 196 // const AltAz MAGIC(-fMagic1*sin(p.Az()-fMagic2), 0);197 // p += MAGIC;198 199 313 const AltAz CA(0, -fCa/cos(p.Alt())); 200 314 p += CA; … … 202 316 const AltAz NPAE(0, -fNpae*tan(p.Alt())); 203 317 p += NPAE; 318 319 const AltAz FLOP(Sign(fFlop, p.Alt()), 0); 320 p += FLOP; 204 321 205 322 const AltAz I(fIe, fIa); … … 217 334 const AltAz I(fIe, fIa); 218 335 p -= I; 336 337 const AltAz FLOP(Sign(fFlop, p.Alt()), 0); 338 p -= FLOP; 219 339 220 340 const AltAz NPAE(0, -fNpae*tan(p.Alt())); … … 229 349 p -= AW; 230 350 231 // const AltAz MAGIC(-fMagic1*sin(p.Az()-fMagic2), 0); 232 // p -= MAGIC; 351 const AltAz TF(Sign(fTf*cos(p.Alt()), p.Alt()), 0); 352 const AltAz TX(Sign(fTx/tan(p.Alt()), p.Alt()), 0); 353 p -= TF; 354 p -= TX; 355 356 const AltAz CEC(-fEcec*cos(p.Alt()), -fAcec*cos(p.Az())); 357 const AltAz CES(-fEces*sin(p.Alt()), -fAces*sin(p.Az())); 358 p -= CEC; 359 p -= CES; 233 360 234 361 const AltAz NRY(fNry*cos(p.Alt()), -fNry*tan(p.Alt())); … … 241 368 p -= CRY; 242 369 p -= CRX; 243 244 const AltAz CEC(-fEcec*cos(p.Alt()), -fAcec*cos(p.Az()));245 const AltAz CES(-fEces*sin(p.Alt()), -fAces*sin(p.Az()));246 p -= CEC;247 p -= CES;248 370 249 371 return p; … … 272 394 Clear(); 273 395 274 switch (n) 275 { 276 case 16: 277 fMagic2=par[15]/kRad2Deg; // Magic User Defined 278 case 15: 279 fMagic1=par[14]/kRad2Deg; // Magic User Defined 280 case 14: 281 fAcec =par[13]/kRad2Deg; // Azimuth Centering Error (cos) 282 case 13: 283 fEcec =par[12]/kRad2Deg; // Elevation Centering Error (cos) 284 case 12: 285 fAces =par[11]/kRad2Deg; // Azimuth Centering Error (sin) 286 case 11: 287 fEces =par[10]/kRad2Deg; // Elevation Centering Error (sin) 288 case 10: 289 fCry =par[9] /kRad2Deg; // Alt/Az Coude Displacement (E-W) 290 case 9: 291 fCrx =par[8] /kRad2Deg; // Alt/Az Coude Displacement (N-S) 292 case 8: 293 fNry =par[7] /kRad2Deg; // Nasmyth rotator displacement, vertical 294 case 7: 295 fNrx =par[6] /kRad2Deg; // Nasmyth rotator displacement, horizontan 296 case 6: 297 fAw =par[5] /kRad2Deg; // Azimuth Axis Misalignment (E-W) 298 case 5: 299 fAn =par[4] /kRad2Deg; // Azimuth Axis Misalignment (N-S) 300 case 4: 301 fCa =par[3] /kRad2Deg; // Left-Right Collimation Error 302 case 3: 303 fNpae =par[2] /kRad2Deg; // Az-El Nonperpendicularity 304 case 2: 305 fIe =par[1] /kRad2Deg; // Index Error in Elevation 306 case 1: 307 fIa =par[0] /kRad2Deg; // Index Error in Azimuth 308 } 396 while (n--) 397 *fCoeff[n] = par[n]/kRad2Deg; 309 398 } 310 399 311 400 void MBending::GetParameters(Double_t *par, Int_t n) const 312 401 { 313 switch (n) 314 { 315 case 16: 316 par[15]=kRad2Deg*fMagic2; // 317 case 15: 318 par[14]=kRad2Deg*fMagic1; // 319 case 14: 320 par[13]=kRad2Deg*fAcec; // Azimuth Centering Error (cos) 321 case 13: 322 par[12]=kRad2Deg*fEcec; // Elevation Centering Error (cos) 323 case 12: 324 par[11]=kRad2Deg*fAces; // Azimuth Centering Error (sin) 325 case 11: 326 par[10]=kRad2Deg*fEces; // Elevation Centering Error (sin) 327 case 10: 328 par[9] =kRad2Deg*fCry; // Alt/Az Coude Displacement (E-W) 329 case 9: 330 par[8] =kRad2Deg*fCrx; // Alt/Az Coude Displacement (N-S) 331 case 8: 332 par[7] =kRad2Deg*fNry; // Nasmyth rotator displacement, vertical 333 case 7: 334 par[6] =kRad2Deg*fNrx; // Nasmyth rotator displacement, horizontan 335 case 6: 336 par[5] =kRad2Deg*fAw; // Azimuth Axis Misalignment (E-W) 337 case 5: 338 par[4] =kRad2Deg*fAn; // Azimuth Axis Misalignment (N-S) 339 case 4: 340 par[3] =kRad2Deg*fCa; // Left-Right Collimation Error 341 case 3: 342 par[2] =kRad2Deg*fNpae; // Az-El Nonperpendicularity 343 case 2: 344 par[1] =kRad2Deg*fIe; // Index Error in Elevation 345 case 1: 346 par[0] =kRad2Deg*fIa; // Index Error in Azimuth 347 } 402 while (n--) 403 par[n] = *fCoeff[n]*kRad2Deg; 348 404 } 349 405 … … 351 407 { 352 408 if (n<0) 353 n = 16;409 n = fNumPar; 354 410 355 411 Int_t ierflg = 0; 356 412 357 switch (n) 358 { 359 case 16: 360 m.mnparm(15,"MAGIC2", fMagic2*kRad2Deg, 1, -360, 360, ierflg); 361 case 15: 362 m.mnparm(14,"MAGIC1", fMagic1*kRad2Deg, 1, -360, 360, ierflg); 363 case 14: 364 m.mnparm(13,"ACEC", fAcec*kRad2Deg, 1, -360, 360, ierflg); 365 case 13: 366 m.mnparm(12,"ECEC", fEcec*kRad2Deg, 1, -360, 360, ierflg); 367 case 12: 368 m.mnparm(11,"ACES", fAcec*kRad2Deg, 1, -360, 360, ierflg); 369 case 11: 370 m.mnparm(10,"ECES", fEcec*kRad2Deg, 1, -360, 360, ierflg); 371 case 10: 372 m.mnparm(9, "CRY", fCry*kRad2Deg, 1, -360, 360, ierflg); 373 case 9: 374 m.mnparm(8, "CRX", fCrx*kRad2Deg, 1, -360, 360, ierflg); 375 case 8: 376 m.mnparm(7, "NRY", fNry*kRad2Deg, 1, -360, 360, ierflg); 377 case 7: 378 m.mnparm(6, "NRX", fNrx*kRad2Deg, 1, -360, 360, ierflg); 379 case 6: 380 m.mnparm(5, "AW", fAw*kRad2Deg, 1, -360, 360, ierflg); 381 case 5: 382 m.mnparm(4, "AN", fAn*kRad2Deg, 1, -360, 360, ierflg); 383 case 4: 384 m.mnparm(3, "CA", fCa*kRad2Deg, 1, -360, 360, ierflg); 385 case 3: 386 m.mnparm(2, "NPAE", fNpae*kRad2Deg, 1, -360, 360, ierflg); 387 case 2: 388 m.mnparm(1, "IE", fIe*kRad2Deg, 1, -90, 90, ierflg); 389 case 1: 390 m.mnparm(0, "IA", fIa*kRad2Deg, 1, -360, 360, ierflg); 391 } 413 while (n--) 414 m.mnparm(n, fName[n], *fCoeff[n]*kRad2Deg, 1, -360, 360, ierflg); 392 415 } 393 416 … … 397 420 n = m.GetNumPars(); 398 421 399 Double_t err; 400 401 switch (n) 402 { 403 case 16: 404 m.GetParameter(15, fMagic2, err); 405 fMagic2 /= kRad2Deg; 406 case 15: 407 m.GetParameter(14, fMagic1, err); 408 fMagic1 /= kRad2Deg; 409 case 14: 410 m.GetParameter(13, fAcec, err); 411 fAcec /= kRad2Deg; 412 case 13: 413 m.GetParameter(12, fEcec, err); 414 fEcec /= kRad2Deg; 415 case 12: 416 m.GetParameter(11, fAces, err); 417 fAces /= kRad2Deg; 418 case 11: 419 m.GetParameter(10, fEces, err); 420 fEces /= kRad2Deg; 421 case 10: 422 m.GetParameter(9, fCry, err); 423 fCry /= kRad2Deg; 424 case 9: 425 m.GetParameter(8, fCrx, err); 426 fCrx /= kRad2Deg; 427 case 8: 428 m.GetParameter(7, fNry, err); 429 fNry /= kRad2Deg; 430 case 7: 431 m.GetParameter(6, fNrx, err); 432 fNrx /= kRad2Deg; 433 case 6: 434 m.GetParameter(5, fAw, err); 435 fAw /= kRad2Deg; 436 case 5: 437 m.GetParameter(4, fAn, err); 438 fAn /= kRad2Deg; 439 case 4: 440 m.GetParameter(3, fCa, err); 441 fCa /= kRad2Deg; 442 case 3: 443 m.GetParameter(2, fNpae, err); 444 fNpae /= kRad2Deg; 445 case 2: 446 m.GetParameter(1, fIe, err); 447 fIe /= kRad2Deg; 448 case 1: 449 m.GetParameter(0, fIa, err); 450 fIa /= kRad2Deg; 422 while (n--) 423 { 424 m.GetParameter(n, *fCoeff[n], fError[n]); 425 *fCoeff[n] /= kRad2Deg; 426 fError[n] /= kRad2Deg; 451 427 } 452 428 } … … 480 456 Double_t par, err; 481 457 482 switch (n) 483 { 484 case 16: 485 m.GetParameter(15, par, err); 486 cout << " 15 MAGIC2: " << setw(8) << par << " +- " << setw(4) << err << endl; 487 case 15: 488 m.GetParameter(14, par, err); 489 cout << " 14 MAGIC1: " << setw(8) << par << " +- " << setw(4) << err << endl; 490 case 14: 491 m.GetParameter(13, par, err); 492 cout << " 13 ACEC: " << setw(8) << par << " +- " << setw(4) << err << " Azimuth Centering Error (cos)" << endl; 493 case 13: 494 m.GetParameter(12, par, err); 495 cout << " 12 ECEC: " << setw(8) << par << " +- " << setw(4) << err << " Elevation Centering Error (cos)" << endl; 496 case 12: 497 m.GetParameter(11, par, err); 498 cout << " 11 ACES: " << setw(8) << par << " +- " << setw(4) << err << " Azimuth Centering Error (sin)" << endl; 499 case 11: 500 m.GetParameter(10, par, err); 501 cout << " 10 ECES: " << setw(8) << par << " +- " << setw(4) << err << " Elevation Centering Error (sin)" << endl; 502 case 10: 503 m.GetParameter(9, par, err); 504 cout << " 9 CRY: " << setw(8) << par << " +- " << setw(4) << err << " Alt/Az Coude Displacement (E-W)" << endl; 505 case 9: 506 m.GetParameter(8, par, err); 507 cout << " 8 CRX: " << setw(8) << par << " +- " << setw(4) << err << " Alt/Az Coude Displacement (N-S)" << endl; 508 case 8: 509 m.GetParameter(7, par, err); 510 cout << " 7 NRY: " << setw(8) << par << " +- " << setw(4) << err << " Nasmyth rotator displacement, vertical" << endl; 511 case 7: 512 m.GetParameter(6, par, err); 513 cout << " 6 NRX: " << setw(8) << par << " +- " << setw(4) << err << " Nasmyth rotator displacement, horizontan" << endl; 514 case 6: 515 m.GetParameter(5, par, err); 516 cout << " 5 AW: " << setw(8) << par << " +- " << setw(4) << err << " Azimuth Axis Misalignment (E-W)" << endl; 517 case 5: 518 m.GetParameter(4, par, err); 519 cout << " 4 AN: " << setw(8) << par << " +- " << setw(4) << err << " Azimuth Axis Misalignment (N-S)" << endl; 520 case 4: 521 m.GetParameter(3, par, err); 522 cout << " 3 CA: " << setw(8) << par << " +- " << setw(4) << err << " Left-Right Collimation Error" << endl; 523 case 3: 524 m.GetParameter(2, par, err); 525 cout << " 2 NPAE: " << setw(8) << par << " +- " << setw(4) << err << " Az-El Nonperpendicularity" << endl; 526 case 2: 527 m.GetParameter(1, par, err); 528 cout << " 1 IE: " << setw(8) << par << " +- " << setw(4) << err << " Index Error Elevation (Offset)" << endl; 529 case 1: 530 m.GetParameter(0, par, err); 531 cout << " 0 IA: " << setw(8) << par << " +- " << setw(4) << err << " Index Error Azimuth (Offset)" << endl; 532 } 533 } 458 while (n--) 459 { 460 m.GetParameter(n, par, err); 461 cout << Form(" %2d %6s: ", n, (const char*)fName[n]); 462 cout << setw(8) << par << " \xb1 " << setw(6) << err << endl; 463 } 464 } -
trunk/MagicSoft/Cosy/main/MBending.h
r1953 r2407 3 3 4 4 #include "coord.h" 5 6 #ifndef ROOT_TArrayD 7 #include <TArrayD.h> 8 #endif 5 9 6 10 class TMinuit; … … 9 13 { 10 14 private: 15 static const Int_t fNumPar; 16 11 17 Double_t fIe ; // [rad] Index Error in Elevation 12 18 Double_t fIa ; // [rad] Index Error in Azimuth 19 Double_t fFlop ; // [rad] Vertical Sag 20 Double_t fNpae ; // [rad] Az-El Nonperpendicularity 13 21 Double_t fCa ; // [rad] Left-Right Collimation Error 14 22 Double_t fAn ; // [rad] Azimuth Axis Misalignment (N-S) 15 23 Double_t fAw ; // [rad] Azimuth Axis Misalignment (E-W) 16 Double_t fNpae ; // [rad] Az-El Nonperpendicularity 17 Double_t fNrx ; // [rad] Nasmyth rotator displacement, horizontan 24 Double_t fTf ; // [rad] Tube fluxture (sin) 25 Double_t fTx ; // [rad] Tube fluxture (tan) 26 Double_t fNrx ; // [rad] Nasmyth rotator displacement, horizontal 18 27 Double_t fNry ; // [rad] Nasmyth rotator displacement, vertical 19 28 Double_t fCrx ; // [rad] Alt/Az Coude Displacement (N-S) … … 26 35 Double_t fMagic2; // [rad] Magic Term (what is it?) 27 36 37 Double_t **fCoeff; //! 38 TString *fName; //! 39 TString *fDescr; //! 40 41 TArrayD fError; 42 43 void Init(); 28 44 29 45 void Clear() 30 46 { 31 fIe =0 ; // Index Error in Elevation 32 fIa =0 ; // Index Error in Azimuth 33 fCa =0 ; // Left-Right Collimation Error 34 fAn =0 ; // Azimuth Axis Misalignment (N-S) 35 fAw =0 ; // Azimuth Axis Misalignment (E-W) 36 fNpae=0 ; // Az-El Nonperpendicularity 37 fNrx =0 ; // Nasmyth rotator displacement, horizontan 38 fNry =0 ; // Nasmyth rotator displacement, vertical 39 fCrx =0 ; // Alt/Az Coude Displacement (N-S) 40 fCry =0 ; // Alt/Az Coude Displacement (E-W) 41 fEces=0 ; // Elevation Centering Error (sin) 42 fAces=0 ; // Azimuth Centering Error (sin) 43 fEcec=0 ; // Elevation Centering Error (cos) 44 fAcec=0 ; // Azimuth Centering Error (cos) 45 fMagic1=0; // Azimuth Centering Error (cos) 46 fMagic2=0; // Azimuth Centering Error (cos) 47 for (int i=0; i<fNumPar; i++) 48 { 49 *fCoeff[i] = 0; 50 fError[i] = 0; 51 } 47 52 } 48 53 54 static Double_t Sign(Double_t val, Double_t alt); 55 49 56 public: 50 MBending() { Clear(); } 51 MBending(const char *name) { Clear(); Load(name); } 57 MBending() { fError.Set(fNumPar); Init(); Clear(); } 58 MBending(const char *name) { fError.Set(fNumPar); Init(); Clear(); Load(name); } 59 virtual ~MBending() { delete fName; delete fCoeff; delete fDescr; } 52 60 53 61 void Load(const char *name); … … 67 75 ZdAz operator()(const ZdAz &zdaz, void (*fcn)(ZdAz &zdaz, Double_t *par)) const 68 76 { 69 Double_t par[ 16];77 Double_t par[fNumPar]; 70 78 GetParameters(par); 71 79 ZdAz za = zdaz; … … 76 84 AltAz operator()(const AltAz &aaz, void (*fcn)(AltAz &aaz, Double_t *par)) const 77 85 { 78 Double_t par[ 16];86 Double_t par[fNumPar]; 79 87 GetParameters(par); 80 88 AltAz aa = aaz; … … 83 91 } 84 92 85 void SetParameters(const Double_t *par, Int_t n=16); 86 void GetParameters(Double_t *par, Int_t n=16) const; 93 void SetParameters(const Double_t *par, Int_t n=fNumPar); 94 void GetParameters(Double_t *par, Int_t n=fNumPar) const; 95 96 void SetParameters(const TArrayD &par) 97 { 98 SetParameters(par.GetArray(), par.GetSize()); 99 } 100 void GetParameters(TArrayD &par) const 101 { 102 par.Set(fNumPar); 103 GetParameters(par.GetArray()); 104 } 105 void GetError(TArrayD &par) const 106 { 107 par = fError; 108 for (int i=0; i<fNumPar; i++) 109 par[i] *= kRad2Deg; 110 } 87 111 88 112 void SetMinuitParameters(TMinuit &m, Int_t n=-1) const; 89 113 void GetMinuitParameters(TMinuit &m, Int_t n=-1); 90 114 void PrintMinuitParameters(TMinuit &m, Int_t n=-1) const; 115 116 const TString &GetName(int i) const { return fName[i]; } 117 const TString &GetDescription(int i) const { return fDescr[i]; } 91 118 92 119 /* … … 107 134 */ 108 135 136 static const Int_t GetNumPar() { return fNumPar; } 109 137 ClassDef(MBending, 1) 110 138 }; -
trunk/MagicSoft/Cosy/tpoint/gui.C
r1811 r2407 1 #include <fstream.h> 1 2 #include <iostream.h> 3 #include <iomanip.h> 2 4 3 5 #include <TGFrame.h> … … 5 7 #include <TGButton.h> 6 8 9 #include <TF1.h> 10 #include <TH1.h> 11 #include <TH2.h> 12 #include <TGraph.h> 13 14 #include <TList.h> 15 #include <TStyle.h> 16 #include <TMinuit.h> 17 18 #include <TView.h> 19 #include <TLine.h> 20 #include <TMarker.h> 21 #include <TCanvas.h> 22 23 #include "coord.h" 24 7 25 #include "MGList.h" 8 26 #include "MBending.h" 27 28 class Set : public TObject 29 { 30 friend ifstream &operator>>(ifstream &fin, Set &set); 31 private: 32 Double_t fStarAz; 33 Double_t fStarEl; 34 35 Double_t fRawAz; 36 Double_t fRawEl; 37 38 public: 39 Set(Double_t sel=0, Double_t saz=0, Double_t rel=0, Double_t raz=0) : 40 fStarAz(saz*TMath::Pi()/180), 41 fStarEl(sel*TMath::Pi()/180), 42 fRawAz(raz*TMath::Pi()/180), 43 fRawEl(rel*TMath::Pi()/180) 44 { 45 } 46 47 Double_t GetResidual() const 48 { 49 Double_t del = fRawEl-fStarEl; 50 Double_t daz = fRawAz-fStarAz; 51 Double_t dphi2 = daz/2.; 52 Double_t cos2 = cos(dphi2)*cos(dphi2); 53 Double_t sin2 = sin(dphi2)*sin(dphi2); 54 Double_t d = cos(del)*cos2 - cos(fRawEl+fStarEl)*sin2; 55 56 Double_t dist = acos(d); 57 58 return dist * 180 / TMath::Pi(); 59 } 60 61 void operator=(Set &set) 62 { 63 fStarAz = set.fStarAz; 64 fStarEl = set.fStarEl; 65 fRawAz = set.fRawAz; 66 fRawEl = set.fRawEl; 67 } 68 69 Double_t GetDEl() const { return (fRawEl-fStarEl)*180/TMath::Pi(); } 70 Double_t GetDZd() const { return -GetDEl(); } 71 Double_t GetDAz() const { return (fRawAz-fStarAz)*180/TMath::Pi(); } 72 Double_t GetStarEl() const { return fStarEl*180/TMath::Pi(); } 73 Double_t GetStarZd() const { return 90.-fStarEl*180/TMath::Pi(); } 74 Double_t GetStarAz() const { return fStarAz*180/TMath::Pi(); } 75 Double_t GetRawEl() const { return fRawEl*180/TMath::Pi(); } 76 Double_t GetRawAz() const { return fRawAz*180/TMath::Pi(); } 77 Double_t GetRawZd() const { return 90.-fRawEl*180/TMath::Pi(); } 78 79 ZdAz GetStarZdAz() const { return ZdAz(TMath::Pi()/2-fStarEl, fStarAz); } 80 AltAz GetStarAltAz() const { return AltAz(fStarEl, fStarAz); } 81 82 ZdAz GetRawZdAz() const { return ZdAz(TMath::Pi()/2-fRawEl, fRawAz); } 83 AltAz GetRawAltAz() const { return AltAz(fRawEl, fRawAz); } 84 85 void AdjustEl(Double_t del) { fStarEl += del*TMath::Pi()/180; } 86 void AdjustAz(Double_t daz) { fStarAz += daz*TMath::Pi()/180; } 87 88 void Adjust(const MBending &bend) 89 { 90 AltAz p = bend(GetStarAltAz()); 91 fStarEl = p.Alt(); 92 fStarAz = p.Az(); 93 } 94 void AdjustBack(const MBending &bend) 95 { 96 AltAz p = bend.CorrectBack(GetRawAltAz()); 97 fRawEl = p.Alt(); 98 fRawAz = p.Az(); 99 } 100 ClassDef(Set, 0) 101 }; 102 103 ClassImp(Set); 104 105 ifstream &operator>>(ifstream &fin, Set &set) 106 { 107 Double_t v[4]; 108 fin >> v[0]; 109 fin >> v[1]; 110 fin >> v[2]; 111 fin >> v[3]; 112 113 Double_t dummy; 114 fin>>dummy; 115 fin>>dummy; 116 fin>>dummy; 117 118 set.fStarAz = v[0]*TMath::Pi()/180; 119 set.fStarEl = v[1]*TMath::Pi()/180; 120 121 set.fRawAz = v[2]*TMath::Pi()/180; 122 set.fRawEl = v[3]*TMath::Pi()/180; 123 124 return fin; 125 } 9 126 10 127 class MFit : public TGMainFrame … … 12 129 private: 13 130 enum { 14 kCbIA, 15 kCbIE, 16 kCbNPAE, 17 kCbCA, 18 kCbAN, 19 kCbAW, 20 kCbCRX, 21 kCbCRY, 22 kCbNRX, 23 kCbNRY 131 kTbFit = 19, //MBending::GetNumPar(), // FIXME!!! 132 kTbLoad, 133 kTbSave, 134 kTbLoadStars, 135 kTbReset, 136 kTbResetStars 24 137 }; 25 138 26 MGList *list; 139 MGList *fList; 140 141 TList fOriginal; 142 TList fCoordinates; 143 TList fLabel; 144 145 MBending fBending; 146 147 FontStruct_t fFont; 148 149 void Fcn(Int_t &npar, Double_t *gin, Double_t &f, Double_t *par, Int_t iflag) 150 { 151 f = 0; 152 153 MBending bend; 154 bend.SetParameters(par); // Set Parameters [deg] to MBending 155 156 for (int i=0; i<fCoordinates.GetSize(); i++) 157 { 158 Set set = *(Set*)fCoordinates.At(i); 159 160 set.Adjust(bend); 161 162 Double_t err = 0.02; // [deg] = 1SE 163 Double_t res = set.GetResidual()/err; 164 165 f += res*res; 166 } 167 168 //f /= (fCoordinates.GetSize()-7)*(fCoordinates.GetSize()-7); 169 //f /= fCoordinates.GetSize()*fCoordinates.GetSize(); 170 f /= fCoordinates.GetSize(); 171 } 172 173 static void fcn(Int_t &npar, Double_t *gin, Double_t &f, Double_t *par, Int_t iflag) 174 { 175 ((MFit*)gMinuit->GetObjectFit())->Fcn(npar, gin, f, par, iflag); 176 } 177 178 void DrawMarker(TVirtualPad *pad, Double_t r0, Double_t phi0, Double_t r1, Double_t phi1) 179 { 180 TView *view = pad->GetView(); 181 182 if (!view) 183 { 184 cout << "No View!" << endl; 185 return; 186 } 187 188 TMarker mark0; 189 TMarker mark1; 190 mark0.SetMarkerStyle(kStar); 191 mark1.SetMarkerStyle(kStar); 192 mark1.SetMarkerColor(kRed); 193 194 r0 /= 90; 195 r1 /= 90; 196 phi0 *= TMath::Pi()/180; 197 phi1 *= TMath::Pi()/180; 198 199 Double_t x0[3] = { r0*cos(phi0), r0*sin(phi0), 0}; 200 Double_t x1[3] = { r1*cos(phi1), r1*sin(phi1), 0}; 201 202 Double_t y0[3], y1[3]; 203 204 view->WCtoNDC(x0, y0); 205 view->WCtoNDC(x1, y1); 206 207 mark0.DrawMarker(y0[0], y0[1]); 208 mark1.DrawMarker(y1[0], y1[1]); 209 } 210 211 void DrawPolLine(TVirtualPad *pad, Double_t r0, Double_t phi0, Double_t r1, Double_t phi1) 212 { 213 TView *view = pad->GetView(); 214 215 if (!view) 216 { 217 cout << "No View!" << endl; 218 return; 219 } 220 /* 221 if (r0<0) 222 { 223 r0 = -r0; 224 phi0 += 180; 225 } 226 if (r1<0) 227 { 228 r1 = -r1; 229 phi1 += 180; 230 } 231 232 phi0 = fmod(phi0+360, 360); 233 phi1 = fmod(phi1+360, 360); 234 235 if (phi1-phi0<-180) 236 phi1+=360; 237 */ 238 TLine line; 239 line.SetLineWidth(2); 240 line.SetLineColor(kBlue); 241 242 Double_t p0 = phi0<phi1?phi0:phi1; 243 Double_t p1 = phi0<phi1?phi1:phi0; 244 245 if (phi0>phi1) 246 { 247 Double_t d = r1; 248 r1 = r0; 249 r0 = d; 250 } 251 252 r0 /= 90; 253 r1 /= 90; 254 255 Double_t dr = r1-r0; 256 Double_t dp = p1-p0; 257 258 Double_t x0[3] = { r0*cos(p0*TMath::Pi()/180), r0*sin(p0*TMath::Pi()/180), 0}; 259 260 for (double i=p0+10; i<p1+10; i+=10) 261 { 262 if (i>p1) 263 i=p1; 264 265 Double_t r = dr/dp*(i-p0)+r0; 266 Double_t p = TMath::Pi()/180*i; 267 268 Double_t x1[3] = { r*cos(p), r*sin(p), 0}; 269 270 Double_t y0[3], y1[3]; 271 272 view->WCtoNDC(x0, y0); 273 view->WCtoNDC(x1, y1); 274 275 line.DrawLine(y0[0], y0[1], y1[0], y1[1]); 276 277 x0[0] = x1[0]; 278 x0[1] = x1[1]; 279 } 280 } 281 282 void DrawSet(TVirtualPad *pad, Set &set, Float_t scale=-1) 283 { 284 Double_t r0 = set.GetRawZd(); 285 Double_t phi0 = set.GetRawAz(); 286 Double_t r1 = set.GetStarZd(); 287 Double_t phi1 = set.GetStarAz(); 288 289 if (r0<0) 290 { 291 r0 = -r0; 292 phi0 += 180; 293 } 294 if (r1<0) 295 { 296 r1 = -r1; 297 phi1 += 180; 298 } 299 300 phi0 = fmod(phi0+360, 360); 301 phi1 = fmod(phi1+360, 360); 302 303 if (phi1-phi0<-180) 304 phi1+=360; 305 306 if (scale<0 || scale>1000) 307 scale = -1; 308 309 if (scale>0) 310 { 311 Double_t d = r1-r0; 312 r0 += scale*d; 313 r1 -= scale*d; 314 d = phi1-phi0; 315 phi0 += scale*d; 316 phi1 -= scale*d; 317 318 DrawPolLine(pad, r0, phi0, r1, phi1); 319 DrawMarker(pad, r0, phi0, r1, phi1); 320 } 321 else 322 DrawMarker(pad, r1, phi1, 0 ,0); 323 } 324 325 void Fit() 326 { 327 if (fOriginal.GetSize()==0) 328 { 329 cout << "Sorry, no input data loaded..." << endl; 330 return; 331 } 332 333 fCoordinates.Delete(); 334 for (int i=0; i<fOriginal.GetSize(); i++) 335 fCoordinates.Add(new Set(*(Set*)fOriginal.At(i))); 336 337 cout << "-----------------------------------------------------------------------" << endl; 338 339 TH1F hres1("Res1", " Residuals before correction ", fOriginal.GetSize()/2, 0, 3); 340 TH1F hres2("Res2", " Residuals after correction ", fOriginal.GetSize(), 0, 3); 341 TH1F hres3("Res3", " Residuals after backward correction ", fOriginal.GetSize(), 0, 3); 342 343 hres1.SetXTitle("\\Delta [\\circ]"); 344 hres1.SetYTitle("Counts"); 345 346 hres2.SetXTitle("\\Delta [\\circ]"); 347 hres2.SetYTitle("Counts"); 348 349 hres3.SetXTitle("\\Delta [\\circ]"); 350 hres3.SetYTitle("Counts"); 351 352 TGraph gdaz; 353 TGraph gdzd; 354 TGraph gaz; 355 TGraph gzd; 356 TGraph graz; 357 TGraph grzd; 358 359 gdaz.SetTitle(" \\Delta Az vs. Zd "); 360 gdzd.SetTitle(" \\Delta Zd vs. Az "); 361 362 gaz.SetTitle(" \\Delta Az vs. Az "); 363 gzd.SetTitle(" \\Delta Zd vs. Zd "); 364 365 graz.SetTitle(" \\Delta vs. Az "); 366 grzd.SetTitle(" \\Delta vs. Zd "); 367 368 TMinuit minuit(MBending::GetNumPar()); //initialize TMinuit with a maximum of 5 params 369 minuit.SetObjectFit(this); 370 minuit.SetPrintLevel(-1); 371 minuit.SetFCN(fcn); 372 373 fBending.SetMinuitParameters(minuit, MBending::GetNumPar()); // Init Parameters [deg] 374 375 for (int i=0; i<MBending::GetNumPar(); i++) 376 { 377 TGButton *l = (TGButton*)fList->FindWidget(i); 378 minuit.FixParameter(i); 379 if (l->GetState()==kButtonDown) 380 minuit.Release(i); 381 } 382 383 //minuit.Command("SHOW PARAMETERS"); 384 //minuit.Command("SHOW LIMITS"); 385 386 cout << endl; 387 cout << "Starting fit..." << endl; 388 cout << "For the fit an measurement error in the residual of "; 389 cout << "0.02deg (=1SE) is assumed." << endl; 390 cout << endl; 391 392 Int_t ierflg = 0; 393 ierflg = minuit.Migrad(); 394 cout << "Migrad returns " << ierflg << endl; 395 // minuit.Release(2); 396 ierflg = minuit.Migrad(); 397 cout << "Migrad returns " << ierflg << endl << endl; 398 399 // 400 // Get Fit Results 401 // 402 fBending.GetMinuitParameters(minuit); 403 fBending.PrintMinuitParameters(minuit); 404 //fBending.Save("bending_magic.txt"); 405 406 407 // 408 // Make a copy of all list entries 409 // 410 TList list; 411 list.SetOwner(); 412 for (int i=0; i<fCoordinates.GetSize(); i++) 413 list.Add(new Set(*(Set*)fCoordinates.At(i))); 414 415 // 416 // Correct for Offsets only 417 // 418 TArrayD par; 419 fBending.GetParameters(par); 420 for (int i=2; i<MBending::GetNumPar(); i++) 421 par[i]=0; 422 423 MBending b2; 424 b2.SetParameters(par); 425 426 // 427 // Calculate correction and residuals 428 // 429 for (int i=0; i<fCoordinates.GetSize(); i++) 430 { 431 Set &set0 = *(Set*)fCoordinates.At(i); 432 433 ZdAz za = set0.GetStarZdAz()*kRad2Deg; 434 435 // 436 // Correct for offsets only 437 // 438 Set set1(set0); 439 set1.Adjust(b2); 440 441 hres1.Fill(set1.GetResidual()); 442 443 set0.Adjust(fBending); 444 hres2.Fill(set0.GetResidual()); 445 446 Double_t dz = fmod(set0.GetDAz()+720, 360); 447 if (dz>180) 448 dz -= 360; 449 450 gdzd.SetPoint(i, za.Az(), set0.GetDZd()); 451 gdaz.SetPoint(i, za.Zd(), dz); 452 graz.SetPoint(i, za.Az(), set0.GetResidual()); 453 grzd.SetPoint(i, za.Zd(), set0.GetResidual()); 454 gaz.SetPoint( i, za.Az(), dz); 455 gzd.SetPoint( i, za.Zd(), set0.GetDZd()); 456 457 } 458 459 // 460 // Check for overflows 461 // 462 const Stat_t ov = hres2.GetBinContent(hres2.GetNbinsX()+1); 463 if (ov>0) 464 cout << "WARNING: " << ov << " overflows in residuals." << endl; 465 466 467 468 cout << dec << endl; 469 cout << " Number of calls to FCN: " << minuit.fNfcn << endl; 470 cout << "Minimum value found for FCN (Chi^2?): " << minuit.fAmin << endl; 471 cout << " Fit-Probability(?): " << TMath::Prob(minuit.fAmin/*fOriginal.GetSize()*/, fOriginal.GetSize()-minuit.GetNumFreePars())*100 << "%" << endl; 472 cout << " Chi^2/NDF: " << minuit.fAmin/(fOriginal.GetSize()-minuit.GetNumFreePars()) << endl; 473 //cout << "Prob(?): " << TMath::Prob(fChisquare,ndf); 474 475 476 477 // 478 // Print all data sets for which the backward correction is 479 // twice times worse than the residual gotten from the 480 // bending correction itself 481 // 482 cout << endl; 483 cout << "Checking backward correction (raw-->star):" << endl; 484 for (int i=0; i<fCoordinates.GetSize(); i++) 485 { 486 Set set0(*(Set*)list.At(i)); 487 Set &set1 = *(Set*)list.At(i); 488 489 set0.AdjustBack(fBending); 490 set1.Adjust(fBending); 491 492 const Double_t res0 = set0.GetResidual(); 493 const Double_t res1 = set1.GetResidual(); 494 const Double_t diff = TMath::Abs(res0-res1); 495 496 hres3.Fill(res0); 497 498 if (diff<hres2.GetMean()*0.66) 499 continue; 500 501 cout << "DBack: " << setw(6) << set0.GetStarZd() << " " << setw(7) << set0.GetStarAz() << ": "; 502 cout << "ResB="<< setw(7) << res0*60 << " ResF=" << setw(7) << res1*60 << " |ResB-ResF|=" << setw(7) << diff*60 << " arcmin" << endl; 503 } 504 cout << "OK." << endl; 505 cout << endl; 506 507 508 509 510 TCanvas *c1; 511 512 if ((c1 = (TCanvas*)gROOT->FindObject("CanvGraphs"))) 513 delete c1; 514 if ((c1 = (TCanvas*)gROOT->FindObject("CanvResiduals"))) 515 delete c1; 516 517 518 519 c1=new TCanvas("CanvGraphs", "Graphs"); 520 c1->Divide(2,3,0,0); 521 522 c1->cd(1); 523 gPad->SetBorderMode(0); 524 TGraph *g=(TGraph*)gaz.DrawClone("A*"); 525 g->SetBit(kCanDelete); 526 g->GetHistogram()->SetXTitle("Az [\\circ]"); 527 g->GetHistogram()->SetYTitle("\\Delta Az [\\circ]"); 528 529 c1->cd(2); 530 gPad->SetBorderMode(0); 531 g=(TGraph*)gdaz.DrawClone("A*"); 532 g->SetBit(kCanDelete); 533 g->GetHistogram()->SetXTitle("Zd [\\circ]"); 534 g->GetHistogram()->SetYTitle("\\Delta Az [\\circ]"); 535 cout << "Mean dAz: " << g->GetMean(2) << " \xb1 " << g->GetRMS(2) << endl; 536 537 c1->cd(3); 538 gPad->SetBorderMode(0); 539 g=(TGraph*)gdzd.DrawClone("A*"); 540 g->SetBit(kCanDelete); 541 g->GetHistogram()->SetXTitle("Az [\\circ]"); 542 g->GetHistogram()->SetYTitle("\\Delta Zd [\\circ]"); 543 cout << "Mean dZd: " << g->GetMean(2) << " \xb1 " << g->GetRMS(2) << endl; 544 cout << endl; 545 546 c1->cd(4); 547 gPad->SetBorderMode(0); 548 g=(TGraph*)gzd.DrawClone("A*"); 549 g->SetBit(kCanDelete); 550 g->GetHistogram()->SetXTitle("Zd [\\circ]"); 551 g->GetHistogram()->SetYTitle("\\Delta Zd [\\circ]"); 552 553 c1->cd(5); 554 gPad->SetBorderMode(0); 555 g=(TGraph*)graz.DrawClone("A*"); 556 g->SetBit(kCanDelete); 557 g->GetHistogram()->SetXTitle("Az [\\circ]"); 558 g->GetHistogram()->SetYTitle("\\Delta [\\circ]"); 559 560 c1->cd(6); 561 gPad->SetBorderMode(0); 562 g=(TGraph*)grzd.DrawClone("A*"); 563 g->SetBit(kCanDelete); 564 g->GetHistogram()->SetXTitle("Zd [\\circ]"); 565 g->GetHistogram()->SetYTitle("\\Delta [\\circ]"); 566 567 568 569 // 570 // Print out the residual before and after correction in several 571 // units 572 // 573 cout << fCoordinates.GetSize() << " data sets." << endl << endl; 574 cout << "Total Spread of Residual:" << endl; 575 cout << "-------------------------" << endl; 576 cout << "before: " << hres1.GetMean() << " \xb1 " << hres1.GetRMS() << " deg " << endl; 577 cout << "after: " << hres2.GetMean() << " \xb1 " << hres2.GetRMS() << " deg " << endl; 578 cout << "before: " << (int)(hres1.GetMean()*60+.5) << " \xb1 " << (int)(hres1.GetRMS()*60+.5) << " arcmin" << endl; 579 cout << "after: " << (int)(hres2.GetMean()*60+.5) << " \xb1 " << (int)(hres2.GetRMS()*60+.5) << " arcmin" << endl; 580 cout << "before: " << (int)(hres1.GetMean()*60*60/23.4+.5) << " \xb1 " << (int)(hres1.GetRMS()*60*60/23.4+.5) << " pix" << endl; 581 cout << "after: " << (int)(hres2.GetMean()*60*60/23.4+.5) << " \xb1 " << (int)(hres2.GetRMS()*60*60/23.4+.5) << " pix" << endl; 582 cout << "after: " << (int)(hres2.GetMean()*16384/360+.5) << " \xb1 " << (int)(hres2.GetRMS()*16384/360+.5) << " SE" << endl; 583 cout << endl; 584 cout << "backw: " << (int)(hres3.GetMean()*60+.5) << " \xb1 " << (int)(hres3.GetRMS()*60+.5) << " arcmin" << endl; 585 cout << endl; // ± 586 587 588 589 gStyle->SetOptStat(1110); 590 gStyle->SetStatFormat("6.2g"); 591 592 593 c1=new TCanvas("CanvResiduals", "Residuals", 800, 800); 594 c1->Divide(2, 2, 0, 0); 595 596 c1->cd(2); 597 gPad->SetBorderMode(0); 598 hres1.SetLineColor(kRed); 599 hres1.DrawCopy(); 600 601 c1->cd(4); 602 gPad->SetBorderMode(0); 603 hres2.SetLineColor(kBlue); 604 TH1 *h=hres2.DrawCopy(); 605 TF1 f("mygaus", "(gaus)", 0, 1); 606 f.SetLineColor(kMagenta/*6*/); 607 f.SetLineWidth(1); 608 f.SetParameter(0, h->GetBinContent(1)); 609 f.FixParameter(1, 0); 610 f.SetParameter(2, h->GetRMS()); 611 h->Fit("mygaus", "QR"); 612 hres3.SetLineColor(kGreen); 613 hres3.SetLineStyle(kDashed); 614 hres3.DrawCopy("same"); 615 cout << "Gaus-Fit Sigma: " << f.GetParameter(2) << "\xb0" << endl; 616 cout << "Fit-Probability: " << f.GetProb()*100 << "%" << endl; 617 cout << " Chi^2/NDF: " << f.GetChisquare()/f.GetNDF() << endl; 618 619 c1->cd(1); 620 gPad->SetBorderMode(0); 621 gPad->SetTheta(90); 622 gPad->SetPhi(90); 623 TH2F h2res1("Res2D1", " Dataset positions on the sky ", 32, 0, 360, 10, 0, 90); 624 h2res1.SetBit(TH1::kNoStats); 625 h2res1.DrawCopy("surf1pol"); 626 gPad->Modified(); 627 gPad->Update(); 628 for (int i=0; i<fCoordinates.GetSize(); i++) 629 DrawSet(gPad, *(Set*)list.At(i));//, 10./hres1.GetMean()); 630 631 c1->cd(3); 632 gPad->SetBorderMode(0); 633 gPad->SetTheta(90); 634 gPad->SetPhi(90); 635 h2res1.SetTitle(" Arb. Residuals after correction (scaled) "); 636 h2res1.DrawCopy("surf1pol"); 637 gPad->Modified(); 638 gPad->Update(); 639 for (int i=0; i<fCoordinates.GetSize(); i++) 640 DrawSet(gPad, *(Set*)fCoordinates.At(i), 10./hres2.GetMean()); 641 642 RaiseWindow(); 643 } 644 645 void LoadStars() 646 { 647 const Int_t size = fOriginal.GetSize(); 648 649 ifstream fin("../tpoint_new.txt"); 650 651 while (fin && fin.get()!='\n'); 652 while (fin && fin.get()!='\n'); 653 while (fin && fin.get()!='\n'); 654 if (!fin) 655 { 656 cout << "File not found!" << endl; 657 return; 658 } 659 660 while (1) 661 { 662 Set set; 663 664 fin >> set; // Read data from file [deg], it is stored in [rad] 665 666 if (!fin) 667 break; 668 669 fOriginal.Add(new Set(set)); 670 } 671 672 cout << "Found " << fOriginal.GetSize()-size << " sets of coordinates "; 673 cout << "(Total=" << fOriginal.GetSize() << ")" << endl; 674 } 27 675 28 676 Bool_t ProcessMessage(Long_t msg, Long_t mp1, Long_t mp2) 29 677 { 30 cout << "Msg: " << hex << GET_MSG(msg) << endl;31 cout << "SubMsg: " << hex << GET_SUBMSG(msg)<< endl;678 // cout << "Msg: " << hex << GET_MSG(msg) << endl; 679 // cout << "SubMsg: " << hex << GET_SUBMSG(msg) << dec << endl; 32 680 switch (GET_MSG(msg)) 33 681 { … … 35 683 switch (GET_SUBMSG(msg)) 36 684 { 37 case kCM_CHECKBUTTON: 38 /* 39 TGCheckButton *but = (TGCheckButton*)list->FindWidget(mp1); 40 cout << hex << but->GetName() << " " << mp2 << endl; 41 */ 685 case kCM_BUTTON: 686 switch (mp1) 687 { 688 case kTbFit: 689 Fit(); 690 DisplayBending(); 691 return kTRUE; 692 case kTbLoad: 693 fBending.Load("bending_magic.txt"); 694 DisplayBending(); 695 return kTRUE; 696 case kTbSave: 697 fBending.Save("bending_magic.txt"); 698 return kTRUE; 699 case kTbLoadStars: 700 LoadStars(); 701 DisplayData(); 702 return kTRUE; 703 case kTbReset: 704 fBending.Clear(); 705 DisplayBending(); 706 return kTRUE; 707 case kTbResetStars: 708 fOriginal.Delete(); 709 DisplayData(); 710 return kTRUE; 711 } 42 712 return kTRUE; 43 713 } … … 52 722 but->Associate(this); 53 723 f->AddFrame(but, h); 54 list->Add(but);724 fList->Add(but); 55 725 56 726 } … … 61 731 but->Associate(this); 62 732 f->AddFrame(but, h); 63 list->Add(but);64 } 65 66 void AddLabel(TGCompositeFrame *f, TString txt, TGLayoutHints *h=0, TList *label=0)67 { 68 TGLabel *l = new TGLabel(f, txt );733 fList->Add(but); 734 } 735 736 TGLabel *AddLabel(TGCompositeFrame *f, TString txt, TGLayoutHints *h=0) 737 { 738 TGLabel *l = new TGLabel(f, txt/*, TGLabel::GetDefaultGC()(), fFont*/); 69 739 f->AddFrame(l, h); 70 list->Add(l); 71 if (label) 72 label->Add(l); 740 fList->Add(l); 741 fLabel.Add(l); 742 return l; 743 } 744 745 void DisplayBending() 746 { 747 TArrayD par, err; 748 fBending.GetParameters(par); 749 fBending.GetError(err); 750 751 TGLabel *l; 752 753 for (int i=0; i<MBending::GetNumPar(); i++) 754 { 755 l = (TGLabel*)fLabel.At(i); 756 l->SetText(Form("%.4f\xb0", par[i])); 757 758 l = (TGLabel*)fLabel.At(MBending::GetNumPar()+i); 759 l->SetText(Form("\xb1 %8.4f\xb0", err[i])); 760 } 761 } 762 763 void DisplayData() 764 { 765 TGLabel *l = (TGLabel*)fLabel.At(3*MBending::GetNumPar()); 766 l->SetText(Form("%d data sets loaded.", fOriginal.GetSize())); 73 767 } 74 768 75 769 public: 76 MFit() : TGMainFrame(gClient->GetRoot(), 550, 350, kHorizontalFrame) 77 { 78 list = new MGList; 79 list->SetOwner(); 770 ~MFit() 771 { 772 if (fFont) 773 gVirtualX->DeleteFont(fFont); 774 } 775 MFit() : TGMainFrame(gClient->GetRoot(), 740, 370, kHorizontalFrame) 776 { 777 fCoordinates.SetOwner(); 778 fOriginal.SetOwner(); 779 780 fList = new MGList; 781 fList->SetOwner(); 782 783 fFont = gVirtualX->LoadQueryFont("7x13bold"); 80 784 81 785 TGLayoutHints *hints0 = new TGLayoutHints(kLHintsExpandY, 7, 5, 5, 6); 82 786 TGLayoutHints *hints1 = new TGLayoutHints(kLHintsExpandX|kLHintsExpandY, 5, 7, 5, 6); 83 787 TGLayoutHints *hints2 = new TGLayoutHints(kLHintsCenterX|kLHintsCenterY, 5, 5, 5, 5); 84 list->Add(hints0);85 list->Add(hints1);86 list->Add(hints2);788 fList->Add(hints0); 789 fList->Add(hints1); 790 fList->Add(hints2); 87 791 88 792 TGGroupFrame *grp1 = new TGGroupFrame(this, "Control", kVerticalFrame); 89 793 AddFrame(grp1, hints0); 90 list->Add(grp1);794 fList->Add(grp1); 91 795 92 796 TGGroupFrame *grp2 = new TGGroupFrame(this, "Parameters", kHorizontalFrame); 93 797 AddFrame(grp2, hints1); 94 list->Add(grp2); 95 96 97 98 TGLayoutHints *hints4 = new TGLayoutHints(kLHintsExpandX, 5, 5, 10); 99 AddTextButton(grp1, "Load Bending Model", -1, hints4); 100 AddTextButton(grp1, "Save Bending Model", -1, hints4); 101 AddTextButton(grp1, "Load Observations", -1, hints4); 102 AddTextButton(grp1, "Fit Parameters", -1, hints4); 103 AddTextButton(grp1, "Reset Parameters", -1, hints4); 798 fList->Add(grp2); 799 800 801 802 TGLayoutHints *hints4 = new TGLayoutHints(kLHintsExpandX, 5, 5, 5); 803 TGLayoutHints *hints5 = new TGLayoutHints(kLHintsExpandX, 5, 5, 15); 804 AddTextButton(grp1, "Load Pointing Model", kTbLoad, hints5); 805 AddTextButton(grp1, "Save Pointing Model", kTbSave, hints4); 806 AddTextButton(grp1, "Fit Parameters", kTbFit, hints5); 807 AddTextButton(grp1, "Reset Parameters", kTbReset, hints4); 808 AddTextButton(grp1, "Load Stars", kTbLoadStars, hints5); 809 AddTextButton(grp1, "Reset Stars", kTbResetStars, hints4); 810 fList->Add(hints4); 811 fList->Add(hints5); 104 812 105 813 106 814 TGHorizontalFrame *comp = new TGHorizontalFrame(grp2, 1, 1); 107 815 grp2->AddFrame(comp); 108 list->Add(comp);816 fList->Add(comp); 109 817 110 818 TGLayoutHints *hints3 = new TGLayoutHints(kLHintsLeft|kLHintsTop, 0, 20, 5, 0); 111 list->Add(hints3);819 fList->Add(hints3); 112 820 113 821 TGLabel *l; … … 115 823 TGVerticalFrame *vframe = new TGVerticalFrame(comp, 1, 1); 116 824 comp->AddFrame(vframe, hints3); 117 list->Add(vframe); 118 119 AddCheckButton(vframe, "IA", kCbIA); 120 AddCheckButton(vframe, "IE", kCbIE); 121 AddCheckButton(vframe, "NPAE", kCbNPAE); 122 AddCheckButton(vframe, "CA", kCbCA); 123 AddCheckButton(vframe, "AN", kCbAN); 124 AddCheckButton(vframe, "AW", kCbAW); 125 AddCheckButton(vframe, "CRX", kCbCRX); 126 AddCheckButton(vframe, "CRY", kCbCRY); 127 AddCheckButton(vframe, "NRX", kCbNRX); 128 AddCheckButton(vframe, "NRY", kCbNRY); 825 fList->Add(vframe); 826 827 for (int i=0; i<MBending::GetNumPar(); i++) 828 AddCheckButton(vframe, fBending.GetName(i), i); 129 829 130 830 vframe = new TGVerticalFrame(comp, 1, 1); 131 831 comp->AddFrame(vframe, hints3); 132 list->Add(vframe); 133 134 135 TList label; 136 137 l = new TGLabel(vframe, "0"); 138 list->Add(l); 139 label.Add(l); 140 141 TGButton *but = (TGButton*)list->FindWidget(kCbIA); 832 fList->Add(vframe); 833 834 l = new TGLabel(vframe, "+000.0000"); 835 l->SetTextJustify(kTextRight); 836 fList->Add(l); 837 fLabel.Add(l); 838 839 TGButton *but = (TGButton*)fList->FindWidget(0); 142 840 143 841 TGLayoutHints *h = new TGLayoutHints(kLHintsCenterY, 0, 0, but->GetHeight()-l->GetHeight()); 144 list->Add(h);842 fList->Add(h); 145 843 146 844 vframe->AddFrame(l,h); 147 845 148 AddLabel(vframe, "0", h, &label); 149 AddLabel(vframe, "0", h, &label); 150 AddLabel(vframe, "0", h, &label); 151 AddLabel(vframe, "0", h, &label); 152 AddLabel(vframe, "0", h, &label); 153 AddLabel(vframe, "0", h, &label); 154 AddLabel(vframe, "0", h, &label); 155 AddLabel(vframe, "0", h, &label); 156 AddLabel(vframe, "0", h, &label); 846 for (int i=1; i<MBending::GetNumPar(); i++) 847 AddLabel(vframe, "+000.0000", h)->SetTextJustify(kTextRight); 157 848 158 849 vframe = new TGVerticalFrame(comp, 1, 1); 159 850 comp->AddFrame(vframe, hints3); 160 list->Add(vframe); 161 162 AddLabel(vframe, "Offset Azimuth", h, &label); 163 AddLabel(vframe, "Offset Zenith Distance", h, &label); 164 AddLabel(vframe, "0", h, &label); 165 AddLabel(vframe, "0", h, &label); 166 AddLabel(vframe, "0", h, &label); 167 AddLabel(vframe, "0", h, &label); 168 AddLabel(vframe, "0", h, &label); 169 AddLabel(vframe, "0", h, &label); 170 AddLabel(vframe, "0", h, &label); 851 fList->Add(vframe); 852 853 for (int i=0; i<MBending::GetNumPar(); i++) 854 AddLabel(vframe, "\xb1 00.0000\xb0", h)->SetTextJustify(kTextRight); 855 856 vframe = new TGVerticalFrame(comp, 1, 1); 857 comp->AddFrame(vframe, hints3); 858 fList->Add(vframe); 859 860 for (int i=0; i<MBending::GetNumPar(); i++) 861 AddLabel(vframe, fBending.GetDescription(i), h); 862 863 l = new TGLabel(grp1, "0000000 Data Sets loaded."); 864 grp1->AddFrame(l, hints5); 865 fList->Add(l); 866 fLabel.Add(l); 867 868 869 ((TGCheckButton*)fList->FindWidget(0))->SetState(kButtonDown); 870 ((TGCheckButton*)fList->FindWidget(1))->SetState(kButtonDown); 871 ((TGCheckButton*)fList->FindWidget(3))->SetState(kButtonDown); 872 ((TGCheckButton*)fList->FindWidget(4))->SetState(kButtonDown); 873 ((TGCheckButton*)fList->FindWidget(5))->SetState(kButtonDown); 874 ((TGCheckButton*)fList->FindWidget(6))->SetState(kButtonDown); 875 ((TGCheckButton*)fList->FindWidget(7))->SetState(kButtonDown); 876 877 SetWindowName("TPoint Fitting Window"); 878 SetIconName("TPoint++"); 171 879 172 880 Layout(); … … 175 883 MapWindow(); 176 884 177 178 179 180 l = (TGLabel*)label.At(0); 181 l->SetText("221.4567"); 182 183 l = (TGLabel*)label.At(1); 184 l->SetText("-1.65423"); 185 186 Layout(); 187 } 885 DisplayBending(); 886 DisplayData(); 887 } 888 ClassDef(MFit, 0) 188 889 }; 890 891 ClassImp(MFit); 189 892 190 893 void gui() … … 192 895 new MFit; 193 896 } 194
Note:
See TracChangeset
for help on using the changeset viewer.