Ignore:
Timestamp:
03/14/06 16:07:39 (19 years ago)
Author:
tbretz
Message:
*** empty log message ***
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/MagicSoft/Mars/mhflux/MHEffectiveOnTime.cc

    r7534 r7602  
    474474
    475475    // FIXME: Do fit only if contents of bin has changed
    476     if (Nm<=0)
     476    if (Nm<=0 || h->GetBinContent(1)<=0)
    477477        return kFALSE;
    478478
     
    483483    // within the range (yq[0], yq[1]) there must be no empty bin;
    484484    // choose pedestrian approach as long as GetQuantiles is not available
    485     Double_t xq[2] = { 0.6, 0.99 };
     485    Double_t xq[2] = { 0.6, 0.95 }; // previously 0.99
    486486    Double_t yq[2];
    487487    h->GetQuantiles(2, yq, xq);
    488488
    489     // Nmdel = Nm * binwidth,  with Nm = number of observed events
    490     const Double_t Nmdel = h->Integral("width");
    491 
    492     //
    493     // Setup Poisson function for the fit:
    494     // lambda [Hz], N0 = ideal no of evts, del = bin width of dt
    495     //
    496     // parameter 0 = lambda
    497     // parameter 1 = N0*del
    498     //
    499     TF1 func("Poisson", " [1]*[2] * [0] * exp(-[0] *x)");
    500     //func.SetParNames("lambda", "N0", "del");
     489    //
     490    // Setup exponential function for the fit:
     491    //
     492    // parameter 0 = rate [Hz]
     493    // parameter 1 = normalization
     494    //
     495    TF1 func("Exp", " exp([1]-[0]*x)");
    501496
    502497    func.SetParameter(0, 200);       // Hz
    503     func.SetParameter(1, Nm);
    504     func.FixParameter(2, Nmdel/Nm);
     498    func.SetParameter(1, log(h->GetBinContent(1)));       // Hz
    505499
    506500    // options : N  do not store the function, do not draw
     
    508502    //           R  use the range specified in the function range
    509503    //           Q  quiet mode
    510     h->Fit(&func, "NIQE", "", yq[0], yq[1]);
     504    //           L  Use log-likelihood (better for low statistics)
     505    h->Fit(&func, "NIQEL", "", h->GetBinLowEdge(3)/*yq[0]*/, yq[1]);
    511506
    512507    const Double_t chi2 = func.GetChisquare();
     508    const Double_t prob = func.GetProb();
    513509    const Int_t    NDF  = func.GetNDF();
    514510
    515511    // was fit successful ?
    516     const Bool_t ok = NDF>0 && chi2<3*NDF;
     512    const Bool_t ok = prob>0.001; //NDF>0 && chi2<3*NDF;
    517513
    518514    if (paint)
     
    523519    }
    524520
     521    // The effective on time is the "real rate" (slope of the exponential)
     522    // divided by the total number of events (histogram integral including
     523    // under- and overflows)
    525524    const Double_t lambda = func.GetParameter(0);
    526     //const Double_t N0     = func.GetParameter(1);
    527     const Double_t prob   = func.GetProb();
    528 
    529     /*
    530      *fLog << all << "Nm/lambda=" << Nm/lambda << "  chi2/NDF=";
    531      *fLog << (NDF ? chi2/NDF : 0.0) << "  lambda=";
    532      *fLog << lambda << "  N0=" << N0 << endl;
    533      */
    534 
    535     Double_t emat[2][2];
    536     gMinuit->mnemat((Double_t*)emat, 2);
    537 
    538     const Double_t dldl  = emat[0][0];
    539     //const Double_t dN0dN0 = emat[1][1];
    540 
    541     const Double_t teff  = Nm/lambda;
    542     const Double_t dteff = teff * TMath::Sqrt(dldl/(lambda*lambda) + 1.0/Nm);
    543     const Double_t dl    = TMath::Sqrt(dldl);
    544 
    545     //const Double_t kappa  = Nm/N0;
    546     //const Double_t Rdead  = 1.0 - kappa;
    547     //const Double_t dRdead = kappa * TMath::Sqrt(dN0dN0/(N0*N0) + 1.0/Nm);
     525    const Double_t dldl   = func.GetParError(0)*func.GetParError(0);
     526    const Double_t teff   = Nm / lambda;
     527    const Double_t dteff  = teff * TMath::Sqrt(dldl/(lambda*lambda) + 1.0/Nm);
     528    const Double_t dl     = TMath::Sqrt(dldl);
    548529
    549530    // the effective on time is Nm/lambda
     
    563544    // Chi2
    564545    res[6] = chi2;
    565 
    566     // Rdead (from fit) is the fraction from real time lost by the dead time
    567     //fHRdead.SetBinContent(i, Rdead);
    568     //fHRdead.SetBinError  (i,dRdead);
    569546
    570547    return ok;
     
    583560    fHThetaNDF.Reset();
    584561
     562    // Use a random name to make sure the object is unique
    585563    const TString name = Form("CalcTheta%d", (UInt_t)gRandom->Uniform(999999999));
    586564
     
    594572        h = fH2DeltaT.ProjectionX(name, i, i, "E");
    595573
    596         Double_t res[7];
    597         if (!FitH(h, res))
     574        Double_t res[7] = {0, 0, 0, 0, 0, 0, 0};
     575        //if (!FitH(h, res))
     576        //    continue;
     577        FitH(h, res);
     578
     579        if (res[0]==0)
    598580            continue;
    599581
Note: See TracChangeset for help on using the changeset viewer.