193     double sum1 = x1, sum2 = x2;
   194     double value1 = x1, value2 = x2;
   196     for(
int i = 1; i < 100; i++) {
   197         value1 = value1 * x1 * x1 / (2 * i + 1);
   199         value2 = value2 * x2 * x2 / (2 * i + 1);
   203     return sum2 * exp(-(x2 * x2) / 2) - sum1 * exp(-(x1 * x1) / 2);
   211     double fsig = sigratio * exp(-t * t / 2.) / 
intGaus;
   213     return fsig / (fsig + fbkg);
   223     for(
int i = 1; i <= dat->GetNbinsX(); ++i) {
   224         integral += dat->GetBinContent(i);
   227     integral = 1.0 / integral;
   229     for(
int i = 1; i <= dat->GetNbinsX(); ++i) {
   230         dat->SetBinContent(i, integral * dat->GetBinContent(i));
   231         dat->SetBinError(i, integral * dat->GetBinError(i));
   240     if(m12 < pow(dm1 + dm2, 2))
   243     if(m12 > pow(bigM - dm3, 2))
   247     fptype e1star = 0.5 * (m12 - dm2 * dm2 + dm1 * dm1) / sqrt(m12);
   248     fptype e3star = 0.5 * (bigM * bigM - m12 - dm3 * dm3) / sqrt(m12);
   252         = pow(e1star + e3star, 2) - pow(sqrt(e1star * e1star - dm1 * dm1) + sqrt(e3star * e3star - dm3 * dm3), 2);
   258         = pow(e1star + e3star, 2) - pow(sqrt(e1star * e1star - dm1 * dm1) - sqrt(e3star * e3star - dm3 * dm3), 2);
   273     loM23Sigma->SetLineWidth(3);
   274     loM23Sigma->SetLineColor(kBlue);
   275     hiM23Sigma->SetLineWidth(3);
   276     hiM23Sigma->SetLineColor(kRed);
   278     hiM23Sigma->GetXaxis()->SetTitle(
"#sigma_{t} [ps]");
   279     hiM23Sigma->GetYaxis()->SetTitle(
"Fraction / 8 fs");
   280     hiM23Sigma->Draw(
"l");
   281     loM23Sigma->Draw(
"lsame");
   283     TLegend blah(0.7, 0.8, 0.95, 0.95);
   284     blah.AddEntry(loM23Sigma, 
"m_{0}^{2} < 1.5", 
"l");
   285     blah.AddEntry(hiM23Sigma, 
"m_{0}^{2} > 1.5", 
"l");
   288     foo->SaveAs(
"./plots_from_mixfit/sigmacomp.png");
   293     TH1F *dat_hist = 
new TH1F(
   296     for(
int i = 0; i < numEvents; ++i) {
   297         dat_hist->Fill(dat->
getValue(var, i));
   300     TH1F *pdf_hist = 
new TH1F(
   307         totalPdf += values[i];
   311         pdf_hist->SetBinContent(i + 1, values[i] * numEvents / totalPdf);
   314     pdf_hist->SetStats(
false);
   315     pdf_hist->SetLineColor(kBlue);
   316     pdf_hist->SetLineWidth(3);
   318     dat_hist->SetStats(
false);
   319     dat_hist->SetMarkerStyle(8);
   320     dat_hist->SetMarkerSize(0.7);
   323     pdf_hist->Draw(
"lsame");
   325     foo->SaveAs((var.
getName() + 
"_fit.png").c_str());
   327     foo->SaveAs((var.
getName() + 
"_logfit.png").c_str());
   331 bool readWrapper(std::ifstream &reader, std::string fname = strbuffer) {
   332     std::cout << 
"Now open file " << fname << 
" for reading" << std::endl;
   333     reader.open(fname.c_str());
   334     assert(reader.good());
   340         std::vector<Observable> vars;
   341         vars.push_back(*m12);
   342         vars.push_back(*m13);
   343         vars.push_back(*dtime);
   344         vars.push_back(*sigma);
   345         vars.push_back(*eventNumber);
   346         vars.push_back(*wSig0);
   352     std::ifstream reader;
   356     while(!reader.eof()) {
   372     while(reader >> dummy
   376           >> dummy >> *m12 >> *m13
   379           >> dummy >> dummy >> dummy
   385           >> dummy >> dummy >> dummy >> dummy >> dummy >> dummy >> dummy >> dummy >> dummy >> dummy >> dummy) {
   386         double resolution = donram.Gaus(0, 1);
   392             md0 = donram.Gaus(md0_toy_mean, md0_toy_width);
   393         } 
while(md0 <= 1.8654 + 0.0075 * md0_lower_window || md0 >= 1.8654 + 0.0075 * 
md0_upper_window);
   412     for(
int ib = 0; ib < nsig * (1 - sigweight) / sigweight; ib++) {
   419             dtime->
setValue(donram.Gaus(toyBkgTimeMean, toyBkgTimeRMS));
   434     Variable effSmoothing(
"effSmoothing", 1.0, 0.1, 0, 1.25);
   446     vector<VetoInfo> vetos;
   447     vetos.push_back(kVetoInfo);
   456     vector<Variable> offsets;
   457     vector<Observable> observables;
   458     vector<Variable> coefficients;
   462     observables.push_back(*m12);
   463     observables.push_back(*m13);
   465     coefficients.push_back(
Variable(
"x0y0", 1.0));
   466     coefficients.push_back(
Variable(
"x1y0", 0.07999, 0.01, -0.5, 0.5));
   467     coefficients.push_back(
Variable(
"x2y0", -0.23732, 0.01, -0.5, 0.5));
   468     coefficients.push_back(
Variable(
"x3y0", 0.10369, 0.01, -1.5, 0.5));
   469     coefficients.push_back(
Variable(
"x0y1", 0.10248, 0.01, -1.5, 0.5));
   470     coefficients.push_back(
Variable(
"x1y1", -0.28543, 0.01, -0.5, 0.5));
   471     coefficients.push_back(
Variable(
"x2y1", 0.15058, 0.01, -1.5, 0.5));
   472     coefficients.push_back(
Variable(
"x0y2", -0.20648, 0.01, -0.5, 0.5));
   473     coefficients.push_back(
Variable(
"x1y2", 0.14567, 0.01, -1.5, 0.5));
   474     coefficients.push_back(
Variable(
"x0y3", 0.06231, 0.01, -0.5, 0.5));
   479     Variable decXmin(
"decXmin", 6.22596);
   480     Variable decYmin(
"decYmin", 6.30722);
   481     Variable decZmin(
"decZmin", 10.82390);
   482     Variable conXmin(
"conXmin", 0.65621);
   483     Variable conYmin(
"conYmin", 0.69527);
   484     Variable conZmin(
"conZmin", 0.31764);
   485     Variable decXmax(
"decXmax", 0.79181);
   486     Variable decYmax(
"decYmax", 5.91211);
   487     Variable decZmax(
"decZmax", 1.52031);
   488     Variable conXmax(
"conXmax", 0.80918);
   489     Variable conYmax(
"conYmax", 0.22158);
   490     Variable conZmax(
"conZmax", 0.41866);
   502     comps.push_back(poly);
   503     comps.push_back(loX);
   504     comps.push_back(hiX);
   505     comps.push_back(loY);
   506     comps.push_back(hiY);
   507     comps.push_back(loZ);
   508     comps.push_back(hiZ);
   509     comps.push_back(kzero_veto);
   517                     Variable(
"xmixing", 0.0016, 0.001, 0, 0),
   518                     Variable(
"ymixing", 0.0055, 0.001, 0, 0)};
   539     bool fixAmps = 
false;
   543         fixAmps ? 
Variable(
"rhom_amp_real", 0.714) : 
Variable(
"rhom_amp_real", 0.714, 0.001, 0, 0),
   544         fixAmps ? 
Variable(
"rhom_amp_imag", -0.025) : 
Variable(
"rhom_amp_imag", -0.025, 0.1, 0, 0),
   552                              fixAmps ? 
Variable(
"rho0_amp_real", 0.565) : 
Variable(
"rho0_amp_real", 0.565, 0.001, 0, 0),
   553                              fixAmps ? 
Variable(
"rho0_amp_imag", 0.164) : 
Variable(
"rho0_amp_imag", 0.164, 0.1, 0, 0),
   559     Variable rho1450Mass(
"rhop_1450_mass", 1.465, 0.01, 1.0, 2.0);
   560     Variable rho1450Width(
"rhop_1450_width", 0.400, 0.01, 0.01, 5.0);
   564         fixAmps ? 
Variable(
"rhop_1450_amp_real", -0.174) : 
Variable(
"rhop_1450_amp_real", -0.174, 0.001, 0, 0),
   565         fixAmps ? 
Variable(
"rhop_1450_amp_imag", -0.117) : 
Variable(
"rhop_1450_amp_imag", -0.117, 0.1, 0, 0),
   573         fixAmps ? 
Variable(
"rho0_1450_amp_real", 0.325) : 
Variable(
"rho0_1450_amp_real", 0.325, 0.001, 0, 0),
   574         fixAmps ? 
Variable(
"rho0_1450_amp_imag", 0.057) : 
Variable(
"rho0_1450_amp_imag", 0.057, 0.1, 0, 0),
   582         fixAmps ? 
Variable(
"rhom_1450_amp_real", 0.788) : 
Variable(
"rhom_1450_amp_real", 0.788, 0.001, 0, 0),
   583         fixAmps ? 
Variable(
"rhom_1450_amp_imag", 0.226) : 
Variable(
"rhom_1450_amp_imag", 0.226, 0.1, 0, 0),
   589     Variable rho1700Mass(
"rhop_1700_mass", 1.720, 0.01, 1.6, 1.9);
   590     Variable rho1700Width(
"rhop_1700_width", 0.250, 0.01, 0.1, 1.0);
   594         fixAmps ? 
Variable(
"rhop_1700_amp_real", 2.151) : 
Variable(
"rhop_1700_amp_real", 2.151, 0.001, 0, 0),
   595         fixAmps ? 
Variable(
"rhop_1700_amp_imag", -0.658) : 
Variable(
"rhop_1700_amp_imag", -0.658, 0.1, 0, 0),
   603         fixAmps ? 
Variable(
"rho0_1700_amp_real", 2.400) : 
Variable(
"rho0_1700_amp_real", 2.400, 0.001, 0, 0),
   604         fixAmps ? 
Variable(
"rho0_1700_amp_imag", -0.734) : 
Variable(
"rho0_1700_amp_imag", -0.734, 0.1, 0, 0),
   612         fixAmps ? 
Variable(
"rhom_1700_amp_real", 1.286) : 
Variable(
"rhom_1700_amp_real", 1.286, 0.001, 0, 0),
   613         fixAmps ? 
Variable(
"rhom_1700_amp_imag", -1.532) : 
Variable(
"rhom_1700_amp_imag", -1.532, 0.1, 0, 0),
   621                                                        : 
Variable(
"f0_980_amp_real", 0.008 * (-
_mD02), 0.001, 0, 0),
   624                                                Variable(
"f0_980_mass", 0.980, 0.01, 0.8, 1.2),
   625                                                Variable(
"f0_980_width", 0.044, 0.001, 0.001, 0.08),
   631                                                         : 
Variable(
"f0_1370_amp_real", -0.058 * (-
_mD02), 0.001, 0, 0),
   634                                                 Variable(
"f0_1370_mass", 1.434, 0.01, 1.2, 1.6),
   635                                                 Variable(
"f0_1370_width", 0.173, 0.01, 0.01, 0.4),
   641                                                         : 
Variable(
"f0_1500_amp_real", 0.057 * (-
_mD02), 0.001, 0, 0),
   644                                                 Variable(
"f0_1500_mass", 1.507, 0.01, 1.3, 1.7),
   645                                                 Variable(
"f0_1500_width", 0.109, 0.01, 0.01, 0.3),
   651                                                         : 
Variable(
"f0_1710_amp_real", 0.070 * (-
_mD02), 0.001, 0, 0),
   654                                                 Variable(
"f0_1710_mass", 1.714, 0.01, 1.5, 2.9),
   655                                                 Variable(
"f0_1710_width", 0.140, 0.01, 0.01, 0.5),
   665                               Variable(
"f2_1270_mass", 1.2754, 0.01, 1.0, 1.5),
   666                               Variable(
"f2_1270_width", 0.1851, 0.01, 0.01, 0.4),
   672                                                        : 
Variable(
"f0_600_amp_real", 0.068 * (-
_mD02), 0.001, 0, 0),
   675                                                Variable(
"f0_600_mass", 0.500, 0.01, 0.3, 0.7),
   676                                                Variable(
"f0_600_width", 0.400, 0.01, 0.2, 0.6),
   682         fixAmps ? 
Variable(
"nonr_amp_real", 0.5595 * (-1)) : 
Variable(
"nonr_amp_real", 0.5595 * (-1), 0.001, 0, 0),
   683         fixAmps ? 
Variable(
"nonr_amp_imag", -0.108761 * (-1)) : 
Variable(
"nonr_amp_imag", -0.108761 * (-1), 0.1, 0, 0));
   722             (*res)->setParameterConstantness(
true);
   727         vector<Variable> offsets;
   728         vector<Observable> observables;
   729         vector<Variable> coefficients;
   731         observables.push_back(*m12);
   732         observables.push_back(*m13);
   736         eff = 
new PolynomialPdf(
"constantEff", observables, coefficients, offsets, 0);
   739     std::vector<MixingTimeResolution *> resList;
   744                 sprintf(strbuffer, 
"coreFrac_%i", i);
   745                 Variable coreFrac(strbuffer, 0.90, 0.001, 0.55, 0.999);
   746                 sprintf(strbuffer, 
"coreBias_%i", i);
   748                 Variable coreBias(strbuffer, -0.1, 0.001, -0.20, 0.30);
   749                 sprintf(strbuffer, 
"coreScaleFactor_%i", i);
   750                 Variable coreScaleFactor(strbuffer, 0.96, 0.001, 0.20, 1.50);
   751                 sprintf(strbuffer, 
"tailScaleFactor_%i", i);
   752                 Variable tailScaleFactor(strbuffer, 1.63, 0.001, 0.90, 6.00);
   761                 resList.push_back(resolution);
   764             Variable coreFrac(
"coreFrac", 0.90, 0.001, 0.35, 0.999);
   766             Variable coreBias(
"coreBias", 0.0, 0.001, -0.20, 0.30);
   767             Variable coreScaleFactor(
"coreScaleFactor", 0.96, 0.001, 0.20, 1.50);
   769             Variable tailScaleFactor(
"tailScaleFactor", 1.63, 0.001, 0.90, 6.00);
   807         mixPdf = 
new TddpPdf(
"mixPdf", *dtime, *sigma, *m12, *m13, *eventNumber, 
dtop0pp, resList, eff, *massd0, wBkg1);
   809         mixPdf = 
new TddpPdf(
"mixPdf", *dtime, *sigma, *m12, *m13, *eventNumber, 
dtop0pp, resolution, eff, wBkg1);
   815     vector<Variable> offsets;
   816     vector<Observable> observables;
   817     vector<Variable> coefficients;
   820     observables.push_back(*m12);
   821     observables.push_back(*m13);
   825     Variable g_mean(
"g_mean", toyBkgTimeMean, 0.01, -0.2, 0.5);
   826     Variable g_sigma(
"g_sigma", toyBkgTimeRMS, 0.01, 0.15, 1.5);
   829     comps.push_back(poly);
   839 int runToyFit(
int ifile, 
int nfile, 
bool noPlots = 
true) {
   840     if(!nfile || ifile < 0 || ifile >= 100)
   849     sigma = 
new Observable(
"sigma", 0.099, 0.101);
   856     eventNumber = 
new EventNumber(
"eventNumber", 0, INT_MAX);
   859     for(
int i = 0; i < nfile; i++) {
   861         sprintf(strbuffer, 
"dataFiles/toyPipipi0/dalitz_toyMC_%03d.txt", ifile);
   862         toyFileName = app_ptr->
get_filename(strbuffer, 
"examples/pipipi0DPFit");
   875     comps.push_back(signalDalitz);
   877     std::cout << 
"Creating overall PDF\n";
   882     std::vector<Observable> evtWeights;
   883     evtWeights.push_back(*wSig0);
   885     std::vector<PdfBase *> components;
   886     components.push_back(signalDalitz);
   887     components.push_back(bkgPdf);
   906     fmt::print(
"Fit results Toy fit:\n"   908                "xmixing: ({:.3})\%\n"   909                "ymixing: ({:.3})\%\n",
   925     std::vector<Observable> vars;
   926     vars.push_back(*m12);
   927     vars.push_back(*m13);
   928     vars.push_back(*dtime);
   929     vars.push_back(*sigma);
   930     vars.push_back(*eventNumber);
   931     vars.push_back(*wSig0);
   932     vars.push_back(*wBkg1);
   933     vars.push_back(*wBkg2);
   934     vars.push_back(*wBkg3);
   935     vars.push_back(*wBkg4);
   938         vars.push_back(*massd0);
   941     std::ifstream reader;
   945     while(!reader.eof()) {
   954     double integralWeights[5] = {0, 0, 0, 0, 0};
   961     while(!reader.eof()) {
  1028         if(dtime->getValue() < dtime->getLowerLimit())
  1031         if(dtime->getValue() > dtime->getUpperLimit())
  1034         if(sigma->getValue() > sigma->getUpperLimit())
  1037         integralWeights[0] += wSig0->
getValue();
  1038         integralWeights[1] += wBkg1->getValue();
  1039         integralWeights[2] += wBkg2->getValue();
  1040         integralWeights[3] += wBkg3->getValue();
  1041         integralWeights[4] += wBkg4->getValue();
  1042         eventNumber->
setValue((*setToFill)->getNumEvents());
  1045         double mistag = wSig0->getValue() + wBkg1->getValue() * 
luckyFrac;
  1046         wSig0->setValue(wSig0->getValue() + wBkg1->getValue());
  1047         wBkg1->setValue(mistag / wSig0->getValue());
  1049         if((binEffData) && (0 == events % effSkip)) {
  1058             (*setToFill)->addEvent();
  1063             double currM23 = 
cpuGetM23(m12->getValue(), m13->getValue());
  1066                 loM23Sigma->Fill(sigma->getValue());
  1068                 hiM23Sigma->Fill(sigma->getValue());
  1073         if(wSig0->getValue() > 1.0)
  1074             std::cout << 
"Problem with event " << (*setToFill)->getNumEvents() << 
", too-large signal weight "  1075                       << wSig0->getValue() << std::endl;
  1094     std::cout << 
"Loaded " << (*setToFill)->getNumEvents() << 
" events.\n";
  1095     std::cout << 
"Integrals: " << integralWeights[0] << 
" " << integralWeights[1] << 
" " << integralWeights[2] << 
" "  1096               << integralWeights[3] << 
" " << integralWeights[4] << 
"\n";
  1100     static bool exists = 
false;
  1115     eventNumber = 
new EventNumber(
"eventNumber", 0, INT_MAX);
  1125     static int jsugg_num = -1;
  1128     sprintf(strbuffer, 
"js_meana_%i", jsugg_num);
  1129     Variable js_meana(strbuffer, 0.0593, 0.01, 0, 0.2);
  1131     sprintf(strbuffer, 
"js_sigma_%i", jsugg_num);
  1132     Variable js_sigma(strbuffer, 0.000474, 0.0001, 0, 0.001);
  1134     sprintf(strbuffer, 
"js_gamma_%i", jsugg_num);
  1135     Variable js_gamma(strbuffer, -10.1942, 1, -30, 0);
  1137     sprintf(strbuffer, 
"js_delta_%i", jsugg_num);
  1138     Variable js_delta(strbuffer, 1.4907, 0.1, 0.5, 5);
  1140     sprintf(strbuffer, 
"frac_jsu_%i", jsugg_num);
  1141     Variable frac_jsu(strbuffer, 0.9516, 0.01, 0.5, 1.0);
  1143     sprintf(strbuffer, 
"frac_ga1_%i", jsugg_num);
  1144     Variable frac_ga1(strbuffer, 0.001845, 0.0005, 0.0001, 0.3);
  1146     sprintf(strbuffer, 
"g1_meana_%i", jsugg_num);
  1147     Variable g1_meana(strbuffer, 0.2578, 0.003, 0.1, 0.5);
  1149     sprintf(strbuffer, 
"g1_sigma_%i", jsugg_num);
  1150     Variable g1_sigma(strbuffer, 0.03086, 0.01, 0.005, 0.25);
  1152     sprintf(strbuffer, 
"g2_meana_%i", jsugg_num);
  1153     Variable g2_meana(strbuffer, 0.32, 0.01, 0.1, 0.5);
  1155     sprintf(strbuffer, 
"g2_sigma_%i", jsugg_num);
  1156     Variable g2_sigma(strbuffer, 0.05825, 0.01, 0.01, 0.1);
  1160     sprintf(strbuffer, 
"js_%i", jsugg_num);
  1162     sprintf(strbuffer, 
"g1_%i", jsugg_num);
  1164     sprintf(strbuffer, 
"g2_%i", jsugg_num);
  1168     weights.push_back(frac_jsu);
  1171     comps.push_back(js);
  1172     comps.push_back(g1);
  1202     sprintf(strbuffer, 
"signal_sigma_%i", jsugg_num);
  1203     AddPdf *signal_sigma = 
new AddPdf(strbuffer, weights, comps);
  1204     return signal_sigma;
  1212     Variable *js_sigma = 
new Variable(
"js_sigma", 0.000474171, 0.0001, 0, 0.001);
  1220     Variable *frac_ga1 = 
new Variable(
"frac_ga1", 0.0184522, 0.00001, 0.001, 0.3);
  1224     Variable *g1_sigma = 
new Variable(
"g1_sigma", 0.0308619, 0.01, 0.005, 0.25);
  1240     weights.push_back(*frac_jsu);
  1241     weights.push_back(*frac_ga1);
  1243     comps.push_back(js);
  1244     comps.push_back(g1);
  1245     comps.push_back(g2);
  1247     GooPdf *ret = 
new AddPdf(
"signal_sigma", weights, comps);
  1262     std::vector<Observable> vars;
  1263     vars.push_back(*sigma);
  1266         sprintf(strbuffer, 
"sigma_data_hist_%i", i);
  1269         sigma_dat_hists[i]->SetStats(
false);
  1270         sigma_dat_hists[i]->SetMarkerStyle(8);
  1271         sigma_dat_hists[i]->SetMarkerSize(0.7);
  1272         sprintf(strbuffer, 
"sigma_pdf_hist_%i", i);
  1275         sigma_pdf_hists[i]->SetStats(
false);
  1276         sigma_pdf_hists[i]->SetLineWidth(3);
  1277         sigma_pdf_hists[i]->SetLineColor(kBlue);
  1284     for(
int i = 0; i < numEvents; ++i) {
  1289         int xbin       = (int)floor(m12->
getValue() / 0.5);
  1290         int ybin       = (int)floor(m13->
getValue() / 0.5);
  1291         int overallbin = ybin * 6 + xbin;
  1292         sigma_dat_hists[overallbin]->Fill(sigma->
getValue());
  1293         sigma_data[overallbin]->
addEvent();
  1299         jsuList.push_back(js);
  1310         if(0 == sigma_data[i]->getNumEvents())
  1313             std::cout << 
"\n\nAbout to start fit of sigma box " << i << std::endl;
  1324             std::cout << 
"Done with sigma box " << i << 
"\n";
  1328     vector<Observable> obses;
  1329     obses.push_back(*m12);
  1330     obses.push_back(*m13);
  1331     vector<double> limits;
  1332     limits.push_back(0);
  1333     limits.push_back(0);
  1334     vector<double> binSizes;
  1335     binSizes.push_back(0.5);
  1336     binSizes.push_back(0.5);
  1337     vector<int> numBins;
  1338     numBins.push_back(6);
  1339     numBins.push_back(6);
  1342     return new MappedPdf(
"sigmaMap", mapFunction, jsuList);
  1346     sigma_dat_hists = 
new TH1F *[1];
  1347     sigma_pdf_hists = 
new TH1F *[1];
  1350     std::vector<Observable> vars;
  1351     vars.push_back(*sigma);
  1353     for(
int i = 0; i < 1; ++i) {
  1354         sprintf(strbuffer, 
"sigma_data_hist_%i", i);
  1357         sigma_dat_hists[i]->SetStats(
false);
  1358         sigma_dat_hists[i]->SetMarkerStyle(8);
  1359         sigma_dat_hists[i]->SetMarkerSize(0.7);
  1360         sprintf(strbuffer, 
"sigma_pdf_hist_%i", i);
  1363         sigma_pdf_hists[i]->SetStats(
false);
  1364         sigma_pdf_hists[i]->SetLineWidth(3);
  1365         sigma_pdf_hists[i]->SetLineColor(kBlue);
  1372     for(
int i = 0; i < numEvents; ++i) {
  1378         sigma_dat_hists[overallbin]->Fill(sigma->
getValue());
  1379         sigma_data[overallbin]->
addEvent();
  1383     for(
int i = 0; i < 1; ++i) {
  1385         jsuList.push_back(js);
  1387         if(0 == sigma_data[i]->getNumEvents())
  1390             std::cout << 
"\n\nAbout to start fit of sigma box " << i << std::endl;
  1401             std::cout << 
"Done with sigma box " << i << 
"\n";
  1405     vector<Observable> obses;
  1406     obses.push_back(*m12);
  1407     obses.push_back(*m13);
  1408     vector<double> limits;
  1409     limits.push_back(0);
  1410     limits.push_back(0);
  1411     vector<double> binSizes;
  1412     binSizes.push_back(3);
  1413     binSizes.push_back(3);
  1414     vector<int> numBins;
  1415     numBins.push_back(1);
  1416     numBins.push_back(1);
  1419     return new MappedPdf(
"sigmaMap", mapFunction, jsuList);
  1423     sigma_dat_hists = 
new TH1F *[4];
  1424     sigma_pdf_hists = 
new TH1F *[4];
  1427     std::vector<Observable> vars;
  1428     vars.push_back(*sigma);
  1430     for(
int i = 0; i < 4; ++i) {
  1431         sprintf(strbuffer, 
"sigma_data_hist_%i", i);
  1434         sigma_dat_hists[i]->SetStats(
false);
  1435         sigma_dat_hists[i]->SetMarkerStyle(8);
  1436         sigma_dat_hists[i]->SetMarkerSize(0.7);
  1437         sprintf(strbuffer, 
"sigma_pdf_hist_%i", i);
  1440         sigma_pdf_hists[i]->SetStats(
false);
  1441         sigma_pdf_hists[i]->SetLineWidth(3);
  1442         sigma_pdf_hists[i]->SetLineColor(kBlue);
  1449     for(
int i = 0; i < numEvents; ++i) {
  1454         int xbin       = (int)floor(m12->
getValue() / 1.5);
  1455         int ybin       = (int)floor(m13->
getValue() / 1.5);
  1456         int overallbin = ybin * 2 + xbin;
  1457         sigma_dat_hists[overallbin]->Fill(sigma->
getValue());
  1458         sigma_data[overallbin]->
addEvent();
  1462     for(
int i = 0; i < 4; ++i) {
  1464         jsuList.push_back(js);
  1466         if(0 == sigma_data[i]->getNumEvents())
  1469             std::cout << 
"\n\nAbout to start fit of sigma box " << i << std::endl;
  1480             std::cout << 
"Done with sigma box " << i << 
"\n";
  1484     vector<Observable> obses;
  1485     obses.push_back(*m12);
  1486     obses.push_back(*m13);
  1487     vector<double> limits;
  1488     limits.push_back(0);
  1489     limits.push_back(0);
  1490     vector<double> binSizes;
  1491     binSizes.push_back(1.5);
  1492     binSizes.push_back(1.5);
  1493     vector<int> numBins;
  1494     numBins.push_back(2);
  1495     numBins.push_back(2);
  1498     return new MappedPdf(
"sigmaMap", mapFunction, jsuList);
  1503     for(
int i = 1; i < m12->
getNumBins(); i += grain) {
  1504         for(
int j = 1; j < m13->
getNumBins(); j += grain) {
  1507             for(
int k = 0; k < grain; ++k) {
  1508                 for(
int l = 0; l < grain; ++l) {
  1509                     total += dalitzHist.GetBinContent(i + k, j + l);
  1513             for(
int k = 0; k < grain; ++k) {
  1514                 for(
int l = 0; l < grain; ++l) {
  1515                     dalitzHist.SetBinContent(i + k, j + l, total);
  1527     double getContent(TH2F *plot);
  1534     for(
unsigned int i = 0; i < width; ++i) {
  1535         for(
unsigned int j = 0; j < height; ++j) {
  1537             if(xbin + i > plot->GetNbinsX())
  1540             if(ybin + j > plot->GetNbinsY())
  1543             ret += plot->GetBinContent(xbin + i, ybin + j);
  1564     bool acceptable = 
false;
  1566     vector<BigBin> binlist;
  1569     while(!acceptable) {
  1571         std::cout << 
"Attempting bin generation with size " << binSize << std::endl;
  1573         for(
int xbin = 1; xbin <= datPlot->GetNbinsX(); xbin += binSize) {
  1574             for(
int ybin = 1; ybin <= datPlot->GetNbinsY(); ybin += binSize) {
  1575                 double lox  = datPlot->GetXaxis()->GetBinLowEdge(xbin + 0);
  1576                 double hix  = datPlot->GetXaxis()->GetBinLowEdge(xbin + 1 + binSize);
  1577                 double loy  = datPlot->GetYaxis()->GetBinLowEdge(ybin + 0);
  1578                 double hiy  = datPlot->GetYaxis()->GetBinLowEdge(ybin + 1 + binSize);
  1579                 bool corner = 
false;
  1597                 binlist.push_back(curr);
  1603         for(vector<BigBin>::iterator bin = binlist.begin(); bin != binlist.end(); ++bin) {
  1604             if((*bin).getContent(datPlot) >= limit)
  1609             std::cout << 
"Couldn't get good bins, retry.\n";
  1614     std::cout << 
"Good bins at size " << binSize << 
", beginning splits.\n";
  1619     while(0 < numSplits) {
  1621         vector<BigBin> newbins;
  1623         for(vector<BigBin>::iterator bin = binlist.begin(); bin != binlist.end(); ++bin) {
  1624             if(1 == (*bin).width * (*bin).height) {
  1625                 newbins.push_back(*bin);
  1633             lolef.
xbin = (*bin).xbin;
  1634             hilef.
xbin = (*bin).xbin;
  1635             lorig.
xbin = (*bin).xbin + (*bin).width / 2;
  1636             hirig.
xbin = (*bin).xbin + (*bin).width / 2;
  1637             lolef.
ybin = (*bin).ybin;
  1638             hilef.
ybin = (*bin).ybin + (*bin).height / 2;
  1639             lorig.
ybin = (*bin).ybin;
  1640             hirig.
ybin = (*bin).ybin + (*bin).height / 2;
  1642             lolef.
width  = (*bin).width / 2;
  1643             lorig.
width  = (*bin).width / 2;
  1644             hilef.
width  = (*bin).width / 2;
  1645             hirig.
width  = (*bin).width / 2;
  1646             lolef.
height = (*bin).height / 2;
  1647             lorig.
height = (*bin).height / 2;
  1648             hilef.
height = (*bin).height / 2;
  1649             hirig.
height = (*bin).height / 2;
  1666                 newbins.push_back(*bin);
  1668                 newbins.push_back(lolef);
  1669                 newbins.push_back(lorig);
  1670                 newbins.push_back(hilef);
  1671                 newbins.push_back(hirig);
  1678         for(vector<BigBin>::iterator i = newbins.begin(); i != newbins.end(); ++i)
  1679             binlist.push_back(*i);
  1681         std::cout << 
"Split " << numSplits << 
" bins.\n";
  1685     ret->
dof         = binlist.size();
  1688                                 datPlot->GetNbinsX(),
  1689                                 datPlot->GetXaxis()->GetBinLowEdge(1),
  1690                                 datPlot->GetXaxis()->GetBinLowEdge(datPlot->GetNbinsX() + 1),
  1691                                 datPlot->GetNbinsY(),
  1692                                 datPlot->GetYaxis()->GetBinLowEdge(1),
  1693                                 datPlot->GetYaxis()->GetBinLowEdge(datPlot->GetNbinsY() + 1));
  1695     double totalDat = 0;
  1696     double totalPdf = 0;
  1698     for(vector<BigBin>::iterator bin = binlist.begin(); bin != binlist.end(); ++bin) {
  1699         double dat  = (*bin).getContent(datPlot);
  1700         double pdf  = (*bin).getContent(pdfPlot);
  1701         double term = (dat - pdf) / sqrt(dat);
  1702         ret->
chisq += term * term;
  1710         for(
int i = 0; i < (*bin).width; ++i) {
  1711             for(
int j = 0; j < (*bin).height; ++j) {
  1712                 bool corner = 
false;
  1713                 double lox  = datPlot->GetXaxis()->GetBinLowEdge((*bin).xbin + i);
  1714                 double hix  = datPlot->GetXaxis()->GetBinLowEdge((*bin).xbin + i + 1);
  1715                 double loy  = datPlot->GetYaxis()->GetBinLowEdge((*bin).ybin + j);
  1716                 double hiy  = datPlot->GetYaxis()->GetBinLowEdge((*bin).ybin + j + 1);
  1730                 ret->
contribPlot->SetBinContent((*bin).xbin + i, (*bin).ybin + j, term);
  1742     std::string call = 
"mkdir -p " + plotdir;
  1743     system(call.c_str());
  1748     dtime_dat_hist.SetStats(
false);
  1749     dtime_dat_hist.SetMarkerStyle(8);
  1750     dtime_dat_hist.SetMarkerSize(1.2);
  1751     dtime_dat_hist.GetXaxis()->SetTitle(
"Decay time [ps]");
  1752     dtime_dat_hist.GetYaxis()->SetTitle(
"Events / 50 fs");
  1754     dtime_pdf_hist.SetStats(
false);
  1755     dtime_pdf_hist.SetLineColor(kBlue);
  1756     dtime_pdf_hist.SetLineWidth(3);
  1758     dtime_sig_hist.SetStats(
false);
  1759     dtime_sig_hist.SetLineColor(kRed);
  1760     dtime_sig_hist.SetLineWidth(3);
  1762     dtime_bg_hist.SetStats(
false);
  1763     dtime_bg_hist.SetLineColor(kMagenta);
  1764     dtime_bg_hist.SetLineWidth(3);
  1766     double totalPdf     = 0;
  1767     double totalPdf_sig = 0;
  1768     double totalPdf_bg  = 0;
  1769     double totalDat     = 0;
  1770     double totalSigProb = 0;
  1771     double totalBGProb  = 0;
  1773     for(
unsigned int evt = 0; evt < data->
getNumEvents(); ++evt) {
  1774         double currTime = data->
getValue(*dtime, evt);
  1775         dtime_dat_hist.Fill(currTime);
  1776         totalSigProb += data->
getValue(*wSig0, evt);
  1777         totalBGProb += 1 - data->
getValue(*wSig0, evt);
  1781     std::cout << 
"totalData = " << totalDat << 
", totalSigProb = " << totalSigProb << std::endl;
  1782     std::vector<Observable> vars;
  1783     vars.push_back(*m12);
  1784     vars.push_back(*m13);
  1785     vars.push_back(*dtime);
  1786     vars.push_back(*sigma);
  1787     vars.push_back(*eventNumber);
  1788     vars.push_back(*wSig0);
  1791     wSig0->
setValue(totalSigProb / totalDat);
  1805             for(
int l = 0; l < dtime->
getNumBins(); ++l) {
  1817     overallSignal->
setData(&currData);
  1821     for(
unsigned int j = 0; j < pdfValues[0].size(); ++j) {
  1822         double currTime = currData.
getValue(*dtime, j);
  1823         dtime_sig_hist.Fill(currTime, pdfValues[1][j]);
  1824         dtime_bg_hist.Fill(currTime, pdfValues[2][j]);
  1825         totalPdf += pdfValues[0][j];
  1826         totalPdf_sig += pdfValues[1][j];
  1827         totalPdf_bg += pdfValues[2][j];
  1830     for(
int i = 1; i <= dtime->
getNumBins(); ++i) {
  1831         dtime_sig_hist.SetBinContent(i, dtime_sig_hist.GetBinContent(i) * totalSigProb / totalPdf_sig);
  1832         dtime_bg_hist.SetBinContent(i, dtime_bg_hist.GetBinContent(i) * totalBGProb / totalPdf_bg);
  1833         dtime_pdf_hist.SetBinContent(i, dtime_sig_hist.GetBinContent(i) + dtime_bg_hist.GetBinContent(i));
  1837     dtime_dat_hist.Draw(
"p");
  1838     dtime_pdf_hist.Draw(
"lsame");
  1839     dtime_bg_hist.SetLineStyle(2);
  1840     dtime_bg_hist.Draw(
"lsame");
  1841     dtime_sig_hist.SetLineStyle(3);
  1842     dtime_sig_hist.Draw(
"lsame");
  1844     foo->SaveAs((plotdir + 
"/dtime_fit.png").c_str());
  1846     foo->SaveAs((plotdir + 
"/dtime_fit_log.png").c_str());
  1847     foo->SetLogy(
false);
  1851     std::string mkplotdir{
"mkdir " + plotdir};
  1852     system(mkplotdir.c_str());
  1856     dtime_dat_hist.SetStats(
false);
  1857     dtime_dat_hist.SetMarkerStyle(8);
  1858     dtime_dat_hist.SetMarkerSize(1.2);
  1859     dtime_dat_hist.GetXaxis()->SetTitle(
"Decay time [ps]");
  1860     dtime_dat_hist.GetYaxis()->SetTitle(
"Events / 50 fs");
  1862     dtime_pdf_hist.SetStats(
false);
  1863     dtime_pdf_hist.SetLineColor(kBlue);
  1864     dtime_pdf_hist.SetLineWidth(3);
  1867     sigma_dat_hist.SetStats(
false);
  1868     sigma_dat_hist.SetMarkerStyle(8);
  1869     sigma_dat_hist.SetMarkerSize(1.2);
  1870     sigma_dat_hist.GetXaxis()->SetTitle(
"Decay time error [ps]");
  1871     sigma_dat_hist.GetYaxis()->SetTitle(
"Events / 8 fs");
  1873     sigma_pdf_hist.SetStats(
false);
  1874     sigma_pdf_hist.SetLineColor(kBlue);
  1875     sigma_pdf_hist.SetLineWidth(3);
  1878     m12_dat_hist.SetStats(
false);
  1879     m12_dat_hist.SetMarkerStyle(8);
  1880     m12_dat_hist.SetMarkerSize(1.2);
  1881     m12_dat_hist.GetXaxis()->SetTitle(
"m^{2}(#pi^{+} #pi^{0}) [GeV]");
  1882     m12_dat_hist.GetYaxis()->SetTitle(
"Events / 12.5 MeV");
  1884     m12_pdf_hist.SetStats(
false);
  1885     m12_pdf_hist.SetLineColor(kBlue);
  1886     m12_pdf_hist.SetLineWidth(3);
  1889     m13_dat_hist.SetStats(
false);
  1890     m13_dat_hist.SetMarkerStyle(8);
  1891     m13_dat_hist.SetMarkerSize(1.2);
  1892     m13_dat_hist.GetXaxis()->SetTitle(
"m^{2}(#pi^{-} #pi^{0}) [GeV]");
  1893     m13_dat_hist.GetYaxis()->SetTitle(
"Events / 12.5 MeV");
  1895     m13_pdf_hist.SetStats(
false);
  1896     m13_pdf_hist.SetLineColor(kBlue);
  1897     m13_pdf_hist.SetLineWidth(3);
  1900     m23_dat_hist.SetStats(
false);
  1901     m23_dat_hist.SetMarkerStyle(8);
  1902     m23_dat_hist.SetMarkerSize(1.2);
  1903     m23_dat_hist.GetXaxis()->SetTitle(
"m^{2}(#pi^{-} #pi^{+}) [GeV]");
  1904     m23_dat_hist.GetYaxis()->SetTitle(
"Events / 12.5 MeV");
  1906     m23_pdf_hist.SetStats(
false);
  1907     m23_pdf_hist.SetLineColor(kBlue);
  1908     m23_pdf_hist.SetLineWidth(3);
  1910     TH2F dalitzpm_dat_hist(
"dalitzpm_dat_hist",
  1918     dalitzpm_dat_hist.SetStats(
false);
  1919     dalitzpm_dat_hist.GetXaxis()->SetTitle(
"m^{2}(#pi^{+} #pi^{0}) [GeV]");
  1920     dalitzpm_dat_hist.GetYaxis()->SetTitle(
"m^{2}(#pi^{-} #pi^{0}) [GeV]");
  1921     TH2F dalitzpm_pdf_hist(
"dalitzpm_pdf_hist",
  1929     dalitzpm_pdf_hist.SetStats(
false);
  1931     TH2F dalitzp0_dat_hist(
"dalitzp0_dat_hist",
  1939     dalitzp0_dat_hist.SetStats(
false);
  1940     dalitzp0_dat_hist.GetXaxis()->SetTitle(
"m^{2}(#pi^{+} #pi^{0}) [GeV]");
  1941     dalitzp0_dat_hist.GetYaxis()->SetTitle(
"m^{2}(#pi^{-} #pi^{+}) [GeV]");
  1942     TH2F dalitzp0_pdf_hist(
"dalitzp0_pdf_hist",
  1950     dalitzp0_pdf_hist.SetStats(
false);
  1952     TH2F dalitzm0_dat_hist(
"dalitzm0_dat_hist",
  1960     dalitzm0_dat_hist.SetStats(
false);
  1961     dalitzm0_dat_hist.GetXaxis()->SetTitle(
"m^{2}(#pi^{-} #pi^{0}) [GeV]");
  1962     dalitzm0_dat_hist.GetYaxis()->SetTitle(
"m^{2}(#pi^{+} #pi^{-}) [GeV]");
  1963     TH2F dalitzm0_pdf_hist(
"dalitzm0_pdf_hist",
  1971     dalitzm0_pdf_hist.SetStats(
false);
  1975     double num_sigma_dat[6];
  1976     double num_sigma_pdf[6];
  1978     for(
int i = 0; i < 6; ++i) {
  1979         sprintf(strbuffer, 
"bkg_sigma_pdf_%i", i);
  1981         sprintf(strbuffer, 
"bkg_sigma_dat_%i", i);
  1984         num_sigma_dat[i] = 0;
  1985         num_sigma_pdf[i] = 0;
  1987         bkg3_data[i]->SetStats(
false);
  1988         bkg3_data[i]->SetMarkerStyle(8);
  1989         bkg3_data[i]->SetMarkerSize(1.2);
  1990         bkg3_data[i]->GetXaxis()->SetTitle(
"Decay time error [ps]");
  1991         bkg3_data[i]->GetYaxis()->SetTitle(
"Events / 8 fs");
  1993         bkg3_pdfs[i]->SetStats(
false);
  1994         bkg3_pdfs[i]->SetLineColor(kBlue);
  1995         bkg3_pdfs[i]->SetLineWidth(3);
  1998     double totalPdf = 0;
  1999     double totalDat = 0;
  2001     for(
unsigned int evt = 0; evt < data->
getNumEvents(); ++evt) {
  2002         double currTime = data->
getValue(*dtime, evt);
  2003         dtime_dat_hist.Fill(currTime);
  2005         double currSigma = data->
getValue(*sigma, evt);
  2006         sigma_dat_hist.Fill(currSigma);
  2008         double currm12 = data->
getValue(*m12, evt);
  2009         m12_dat_hist.Fill(currm12);
  2011         double currm13 = data->
getValue(*m13, evt);
  2012         m13_dat_hist.Fill(currm13);
  2014         dalitzpm_dat_hist.Fill(currm12, currm13);
  2016         double currm23 = 
cpuGetM23(currm12, currm13);
  2017         m23_dat_hist.Fill(currm23);
  2019         dalitzp0_dat_hist.Fill(currm12, currm23);
  2020         dalitzm0_dat_hist.Fill(currm13, currm23);
  2024         int m23bin = (int)floor(currm23 / 0.5);
  2025         bkg3_data[m23bin]->Fill(currSigma);
  2026         num_sigma_dat[m23bin]++;
  2029     double maxBinContent = 0;
  2033     for(
int i = 1; i <= m12->
getNumBins(); ++i) {
  2034         for(
int j = 1; j <= m13->
getNumBins(); ++j) {
  2035             double curr = dalitzpm_dat_hist.GetBinContent(i, j);
  2037             if(curr < maxBinContent)
  2040             maxBinContent = curr;
  2046     std::cout << 
"Max bin content: " << maxBinContent << 
" (" << bestI << 
", " << bestJ << 
")\n";
  2048     bool dependsOnSigma           = 
true;
  2051     if(std::find(obses.begin(), obses.end(), *
sigma) == obses.end())
  2052         dependsOnSigma = 
false;
  2057     const int division = 2;
  2059     for(
int half = 0; half < division; ++half) {
  2060         std::vector<Observable> vars;
  2061         vars.push_back(*m12);
  2062         vars.push_back(*m13);
  2063         vars.push_back(*dtime);
  2064         vars.push_back(*sigma);
  2065         vars.push_back(*eventNumber);
  2066         vars.push_back(*wBkg1);
  2084                 for(
int l = half; l < dtime->
getNumBins(); l += division) {
  2095         for(
int k = 0; k < sigma->
getNumBins(); ++k) {
  2100                 std::cout << 
"sigma iteration " << half << 
" " << k << std::endl;
  2103             overallSignal->
setData(&currData);
  2130             for(
unsigned int j = 0; j < pdfValues[0].size(); ++j) {
  2131                 double currTime = currData.
getValue(*dtime, j);
  2132                 dtime_pdf_hist.Fill(currTime, pdfValues[0][j]);
  2134                 double currSigma = currData.
getValue(*sigma, j);
  2135                 sigma_pdf_hist.Fill(currSigma, pdfValues[0][j]);
  2138                 double currm12 = currData.
getValue(*m13, j);
  2139                 m12_pdf_hist.Fill(currm12, pdfValues[0][j]);
  2141                 double currm13 = currData.
getValue(*m12, j);
  2142                 m13_pdf_hist.Fill(currm13, pdfValues[0][j]);
  2143                 dalitzpm_pdf_hist.Fill(currm12, currm13, pdfValues[0][j]);
  2145                 double currm23 = 
cpuGetM23(currm12, currm13);
  2146                 m23_pdf_hist.Fill(currm23, pdfValues[0][j]);
  2147                 dalitzp0_pdf_hist.Fill(currm12, currm23, pdfValues[0][j]);
  2148                 dalitzm0_pdf_hist.Fill(currm13, currm23, pdfValues[0][j]);
  2150                 int currM23Bin = (int)(currm23 / 0.5);
  2151                 bkg3_pdfs[currM23Bin]->Fill(currSigma, pdfValues[0][j]);
  2152                 num_sigma_pdf[currM23Bin] += pdfValues[0][j];
  2154                 totalPdf += pdfValues[0][j];
  2156                 if(std::isnan(pdfValues[0][j])) {
  2157                     std::cout << 
"Major problem: " << k << 
" " << j << std::endl;
  2161                 if(std::isinf(pdfValues[0][j])) {
  2162                     std::cout << 
"Infinity " << k << 
" " << j << std::endl;
  2175     for(
int i = 1; i <= dtime->
getNumBins(); ++i) {
  2176         dtime_pdf_hist.SetBinContent(i, dtime_pdf_hist.GetBinContent(i) * totalDat / totalPdf);
  2179     for(
int i = 1; i <= sigma->
getNumBins(); ++i) {
  2180         sigma_pdf_hist.SetBinContent(i, sigma_pdf_hist.GetBinContent(i) * totalDat / totalPdf);
  2182         for(
int j = 0; j < 6; ++j) {
  2183             bkg3_pdfs[j]->SetBinContent(i, bkg3_pdfs[j]->GetBinContent(i) * num_sigma_dat[j] / num_sigma_pdf[j]);
  2187     for(
int i = 1; i <= m12->
getNumBins(); ++i) {
  2188         m12_pdf_hist.SetBinContent(i, m12_pdf_hist.GetBinContent(i) * totalDat / totalPdf);
  2191     for(
int i = 1; i <= m13->
getNumBins(); ++i) {
  2192         m13_pdf_hist.SetBinContent(i, m13_pdf_hist.GetBinContent(i) * totalDat / totalPdf);
  2193         m23_pdf_hist.SetBinContent(i, m23_pdf_hist.GetBinContent(i) * totalDat / totalPdf);
  2196     for(
int i = 1; i <= m12->
getNumBins(); ++i) {
  2197         for(
int j = 1; j <= m13->
getNumBins(); ++j) {
  2198             dalitzpm_pdf_hist.SetBinContent(i, j, dalitzpm_pdf_hist.GetBinContent(i, j) * totalDat / totalPdf);
  2199             dalitzp0_pdf_hist.SetBinContent(i, j, dalitzp0_pdf_hist.GetBinContent(i, j) * totalDat / totalPdf);
  2200             dalitzm0_pdf_hist.SetBinContent(i, j, dalitzm0_pdf_hist.GetBinContent(i, j) * totalDat / totalPdf);
  2206     std::cout << 
"Chisquare: " << chisq->
chisq << 
" / " << chisq->
dof << std::endl;
  2211     foodal->SaveAs((plotdir + 
"/chisq.png").c_str());
  2221     dtime_dat_hist.Draw(
"p");
  2222     dtime_pdf_hist.Draw(
"lsame");
  2223     foo->SaveAs((plotdir + 
"/dtime_fit.png").c_str());
  2225     foo->SaveAs((plotdir + 
"/dtime_fit_log.png").c_str());
  2226     foo->SetLogy(
false);
  2228     for(
int i = 0; i < 6; ++i) {
  2229         if(!dependsOnSigma) {
  2230             bkg3_data[i]->Draw(
"p");
  2231         } 
else if(bkg3_data[i]->GetMaximum() > bkg3_pdfs[i]->GetMaximum()) {
  2232             bkg3_data[i]->Draw(
"p");
  2233             bkg3_pdfs[i]->Draw(
"lsame");
  2235             bkg3_pdfs[i]->Draw(
"l");
  2236             bkg3_data[i]->Draw(
"psame");
  2239         sprintf(strbuffer, 
"%i", i);
  2241         slicenum.DrawTextNDC(0.2, 0.8, strbuffer);
  2243         foo->SaveAs((plotdir + bkg3_pdfs[i]->GetName() + 
".png").c_str());
  2245         foo->SaveAs((plotdir + bkg3_pdfs[i]->GetName() + 
"_log.png").c_str());
  2246         foo->SetLogy(
false);
  2249     m13_dat_hist.Draw(
"p");
  2250     m13_pdf_hist.Draw(
"lsame");
  2251     foo->SaveAs((plotdir + 
"/m13_fit.png").c_str());
  2253     foo->SaveAs((plotdir + 
"/m13_fit_log.png").c_str());
  2254     foo->SetLogy(
false);
  2256     sigma_dat_hist.Draw(
"p");
  2257     sigma_pdf_hist.Draw(
"lsame");
  2258     foo->SaveAs((plotdir + 
"/sigma_fit.png").c_str());
  2260     foo->SaveAs((plotdir + 
"/sigma_fit_log.png").c_str());
  2261     foo->SetLogy(
false);
  2263     m12_dat_hist.Draw(
"p");
  2264     m12_pdf_hist.Draw(
"lsame");
  2265     foo->SaveAs((plotdir + 
"/m12_fit.png").c_str());
  2267     foo->SaveAs((plotdir + 
"/m12_fit_log.png").c_str());
  2268     foo->SetLogy(
false);
  2270     m23_dat_hist.Draw(
"p");
  2271     m23_pdf_hist.Draw(
"lsame");
  2272     foo->SaveAs((plotdir + 
"/m23_fit.png").c_str());
  2274     foo->SaveAs((plotdir + 
"/m23_fit_log.png").c_str());
  2275     foo->SetLogy(
false);
  2278     dalitzpm_dat_hist.Draw(
"colz");
  2280     for(
int slice = 0; slice < 6; ++slice) {
  2281         double line_m12 = 
cpuGetM23(0, 0.5 * (slice + 1));
  2283         sliceLine.SetLineWidth(2);
  2284         sliceLine.DrawLine(0, line_m12, line_m12, 0);
  2285         sprintf(strbuffer, 
"%i", slice);
  2287         sliceNum.DrawText(0.25, line_m12 - 0.25, strbuffer);
  2290     foodal->SaveAs((plotdir + 
"/dalitzpm_dat.png").c_str());
  2292     foodal->SaveAs((plotdir + 
"/dalitzpm_dat_log.png").c_str());
  2294     dalitzp0_dat_hist.Draw(
"colz");
  2295     foodal->SaveAs((plotdir + 
"/dalitzp0_dat.png").c_str());
  2297     foodal->SaveAs((plotdir + 
"/dalitzp0_dat_log.png").c_str());
  2299     dalitzm0_dat_hist.Draw(
"colz");
  2300     foodal->SaveAs((plotdir + 
"/dalitzm0_dat.png").c_str());
  2302     foodal->SaveAs((plotdir + 
"/dalitzm0_dat_log.png").c_str());
  2305     dalitzpm_pdf_hist.Draw(
"colz");
  2306     foodal->SaveAs((plotdir + 
"/dalitzpm_pdf.png").c_str());
  2308     foodal->SaveAs((plotdir + 
"/dalitzpm_pdf_log.png").c_str());
  2310     dalitzpm_pdf_hist.GetZaxis()->SetRangeUser(0, dalitzpm_dat_hist.GetMaximum());
  2311     dalitzpm_pdf_hist.Draw(
"colz");
  2312     foodal->SaveAs((plotdir + 
"/dalitzpm_pdf_matched.png").c_str());
  2314     foodal->SaveAs((plotdir + 
"/dalitzpm_pdf_matched_log.png").c_str());
  2316     dalitzp0_pdf_hist.GetZaxis()->SetRangeUser(0, dalitzp0_dat_hist.GetMaximum());
  2317     dalitzp0_pdf_hist.Draw(
"colz");
  2318     foodal->SaveAs((plotdir + 
"/dalitzp0_pdf.png").c_str());
  2320     foodal->SaveAs((plotdir + 
"/dalitzp0_pdf_log.png").c_str());
  2322     dalitzm0_pdf_hist.GetZaxis()->SetRangeUser(0, dalitzm0_dat_hist.GetMaximum());
  2323     dalitzm0_pdf_hist.Draw(
"colz");
  2324     foodal->SaveAs((plotdir + 
"/dalitzm0_pdf.png").c_str());
  2326     foodal->SaveAs((plotdir + 
"/dalitzm0_pdf_log.png").c_str());
  2329     TH1F pull_pm_hist(
"pull_pm_hist", 
"", 100, -5, 5);
  2330     pull_pm_hist.GetXaxis()->SetTitle(
"(Data - PDF) / sqrt(Data)");
  2331     pull_pm_hist.GetYaxis()->SetTitle(
"Bins / 0.1");
  2333     for(
int i = 1; i <= m12->
getNumBins(); ++i) {
  2339         for(
int j = 1; j <= m13->
getNumBins(); ++j) {
  2344                 dalitzpm_dat_hist.SetBinContent(i, j, 0);
  2349                 dalitzpm_dat_hist.SetBinContent(i, j, 0);
  2357                 dalitzpm_dat_hist.SetBinContent(i, j, 0);
  2362                 dalitzpm_dat_hist.SetBinContent(i, j, 0);
  2366             double dat = dalitzpm_dat_hist.GetBinContent(i, j);
  2367             double pdf = dalitzpm_pdf_hist.GetBinContent(i, j);
  2369             double pullval = (dat - pdf) / sqrt(max(1.0, dat));
  2370             dalitzpm_dat_hist.SetBinContent(i, j, pullval);
  2371             pull_pm_hist.Fill(pullval);
  2374         for(
int j = 1; j <= m13->
getNumBins(); ++j) {
  2380                 dalitzp0_dat_hist.SetBinContent(i, j, 0);
  2385                 dalitzp0_dat_hist.SetBinContent(i, j, 0);
  2393                 dalitzp0_dat_hist.SetBinContent(i, j, 0);
  2398                 dalitzp0_dat_hist.SetBinContent(i, j, 0);
  2402             double dat = dalitzp0_dat_hist.GetBinContent(i, j);
  2403             double pdf = dalitzp0_pdf_hist.GetBinContent(i, j);
  2405             dalitzp0_dat_hist.SetBinContent(i, j, (dat - pdf) / sqrt(max(1.0, dat)));
  2409         for(
int j = 1; j <= m13->
getNumBins(); ++j) {
  2414                 dalitzm0_dat_hist.SetBinContent(i, j, 0);
  2419                 dalitzm0_dat_hist.SetBinContent(i, j, 0);
  2427                 dalitzm0_dat_hist.SetBinContent(i, j, 0);
  2432                 dalitzm0_dat_hist.SetBinContent(i, j, 0);
  2436             double dat = dalitzm0_dat_hist.GetBinContent(i, j);
  2437             double pdf = dalitzm0_pdf_hist.GetBinContent(i, j);
  2439             dalitzm0_dat_hist.SetBinContent(i, j, (dat - pdf) / sqrt(max(1.0, dat)));
  2443     dalitzpm_dat_hist.GetZaxis()->SetRangeUser(-5, 5);
  2444     dalitzpm_dat_hist.Draw(
"colz");
  2445     foodal->SaveAs((plotdir + 
"/dalitzpm_pull.png").c_str());
  2446     dalitzp0_dat_hist.GetZaxis()->SetRangeUser(-5, 5);
  2447     dalitzp0_dat_hist.Draw(
"colz");
  2448     foodal->SaveAs((plotdir + 
"/dalitzp0_pull.png").c_str());
  2449     dalitzm0_dat_hist.GetZaxis()->SetRangeUser(-5, 5);
  2450     dalitzm0_dat_hist.Draw(
"colz");
  2451     foodal->SaveAs((plotdir + 
"/dalitzm0_pull.png").c_str());
  2455     pull_pm_hist.Draw(
"");
  2456     foo->SaveAs((plotdir + 
"/pull_pm_hist.png").c_str());
  2468     vector<Observable> obses;
  2469     vector<Variable> offsets;
  2470     vector<Variable> coefficients;
  2471     vector<PdfBase *> components;
  2472     vector<double> limits;
  2473     vector<double> binSizes;
  2474     vector<int> numBins;
  2479     obses.push_back(*m12);
  2480     obses.push_back(*m13);
  2490     coefficients.clear();
  2491     obses.push_back(*m12); 
  2492     limits.push_back(0);   
  2499     return m23_composite;
  2504     std::vector<std::unique_ptr<BinnedDataSet>> sigmaHists;
  2509     std::ifstream reader;
  2510     std::string fname = app_ptr->
get_filename(
"./dataFiles/signalMC_truth_mm_0.txt", 
"examples/pipipi0DPFit");
  2514     while(!reader.eof()) {
  2517         if(buffer == 
"====")
  2520         std::cout << buffer;
  2526     while(!reader.eof()) {
  2549         if(dtime->getValue() < dtime->getLowerLimit())
  2552         if(dtime->getValue() > dtime->getUpperLimit())
  2555         int bin = (int)floor((m23 / 3.0) * 
m23Slices);
  2556         sigmaHists[bin]->addEvent();
  2562         sprintf(strbuffer, 
"signal_sigma_hist_%i", i);
  2564         jsuList.push_back(hist);
  2567     return new MappedPdf(
"signalSigmaHist", m23_composite, jsuList);
  2574     vector<ConvolutionPdf *> convList;
  2575     bool useShare = 
false;
  2578         sprintf(strbuffer, 
"bkg%i_sigma_slice%i_expalpha", bkgnum, i);
  2579         Variable exp_alpha(strbuffer, 7.50, 0.10, 0, 10.00);
  2580         sprintf(strbuffer, 
"bkg%i_sigma_slice%i_gauss_meana", bkgnum, i);
  2581         Variable g_meana(strbuffer, 0.20, 0.01, 0.00, 0.80);
  2582         sprintf(strbuffer, 
"bkg%i_sigma_slice%i_gauss_sigma", bkgnum, i);
  2583         Variable g_sigma(strbuffer, 0.03, 0.01, 0.01, 0.20);
  2585         sprintf(strbuffer, 
"bkg%i_sigma_slice%i_conv", bkgnum, i);
  2587         jsuList.push_back(expfunc);
  2591         for(vector<ConvolutionPdf *>::iterator conv = convList.begin(); conv != convList.end(); ++conv) {
  2592             (*conv)->registerOthers(convList);
  2596     sprintf(strbuffer, 
"bkg%i_sigma_map", bkgnum);
  2597     return new MappedPdf(strbuffer, m23_composite, jsuList);
  2613     for(
int i = 1; i <= m12->
getNumBins(); ++i) {
  2615             double maxCount = 0;
  2618             for(
double currM12 = m12->
getLowerLimit() + step12 * (i - 1) + 0.05 * step12;
  2620                 currM12 += 0.1 * step12) {
  2621                 for(
double currM13 = m13->
getLowerLimit() + step13 * (j - 1) + 0.05 * step13;
  2623                     currM13 += 0.1 * step13) {
  2660     vector<Observable> lvars;
  2661     lvars.push_back(*m12);
  2662     lvars.push_back(*m13);
  2665     std::cout << 
"Loading efficiency data" << std::endl;
  2666     std::string fname = app_ptr->
get_filename(
"./dataFiles/efficiency_flat.txt", 
"examples/pipipi0DPFit");
  2670         system(
"mkdir plots_from_mixfit");
  2673         foodal->SaveAs(
"plots_from_mixfit/efficiency_bins.png");
  2675         foodal->SaveAs(
"plots_from_mixfit/efficiency_bins_log.png");
  2700     binEffData = 
nullptr;
  2708     comps.push_back(eff);
  2709     comps.push_back(kzero_veto);
  2712     std::cout << 
"Creating signal PDF\n";
  2715     std::cout << 
"Creating sigma PDF\n";
  2738     sprintf(strbuffer, 
"signal_sigma_%islices_pdf.txt", 
m23Slices);
  2739     fname = app_ptr->
get_filename(strbuffer, 
"examples/pipipi0DPFit");
  2744     comps.push_back(signalDalitz);
  2745     comps.push_back(sig0_jsugg);
  2746     std::cout << 
"Creating overall PDF\n";
  2748     return overallSignal;
  2754     std::cout << 
"Loading MC data from " << fname << std::endl;
  2775     fmt::print(
"Fit results Toy fit TruthMC fit:\n"  2777                "xmixing: ({:.3})\%\n"  2778                "ymixing: ({:.3})\%\n",
  2792     std::cout << 
"Loading (generated) MC data from " << fname << std::endl;
  2802     if(0 != genResolutions) {
  2805         for(
int i = 0; i < numEvents; ++i) {
  2813                     std::cout << 
"Before smear: " << m12->
getValue() << 
" " << m13->
getValue();
  2815                 smear1 = donram.Gaus(0, dplotres);
  2816                 smear2 = donram.Gaus(0, dplotres);
  2826                 std::cout << 
" After smear: " << m12->
getValue() << 
" " << m13->
getValue() << 
"\n";
  2910     foodal->SaveAs(
"./plots_from_mixfit/efficiency_weights.png");
  2912     vector<Observable> lvars;
  2913     lvars.push_back(*m12);
  2914     lvars.push_back(*m13);
  2916     fname      = app_ptr->
get_filename(
"dataFiles/efficiency_gen.txt", 
"examples/pipipi0DPFit");
  2932     signalDalitz->
setData(smearedData);
  2976     fmt::print(
"Fit results Canonical fit:\n"  2978                "xmixing: ({:.3})\%\n"  2979                "ymixing: ({:.3})\%\n",
  2987     std::string::size_type pos = fname.find(
"mm");
  2989     if(pos != std::string::npos)
  2990         inputx = inputy = -1;
  2992         pos = fname.find(
"mp");
  2994         if(pos != std::string::npos)
  2997             pos = fname.find(
"pm");
  2999             if(pos != std::string::npos)
  3002                 pos = fname.find(
"pp");
  3003                 assert(pos != std::string::npos);
  3008     std::string ident = fname.substr(pos, 4);
  3009     sprintf(strbuffer, 
"result_%s_%f", ident.c_str(), dplotres);
  3011     writer.open(strbuffer);
  3029     Variable bkg2_sigma_num_jsu(
"bkg2_sigma_num_jsu", 9100, 200, 1000, 15000);
  3030     Variable bkg2_sigma_num_ga1(
"bkg2_sigma_num_ga1", 2400, 200, 500, 7000);
  3031     Variable bkg2_sigma_num_ga2(
"bkg2_sigma_num_ga2", 2900, 200, 500, 7000);
  3033     Variable bkg2_sigma_g1_meana(
"bkg2_sigma_g1_meana", 0.35, 0.01, 0.10, 0.50);
  3034     Variable bkg2_sigma_g1_sigma(
"bkg2_sigma_g1_sigma", 0.30, 0.01, 0.05, 0.55);
  3035     Variable bkg2_sigma_g2_meana(
"bkg2_sigma_g2_meana", 0.80, 0.01, 0.01, 1.50);
  3036     Variable bkg2_sigma_g2_sigma(
"bkg2_sigma_g2_sigma", 0.90, 0.01, 0.01, 2.75);
  3040     Variable bkg2_sigma_js_meana(
"bkg2_sigma_js_meana", 0.35, 0.01, 0.00, 0.60);
  3041     Variable bkg2_sigma_js_sigma(
"bkg2_sigma_js_sigma", 0.09, 0.01, 0, 0.4);
  3042     Variable bkg2_sigma_js_gamma(
"bkg2_sigma_js_gamma", 2.00, 0.10, 0, 10);
  3043     Variable bkg2_sigma_js_delta(
"bkg2_sigma_js_delta", 2);
  3045         "bkg2_sigma_js", *sigma, bkg2_sigma_js_meana, bkg2_sigma_js_sigma, bkg2_sigma_js_gamma, bkg2_sigma_js_delta);
  3047     GaussianPdf *bkg2_sigma_g1 = 
new GaussianPdf(
"bkg2_sigma_g1", *sigma, bkg2_sigma_g1_meana, bkg2_sigma_g1_sigma);
  3048     GaussianPdf *bkg2_sigma_g2 = 
new GaussianPdf(
"bkg2_sigma_g2", *sigma, bkg2_sigma_g2_meana, bkg2_sigma_g2_sigma);
  3051     weights.push_back(bkg2_sigma_num_jsu);
  3052     weights.push_back(bkg2_sigma_num_ga1);
  3053     weights.push_back(bkg2_sigma_num_ga2);
  3055     comps.push_back(bkg2_sigma_js);
  3056     comps.push_back(bkg2_sigma_g1);
  3057     comps.push_back(bkg2_sigma_g2);
  3059     GooPdf *ret = 
new AddPdf(
"bkg2_jsugg", weights, comps);
  3072     Variable bkg4_sigma_num_jsu(
"bkg4_sigma_num_jsu", 9100, 200, 1000, 15000);
  3073     Variable bkg4_sigma_num_ga1(
"bkg4_sigma_num_ga1", 2400, 200, 500, 7000);
  3074     Variable bkg4_sigma_num_ga2(
"bkg4_sigma_num_ga2", 2900, 200, 500, 7000);
  3076     Variable bkg4_sigma_g1_meana(
"bkg4_sigma_g1_meana", 0.35, 0.01, 0.10, 0.50);
  3077     Variable bkg4_sigma_g1_sigma(
"bkg4_sigma_g1_sigma", 0.30, 0.01, 0.05, 0.55);
  3078     Variable bkg4_sigma_g2_meana(
"bkg4_sigma_g2_meana", 0.80, 0.01, 0.01, 1.50);
  3079     Variable bkg4_sigma_g2_sigma(
"bkg4_sigma_g2_sigma", 0.90, 0.01, 0.01, 2.75);
  3083     Variable bkg4_sigma_js_meana(
"bkg4_sigma_js_meana", 0.35, 0.01, 0.00, 0.60);
  3084     Variable bkg4_sigma_js_sigma(
"bkg4_sigma_js_sigma", 0.09, 0.01, 0, 0.4);
  3085     Variable bkg4_sigma_js_gamma(
"bkg4_sigma_js_gamma", 2.00, 0.10, 0, 10);
  3086     Variable bkg4_sigma_js_delta(
"bkg4_sigma_js_delta", 2);
  3088         "bkg4_sigma_js", *sigma, bkg4_sigma_js_meana, bkg4_sigma_js_sigma, bkg4_sigma_js_gamma, bkg4_sigma_js_delta);
  3090     GaussianPdf *bkg4_sigma_g1 = 
new GaussianPdf(
"bkg4_sigma_g1", *sigma, bkg4_sigma_g1_meana, bkg4_sigma_g1_sigma);
  3091     GaussianPdf *bkg4_sigma_g2 = 
new GaussianPdf(
"bkg4_sigma_g2", *sigma, bkg4_sigma_g2_meana, bkg4_sigma_g2_sigma);
  3094     weights.push_back(bkg4_sigma_num_jsu);
  3095     weights.push_back(bkg4_sigma_num_ga1);
  3096     weights.push_back(bkg4_sigma_num_ga2);
  3098     comps.push_back(bkg4_sigma_js);
  3099     comps.push_back(bkg4_sigma_g1);
  3100     comps.push_back(bkg4_sigma_g2);
  3102     GooPdf *ret = 
new AddPdf(
"bkg4_jsugg", weights, comps);
  3111     Variable bkg3_sigma_frac_jsu(
"bkg3_sigma_frac_jsu", 0.50, 0.01, 0.01, 1.00);
  3112     Variable bkg3_sigma_frac_ga1(
"bkg3_sigma_frac_ga1", 0.04, 0.01, 0.01, 0.20);
  3119     Variable bkg3_sigma_g1_meana(
"bkg3_sigma_g1_meana", 0.35, 0.01, 0.10, 0.50);
  3120     Variable bkg3_sigma_g1_sigma(
"bkg3_sigma_g1_sigma", 0.10, 0.01, 0.01, 0.55);
  3121     Variable bkg3_sigma_g2_meana(
"bkg3_sigma_g2_meana", 0.20, 0.01, 0.01, 1.50);
  3122     Variable bkg3_sigma_g2_sigma(
"bkg3_sigma_g2_sigma", 0.10, 0.01, 0.001, 0.15);
  3123     Variable bkg3_sigma_g2_gamma(
"bkg3_sigma_g2_gamma", -2.00, 1.00, -10, 10);
  3124     Variable bkg3_sigma_g2_delta(
"bkg3_sigma_g2_delta", 2, 0.10, 0.50, 5.00);
  3131     Variable bkg3_sigma_js_meana(
"bkg3_sigma_js_meana", 0.35, 0.01, 0.00, 0.60);
  3132     Variable bkg3_sigma_js_sigma(
"bkg3_sigma_js_sigma", 0.09, 0.01, 0, 0.40);
  3133     Variable bkg3_sigma_js_gamma(
"bkg3_sigma_js_gamma", 2.00, 0.10, 0, 10);
  3134     Variable bkg3_sigma_js_delta(
"bkg3_sigma_js_delta", 2);
  3136         "bkg3_sigma_js", *sigma, bkg3_sigma_js_meana, bkg3_sigma_js_sigma, bkg3_sigma_js_gamma, bkg3_sigma_js_delta);
  3140     GaussianPdf *bkg3_sigma_g1 = 
new GaussianPdf(
"bkg3_sigma_g1", *sigma, bkg3_sigma_g1_meana, bkg3_sigma_g1_sigma);
  3145         "bkg3_sigma_g2", *sigma, bkg3_sigma_g2_meana, bkg3_sigma_g2_sigma, bkg3_sigma_g2_gamma, bkg3_sigma_g2_delta);
  3155     weights.push_back(bkg3_sigma_frac_jsu);
  3156     weights.push_back(bkg3_sigma_frac_ga1);
  3158     comps.push_back(bkg3_sigma_js);
  3159     comps.push_back(bkg3_sigma_g1);
  3160     comps.push_back(bkg3_sigma_g2);
  3163     GooPdf *ret = 
new AddPdf(
"bkg3_jsugg", weights, comps);
  3178     std::string bkgname = 
"";
  3182         frac_ga2 = 
new Variable(
"bkg4_frac_ga2", 0.60780, 0.01, 0.40, 0.80);
  3183         frac_ga3 = 
new Variable(
"bkg4_frac_ga3", 0.04776, 0.01, 0.00, 0.20);
  3184         g1_meana = 
new Variable(
"bkg4_g1_meana", 0.10164, 0.01, 0.00, 0.80);
  3185         g1_sigma = 
new Variable(
"bkg4_g1_sigma", 0.27504, 0.01, 0.10, 0.80);
  3186         g2_meana = 
new Variable(
"bkg4_g2_meana", 0.19974, 0.01, 0.10, 0.80);
  3187         g2_sigma = 
new Variable(
"bkg4_g2_sigma", 0.63765, 0.01, 0.40, 0.80);
  3188         g3_meana = 
new Variable(
"bkg4_g3_meana", 0.45817, 0.01, 0.20, 0.80);
  3189         g3_sigma = 
new Variable(
"bkg4_g3_sigma", 1.52905, 0.01, 1.40, 1.80);
  3194         frac_ga2 = 
new Variable(
"bkg3_frac_ga2", 0.51448, 0.01, 0.25, 0.75);
  3195         frac_ga3 = 
new Variable(
"bkg3_frac_ga3", 0.04169, 0.01, 0.00, 0.40);
  3196         g1_meana = 
new Variable(
"bkg3_g1_meana", 0.25101, 0.01, 0.01, 0.50);
  3197         g1_sigma = 
new Variable(
"bkg3_g1_sigma", 0.31953, 0.01, 0.02, 0.50);
  3198         g2_meana = 
new Variable(
"bkg3_g2_meana", 0.49139, 0.01, 0.25, 0.75);
  3199         g2_sigma = 
new Variable(
"bkg3_g2_sigma", 0.65443, 0.01, 0.10, 1.00);
  3200         g3_meana = 
new Variable(
"bkg3_g3_meana", 0.83600, 0.01, 0.50, 1.00);
  3201         g3_sigma = 
new Variable(
"bkg3_g3_sigma", 1.51839, 0.01, 0.10, 2.00);
  3207         frac_ga2 = 
new Variable(
"frac_ga2", 0.48994, 0.01, 0.1, 0.6);
  3208         frac_ga3 = 
new Variable(
"frac_ga3", 0.04721, 0.01, 0.0, 0.1);
  3209         g1_meana = 
new Variable(
"g1_meana", 0.01216, 0.01, -0.1, 0.1);
  3210         g1_sigma = 
new Variable(
"g1_sigma", 0.25813, 0.01, 0.15, 0.35);
  3211         g2_meana = 
new Variable(
"g2_meana", 0.05335, 0.01, -0.1, 0.1);
  3212         g2_sigma = 
new Variable(
"g2_sigma", 0.58651, 0.01, 0.5, 1.2);
  3213         g3_meana = 
new Variable(
"g3_meana", 0.17451, 0.01, 0.1, 1.85);
  3214         g3_sigma = 
new Variable(
"g3_sigma", 1.15125, 0.01, 0.5, 1.3);
  3224     weights.push_back(*frac_ga2);
  3227         weights.push_back(*frac_ga3);
  3230     comps.push_back(g2);
  3233         comps.push_back(g3);
  3235     comps.push_back(g1);
  3236     AddPdf *bkg_dtime = 
new AddPdf((bkgname + 
"_dtime").c_str(), weights, comps);
  3241     std::string bkgname = 
"";
  3258     Variable g1_mean((bkgname + 
"_dtime_gmean1"), 0, 0.01, -0.5, 0.5);
  3259     Variable g1_sigm((bkgname + 
"_dtime_gsigm1"), 0.2, 0.01, 0.01, 0.8);
  3260     Variable e1_alph((bkgname + 
"_dtime_alpha1"), 2.5, 0.01, 0.01, 7.5);
  3262     Variable g2_mean((bkgname + 
"_dtime_gmean2"), -0.3, 0.01, -0.85, 0.85);
  3263     Variable g2_sigm((bkgname + 
"_dtime_gsigm2"), 0.2, 0.01, 0.01, 0.8);
  3264     Variable e2_alph((bkgname + 
"_dtime_alpha2"), 0.5, 0.01, 0.01, 10.0);
  3269     Variable frac1((bkgname + 
"_dtime_frac1"), 0.1, 0.01, 0, 0.8);
  3271     GooPdf *ret = 
new AddPdf((bkgname + 
"_dtime"), frac1, exp1, exp2);
  3280     GooPdf *bkg2_dalitz = 
nullptr;
  3285         vector<Variable> offsets;
  3286         vector<Observable> observables;
  3287         vector<Variable> coefficients;
  3290         observables.push_back(*m12);
  3291         observables.push_back(*m13);
  3292         double weightOffset = 3;
  3294         coefficients.push_back(
Variable(
"bkg2_x0y0", 1.0 * weightOffset));
  3295         coefficients.push_back(
  3296             Variable(
"bkg2_x1y0", 0.13184 * weightOffset, 0.01, 0.01 * weightOffset, 0.18 * weightOffset));
  3297         coefficients.push_back(
  3298             Variable(
"bkg2_x2y0", 0.02062 * weightOffset, 0.01, 0.00 * weightOffset, 0.17 * weightOffset));
  3299         coefficients.push_back(
  3300             Variable(
"bkg2_x3y0", 0.04688 * weightOffset, 0.01, 0.00 * weightOffset, 0.08 * weightOffset));
  3301         coefficients.push_back(
  3302             Variable(
"bkg2_x0y1", -0.02568 * weightOffset, 0.01, -0.15 * weightOffset, 0.04 * weightOffset));
  3303         coefficients.push_back(
  3304             Variable(
"bkg2_x1y1", 0.06805 * weightOffset, 0.01, 0.02 * weightOffset, 0.10 * weightOffset));
  3305         coefficients.push_back(
  3306             Variable(
"bkg2_x2y1", 0.38557 * weightOffset, 0.01, 0.30 * weightOffset, 0.50 * weightOffset));
  3307         coefficients.push_back(
  3308             Variable(
"bkg2_x0y2", 0.11252 * weightOffset, 0.01, 0.05 * weightOffset, 0.20 * weightOffset));
  3309         coefficients.push_back(
  3310             Variable(
"bkg2_x1y2", 0.24896 * weightOffset, 0.01, 0.20 * weightOffset, 0.50 * weightOffset));
  3311         coefficients.push_back(
  3312             Variable(
"bkg2_x0y3", 0.05605 * weightOffset, 0.01, -0.05 * weightOffset, 0.15 * weightOffset));
  3316         Variable bkg2_decZmin(
"bkg2_decZmin", 3.30411);
  3317         Variable bkg2_conZmin(
"bkg2_conZmin", 0.29909);
  3323         comps.push_back(poly);
  3324         comps.push_back(bkg2_loZ);
  3325         comps.push_back(kzero_veto);
  3341             Variable(
"bkg2_rho_ref_amp", 0.00896 * weightOffset, 0.001, 0, 0.015 * weightOffset),
  3343             Variable(
"bkg2_rho_ref_mass", 0.53172),
  3344             Variable(
"bkg2_rho_ref_width", 0.06426),
  3346         special_rho_decay.
resonances.push_back(bkg2_rho_ref);
  3348         Variable bkg2_rho_poly_offset(
"bkg2_rho_poly_offset", 1.64254);
  3349         Variable bkg2_rho_poly_linear(
"bkg2_rho_poly_linear", 0);
  3350         Variable bkg2_rho_poly_second(
"bkg2_rho_poly_second", -0.48166);
  3353         weights.push_back(bkg2_rho_poly_linear);
  3354         weights.push_back(bkg2_rho_poly_second);
  3357         comps.push_back(kzero_veto);
  3358         comps.push_back(bkg2_rho_poly);
  3359         comps.push_back(bkg2_loZ);
  3361         incsum1 = 
new IncoherentSumPdf(
"incsum1", *m12, *m13, *eventNumber, special_rho_decay, bkg2_rho_mods);
  3373             Variable(
"bkg2_incRho0_amp", 0.00304 * weightOffset, 0.001, 0.0, 0.006 * weightOffset),
  3379         incoherent_rho0s.
resonances.push_back(bkg2_incRho0);
  3383             Variable(
"bkg2_incRhoP_amp", 0.00586 * weightOffset, 0.001, 0.0, 0.012 * weightOffset),
  3389         incoherent_rho0s.
resonances.push_back(bkg2_incRhoP);
  3393             Variable(
"bkg2_incRhoM_amp", 0.00635 * weightOffset, 0.001, 0.0, 0.015 * weightOffset),
  3399         incoherent_rho0s.
resonances.push_back(bkg2_incRhoM);
  3402         comps.push_back(kzero_veto);
  3403         comps.push_back(bkg2_loZ);
  3406         incsum2 = 
new IncoherentSumPdf(
"incsum2", *m12, *m13, *eventNumber, incoherent_rho0s, bkg2_rho_mods2);
  3413         comps.push_back(poly_x_veto);
  3414         comps.push_back(incsum1);
  3415         comps.push_back(incsum2);
  3417         bkg2_dalitz = 
new AddPdf(
"bkg2_dalitz", weights, comps);
  3428         std::string fname = app_ptr->
get_filename(
"dataFiles/sideband1.txt", 
"examples/pipipi0DPFit");
  3430         fname = app_ptr->
get_filename(
"dataFiles/sideband2.txt", 
"examples/pipipi0DPFit");
  3435         weights.push_back(
Variable(
"sband1Weight", 300000, 1000, 100, 750000));
  3436         weights.push_back(
Variable(
"sband2Weight", 100000, 1000, 100, 500000));
  3439         bkg2_dalitz = 
new AddPdf(
"bkg2_dalitz", weights, comps);
  3445     GooPdf *bkg2_dtime = 
nullptr;
  3463     comps.push_back(bkg2_dalitz);
  3464     comps.push_back(bkg2_dtime);
  3465     comps.push_back(bkg2_jsugg);
  3480     obsweights.push_back(*m12);
  3481     obsweights.push_back(*m13);
  3489     std::ifstream reader;
  3490     std::string fname = app_ptr->
get_filename(
"dataFiles/efficiency_bkg3_flat.txt", 
"examples/pipipi0DPFit");
  3494     while(!reader.eof()) {
  3497         if(buffer == 
"====")
  3500         std::cout << buffer;
  3505     while(!reader.eof()) {
  3516         for(
int i = 0; i < 16; ++i)
  3522     Variable bkg3_eff_smoothing(
"bkg3_eff_smoothing", 1.0, 0.1, 0, 1.25);
  3533     std::ifstream reader;
  3534     sprintf(strbuffer, 
"./dataFiles/bkgDalitz_%i.txt", bkgnum);
  3536     if(overridename != 
"")
  3537         sprintf(strbuffer, 
"%s", overridename.c_str());
  3539     std::string fname = app_ptr->
get_filename(strbuffer, 
"examples/pipipi0DPFit");
  3543     while(!reader.eof()) {
  3546         if(buffer == 
"====")
  3549         std::cout << buffer;
  3553     obsweights.push_back(*m12);
  3554     obsweights.push_back(*m13);
  3559     while(!reader.eof()) {
  3566         for(
int i = 0; i < 16; ++i)
  3574     std::cout << 
"Read " << bkg_binned_data->
getNumEvents() << 
" events for background " << bkgnum << std::endl;
  3575     sprintf(strbuffer, 
"bkg%i_dalitz_smoothing", bkgnum);
  3579         std::cout << 
"Shuffling background " << bkgnum << 
" histogram with random seed " << 
bkgHistRandSeed  3583         for(
unsigned int bin = 0; bin < bkg_binned_data->
getNumBins(); ++bin) {
  3589             double newEvents = -1;
  3591             while(0 > newEvents)
  3592                 newEvents = donram.Gaus(events, sqrt(events));
  3598     sprintf(strbuffer, 
"bkg%i_dalitz", bkgnum);
  3610     vector<Variable> offsets;
  3611     vector<Observable> observables;
  3612     vector<Variable> coefficients;
  3616     observables.push_back(*m12);
  3617     observables.push_back(*m13);
  3619     double weightOffset = 1;
  3621     coefficients.push_back(
Variable(
"bkg3_x0y0", 1.00 * weightOffset));
  3624     coefficients.push_back(
  3625         Variable(
"bkg3_x1y0", -0.36937 * weightOffset, 0.01, -1.50 * weightOffset, 0.00 * weightOffset));
  3626     coefficients.push_back(
  3627         Variable(
"bkg3_x2y0", 1.36184 * weightOffset, 0.01, -0.10 * weightOffset, 1.60 * weightOffset));
  3630     coefficients.push_back(
  3631         Variable(
"bkg3_x0y1", -0.27691 * weightOffset, 0.01, -1.50 * weightOffset, 0.00 * weightOffset));
  3632     coefficients.push_back(
  3633         Variable(
"bkg3_x1y1", 2.16029 * weightOffset, 0.01, 0.30 * weightOffset, 4.50 * weightOffset));
  3636     coefficients.push_back(
  3637         Variable(
"bkg3_x0y2", 1.33100 * weightOffset, 0.01, 1.00 * weightOffset, 2.00 * weightOffset));
  3661     comps.push_back(poly);
  3662     comps.push_back(kzero_veto);
  3679         Variable(
"bkg3_pi0_ref_amp", 0.01189 * weightOffset, 0.01, 0.00 * weightOffset, 0.25 * weightOffset),
  3681         Variable(
"bkg3_pi0_ref_mass", 1.65766, 0.01, 1.4, 1.8),
  3682         Variable(
"bkg3_pi0_ref_width", 0.05018, 0.01, 0.02, 0.20),
  3684     special_pi0_decay.
resonances.push_back(bkg3_pi0_ref);
  3688     Variable bkg3_pi0_transZ_offset(
"bkg3_pi0_transZ_offset", -0.04381);
  3690     observables.clear();
  3691     coefficients.clear();
  3692     observables.push_back(*m12);
  3693     observables.push_back(*m13);
  3694     coefficients.push_back(bkg3_pi0_transZ_offset);
  3703     Variable bkg3_pi0_transZ_quad(
"bkg3_pi0_transZ_quad", 2.12277);
  3704     coefficients.clear();
  3707     coefficients.push_back(bkg3_pi0_transZ_quad);
  3714     comps.push_back(kzero_veto);
  3715     comps.push_back(bkg3_pi0_transZ_total);
  3731         Variable(
"bkg3_incRho0_amp", 0.00807 * weightOffset, 0.01, 0.00 * weightOffset, 0.25 * weightOffset),
  3733         Variable(
"bkg3_incRho0_mass", 0.800, 0.01, 0.6, 1.0),
  3734         Variable(
"bkg3_incRho0_width", 0.15, 0.01, 0.10, 0.40),
  3737     incoherent_rhos.
resonances.push_back(bkg3_incRho0);
  3741         Variable(
"bkg3_incRhoP_amp", 0.01683 * weightOffset, 0.01, 0.00 * weightOffset, 0.25 * weightOffset),
  3743         Variable(
"bkg3_incRhoP_mass", 0.800, 0.01, 0.6, 1.0),
  3744         Variable(
"bkg3_incRhoP_width", 0.15, 0.01, 0.10, 0.40),
  3747     incoherent_rhos.
resonances.push_back(bkg3_incRhoP);
  3751         Variable(
"bkg3_incRhoM_amp", 0.01645 * weightOffset, 0.01, 0.00 * weightOffset, 0.25 * weightOffset),
  3753         Variable(
"bkg3_incRhoM_mass", 0.900, 0.01, 0.6, 1.0),
  3754         Variable(
"bkg3_incRhoM_width", 0.35, 0.01, 0.10, 0.60),
  3757     incoherent_rhos.
resonances.push_back(bkg3_incRhoM);
  3760     comps.push_back(kzero_veto);
  3773     comps.push_back(poly_x_veto);
  3777     AddPdf *bkg3_dalitz = 
new AddPdf(
"bkg3_dalitz", weights, comps);
  3783     vector<Variable> offsets;
  3784     vector<Observable> observables;
  3785     vector<Variable> coefficients;
  3789     observables.push_back(*m12);
  3790     observables.push_back(*m13);
  3793     double weightOffset = 3;
  3796     coefficients.push_back(
Variable(
"bkg4_x0y0", 1.0 * weightOffset));
  3797     coefficients.push_back(
  3798         Variable(
"bkg4_x1y0", -0.18594 * weightOffset, 0.01, -0.50 * weightOffset, 0.50 * weightOffset));
  3799     coefficients.push_back(
  3800         Variable(
"bkg4_x2y0", 0.45459 * weightOffset, 0.01, 0.25 * weightOffset, 0.75 * weightOffset));
  3801     coefficients.push_back(
  3802         Variable(
"bkg4_x3y0", -0.20869 * weightOffset, 0.01, -0.50 * weightOffset, 0.50 * weightOffset));
  3803     coefficients.push_back(
  3804         Variable(
"bkg4_x0y1", -0.65061 * weightOffset, 0.01, -1.50 * weightOffset, 0.50 * weightOffset));
  3805     coefficients.push_back(
  3806         Variable(
"bkg4_x1y1", 0.11000 * weightOffset, 0.01, 0.00 * weightOffset, 0.50 * weightOffset));
  3807     coefficients.push_back(
  3808         Variable(
"bkg4_x2y1", 0.42009 * weightOffset, 0.01, 0.25 * weightOffset, 1.00 * weightOffset));
  3809     coefficients.push_back(
  3810         Variable(
"bkg4_x0y2", -0.06151 * weightOffset, 0.01, -0.50 * weightOffset, 0.50 * weightOffset));
  3811     coefficients.push_back(
  3812         Variable(
"bkg4_x1y2", 0.58508 * weightOffset, 0.01, 0.20 * weightOffset, 1.50 * weightOffset));
  3813     coefficients.push_back(
  3814         Variable(
"bkg4_x0y3", 0.54740 * weightOffset, 0.01, 0.20 * weightOffset, 1.50 * weightOffset));
  3818     Variable bkg4_decZmin(
"bkg4_decZmin", 2.77576);
  3819     Variable bkg4_conZmin(
"bkg4_conZmin", 0.23328);
  3824     comps.push_back(poly);
  3825     comps.push_back(bkg4_loZ);
  3826     comps.push_back(kzero_veto);
  3840                                                         Variable(
"bkg4_pipi_ref_amp", 0.00147 * weightOffset),
  3842                                                         Variable(
"bkg4_pipi_ref_mass", 1.32447),
  3843                                                         Variable(
"bkg4_pipi_ref_width", 0.04675),
  3845     special_pipi_decay.
resonances.push_back(bkg4_pipi_ref);
  3848     Variable bkg4_pipi_transZ_offset(
"bkg4_pipi_transZ_offset", -0.39877);
  3851     observables.clear();
  3852     coefficients.clear();
  3853     observables.push_back(*m12);
  3854     observables.push_back(*m13);
  3855     coefficients.push_back(bkg4_pipi_transZ_offset);
  3863     Variable bkg4_pipi_transZ_quad(
"bkg4_pipi_transZ_quad", -0.25640);
  3864     coefficients.clear();
  3867     coefficients.push_back(bkg4_pipi_transZ_quad);
  3872         = 
new CompositePdf(
"bkg4_pipi_transZ_total", bkg4_pipi_transZ, bkg4_pipi_shell);
  3875     comps.push_back(kzero_veto);
  3876     comps.push_back(bkg4_loZ);
  3877     comps.push_back(bkg4_pipi_transZ_total);
  3880     incsum5 = 
new IncoherentSumPdf(
"incsum5", *m12, *m13, *eventNumber, special_pipi_decay, bkg4_pipi_mods);
  3891                                                      Variable(
"bkg4_incRho0_amp", 0.00429 * weightOffset),
  3897     incoherent_rho0s.
resonances.push_back(bkg4_incRho0);
  3900                                                      Variable(
"bkg4_incRhoP_amp", 0.00705 * weightOffset),
  3906     incoherent_rho0s.
resonances.push_back(bkg4_incRhoP);
  3909                                                      Variable(
"bkg4_incRhoM_amp", -0.00043 * weightOffset),
  3915     incoherent_rho0s.
resonances.push_back(bkg4_incRhoM);
  3918     comps.push_back(kzero_veto);
  3919     comps.push_back(bkg4_loZ);
  3920     ProdPdf *bkg4_incrho_mods = 
new ProdPdf(
"bkg4_incrho_mods", comps);
  3921     incsum6 = 
new IncoherentSumPdf(
"incsum6", *m12, *m13, *eventNumber, incoherent_rho0s, bkg4_incrho_mods);
  3929     comps.push_back(poly_x_veto);
  3930     comps.push_back(incsum5);
  3931     comps.push_back(incsum6);
  3933     AddPdf *bkg4_dalitz = 
new AddPdf(
"bkg4_dalitz", weights, comps);
  3952     GooPdf *bkg3_dalitz = 
nullptr;
  3961     GooPdf *bkg3_dtime = 
nullptr;
  3980     comps.push_back(bkg3_dalitz);
  3983     comps.push_back(bkg3_dtime);
  4003     GooPdf *bkg4_dalitz = 
nullptr;
  4010     GooPdf *bkg4_dtime = 
nullptr;
  4024     comps.push_back(bkg4_dalitz);
  4025     comps.push_back(bkg4_dtime);
  4043     std::cout << 
"Loading events from " << fname << std::endl;
  4046     std::cout << 
"Creating overall signal PDF\n";
  4063     std::cout << 
"Creating background PDFs\n";
  4071     std::cout << 
"Reading bkg2 parameters from " << strbuffer << std::endl;
  4075     std::cout << 
"Reading bkg3 parameters from " << strbuffer << std::endl;
  4078     std::cout << 
"Reading bkg4 parameters from " << strbuffer << std::endl;
  4087     int eventSize = massd0 ? 11 : 10;
  4088     std::cout << 
"Setting data size " << eventSize << std::endl;
  4111     std::cout << 
"Creating overall PDF\n";
  4112     std::vector<Observable> evtWeights;
  4113     evtWeights.push_back(*wSig0);
  4114     evtWeights.push_back(*wBkg2);
  4115     evtWeights.push_back(*wBkg3);
  4116     evtWeights.push_back(*wBkg4);
  4117     std::vector<PdfBase *> components;
  4118     components.push_back(overallSignal);
  4119     components.push_back(bkg2Pdf);
  4120     components.push_back(bkg3Pdf);
  4121     components.push_back(bkg4Pdf);
  4124     std::cout << 
"Copying data to GPU\n";
  4156     fmt::print(
"Fit results Canonical fit:\n"  4157                "tau    : ({:.3}) fs\n"  4158                "xmixing: ({:.3})\%\n"  4159                "ymixing: ({:.3})\%\n",
  4198     loM23Sigma->SetStats(
false);
  4200     hiM23Sigma->SetStats(
false);
  4220     sprintf(strbuffer, 
"signal_sigma_%islices_pdf.txt", 
m23Slices);
  4226     std::vector<Observable> gridvars;
  4227     gridvars.push_back(*m12);
  4228     gridvars.push_back(*m13);
  4229     gridvars.push_back(*sigma);
  4232     TH1F *sigma_pdfs[6];
  4233     TH1F *sigma_data[6];
  4234     double num_sigma_dat[6];
  4235     double num_sigma_pdf[6];
  4237     for(
int i = 0; i < 6; ++i) {
  4238         sprintf(strbuffer, 
"sigma_pdf_%i", i);
  4240         sprintf(strbuffer, 
"sigma_dat_%i", i);
  4243         num_sigma_dat[i] = 0;
  4244         num_sigma_pdf[i] = 0;
  4246         sigma_data[i]->SetStats(
false);
  4247         sigma_data[i]->SetMarkerStyle(8);
  4248         sigma_data[i]->SetMarkerSize(1.2);
  4249         sigma_data[i]->GetXaxis()->SetTitle(
"Decay time error [ps]");
  4250         sigma_data[i]->GetYaxis()->SetTitle(
"Events / 8 fs");
  4252         sigma_pdfs[i]->SetStats(
false);
  4253         sigma_pdfs[i]->SetLineColor(kBlue);
  4254         sigma_pdfs[i]->SetLineWidth(3);
  4257     double totalPdf = 0;
  4258     double totalDat = 0;
  4260     for(
unsigned int evt = 0; evt < data->
getNumEvents(); ++evt) {
  4261         double currSigma = data->
getValue(*sigma, evt);
  4262         double currm12   = data->
getValue(*m12, evt);
  4263         double currm13   = data->
getValue(*m13, evt);
  4264         double currm23   = 
cpuGetM23(currm12, currm13);
  4265         int m23bin       = (int)floor(currm23 / 0.5);
  4266         sigma_data[m23bin]->Fill(currSigma);
  4267         num_sigma_dat[m23bin]++;
  4280             for(
int k = 0; k < sigma->
getNumBins(); ++k) {
  4291     for(
unsigned int j = 0; j < pdfValues[0].size(); ++j) {
  4292         double currM12   = grid.
getValue(*m12, j);
  4293         double currM13   = grid.
getValue(*m13, j);
  4294         double currSigma = grid.
getValue(*sigma, j);
  4295         double currm23   = 
cpuGetM23(currM12, currM13);
  4296         int m23bin       = (int)floor(currm23 / 0.5);
  4297         sigma_pdfs[m23bin]->Fill(currSigma, pdfValues[0][j]);
  4298         num_sigma_pdf[m23bin] += pdfValues[0][j];
  4299         totalPdf += pdfValues[0][j];
  4302     for(
int i = 1; i <= sigma->
getNumBins(); ++i) {
  4303         for(
int j = 0; j < 6; ++j) {
  4304             sigma_pdfs[j]->SetBinContent(i, sigma_pdfs[j]->GetBinContent(i) * num_sigma_dat[j] / num_sigma_pdf[j]);
  4308     std::string plotdir = 
"./plots_from_mixfit/";
  4310     for(
int i = 0; i < 6; ++i) {
  4311         if(sigma_data[i]->GetMaximum() > sigma_pdfs[i]->GetMaximum()) {
  4312             sigma_data[i]->Draw(
"p");
  4313             sigma_pdfs[i]->Draw(
"lsame");
  4315             sigma_pdfs[i]->Draw(
"l");
  4316             sigma_data[i]->Draw(
"psame");
  4319         sprintf(strbuffer, 
"%i", i);
  4321         slicenum.DrawTextNDC(0.2, 0.8, strbuffer);
  4323         foo->SaveAs((plotdir + sigma_pdfs[i]->GetName() + 
".png").c_str());
  4325         foo->SaveAs((plotdir + sigma_pdfs[i]->GetName() + 
"_log.png").c_str());
  4326         foo->SetLogy(
false);
  4373     vector<Observable *> lvars;
  4374     lvars.push_back(m12);
  4375     lvars.push_back(m13);
  4383     std::string fname_3flat = app_ptr->
get_filename(
"dataFiles/efficiency_bkg3_flat.txt", 
"examples/pipipi0DPFit");
  4384     std::string fname_flat  = app_ptr->
get_filename(
"dataFiles/efficiency_flat.txt", 
"examples/pipipi0DPFit");
  4394         foo->SaveAs(
"./plots_from_mixfit/efficiency_bins.png");
  4413     TH2F dalitz_dat_hist(
"dalitz_dat_hist",
  4421     dalitz_dat_hist.SetStats(
false);
  4422     dalitz_dat_hist.GetXaxis()->SetTitle(
"m^{2}(#pi^{+} #pi^{0}) [GeV]");
  4423     dalitz_dat_hist.GetYaxis()->SetTitle(
"m^{2}(#pi^{-} #pi^{0}) [GeV]");
  4424     TH2F dalitz_pdf_hist(
"dalitz_pdf_hist",
  4432     dalitz_pdf_hist.SetStats(
false);
  4434     double totalPdf = 0;
  4435     double totalDat = 0;
  4437     for(
unsigned int evt = 0; evt < data->
getNumEvents(); ++evt) {
  4438         double currval = data->
getValue(*m12, evt);
  4440         double currval2 = data->
getValue(*m13, evt);
  4442         dalitz_dat_hist.Fill(currval, currval2);
  4446     std::vector<Observable> nvars;
  4447     nvars.push_back(*m12);
  4448     nvars.push_back(*m13);
  4469     for(
unsigned int j = 0; j < pdfValues[0].size(); ++j) {
  4470         double currVal = currData.
getValue(*m12, j);
  4472         double currVal2 = currData.
getValue(*m13, j);
  4474         dalitz_pdf_hist.Fill(currVal, currVal2, pdfValues[0][j]);
  4476         totalPdf += pdfValues[0][j];
  4478         if(std::isnan(pdfValues[0][j])) {
  4479             std::cout << 
"Major problem: " << currVal << 
" " << currVal2 << 
" " << j << std::endl;
  4483         if(std::isinf(pdfValues[0][j])) {
  4484             std::cout << 
"Infinity " << j << std::endl;
  4497     for(
int i = 1; i <= m12->
getNumBins(); ++i) {
  4498         for(
int j = 1; j <= m13->
getNumBins(); ++j) {
  4499             double currNormEff = dalitz_pdf_hist.GetBinContent(i, j) * totalDat / totalPdf;
  4500             dalitz_pdf_hist.SetBinContent(i, j, currNormEff);
  4502             if(currNormEff >= 50)
  4503                 std::cout << 
"High efficiency: " << currNormEff << 
" " << i << 
" " << j << std::endl;
  4509     dalitz_dat_hist.GetZaxis()->SetRangeUser(0, 40);
  4510     dalitz_dat_hist.Draw(
"colz");
  4511     foodal->SaveAs(
"./plots_from_mixfit/efficiency_dat.png");
  4513     dalitz_pdf_hist.GetZaxis()->SetRangeUser(0, 40);
  4514     dalitz_pdf_hist.Draw(
"colz");
  4515     foodal->SaveAs(
"./plots_from_mixfit/efficiency_pdf.png");
  4518     TH1F pullplot(
"pullplot", 
"", 100, -5, 5);
  4519     TH1F hiM23pullplot(
"hiM23pullplot", 
"", 100, -5, 5);
  4520     TH1F loM23pullplot(
"loM23pullplot", 
"", 100, -5, 5);
  4522     for(
int i = 1; i <= m12->
getNumBins(); ++i) {
  4528         for(
int j = 1; j <= m13->
getNumBins(); ++j) {
  4533                 dalitz_dat_hist.SetBinContent(i, j, 0);
  4538                 dalitz_dat_hist.SetBinContent(i, j, 0);
  4546                 dalitz_dat_hist.SetBinContent(i, j, 0);
  4551                 dalitz_dat_hist.SetBinContent(i, j, 0);
  4555             double dat = dalitz_dat_hist.GetBinContent(i, j);
  4556             double pdf = dalitz_pdf_hist.GetBinContent(i, j);
  4558             double pull = (dat - pdf) / sqrt(max(1.0, dat));
  4560             dalitz_dat_hist.SetBinContent(i, j, pull);
  4561             pullplot.Fill(pull);
  4563             double currm12 = dalitz_dat_hist.GetXaxis()->GetBinCenter(i);
  4564             double currm13 = dalitz_dat_hist.GetYaxis()->GetBinCenter(j);
  4569             if((currm13 > 2) || (currm12 > 2))
  4570                 hiM23pullplot.Fill(pull);
  4572                 loM23pullplot.Fill(pull);
  4577     dalitz_dat_hist.GetZaxis()->SetRangeUser(-5, 5);
  4578     dalitz_dat_hist.Draw(
"colz");
  4579     foodal->SaveAs(
"./plots_from_mixfit/efficiency_pull.png");
  4583     foo->SaveAs(
"./plots_from_mixfit/effpull.png");
  4585     hiM23pullplot.Draw();
  4586     foo->SaveAs(
"./plots_from_mixfit/hieffpull.png");
  4588     loM23pullplot.Draw();
  4589     foo->SaveAs(
"./plots_from_mixfit/loeffpull.png");
  4615     sprintf(strbuffer, 
"./dataFiles/bkgDalitz_%i.txt", bkgType);
  4616     std::string fname = app_ptr->
get_filename(strbuffer, 
"examples/pipipi0DPFit");
  4660         std::string fname = app_ptr->
get_filename(strbuffer, 
"examples/pipipi0DPFit");
  4669         sprintf(strbuffer, 
"./bkg_%i_mikhail.txt", bkgType);
  4673                 sprintf(strbuffer, 
"./bkg_2_pdf_sideband_%islices.txt", 
m23Slices);
  4675                 sprintf(strbuffer, 
"./bkg_2_pdf_%islices.txt", 
m23Slices);
  4677             std::string pdftype;
  4682             sprintf(strbuffer, 
"./bkg_%i_pdf%s.txt", bkgType, pdftype.c_str());
  4691     std::cout << 
"Loading MC data from " << fname << std::endl;
  4695     timeMean.SetStats(
false);
  4696     timeMean.SetLineWidth(3);
  4697     timeMean.SetXTitle(
"#pi#pi#pi^{0} mass [GeV]");
  4698     timeMean.SetYTitle(
"Mean of decay time [ps]");
  4699     TH2F timeVsMass(
"timeVsMass",
  4707     timeVsMass.SetStats(
false);
  4708     timeVsMass.GetXaxis()->SetTitle(
"#pi#pi#pi^{0} mass [GeV]");
  4709     timeVsMass.GetYaxis()->SetTitle(
"Decay time [ps]");
  4711     int colors[6] = {kViolet + 1, kBlue, kCyan, kGreen, kYellow, kRed};
  4715     for(
int i = 0; i < 6; ++i) {
  4716         sprintf(strbuffer, 
"timePlot_%i.png", i);
  4718         timePlots[i]->SetStats(
false);
  4719         timePlots[i]->SetXTitle(
"Decay time [ps]");
  4720         timePlots[i]->SetYTitle(
"Ratio");
  4721         timePlots[i]->SetLineWidth(3);
  4722         timePlots[i]->SetLineColor(colors[i]);
  4727         sprintf(strbuffer, 
"massPlot_%i.png", i);
  4729         massPlots[i]->SetStats(
false);
  4730         massPlots[i]->SetLineWidth(3);
  4731         massPlots[i]->SetLineColor(colors[i]);
  4746         timePlots[slice]->Fill(dtime->
getValue());
  4750         massPlots[slice]->Fill(massd0->
getValue());
  4755     timePlots[3]->SetMinimum(0);
  4756     timePlots[3]->Draw(
"hist");
  4758     for(
int i = 0; i < 6; ++i) {
  4760         timePlots[i]->Draw(
"histsame");
  4761         timeMean.SetBinContent(i + 1, timePlots[i]->GetMean());
  4762         timeMean.SetBinError(i + 1, timePlots[i]->GetMeanError());
  4765     foo->SaveAs(
"timePlots.png");
  4767     foo->SaveAs(
"timeMeanPlot.png");
  4770     massPlots[2]->GetYaxis()->SetRangeUser(0, massPlots[2]->GetMaximum() * 1.1);
  4771     massPlots[2]->Draw(
"");
  4773     for(
int i = 0; i < 5; ++i) {
  4775         massPlots[i]->Draw(
"same");
  4778     foo->SaveAs(
"massPlots.png");
  4780     timeVsMass.Draw(
"colz");
  4782     for(
int i = 0; i < 6; ++i) {
  4788         currLine->SetLineWidth(12);
  4789         currLine->SetLineColor(colors[i]);
  4799         currLine->SetLineWidth(12);
  4800         currLine->SetLineColor(colors[i]);
  4804     foo->SaveAs(
"timeVsMass.png");
  4820         loM23Sigma->SetStats(
false);
  4822         hiM23Sigma->SetStats(
false);
  4828     sprintf(strbuffer, 
"./dataFiles/bkgDalitz_%i.txt", bkgType);
  4829     std::string fname = app_ptr->
get_filename(strbuffer, 
"examples/pipipi0DPFit");
  4848     plotFit(*sigma, data, bkgPdf);
  4860     thrust::host_vector<fptype> host_hist;
  4862     sprintf(strbuffer, 
"Bkg%i_dalitzhist.txt", bkg);
  4863     std::string fname = app_ptr->
get_filename(strbuffer, 
"examples/pipipi0DPFit");
  4882     app->add_option(
"--luckyFrac", 
luckyFrac, 
"", 
true);
  4883     app->add_option(
"--mesonRad", 
mesonRad, 
"", 
true);
  4884     app->add_option(
"--normBins", 
normBinning, 
"", 
true);
  4885     app->add_option(
"--blindSeed", 
blindSeed, 
"", 
true);
  4886     app->add_option(
"--mdslices", 
mdslices, 
"", 
true);
  4887     app->add_option(
"--offset", 
md0offset, 
"Offest in GeV", 
true);
  4893     app->add_option(
"--upperTime", 
upperTime, 
"", 
true);
  4894     app->add_option(
"--lowerTime", 
lowerTime, 
"", 
true);
  4895     app->add_option(
"--maxSigma", 
maxSigma, 
"", 
true);
  4896     app->add_option(
"--polyEff", 
polyEff, 
"", 
true);
  4897     app->add_option(
"--m23Slices", 
m23Slices, 
"", 
true);
  4910     app->add_flag(
"--makePlots", 
makePlots);
  4911     app->add_set(
"--mkg2Model", 
bkg2Model_str, {
"histogram", 
"parameter", 
"sideband"}, 
"", 
true);
  4914     app->add_option(
"--bkgHistBins", 
bkgHistBins, 
"", 
true);
  4915     app->add_option(
"--varyParameterUp", 
paramUp, 
"", 
true);
  4916     app->add_option(
"--varyParameterDn", 
paramDn, 
"", 
true);
  4921     gStyle->SetCanvasBorderMode(0);
  4922     gStyle->SetCanvasColor(10);
  4923     gStyle->SetFrameFillColor(10);
  4924     gStyle->SetFrameBorderMode(0);
  4925     gStyle->SetPadColor(0);
  4926     gStyle->SetTitleColor(1);
  4927     gStyle->SetStatColor(0);
  4928     gStyle->SetFillColor(0);
  4929     gStyle->SetFuncWidth(1);
  4930     gStyle->SetLineWidth(1);
  4931     gStyle->SetLineColor(1);
  4932     gStyle->SetPalette(1, 0);
  4933     foo    = 
new TCanvas();
  4941     app.require_subcommand();
  4943     app.add_flag(
"--minuit1", 
minuit1, 
"Use Minuit 1 instead of Minuit 2");
  4949     int genResolutions = 0;
  4950     double dplotres    = 0;
  4952     auto toy = app.add_subcommand(
"toy", 
"Toy MC Performance evaluation");
  4953     toy->add_option(
"-s,--sample,sample", sample, 
"Sample number to use", 
true);
  4954     toy->add_option(
"-l,--load,load", load, 
"Number of times to load", 
true);
  4955     toy->add_option(
"-m,--max", 
maxEvents, 
"Maximum number of events to read", 
true);
  4956     toy->add_flag(
"-p,--plot", plots, 
"Also make plots");
  4957     toy->set_callback([&]() { retval = 
runToyFit(sample, load, plots); });
  4959     auto truth_fit = app.add_subcommand(
"truth", 
"Truth Monte Carlo fit");
  4960     truth_fit->add_option(
"-d,--data,data", data, 
"Data to use")->required()->check(GooFit::ExistingFile);
  4961     truth_fit->set_callback([&]() { retval = 
runTruthMCFit(data, 
false); });
  4963     auto sigma_fit = app.add_subcommand(
"sigma", 
"Run sigma fit");
  4964     sigma_fit->add_option(
"-d,--data,data", data, 
"Data to use")->required()->check(GooFit::ExistingFile);
  4965     sigma_fit->add_option(
"-s,--slices,slices", 
m23Slices, 
"m23 slices")->required();
  4966     sigma_fit->set_callback([&]() { retval = 
runSigmaFit(data.c_str()); });
  4968     auto efficiency_fit = app.add_subcommand(
"efficiency", 
"Run efficiency fit");
  4969     efficiency_fit->add_option(
"-s,--sample,sample", sample, 
"Sample number to use", 
true);
  4970     efficiency_fit->set_callback([&]() { retval = 
runEfficiencyFit(sample); });
  4972     auto canonical_fit = app.add_subcommand(
"canonical", 
"Run the canonical fit");
  4973     canonical_fit->add_option(
"-d,--data,data", data, 
"Data to use")->required()->check(GooFit::ExistingFile);
  4975     canonical_fit->set_callback([&]() {
  4980     auto background_dalitz_fit = app.add_subcommand(
"background_dalitz", 
"Run the background Dalitz fit");
  4981     background_dalitz_fit->add_option(
"-s,--sample,sample", sample, 
"Sample number to use", 
true);
  4983     background_dalitz_fit->set_callback([&]() {
  4988     auto background_sigma_fit = app.add_subcommand(
"background_sigma", 
"Run background sigma fit");
  4989     background_sigma_fit->add_option(
"-s,--sample,sample", sample, 
"Sample number to use", 
true);
  4992     auto write_background_histograms = app.add_subcommand(
"background_histograms", 
"Write background histograms");
  4993     write_background_histograms->add_option(
"-s,--sample,sample", sample, 
"Sample number to use", 
true);
  4996     auto run_gen_mc_fit = app.add_subcommand(
"run_gen_mc", 
"Run generated Monte Carlo fit");
  4997     run_gen_mc_fit->add_option(
"-d,--data,data", data, 
"Data to use")->required()->check(GooFit::ExistingFile);
  4998     run_gen_mc_fit->add_option(
"-g,--genres,gen-resolutions", genResolutions)->required();
  4999     run_gen_mc_fit->add_option(
"-p,--dplotres,dplotres", dplotres);
  5000     run_gen_mc_fit->set_callback([&]() {
  5006     auto make_time_plots = app.add_subcommand(
"make_time_plots", 
"Make time plots");
  5007     make_time_plots->add_option(
"-d,--data,data", data, 
"Data to use")->required()->check(GooFit::ExistingFile);
  5008     make_time_plots->set_callback([&]() { 
makeTimePlots(data); });
 IncoherentSumPdf * incsum2
 
size_t getNumEvents() const
 
fptype getBinSize() const
Get the bin size, (upper-lower) / bins. 
 
__host__ void printProfileInfo(bool topLevel=true)
 
void normalize(TH1F *dat)
 
void setFixed(bool fix)
Set the fixedness of a variable. 
 
std::vector< ResonancePdf * > resonances
 
vector< GooPdf * > jsuList
 
void makeFullFitVariables()
 
fptype getBinContent(size_t bin) const
Get the content of a bin. 
 
__host__ void setParameterConstantness(bool constant=true)
 
void setNumBins(size_t num)
Set the number of bins. 
 
int runGeneratedMCFit(std::string fname, int genResolutions, double dplotres)
 
Variable maxDalitzY("maxDalitzY", pow(_mD0 - piPlusMass, 2))
 
Variable constantZero("constantZero", 0)
 
double deltam_lower_window
 
GooPdf * makeBkg4_sigma()
 
GooPdf * makeFlatBkgDalitzPdf(bool fixem=true)
 
Variable neutrlM("neutrlM", 0.1349766)
 
bool notUseBackground3Hist
 
Variable massSum("massSum", _mD0 *_mD0+2 *piPlusMass *piPlusMass+piZeroMass *piZeroMass)
 
__host__ Variable * getParameterByName(std::string n)
 
int runSigmaFit(const char *fname)
 
TddpPdf * makeSignalPdf(MixingTimeResolution *resolution=0, GooPdf *eff=0)
 
Variable chargeM("chargeM", 0.13957018)
 
void makeToyDalitzPlots(GooPdf *overallSignal, std::string plotdir="./plots_from_toy_mixfit/")
 
Variable minDalitzX("minDalitzX", pow(piPlusMass+piZeroMass, 2))
 
fptype cpuGetM23(fptype massPZ, fptype massPM)
 
std::vector< Variable > weights
 
void setMaxCalls(double mxc)
 
void coarseBin(TH2F &dalitzHist, int grain)
 
__host__ std::vector< std::vector< fptype > > getCompProbsAtDataPoints()
Produce a list of probabilies at points. 
 
GooPdf * makeBkg_sigma_strips(int bkgnum)
 
void parseArg(GooFit::App *app)
 
void makeDalitzPlots(GooPdf *overallSignal, std::string plotdir="./plots_from_mixfit/")
 
void loadDataFile(std::string fname, UnbinnedDataSet **setToFill=0, int effSkip=3)
 
void writeToFile(PdfBase *pdf, const char *fname)
 
void setValue(fptype val)
Set the value. 
 
bool cpuDalitz(fptype m12, fptype m13, fptype bigM, fptype dm1, fptype dm2, fptype dm3)
 
double getContent(TH2F *plot)
 
GooPdf * makeEfficiencyPdf()
 
int runToyFit(int ifile, int nfile, bool noPlots=true)
 
Special class for observables. Used in DataSets. 
 
GooPdf * makeBkg3DalitzPdf(bool fixem=true)
 
const float toySigFraction
 
ChisqInfo * getAdaptiveChisquare(TH2F *datPlot, TH2F *pdfPlot)
 
Variable constantTwo("constantTwo", 2)
 
fptype getValue(const Observable &var, size_t idx) const
Get the value at a specific variable and event number. 
 
Variable fixedRhoWidth("rho_width", 0.1503, 0.01, 0.1, 0.2)
 
Variable minDalitzY("minDalitzY", pow(piPlusMass+piZeroMass, 2))
 
Variable constantBigM("constantBigM", _mD02+2 *piPlusMass *piPlusMass+piZeroMass *piZeroMass)
 
Variable minDalitzZ("minDalitzZ", pow(piPlusMass+piPlusMass, 2))
 
void setBinContent(unsigned int bin, fptype value)
 
bool notUseBackground4Hist
 
GooPdf * makeBackground3DalitzParam()
 
__host__ void extractHistogram(thrust::host_vector< fptype > &host_hist)
 
size_t getNumBins() const
Get the number of bins. 
 
UnbinnedDataSet * effdata
 
Variable constantOne("constantOne", 1)
 
IncoherentSumPdf * incsum3
 
BinnedDataSet * binEffData
 
__host__ void setDataSize(unsigned int dataSize, unsigned int evtSize=5)
 
GooPdf * make4BinSigmaMap()
 
__host__ void setData(DataSet *data)
 
int runCanonicalFit(std::string fname, bool noPlots=true)
 
void setUpperLimit(fptype val)
Set the upper limit. 
 
const float toyBkgTimeRMS
 
std::vector< PdfBase * > comps
 
int runBackgroundDalitzFit(int bkgType, bool plots=false)
 
void createWeightHistogram()
 
GooPdf * makeBkg2DalitzPdf(bool fixem=true)
 
double deltam_upper_window
 
int runBackgroundSigmaFit(int bkgType)
 
void getBackgroundFile(int bkgType)
 
void writeListOfNumbers(thrust::host_vector< fptype > &target, const char *fname)
 
GooPdf * makeMikhailJSU_gg(bool fixem=true)
 
std::string bkg2Model_str
 
const float toyBkgTimeMean
 
GooPdf * makeOverallSignal()
 
EventNumber * eventNumber
 
virtual __host__ std::vector< Observable > getObservables() const
 
__host__ std::vector< fptype > evaluateAtPoints(Observable var)
 
GooPdf * makeBkg3_sigma()
 
void plotFit(Observable var, UnbinnedDataSet *dat, GooPdf *fit)
 
fptype getLowerLimit() const
Get the lower limit. 
 
GooPdf * make1BinSigmaMap()
 
const std::vector< Observable > & getObservables() const
 
Variable fixedRhoMass("rho_mass", 0.7758, 0.01, 0.7, 0.8)
 
fptype getValue() const
Get the value. 
 
Variable constantMinusOne("constantMinusOne", -1)
 
fptype getUpperLimit() const
Get the upper limit. 
 
int main(int argc, char **argv)
 
void addWeightedEvent(double weight) override
 
void setBlind(fptype val)
Hides the number; the real value is the result minus this value. Cannot be retreived once set...
 
double calcGauInteg(double x1, double x2)
 
Variable maxDalitzX("maxDalitzX", pow(_mD0 - piPlusMass, 2))
 
Variable motherM("motherM", 1.86484)
 
Variable maxDalitzZ("maxDalitzZ", pow(_mD0 - piZeroMass, 2))
 
GooPdf * make_m23_transform()
 
void setMaxCalls(unsigned int max_calls=0)
Set the maximum number of calls. 0 for Minuit2 default. 
 
void getToyData(float sigweight=0.9)
 
void set_bkg_model_from_string()
 
void setValueForAllEvents(const Observable &var)
Set all entries to a constant value (note: this is kind of ugly) 
 
GooPdf * makeGaussianTimePdf(int bkg)
 
void readFromFile(PdfBase *pdf, const char *fname)
 
GooPdf * makeExpGausTimePdf(int bkg)
 
ROOT::Minuit2::FunctionMinimum fit()
This runs the fit. 
 
#define GOOFIT_PARSE(app,...)
 
size_t getNumBins() const
 
Relativistic Breit-Wigner. 
 
IncoherentSumPdf * incsum5
 
IncoherentSumPdf * incsum1
 
void makeTimePlots(std::string fname)
 
void loadEvent(size_t idx)
Set all the variables to the current event values. 
 
int runTruthMCFit(std::string fname, bool noPlots=true)
 
__host__ void setDataSize(unsigned int dataSize, unsigned int evtSize=3)
 
int runEfficiencyFit(int which)
 
void setLowerLimit(fptype val)
Set the lower limit. 
 
bool readWrapper(std::ifstream &reader, std::string fname=strbuffer)
 
GooFit::Application * app_ptr
 
GooPdf * makeSigmaHists()
 
IncoherentSumPdf * incsum6
 
GooPdf * makeSignalJSU_gg(int idx, bool fixem=true)
 
UnbinnedDataSet ** sigma_data
 
__host__ void addSpecialMask(int m)
 
fptype getError() const
Get the error. 
 
double calcToyWeight(double sigratio, double m)
 
std::string get_filename(const std::string &input_str, std::string base="") const
 
void printMemoryStatus(std::string file, int line)
 
GooPdf * makeBackground4DalitzParam()
 
GooPdf * makeBkg4DalitzPdf(bool fixem=true)
 
void writeBackgroundHistograms(int bkg)
 
IncoherentSumPdf * incsum4
 
GooPdf * makeEfficiencyPoly()
 
std::vector< Observable > obsweights
 
SmoothHistogramPdf * makeBackgroundHistogram(int bkgnum, std::string overridename="")
 
GooPdf * makeBkg2_sigma()
 
const std::string & getName() const
Get the name.