Changeset 1810 for trunk/MagicSoft/Cosy/tpoint
- Timestamp:
- 03/11/03 13:52:48 (22 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/MagicSoft/Cosy/tpoint/tpointfit.C
r1806 r1810 1 1 #include <fstream.h> 2 2 #include <iostream.h> 3 #include <iomanip.h> 3 4 4 5 #include <TF1.h> … … 21 22 // Sekans = 1/cos 22 23 // 23 24 void MyAdjust(AltAz &p, Double_t *par)25 {26 // p[rad]27 MBending bend;28 bend.SetParameters(par); // [deg]29 p=bend(p);30 }31 24 32 25 class Set : public TObject … … 54 47 Double_t GetResidual() const 55 48 { 56 Double_t daz = fRawEl-fStarEl; 57 Double_t del = fRawAz-fStarAz; 58 59 //Double_t rzd = TMath::Pi()/2-fRawEl; 60 Double_t rzd = TMath::Pi()/2-fOrigStarEl; 49 Double_t del = fRawEl-fStarEl; 50 Double_t daz = fRawAz-fStarAz; 61 51 62 52 Double_t dphi2 = daz/2.; 63 53 Double_t cos2 = cos(dphi2)*cos(dphi2); 64 54 Double_t sin2 = sin(dphi2)*sin(dphi2); 65 Double_t d = cos(del)*cos2 - cos(2*rzd+del)*sin2;66 67 Double_t dist = acos(d);55 Double_t d = cos(del)*cos2 - cos(2*fOrigStarEl+del)*sin2; 56 57 Double_t dist = acos(d); 68 58 69 59 return dist * 180 / TMath::Pi(); … … 79 69 80 70 Double_t GetDEl() const { return (fRawEl-fStarEl)*180/TMath::Pi(); } 71 Double_t GetDZd() const { return -GetDEl(); } 81 72 Double_t GetDAz() const { return (fRawAz-fStarAz)*180/TMath::Pi(); } 82 73 Double_t GetStarEl() const { return fStarEl*180/TMath::Pi(); } … … 102 93 fStarAz = p.Az(); 103 94 } 104 105 void Adjust(const MBending &bend, void (*fcn)(AltAz &zdaz, Double_t *par)) 106 { 107 AltAz star = GetStarAltAz(); 108 109 AltAz p = bend(star, fcn); 110 fStarEl = p.Alt(); 111 fStarAz = p.Az(); 95 void AdjustBack(const MBending &bend) 96 { 97 AltAz p = bend.CorrectBack(GetRawAltAz()); 98 fRawEl = p.Alt(); 99 fRawAz = p.Az(); 112 100 } 113 101 }; … … 116 104 { 117 105 Double_t v[4]; 106 fin >> v[0]; 107 fin >> v[1]; 118 108 fin >> v[2]; 119 109 fin >> v[3]; 120 fin >> v[0];121 fin >> v[1];122 110 123 111 set.fStarAz = v[0]*TMath::Pi()/180; … … 140 128 141 129 MBending bend; 142 bend.SetParameters(par /*, npar*/); // Set Parameters [deg] to MBending130 bend.SetParameters(par); // Set Parameters [deg] to MBending 143 131 144 132 for (int i=0; i<gCoordinates.GetSize(); i++) … … 146 134 Set set = *(Set*)gCoordinates.At(i); 147 135 148 //set.Adjust(bend); 149 set.Adjust(bend, MyAdjust); 136 set.Adjust(bend); 150 137 151 138 Double_t err = 1; … … 200 187 return; 201 188 } 202 189 /* 203 190 if (r0<0) 204 191 { … … 212 199 } 213 200 214 /* 215 phi0 = fmod(phi0+360, 360); 216 phi1 = fmod(phi1+360, 360); 201 phi0 = fmod(phi0+360, 360); 202 phi1 = fmod(phi1+360, 360); 203 204 if (phi1-phi0<-180) 205 phi1+=360; 217 206 */ 218 219 207 TLine line; 220 208 line.SetLineWidth(2); … … 268 256 Double_t phi1 = set.GetStarAz(); 269 257 258 if (r0<0) 259 { 260 r0 = -r0; 261 phi0 += 180; 262 } 263 if (r1<0) 264 { 265 r1 = -r1; 266 phi1 += 180; 267 } 268 269 phi0 = fmod(phi0+360, 360); 270 phi1 = fmod(phi1+360, 360); 271 272 if (phi1-phi0<-180) 273 phi1+=360; 274 275 if (scale<0 || scale>1000) 276 scale = -1; 277 270 278 if (scale>0) 271 279 { 272 280 Double_t d = r1-r0; 273 if (d<0) d=-d; 274 r0 -= scale*d; 275 r1 += scale*d; 281 r0 += scale*d; 282 r1 -= scale*d; 276 283 d = phi1-phi0; 277 if (d<0) d=-d; 278 phi0 -= scale*d; 279 phi1 += scale*d; 284 phi0 += scale*d; 285 phi1 -= scale*d; 280 286 } 281 287 … … 290 296 gCoordinates.SetOwner(); 291 297 292 TH2F hdaz("dAz", "\\Delta Az vs. Alt", 32, 0, 90, 32, -1, 1);293 TH2F hdzd("dZd", "\\Delta Alt vs. Az", 32, 0, 360, 32, -1, 1);294 295 298 TH1F hres1("Res1", " Residuals before correction ", 10, 0, 180); 296 299 TH1F hres2("Res2", " Residuals after correction ", 10, 0, 1); 297 300 298 TH2F h2res1("Res2D1", " Arb. Residuals before correction ", 32, 0, 360, 10, 0, 90);299 TH2F h2res2("Res2D2", " Arb. Residuals after correction ", 32, 0, 360, 10, 0, 90);300 301 hdaz.SetXTitle("Zd [\\circ]");302 hdaz.SetYTitle("\\Delta Az [\\circ]");303 304 hdzd.SetXTitle("Az [\\circ]");305 hdzd.SetYTitle("\\Delta Zd [\\circ]");306 307 301 hres1.SetXTitle("\\Delta [\\circ]"); 308 302 hres1.SetYTitle("Counts"); … … 313 307 TGraph gdaz; 314 308 TGraph gdzd; 315 316 ifstream fin("tpoint/tpoint2.txt"); 309 TGraph gaz; 310 TGraph gzd; 311 312 gdaz.SetTitle(" \\Delta Az vs. Zd "); 313 gdzd.SetTitle(" \\Delta Zd vs. Az "); 314 315 gaz.SetTitle(" \\Delta Az vs. Az "); 316 gzd.SetTitle(" \\Delta Zd vs. Zd "); 317 318 ifstream fin("tpoint/tpoint3.txt"); 317 319 318 320 while (fin && fin.get()!='\n'); … … 346 348 bending.SetMinuitParameters(minuit, 16); // Init Parameters [deg] 347 349 348 Int_t ierflg = 0; 349 350 // minuit.FixParameter(2); // NPAE 351 // minuit.FixParameter(3); // CA 352 // minuit.FixParameter(4); // AN 353 // minuit.FixParameter(5); // AW 354 // minuit.FixParameter(6); // NRX 355 // minuit.FixParameter(7); // NRY 350 //minuit.FixParameter(0); //(1) IA 351 //minuit.FixParameter(1); //(1) IE 352 minuit.FixParameter(2); //(2) NPAE 353 //minuit.FixParameter(3); //(1) CA 354 minuit.FixParameter(4); //(2) AN 355 //minuit.FixParameter(5); //(1) AW 356 357 minuit.FixParameter(6); // NRX 358 minuit.FixParameter(7); // NRY 356 359 minuit.FixParameter(8); // CRX 357 360 minuit.FixParameter(9); // CRY 358 //minuit.FixParameter(10); // ECES359 // minuit.FixParameter(11); //ACES360 //minuit.FixParameter(12); // ECEC361 // minuit.FixParameter(13); //ACEC362 //minuit.FixParameter(14); // MAGIC1361 minuit.FixParameter(10); // ECES 362 minuit.FixParameter(11); //(2) ACES 363 minuit.FixParameter(12); // ECEC 364 minuit.FixParameter(13); //(2) ACEC 365 minuit.FixParameter(14); // MAGIC1 363 366 minuit.FixParameter(15); // MAGIC2 364 367 368 365 369 //minuit.Command("SHOW PARAMETERS"); 370 //minuit.Command("SHOW LIMITS"); 371 cout << endl; 372 373 Int_t ierflg = 0; 366 374 ierflg = minuit.Migrad(); 367 cout << endl << "Migrad returns " << ierflg << endl << endl; 368 minuit.Command("SHOW LIMITS"); 369 370 cout << endl; 371 372 /* 373 minuit.FixParameter(0); 374 minuit.FixParameter(1); 375 minuit.Release(2); 376 377 ierflg = minuit.Migrad(); 378 cout << endl << "Migrad returns " << ierflg << endl << endl; 379 */ 380 375 cout << "Migrad returns " << ierflg << endl; 376 // minuit.Release(2); 377 ierflg = minuit.Migrad(); 378 cout << "Migrad returns " << ierflg << endl << endl; 379 380 // 381 // Get Fit Results 382 // 381 383 bending.GetMinuitParameters(minuit); 382 384 bending.PrintMinuitParameters(minuit); 383 385 bending.Save("bending_magic.txt"); 384 386 387 388 // 389 // Make a copy of all list entries 390 // 385 391 TList list; 386 392 list.SetOwner(); 387 388 393 for (int i=0; i<gCoordinates.GetSize(); i++) 394 list.Add(new Set(*(Set*)gCoordinates.At(i))); 395 396 // 397 // Calculate correction and residuals 398 // 399 for (int i=0; i<gCoordinates.GetSize(); i++) 389 400 { 390 401 Set &set0 = *(Set*)gCoordinates.At(i); 391 402 392 list.Add(new Set(set0));403 ZdAz za = set0.GetStarZdAz()*kRad2Deg; 393 404 394 405 hres1.Fill(set0.GetResidual()); 395 //set0.Adjust(bending); 396 set0.Adjust(bending, MyAdjust); 406 set0.Adjust(bending); 397 407 hres2.Fill(set0.GetResidual()); 398 408 399 hdzd.Fill( set0.GetStarAz(), set0.GetDEl()); 400 hdaz.Fill(90-set0.GetStarEl(), set0.GetDAz()); 409 Double_t dz = fmod(set0.GetDAz()+720, 360); 410 if (dz>180) 411 dz -= 360; 401 412 402 413 static int j=0; 403 gdzd.SetPoint(j, set0.GetStarAz(), set0.GetDEl()); 404 gdaz.SetPoint(j, 90-set0.GetStarEl(), set0.GetDAz()); 414 gdzd.SetPoint(j, za.Az()/* set0.GetStarAz()*/, set0.GetDZd()); 415 gaz.SetPoint( j, za.Az()/* set0.GetStarAz()*/, dz); 416 gdaz.SetPoint(j, za.Zd()/*90-set0.GetStarEl()*/, dz); 417 gzd.SetPoint( j, za.Zd()/*90-set0.GetStarEl()*/, set0.GetDZd()); 405 418 j++; 406 419 } 407 420 421 // 422 // Check for overflows 423 // 424 const Stat_t ov = hres2.GetBinContent(hres2.GetNbinsX()+1); 425 if (ov>0) 426 cout << "WARNING: " << ov << " overflows in residuals." << endl; 427 428 // 429 // Print all data sets for which the backward correction is 430 // twice times worse than the residual gotten from the 431 // bending correction itself 432 // 408 433 cout << endl; 434 cout << "Checking backward correction (raw-->star):" << endl; 435 for (int i=0; i<gCoordinates.GetSize(); i++) 436 { 437 Set set0(*(Set*)list.At(i)); 438 Set set1(*(Set*)list.At(i)); 439 440 set0.AdjustBack(bending); 441 set1.Adjust(bending); 442 443 Double_t res0 = set0.GetResidual(); 444 Double_t res1 = set1.GetResidual(); 445 446 Double_t diff = fabs(res0-res1); 447 448 if (diff<hres2.GetMean()*0.66) 449 continue; 450 451 cout << "DBack: " << setw(7) << set0.GetStarZd() << " " << setw(8) << set0.GetStarAz() << ": "; 452 cout << "ResB="<< setw(7) << res0*60 << " ResF=" << setw(7) << res1*60 << " |ResB-ResF|=" << setw(7) << diff*60 << " arcmin" << endl; 453 } 454 cout << "OK." << endl; 455 456 // 457 // Print out the residual before and after correction in several 458 // units 459 // 460 cout << endl; 461 cout << gCoordinates.GetSize() << " data sets." << endl << endl; 409 462 cout << "Spead before: " << hres1.GetMean() << "deg +- " << hres1.GetRMS() << "deg" << endl; 410 463 cout << "Spead after: " << hres2.GetMean() << "deg +- " << hres2.GetRMS() << "deg" << endl; … … 414 467 cout << endl; 415 468 469 470 416 471 TCanvas *c1=new TCanvas("c1", "c"); 417 c1->Divide(3,2); 472 c1->Divide(2,2); 473 474 c1->cd(2); 475 gdaz.DrawClone("A*"); 418 476 419 477 c1->cd(1); 420 hdaz.DrawCopy("cont"); 421 gdaz.DrawClone("*"); 478 gaz.DrawClone("A*"); 479 480 c1->cd(3); 481 gdzd.DrawClone("A*"); 422 482 423 483 c1->cd(4); 424 hdzd.DrawCopy("cont"); 425 gdzd.DrawClone("*"); 484 gzd.DrawClone("A*"); 485 486 487 488 c1=new TCanvas("c2", "c", 800, 800); 489 c1->Divide(2,2); 426 490 427 491 c1->cd(2); … … 429 493 hres1.DrawCopy(); 430 494 431 c1->cd( 5);495 c1->cd(4); 432 496 hres2.SetLineColor(kBlue); 433 497 hres2.DrawCopy(); 434 498 435 // c1->cd(3); 436 // gPad->SetTheta(90); 437 // gPad->SetPhi(90); 438 // h2res1.DrawCopy("surf1pol"); 439 // gPad->Modified(); 440 // gPad->Update(); 441 // for (int i=0; i<gCoordinates.GetSize(); i++) 442 // DrawSet(gPad, *(Set*)list.At(i), 10./hres1.GetMean()); 443 444 // c1->cd(6); 445 // gPad->SetTheta(90); 446 // gPad->SetPhi(90); 447 // h2res1.DrawCopy("surf1pol"); 448 // gPad->Modified(); 449 // gPad->Update(); 450 // for (int i=0; i<gCoordinates.GetSize(); i++) 451 // DrawSet(gPad, *(Set*)gCoordinates.At(i), 10./hres2.GetMean()); 499 c1->cd(1); 500 gPad->SetTheta(90); 501 gPad->SetPhi(90); 502 TH2F h2res1("Res2D1", " Arb. Residuals before correction (scaled) ", 32, 0, 360, 10, 0, 90); 503 h2res1.DrawCopy("surf1pol"); 504 gPad->Modified(); 505 gPad->Update(); 506 for (int i=0; i<gCoordinates.GetSize(); i++) 507 DrawSet(gPad, *(Set*)list.At(i), 10./hres1.GetMean()); 508 509 c1->cd(3); 510 gPad->SetTheta(90); 511 gPad->SetPhi(90); 512 h2res1.SetTitle(" Arb. Residuals after correction (scaled) "); 513 h2res1.DrawCopy("surf1pol"); 514 gPad->Modified(); 515 gPad->Update(); 516 for (int i=0; i<gCoordinates.GetSize(); i++) 517 DrawSet(gPad, *(Set*)gCoordinates.At(i), 10./hres2.GetMean()); 452 518 453 519 }
Note:
See TracChangeset
for help on using the changeset viewer.