Changeset 7622 for trunk/MagicSoft
- Timestamp:
- 03/23/06 21:50:04 (19 years ago)
- Location:
- trunk/MagicSoft/Cosy
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/MagicSoft/Cosy/Changelog
r7614 r7622 1 1 -*-*- END -*-*- 2 2006/03/23 - Daniela Dorner, Thomas Bretz 3 4 * main/MStarguider.[h,cc]: 5 - changed starguider algorithm 6 7 8 2 9 2006/03/19 - Daniela Dorner 3 10 … … 28 35 - removed starguider analyis (writing root-files) from starguider mode to 29 36 stabilize the code 37 - added 'fGetter->ExitLoop()' before each 'delete fGetter' 38 - added SetDirectory(0) for histogram in starguider 30 39 31 40 -
trunk/MagicSoft/Cosy/main/MStarguider.cc
r7614 r7622 643 643 if (ch0!=ch1) 644 644 { 645 // fGetter->ExitLoop(); 645 646 delete fGetter; 646 647 usleep(150000); // FIX: Device or resource busy. … … 952 953 if (ch0!=ch1) 953 954 { 955 // fGetter->ExitLoop(); 954 956 delete fGetter; 955 957 usleep(150000); // FIX: Device or resource busy. … … 1159 1161 fChannel->CheckEntry (ch1==0?IDM_kChannel1:IDM_kChannel2); 1160 1162 fChannel->UnCheckEntry(ch1==1?IDM_kChannel1:IDM_kChannel2); 1163 // fGetter->ExitLoop(); 1161 1164 delete fGetter; 1162 1165 usleep(150000); // FIX: Device or resource busy. … … 1243 1246 } 1244 1247 1245 ZdAz MStarguider::TrackingError(TArrayF &x, TArrayF &y, TArrayF &mag) const 1246 { 1247 // 1248 // Viewable area (FIXME: AZ) 1249 // 1250 // TH2F h("Hist", "dX/dY", 77, -768/2-.5, 768/2+.5, 58, -576/2-.5, 576/2+.5); // 3 1251 // chose a bit coarser binning to enhance excess 1252 // important: chose binning symmetrical around (0|0)! 1253 // TH2F h("Hist", "dX/dY", 49, -576/2-8, 576/2+8, 37, -576/2-8, 576/2+8); // 3 1254 // reduced range in which histogram is filled, made bins a bit smaller 1255 // 72pix equivalent to 0.6deg 1256 TH2F h("Hist", "dX/dY", 7, -72, 72, 7, -72, 72); 1257 1258 // TH1F hmag("HistMag", "Mag", 19, 0, 100); 1259 // for (int i=0; i<mag.GetSize(); i++) 1260 // hmag.Fill(mag[i]); 1261 1248 ZdAz MStarguider::TrackingError(TArrayF &x, TArrayF &y, TArrayF &mag, 1249 Int_t &num) const 1250 { 1251 num = -1; 1252 1253 // Width of the final 2D gaussian 1254 const Double_t width = 0.8; 1255 1256 // The binning is made 1.7 sigma (which, in the 1D case, gives the 1257 // highest significance of a gaussian signal) (1bin equiv 3x3 sigma) 1258 const Double_t max = 50; 1259 const Int_t n = TMath::Nint(2*max/(1.77*1.7*width)); 1260 //1.77=sqrt(pi) comes from pir=bin 1261 1262 // Fill a histogram with the dx/dy values from the file 1263 TH2F hist("Hist", "dX/dY", n, -max, max, n, -max, max); 1264 // hist.SetDirectory(0); 1265 1262 1266 // 1263 1267 // Search for matching Magnitudes 1264 1268 // 1269 //for (int i=0; i<mag.GetSize(); i++) 1270 //{ 1271 // if (mag[i]>48-15 && mag[i]<48+15) 1272 // h.Fill(x[i], y[i]); 1273 //} 1274 1275 // fill dx and dy into histogram 1265 1276 for (int i=0; i<mag.GetSize(); i++) 1266 { 1267 if (mag[i]>48-15 && mag[i]<48+15) 1268 h.Fill(x[i], y[i]); 1269 } 1270 1271 // 1272 // Search for an excess in the histogram 1273 // 1274 Int_t mx, my, dummy; 1275 h.GetMaximumBin(mx, my, dummy); 1276 1277 const double xmax = h.GetXaxis()->GetBinCenter(mx); 1278 const double dx = h.GetXaxis()->GetBinWidth(mx)/2; 1279 1280 const double ymax = h.GetYaxis()->GetBinCenter(my); 1281 const double dy = h.GetYaxis()->GetBinWidth(my)/2; 1277 hist.Fill(x[i], y[i]); 1278 1279 // Remove all bins which have content of only a single event 1280 // including under- and overflow bins 1281 for (int i=0; i<hist.GetSize(); i++) 1282 if (hist.GetBinContent(i)<1.5) 1283 hist.SetBinContent(i, 0); 1284 1285 // Find the bin containing the maximum 1286 Int_t bx, by, bz; 1287 hist.GetMaximumBin(bx, by, bz); 1288 1289 // In the worst case the events are spread through the 1290 // bins which are the neighbors of the maximum 1291 // Normally neighbors which do not belong to the signal are empty! 1292 hist.GetXaxis()->SetRange(bx-1, bx+1); // 3x3bins ~8x8pix ~9x9sigma 1293 hist.GetYaxis()->SetRange(by-1, by+1); // 3x3bins ~8x8pix ~9x9sigma 1294 1295 // Check whether this region contains events 1296 num = TMath::Nint(hist.Integral()); 1297 if (num<1) 1298 return ZdAz(); 1299 1300 // Get Mean for the given axis range 1301 Double_t mx = hist.GetMean(1); 1302 Double_t my = hist.GetMean(2); 1303 1304 const Int_t max1 = TMath::Nint(hist.GetBinContent(bx, by)); 1305 1306 // Check if the maximum is unique 1307 Int_t bx2, by2, bz2; 1308 hist.GetXaxis()->SetRange(-1, 9999); 1309 hist.GetYaxis()->SetRange(-1, 9999); 1310 hist.SetBinContent(bx, by, 0); 1311 hist.GetMaximumBin(bx2, by2, bz2); 1312 1313 const Int_t max2 = TMath::Nint(hist.GetBinContent(bx2, by2)); 1314 if (max1==max2 && TMath::Abs(bx2-bx)+TMath::Abs(by2-by)>1) 1315 return ZdAz(); 1316 1317 // loop again over the file and fill the histogram again. 1318 // to get closer to the correct value 1319 Double_t sumx = 0; 1320 Double_t sumy = 0; 1321 num = 0; 1322 for (int i=0; i<mag.GetSize(); i++) 1323 { 1324 // only fill values into the histogram which 1325 // are inside 2*1.7=3.4 sigma (99.7%) 1326 if (TMath::Hypot(x[i]-mx, y[i]-my)>width*3.4) 1327 continue; 1328 1329 sumx += x[i]; 1330 sumy += y[i]; 1331 num++; 1332 } 1333 1334 if (num<1) 1335 return ZdAz(); 1336 1337 // calc MeanX and MeanY 1338 mx = sumx/num; 1339 my = sumy/num; 1340 1341 // loop again to fill the mispointing corrected histograms 1342 // and fill another histogram to check the quality of the calculated 1343 // mispointing. 1344 sumx = 0; 1345 sumy = 0; 1346 num = 0; 1347 for (int i=0; i<mag.GetSize(); i++) 1348 { 1349 // only fill values into the histogram which 1350 // are inside 1.7=3.4 sigma (92%) 1351 // Cut at 1.7 sigma which gives the best background supression 1352 if (TMath::Hypot(x[i]-mx, y[i]-my)>width*1.7) 1353 continue; 1354 1355 sumx += x[i]; 1356 sumy += y[i]; 1357 num++; 1358 } 1359 1360 if (num<1) 1361 return ZdAz(); // FIXME!!!!!!!!!!!! 1362 1363 // Mispointing 1364 mx = sumx/num; 1365 my = sumy/num; 1282 1366 1283 1367 #ifdef EXPERT 1284 cout << setprecision(3); 1285 cout << "Cut-XY: " << xmax << " +- " << dx << " / " << ymax << " +- " << dy << endl; 1368 cout << "Offset-XY: " << mx << " +- " << my << endl; 1286 1369 #endif 1287 1370 1288 TGraph g; 1289 for (int i=0; i<mag.GetSize(); i++) 1290 { 1291 if (!(x[i]>xmax-dx && x[i]<xmax+dx && 1292 y[i]>ymax-dy && y[i]<ymax+dy /*&& 1293 mag[i]>48-15 && mag[i]<48+15*/)) 1294 continue; 1295 1296 g.SetPoint(g.GetN(), x[i], y[i]); 1297 } 1298 1299 #ifdef EXPERT 1300 cout << "Offset-XY: " << g.GetMean(1) << " +- " << g.GetRMS(1) << " / "; 1301 cout << g.GetMean(2) << " +- " << g.GetRMS(2) << endl; 1302 #endif 1303 1304 AltAz pos0 = fSao->CalcAltAzFromPix(768/2, 576/2)*kRad2Deg; 1305 AltAz pos1 = fSao->CalcAltAzFromPix(768/2+g.GetMean(1), 576/2+g.GetMean(2))*kRad2Deg; 1371 AltAz pos0 = fSao->CalcAltAzFromPix(768/2, 576/2)*kRad2Deg; 1372 AltAz pos1 = fSao->CalcAltAzFromPix(768/2+mx, 576/2+my)*kRad2Deg; 1306 1373 1307 1374 ofstream fout1("pointingpos.txt"); … … 1319 1386 fout2 << -pos1.Alt() << " " << pos1.Az() << endl; 1320 1387 1321 // if (g.GetMean(1)>9 || g.GetMean(2)>9) {1322 // TFile f1("sguider-highoffset.root","UPDATE");1323 // h.Write();1324 // hmag.Write();1325 // g.Write();1326 // f1.Close();1327 // } else {1328 // TFile f1("sguider-niceoffset.root","UPDATE");1329 // h.Write();1330 // hmag.Write();1331 // g.Write();1332 // f1.Close();1333 1334 1335 // }1336 1337 //deleting histogram and graph1338 h.Delete();1339 g.Delete();1340 1388 return ZdAz(-pos1.Alt(), pos1.Az()); 1341 1389 } 1342 1390 1343 bool MStarguider::CalcTrackingError(Leds &leds, MStarList &stars, ZdAz &d, MTime &t, double &bright) 1391 Int_t MStarguider::CalcTrackingError(Leds &leds, MStarList &stars, 1392 ZdAz &d, MTime &t, double &bright) 1344 1393 { 1345 1394 const Int_t max = leds.GetEntries(); … … 1349 1398 if (fStargTPoint->IsDown()) 1350 1399 fStargTPoint->SetDown(kFALSE); 1351 return kFALSE;1400 return 0; 1352 1401 } 1353 1402 if (max < 3) //was 1 … … 1356 1405 if (fStargTPoint->IsDown()) 1357 1406 fStargTPoint->SetDown(kFALSE); 1358 return kFALSE;1407 return 0; 1359 1408 } 1360 1409 … … 1383 1432 while ((spot=(Led*)NextSp())) 1384 1433 { 1385 const XY dpos(spot->GetX()-(768-star->GetX()), spot->GetY()-star->GetY()); 1434 const XY dpos(spot->GetX()-(768-star->GetX()), 1435 spot->GetY()-star->GetY()); 1386 1436 1387 1437 const Int_t idx = x.GetSize(); … … 1409 1459 } 1410 1460 1411 d = TrackingError(x, y, mag); 1461 d = TrackingError(x, y, mag, num); 1462 1463 if (num<1) 1464 return 0; 1465 1412 1466 fDZdAz->SetCoordinates(d); 1413 1467 1414 1468 // 1415 1469 // Calculated offsets … … 1468 1522 if ((t.GetMjd()-t2.GetMjd())>0.001) //1min20sec 1469 1523 { 1470 cout << "time difference between tpoint and starguider-tpoint > " << 1471 t.GetMjd()-t2.GetMjd() << "s => starguider tpoint hasn't been stored. Please repeat whole procedure. " << endl; 1524 cout << " time difference between tpoint and starguider-tpoint > 1 min *" << 1525 t.GetMjd()-t2.GetMjd() << "s) " << endl; 1526 cout << " => starguider tpoint hasn't been stored. " << endl; 1527 cout << " Please repeat whole procedure. " << endl; 1472 1528 return kTRUE; 1473 1529 } … … 1489 1545 *fOutStargTp << endl; 1490 1546 1491 1492 1493 1494 1495 1496 1547 fTimeFromTp.Set(1970,1,1); 1497 1548 1498 return kTRUE; 1499 1549 return num; 1500 1550 } 1501 1551 … … 1980 2030 fSkyBright->SetBackgroundColor(color); 1981 2031 1982 boolrc = CalcTrackingError(spots, stars, fD, t, bright);1983 1984 if ( rc &&(bright <= 1.75* fLastBright) && (bright < 110))2032 const Int_t rc = CalcTrackingError(spots, stars, fD, t, bright); 2033 2034 if ((bright <= 1.75* fLastBright) && (bright < 110)) 1985 2035 fStatus = MDriveCom::kMonitoring; 1986 2036 else 1987 2037 fStatus = MDriveCom::kError; 1988 2038 1989 1990 fPos = fCosy->GetPointingPos(); 1991 1992 if (fOperations->IsEntryChecked(IDM_kStargAnalysis))2039 if (fCosy) 2040 fPos = fCosy->GetPointingPos(); 2041 2042 if (fOperations->IsEntryChecked(IDM_kStargAnalysis)) 1993 2043 fStargHistograms->Fill(spots, stars, fD, 1994 2044 fSao->GetZdAz(), sgcenter, sgcenterzdaz, 1995 2045 star, bright, fPos, t); 1996 2046 1997 2047 fLastBright = bright; 1998 2048 1999 2049 if (fCosy) 2000 2050 { 2001 2051 MDriveCom &com = *fCosy->GetDriveCom(); 2002 com.SendStargReport(fStatus, fD, fSao->GetZdAz(), sgcenter, spots.GetEntries(), bright, time.GetMjd(), 0, 0); // Report 2052 com.SendStargReport(fStatus, fD, fSao->GetZdAz(), 2053 sgcenter, rc, bright, 2054 time.GetMjd(), 0, 0); // Report 2003 2055 } 2004 2005 2056 } //kStarguider 2006 2057 -
trunk/MagicSoft/Cosy/main/MStarguider.h
r7614 r7622 129 129 void ToggleCaosFilter(); 130 130 //void GetCoordinates(); 131 boolCalcTrackingError(Leds &, MStarList &, ZdAz &, MTime &, double &bright);131 Int_t CalcTrackingError(Leds &, MStarList &, ZdAz &, MTime &, double &bright); 132 132 //void CalcTrackingError(Leds &, MStarList &); 133 ZdAz TrackingError(TArrayF &alt, TArrayF &az, TArrayF &mag ) const;133 ZdAz TrackingError(TArrayF &alt, TArrayF &az, TArrayF &mag, Int_t &num) const; 134 134 bool Interpolate(const unsigned long n, byte *img) const; 135 135
Note:
See TracChangeset
for help on using the changeset viewer.