2 #include "TFitResultPtr.h" 3 #include "TFitResult.h" 24 fGuessParams.resize(0);
26 fLooseGuessParams.resize(0);
27 fLooseGuesses.resize(0);
32 fParamHighs.resize(0);
33 fLooseParams.resize(0);
34 fLooseParamLows.resize(0);
35 fLooseParamHighs.resize(0);
110 for (UInt_t iParam = 0; iParam !=
fParamFrom.size(); ++iParam) {
114 fitFunc->SetParameter(
fParamTo[iParam], value);
122 TF1**& fitHolder, TMatrixDSym**& covHolder)
126 fitHolder =
new TF1*[1];
127 covHolder =
new TMatrixDSym*[1];
128 TCanvas *tempCanvas =
new TCanvas();
133 MapTo(fitFunc,looseFunc);
137 TFitResultPtr fitResult = histToFit->Fit(fitFunc,
fFitOptions +
"S");
139 fitHolder[0] = (TF2*) fitFunc->Clone();
140 covHolder[0] =
new TMatrixDSym(fitFunc->GetNpar());
141 *covHolder[0] = fitResult->GetCovarianceMatrix();
151 tempCanvas->SaveAs(dumpName+
".C");
153 tempCanvas->SaveAs(dumpName+
".png");
155 tempCanvas->SaveAs(dumpName+
".pdf");
164 Int_t NumYBins, Double_t MinY, Double_t MaxY)
173 std::cerr <<
"You haven't set a function!" << std::endl;
179 std::cerr <<
"You haven't initialized an x expression yet!" << std::endl;
193 std::cerr <<
"Nothing has been initialized in resolution plot." << std::endl;
203 TProfile *tempProfile;
205 TF1 *looseFunc = NULL;
210 looseFunc->SetLineColor(kGreen);
217 for (UInt_t iParam = 0; iParam !=
fLooseParams.size(); ++iParam)
221 fitFunc->SetLineColor(kBlue);
223 for (UInt_t iGuess = 0; iGuess !=
fGuessParams.size(); ++iGuess)
226 for (UInt_t iParam = 0; iParam !=
fParams.size(); ++iParam)
230 TMatrixDSym **holdCovs;
232 for (UInt_t iPlot = 0; iPlot < NumPlots; iPlot++) {
234 std::cout << NumPlots - iPlot <<
" more to go." << std::endl;
248 tempHist =
new TH2D(tempName, tempName, NumXBins, XBins, NumYBins, MinY, MaxY);
251 TString drawCommand = inExpr +
":" +
fInExprX +
">>" + tempName;
253 Message(
eDebug,
"About to use tree at %p to draw %s with cut %s",
254 inTree, drawCommand.Data(), inCut.GetTitle());
256 inTree->Draw(drawCommand, inCut);
257 Message(
eDebug,
"Histogram has %f events", tempHist, tempHist->Integral());
259 TString dumpTitle =
fLegendEntries[iPlot] +
";" + inExpr +
";Num Events";
264 fitFunc->SetTitle(dumpTitle);
267 DoFit(fitFunc, looseFunc, tempHist, holdFits, holdCovs);
269 fFits.push_back(holdFits);
270 fCovs.push_back(holdCovs);
280 Int_t NumYBins, Double_t MinY, Double_t MaxY)
283 Double_t XBins[NumXBins+1];
285 DoFits(NumXBins, XBins, NumYBins, MinY, MaxY);
296 std::vector<TF1*> theFuncs;
298 for (UInt_t iLine = 0; iLine !=
fFits.size(); ++iLine) {
300 tempFunc =
new TF1(
"parameterHolder", ParameterExpr, MinX, MaxX);
302 for (Int_t iParam = 0; iParam != tempFunc->GetNpar(); ++iParam) {
304 Int_t parNumInFit =
fFits[iLine][0]->GetParNumber(tempFunc->GetParName(iParam));
305 tempFunc->SetParameter(iParam,
fFits[iLine][0]->GetParameter(parNumInFit));
306 tempFunc->SetParError(iParam,
fFits[iLine][0]->GetParError(parNumInFit));
310 theFuncs.push_back(tempFunc);
319 std::vector<TGraphErrors*>
327 fFits[0][0]->GetRange(MinX, MaxX);
329 std::vector<TF1*> theFuncs =
MakeFuncs(ParameterExpr, MinX, MaxX);
330 std::vector<TGraphErrors*> theGraphs;
331 TGraphErrors* tempGraph;
335 for (UInt_t iFunc = 0; iFunc != theFuncs.size(); ++iFunc) {
337 std::vector<TF1*> holdFuncs;
339 for (Int_t iParam = 0; iParam != theFuncs[iFunc]->GetNpar(); ++iParam) {
341 TString parToReplace = TString(
'[') + theFuncs[iFunc]->GetParName(iParam) + TString(
']');
342 TF1* holdFunc =
new TF1(
"holding",theFuncs[iFunc]->GetExpFormula().ReplaceAll(
'x',
"[x0]").ReplaceAll(parToReplace,
'x'));
344 for (Int_t jParam = 0; jParam != holdFunc->GetNpar(); ++jParam) {
346 TString paramName = holdFunc->GetParName(jParam);
348 if (paramName ==
"x0")
351 holdFunc->SetParameter(jParam,theFuncs[iFunc]->GetParameter(paramName));
355 holdFuncs.push_back(holdFunc);
360 Double_t xVal = MinX;
362 for (Int_t iPoint = 0; iPoint !=
fNumPoints + 1; ++iPoint) {
364 tempGraph->SetPoint(iPoint,xVal,theFuncs[iFunc]->Eval(xVal));
367 for (Int_t iParam = 0; iParam != theFuncs[iFunc]->GetNpar(); ++iParam) {
369 holdFuncs[iParam]->SetParameter(
"x0",xVal);
371 for (Int_t jParam = 0; jParam != iParam + 1; ++jParam) {
373 Double_t factor = 2.0;
375 if (iParam == jParam)
378 Double_t toAdd = holdFuncs[iParam]->Derivative(theFuncs[iFunc]->GetParameter(iParam)) * ((*(
fCovs[iFunc][0]))(iParam, jParam));
379 error2 += toAdd*toAdd;
385 tempGraph->SetPointError(iPoint,0,TMath::Sqrt(error2));
390 theGraphs.push_back(tempGraph);
392 for (UInt_t iParam = 0; iParam != holdFuncs.size(); ++iParam)
393 delete holdFuncs[iParam];
397 for (UInt_t iFunc = 0; iFunc != theFuncs.size(); ++iFunc)
398 delete theFuncs[iFunc];
406 Plot2D::MakeCanvas(TString FileBase, std::vector<TGraphErrors*> theGraphs, TString XLabel, TString YLabel,
407 Double_t YMin, Double_t YMax, Bool_t logY)
410 for (UInt_t iGraph = 0; iGraph != theGraphs.size(); ++iGraph)
411 theGraphs[iGraph]->GetYaxis()->SetRangeUser(YMin, YMax);
413 BaseCanvas(FileBase, theGraphs, XLabel, YLabel, logY);
420 Double_t YMin, Double_t YMax, Bool_t logY)
423 std::vector<TGraphErrors*> theGraphs =
MakeGraphs(ParameterExpr);
424 MakeCanvas(FileBase, theGraphs, XLabel, YLabel, YMin, YMax, logY);
426 for (UInt_t iGraph = 0; iGraph != theGraphs.size(); ++iGraph)
427 delete theGraphs[iGraph];
434 Double_t YMin, Double_t YMax, Bool_t logY)
437 TString ParameterExpr =
"";
438 ParameterExpr.Form(
"[%d]", ParameterNum);
439 MakeCanvas(FileBase, ParameterExpr, XLabel, YLabel, YMin, YMax, logY);