Ignore:
Timestamp:
08/19/07 22:40:04 (18 years ago)
Author:
tbretz
Message:
*** empty log message ***
Location:
trunk/MagicSoft/Mars/mtools
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • TabularUnified trunk/MagicSoft/Mars/mtools/MChisqEval.cc

    r8074 r8679  
    4949const TString MChisqEval::gsDefTitle = "Evaluate a chisq";
    5050
    51 MChisqEval::MChisqEval(const char *name, const char *title) : fData0(NULL), fData1(NULL), fNameResult("MinimizationValue")
     51MChisqEval::MChisqEval(const char *name, const char *title)
     52    : fData0(NULL), fData1(NULL), fWeight(NULL), fNameResult("MinimizationValue")
    5253{
    5354    fName  = name  ? name  : gsDefName.Data();
     
    5556}
    5657
    57 MChisqEval::MChisqEval(MData *y1, const char *name, const char *title) : fData0(NULL), fData1(NULL), fNameResult("MinimizationValue")
     58MChisqEval::MChisqEval(MData *y1, const char *name, const char *title)
     59: fData0(NULL), fData1(NULL), fWeight(NULL), fNameResult("MinimizationValue")
    5860{
    5961    fName  = name  ? name  : gsDefName.Data();
     
    6264}
    6365
    64 MChisqEval::MChisqEval(MData *y1, MData *y2, const char *name, const char *title) : fData0(NULL), fData1(NULL), fNameResult("MinimizationValue")
     66MChisqEval::MChisqEval(MData *y1, MData *y2, const char *name, const char *title)
     67: fData0(NULL), fData1(NULL), fWeight(NULL), fNameResult("MinimizationValue")
    6568{
    6669    fName  = name  ? name  : gsDefName.Data();
     
    112115{
    113116    fChisq = 0;
     117    fSumW  = 0;
    114118
    115119    if (!fData0)
     
    122126        if (!fData1->PreProcess(plist))
    123127            return kFALSE;
     128
     129    if (!fNameWeight.IsNull())
     130    {
     131        fWeight = (MParameterD*)plist->FindObject(fNameWeight, "MParameterD");
     132        if (!fWeight)
     133            return kFALSE;
     134    }
    124135
    125136    fResult = (MParameterD*)plist->FindCreateObj("MParameterD", fNameResult);
     
    138149    const Double_t err = fData1 ? y1*y2 : 1;
    139150
    140     fChisq += dy*dy/err;
     151    const Double_t w   = fWeight ? fWeight->GetVal() : 1;
     152
     153    fChisq += w*dy*dy/err;
     154    fSumW  += w;
     155
    141156    return kTRUE;
    142157}
     
    145160{
    146161    if (GetNumExecutions()>0)
    147         fChisq /= GetNumExecutions();
     162        fChisq /= fSumW;
    148163
    149164    fResult->SetVal(fChisq);
  • TabularUnified trunk/MagicSoft/Mars/mtools/MChisqEval.h

    r7804 r8679  
    1515    static const TString gsDefTitle;
    1616
    17     Double_t     fChisq;  //! Evaluated chi square
    18     MParameterD *fResult; //! Storage for result
    19 
    2017    MData   *fData0; // Data Member one (monte carlo data or chisq function)
    2118    MData   *fData1; // Data Member two (measured data)
    2219
     20    MParameterD *fWeight;  //! Storage for weight
     21    MParameterD *fResult;  //! Storage for result
     22
    2323    TString fNameResult;
     24    TString fNameWeight;
     25
     26    Double_t     fChisq;   //! Evaluated chi square
     27    Double_t     fSumW;    //! Sum of weights
    2428
    2529    void StreamPrimitive(ostream &out) const;
     
    4347
    4448    void SetOwner(Bool_t o=kTRUE) { o ? SetBit(kIsOwner) : ResetBit(kIsOwner); }
     49    void SetNameWeight(TString w="MWeight") { fNameWeight=w; }
    4550
    4651    Double_t GetChisq() const { return fChisq; }
Note: See TracChangeset for help on using the changeset viewer.