36 Double_t trueP2 = 1. - trueP0 - trueP1;
39 TF1 f0(
"f0",
"[0]*(1-cos(x))/TMath::Pi()", 0.,
TMath::Pi());
40 f0.SetParameter(0, 1.);
45 TF1 f1(
"f1",
"[0]*(1-cos(x)*cos(x))*2./TMath::Pi()", 0.,
TMath::Pi());
46 f1.SetParameter(0, 1.);
51 TF1 f2(
"f2",
"[0]*(1+cos(x))/TMath::Pi()", 0.,
TMath::Pi());
52 f2.SetParameter(0, 1.);
59 data.SetMarkerStyle(20);
60 data.SetMarkerSize(.7);
63 htruemc0.SetLineColor(2);
65 htruemc1.SetLineColor(3);
67 htruemc2.SetLineColor(4);
69 for (
Int_t i = 0; i < Ndata; i++) {
74 }
else if (p < trueP0 + trueP1) {
85 TH1F mc0(
"mc0",
"MC sample 0 angle distribution", nBins, 0,
TMath::Pi());
88 mc0.SetMarkerColor(2);
89 mc0.SetMarkerStyle(24);
90 mc0.SetMarkerSize(.7);
91 for (
Int_t i = 0; i < N0; i++) {
92 mc0.Fill(f0.GetRandom());
95 TH1F mc1(
"mc1",
"MC sample 1 angle distribution", nBins, 0,
TMath::Pi());
98 mc1.SetMarkerColor(3);
99 mc1.SetMarkerStyle(24);
100 mc1.SetMarkerSize(.7);
101 for (
Int_t i = 0; i < N1; i++) {
102 mc1.Fill(
f1.GetRandom());
105 TH1F mc2(
"mc2",
"MC sample 2 angle distribution", nBins, 0,
TMath::Pi());
108 mc2.SetMarkerColor(4);
109 mc2.SetMarkerStyle(24);
110 mc2.SetMarkerSize(.7);
111 for (
Int_t i = 0; i < N2; i++) {
112 mc2.Fill(f2.GetRandom());
121 fit.Constrain(0, 0.0, 1.0);
122 fit.Constrain(1, 0.0, 1.0);
123 fit.Constrain(2, 0.0, 1.0);
125 Int_t status = fit.Fit();
126 std::cout <<
"Status: " << status << std::endl;
130 TCanvas c(
"c",
"FractionFitter example", 700, 700);
135 f0.GetHistogram()->SetTitle(
"Original MC distributions");
136 f1.DrawClone(
"same");
137 f2.DrawClone(
"same");
140 data.SetTitle(
"Data distribution with true contributions");
141 data.DrawClone(
"EP");
142 htruemc0.Draw(
"same");
143 htruemc1.Draw(
"same");
144 htruemc2.Draw(
"same");
147 mc0.SetTitle(
"MC generated samples with fit predictions");
152 auto mcp0 = (
TH1F *)fit.GetMCPrediction(0);
153 mcp0->SetLineColor(2);
155 auto mcp1 = (
TH1F *)fit.GetMCPrediction(1);
156 mcp1->SetLineColor(3);
158 auto mcp2 = (
TH1F *)fit.GetMCPrediction(2);
159 mcp2->SetLineColor(4);
164 Double_t p0, p1, p2, errP0, errP1, errP2;
169 auto result = (
TH1F *)fit.GetPlot();
170 fit.GetResult(0, p0, errP0);
171 printf(
" Parameter %d: true %.3f, estim. %.3f +/- %.3f\n", 0, trueP0, p0, errP0);
172 fit.GetResult(1, p1, errP1);
173 printf(
" Parameter %d: true %.3f, estim. %.3f +/- %.3f\n", 1, trueP1, p1, errP1);
174 fit.GetResult(2, p2, errP2);
175 printf(
" Parameter %d: true %.3f, estim. %.3f +/- %.3f\n", 2, trueP2, p2, errP2);
176 data.SetTitle(
"Data distribution with fitted contributions");
177 data.DrawClone(
"Ep");
178 result->Draw(
"same");
179 f0.SetParameter(0, Ndata * p0 / int0 * data.GetBinWidth(1));
181 f0.DrawClone(
"same");
182 f1.SetParameter(0, Ndata * p1 / int1 * data.GetBinWidth(1));
184 f1.DrawClone(
"same");
185 f2.SetParameter(0, Ndata * p2 / int2 * data.GetBinWidth(1));
187 f2.DrawClone(
"same");
188 sprintf(
text,
"%d: true %.2f, estimated %.2f +/- %.2f\n", 0, trueP0, p0, errP0);
189 l.DrawTextNDC(.45, .30,
text);
190 sprintf(
text,
"%d: true %.2f, estimated %.2f +/- %.2f\n", 1, trueP1, p1, errP1);
191 l.DrawTextNDC(.45, .25,
text);
192 sprintf(
text,
"%d: true %.2f, estimated %.2f +/- %.2f\n", 2, trueP2, p2, errP2);
193 l.DrawTextNDC(.45, .20,
text);
196 auto cnew =
c.DrawClone();
int Int_t
Signed integer 4 bytes (int).
char Char_t
Character 1 byte (char).
double Double_t
Double 8 bytes.
Fits MC fractions to data histogram.
1-D histogram with a float per channel (see TH1 documentation)