#include #include #include "MParList.h" #include "MTaskList.h" #include "MEvtLoop.h" #include "MReadTree.h" #include "MHMatrix.h" #include "MChisqEval.h" #include "MMatrixLoop.h" #include "MDataMember.h" #include "MDataElement.h" #include "MEnergyEstParam.h" // -------------------------------------------------------------------------- void fcn(Int_t &npar, Double_t *gin, Double_t &f, Double_t *par, Int_t iflag) { MEvtLoop &evtloop = *(MEvtLoop*)gMinuit->GetObjectFit(); MTaskList &tlist = *(MTaskList*)evtloop.GetParList()->FindObject("MTaskList"); //GetTaskList(); MChisqEval &eval = *(MChisqEval*) tlist.FindObject("MChisqEval"); MEnergyEstParam &eest = *(MEnergyEstParam*)tlist.FindObject("MEnergyEstParam"); eest.SetCoeff(TArrayD(eest.GetNumCoeff(), par)); evtloop.Eventloop(); f = eval.GetChisq(); } // -------------------------------------------------------------------------- void estfit(Bool_t evalenergy=kFALSE) { // // Fill events into a MHMatrix // MParList parlist; MHMatrix matrix; Int_t col = matrix.AddColumn(evalenergy?"MMcEvt.fEnergy":"MMcEvt.fImpact"); MEnergyEstParam eest("Hillas"); eest.Add("HillasSrc"); eest.InitMapping(&matrix); MReadTree read("Events", "~/ct1/MC_ON2.root"); read.DisableAutoScheme(); if (!matrix.Fill(&parlist, &read)) return; // // Setup the tasklist used to evaluate the needed chisq // MTaskList tasklist; parlist.AddToList(&tasklist); MMatrixLoop loop(&matrix); MChisqEval eval; eval.SetY1(new MDataElement(&matrix, col)); eval.SetY2(new MDataMember(evalenergy ? "MEnergyEst.fEnergy" : "MEnergyEst.fImpact")); eval.SetOwner(); tasklist.AddToList(&loop); tasklist.AddToList(&eest); tasklist.AddToList(&eval); MEvtLoop evtloop; evtloop.SetParList(&parlist); // // Be carefull: This is not thread safe // TMinuit minuit(12); minuit.SetPrintLevel(-1); minuit.SetFCN(fcn); // Ready for: minuit.mnexcm("SET ERR", arglist, 1, ierflg) if (minuit.SetErrorDef(1)) { cout << "SetErrorDef failed." << endl; return; } // // Set initial values // TArrayD fA(5); fA[0] = -3907.74; //4916.4; //-2414.75; fA[1] = 1162.3; //149.549; // 1134.28; fA[2] = 199.351; //-558.209; // 132.932; fA[3] = 0.403192; //0.270725; //0.292845; fA[4] = 121.921; //107.001; // 107.001; TArrayD fB(7); fB[0] = -100; fB[1] = 10; fB[2] = 0.1; fB[3] = 10; fB[4] = -1; fB[5] = -0.1; fB[6] = -0.1; // Set starting values and step sizes for parameters for (Int_t i=0; i