Ignore:
Timestamp:
03/19/03 16:29:30 (22 years ago)
Author:
tbretz
Message:
*** empty log message ***
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/MagicSoft/Mars/macros/estfit.C

    r1633 r1840  
    1 #include <fstream.h>
     1#include <TStopwatch.h>
     2#include <TMinuit.h>
    23
    3 #include "MTask.h"
    44#include "MParList.h"
     5#include "MTaskList.h"
     6#include "MEvtLoop.h"
    57
    6 #include "MDataChain.h"
    7 
    8 class MChisqEval : public MTask
    9 {
    10 private:
    11     static const TString gsDefName;
    12     static const TString gsDefTitle;
    13 
    14     Double_t fChisq; //! Evaluated chi square
    15 
    16     MData   *fData0; // Data Member one (monte carlo data or chisq function)
    17     MData   *fData1; // Data Member two (measured data)
    18 
    19     // --------------------------------------------------------------------------
    20     //
    21     // Implementation of SavePrimitive. Used to write the call to a constructor
    22     // to a macro. In the original root implementation it is used to write
    23     // gui elements to a macro-file.
    24     //
    25     void StreamPrimitive(ofstream &out) const
    26     {
    27         out << "   MChisqEval " << GetUniqueName() << ";";
    28         if (fData0)
    29             out << "   " << GetUniqueName() << ".SetY1(\"" << fData0->GetRule() << "\");" << endl;
    30         if (fData1)
    31             out << "   " << GetUniqueName() << ".SetY1(\"" << fData1->GetRule() << "\");" << endl;
    32     }
    33 
    34     enum { kIsOwner = BIT(14) };
    35 
    36 public:
    37     MChisqEval(const char *name=NULL, const char *title=NULL) : fData0(NULL), fData1(NULL)// : fMatrix(mat), fColumn(col), fEvalE(evale)
    38     {
    39         fName  = name  ? name  : gsDefName.Data();
    40         fTitle = title ? title : gsDefTitle.Data();
    41     }
    42 
    43     MChisqEval(MData *y1, const char *name=NULL, const char *title=NULL) : fData0(NULL), fData1(NULL)// : fMatrix(mat), fColumn(col), fEvalE(evale)
    44     {
    45         fName  = name  ? name  : gsDefName.Data();
    46         fTitle = title ? title : gsDefTitle.Data();
    47         SetY1(y1);
    48     }
    49     MChisqEval(MData *y1, MData *y2, const char *name=NULL, const char *title=NULL) : fData0(NULL), fData1(NULL)// : fMatrix(mat), fColumn(col), fEvalE(evale)
    50     {
    51         fName  = name  ? name  : gsDefName.Data();
    52         fTitle = title ? title : gsDefTitle.Data();
    53         SetY1(y1);
    54         SetY2(y2);
    55     }
    56     ~MChisqEval()
    57     {
    58         if (fData0 && (fData0->TestBit(kCanDelete) || TestBit(kIsOwner)))
    59             delete fData0;
    60 
    61         if (fData1 && (fData1->TestBit(kCanDelete) || TestBit(kIsOwner)))
    62             delete fData1;
    63     }
    64 
    65     void SetY1(MData *data)
    66     {
    67         // Set MC value
    68         if (fData0 && (fData0->TestBit(kCanDelete) || TestBit(kIsOwner)))
    69             delete fData0;
    70         fData0 = data;
    71         fData0->SetBit(kCanDelete);
    72         AddToBranchList(fData0->GetDataMember());
    73     }
    74     void SetY2(MData *data)
    75     {
    76         // Set measured/estimated value
    77         if (fData1 && (fData1->TestBit(kCanDelete) || TestBit(kIsOwner)))
    78             delete fData1;
    79         fData1 = data;
    80         fData1->SetBit(kCanDelete);
    81         AddToBranchList(fData1->GetDataMember());
    82     }
    83     void SetY1(const TString data) { SetY1(new MDataChain(data)); }
    84     void SetY2(const TString data) { SetY2(new MDataChain(data)); }
    85 
    86     void SetOwner(Bool_t o=kTRUE) { o ? SetBit(kIsOwner) : ResetBit(kIsOwner); }
    87 
    88     Bool_t PreProcess(MParList *plist)
    89     {
    90         fChisq = 0;
    91 
    92         if (!fData0)
    93             return kFALSE;
    94 
    95         if (!fData0->PreProcess(plist))
    96             return kFALSE;
    97 
    98         if (fData1)
    99             if (!fData1->PreProcess(plist))
    100                 return kFALSE;
    101 
    102         return kTRUE;
    103     }
    104 
    105     Bool_t Process()
    106     {
    107         const Double_t y1 = fData0->GetValue();
    108         const Double_t y2 = fData1 ? fData1->GetValue() : 0;
    109 
    110         const Double_t dy  = y2-y1;
    111         const Double_t err = fData1 ? y1*y1 : 1;
    112 
    113         fChisq += dy*dy/err;
    114         return kTRUE;
    115     }
    116 
    117     Bool_t PostProcess()
    118     {
    119         fChisq /= GetNumExecutions();
    120         return kTRUE;
    121     }
    122 
    123     Double_t GetChisq() const { return fChisq; }
    124  
    125     ClassDef(MChisqEval, 0)
    126 };
    127 
    128 ClassImp(MChisqEval);
    129 
    130 const TString MChisqEval::gsDefName  = "MChisqEval";
    131 const TString MChisqEval::gsDefTitle = "Evaluate a chisq";
     8#include "MReadTree.h"
     9#include "MHMatrix.h"
     10#include "MChisqEval.h"
     11#include "MMatrixLoop.h"
     12#include "MDataMember.h"
     13#include "MDataElement.h"
     14#include "MEnergyEstParam.h"
    13215
    13316// --------------------------------------------------------------------------
    134 
    135 #include <TMinuit.h>
    136 
    137 #include "MEvtLoop.h"
    138 #include "MTaskList.h"
    139 #include "MEnergyEstParam.h"
    14017
    14118void fcn(Int_t &npar, Double_t *gin, Double_t &f, Double_t *par, Int_t iflag)
     
    15633
    15734// --------------------------------------------------------------------------
    158 #include <TStopwatch.h>
    159 
    160 #include "MHMatrix.h"
    161 #include "MEnergyEst.h"
    162 
    163 #include "MDataMember.h"
    164 #include "MDataElement.h"
    165 
    166 #include "MReadTree.h"
    167 #include "MMatrixLoop.h"
    16835
    16936void estfit(Bool_t evalenergy=kFALSE)
     
    17744    Int_t col = matrix.AddColumn(evalenergy?"MMcEvt.fEnergy":"MMcEvt.fImpact");
    17845
    179     MEnergyEstParam eest;
    180     eest.Add("MHillasSrc");
     46    MEnergyEstParam eest("Hillas");
     47    eest.Add("HillasSrc");
    18148    eest.InitMapping(&matrix);
    18249
    183     MReadTree read("Events", "gammas.root");
     50    MReadTree read("Events", "~/ct1/MC_ON2.root");
    18451    read.DisableAutoScheme();
    18552
     
    21178    //
    21279    TMinuit minuit(12);
     80    minuit.SetPrintLevel(-1);
    21381    minuit.SetFCN(fcn);
    21482
     
    22492    //
    22593    TArrayD fA(5);
    226     fA[0] =  -2539; // [cm]
    227     fA[1] =    900; // [cm]
    228     fA[2] =   17.5; // [cm]
    229     fA[3] =  1;//    4;
    230     fA[4] =   58.3;
     94    fA[0] = -3907.74; //4916.4;    //-2414.75;
     95    fA[1] = 1162.3;   //149.549;   // 1134.28;
     96    fA[2] = 199.351;  //-558.209;  // 132.932;
     97    fA[3] = 0.403192; //0.270725;  //0.292845;
     98    fA[4] = 121.921;  //107.001;   // 107.001;
    23199
    232100    TArrayD fB(7);
    233     fB[0] =    -8.64; // [GeV]
    234     fB[1] =   -0.069; // [GeV]
    235     fB[2] =  0.00066; // [GeV]
    236     fB[3] =    0.033; // [GeV]
    237     fB[4] = 0.000226; // [GeV]
    238     fB[5] =  4.14e-8; // [GeV]
    239     fB[6] =    -0.06;
     101    fB[0] = -100;
     102    fB[1] = 10;
     103    fB[2] = 0.1;
     104    fB[3] = 10;
     105    fB[4] = -1;
     106    fB[5] = -0.1;
     107    fB[6] = -0.1;
    240108
    241109    // Set starting values and step sizes for parameters
Note: See TracChangeset for help on using the changeset viewer.