Changeset 4060


Ignore:
Timestamp:
05/13/04 14:03:32 (21 years ago)
Author:
jlopez
Message:
*** empty log message ***
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/MagicSoft/Mars/mtemp/MFindStars.cc

    r4054 r4060  
    4343#include "MMcConfigRunHeader.h"
    4444
    45 #include "MMinuitInterface.h"
    46 
    4745#include "MLog.h"
    4846#include "MLogManip.h"
     
    8482
    8583    MFindStars* find =  (MFindStars*)gMinuit->GetObjectFit();
    86     MHCamera* display = (MHCamera*)find->GetDisplay();
     84    MHCamera& display = (MHCamera&)find->GetDisplay();
    8785    Float_t ped = find->GetPedestalDC();
    8886    Float_t rms = find->GetPedestalRMSDC();
    89     MGeomCam& geom = (MGeomCam&)display->GetGeomCam();
     87    MGeomCam& geom = (MGeomCam&)display.GetGeomCam();
    9088
    9189    UInt_t numPixels = geom.GetNumPixels();
     
    10098    for (UInt_t pixid=1; pixid<numPixels; pixid++)
    10199    {
    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))
    105103        {
    106104            x = geom[pixid].GetX();
     
    131129  fMaxNumIntegratedEvents = 10;
    132130  fRingInterest = 125.; //[mm] ~ 0.4 deg
    133   fMinDCForStars = 2.*fMaxNumIntegratedEvents; //[uA]
     131  fDCTailCut = 4;
    134132 
    135133  fPixelsUsed.Set(577);
     
    138136  //Fitting(Minuit) initialitation
    139137  const Float_t pixelSize = 31.5; //[mm]
    140 
     138  fMinuitPrintOutLevel = -1;
     139 
    141140  fVname = new TString[fNumVar];
    142141  fVinit.Set(fNumVar);
     
    155154  fVname[1] = "meanx";
    156155  fVinit[1] = 0.;
    157   fStep[1]  = fVinit[0]/sqrt2;
     156  fStep[1]  = fVinit[1]/sqrt2;
    158157  fLimlo[1] = -600.;
    159158  fLimup[1] = 600.;
     
    162161  fVname[2] = "sigmaminor";
    163162  fVinit[2] = pixelSize;
    164   fStep[2]  = fVinit[0]/sqrt2;
     163  fStep[2]  = fVinit[2]/sqrt2;
    165164  fLimlo[2] = pixelSize/(2*sqrt3);
    166165  fLimup[2] = 500.;
     
    169168  fVname[3] = "meany";
    170169  fVinit[3] = 0.;
    171   fStep[3]  = fVinit[0]/sqrt2;
     170  fStep[3]  = fVinit[3]/sqrt2;
    172171  fLimlo[3] = -600.;
    173172  fLimup[3] = 600.;
     
    176175  fVname[4] = "sigmamajor";
    177176  fVinit[4] = pixelSize;
    178   fStep[4]  = fVinit[0]/sqrt2;
     177  fStep[4]  = fVinit[4]/sqrt2;
    179178  fLimlo[4] = pixelSize/(2*sqrt3);
    180179  fLimup[4] = 500.;
     
    183182  fObjectFit  = NULL;
    184183  //  fMethod     = "SIMPLEX";
    185   //  fMethod     = "MIGRAD";
    186   fMethod     = "MINIMIZE";
     184  fMethod     = "MIGRAD";
     185  //  fMethod     = "MINIMIZE";
    187186  fNulloutput = kFALSE;
    188187}
     
    199198    }
    200199
     200    // Initialize camera display with the MGeomCam information
    201201    fDisplay.SetGeometry(*fGeomCam);
    202202    fDisplay.SetUsed(fPixelsUsed);
     
    281281      return kFALSE;
    282282    }
     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);
    283301
    284302    return kTRUE;
     
    319337         
    320338          DCPedestalCalc(fPedestalDC, fPedestalRMSDC);
    321           fMinDCForStars = fMinDCForStars>(fPedestalDC+5*fPedestalRMSDC)?fMinDCForStars:(fPedestalDC+5*fPedestalRMSDC);
     339          fMinDCForStars = fMinDCForStars>(fPedestalDC+fDCTailCut*fPedestalRMSDC)?fMinDCForStars:(fPedestalDC+fDCTailCut*fPedestalRMSDC);
    322340
    323341          *fLog << dbg << " DC pedestal = " << fPedestalDC << " pedestal rms = " << fPedestalRMSDC << endl;
     
    416434Bool_t MFindStars::DCPedestalCalc(Float_t &ped, Float_t &rms)
    417435{
    418   //-------------------------------------------------------------
    419   // save pointer to the MINUIT object for optimizing the supercuts
    420   // because it will be overwritten
    421   // when fitting the alpha distribution in MHFindSignificance
    422   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    //-------------------------------------------------------------
    424442
    425443   UInt_t numPixels = fGeomCam->GetNumPixels();
     
    453471   
    454472   dchist.Fit("func","QR0");
     473   // Remove the comments if you want to go through the file
     474   // event-by-event:
     475   //   HandleInput();
    455476
    456477   UInt_t aproxnumdegrees = 6*(bin-dchist.GetMaximumBin());
     
    465486   minbin=minbin<1?1:minbin;
    466487   Axis_t maxbin = ped+numsigmas*rms/dchist.GetBinWidth(1);
    467 
    468488   *fLog << dbg << " Number of pixels with dc under " << numsigmas << " sigmas = " << dchist.Integral((int)minbin,(int)maxbin) << endl;
    469489
    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    //-------------------------------------------
    484505
    485506   return kTRUE;
     
    598619            usedPx++;
    599620
    600             Float_t charge  = fDisplay.GetBinContent(pix+1);
     621            Float_t charge  = fDisplay.GetBinContent(pix+1)-fPedestalDC;
    601622            Float_t pixXpos = (*fGeomCam)[pix].GetX();
    602623            Float_t pixYpos = (*fGeomCam)[pix].GetY();
     
    618639    meanSqY /= sumCharge;
    619640
    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      }
    625661   
    626662    star->SetCalcValues(sumCharge,max,meanX,meanY,rmsX,rmsY);
    627663
    628 
     664    if (rmsX <= 0. || rmsY <= 0.)
     665      return kFALSE;
     666   
    629667// fit the star spot using TMinuit
    630668
    631   for (UInt_t pix=1; pix<numPixels; pix++)
     669   
     670    for (UInt_t pix=1; pix<numPixels; pix++)
    632671      if (fDisplay.IsUsed(pix))
    633672        *fLog << dbg << "[fit the star spot] fDisplay.IsUsed(" << pix << ") kTRUE" << endl;
    634673 
    635674  //Initialate variables for fit
    636     fVinit[0] = star->GetMaxCalc()-fPedestalDC;
     675    fVinit[0] = max;
    637676    fLimlo[0] = fMinDCForStars-fPedestalDC;
    638     fLimup[0] = fLimup[0]-fPedestalDC;
     677    fLimup[0] = 30*fMaxNumIntegratedEvents-fPedestalDC;
    639678    fVinit[1] = meanX;
    640679    fVinit[2] = rmsX;
     
    647686    //
    648687
     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
    649697    TStopwatch clock;
    650698    clock.Start();
    651699
    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
    661705    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      }
    663712
    664713    Double_t integratedCharge;
     
    671720    Int_t   dregrees  = GetDegreesofFreedom()-fNumVar;
    672721
    673     if (rc)
     722    if (!ierflg)
    674723      {
    675724        gMinuit->GetParameter(0,maxFit, maxFitError);
     
    692741        sigmaMajorAxis = 0.;
    693742        integratedCharge = 0.;
    694       }
    695    
    696    
     743
     744        *fLog << err << "TMinuit::Call error " << ierflg << endl;
     745      }
    697746   
    698747    star->SetFitValues(integratedCharge,maxFit,meanXFit,meanYFit,sigmaMinorAxis,sigmaMajorAxis,chisquare,dregrees);
    699 
     748   
    700749    // reset the display to the starting values
    701750    fDisplay.SetUsed(origPixelsUsed);
    702751
    703     return rc;
     752    if (ierflg)
     753      return kCONTINUE;
     754    return kTRUE;
    704755}
    705756
     
    740791
    741792
     793
     794
Note: See TracChangeset for help on using the changeset viewer.