Changeset 5901 for trunk


Ignore:
Timestamp:
01/19/05 13:17:09 (20 years ago)
Author:
tbretz
Message:
*** empty log message ***
Location:
trunk/MagicSoft/Mars
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/MagicSoft/Mars/Changelog

    r5900 r5901  
    2121                                                 -*-*- END OF LINE -*-*-
    2222
    23  2205/01/19 Abelardo Moralejo
     23 2005/01/19 Thomas Bretz
     24 
     25   * mbase/MMath.cc:
     26     - added a comment to SignificanceLiMa, made by Daniel Mazin
     27     - also check for b==0
     28
     29   * mhflux/MAlphaFitter.[h,cc]:
     30     - fixed significance calculation in case of on-off data
     31     - added fScaleFactor
     32
     33   * mhflux/MHAlpha.[h,cc], mhflux/MHFalseSource.cc:
     34     - handle scale factor in case of on-off observations
     35
     36
     37
     38 2005/01/19 Abelardo Moralejo
    2439
    2540   * mtrigger/MFTriggerPattern.[cc,h]
     
    2742       defined by N. Galante (see below)
    2843
    29  2205/01/19 Nicola Galante
     44
     45
     46 2005/01/19 Nicola Galante
    3047
    3148   * mtrigger/MFTriggerPattern.[cc,h]
     
    3552     - fixed a bug in Process, both fMaskRequiredUnprescaled and
    3653       fMaskRequiredPrescaled are checked simultaneously.
     54
    3755
    3856
  • trunk/MagicSoft/Mars/mbase/MMath.cc

    r5883 r5901  
    7070//
    7171//  Returns -1 if sum<0 or alpha<0 or the argument of sqrt<0
    72 //  Returns  0 if s+b==0 or s==0
     72//  Returns  0 if s+b==0, s==0 or b==0
     73//
     74// Here is some eMail written by Daniel Mazin about the meaning of the arguments:
     75//
     76//  > Ok. Here is my understanding:
     77//  > According to Li&Ma paper (correctly cited in MMath.cc) alpha is the
     78//  > scaling factor. The mathematics behind the formula 17 (and/or 9) implies
     79//  > exactly this. If you scale OFF to ON first (using time or using any other
     80//  > method), then you cannot use formula 17 (9) anymore. You can just try
     81//  > the formula before scaling (alpha!=1) and after scaling (alpha=1), you
     82//  > will see the result will be different.
     83//
     84//  > Here are less mathematical arguments:
     85//
     86//  >  1) the better background determination you have (smaller alpha) the more
     87//  > significant is your excess, thus your analysis is more sensitive. If you
     88//  > normalize OFF to ON first, you loose this sensitivity.
     89//
     90//  >  2) the normalization OFF to ON has an error, which naturally depends on
     91//  > the OFF and ON. This error is propagating to the significance of your
     92//  > excess if you use the Li&Ma formula 17 correctly. But if you normalize
     93//  > first and use then alpha=1, the error gets lost completely, you loose
     94//  > somehow the criteria of goodness of the normalization.
    7395//
    7496Double_t MMath::SignificanceLiMa(Double_t s, Double_t b, Double_t alpha)
     
    7698    const Double_t sum = s+b;
    7799
    78     if (s==0 || sum==0)
     100    if (s==0 || b==0 || sum==0)
    79101        return 0;
    80102
  • trunk/MagicSoft/Mars/mhflux/MAlphaFitter.cc

    r5776 r5901  
    6565    fChiSqBg=0;
    6666    fIntegralMax=0;
     67    fScaleFactor=1;
    6768
    6869    fCoefficients.Reset();
     
    210211}
    211212
    212 Bool_t MAlphaFitter::Fit(TH1D &hon, TH1D &hof, Bool_t paint)
     213Bool_t MAlphaFitter::Fit(TH1D &hon, TH1D &hof, Double_t alpha, Bool_t paint)
    213214{
    214215    /*
     
    224225    fit.SetPolynomOrder(1);
    225226
    226     if (!fit.Fit(h, paint))
     227    if (alpha<=0 || !fit.Fit(h, paint))
    227228        return kFALSE;
    228229
     
    237238    fEventsSignal     = hon.Integral(0, bin);
    238239    fEventsExcess     = fEventsSignal-fEventsBackground;
    239     fSignificance     = MMath::SignificanceLiMaSigned(fEventsSignal, fEventsBackground);
     240    fScaleFactor      = alpha;
     241    fSignificance     = MMath::SignificanceLiMaSigned(fEventsSignal, fEventsBackground/alpha, alpha);
    240242
    241243    if (fEventsExcess<0)
     
    399401    h0->SetDirectory(0);
    400402
    401     Scale(*h0, *h1);
    402 
    403     const Bool_t rc = Fit(*h1, *h0, paint);
     403    const Bool_t rc = ScaleAndFit(*h1, h0, paint);
    404404
    405405    delete h0;
     
    419419    h0->SetDirectory(0);
    420420
    421     Scale(*h0, *h1);
    422 
    423     const Bool_t rc = Fit(*h1, *h0, paint);
     421    const Bool_t rc = ScaleAndFit(*h1, h0, paint);
    424422
    425423    delete h0;
     
    439437    h0->SetDirectory(0);
    440438
    441     Scale(*h0, *h1);
    442 
    443     const Bool_t rc = Fit(*h1, *h0, paint);
     439    const Bool_t rc = ScaleAndFit(*h1, h0, paint);
    444440
    445441    delete h0;
     
    449445}
    450446
    451 void MAlphaFitter::Scale(TH1D &of, const TH1D &on) const
     447Double_t MAlphaFitter::Scale(TH1D &of, const TH1D &on) const
    452448{
    453449    Float_t scaleon = 1;
     
    456452    {
    457453    case kNone:
    458         return;
     454        return 1;
    459455
    460456    case kEntries:
     
    481477        break;
    482478
     479        // This is just to make some compiler happy
    483480    default:
    484         return;
     481        return 1;
    485482    }
    486483
    487484    if (scaleof!=0)
     485    {
    488486        of.Scale(scaleon/scaleof);
     487        return scaleon/scaleof;
     488    }
    489489    else
     490    {
    490491        of.Reset();
    491 }
     492        return 0;
     493    }
     494}
  • trunk/MagicSoft/Mars/mhflux/MAlphaFitter.h

    r5776 r5901  
    4040    Double_t fEventsExcess;
    4141    Double_t fEventsSignal;
    42     Double_t fEventsBackground;
     42    Double_t fEventsBackground; // fScaleFactor already applied
    4343
    4444    Double_t fChiSqSignal;
    4545    Double_t fChiSqBg;
    4646    Double_t fIntegralMax;
     47    Double_t fScaleFactor;  // Scale factor for off-data
    4748
    4849    TArrayD fCoefficients;
     
    6263        gROOT->GetListOfFunctions()->Remove(fFunc);
    6364        fFunc->SetName("Dummy");
     65
     66        Clear();
    6467    }
    6568
     
    103106    Double_t GetChiSqSignal() const        { return fChiSqSignal; }
    104107    Double_t GetChiSqBg() const            { return fChiSqBg; }
     108    Double_t GetScaleFactor() const        { return fScaleFactor; }
    105109
    106110    Double_t GetGausSigma() const          { return fCoefficients[2]; }
     
    113117
    114118    Bool_t Fit(TH1D &h, Bool_t paint=kFALSE);
    115     Bool_t Fit(TH1D &on, TH1D &off, Bool_t paint=kFALSE);
     119    Bool_t Fit(TH1D &on, TH1D &off, Double_t alpha, Bool_t paint=kFALSE);
     120    Bool_t Fit(TH1D &on, TH1D *off, Double_t alpha, Bool_t paint=kFALSE)
     121    {
     122        return off ? Fit(on, *off, alpha, paint) : Fit(on, paint);
     123    }
    116124    Bool_t Fit(TH1D &on, TH1D *off, Bool_t paint=kFALSE)
    117125    {
    118         return off ? Fit(on, *off, paint) : Fit(on, paint);
     126        return off ? Fit(on, *off, 1, paint) : Fit(on, paint);
     127    }
     128    Bool_t ScaleAndFit(TH1D &on, TH1D *off, Bool_t paint=kFALSE)
     129    {
     130        const Double_t alpha = off ? Scale(*off, on) : 1;
     131        return off ? Fit(on, *off, alpha, paint) : Fit(on, paint);
    119132    }
    120133
     
    140153    }
    141154
    142     void Scale(TH1D &off, const TH1D &on) const;
     155    Double_t Scale(TH1D &off, const TH1D &on) const;
    143156
    144157    ClassDef(MAlphaFitter, 1)
  • trunk/MagicSoft/Mars/mhflux/MHAlpha.cc

    r5883 r5901  
    392392
    393393    TH1D *h = fOffData ? fOffData->ProjectionZ("ProjTimeTemp", -1, 9999, -1, 9999, "E") : 0;
    394     const Bool_t rc = fit.Fit(fHAlphaTime, h);
     394    const Bool_t rc = fit.ScaleAndFit(fHAlphaTime, h);
    395395    if (h)
    396396        delete h;
     
    544544        {
    545545            TH1D *hoff = fOffData->ProjectionZ("ProjAlphaOff");
    546             fFit.Scale(*hoff, *hon);
     546            const Double_t alpha = fFit.Scale(*hoff, *hon);
    547547
    548548            hon->SetMaximum();
    549549            hon->SetMaximum(TMath::Max(hon->GetMaximum(), hoff->GetMaximum())*1.05);
     550
     551            // BE CARFEULL: This is a really weird workaround!
     552            hoff->SetMaximum(alpha);
    550553
    551554            if ((h0=(TH1D*)gPad->FindObject("ProjAlphaOnOff")))
     
    564567        if ((h0 = (TH1D*)gPad->FindObject("ProjAlpha")))
    565568        {
    566             // Do not store the 'final' result in fFit
    567             MAlphaFitter fit(fFit);
     569            // Check whether we are dealing with on-off analysis
    568570            TH1D *hoff = (TH1D*)gPad->FindObject("ProjAlphaOff");
    569             fit.Fit(*h0, hoff, kTRUE);
    570             fit.PaintResult();
     571            if (hoff)
     572            {
     573                // Do not store the 'final' result in fFit
     574                MAlphaFitter fit(fFit);
     575
     576                // BE CARFEULL: This is a really weird workaround!
     577                const Double_t alpha = hoff->GetMaximum();
     578                fit.Fit(*h0, hoff, alpha<0 ? 1: alpha, kTRUE);
     579
     580                fit.PaintResult();
     581            }
    571582        }
    572583
     
    757768
    758769        TH1D *hof = 0;
     770        Double_t alpha = 1;
    759771
    760772        if (fOffData)
     
    772784            hof->Draw("same");
    773785
    774             fit.Scale(*hof, *hon);
     786            alpha = fit.Scale(*hof, *hon);
    775787
    776788            hon->SetMaximum();
     
    796808        }
    797809
    798         if (hof ? fit.Fit(*hon, *hof) : fit.Fit(*hon))
    799                 *fLog << dbg << "Bin " << i << ": sigma=" << fit.GetSignificance() << " omega=" << fit.GetGausSigma() << " events=" << fit.GetEventsExcess() << endl;
     810        if (hof ? fit.Fit(*hon, *hof, alpha) : fit.Fit(*hon))
     811            *fLog << dbg << "Bin " << i << ": sigma=" << fit.GetSignificance() << " omega=" << fit.GetGausSigma() << " events=" << fit.GetEventsExcess() << endl;
    800812        /*
    801813        if (fit.FitEnergy(fHAlpha, fOffData, i, kTRUE))
  • trunk/MagicSoft/Mars/mhflux/MHFalseSource.cc

    r5869 r5901  
    954954
    955955    TH1D *h=0, *hoff=0;
     956    Double_t scale = 1;
    956957    for (int ix=1; ix<=nx; ix++)
    957958        for (int iy=1; iy<=ny; iy++)
     
    969970            {
    970971                hoff = fHistOff->ProjectionZ("AlphaFitOff", ix, ix, iy, iy);
    971                 hoff->Scale(entries/hoff->GetEntries());
     972                hoff->Scale(entries/h->GetEntries());
     973                scale = fit.Scale(*hoff, *h);
    972974            }
    973975
    974             if (!fit.Fit(*h, hoff))
     976            if (!fit.Fit(*h, hoff, scale))
    975977                continue;
    976978
Note: See TracChangeset for help on using the changeset viewer.