Double_t getBestFitShift(TTree *dataTree, TTree *mcTree, TCut dataCandidateCut, TCut sidebandCut, TCut mcSignalCut, Double_t backgroundShift, Double_t purityBinVal) { dtree_ = dataTree; mtree_ = mcTree; dCut_ = dataCandidateCut; sCut_ = sidebandCut; mCut_ = mcSignalCut; bkg_shift_ = backgroundShift; purityBinVal_ = purityBinVal; // ROOT::Minuit2::Minuit2Minimizer min ( ROOT::Minuit2::kMigrad ); // min.SetMaxFunctionCalls(1000000); // min.SetMaxIterations(100000); // min.SetTolerance(0.00001); // ROOT::Math::Functor f(&minimizerPurity,1); // double step = 0.00001; // double variable = 0; // min.SetFunction(f); // // Set the free variables to be minimized! // //min.SetLimitedVariable(0,"sigShift",variable, step,-0.0005,0.0005); // min.SetVariable(0,"sigShift",variable, step); // min.Minimize(); ROOT::Math::Functor1D func(&minimizerPurity); ROOT::Math::BrentMinimizer1D bm; bm.SetFunction(func, -0.0005,0.0005); bm.Minimize(10); //cout << "f(" << bm.XMinimum() << ") = " <<bm.FValMinimum() << endl; //return min.X()[0]; return bm.XMinimum(); }
void optimizenorm(size_t i, const std::string& path) { if (v_graphs.size()==1) { double *py = v_graphs[0]->GetY(); int npts = v_graphs[0]->GetN(); double norm = 1./py[0]; // cout << npts << endl; for (int j=0; j<npts; j++) py[j] = norm*py[j]; } else if (v_graphs.size() > 1) { ROOT::Math::Functor1D func(& mydistance); ROOT::Math::BrentMinimizer1D bm; bm.SetFunction(func, 1,7000); // "x" is the norm (denom) scale factor bm.Minimize(100,0.01,0.01); cout << path << ": best norm scale " << bm.XMinimum() << ", gives distance " << bm.FValMinimum() << endl; double *py = v_graphs[i]->GetY(); for (int j=0; j<v_graphs[0]->GetN(); j++) py[j] /= bm.XMinimum(); } } // optimizenorm