Changeset 4060
- Timestamp:
- 05/13/04 14:03:32 (21 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/MagicSoft/Mars/mtemp/MFindStars.cc
r4054 r4060 43 43 #include "MMcConfigRunHeader.h" 44 44 45 #include "MMinuitInterface.h"46 47 45 #include "MLog.h" 48 46 #include "MLogManip.h" … … 84 82 85 83 MFindStars* find = (MFindStars*)gMinuit->GetObjectFit(); 86 MHCamera * display = (MHCamera*)find->GetDisplay();84 MHCamera& display = (MHCamera&)find->GetDisplay(); 87 85 Float_t ped = find->GetPedestalDC(); 88 86 Float_t rms = find->GetPedestalRMSDC(); 89 MGeomCam& geom = (MGeomCam&)display ->GetGeomCam();87 MGeomCam& geom = (MGeomCam&)display.GetGeomCam(); 90 88 91 89 UInt_t numPixels = geom.GetNumPixels(); … … 100 98 for (UInt_t pixid=1; pixid<numPixels; pixid++) 101 99 { 102 z = display ->GetBinContent(pixid+1)-ped;103 104 if (display ->IsUsed(pixid) && z > 0.)100 z = display.GetBinContent(pixid+1)-ped; 101 102 if (display.IsUsed(pixid)) 105 103 { 106 104 x = geom[pixid].GetX(); … … 131 129 fMaxNumIntegratedEvents = 10; 132 130 fRingInterest = 125.; //[mm] ~ 0.4 deg 133 f MinDCForStars = 2.*fMaxNumIntegratedEvents; //[uA]131 fDCTailCut = 4; 134 132 135 133 fPixelsUsed.Set(577); … … 138 136 //Fitting(Minuit) initialitation 139 137 const Float_t pixelSize = 31.5; //[mm] 140 138 fMinuitPrintOutLevel = -1; 139 141 140 fVname = new TString[fNumVar]; 142 141 fVinit.Set(fNumVar); … … 155 154 fVname[1] = "meanx"; 156 155 fVinit[1] = 0.; 157 fStep[1] = fVinit[ 0]/sqrt2;156 fStep[1] = fVinit[1]/sqrt2; 158 157 fLimlo[1] = -600.; 159 158 fLimup[1] = 600.; … … 162 161 fVname[2] = "sigmaminor"; 163 162 fVinit[2] = pixelSize; 164 fStep[2] = fVinit[ 0]/sqrt2;163 fStep[2] = fVinit[2]/sqrt2; 165 164 fLimlo[2] = pixelSize/(2*sqrt3); 166 165 fLimup[2] = 500.; … … 169 168 fVname[3] = "meany"; 170 169 fVinit[3] = 0.; 171 fStep[3] = fVinit[ 0]/sqrt2;170 fStep[3] = fVinit[3]/sqrt2; 172 171 fLimlo[3] = -600.; 173 172 fLimup[3] = 600.; … … 176 175 fVname[4] = "sigmamajor"; 177 176 fVinit[4] = pixelSize; 178 fStep[4] = fVinit[ 0]/sqrt2;177 fStep[4] = fVinit[4]/sqrt2; 179 178 fLimlo[4] = pixelSize/(2*sqrt3); 180 179 fLimup[4] = 500.; … … 183 182 fObjectFit = NULL; 184 183 // fMethod = "SIMPLEX"; 185 //fMethod = "MIGRAD";186 fMethod = "MINIMIZE";184 fMethod = "MIGRAD"; 185 // fMethod = "MINIMIZE"; 187 186 fNulloutput = kFALSE; 188 187 } … … 199 198 } 200 199 200 // Initialize camera display with the MGeomCam information 201 201 fDisplay.SetGeometry(*fGeomCam); 202 202 fDisplay.SetUsed(fPixelsUsed); … … 281 281 return kFALSE; 282 282 } 283 284 fMinDCForStars = 1.5*fMaxNumIntegratedEvents; //[uA] 285 286 // Initialize the TMinuit object 287 288 TMinuit *gMinuit = new TMinuit(fNumVar); //initialize TMinuit with a maximum of params 289 gMinuit->SetFCN(fcn); 290 291 Double_t arglist[10]; 292 Int_t ierflg = 0; 293 294 arglist[0] = 1; 295 gMinuit->mnexcm("SET ERR", arglist ,1,ierflg); 296 arglist[0] = fMinuitPrintOutLevel; 297 gMinuit->mnexcm("SET PRI", arglist ,1,ierflg); 298 299 // Set object pointer to allow mimuit to access internally 300 gMinuit->SetObjectFit(this); 283 301 284 302 return kTRUE; … … 319 337 320 338 DCPedestalCalc(fPedestalDC, fPedestalRMSDC); 321 fMinDCForStars = fMinDCForStars>(fPedestalDC+ 5*fPedestalRMSDC)?fMinDCForStars:(fPedestalDC+5*fPedestalRMSDC);339 fMinDCForStars = fMinDCForStars>(fPedestalDC+fDCTailCut*fPedestalRMSDC)?fMinDCForStars:(fPedestalDC+fDCTailCut*fPedestalRMSDC); 322 340 323 341 *fLog << dbg << " DC pedestal = " << fPedestalDC << " pedestal rms = " << fPedestalRMSDC << endl; … … 416 434 Bool_t MFindStars::DCPedestalCalc(Float_t &ped, Float_t &rms) 417 435 { 418 //-------------------------------------------------------------419 // save pointer to the MINUIT object for optimizing the supercuts420 // because it will be overwritten421 // when fitting the alpha distribution in MHFindSignificance422 TMinuit *savePointer = gMinuit;423 //-------------------------------------------------------------436 //------------------------------------------------------------- 437 // save pointer to the MINUIT object for optimizing the supercuts 438 // because it will be overwritten 439 // when fitting the alpha distribution in MHFindSignificance 440 TMinuit *savePointer = gMinuit; 441 //------------------------------------------------------------- 424 442 425 443 UInt_t numPixels = fGeomCam->GetNumPixels(); … … 453 471 454 472 dchist.Fit("func","QR0"); 473 // Remove the comments if you want to go through the file 474 // event-by-event: 475 // HandleInput(); 455 476 456 477 UInt_t aproxnumdegrees = 6*(bin-dchist.GetMaximumBin()); … … 465 486 minbin=minbin<1?1:minbin; 466 487 Axis_t maxbin = ped+numsigmas*rms/dchist.GetBinWidth(1); 467 468 488 *fLog << dbg << " Number of pixels with dc under " << numsigmas << " sigmas = " << dchist.Integral((int)minbin,(int)maxbin) << endl; 469 489 470 //Check results from the fit are consistent 471 if (TMath::Abs(ped-maxprobdc) > rmsguess || rms > rmsguess) 472 { 473 *fLog << warn << GetName() << " Pedestal DC fit give non consistent results." << endl; 474 *fLog << warn << " maxprobdc " << maxprobdc << " rmsguess " << rmsguess << endl; 475 *fLog << warn << " ped " << ped << " rms " << rms << " chiq/ndof " << chiq << "/" << aproxnumdegrees << endl; 476 ped = maxprobdc; 477 rms = rmsguess/1.175; // FWHM=2.35*rms 478 } 479 480 //================================================================= 481 // reset gMinuit to the MINUIT object for optimizing the supercuts 482 gMinuit = savePointer; 483 //------------------------------------------- 490 //Check results from the fit are consistent 491 if (TMath::Abs(ped-maxprobdc) > rmsguess || rms > rmsguess) 492 { 493 *fLog << warn << GetName() << " Pedestal DC fit give non consistent results." << endl; 494 *fLog << warn << " maxprobdc " << maxprobdc << " rmsguess " << rmsguess << endl; 495 *fLog << warn << " ped " << ped << " rms " << rms << " chiq/ndof " << chiq << "/" << aproxnumdegrees << endl; 496 ped = maxprobdc; 497 rms = rmsguess/1.175; // FWHM=2.35*rms 498 } 499 500 //================================================================= 501 502 // reset gMinuit to the MINUIT object for optimizing the supercuts 503 gMinuit = savePointer; 504 //------------------------------------------- 484 505 485 506 return kTRUE; … … 598 619 usedPx++; 599 620 600 Float_t charge = fDisplay.GetBinContent(pix+1) ;621 Float_t charge = fDisplay.GetBinContent(pix+1)-fPedestalDC; 601 622 Float_t pixXpos = (*fGeomCam)[pix].GetX(); 602 623 Float_t pixYpos = (*fGeomCam)[pix].GetY(); … … 618 639 meanSqY /= sumCharge; 619 640 620 //Substract pedestal from sumCharge 621 sumCharge -= usedPx*fPedestalDC; 622 623 Float_t rmsX = TMath::Sqrt(meanSqX - meanX*meanX); 624 Float_t rmsY = TMath::Sqrt(meanSqY - meanY*meanY); 641 Float_t rmsX = (meanSqX - meanX*meanX); 642 Float_t rmsY = (meanSqY - meanY*meanY); 643 644 if ( rmsX > 0) 645 rmsX = TMath::Sqrt(rmsX); 646 else 647 { 648 *fLog << warn << " MFindStars::FindStar negative rmsX² " << rmsX << endl; 649 *fLog << warn << " meanSqX " << meanSqX << " meanX " << meanX << " sumCharge " << sumCharge << endl; 650 rmsX = 0.; 651 } 652 653 if ( rmsY > 0) 654 rmsY = TMath::Sqrt(rmsY); 655 else 656 { 657 *fLog << warn << " MFindStars::FindStar negative rmsY² " << rmsY << endl; 658 *fLog << warn << " meanSqY " << meanSqY << " meanY " << meanY << endl; 659 rmsY = 0.; 660 } 625 661 626 662 star->SetCalcValues(sumCharge,max,meanX,meanY,rmsX,rmsY); 627 663 628 664 if (rmsX <= 0. || rmsY <= 0.) 665 return kFALSE; 666 629 667 // fit the star spot using TMinuit 630 668 631 for (UInt_t pix=1; pix<numPixels; pix++) 669 670 for (UInt_t pix=1; pix<numPixels; pix++) 632 671 if (fDisplay.IsUsed(pix)) 633 672 *fLog << dbg << "[fit the star spot] fDisplay.IsUsed(" << pix << ") kTRUE" << endl; 634 673 635 674 //Initialate variables for fit 636 fVinit[0] = star->GetMaxCalc()-fPedestalDC;675 fVinit[0] = max; 637 676 fLimlo[0] = fMinDCForStars-fPedestalDC; 638 fLimup[0] = fLimup[0]-fPedestalDC;677 fLimup[0] = 30*fMaxNumIntegratedEvents-fPedestalDC; 639 678 fVinit[1] = meanX; 640 679 fVinit[2] = rmsX; … … 647 686 // 648 687 688 // ------------------------------------------- 689 // call MINUIT 690 691 Double_t arglist[10]; 692 Int_t ierflg = 0; 693 694 for (Int_t i=0; i<fNumVar; i++) 695 gMinuit->mnparm(i, fVname[i], fVinit[i], fStep[i], fLimlo[i], fLimup[i], ierflg); 696 649 697 TStopwatch clock; 650 698 clock.Start(); 651 699 652 *fLog << dbg << " before calling CallMinuit" << endl; 653 654 MMinuitInterface inter; 655 Bool_t rc = inter.CallMinuit(fcn, fVname, 656 fVinit, fStep, fLimlo, fLimup, fFix, 657 this, fMethod, fNulloutput); 658 659 *fLog << dbg << "after calling CallMinuit" << endl; 660 *fLog << dbg << "Time spent for the minimization in MINUIT : " << endl;; 700 // Now ready for minimization step 701 arglist[0] = 500; 702 arglist[1] = 1.; 703 gMinuit->mnexcm(fMethod, arglist ,2,ierflg); 704 661 705 clock.Stop(); 662 clock.Print(); 706 707 if(fMinuitPrintOutLevel>=0) 708 { 709 *fLog << dbg << "Time spent for the minimization in MINUIT : " << endl;; 710 clock.Print(); 711 } 663 712 664 713 Double_t integratedCharge; … … 671 720 Int_t dregrees = GetDegreesofFreedom()-fNumVar; 672 721 673 if ( rc)722 if (!ierflg) 674 723 { 675 724 gMinuit->GetParameter(0,maxFit, maxFitError); … … 692 741 sigmaMajorAxis = 0.; 693 742 integratedCharge = 0.; 694 } 695 696 743 744 *fLog << err << "TMinuit::Call error " << ierflg << endl; 745 } 697 746 698 747 star->SetFitValues(integratedCharge,maxFit,meanXFit,meanYFit,sigmaMinorAxis,sigmaMajorAxis,chisquare,dregrees); 699 748 700 749 // reset the display to the starting values 701 750 fDisplay.SetUsed(origPixelsUsed); 702 751 703 return rc; 752 if (ierflg) 753 return kCONTINUE; 754 return kTRUE; 704 755 } 705 756 … … 740 791 741 792 793 794
Note:
See TracChangeset
for help on using the changeset viewer.