Ignore:
Timestamp:
06/13/05 10:20:58 (19 years ago)
Author:
tbretz
Message:
*** empty log message ***
Location:
trunk/MagicSoft/Mars/mhflux
Files:
5 edited

Legend:

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

    r7142 r7151  
    135135
    136136    for (int i=5; i<fFunc->GetNpar(); i++)
    137         fFunc->ReleaseParameter(i);
     137        if (fFitBackground)
     138            fFunc->ReleaseParameter(i);
     139        else
     140            fFunc->SetParameter(i, 0);
    138141
    139142    // options : N  do not store the function, do not draw
     
    142145    //           Q  quiet mode
    143146    //           E  Perform better Errors estimation using Minos technique
    144     h.Fit(fFunc, "NQI", "", bgmin, bgmax);
    145 
    146     fChiSqBg = fFunc->GetChisquare()/fFunc->GetNDF();
     147    if (fFitBackground)
     148    {
     149        h.Fit(fFunc, "NQI", "", bgmin, bgmax);
     150        fChiSqBg = fFunc->GetChisquare()/fFunc->GetNDF();
     151    }
     152
    147153
    148154    // ------------------------------------
    149     if (paint)
     155    if (paint && fFitBackground)
    150156    {
    151157        fFunc->SetRange(0, 90);
     
    209215    fSignificance     = MMath::SignificanceLiMaSigned(fEventsSignal, fEventsBackground);
    210216
     217    if (TMath::IsNaN(fSignificance))
     218        fSignificance=0;
     219
    211220    if (fEventsExcess<0)
    212221        fEventsExcess=0;
     
    240249    fSignificance     = MMath::SignificanceLiMaSigned(fEventsSignal, fEventsBackground/alpha, alpha);
    241250
     251    if (TMath::IsNaN(fSignificance))
     252        fSignificance=0;
    242253    if (fEventsExcess<0)
    243254        fEventsExcess=0;
    244 /*
    245     TF1 func("", "gaus(0)+pol0(3)", 0., 90.);
    246 
    247     const Double_t A  = fEventsSignal/bin;
    248     const Double_t dA = TMath::Abs(A);
    249     func.SetParLimits(0, -dA*4, dA*4);
    250     func.SetParLimits(2, 0, 90);
    251     func.SetParLimits(3, -dA, dA);
    252 
    253     func.SetParameter(0, A);
    254     func.FixParameter(1, 0);
    255     func.SetParameter(2, fSigMax*0.75);
    256     func.SetParameter(3, 0);
    257 
    258     // options : N  do not store the function, do not draw
    259     //           I  use integral of function in bin rather than value at bin center
    260     //           R  use the range specified in the function range
    261     //           Q  quiet mode
    262     //           E  Perform better Errors estimation using Minos technique
    263     TH1D h(hon);
    264     h.Add(&hof, -1);
    265     h.Fit(&func, "NQI", "", 0, 90);
    266 
    267     fChiSqSignal = func.GetChisquare()/func.GetNDF();
    268 
    269     const Int_t bin1 = h.GetXaxis()->FindFixBin(func.GetParameter(2)*2);
    270 
    271     fChiSqBg = 0;
    272     for (int i=bin1; i<=h.GetNbinsX(); i++)
    273     {
    274         const Float_t val = h.GetBinContent(i);
    275         fChiSqBg = val*val;
    276     }
    277     if (fChiSqBg>0)
    278         fChiSqBg /= h.GetNbinsX()+1-bin1;
    279 
    280     fCoefficients.Set(func.GetNpar(), func.GetParameters());
    281 
    282     // ------------------------------------
    283     if (paint)
    284     {
    285         func.SetLineColor(kBlue);
    286         func.SetLineWidth(2);
    287         func.Paint("same");
    288     }
    289     // ------------------------------------
    290   */
     255
    291256    return kTRUE;
    292257}
     
    323288    f.fScaleMax     = fScaleMax;
    324289    f.fPolynomOrder = fPolynomOrder;
     290    f.fFitBackground= fFitBackground;
     291    f.fSignalFunc   = fSignalFunc;
    325292    f.fScaleMode    = fScaleMode;
    326293    f.fScaleUser    = fScaleUser;
     
    350317{
    351318    *fLog << GetDescriptor() << ": Fitting..." << endl;
    352     *fLog << " ...background from " << fBgMin << " to " << fBgMax << endl;
    353319    *fLog << " ...signal to " << fSigMax << " (integrate into bin at " << fSigInt << ")" << endl;
    354     *fLog << " ...polynom order " << fPolynomOrder << endl;
    355     *fLog << " ...scale mode: ";
    356     switch (fScaleMode)
    357     {
    358     case kNone:        *fLog << "none.";         break;
    359     case kEntries:     *fLog << "entries.";      break;
    360     case kIntegral:    *fLog << "integral.";     break;
    361     case kOffRegion:   *fLog << "off region (integral between " << fScaleMin << " and " << fScaleMax << ")"; break;
    362     case kBackground:  *fLog << "background (integral between " << fBgMin    << " and " << fBgMax    << ")"; break;
    363     case kLeastSquare: *fLog << "least square (N/A)"; break;
    364     case kUserScale:   *fLog << "user def (" << fScaleUser << ")"; break;
     320    *fLog << " ...signal function: ";
     321    switch (fSignalFunc)
     322    {
     323    case kGauss:       *fLog << "gauss(x)";        break;
     324    case kThetaSq:     *fLog << "gauss(sqrt(x))";  break;
    365325    }
    366326    *fLog << endl;
     327    if (!fFitBackground)
     328        *fLog << " ...no background." << endl;
     329    else
     330    {
     331        *fLog << " ...background from " << fBgMin << " to " << fBgMax << endl;
     332        *fLog << " ...polynom order " << fPolynomOrder << endl;
     333        *fLog << " ...scale mode: ";
     334        switch (fScaleMode)
     335        {
     336        case kNone:        *fLog << "none.";         break;
     337        case kEntries:     *fLog << "entries.";      break;
     338        case kIntegral:    *fLog << "integral.";     break;
     339        case kOffRegion:   *fLog << "off region (integral between " << fScaleMin << " and " << fScaleMax << ")"; break;
     340        case kBackground:  *fLog << "background (integral between " << fBgMin    << " and " << fBgMax    << ")"; break;
     341        case kLeastSquare: *fLog << "least square (N/A)"; break;
     342        case kUserScale:   *fLog << "user def (" << fScaleUser << ")"; break;
     343        }
     344        *fLog << endl;
     345    }
    367346
    368347    if (TString(o).Contains("result"))
     
    402381}
    403382
     383Bool_t MAlphaFitter::FitTime(const TH3D &hon, UInt_t bin, Bool_t paint)
     384{
     385    const TString name(Form("TempAlphaTime%06d", gRandom->Integer(1000000)));
     386
     387    hon.GetZaxis()->SetRange(bin,bin);
     388    TH1D *h = (TH1D*)hon.Project3D("ye");
     389    hon.GetZaxis()->SetRange(-1,9999);
     390
     391    h->SetDirectory(0);
     392
     393    const Bool_t rc = Fit(*h, paint);
     394    delete h;
     395    return rc;
     396}
     397
    404398Bool_t MAlphaFitter::FitAlpha(const TH3D &hon, Bool_t paint)
    405399{
     
    448442    return rc;
    449443}
    450 
     444/*
     445Bool_t MAlphaFitter::FitTime(const TH3D &hon, const TH3D &hof, UInt_t bin, Bool_t paint)
     446{
     447    const TString name1(Form("TempAlphaTime%06d_on",  gRandom->Integer(1000000)));
     448    const TString name0(Form("TempAlphaTime%06d_off", gRandom->Integer(1000000)));
     449
     450    hon.GetZaxis()->SetRange(bin,bin);
     451    TH1D *h1 = (TH1D*)hon.Project3D("ye");
     452    hon.GetZaxis()->SetRange(-1,9999);
     453    h1->SetDirectory(0);
     454
     455    hof.GetZaxis()->SetRange(bin,bin);
     456    TH1D *h0 = (TH1D*)hof.Project3D("ye");
     457    hof.GetZaxis()->SetRange(-1,9999);
     458    h0->SetDirectory(0);
     459
     460    const Bool_t rc = ScaleAndFit(*h1, h0, paint);
     461
     462    delete h0;
     463    delete h1;
     464
     465    return rc;
     466}
     467*/
    451468Bool_t MAlphaFitter::FitAlpha(const TH3D &hon, const TH3D &hof, Bool_t paint)
    452469{
     
    541558    case kExcess:
    542559        return -GetEventsExcess();
     560    case kGaussSigma:
     561        return GetGausSigma();
    543562    }
    544563    return 0;
     
    601620        if (txt==(TString)"excess")
    602621            fStrategy = kExcess;
     622        if (txt==(TString)"gausssigma" || txt==(TString)"gaussigma")
     623            fStrategy = kGaussSigma;
    603624        rc = kTRUE;
    604625    }
     
    625646        rc = kTRUE;
    626647    }
     648    if (IsEnvDefined(env, prefix, "Signalfunction", print))
     649    {
     650        TString txt = GetEnvValue(env, prefix, "SignalFunction", "");
     651        txt = txt.Strip(TString::kBoth);
     652        txt.ToLower();
     653        if (txt==(TString)"gauss" || txt==(TString)"gaus")
     654            SetSignalFunction(kGauss);
     655        if (txt==(TString)"thetasq")
     656            SetSignalFunction(kThetaSq);
     657        rc = kTRUE;
     658    }
    627659    if (IsEnvDefined(env, prefix, "Scale", print))
    628660    {
  • trunk/MagicSoft/Mars/mhflux/MAlphaFitter.h

    r7066 r7151  
    3434        kSignificanceLogExcess,
    3535        kSignificanceExcess,
    36         kExcess
     36        kExcess,
     37        kGaussSigma
    3738    };
     39    enum SignalFunc_t {
     40        kGauss, kThetaSq
     41    };
     42
    3843private:
    39     Float_t fSigInt;
    40     Float_t fSigMax;
    41     Float_t fBgMin;
    42     Float_t fBgMax;
    43     Float_t fScaleMin;
    44     Float_t fScaleMax;
    45     Int_t   fPolynomOrder;
    46 
    47     Double_t fSignificance;
    48     Double_t fEventsExcess;
    49     Double_t fEventsSignal;
    50     Double_t fEventsBackground; // fScaleFactor already applied
    51 
    52     Double_t fChiSqSignal;
    53     Double_t fChiSqBg;
    54     Double_t fIntegralMax;
    55     Double_t fScaleFactor;  // Scale factor for off-data
    56 
    57     TArrayD fCoefficients;
    58 
    59     TF1 *fFunc;
    60 
    61     ScaleMode_t fScaleMode;
    62     Double_t fScaleUser;
    63 
    64     Strategy_t fStrategy;
     44    // Fitting Setup
     45    Float_t fSigInt;            // minimum of range to fit the signal
     46    Float_t fSigMax;            // maximum of range to fit the signal
     47    Float_t fBgMin;             // minimum of range to fit the background
     48    Float_t fBgMax;             // minimum of range to fit the background
     49    Float_t fScaleMin;          // minimum of range to determin the scale factor of the background
     50    Float_t fScaleMax;          // maximum of range to determin the scale factor of the background
     51    Int_t   fPolynomOrder;      // order of polyom to be fitted to the background
     52    Bool_t  fFitBackground;     // Backround fit: yes/no
     53    SignalFunc_t fSignalFunc;  // Type of signal function
     54    // Result
     55    Double_t fSignificance;     // significance of signal
     56    Double_t fEventsExcess;     // calculated number of excess events (signal-bg)
     57    Double_t fEventsSignal;     // calculated number of signal events
     58    Double_t fEventsBackground; // calculated number of bg events (fScaleFactor already applied)
     59
     60    Double_t fChiSqSignal;      // Reduced (chi^2/NDF) chisq of signal fit
     61    Double_t fChiSqBg;          // Reduced (chi^2/NDF) chisq of bg fit
     62    Double_t fIntegralMax;      // Calculated bin border to which it was integrated
     63    Double_t fScaleFactor;      // Scale factor for off-data
     64
     65    TArrayD fCoefficients;      // Fit result
     66
     67    // Function
     68    TF1 *fFunc;                 // fit function (gauss + polynom)
     69
     70    // Scaling setup
     71    ScaleMode_t fScaleMode;     // scaling mode
     72    Double_t    fScaleUser;     // user scale factor
     73
     74    // Minimization strategy
     75    Strategy_t fStrategy;       // How to calc minimization value
    6576
    6677public:
    6778    // Implementing the function yourself is only about 5% faster
    68     MAlphaFitter(const char *name=0, const char *title=0) : fSigInt(15), fSigMax(75), fBgMin(45), fBgMax(85), fScaleMin(40), fScaleMax(80), fPolynomOrder(2), fCoefficients(3+fPolynomOrder+1), fFunc(new TF1("", Form("gaus(0) + pol%d(3)", fPolynomOrder), 0, 90)), fScaleMode(kOffRegion), fScaleUser(1), fStrategy(kSignificance)
     79    MAlphaFitter(const char *name=0, const char *title=0) : fSigInt(15),
     80        fSigMax(75), fBgMin(45), fBgMax(85), fScaleMin(40), fScaleMax(80),
     81        fPolynomOrder(2), fFitBackground(kTRUE), fSignalFunc(kGauss),
     82        fCoefficients(3+fPolynomOrder+1),
     83        fFunc(new TF1("", Form("gaus(0) + pol%d(3)", fPolynomOrder), 0, 90)),
     84        fScaleMode(kOffRegion), fScaleUser(1), fStrategy(kSignificance)
    6985    {
    7086        fName  = name  ? name  : "MAlphaFitter";
     
    86102    }
    87103
     104    // TObject
    88105    void Clear(Option_t *o="");
    89106    void Print(Option_t *o="") const; //*MENU*
    90107    void Copy(TObject &o) const;
    91     /*
    92     TObject *Clone(const char *name) const
    93     {
    94         return new MAlphaFitter(*this);
    95     }
    96     */
    97 
     108
     109    // Setter
    98110    void SetScaleUser(Float_t scale)       { fScaleUser = scale; fScaleMode=kUserScale; }
    99111    void SetScaleMode(ScaleMode_t mode)    { fScaleMode    = mode; }
     
    105117    void SetScaleMin(Float_t s)            { fScaleMin     = s; }
    106118    void SetScaleMax(Float_t s)            { fScaleMax     = s; }
    107     void SetPolynomOrder(Int_t s)          { if (s==fPolynomOrder) return; fPolynomOrder = s; delete fFunc; fFunc=new TF1 ("", Form("gaus(0) + pol%d(3)", s));
     119    void SetPolynomOrder(Int_t s)
     120    {
     121        if (s==fPolynomOrder)
     122            return;
     123
     124        fPolynomOrder = s;
     125
     126        SetSignalFunction(fSignalFunc);
     127    }
     128    void SetSignalFunction(SignalFunc_t func)
     129    {
     130        delete fFunc;
     131        switch (func)
     132        {
     133        case kGauss:
     134            fFunc=new TF1 ("", Form("gaus(0) + pol%d(3)", fPolynomOrder));
     135            break;
     136        case kThetaSq:
     137            fFunc=new TF1 ("", Form("[0]*exp(-((sqrt(x)-[1])/[2])^2) + pol%d(3)", fPolynomOrder));
     138            break;
     139        }
     140        fSignalFunc=func;
    108141        gROOT->GetListOfFunctions()->Remove(fFunc);
    109142        fFunc->SetName("Dummy");
    110         fCoefficients.Set(3+s+1); fCoefficients.Reset(); }
    111 
     143        fCoefficients.Set(3+fPolynomOrder+1);
     144        fCoefficients.Reset();
     145    }
     146    void EnableBackgroundFit(Bool_t b=kTRUE) { fFitBackground=b; }
     147
     148    // Getter
    112149    Double_t GetSignalIntegralMax() const  { return fSigInt; }
    113150
     
    127164    Double_t GetCoefficient(Int_t i) const { return fCoefficients[i]; }
    128165    const TArrayD &GetCoefficients() const { return fCoefficients; }
    129 
    130     void PaintResult(Float_t x=0.04, Float_t y=0.94, Float_t size=0.035) const;
    131 
     166    Double_t Eval(Double_t d) const { return fFunc ? fFunc->Eval(d) : 0; }
     167
     168    // Interface to fit
    132169    Bool_t Fit(TH1D &h, Bool_t paint=kFALSE);
    133170    Bool_t Fit(const TH1D &on, const TH1D &off, Double_t alpha, Bool_t paint=kFALSE);
     
    149186    Bool_t FitEnergy(const TH3D &h, UInt_t bin, Bool_t paint=kFALSE);
    150187    Bool_t FitTheta(const TH3D &h,  UInt_t bin, Bool_t paint=kFALSE);
     188    //Bool_t FitTime(const TH3D &h,  UInt_t bin, Bool_t paint=kFALSE);
    151189
    152190    Bool_t FitAlpha(const TH3D &on, const TH3D &off, Bool_t paint=kFALSE);
    153191    Bool_t FitEnergy(const TH3D &on, const TH3D &off, UInt_t bin, Bool_t paint=kFALSE);
    154192    Bool_t FitTheta(const TH3D &on, const TH3D &off, UInt_t bin, Bool_t paint=kFALSE);
     193    //Bool_t FitTime(const TH3D &on, const TH3D &off, UInt_t bin, Bool_t paint=kFALSE);
    155194
    156195    Bool_t FitAlpha(const TH3D &on, const TH3D *off, Bool_t paint=kFALSE)
     
    165204    {
    166205        return off ? FitTheta(on, *off, bin, paint) : FitTheta(on, bin, paint);
    167     }
     206    }/*
     207    Bool_t FitTime(const TH3D &on, const TH3D *off, UInt_t bin, Bool_t paint=kFALSE)
     208    {
     209        return off ? FitTime(on, *off, bin, paint) : FitTime(on, bin, paint);
     210    }*/
    168211
    169212    Double_t Scale(TH1D &off, const TH1D &on) const;
    170213
     214    // Interface to result
     215    void PaintResult(Float_t x=0.04, Float_t y=0.94, Float_t size=0.035) const;
     216
     217    // MTask
    171218    Int_t ReadEnv(const TEnv &env, TString prefix, Bool_t print=kFALSE);
    172219
  • trunk/MagicSoft/Mars/mhflux/MHAlpha.cc

    r7142 r7151  
    292292    if (!fResult)
    293293        return kFALSE;
     294    fSigma = (MParameterD*)const_cast<MParList*>(pl)->FindCreateObj("MParameterD", "GaussSigma");
     295    if (!fSigma)
     296        return kFALSE;
    294297
    295298    //fExcess = (MParameterD*)const_cast<MParList*>(pl)->FindCreateObj("MParameterD", "MExcess");
     
    469472            size = fHillas->GetSize();
    470473        energy = fEnergy   ? fEnergy->GetVal() : (fHillas?fHillas->GetSize():1000);
    471         theta  = fPointPos ? fPointPos->GetZd()   : 0;
    472     }
    473 
    474     //if (size>0)
    475     //    alpha /= (2.4 + 1.13*(log10((energy-14)/0.37)-5)*(log10((energy-14)/0.37)-5))/15;
     474        theta  = fPointPos ? fPointPos->GetZd() : 0;
     475    }
    476476
    477477    // enhance histogram if necessary
     
    480480    // Fill histograms
    481481    fHist.Fill(theta, energy, TMath::Abs(alpha), w);
    482 
    483     // Check cuts
    484     /*
    485     if ( (fEnergyMin>=0 && energy<fEnergyMin) ||
    486          (fEnergyMax>=0 && energy>fEnergyMax) ||
    487          (fSizeMin>=0   && size  <fSizeMin)   ||
    488          (fSizeMax>=0   && size  >fSizeMin) )
    489          return kTRUE;
    490          */
    491482
    492483    if (!fSkipHistTime)
     
    851842
    852843    fResult->SetVal(fFit.GetMinimizationValue());
     844    fSigma->SetVal(fFit.GetGausSigma());
    853845
    854846    if (!fSkipHistEnergy)
  • trunk/MagicSoft/Mars/mhflux/MHAlpha.h

    r7122 r7151  
    4444
    4545    MParameterD   *fResult;     //!
     46    MParameterD   *fSigma;      //!
    4647    MParameterD   *fEnergy;     //!
    4748    MHillas       *fHillas;     //!
  • trunk/MagicSoft/Mars/mhflux/MHThetaSq.h

    r7147 r7151  
    2424
    2525    Bool_t SetupFill(const MParList *pl);
    26     void InitMapping(MHMatrix *mat, Int_t type=0);
    2726
    2827    // MParContainer
     
    3130public:
    3231    MHThetaSq(const char *name=NULL, const char *title=NULL);
     32
     33    void InitMapping(MHMatrix *mat, Int_t type=0);
    3334
    3435    void SetNumBinsSignal(UInt_t n) { fNumBinsSignal=TMath::Max(n, 1U); }
Note: See TracChangeset for help on using the changeset viewer.